// JavaScript Document
	
	function getHTTPObject(){
		var xmlHttp;	
		if (window.XMLHttpRequest){ // if Mozilla, Safari etc
			xmlHttp = new XMLHttpRequest();
		} else if (window.ActiveXObject){ // if IE <7
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			if(!xmlHttp){
					xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
		}
		return xmlHttp;			
	}
	
	var http=getHTTPObject();

	function valid_email(id){
		var x=document.getElementById(id).value;
		if(x==""){
			document.getElementById("_"+id).innerHTML="<span style='color:red'> * Required Fields</span>";
			document.getElementById("send").disabled=true;
		}else if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",x)) {
			document.getElementById("_"+id).innerHTML="";
			document.getElementById("send").disabled=false;
		}else {
			document.getElementById("_"+id).innerHTML="<span style='color:red'> * Required Fields</span>";
			document.getElementById("send").disabled=true;
		}	
	}
	
	function valid_onblur(id){		
		var x=document.getElementById(id).value;
		if(x==""){
			document.getElementById("_"+id).innerHTML="<span style='color:red'> * Required Fields</span>";
			document.getElementById("send").disabled=true;
		}else{
			document.getElementById("_"+id).innerHTML="";
			document.getElementById("send").disabled=false;
		}
	}
		
	function requestinfo(url,id){
		http.open("GET",url,id,true);
		http.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );		
		http.onreadystatechange = function (){

						if (http.readyState==4){
							if (http.status==200){
								var expa = document.getElementById(id);
								var pX = document.createElement("span_child");
								if(expa.getAttribute("openRow")=="1"){
									expa.setAttribute("openRow","0");
									expa.removeChild(expa.lastChild);
								}else{
									expa.setAttribute("openRow","1");
									pX.innerHTML=http.responseText ;
									expa.appendChild(pX);															
								}
							} else {
								document.getElementById(id).innerHTML="Error! : "+ http.statusText ;
							}
						}
		};
		http.send(null);		
	}
	
	function requestinfo_2(url,id){
		http.open("GET",url,id,true);
		http.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );		
		http.onreadystatechange = function (){

						if (http.readyState==4){
							if (http.status==200){
								var expa = document.getElementById(id);
								var pX = document.createElement("span_child");
								window.location.href="index.php";
							} else {
								document.getElementById(id).innerHTML="Error! : "+ http.statusText ;
							}
						}
		};
		http.send(null);		
	}
	
	function getdistric(id,id2){
		var x=document.getElementById(id).selectedIndex;
		var pv_code=document.getElementById(id).getElementsByTagName("option")[x].value		
		if(pv_code==106){
			http.open("Get","district.php",true)
			http.onreadystatechange = function handleStateChange_(){
				if (http.readyState==4){
					if (http.status==200){
						var expa = document.getElementById(id2);
						expa.innerHTML=http.responseText ;
					} else {
						document.getElementById(id2).innerHTML="Error! : "+ http.statusText ;
					}
				}
			}		
			http.send(null);		
		}else{
			document.getElementById(id2).innerHTML="";
		}
	}
	
	function get_redirect(name){
		alert("ข้อมูลบันทึกเรียบร้อย");
		window.location.href=name;
	}	