var ajaxRequest;
var newwindow=null;
function GetXmlHttpObject(handler) { 
	var objXmlHttp=null

	if (navigator.userAgent.indexOf("Opera")>=0) {
		alert("This example doesn't work in Opera") 
		return; 
	}
	if (navigator.userAgent.indexOf("MSIE")>=0)	{ 
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP"
		} 
		try	{ 
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler 
			return objXmlHttp
		} catch(e) { 
			alert("Error. Scripting for ActiveX might be disabled") 
			return;
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0) {
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler 
		return objXmlHttp
	}
}

function _doOpen(id)
{
	var url="intermediate_chat.php?toid="+id;
	xmlHttp = GetXmlHttpObject(ReturnSubchat)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)	
}

function ReturnSubchat() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		var arr=Array;
		var arr =xmlHttp.responseText.split("|");
		var title=arr[0];
		var toid=arr[1];
		var fromid=arr[2];
		var url='chat.php?chat_id='+title+'&toid='+toid+'&fromid='+fromid+'&type='+arr[3];
		
		var width = 480;
    	var height = 450;
		var left = parseInt((screen.availWidth/2) - (width/2));
   		var top = parseInt((screen.availHeight/2) - (height/2));		
		
		newwindow=window.open(url,title,'width=480,height=450,location=no,menubar=no,scrollbars=no,toolbar=no,resizable=no,fullscreen=no,left='+left+',top='+top+'screenX='+left+',screenY=' + top);
		//if(window.focus) 
		newwindow.focus();
	}	
}

function _doCheckChat()
{
	setInterval("doOpenChat()", 5000);
}

function doOpenChat()
{
  	var url="chatmessage.php";
	xmlHttp = GetXmlHttpObject(ReturnOpenChat)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
}

function ReturnOpenChat() {

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		
		var arr=Array;
		arr =xmlHttp.responseText.split("|");
		var title=arr[0];
		var toid=arr[1];
		var fromid=arr[2];
		if(arr[4]>0)
		{
			var url='chat.php?chat_id='+title+'&toid='+toid+'&fromid='+fromid+'&type='+arr[3];
			if(newwindow==null || newwindow.closed)
			{
				var width = 480;
				var height = 450;
				var left = parseInt((screen.availWidth/2) - (width/2));
				var top = parseInt((screen.availHeight/2) - (height/2));				
		
				newwindow=window.open(url,title,'width=480,height=450,location=yes,menubar=no,scrollbars=no,toolbar=no,resizable=yes,fullscreen=no,left='+left+',top='+top+'screenX='+left+',screenY=' + top);
				//if(window.focus) 
			}
			newwindow.focus();
			_doUpdate(title);
		}
	}	

}

function _doUpdate(title)
{
  	var url="chatmsgupdate.php?title="+title;
	xmlHttp = GetXmlHttpObject(ReturnMsg)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
}
function ReturnMsg() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
			//alert('Hurray!');
			//alert(xmlHttp.responseText);
		}
}

function clearChatBox(chatId){
		var url="ajax.clearBox.php?chat_id="+chatId;
		xmlHttp = GetXmlHttpObject(ReturnChatBox)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
	}
function ReturnChatBox() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")  {
			
	}
}

function setSessionValues(values){
		var url="ajax.setSessionValueAdv.php?val="+values;
		xmlHttp = GetXmlHttpObject(ReturnsetSessionValues)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
	}
	
function ReturnsetSessionValues() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById('showAdvs').innerHTML = '';
		document.getElementById('showAdvs').innerHTML = xmlHttp.responseText;		
	}
}

function setsessionDisplayvalue(theValue,tdid,fid){
		var url="ajax.setsessionDisplayvalue.php?theValue="+theValue+"&tdid="+tdid+"&fid="+fid;
		xmlHttp = GetXmlHttpObject(ReturnsetsessionDisplayvalue)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
}
	
function ReturnsetsessionDisplayvalue() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){	
		var responseText = xmlHttp.responseText.split("|");	
		var theId = responseText[1] + "1";
		var style = responseText[0];
		
		if(style == 'none'){ 
			var any = 'Any';			
		}else{ 
			var any = '';
		}
		//alert(responseText[1]);
		if(responseText[1] == "haircolors"){
			var theText = "Hair Color";
		}else if(responseText[1] == "eyecolors"){
			var theText = "Eye Color";
		}else if(responseText[1] == "bodytypes"){
			var theText = "Body Types";
		}else if(responseText[1] == "exercises"){
			var theText = "Exercise";
		}else if(responseText[1] == "politicss"){
			var theText = "Politics";
		}else if(responseText[1] == "smokings"){
			var theText = "Smoking";
		}else if(responseText[1] == "drinkings"){
			var theText = "Drinking";
		}else if(responseText[1] == "ethnicitys"){
			var theText = "Ethnicity";
		}else if(responseText[1] == "religions"){
			var theText = "Religion";
		}else if(responseText[1] == "frequencyofsynagogues"){
			var theText = "Frequency of Synagogue";
		}else if(responseText[1] == "koshers"){
			var theText = "Kosher";
		}else if(responseText[1] == "parentsarejewishs"){
			var theText = "Parents are Jewish?";
		}else if(responseText[1] == "beentoisraels"){
			var theText = "Been to Israel";
		}else if(responseText[1] == "wantchildrens"){
			var theText = "Want Children";
		}else if(responseText[1] == "educations"){
			var theText = "Education";
		}else if(responseText[1] == "salarys"){
			var theText = "Salary";
		}else if(responseText[1] == "relocates"){
			var theText = "Relocate";
		}else if(responseText[1] == "willing_to_make_aliyahs"){
			var theText = "Willing to make Aliyah";
		}	
		
		
		document.getElementById(theId).innerHTML = "<a href=\"javascript:expend('"+responseText[1]+"','"+style+"');\" class=\"gtextB_red\">"+theText+":</a>&nbsp;&nbsp;"+any;		
	}
}



function changeRegion(country,css){
		var url="ajax.changeRegion.php?val="+country+"&css="+css;
		document.getElementById('region').innerHTML = "<img src=\"images/loadingAnimation2.gif\" width=\"20\" height=\"20\" />";
		xmlHttp = GetXmlHttpObject(ReturnchangeRegion)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
	}
	
function ReturnchangeRegion() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		//alert(xmlHttp.responseText);
		document.getElementById('region').innerHTML = '';
		document.getElementById('region').innerHTML = xmlHttp.responseText;		
	}
}

function changeSearchRegion(country){
		var url="ajax.changeSearchRegion.php?val="+country;
		document.getElementById('regions').innerHTML = "<img src=\"images/loadingAnimation2.gif\" width=\"20\" height=\"20\" />";
		xmlHttp = GetXmlHttpObject(ReturnchangeSearchRegion)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
	}
	
function ReturnchangeSearchRegion() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		//alert(xmlHttp.responseText);
		document.getElementById('regions').innerHTML = '';
		document.getElementById('regions').innerHTML = xmlHttp.responseText;		
	}
}


