
function new_window(loc,w,h,para,rs){
	var ww = (screen.width-w)/2;
	var hh = (screen.height-h)/2;
	var newWindow = 		window.open(loc,para,"fullscreen=no,scrollbars=yes,resizable="+rs+",toolbar=no,status=yes,menubar=no,width="+w+",height="+h+",left="+ww+",top="+hh);
}


function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}else{
		return TRIM_VALUE;
	}
} //End Function
function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;
	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	} //End While
	return strTemp;
} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;
	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
}
/*
var xmlhttp = false;
try{
	xmlhttp = new XMLHttpRequest();
}catch(trymicrosoft){
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(othermicrosoft){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(failed){
			xmlhttp = false;
		}
	}
}
*/




function checkUsername(){
	var url = "ajax/checkuser.php?username=" +Trim(document.getElementById("username").value.toUpperCase() );
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange = returnUsername;
	xmlhttp.send(null);
}

function returnUsername(){
	if(xmlhttp.readyState==4){
		if(xmlhttp.status==200){
			var xmldoc = xmlhttp.responseXML;
			var elems = xmldoc.getElementsByTagName("row");
			document.getElementById("divError").style.visibility = "visible";
			
			if (xmlhttp.responseText != "NO"){
				document.getElementById("divError").style.position = "fixed";
			}else{
				document.getElementById("divError").style.position = "absolute";
			}
			
			document.getElementById("divError").innerHTML = xmlhttp.responseText;
		}else if(xmlhttp.status==404){
			alert('Request file not found !');
		}else{
			alert('[returnUsername] Error has occurred with status code : '+ xmlhttp.status);	
		}
	}
}




















/*

function checkEmail(){
	var url = "ajax/checkData.aspx?email=" +document.getElementById("txtEmail").value;
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange = returnEmail;
	xmlhttp.send(null);
}
function returnEmail(){
	if(xmlhttp.readyState==4){
		if(xmlhttp.status==200){
			var xmldoc = xmlhttp.responseXML;
			var elems = xmldoc.getElementsByTagName("row");
			document.getElementById("semail").style.visibility = "visible";
			if (xmlhttp.responseText != ""){
				document.getElementById("semail").style.position = "fixed";
			}else{
				document.getElementById("semail").style.position = "absolute";
			}
			document.getElementById("semail").innerHTML = xmlhttp.responseText;
			
		}else if(xmlhttp.status==404){
			alert('Request file not found !');
		}else{
			alert('[returnEmail] Error has occurred with status code : '+ xmlhttp.status);	
		}
	}
}


*/
//*****************  Reguster ************************//






/*
function getAmphur(){
	imgAmphur.style.visibility = 'visible';
	
	ClearSelect('district');
	AddItem('district','','0');
	
	var province = encodeURIComponent(document.getElementById("province").value);
	
	var url = "ajax/getAddress.aspx?province=" + province ;
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange = returnAmphur;
	xmlhttp.send(null);
}

function returnAmphur(){
	if(xmlhttp.readyState==4){
		if(xmlhttp.status==200){
			var xmldoc = xmlhttp.responseXML;
			var elems = xmldoc.getElementsByTagName("row");
			document.getElementById("span_amphur").innerHTML = xmlhttp.responseText;
			imgAmphur.style.visibility = 'hidden';
		}else if(xmlhttp.status==404){
			alert('Request file not found !');
		}else{
			alert('[returnUsername] Error has occurred with status code : '+ xmlhttp.status);	
		}
	}
}

function getDistrict(){
	imgDistrict.style.visibility = 'visible';
	
	//ClearSelect('village');
	//AddItem('village','','0');
	
	var province = encodeURIComponent(document.getElementById("province").value);
	var amphur = encodeURIComponent(document.getElementById("amphur").value);
	
	var url = "ajax/getAddress.aspx?province=" + province + "&amphur="+amphur;
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange = returnDistrict;
	xmlhttp.send(null);
}

function returnDistrict(){
	if(xmlhttp.readyState==4){
		if(xmlhttp.status==200){
			var xmldoc = xmlhttp.responseXML;
			var elems = xmldoc.getElementsByTagName("row");
			document.getElementById("span_district").innerHTML = xmlhttp.responseText;
			imgDistrict.style.visibility = 'hidden';
		}else if(xmlhttp.status==404){
			alert('Request file not found !');
		}else{
			alert('[returnUsername] Error has occurred with status code : '+ xmlhttp.status);	
		}
	}
}

/*
function getVillage(){
	imgVillage.style.visibility = 'visible';
	
	var province = encodeURIComponent(document.getElementById("province").value);
	var amphur = encodeURIComponent(document.getElementById("amphur").value);
	var district = encodeURIComponent(document.getElementById("district").value);
	
	var url = "ajax/getAddress.aspx?province=" + province + "&amphur="+amphur+"&district="+district;
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange = returnVillage;
	xmlhttp.send(null);
}

function returnVillage(){
	if(xmlhttp.readyState==4){
		if(xmlhttp.status==200){
			var xmldoc = xmlhttp.responseXML;
			var elems = xmldoc.getElementsByTagName("row");
			document.getElementById("span_village").innerHTML = xmlhttp.responseText;
			imgVillage.style.visibility = 'hidden';
		}else if(xmlhttp.status==404){
			alert('Request file not found !');
		}else{
			alert('[returnUsername] Error has occurred with status code : '+ xmlhttp.status);	
		}
	}
}


function getZipcode(){
	
	var province = encodeURIComponent(document.getElementById("province").value);
	var amphur = encodeURIComponent(document.getElementById("amphur").value);
	var district = encodeURIComponent(document.getElementById("district").value);
	//var village = encodeURIComponent(document.getElementById("village").value);
	
	var url = "ajax/getAddress.aspx?province=" + province + "&amphur="+amphur+"&district="+district+"&flag=1";
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange = returnZipcode;
	xmlhttp.send(null);
}

function returnZipcode(){
	if(xmlhttp.readyState==4){
		if(xmlhttp.status==200){
			var xmldoc = xmlhttp.responseXML;
			var elems = xmldoc.getElementsByTagName("row");
			document.getElementById("txtZipcode").innerText = xmlhttp.responseText;
		}else if(xmlhttp.status==404){
			alert('Request file not found !');
		}else{
			alert('[returnUsername] Error has occurred with status code : '+ xmlhttp.status);	
		}
	}
}


*/
