var xmlHttp
var div
function showAvailability(url,target_div){ 

		div = target_div;
		document.getElementById(div).innerHTML = "<img src='loading.gif'>";
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null){
			alert ("Browser does not support HTTP Request")
			return
		} 
		xmlHttp.onreadystatechange=stateChanged 
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
}

function showAvailability2(url,target_div,val,doc){ 

var format=postit(val);
if(format==false)
{
	//doc.value="";
	return false;
	}
		div = target_div;
		document.getElementById(div).innerHTML = "<img src='loading.gif'>";
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null){
			alert ("Browser does not support HTTP Request")
			return
		} 
		xmlHttp.onreadystatechange=stateChanged 
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
}

function stateChanged(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById(div).innerHTML=xmlHttp.responseText 
		if(xmlHttp.responseText==""){
			document.frmreg.security_code.value = "set";
		}else{	
			document.frmreg.security_code.value = "";
		}
	} 
} 

function GetXmlHttpObject(){ 
	var objXMLHttp=null
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest()
	}else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}

function checkAvailability(url,target_div){ 
		div = target_div;
		document.getElementById(div).innerHTML = "<img src='loading.gif'>";
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null){
			alert ("Browser does not support HTTP Request")
			return
		} 
		xmlHttp.onreadystatechange=stateChangednew 
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
}
function stateChangednew(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById(div).innerHTML=xmlHttp.responseText 
		/*if(xmlHttp.responseText==""){
			document.frmreg.security_code.value = "set";
		}else{	
			document.frmreg.security_code.value = "";
		}*/
	} 
} 

function listone(url,target_div)
{
	
	div = target_div;
		document.getElementById(div).innerHTML = "<img src='loading.gif'>";
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null){
			alert ("Browser does not support HTTP Request")
			return
		} 
		xmlHttp.onreadystatechange=stateChangedhour 
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	}
	
	function stateChangedhour(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById(div).innerHTML=xmlHttp.responseText 
		/*if(xmlHttp.responseText==""){
			document.frmreg.security_code.value = "set";
		}else{	
			document.frmreg.security_code.value = "";
		}*/
	} 
} 

function openTimediv(url,target_div)
{
	div = target_div;
		document.getElementById(div).innerHTML = "<img src='loading.gif'>";
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null){
			alert ("Browser does not support HTTP Request")
			return
		} 
		xmlHttp.onreadystatechange=stateChangedtimings 
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
}

function stateChangedtimings(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById(div).innerHTML=xmlHttp.responseText 
		/*if(xmlHttp.responseText==""){
			document.frmreg.security_code.value = "set";
		}else{	
			document.frmreg.security_code.value = "";
		}*/
	} 
} 

function gettime(url,target_div)
{
	div = target_div;
		document.getElementById(div).innerHTML = "<img src='loading.gif'>";
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null){
			alert ("Browser does not support HTTP Request")
			return
		} 
		xmlHttp.onreadystatechange=stateChangedgettime 
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	}

function stateChangedgettime(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById(div).innerHTML=xmlHttp.responseText 
		/*if(xmlHttp.responseText==""){
			document.frmreg.security_code.value = "set";
		}else{	
			document.frmreg.security_code.value = "";
		}*/
	} 
} 


function postit(val){
	//check postcode format is valid
 test = val; size = test.length
 test = test.toUpperCase(); //Change to uppercase
 while (test.slice(0,1) == " ") //Strip leading spaces
  {test = test.substr(1,size-1);size = test.length
  }
 while(test.slice(size-1,size)== " ") //Strip trailing spaces
  {test = test.substr(0,size-1);size = test.length
  }
 val.value = test; //write back to form field
 if (size < 6 || size > 8){ //Code length rule
  alert(test + " is not a valid postcode"); //- wrong length
  //document.details.pcode.focus();

     return false;
  }
 if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
   alert(test + " is not a valid postcode"); // - cannot start with a number
   //document.details.pcode.focus();
 
    return false;
  }
 if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule
   alert(test + " is not a valid postcode"); // - alpha character in wrong position
   //document.details.pcode.focus();
  
    return false;
  }
 if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   //document.details.pcode.focus();
 
    return false;
  }
 if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
   alert(test + " is not a valid postcode"); // - number in wrong position
   //document.details.pcode.focus();
   
    return false;
  }
 if (!(test.charAt(size-4) == " ")){//space in position length-3 rule
   alert(test + " is not a valid postcode"); // - no space or space in wrong position
   //document.details.pcode.focus();
 
    return false;
   }
 count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
 if (count1 != count2){//only one space rule
   alert(test + " is not a valid postcode"); // - only one space allowed
  // document.details.pcode.focus();
     return false;
  }
alert("Postcode Format OK");
return true;
}
