// JavaScript Document
	function trim(pstrString)
	{
		var intLoop=0;
		for(intLoop=0; intLoop<pstrString.length; )
		{
			if(pstrString.charAt(intLoop)==" ")
			{
				pstrString=pstrString.substring(intLoop+1, pstrString.length);
			}
			else
				break;
		}

		for(intLoop=pstrString.length-1; intLoop>=0; intLoop=pstrString.length-1)
		{
			if(pstrString.charAt(intLoop)==" ")
					pstrString=pstrString.substring(0,intLoop);
			else
					break;
		}
	return pstrString;
	}

/////////////////////////////////////////////////   Validate Email   ////////////////////////////////////////
// Email Validation Javascript
// copyright 23rd March 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function validateEmail(addr,man,db) {
	if (addr == '' && man) {
	   if (db) alert('email address is mandatory');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  if (db) alert('email address contains invalid characters');
		  return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  if (db) alert("email address contains non ascii characters.");
		  return false;
	   }
	}

	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('two periods must not be adjacent in email address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('invalid primary domain in email address');
	   return false;
	}
	return true;
}

////////////////////////////////////////////////      End     ///////////////////////////////////////////////

///////////////////////////////////////////// AJAX CODE ///////////////////////////////////////////////////////

	function createRequestObject() {
		var ro;
		var browser = navigator.appName;
		if(browser == "Microsoft Internet Explorer"){
			ro = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			ro = new XMLHttpRequest();
		}
		return ro;
	}

	var http = createRequestObject();
	var httpd = createRequestObject();
	var httpdd = createRequestObject();
	var Frm;
	var Src;
	var Dest;

	function handleResponse1() {
		var idx=0;
		if(http.readyState == 4){
			var response = http.responseText;
			alert(response);
		}
	}

	function handleResponse() {
		var idx=0;
		if(http.readyState == 4){
			var response = http.responseText;
			var update = new Array();
			update = response.split('|');
			var id= new Array();
			var names= new Array();
			var i;
			for(i=0; i<update.length; i++){
				res= update[i].split("*");
				names[i]=res[0];
				id[i] = res[1];
			}
			addToList(Frm, Dest, names, id);
		}
	}



	function addToList(frm, selName, str, id) {
		var ListObj="window.document." + frm + "." + selName;
		var destList = eval(ListObj);
		var indx=0;
		var cnt;
		for(cnt =0; cnt< str.length; cnt++ ){
			destList.options[indx] = new Option(str[indx]);
			destList.options[indx].value=id[indx];
			indx++;
		}
	}

	function deleteFromList(frm, selName) {
		var ListObj="window.document." + frm + "." + selName;
		var destList  = eval(ListObj);
		var len = destList.options.length;
		for(var i = (len-1); i >= 0; i--){
		if ( destList.options[i] != null ){
			destList.options[i] = null;
			}
		}
	}

////////////////////////////////////////////   END   //////////////////////////////////////////////////////////////

////////////////////////////////////////////   POPULATE COUNTRY   //////////////////////////////////////////////////


	function sndReq(continent_id) {
		http.open('get', 'common/populate_country.php?continent_id='+continent_id);
		http.onreadystatechange = handleResponse;
		deleteFromList(Frm, Dest);
		http.send(null);
	}

	function ContinentToCountry(frm, src, dest){
		//alert();
		var getSelectedSrc="document." + frm + "." + src + ".options[document."+ frm+ "." + src + ".selectedIndex].value";
		Frm=frm;
		Src=src;
		Dest=dest
		var continent_id=eval(getSelectedSrc);
		sndReq(continent_id);
	}

////////////////////////////////////////////     END     //////////////////////////////////////////////////



//////////////////////////////////////////// POPULATE COUNTY   ////////////////////////////////////////////

	function sndReq_country(country_id) {
		http.open('get', 'common/populate_county.php?country_id='+country_id);
		http.onreadystatechange = handleResponse;
		deleteFromList(Frm, Dest);
		http.send(null);
	}

	function CountryToCounty(frm, src, dest)
	{
		var getSelectedSrc="document." + frm + "." + src + ".options[document."+ frm+ "." + src + ".selectedIndex].value";
		Frm=frm;
		Src=src;
		Dest=dest
		var country_id=eval(getSelectedSrc);
		sndReq_country(country_id);
	}

////////////////////////////////////////////    END    //////////////////////////////////////////////////

//////////////////////////////////////////// POPULATE CITY   ////////////////////////////////////////////


	function sndReq_city(county_id) {
		http.open('get', 'common/populate_city.php?county_id='+county_id);
		http.onreadystatechange = handleResponse;
		deleteFromList(Frm, Dest);
		http.send(null);
	}

	function CountyToCity(frm, src, dest)
	{
		//County_Enable();
		var getSelectedSrc="document." + frm + "." + src + ".options[document."+ frm+ "." + src + ".selectedIndex].value";
		Frm=frm;
		Src=src;
		Dest=dest
		var county_id=eval(getSelectedSrc);
		sndReq_city(county_id);
	}


