var xmlHttp;
var divtag;

function validajax (thestring, thediv, thetype, themin, themax, thefield) {
	// thestring = the string to be validated
	// thediv = the div tag to be updated with response
	// thetype = type of validation ("username", "password", "email")
	// themin = minimum number of characters allowed (0 = blank)
	// themax = maximum number of characters allowed (0 = unlimited)
	// thefield = database field if any
	
	// Set default values for optional fields
	themin = themin || 0;	
	themax = themax || 0;
	thefield = thefield || "";
	
	// Set the global variable divtag to the div to be updated (fix for stateChanged limitation)
	divtag = thediv;
	
	// Get XML HTTP Object
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp===null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	// generate URL
	var url="http://www.imphenzia.com/common/validajax.php";								// name of php file for processing	
	url=url+"?sid="+Math.random();							// generate a random querystring to get away from caching problems
	url=url+"&thestring="+thestring;						// submit the string to be validated	
	url=url+"&thetype="+thetype;							// submit the type of validation	
	url=url+"&themin="+themin;								// submit the minimum number of characters validation	
	url=url+"&themax="+themax;								// submit the maximum number of characters of validation		
	if (thefield != "") {url=url+"&thefield="+thefield;}	// submit database field if any
	
	// Carry out the ajax operation
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=stateChanged;	
	xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp.setRequestHeader("Cache-Control", "no-cache"); 	
	xmlHttp.send(null);	
}

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

