function SwitcherFilterList(div) {
	var div=document.getElementById(div);
	if (div.style.display=="none") {div.style.display="block";}
	else {div.style.display="none";}
}

function SetFilter(div,value) {
var div=document.getElementById(div);
re="&lt;";
value=value.replace(re,"<");
re="&gt;";
value=value.replace(re,">");
div.value=value;
}



function FilterSubmit(){
var price=document.getElementById("price").value;
var color=document.getElementById("color").value;
var filter_area=document.getElementById("filter_area").value;
	
	var v=new Date();	
	
	href=href+'&proc=filter&price='+encodeURIComponent(price)+'&color='+encodeURIComponent(color);
	ShowCatalog(href,"");

}

function SetColor() {
//document.getElementById("id_color").;
}
function ClearFilter() {
document.getElementById("price").value="";
document.getElementById("color").value="";
}

function PositionList(id_parrent,id,position) {
//alert("\n id="+id);

	if (position=="top") {
	document.getElementById(id).style.top=document.getElementById(id_parrent).offsetTop-document.getElementById(id).offsetHeight+"px";
	document.getElementById(id).style.left=document.getElementById(id_parrent).offsetLeft+"px";
	}
	if (position=="bottom") {
	document.getElementById(id).style.top=document.getElementById(id_parrent).offsetTop+document.getElementById(id_parrent).offsetHeight+"px";
	document.getElementById(id).style.left=document.getElementById(id_parrent).offsetLeft+"px";
	
	}
	if (position=="left") {
	document.getElementById(id).style.top=document.getElementById(id_parrent).offsetTop+"px";
	document.getElementById(id).style.left=document.getElementById(id_parrent).offsetLeft-document.getElementById(id).offsetWidth+"px";
	}
	
}


function AddColor(div_id,hidden_id,color_id,color_name) {



var ohidden_id=document.getElementById(hidden_id);

	if (ohidden_id.value=="1") {alert('Ýòîò öâåò óæå âûáðàí');}
	else {
	var odiv_id=document.getElementById(div_id);
	odiv_id.innerHTML+='<a id="color_'+color_id+'" onclick=\'DeleteColor("'+div_id+'","'+hidden_id+'","'+color_id+'")\'  style="curso:pointer">'+color_name+',&nbsp;&nbsp;</a>';
	ohidden_id.value=1;
	}	
	
}

function DeleteColor(div_id,hidden_id,color_id) {
var hidden_id=document.getElementById(hidden_id);

hidden_id.value="";

if (document.getElementById("color_"+color_id).outerHTML) { document.getElementById("color_"+color_id).outerHTML = ""; } 
else { 
var range = document.createRange(); 
range.setStartBefore(document.getElementById("color_"+color_id)); 
var docFrag = range.createContextualFragment(""); 
document.getElementById("color_"+color_id).parentNode.replaceChild(docFrag, document.getElementById("color_"+color_id));

} 
}

function ShowForm(div) {

var y=getBodyScrollTop();
var div=document.getElementById(div);
div.style.top=y+"px";
div.style.left=0+"px";
div.style.display="block";
}

function getBodyScrollTop()
{
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function captcha() {
	var v=new Date();	
	var page='captcha_img.php?v='+v.getTime();
	var xmlhttp = getXmlHttp();
	xmlhttp.open('GET', page, true);
	xmlhttp.setRequestHeader('Content-Type', 'image/jpeg');
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			if(xmlhttp.status == 200) {
    		document.getElementById("div_captcha_img").innerHTML=xmlhttp.responseText;
			document.getElementById("img_captcha_img").src=xmlhttp.responseText;
   			}
  		}
	}
	xmlhttp.send(null);

}



function SendLetter(id) {
	var keystring=document.getElementById("keystring").value;
	var name=document.getElementById("name").value;
	var email=document.getElementById("email").value;
	var quest=document.getElementById("quest_area").value;
	
	//var params = 'keystring=' + encodeURIComponent(keystring)+'proc'+ encodeURIComponent(proc)+'id=5';
	var v=new Date();	
	var page='dress_more_right_area.php?keystring='+encodeURIComponent(keystring)+'&status_send=sending'+'&id='+id+'&name='+encodeURIComponent(name)+'&email='+encodeURIComponent(email)+'&quest='+encodeURIComponent(quest)+'&v='+v.getTime();
	var xmlhttp = getXmlHttp();
	xmlhttp.open("GET", page, true);
	//xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			if(xmlhttp.status == 200) {
    		document.getElementById("right_area").innerHTML=xmlhttp.responseText;
   			}
  		}
	}
	xmlhttp.send(null);
	
}

function RefreshCaptcha(id) {
	var name=document.getElementById("name").value;
	var email=document.getElementById("email").value;
	var quest=document.getElementById("quest_area").value;

	//var params = 'keystring=' + encodeURIComponent(keystring)+'proc'+ encodeURIComponent(proc)+'id=5';
	var v=new Date();	
	var page='dress_more_right_area.php?'+'&id='+id+'&name='+encodeURIComponent(name)+'&email='+encodeURIComponent(email)+'&quest='+encodeURIComponent(quest)+'&v='+v.getTime();
	var xmlhttp = getXmlHttp();
	xmlhttp.open("GET", page, true);
	//xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			if(xmlhttp.status == 200) {
    		document.getElementById("right_area").innerHTML=xmlhttp.responseText;
			ShowSubmenu("more","quest",95,255,20);
   			}
  		}
	}
	xmlhttp.send(null);
}

