$(document).ready(function(){
	// Обновить информацию о корзине
	showBasket();
});

function setFilterCatalog(part,cid){
	loc="";
	
//	if($("#fullSearch").attr("checked") && cid>0) part += "/cid/"+cid;
//	if($("#fullSearch").attr("checked") && cid>0) 
	part += "/cid/"+cid;

	$("form#filter select").each(function(){
		nameFilter = this.id;
		if($("#"+nameFilter).attr("value")!=""&&$("#"+nameFilter).attr("value")!=undefined) loc +="/"+nameFilter+"/"+$("#"+nameFilter).attr("value");
	})

	if($("#fullSearch").attr("checked"))
		loc +="/fullsearch/true";
	else
		loc +="/fullsearch/false";
	

	location.href = "/"+part+loc+"/";
	return false;
}
function resetFilterCatalog(part,cid){
	loc="";
	part += "/cid/"+cid;
	location.href = "/"+part+loc+"/";
}

function open_close_div(divName){
	if($("#"+divName).css("display")=='none'){
		$("#"+divName).animate({height:"show"},500);
		$("#filter_header_img_img").attr("src","/img/arrowdown.png");
	}else{
		$("#"+divName).animate({height:"hide"},500);
		$("#filter_header_img_img").attr("src","/img/arrowright.png");
	}	
}

function showBasket(){
	$(".order").load("/50/view/1/",function(){});
}

function logining(){
	var formData = new Object();
	formData.logining = "1"; 
	formData.login = $("#login").attr("value");
	formData.pass = $("#pass").attr("value");


	$.post("/14/",formData,	
	        function(data){
			switch(parseInt(data)){
				case 0: 
					ShowMessage("Ваша учётная запись не найдена.<br />Проверте правельность логина и пароля|err");
					break;
				case 1: 
					ShowMessage("Ваша учётная запись не активирована. Проверьте почту, и следуйте инструкциям в письме, с нашего сайта|err");
					break;
				case 2:
					document.location.href = "/4/";
					break;
				
			}
		}
	)
}
function unlogining(){
	var formData = new Object();
	formData.unlogining = "1"; 

	$.post("/14/",formData,	
	        function(data){
			document.location.href = "/14/";
		}
	)
}
function ShowMessage(messageText){ 
if(messageText!=''){
	messageText = messageText.split("\|");	
	switch(messageText[1]){
		case "info": ico="65.png"; title="Информация"; break;
		case "confirm": ico="25.png"; title="Вопрос"; break;
		case "alert": ico="25.png"; title="Внимание"; break;
		case "ok": ico="100.png"; title="Сообщение"; break;
		case "err": ico="116.png"; title="Внимание"; /*$("#messageWindow #messageText").css("color","red");*/ break;
		default: ico="25.png"; title=""; break;		
	}	
/*	$("#messageWindow #massageIco img").attr("src","/admin/img/pics2/"+ico);
	$("#messageWindow #massageIco img").load(function(){
		$("#messageWindow #massageIco img").show();
	});*/

	$("#messageWindow #messageText").html(messageText[0]);
	$("#messageWindow").attr("title",title);
	$("#messageWindow").dialog({
			bgiframe: true,
			resizable: false,
			height:200,
			modal: true,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},
			buttons: {
				'Закрыть': function(){
					$(this).dialog('destroy');					
				}
			}
	});
}
return false;
}
function ShowExample(src){ 
	var widthWindow = 480;
	var heightWindow = 520;
	$("#popUpWindow #content iframe").attr("src","/templates/load.tpl");

        $("#popUpWindow")
		.show()
		.css("height",(document.getElementById("page").offsetHeight)+"px");

	$("#popUpWindow .messagerFront")
		.css("top",(document.body.scrollTop+(document.body['clientHeight'] -  heightWindow)/2))
		.css("left",(document.body['clientWidth'] - widthWindow)/2);

	$("#popUpWindow #content iframe").attr("src",src+"?"+Math.random());

	return false;
}