////////////////////////////////////////////    END    //////////////////////////////////////////////////

/////////////////////////////////////////////   Add to Short List Message   ////////////////////////////

	function Short_listed(user_id,property_id) {
		http.open('get', 'addtoList.php?user_id='+user_id+'&property_id='+property_id);
		http.onreadystatechange = handleResponse1;
		http.send(null);
	}
////////////////////////////////////////////    END    //////////////////////////////////////////////////

/////////////////////////////////////////////   Add to ms_enquiry   ////////////////////////////

	function ms_enquiry(property_id) {
		window.open('send_enquery.php?propertyid='+property_id,'helpvin','width=450,height=345,top=20,left=40,scrollbars=yes');
		http.onreadystatechange = handleResponse1;
		http.send(null);
	}
/////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////   Populate MyLocation   ////////////////////////////
		function Populate_Mycountry() {
		http.open('get', 'common/populate_mycountry.php');
		http.onreadystatechange = handleResponse;
		http.send(null);
	}

/////////////////////////////////////////////   Display or Hide elements   ////////////////////////////
	function showhide(element, mode)
	  {
	  		if (document.getElementById)
			{
				// this is the way the standards work
				var style2 = document.getElementById(element).style;			
				style2.display = mode;
			}
			else if (document.all)
			{
				// this is the way old msie versions work
				var style2 = document.all[element].style;	
				style2.display = mode;
			}
			else if (document.layers)
			{
				// this is the way nn4 works
				var style2 = document.layers[element].style;	
				style2.display = mode;
			}    
		   
	  }
/////////////////////////////////////////////////////////////////////////////////////////////////////////

	function County(frm,src,dest,Str){	
		
		//alert(Str.name);
		if(Str.checked==true){
			
			showhide('location', 'block');			
			
		//var getSelectedSrc="document." + frm + "." + src + ".options[document."+ frm+ "." + src + ".selectedIndex].value";
		Frm=frm;
		Src=src;
		Dest=dest
		//var county_id=eval(getSelectedSrc);
		//sndReq_city(county_id);
		Populate_Mycountry();
		}
		else{
			deleteFromList(frm, 'cbomycountry');
			showhide('location', 'none');		
		}
	}



/////////////////////////////////////////////////////////////////////////////////////////////////////////


function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	{
		field.value = field.value.substring(0, maxlimit);
	}	
	else // otherwise, update 'characters left' counter
	{
		cntfield.value = maxlimit - field.value.length;
	}
}

function textCounter1(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	{
		field.value = field.value.substring(0, maxlimit);
	}	
	else // otherwise, update 'characters left' counter
	{
		cntfield.value = maxlimit - field.value.length;
	}
}



	function Check_Element(strform,strtype)
	{
		var flag=false;
		for(var i=0; i<strform.elements.length; i++){
			if(strform.elements[i].type==strtype){
				if(strform.elements[i].checked==true){
					flag=true;
				}
			}
		}
		if(flag==true)
			return true;
		else
			return false;
	}

	function isNumeric(strform)
	{
		var characters="0123456789-";
		var tmp;
		var lTag;
		lTag = 0;
		temp = (strform.txtphone.value.length);
		for (var i=0;i<temp;i++){
			tmp=strform.txtphone.value.substring(i,i+1);
			if (characters.indexOf(tmp)==-1){
				lTag = 1;
			}
		}
		if(lTag == 1)
			return false;
		else
			return true;
	}

	function Previous_step(Strform,Strpre){
		Strform.action=Strpre;
		Strform.submit();
	}
	
	function chkimage(image)
	{
		var val = trim(image);
		strlen = val.length;
		strcnt = val.lastIndexOf("\\");
		newstr = val.substr(strcnt+1,strlen);
		tempval = val.toUpperCase();
		val = tempval.substr(val.lastIndexOf("."),val.length);

		if(((val.length==4)&&((val!='.JPG')  &&  (val!='.GIF') &&  (val!='.PNG') )) || ((val.length==5)&&(val!='.JPEG'))){
			return false;
		}
		else{
			return true;
		}
	}

	function imagechange(str){
		document.getElementById("hiddenimages").innerHTML="<img src='"+str+"' height=200 width=300 border='0'>";
	}
	
//////////////////////////////////////////////////////// Language Change ////////////////////////////////////////////////////////////////////////////////////////////

	function ChangeLangusge(Strvalue){
		//alert(Strvalue);
		if(Strvalue=="english"){
			document.frmHeader.action="http://translate.google.com/translate?u=http%3A%2F%2Fwww.simplyhomeexchange.com%2F&langpair=fr%7Cen&hl=en&ie=UTF8";
			document.frmHeader.submit();
		}
		else{
			document.frmHeader.action="http://translate.google.com/translate?u=http%3A%2F%2Fwww.simplyhomeexchange.com%2F&langpair=en%7Cfr&hl=en&ie=UTF8";
			document.frmHeader.submit();
		}
	}

////////////////////////////////////////////////////////  End  ///////////////////////////////////////////////////////////////////////////////////////////////////////
