
    var popupStatus = 0;

	jQuery(function($)  {
		$("#sbmSearch").click(function(){
			$('html, body').animate({scrollTop:0}, 'fast');
			centerPopup("showSearchBar");
			loadPopup("showSearchBar");
		});
	});
    
	jQuery(function($)  {
		$("#search_style_select").change(function(){
			$('html, body').animate({scrollTop:0}, 'fast');
			centerPopup("showSearchBar");
			loadPopup("showSearchBar");
		});
	});
	
	jQuery(function($)  {
		$("#search_label_select").change(function(){
			$('html, body').animate({scrollTop:0}, 'fast');
			centerPopup("showSearchBar");
			loadPopup("showSearchBar");
		});
	});
	
	jQuery(function($)  {
		$("#search_manufacturer_select").change(function(){
			$('html, body').animate({scrollTop:0}, 'fast');
			centerPopup("showSearchBar");
			loadPopup("showSearchBar");
		});
	});
	
	
	function loadPopup(div_id){
		//loads popup only if it is disabled
		if(popupStatus == 0){
			jQuery("#backgroundPopup").css({
				"opacity": "0.7"
			});
			jQuery("#backgroundPopup").fadeIn("slow");
			jQuery("#"+div_id).fadeIn("slow");
			popupStatus = 1;
		}
	}
	
	//disabling popup with jQuery magic!
	function disablePopup(div_id){
		//disables popup only if it is enabled
		if(popupStatus == 1){
			jQuery("#backgroundPopup").fadeOut("slow");
			jQuery("#"+div_id).fadeOut("slow");
			popupStatus = 0;
		}
	}
	
	
	//centering popup
	function centerPopup(div_id){
		//request data for centering
		var windowWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;
		var popupHeight = jQuery("#"+div_id).height();
		var popupWidth = jQuery("#"+div_id).width();
		//centering
		jQuery("#"+div_id).css({
			"position": "absolute",
			"top": (windowHeight/2) - (popupHeight/2),
			"left": (windowWidth/2) - (popupWidth/2)
		});
		//only need force for IE6
		jQuery("#backgroundPopup").css({
			"height": windowHeight
		});
	}

	
	function fillFormByZipCode(zipcode){
		$.getJSON('zipresolve.php', {'zipcode': zipcode}, function(data){
			if(data != null){
				$('#zipCode').removeClass('error');
				$('#region').val(data.region).attr('readonly', 'readonly');
				$('#subregion').val(data.area).attr('readonly', 'readonly');
				$('#city').val(data.city).attr('readonly', 'readonly');
			}
			else{
				$('#zipCode').addClass('error');
				$('#region').val('');
				$('#subregion').val('');
				$('#city').val('');
			}
		});
	}

	function handleZipCodeChangeEvent(zipcode){
		zipcode = zipcode.replace(/[^0-9]/g, '');
		if(zipcode.length == 6){
			fillFormByZipCode(zipcode);
		}
		else{
			$('#zipCode').addClass('error');
			$('#region').val('');
			$('#subregion').val('');
			$('#city').val('');
		}
	}
	
function open_window(link,w,h){var win="width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";newWin2=window.open(link,'newWin2',win);newWin2.focus();}function playWin(link,w,h){var win="width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";newWin=window.open(link,'newWin',win);newWin.focus();}
function confirmDelete(){alert('Чтобы удалить Ваш аккаунт, обратитесь пожалуйста к администрации магазина.');}
function validate(){if(document.subscription_form.email.value.length<1){alert("Пожалуйста, вводите e-mail правильно");return false;}if(document.subscription_form.email.value=='Email'){alert("Пожалуйста, вводите e-mail правильно");return false;}return true;}
function validate_disc(){if(document.formD.nick.value.length<1){alert("Пожалуйста, введите Ваш псевдоним");return false;}if(document.formD.topic.value.length<1){alert("Пожалуйста, введите тему сообщения");return false;}return true;}function validate_search(){if(document.Sform.price1.value!=""&&((document.Sform.price1.value<0)||isNaN(document.Sform.price1.value))){alert("Цена должна быть положительным числом");return false;}if(document.Sform.price2.value!=""&&((document.Sform.price2.value<0)||isNaN(document.Sform.price2.value))){alert("Цена должна быть положительным числом");return false;}return true;}
function checkShipAndPaymentRelation(){if(document.form_ship_and_payment.payment_type.value==1){if(document.form_ship_and_payment.shipping_type.value!=1||document.form_ship_and_payment.shipping_type.value!=5){alert("Наличными можно платить только при доставке курьером или если Вы забираете товар сами.")}}}
	