

function remove(obj){
    (obj.parentNode).removeChild(obj);
}

function hide_remove(obj){
    setTimeout(function(){
        var o = obj.style.opacity -= 0.1;
        if (o >= 0){
			
            setTimeout(arguments.callee,200);		
        }
		if((obj.style.opacity<=0.11)||(obj.style.opacity<0)){
			obj.style.opacity=0;
			remove(obj)
		}
    },200);
	
}
			



function hint_show(hint){
	 document.getElementById("hint").innerHTML = "&nbsp;&nbsp;<b> "+hint+"</b>";
	 document.getElementById("hint").style.visibility = "visible";

}

function hint_hide(){
	document.getElementById("hint").style.visibility = "hidden";
}



function img_ok(img){

    var i = document.getElementById(img);
    var elm = document.getElementById('errors');
    if(i.lang!='ok'){
        elm.value = elm.value-1;
        if (elm.value==0){
            document.getElementById('reg_buttom').style.visibility = 'visible';
        }
    }
    i.src = '/images/ok.png';
    i.lang = 'ok';
}

function img_bad(img){
    var i = document.getElementById(img);
    if(i.lang!='bad'){
        var elm = document.getElementById('errors');
        elm.value = Number(elm.value)+1;
        if (elm.value>0){
            document.getElementById('reg_buttom').style.visibility = 'hidden';
        }
    }
    i.src = '/images/bad.png';
    i.lang = 'bad';
}

function chek_length(v,img){
    if(v.length>1){
        img_ok(img);
    }else{
        img_bad(img);
    }
}

function equality(v1,v2,img){
    if(v1.value===v2.value){
       img_ok(img);
    }else{
        img_bad(img);
    }
}

function chek_tell(tell,img){

    if ((tell.value.match(/[0-9]{3}\s[0-9]{3}\-[0-9]{2}\-[0-9]{2}/))
            ||(tell.value.match(/\([0-9]{3}\)\s[0-9]{3}\-[0-9]{2}\-[0-9]{2}/))
            ||(tell.value.match(/[0-9]{3}[0-9]{3}\-[0-9]{2}\-[0-9]{2}/))
            ||(tell.value.match(/[0-9]{3}\-[0-9]{3}\-[0-9]{2}\-[0-9]{2}/))
            ||(tell.value.match(/\([0-9]{3}\)[0-9]{3}\-[0-9]{2}\-[0-9]{2}/))
            ||(tell.value.match(/\([0-9]{3}\)\-[0-9]{3}\-[0-9]{2}\-[0-9]{2}/))
            ||(tell.value.match(/[0-9]{10}/))
            ) {
        img_ok(img);
    }else{
        img_bad(img);
    }
}

function is_login(login,img){
    $.post("/register/is_login/"+login,
        function(data){
            if(data==0){
                img_ok(img);
            }else{
                img_bad(img);
            }
        });
}

function show_pics(cat,pics){
    $("#shadow_bg").css("display","block");
    $("#shadow_bg").css("zIndex","1000");
    $("#shadow_bg").css("height",document.body.scrollHeight);
    $.post("/gallery/picture/"+cat+"/"+pics,{},function complite(html){
        $("#shadow_bg").html(html);
    });
}

function change_pics(cat,pics){

	$.post("/gallery/new_pics_build/"+pics+"/"+cat,function complite(html){
		$("#pc").fadeOut(500,function(){
			$("#pc").html(html);
			
			
			var pred = $("#pd").html();	
			var next = $("#nx").html();
			$("#next").attr("lang",next);
			$("#pred").attr("lang",pred);	
			$("#pc").fadeIn(500);
		});
    });
}

function change(id){
    $("#"+id).stop(true, true);  
	if($("#"+id).css("opacity")==0){
		$("#"+id).fadeTo(1000, 1);
	}else if ($("#"+id).css("opacity")==1){
		$("#"+id).fadeTo(1000, 0);
	}
	$("#hint"+id).fadeTo(500, 1);
}

function hide(id){
	$("#hint"+id).fadeTo(500, 0);
}



function close_form(elm){
    document.getElementById(elm).style.display = "none";
    document.getElementById(elm).style.zIndex = 0;
}


function show_price(){
    bprice = parseFloat(document.getElementById('border_price').value);
    pprice = parseFloat(document.getElementById('pics_price').value);
    bcash = (bprice*pprice)/100;
    t = (bcash/10).toFixed(0);
    bcash = t*10;
    if (isNaN(pprice)){
        pprice=0;
        bcash=0;
    }
    if (isNaN(bprice)){
        bcash=0;
    }
    tprice = pprice+bcash;
    document.getElementById("p_price").innerHTML = pprice;
    document.getElementById("b_price").innerHTML = bcash;
    document.getElementById("t_price").innerHTML = tprice;
}

