function trim(str){
   return(trimExt(str,' '));	
}

function trimExt(str,ch){
   if(str == null) return(null);
   	
   var start = 0,end = 0; 
   var i = 0;
   while(i<str.length){
   	  if(str.charAt(i) == ch){
   	  	i++;
   	  }else{
   	    start = i;
   	    break;
   	  }
   }
   
   i = str.length -1;
   while(i>=0){
   	  if(str.charAt(i) == ch){
   	  	i--;
   	  }else{
   	    end = i + 1;
   	    break;
   	  }
   }   
   
   return(str.substring(start,end));
}


function CheckText(theText)
{
if (theText.value == "Enter text here")
alert("Please enter the term to search for!");
return false;
return true;
}

function ClearText(theText) 
{
 if (theText.value =="Enter text here"  )
 {
         theText.value = ""
     }
	 theText.select();
 }
function FillText(theText)
{
	if (theText.value=="")
		{
		theText.value="Enter text here"
		}
}

function popup()
{
 my_window = window.open("/feedbackform.php",
    "gyp_feedback","status=1,width=350,height=150");
}

function checkValues()
{
	if(trim(document.frmSubmit.txtName.value) == "")
	{
		alert('Please input a company name.');
		document.frmSubmit.txtName.focus();
		return false;
	}
	if(document.frmSubmit.lstCompanyType.value == 0)
	{
		alert('Please select your company type.');
		document.frmSubmit.lstCompanyType.focus();
		return false;
	}
	if(trim(document.frmSubmit.txtStreet.value) == "")
	{
		alert('Please input a byelane or street name where your office is situated.');
		document.frmSubmit.txtStreet.focus();
		return false;
	}
	if(trim(document.frmSubmit.txtLocality.value) == "")
	{
		alert('Please enter the name of your locality.');
		document.frmSubmit.txtLocality.focus();
		return false;
	}
	if(trim(document.frmSubmit.txtEmail.value) == "")
	{
		alert('Please enter the name of your locality.');
		document.frmSubmit.txtEmail.focus();
		return false;
	}
	if(trim(document.frmSubmit.txtPhone1.value) == "" &&
		   trim(document.frmSubmit.txtPhone2.value) == "" &&
		   trim(document.frmSubmit.txtMobile.value) == "")
	{
		alert('Please enter atleast one phone number'); 
		document.frmSubmit.txtPhone1.focus();
		return false;
	}
	if(!document.frmSubmit.chkTerms.status)
	{
		alert('Please agree to abide by our terms and conditions');
		document.frmSubmit.chkTerms.focus();
		return false;
	}
return true;
}


function isNumber(e)
{
var keynum
var keychar
var numcheck
if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)
numcheck = /\d/
return numcheck.test(keychar)
}

var xmlHttp;
//Function to show state names
function showStates(str)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request");
		 return;
	 }
	 
	var url="showstates.php";
	url=url+"?q="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

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


//Function to show district names
function showDistricts(str)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request");
		 return;
	 }
	 
	var url="showdistricts.php";
	url=url+"?q="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

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



//Function to show names
function showNames(str)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request");
		 return;
	 }
	 
	var url="shownames.php";
	url=url+"?q="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=nameChanged ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function nameChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("txtNames").innerHTML=xmlHttp.responseText;
 } 
}


//Function to show hints
function showHints(str)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request");
		 return;
	 }
	 
	var url="showhints.php";
	url=url+"?q="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=hintChanged ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function hintChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
 } 
}

//Function to load company info
function loadInfo(str)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request");
		 return;
	 }
	 
	var url="loadinfo.php";
	url=url+"?q="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=nameClicked ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function nameClicked() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("txtLoad").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;
}