function CloseExample(){
	$('#popUpWindow',window.parent.document).hide();
	$("#popUpWindow iframe",window.parent.document).attr("src","/templates/load.tpl");
	return false;
}
function setRadingFormOrder(){
	$("#formaOrder").validate({
               rules : {
                	name : {required : true},
	                phone : {required : true},
			email : {required: true, email: true},
			adress : {required: true}
               },
               messages : {
                       	name : {
                               required : "Введите ваше имя"
	                      },
               	       	phone : {
                               required : "Введите телефон "
	                      },
               	      	email : {
                                required : "Введите адрес электронной почты",
				email: "Нужен корректный email адрес"
	                      },
               	      	adress: {
                                required : "Введите адрес доставки"
	                      }
	       }

       });

	$("#sendform").validate({
               rules : {
                	fio : {required : true},
	                phone : {required : true},
			sender_mail : {required: true, email: true},
	                info : {required : true},

               },
               messages : {
                       	fio : {
                               required : "Введите ваше имя"
	                      },
               	       	phone : {
                               required : "Введите телефон"
	                      },
               	      	sender_mail : {
                                required : "Введите адрес электронной почты",
				email: "Нужен корректный email адрес"
	                      },
               	      	info: {
                                required : "Введите текст сообщения"
	                      }
	       }

       });


	$("#registrationForm").validate({
               rules : {
                	name : {required : true, minlength: 3},
                	login : {required : true, minlength: 3},
                	pass : {required : true, minlength: 6},
                	pass_again : {required : true, equalTo: "#pass_"},
	                phone : {required : true, minlength: 4},
	                orgname : {required : true},
	                nomsv : {required : true},
	                email : {required : true, email:true},
			code : {required: true,  minlength: 5}
               },
               messages : {
                       	name : {
                               required : "Введите ваше имя",
                               minlength : "Введите не менее, чем 3 символа"
	                      },
                       	login : {
                               required : "Введите ваш login",
                               minlength : "Введите не менее, чем 3 символа"
	                      },
                       	pass : {
                               required : "Введите ваш пароль",
                               minlength : "Введите не менее, чем 6 символа"
	                      },
                       	pass_again : {
				required : "Введите ваш пароль ещё раз",
				equalTo: "Пароль не совпадает"
	                      },
               	       	phone : {
                               required : "Введите телефон ",
                               minlength : "Введите телефон"
	                      },
               	       	orgname : {
                               required : "Введите название организации"
	                      },
               	       	nomsv : {
                               required : "Введите номер свидетельства"
	                      },
               	      	email : {
                                required : "Введите адрес электронной почты",
				email: "Нужен корректный email адрес"
	                      },
                       	code : {
                               required : "Введите код с картинки",
                               minlength : "Введите код с картинки полностью"
	                      }
	       }

       });
}

function setCountProd(id,count){
	$.post("/50/",{id: id,deystvo:"setCountProd",count: count},function(data){
		showBasket();
	});
	return false;
}

function buy(id){
	var elem = $("#"+id);
	var idNom = elem.attr("idNom");
		
	$.post("/50/",{id: elem.attr("idNom")},function(data){
		if(data=="adding"){
//			$("#adding"+idNom).css("left",elem.offset().left - 70).css("top",elem.offset().top).show();
			$("#adding"+idNom).fadeIn(300);
			showBasket();
		}else if(data=="earlier_add"){
//			$("#earlier_add"+idNom).css("left",elem.offset().left - 80).css("top",elem.offset().top).show();
			$("#earlier_add"+idNom).fadeIn(300);
			showBasket();
		}
		setTimeout(
			function ShowToolTip(event){	
				$("#adding"+idNom).fadeOut(400);
				$("#earlier_add"+idNom).fadeOut(400);
			}
		, 1500);
		
	});
	return false;
}