/*---------------------------- ÍÀÂÈÃÀÖÈß ÏÎ ÊÀÒÀËÎÃÓ ------------------------------*/
var id_current_show_model=0;
var models=new Array();
var cmodel=0;
var p=1;
var href;
var next_id;
var previous_id;
var last_page;
var status_message=0;

var memory_href;
var memory_id;




function ShowModel(id) {
id_current_show_model=id;

if (memory_href==href){memory_id=id; }
	for (c in models) {	if(models[c]==id) {cmodel=c;}}
	var v=new Date();	
	var page='dress_more_right_area.php?id='+id+'&v='+v.getTime();
	var xmlhttp = getXmlHttp();
	xmlhttp.open('GET', page, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			if(xmlhttp.status == 200) {
    		document.getElementById("right_area").innerHTML=xmlhttp.responseText;
   			}
  		}
	}
	xmlhttp.send(null);


}


function ShowCatalog(href0,start_model) {
href=href0;
var proc_value=GetVarOfHref(href,"proc");
if (proc_value==false) {memory_href=href;}

	var v=new Date();	
	var page='catalog2.php?'+href+'&v='+v.getTime();
	var xmlhttp = getXmlHttp();
	xmlhttp.open('GET', page, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			if(xmlhttp.status == 200) {
    		document.getElementById("all_catalog").innerHTML=xmlhttp.responseText;
				if (document.getElementById("special_offer_text")) {
				document.getElementById("catalog").style.top=+document.getElementById("special_offer_text").offsetHeight+150+"px";
				//alert(document.getElementById("root").style.height+"/"+document.getElementById("div_bottom").style.height);
				document.getElementById("root").style.height=document.getElementById("special_offer_text").offsetHeight+1100+"px";
				document.getElementById("div_bottom").style.height=document.getElementById("special_offer_text").offsetHeight+1100+"px";
				//alert(document.getElementById("root").style.height+"/"+document.getElementById("div_bottom").style.height);
				}
			count_of_selected();
   			}
  		}
	}
	xmlhttp.send(null);
GetModels(href,start_model);

}


function GetModels(href0,start_model) {
href=href0;
var proc_value=GetVarOfHref(href,"proc");
if (proc_value==false) {memory_href=href;}
	var v=new Date();	
	
	var page='getmodels.php?'+href+'&v='+v.getTime();

	var xmlhttp = getXmlHttp();
	xmlhttp.open('GET', page, true);	
	xmlhttp.onreadystatechange = function() {
	
		if (xmlhttp.readyState == 4) {
		
			if(xmlhttp.status == 200) {
		//alert("/"+xmlhttp.responseText+"/");
    		eval(xmlhttp.responseText);
			
			models.pop();		
				if (id_current_show_model!=0) {
					if(start_model=="") {start_model=models[0];}
					
						ShowModel(start_model);
				}
			//alert("GetModels\n page "+page+"\n "+xmlhttp.responseText);			
   			}
  		}
	}
	xmlhttp.send(null);

}

function GetVarOfHref(string_href,name_of_var) {
var href_array=string_href.split("&");
var value;
	for (c in href_array) {
	vars_array=href_array[c].split("=");
		if (vars_array[0]==name_of_var) {
		value=vars_array[1];
		break;
		}
	}
if (value) {return value;}
else {return false;}
}

function SetVarOfHref(string_href,name_of_var,new_value) {
var href_array=string_href.split("&");
var value;
	for (c in href_array) {
	vars_array=href_array[c].split("=");
		if (vars_array[0]==name_of_var) {
		value=vars_array[1];
		vars_array[1]=new_value;
		href_array[c]=vars_array.join("=");
		string_href=href_array.join("&");
		}
	}
	if (value) {return string_href;}
	else {
	href_array.push(name_of_var+"="+new_value);
	string_href=href_array.join("&");
	return string_href;
	}
}

function NextModel() {
if (cmodel<models.length-1) {
cmodel++;
ShowModel(models[cmodel]);
} 

else {

current_p=GetVarOfHref(href,"p");

	if (current_p) {
	current_p=parseInt(current_p);
		if(current_p<last_page) {
		p=current_p;
		p++;
		}
		if(current_p<last_page) {
		cmodel=0;
		href=SetVarOfHref(href,"p",p);
		ShowCatalog(href,next_id);
		}
	}else {p=2;}
	
}


}

function PreviousModel() {
//alert(cmodel);
if (cmodel>0) {

cmodel--;
ShowModel(models[cmodel]);
} else {
current_p=GetVarOfHref(href,"p");
	if (current_p) {p=parseInt(current_p);p--;}
	else {p=1;}
	
	if (p>=1) {
	cmodel=models.length-1;
	href=SetVarOfHref(href,"p",p);
	ShowCatalog(href,previous_id);	
	}

}
}

