/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}


/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

/*
	Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue)	{
			listElement.selectedIndex = i;
		}
	}	
}



function az_09(alphane)
{
	var numaric = alphane;
		for(var j=0; j<numaric.length; j++)
		{
				  var alphaa = numaric.charAt(j);
				  var hh = alphaa.charCodeAt(0);
				  if((hh > 47 && hh<59) ||  (hh > 96 && hh<123) || hh==95 )
				  {	  }		else	{
                   alert("Only a-z,0-9 and _ are valid.");
					 return false;
				  }
		}
  return true;
}
function az09(alphane)
{
	var numaric = alphane;
		for(var j=0; j<numaric.length; j++)
		{
				  var alphaa = numaric.charAt(j);
				  var hh = alphaa.charCodeAt(0);
				  if((hh > 47 && hh<59) ||  (hh > 96 && hh<123))
				  {	  }		else	{
                   alert("Only a-z and 0-9 are valid.");
					 return false;
				  }
		}
  return true;
}

function azAZ(alphane)
{
	var numaric = alphane;
		for(var j=0; j<numaric.length; j++)
		{
				  var alphaa = numaric.charAt(j);
				  var hh = alphaa.charCodeAt(0);
				  if((hh > 64 && hh<91) ||  (hh > 96 && hh<123) )
				  {	  }		else	{
                   alert("Only a-z and A-Z are valid.");
					 return false;
				  }
		}
  return true;
}

function azAZspacedot_09(alphane)
{
	var numaric = alphane;
		for(var j=0; j<numaric.length; j++)
		{
				  var alphaa = numaric.charAt(j);
				  var hh = alphaa.charCodeAt(0);
				  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==46 || hh==95 || hh==32 )
				  {	  }		else	{
                   alert("Only a-z,A-Z,0-9, . sapce and _ are valid .");
					 return false;
				  }
		}
  return true;
}

function azAZSpace(alphane)
{
	var numaric = alphane;
		for(var j=0; j<numaric.length; j++)
		{
				  var alphaa = numaric.charAt(j);
				  var hh = alphaa.charCodeAt(0);
				  if((hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==32 )
				  {	  }		else	{
                   alert("Only a-z,A-Z and sapce are valid .");
					 return false;
				  }
		}
  return true;
}


function numeric(alphane)
{
	var numaric = alphane;
	if(numaric.length < 9 )
	{
	alert("Enter valid Phone no .");
					 return false;
	}
		for(var j=0; j<numaric.length; j++)
		{
				  var alphaa = numaric.charAt(j);
				  var hh = alphaa.charCodeAt(0);
				  if((hh > 47 && hh<59) ||  hh==32 )
				  {
				  	
				  }		
				   else	
				   {
                   alert("Enter valid Phone no .");
					 return false;
				  }
				  
		}
   return true;
}	
function pincode(alphane)
{
	var numaric = alphane;

		for(var j=0; j<numaric.length; j++)
		{
				  var alphaa = numaric.charAt(j);
				  var hh = alphaa.charCodeAt(0);
				  if((hh > 47 && hh<59) ||  hh==32 )
				  {
				  	
				  }		
				   else	
				   {
                   alert("Enter valid Postal Code/Zip Code.");
					 return false;
				  }
				  
		}
		 return true;
  
}
function areacode(alphane)
{
	var numaric = alphane;

		for(var j=0; j<numaric.length; j++)
		{
				  var alphaa = numaric.charAt(j);
				  var hh = alphaa.charCodeAt(0);
				  if((hh > 47 && hh<59) ||  hh==32 )
				  {
				  	
				  }		
				   else	
				   {
                   alert("Enter valid Area Code.");
					 return false;
				  }
				 
		}
		  return true;
  
}


function checkNumberPhone(txtbox)
{
	alphane=txtbox.value;
	
	var numaric = alphane;
		for(var j=0; j<numaric.length; j++)
		{
				  var alphaa = numaric.charAt(j);
				  var hh = alphaa.charCodeAt(0);
				  if((hh > 47 && hh<59) ||  hh==32 ||  hh==43 ||  hh==44 || hh==45)
				  {	  }		else	{
                   alert('Only [0-9  +  - , sapce ]  are valid .');
				  txtbox.value="";
					 return false;
				  }
				 
		}
   return true;
}	
/*
	Email
*/

function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID");
		   return false;
		}
		
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
 		 return true;				
	} 


/*
	Ajax
*/
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;
}
////////////////////////////////////
function stateChanged() 
{ if (xmlHttp.readyState==4){ 
document.getElementById("city").innerHTML=xmlHttp.responseText;
}
}

function showCity(str)
{
if (str.length==0)
  { 
  document.getElementById("city").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="../../citytownvillage.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
//alert(url);
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

////////////////////////////////////


function showCityTextBox(str)
{ 
  if(str=="-1"){
	 document.getElementById("txtCity").style.display='block';
    } else {
	 document.getElementById("txtCity").style.display='none';	
	}
}

function showOrganisationCatTextBox(str)
{ 
  if(str=="-1"){
	 document.getElementById("txtOrganisationCat").style.display='block';
    } else {
	 document.getElementById("txtOrganisationCat").style.display='none';	
	}
}

function rowsPerPage(str) {
	window.location.href = 'index.php?view=list&rows=' + str;
}