var request;
var dest;
var query_str;

function ShowHide(elem,pic,minus_pic,plus_pic)
	{
	if(!document.getElementById) return false;
	var iel=$(pic);
	var el=$(elem);

	if (el.style.display=='none')
		{
		display='block';
		src='images/'+minus_pic;
		}
	else{
		display='none';
		src='images/'+plus_pic;
		}
	el.style.display=display;
	return false;
	}
function HideShow(elem)
	{
	if(!document.getElementById) return false;

	if (elem.style.display=='none')
		{
		display='block';
		}
	else{
		display='none';
		}
	elem.style.display=display;
	return false;
	}

function GetRadioGroupValue(radioGroupObj)
	{
	for (var i=0; i < radioGroupObj.length; i++)
	if (radioGroupObj[i].checked) return radioGroupObj[i].value;
	return null;
	}

function GetCheckBoxValue(CheckBoxObj)
	{
	var temp_str="";
	if (CheckBoxObj.length >1)
		{
		for (var i=0; i < CheckBoxObj.length; i++)
			{if (CheckBoxObj[i].checked) temp_str = temp_str + "[" + CheckBoxObj[i].value + "]";}
		}
	else {if (CheckBoxObj.checked) temp_str = "[" + CheckBoxObj.value + "]";}
	return temp_str;
	}

function processStateChange()
	{
	if (request.readyState < 4)$(dest).innerHTML = "Loading...";
	if (request.readyState == 4)
		{
		contentDiv = $(dest);
		if (dest=='state') { contentDiv1 = $('city_place'); }
		if (request.status == 200)
			{
			response = request.responseText;
			contentDiv.innerHTML = response;
			if (dest=='state') { contentDiv1.innerHTML = ''; }
			}
		else
			{
			contentDiv.innerHTML = "Error: Status "+request.status;
			}
		}
	}

function AjaxRequest(URL,query,destination,var1,var2)
	{	//	alert (query);
	var error='';
	if (var2 == 'city' && var1!='other'){error='1';}
	else if (destination=='other_rubric_place')
		{
		if ( $('rubric').value != 'other' )
			{
			$('other_rubric_place').innerHTML='';
			error='1';
			}
		}
	if (error=='')
		{
		dest = destination;
		if (destination=='rubric_place') {URL = URL + escape(query);}
		else URL = URL + query;

		if (window.XMLHttpRequest)
			{
			request = new XMLHttpRequest();
			request.onreadystatechange = processStateChange;
			request.open("GET", URL, true);
			request.send(null);
			}
		else if (window.ActiveXObject)
			{
			request = new ActiveXObject("Microsoft.XMLHTTP");
			if (request)
				{
				request.onreadystatechange = processStateChange;
				request.open("GET", URL, true);
				request.send();
				}
			}
		}
	}