function calc_pics_price(psize){

    if (psize<150){
        cash = (psize*0.1)*(psize*0.1) - (psize * 0.3);
    }else if ((psize >= 150)&&(psize <= 250)){
        cash = (psize*0.1)*(psize*0.1);
    }else {
        cash = (psize*0.1)*(psize*0.1)-(psize*0.2);
    }
    t = (cash/10).toFixed(0);
    cash = t*10;
    document.getElementById('pics_price').value = cash;
    show_price();
}
function oralo(){
	alert("aaa");
}

function buildborder(bid){
	
	$(".bord").fadeOut(500,function(){
		$("#k1").attr("src","/images/border/b"+bid+"/k1.jpg");
		$("#k2").attr("src","/images/border/b"+bid+"/k2.jpg");
		$("#k3").attr("src","/images/border/b"+bid+"/k4.jpg");
		$("#k4").attr("src","/images/border/b"+bid+"/k3.jpg");
		$("#s1").attr("src","/images/border/b"+bid+"/s1.jpg");
		$("#s2").attr("src","/images/border/b"+bid+"/s4.jpg");
		$("#s3").attr("src","/images/border/b"+bid+"/s2.jpg");
		$("#s4").attr("src","/images/border/b"+bid+"/s3.jpg");
		$("#s4").load(function(){$(".bord").fadeIn(500);});
		
	});
	
}

function add_to_cart(bid,pid,size,cash,pimg,bimg){
	
	$.post("/buy/",{bid:bid,pid:pid,size:size,cash:cash,pimg:pimg,bimg:bimg},function complite(html){
		document.getElementById("buy_shadow").style.display = "none";
		document.getElementById("buy_shadow").style.zIndex = 0;
		document.getElementById("shadow_bg").style.display = "none";
		document.getElementById("shadow_bg").style.zIndex = 0;
		
		фдуке("Товар добавлений у кошик");

		document.getElementById("count_cart_item").innerHTML = html;
	});
}

function buy_form(){ 

    $.post("/buy/form/",{pid:document.getElementById("pics_id").value,bid:document.getElementById("border_id").value,border:document.getElementById("border_pics").value,size:document.getElementById("size").value,img:document.getElementById("image").src,price:document.getElementById("t_price").innerHTML},function complite(html){
		document.getElementById("buy_shadow").style.display = "block";
		document.getElementById("buy_shadow").style.zIndex = 1500;
		document.getElementById("buy_shadow").innerHTML = html;
    });
}

function set_b_price(price,path,bid){ 
    document.getElementById('border_price').value = price;
    document.getElementById('border_pics').value = path;
    document.getElementById('border_id').value = bid;
}


function dell(id){
    var div = document.getElementById(id);
    var hidden_input = document.createElement('input');
    hidden_input.type = "hidden";
    hidden_input.id = 'h'+id;
    hidden_input.value = div.innerHTML;
    var t_price =  document.getElementById("t_price");
    var price = document.getElementById("price"+id);
    t_price.innerHTML = t_price.innerHTML-price.innerHTML;
    div.innerHTML = "Видалено!"; //<a onclick='restore("+id+")'>Відновити?</a>
    div.appendChild(hidden_input);

    $.post("/buy/dell/"+id,
            function complite(html){
                document.getElementById("count_cart_item").innerHTML = html;

            });

}
function restore(id){
    var hidden_input = document.getElementById("h"+id);
    var div = document.getElementById(id);
    div.innerHTML = hidden_input.value;
	
    var pics_id = document.getElementById("p"+id).value;
    var border_id = document.getElementById("b"+id).value;
    var cash = document.getElementById("price"+id).innerHTML;
    var size = document.getElementById("size"+id).innerHTML;
	var pimg = document.getElementById("image"+id).src;
	var bimg = document.getElementById("brd"+id).src;
    t_price.innerHTML = parseInt(t_price.innerHTML)+parseInt(price.innerHTML);
    $.post("/buy/restore/"+id,{bid:border_id,pid:pics_id,size:size,cash:cash,pimg:pimg,bimg:bimg},
            function(data){
                

                 
            });

}

function order_make(){
	$.post("/order/make",{pip:document.getElementById("pip").value,tel:document.getElementById("tel").value,town:document.getElementById("town").value},function complite(html){
		alert('ваше замовлення успішно виконане!');
		window.location.href = "/";
	});
	
}


function getNameBrouser() {
 var ua = navigator.userAgent.toLowerCase();

 if (ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1 && ua.indexOf("webtv") == -1) {
   alert("Для перегляду даного сайту скористайтесь іншин браузером. Такими як: Mozilla Firefox, Opera, Chrome..");
   window.location.href = "http://mozilla-russia.org/"
 }

 if (ua.indexOf("opera") != -1) {
   return "opera"
 }

 if (ua.indexOf("gecko") != -1) {
   return "mozilla";
 }

 if (ua.indexOf("safari") != -1) {
   return "safari";
 }

 if (ua.indexOf("konqueror") != -1) {
   return "konqueror";
 }
 return "unknown";
}
