/***********************************************************************************************************
1. function selectCountry(obj, page)
2. function selectState(obj, page, country)
3. function checkemail(str)
4. function trimspaces(s)
************************************************************************************************************/
function selectCountry(obj, page)
{
	checkIn=document.form1.movein.value;
	checkOut=document.form1.moveout.value;
	location.href=page+"?aptCountry="+obj.value+"&movein="+checkIn+"&moveout="+checkOut;
}

function selectState(obj, page, country)
{
	checkIn=document.form1.movein.value;
	checkOut=document.form1.moveout.value;
	location.href=page+"?aptCountry="+country+"&aptState="+obj.value+"&movein="+checkIn+"&moveout="+checkOut;
}

function selectAdminCountry(obj, page)
{
	aptTitle=document.form1.aptTitle.value;
	aptDescription=document.form1.aptDescription.value;
	aptAddress=document.form1.aptAddress.value;
	location.href=page+"?aptCountry="+obj.value+"&aptTitle="+aptTitle+"&aptDescription="+aptDescription+"&aptAddress="+aptAddress;
}

function selectAdminState(obj, page, country)
{
	aptTitle=document.form1.aptTitle.value;
	aptDescription=document.form1.aptDescription.value;
	aptAddress=document.form1.aptAddress.value;
	location.href=page+"?aptCountry="+country+"&aptState="+obj.value+"&aptTitle="+aptTitle+"&aptDescription="+aptDescription+"&aptAddress="+aptAddress;
}
// Proper Email Validation
function checkemail(str)
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1)
		return false;
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		return false;
	if (str.indexOf(at,(lat+1))!=-1)
		return false;
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		return false;
	if (str.indexOf(dot,(lat+2))==-1)
		return false;
	if (str.indexOf(" ")!=-1)
		return false;
	return true;
}

// Removing heading and trailing spaces from a form field.
function trimspaces(s)
{
	while((s.indexOf(' ',0) == 0) && (s.length > 1))
	{
		s = s.substring(1,s.length);
	}
	while((s.lastIndexOf(' ') == (s.length - 1) && (s.length > 1)))
	{
		s = s.substring(0,(s.length - 1));
	}
	if((s.indexOf(' ',0) == 0) && (s.length == 1)) s = '';
	return s;
}

// Start of AJAX
var xmlHttp
function showState(str)
{
	if (str.length==0)
	{
		document.getElementById("aptState").innerHTML="---- Select ----";
		return false;
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
  {
		alert ("Your browser does not support AJAX!");
		return false;
	}
	var url="selectRegion.php";
	url=url+"?aptState="+str.value;
	//alert (url);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.send(null);
}

function stateChanged()
{
	if (xmlHttp.readyState==4)
	{
		document.getElementById("aptState").innerHTML=xmlHttp.responseText;
	}
}

function showCity(str)
{
	if (str.length==0)
	{
		document.getElementById("aptCity").innerHTML="---- Select ----";
		return false;
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
  {
		alert ("Your browser does not support AJAX!");
		return false;
	}
	var url="selectRegion.php";
	url=url+"?aptCity="+str.value;
	//alert (url);
	xmlHttp.onreadystatechange=cityChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.send(null);
}

function cityChanged()
{
	if (xmlHttp.readyState==4)
	{
		document.getElementById("aptCity").innerHTML=xmlHttp.responseText;
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
  {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
  }
	catch (e)
  {
		// Internet Explorer
		try
    {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
	  catch (e)
    {
		  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
	return xmlHttp;
}
// End of AJAX