function LastModel() {
cmodel=models.length-1;
ShowModel(models[cmodel]);
}

function StartModel() {
cmodel=0;
ShowModel(models[cmodel]);
}

/* ----------------------------------------------------------------------------------*/



function get_cookie(name){
cookie_name = name + "=";
cookie_length = document.cookie.length;
cookie_begin = 0;
	while (cookie_begin < cookie_length){
	value_begin = cookie_begin + cookie_name.length;
		if (document.cookie.substring(cookie_begin, value_begin) == cookie_name){
		var value_end = document.cookie.indexOf (";", value_begin);
			if (value_end == -1){
			value_end = cookie_length;
			}
		return unescape(document.cookie.substring(value_begin, value_end));
		}
	cookie_begin = document.cookie.indexOf(" ", cookie_begin) + 1;
		if (cookie_begin == 0){break;}
	}
return null;
}


function set_cookie(name, value, expires){
	if (!expires){expires = new Date();}
document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() +  "; path=/";
}


function add_to_favorites(id) {
var name = "salonmechta";
document.getElementById("span_favorites").style.fontWeight="bold";
var oldcookie=get_cookie("salonmechta");
	if (oldcookie) {
	oldcookie=oldcookie.split("/");
	var exist=0;
		for (c in oldcookie) {
			if (oldcookie[c]==id) {exist=1;break;}
		}
	if (exist!=1) {
	oldcookie.push(id);
	var newcookie=oldcookie.join("/");
	}
} else {newcookie=id;}
if (exist!=1) {
expires = new Date(); 
expires.setTime(expires.getTime() + (1000 * 86400 * 365)); 
set_cookie(name, newcookie, expires); 
count_of_selected();
}
}


function view_favorites() {
 var current_cookie=get_cookie("salonmechta");
 if (current_cookie) { 
	var v=new Date();	
	href='page=catalog&proc=select&ids='+current_cookie;
	ShowCatalog(href,"");
}
}



function clear_favorites() {
document.getElementById("span_favorites").style.fontWeight="normal";
var oldcookie=get_cookie("salonmechta");
	if (oldcookie) {
	set_cookie("salonmechta", "", "");
	}

ReturnToCatalog();
}



function ReturnToCatalog() {
	/*if (href) {
		if (id_current_show_model!=0 && models.length>0) {
		start_model=models[cmodel];
		} else {start_model="";}*/
	ShowCatalog(memory_href,memory_id);
	//}
}


function count_of_selected() {
 var oldcookie=get_cookie("salonmechta");
 if (oldcookie) { 
 oldcookie_array=oldcookie.split("/");
document.getElementById("count_of_selected").innerHTML=oldcookie_array.length;
//document.getElementById("count_of_selected").href="view.php?page=catalog&proc=select&ids="+oldcookie;
} else {document.getElementById("count_of_selected").innerHTML=0;}
}


var previousdiv="";


function ShowSubmenu(id,idshow,minheight,maxheight,step) {
if (document.getElementById("msg")) {
document.getElementById("msg").outerHTML="";
}
	var px=new RegExp("px","i");
	var submenu=document.getElementById(id);
	var heightpx=submenu.style.height;
	var height=parseInt(heightpx.replace(px,""));


	
		if (height==maxheight) {
			if (idshow==previousdiv) {
			document.getElementById("more1").style.display="none";
			document.getElementById("quest").style.display="none";	
			Expand(id,minheight,"narrow",step);
			}	else {
				if (idshow=="quest") {
				document.getElementById("more1").style.display="none";
				document.getElementById("quest").style.display="block";
				previousdiv="quest";
				} else {
				document.getElementById("quest").style.display="none";		
				document.getElementById("more1").style.display="block";	
				previousdiv="more1";
				}
			}
		}
		if (height==minheight) {
		Expand(id,maxheight,"expand",step);
			if (idshow=="quest") {
			document.getElementById("more1").style.display="none";
			document.getElementById("quest").style.display="block";
			previousdiv="quest";
			} else {
			document.getElementById("quest").style.display="none";		
			document.getElementById("more1").style.display="block";	
			previousdiv="more1";
			}
		}
}

function Expand(id,mheight,direction,step) {
var submenu=document.getElementById(id);
var heightpx=submenu.style.height;

var px=new RegExp("px","i");
var height=heightpx.replace(px,"");
height=parseInt(height); 


if (height<mheight && direction=="expand") {
height=height+step;
heightpx=height+"px";
submenu.style.height=heightpx;
setTimeout('void Expand("'+id+'",'+mheight+',"'+direction+'",'+step+');', 1);
}
else {//alert(height);
}
if (height>mheight && direction=="narrow") {
height=height-step;
heightpx=height+"px";
submenu.style.height=heightpx;
setTimeout('void Expand("'+id+'",'+mheight+',"'+direction+'",'+step+');', 1);
}
if (height==mheight && direction=="narrow") {}
}