function AjaxPost(URL,page,destination)
	{
	var temp_str="";
	var i;
	dest = destination;

	if	( page =='match' )
		{
		query_str = "&profile_id=" + document.search_form.profile_id.value;
		}
	else if	( page =='personal' )
		{
		query_str = "&newpass1=" + escape(document.profile_form.newpass1.value)
		+ "&newpass2=" + escape(document.profile_form.newpass2.value)
		+ "&new_name=" + escape(document.profile_form.name.value)
		+ "&new_gender=" + GetRadioGroupValue(document.profile_form.gender)
		+ "&new_birthday=" + document.profile_form.birthday.value
		+ "&new_birthmonth=" + document.profile_form.birthmonth.value
		+ "&new_birthyear=" + document.profile_form.birthyear.value
		+ "&new_country=" + document.profile_form.country.value
		+ "&new_state=" + document.profile_form.state.value;

		if(document.profile_form.chpas.checked) query_str = query_str + "&chpas=1";
		if(document.profile_form.delprof.checked) query_str = query_str + "&delprof=1";
		if(document.all.city != null) query_str = query_str + "&new_city=" + document.profile_form.city.value;
		if(document.all.another_city != null) query_str = query_str + "&new_another_city=" + escape(document.profile_form.another_city.value);
		}
	else if ( page =='looking' )
		{
		query_str = "&new_interested_for=" + GetCheckBoxValue(document.profile_form.interested_for)
		+ "&new_his_gender=" + GetCheckBoxValue(document.profile_form.his_gender)
		+ "&new_age_from=" + document.profile_form.age_from.value
		+ "&new_age_to=" + document.profile_form.age_to.value;
		}
	else if ( page =='sex' )
		{
		query_str = "&sex_orient=" + GetRadioGroupValue(document.profile_form.sex_orient)
		+ "&sex_exp=" + GetRadioGroupValue(document.profile_form.sex_exp)
		+ "&sex_often=" + GetRadioGroupValue(document.profile_form.sex_often)
		+ "&sex_vich=" + GetRadioGroupValue(document.profile_form.sex_vich)
		+ "&sex_role=" + GetRadioGroupValue(document.profile_form.sex_role)
		+ "&excited=" + GetCheckBoxValue(document.profile_form.excited);
		}
	else if ( page == 'interests')
		{
		query_str = "&smoke=" + document.profile_form.smoke.value
		+ "&drink=" + document.profile_form.drink.value
		+ "&drugs=" + document.profile_form.drugs.value
		+ "&interests=" + GetCheckBoxValue(document.profile_form.interests)
		+ "&music=" + GetCheckBoxValue(document.profile_form.music);
		}
	else if ( page == 'appearance')
		{
		query_str = "&ethnicity=" + GetRadioGroupValue(document.profile_form.ethnicity)
		+ "&body_type=" + GetRadioGroupValue(document.profile_form.body_type)
		+ "&hair_color=" + GetRadioGroupValue(document.profile_form.hair_color)
		+ "&eye_color=" + GetRadioGroupValue(document.profile_form.eye_color)
		+ "&body_art=" + GetCheckBoxValue(document.profile_form.body_art)
		+ "&height=" + document.profile_form.height.value
		+ "&weight=" + document.profile_form.weight.value;
		}

	URL = URL + "?page=" + page + "&action=save" + query_str;

	if (window.XMLHttpRequest)
		{
		request = new XMLHttpRequest();
		request.onreadystatechange = processStateChange;
		request.open("GET", URL, true);
		request.send(null);
		}
	else if (window.ActiveXObject)
		{
		request = new ActiveXObject("Microsoft.XMLHTTP");
		if (request)
			{
			request.onreadystatechange = processStateChange;
			request.open("GET", URL, true);
			request.send();
			}
		}
	if	( page =='simple_search' ){ShowHide('show_search','search_anc','bminus.gif','bplus.gif');}
	}

