function getXmlHttpRequestObject(){
	try{
		// Firefox, Opera 8.0+, Safari
		return new XMLHttpRequest();
	}
	catch(e){
		// Internet Explorer
		try{
			return new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e){
			try{
				return new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				alert("Your browser does not support AJAX!");
				return false;
			}
		}//end catch
	}//end catch
}//end function

var xmlRequest = getXmlHttpRequestObject();

function checkUserName(fieldTest,fieldName,type){
	var nameField = document.getElementById(fieldTest);
	var phpPath = "";
	switch(type){
		case "1"://from admin/setting
			phpPath = "../../../scripts/ajax-username.php?name="+nameField.value+"&sid="+Math.random();
		break;
		case "2"://from frontend
			phpPath = "../scripts/ajax-username.php?name="+nameField.value+"&sid="+Math.random();
		break;
	}//end switch
	xmlRequest.open("GET",phpPath,true);
	xmlRequest.onreadystatechange = function(){
		if(xmlRequest.readyState == 4 && xmlRequest.status == 200) { // Complete
			var returnResult = xmlRequest.responseText;
			if(returnResult == "empty"){				
				nameField.value = "";
				document.getElementById(fieldName).value = "";
				document.getElementById("showusername").innerHTML = "";
			}
			else if(returnResult == "0"){				
				document.getElementById(fieldName).value = nameField.value;
				document.getElementById("showusername").innerHTML = nameField.value;
			}
			else{
				window.alert("User Name is duplicate");
				nameField.value = "";				
				document.getElementById(fieldName).value = "";
				document.getElementById("showusername").innerHTML = "";
			}
		}//end if
		
	}//end function
	xmlRequest.send(null);
}//end function