
/* Popup */

function popUp(URL,w,h) 
{
	day = new Date();
	id = day.getTime();
	
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width="+w+",height="+h+",left = 240,top = 212');");
}

/* Menu */

function toggle(node)
{
	var expires = new Date();
 	expires.setTime(expires.getTime() + (1000 * 86400 * 360));
	
	var oTblStyle = document.getElementById("tree" + node).style.display;
	
	if (oTblStyle == "none")
	{
		document.getElementById(node).src = "images/arr_search_girl_top.gif";
		document.getElementById("tree" + node).style.display = "block";
		
		//Set cookie						
		document.cookie =  node + "=vis; path=/";
	}
	else
	{		
		document.getElementById(node).src = "images/arr_search_girl_down.gif";
		document.getElementById("tree" + node).style.display = "none";
		
		//Set cookie		
		document.cookie =  node + "=unv; path=/";
	}
}

/* Checkbox */

function searchCheckboxSelect()
{
	var oForm = document.getElementById("searchForm");	
	var status = document.getElementById("searchAllCheckbox").checked;
	
	for(var i = 0; i < oForm.length; i++)
	{
		if(oForm.elements[i].getAttribute("type") == "checkbox" && oForm.elements[i].getAttribute("name") == "search_service[]") 
		{
			oForm.elements[i].checked = status;		
		}
	}		
}

function searchCheckboxChange()
{
	var yes = 0;
	var all = 0;
	var oForm = document.getElementById("searchForm");
	
	for(var i = 0; i < oForm.length; i++)
	{		
		if(oForm.elements[i].getAttribute("type") == "checkbox" && oForm.elements[i].getAttribute("name") == "search_service[]")
		{			
			if(oForm.elements[i].checked == true) yes++;			
						
			all++;
		}		
	}
	
	if(yes == all) document.getElementById("searchAllCheckbox").checked = true;
	else document.getElementById("searchAllCheckbox").checked = false;
}

$(document).ready(function() {
	
$(".searchSign").click( function () {
		var div = "#tree"+this.id;	
		
		if($(div).attr("style") == "display: none;" || $(div).attr("style") == "display: none" || $(div).attr("style") == "DISPLAY: none;" || $(div).attr("style") == "DISPLAY: none" || $(div).attr("style") == "")
		{
			$(div).attr("style", "display: block;");
			$(this).attr("src", "images/arr_search_girl_top.gif");			
			$.cookie(this.id, "vis", {path: "/"});
			
			/*$.ajax({
				type: "POST",  
        		data: "search_load="+this.id,  
       	 		url: "search_ajax.php",  
				beforeSend: function(){$(div).html("<div class=\"loadingCont\"><img src=\"images/loading.gif\"><div>")},
				success: function(data){$(div).html(data)},
				timeout:20000
			});*/
		}
		else {							
			//Обнуляем куки формы
			
			var inputArr1 = $(div + " select");			

			$.each(inputArr1, function(i, inputObj){
		  								
				var inputName = $(inputObj).attr("name");
   				var inputValue = $(inputObj).attr("value");
   		
   				if(inputName == "search_service[]") var cookieName = "search_service[" + inputValue + "]";
   				else var cookieName = inputName;

				if(cookieName.length > 0) $.cookie(cookieName, null, {path: "/"});
 			});
 			
 			var inputArr2 = $(div + " input");
 			
 			$.each(inputArr2, function(i, inputObj){
		  								
				var inputName = $(inputObj).attr("name");
   				var inputValue = $(inputObj).attr("value");
   		
   				if(inputName == "search_service[]") var cookieName = "search_service[" + inputValue + "]";
   				else var cookieName = inputName;

				if(cookieName.length > 0) $.cookie(cookieName, null, {path: "/"});
 			});
 			
 			$(div).attr("style", "display: none;");//Скрываем div
			$(this).attr("src", "images/arr_search_girl_down.gif");//Меняем значек
			$.cookie(this.id, "unv", {path: "/"});//Меняем cookie
 			//$(div).html("");//Удаляем поля формы
		}
  });
  
 $("#searchResetButton").click( function () {
 	
	search_form_reset();
	
 	window.location = "/devushki/" + $(this).attr("name") + "/";
    
  });
  
})

function search_form_reset()
{
	//Обнуляем куки формы
	var inputArr = $("#searchForm input,select");
	
	$.each(inputArr, function(i, inputObj){
	
		var inputName = $(inputObj).attr("name");
   		var inputValue = $(inputObj).attr("value");
   		
   		if(inputName == "search_service[]") var cookieName = "search_service[" + inputValue + "]";
   		else var cookieName = inputName;

		if(cookieName.length > 0) $.cookie(cookieName, null, {path: "/"});
 	});
 	
 	//Обнуляем div
 	$("#searchForm div").attr("style", "display: none;");
	$("#searchForm img").attr("src", "images/arr_search_girl_down.gif");
	
	//Обнуляем возраст
	
	$("#treeAgeBlock").attr("style", "display: block;");
	$("#AgeBlock").attr("src", "images/arr_search_girl_top.gif");	
	
	$("#ageFromSelect").val("18");
	$("#ageToSelect").val("65");
	
	//Обнуляем куки div
	var divArr = $("#searchForm div");
	
	$.each(divArr, function(i, divObj){
		
   		var divId = $(divObj).attr("id");
		var cookieName = divId.replace("tree", "")
		
		if(cookieName.length > 0) $.cookie(cookieName, null, {path: "/"});
 	});
}