// JavaScript Document
var xmlHttp;
var oXMLHttp;
var ooXMLHttp;
var rxmlHttp;

function showHint(str){
	//** *********************************************************************** **//
	//** 08/20/2009															     **//
	//** THIS FUNCTION IS BEING USED BY createAccount2.php and update.php. 		 **//
	//** BECAUSE update.php ISN'T IN THE ROOT DIRECTORY HAVE TO FIGURE OUT	 	 **//
	//** WHICH SCRIPT IS CALLING THIS FUNCTION BECAUSE OF THE PATH TO THE FILE   **//
	//** getAvailability.php. IF CALLING SCRIPT IS update.php PATH TO 			 **//
	//** availability.php NEEDS TO BE PREPENDED WITH ../../					     **//
	//** *********************************************************************** **//
	
	var filename = location.href.substring(location.href.lastIndexOf('/')+1); //get filename
	
	var parts = filename.split('?'); //explode file name on question mark	
	if(parts[0] == 'update.php'){ //script is called from update.php page. Prepend ../../
		var dir = '../../';	
	}else{
		var dir = '';
	}
	//alert(parts[0]);
	if (str.length == 0){ 
  		document.getElementById("txtHint").innerHTML="";
		document.getElementById('uName').focus();
		document.getElementById('uName').value = '';
		return;
  	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	var url= dir + "getAvailability.php";
	url=url+"?q="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}//end function

function stateChanged() { 
	
	if (xmlHttp.readyState == 4){ 
		document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
		var obj = document.getElementById("txtHint").innerHTML;
		if(document.getElementById("uName").value != ''){
			var str = document.getElementById("uName").value;
			var len = str.length;			
			if(str.indexOf(".") < 1 || str.indexOf("@") < 1 || str.charAt(len-1) == '.'){
				document.getElementById("uName").value = '';
				document.getElementById("uName").focus();
			}//end if
		}//end if			
		
		if(obj.length > 0){
			document.getElementById("uName").focus();				
		}
	}
}//end function

//////////////////////////////////////////////
//display county on change (createAccount.php)
//////////////////////////////////////////////
function showCounty(ct){
	var filename = location.href.substring(location.href.lastIndexOf('/')+1); //get filename
	
	var parts = filename.split('?'); //explode file name on question mark	
	if(parts[0] == 'update.php'){ //script is called from update.php page. Prepend ../../
		var dir = '../../';	
	}else{
		var dir = '';
	}//end if/else
	
	
	if (ct.length==0){ 
  		document.getElementById("countyBox").innerHTML="";
		return;
  	}
	oXMLHttp=GetXmlHttpObject();
	if (oXMLHttp==null){
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	var url=dir +"getCounty.php";
	url=url+"?county="+ct;
	url=url+"&sid="+Math.random();
	oXMLHttp.onreadystatechange = countyStateChanged;
	oXMLHttp.open("GET",url,true);
	oXMLHttp.send(null);	
	
	//region drop down
	var regionURL="getRegion.php";
	regionURL=regionURL+"?county="+ct;
	regionURL=regionURL+"&sid="+Math.random();
	ooXMLHttp.onreadystatechange = countyStateChanged;
	ooXMLHttp.open("GET",url,true);
	ooXMLHttp.send(null);	
	//alert(ct);
	
	if(ct == "NC"){
		document.getElementById('county').style.display = "";
		document.getElementById('regionRow').style.display = "";
	}else{
		document.getElementById('county').style.display = 'none';
		document.getElementById('regionRow').style.display = 'none';
		//document.getElementById('tempID').style.display = 'none';
		document.forms.createAccount.HomeCounty.value = '';
	}//end else		
}//end function


function countyStateChanged() { 
	if (oXMLHttp.readyState==4 || oXMLHttp.readyState == 'complete'){ 
		document.getElementById("countyBox").innerHTML=oXMLHttp.responseText;
	}//end if
}//end function


//////////////////////////////////////////////////////////
///// show appropriate region on home county change //////
//////////////////////////////////////////////////////////
function showRegion(reg){
	var filename = location.href.substring(location.href.lastIndexOf('/')+1); //get filename
	
	var parts = filename.split('?'); //explode file name on question mark	
	if(parts[0] == 'update.php'){ //script is called from update.php page. Prepend ../../
		var dir = '../../';	
	}else{
		var dir = '';
	}
	//alert(parts[0]);
	
	
	document.getElementById('regionRow').style.display = "";
	//if (reg.length==0){ 
  		//document.getElementById("region").innerHTML="";
		//return;
  	//}
	rxmlHttp=GetXmlHttpObject();
	if (rxmlHttp==null){
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	var url=dir + "getRegion.php";
	url=url+"?r="+reg;
	url=url+"&sid="+Math.random();
	rxmlHttp.onreadystatechange = regionChanged;
	rxmlHttp.open("GET",url,true);
	rxmlHttp.send(null);
	//alert (url);
}//end function

function regionChanged() { 
	if (rxmlHttp.readyState==4){ 	
		document.getElementById("region").innerHTML=rxmlHttp.responseText;	
	}//end if
}//end function



function GetXmlHttpObject(){
	var xmlHttp=null;
	var oXMLHttp=null;
	//var rxmlHttp=null;
		
	try{
  		// Firefox, Opera 8.0+, Safari
  		xmlHttp=new XMLHttpRequest();
		oXMLHttp=new XMLHttpRequest();
		ooXMLHttp=new XMLHttpRequest();
		rxmlHttp=new XMLHttpRequest();
	}//end try
	catch (e){
  		// Internet Explorer
  		try{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			oXMLHttp=new ActiveXObject("Msxm12.XMLHTTP");
			ooXMLHttp=new ActiveXObject("Msxm12.XMLHTTP");
			rxmlHttp=new ActiveXObject("Msxm12.XMLHTTP");
			
    	}//end try
  		catch (e){
    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			oXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
			ooXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
			rxmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			
    	}//end catch
 	}//end catch
	return xmlHttp;
	return oXMLHttp;
	return ooXMLHttp;
	return rxmlHttp;
	
}//end function

///////////////////////////////////
function stopIt(str){
	var myRe = str;
	if(myRe.match(/%/) || myRe.match(/_/) || myRe.match(/&/)){
		alert("Can't use special characters");
		document.getElementById('kw').value = "";		
	}//end if
	
}//end function

///////////////////////////////////