function AjaxPostRequest(URL,page,query,destination,user_id)
	{
	var error='',temp_str='',temp_str1='';

	dest = destination;
	query_str ="&page=" + page + query;

	if	( page =='gallery' )
		{
		if (document.gallery_form.title_photo.length >1)
			{			for(var i=0; i < document.gallery_form.title_photo.length; i++){temp_str = temp_str + "[" + escape(document.gallery_form.title_photo[i].value) + "]";}
			}
		if (document.gallery_form.rating_id.length >1)
			{for(var i=0; i < document.gallery_form.rating_id.length; i++){temp_str1 = temp_str1 + "[" + document.gallery_form.rating_id[i].value + "]";}
			}
		query_str = query_str + '&title_photo=' + temp_str + "&rating_id=" + temp_str1 + "&action=save&first_photo=" + GetRadioGroupValue(document.gallery_form.first_photo)
		+ "&del_photo=" + GetCheckBoxValue(document.gallery_form.del_photo);
		}
	else if ( page == 'about_myself')
		{
		query_str =  query_str + "&about_myself=" + escape( document.profile_form.about_myself.value )
		+ "&about_him=" + escape( document.profile_form.about_him.value )
		+ "&occupation=" + document.profile_form.occupation.value
		+ "&education=" + document.profile_form.education.value
		+ "&marital_status=" + GetRadioGroupValue(document.profile_form.marital_status)
		+ "&children=" + GetRadioGroupValue(document.profile_form.children)
		+ "&want_children=" + GetRadioGroupValue(document.profile_form.want_children)
		+ "&religious=" + GetRadioGroupValue(document.profile_form.religious)
		+ "&inhabitation=" + GetRadioGroupValue(document.profile_form.inhabitation)
		+ "&income=" + GetRadioGroupValue(document.profile_form.income)
		+ "&annual_income=" + GetRadioGroupValue(document.profile_form.annual_income)
		+ "&financial_aid=" + GetRadioGroupValue(document.profile_form.financial_aid)
		+ "&languages=" + GetCheckBoxValue(document.profile_form.languages);
		}
	else if ( page == 'complain')
		{
		if ( document.getElementById('reason') )
			{
			if ( document.getElementById('reason').value == 0 ) { error='1'; alert ("Óêàæèòå ïðè÷èíó æàëîáû"); }
			else query_str = query_str + "&reason=" + document.getElementById('reason').value;
			if ( document.getElementById('complain').value=='' ) { error='1'; alert ("Îïèøèòå æàëîáó"); }
			else query_str = query_str + "&complain=" + escape( document.getElementById('complain').value );
			}
		}

	if (error=='')
		{
		if (window.XMLHttpRequest)
			{
			request = new XMLHttpRequest();
			}
		else if (window.ActiveXObject)
			{
			request = new ActiveXObject("Microsoft.XMLHTTP");
			}
		request.onreadystatechange = processStateChange;
		request.open('POST', URL, true);
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=windows-1251");
		request.setRequestHeader("Content-length", query_str.length);
		request.setRequestHeader("Connection", "close");
		request.send(query_str);
		}
	}

function getObject(obj)
	{
	var theObj;
	if(document.all) {if(typeof obj=="string") {return document.all(obj);}
	else {return obj.style;}}
	if(document.getElementById) {
	if(typeof obj=="string"){return document.getElementById(obj);}
	else{return obj.style;}}
	return null;
	}
function Contar(source,dest,texto,caracteres) {
	var sourceObj=getObject(source);
	var destObj=getObject(dest);
	var longitud=caracteres - sourceObj.value.length;
	if(longitud <= 0){
	longitud=0;
	texto='<span style="background-color: rgb(255,206,206)"> '+texto+' </span>';
	sourceObj.value=sourceObj.value.substr(0,caracteres);}
	destObj.innerHTML = texto.replace("{CHAR}",longitud);
	}
function clickGroup(name,value)
	{
	var iel=$('gr'+name);
	var el=$('block'+name);
	if (value!= null){el.style.display=value=='none'?'block':'none';}
	if (el.style.display=='none')
		{
		display='block';
		src='images/minus.gif';
		}
	else{
		display='none';
		src='images/plus.gif';
		}
	el.style.display=display;
	iel.src=src;
	return false;
	}
function menu(elem)
	{
	$('simp').className='pastab';
	$('adv').className='pastab';
	$('meet').className='pastab';
	elem.className='acttab';
	$('srch').innerHTML='<img src=images/loading_ray.gif width=70 height=10 align=center vspace=40>';
	new Ajax.Updater('srch','content/search_tab.php?tb='+elem.id,{method:'post',evalScripts:true});
	}
function PopUp(profile_id)
	{	popUp=window.open('content/mail.php?interlocutor='+ profile_id,'console','width=500,height=700,top=0,left=0,status=0,location=0,menubar=0,resizable=1,scrollbars=0,toolbar=0');
	popUp.focus();
	}

