 //  Ajax Start
     var xmlHttp;
	function createXMLHttpRequest() {
	     if (window.ActiveXObject) {
		    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		 } 
			else if (window.XMLHttpRequest) {
			 xmlHttp = new XMLHttpRequest();
			 }
		}


//  
function update_topic_view(action,idd) {
		      createXMLHttpRequest();
              xmlHttp.open("get", "ajax_action_script.php?action_script="+action+'&id='+idd , true);
              xmlHttp.onreadystatechange = function () {
              if(xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
					 	 //alert(action+idd);
   					     // document.getElementById("div_show_view").innerHTML =xmlHttp.responseText;
                       } else {
                         // document.getElementById("div_show_view").innerHTML = "Error";
                     }
                }            
            };
       xmlHttp.send(null);
 }


 

 function select_value(action,idd,div) {
		      createXMLHttpRequest();
			  //alert(idd)
              xmlHttp.open("get", "ajax_action_script.php?action_script="+action+'&id='+idd , true);
              xmlHttp.onreadystatechange = function () {
              if(xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
					 	 //alert(action+idd);
   					     document.getElementById(div).innerHTML =xmlHttp.responseText;
                       } else {
                         document.getElementById(div).innerHTML = "Error";
                     }
                }            
            };
       xmlHttp.send(null);
			 
}

 function select_value2(action,idd,div) {
		      createXMLHttpRequest();
			  //alert(idd)
              xmlHttp.open("get", "ajax_action_script.php?action_script="+action+'&id='+idd , true);
              xmlHttp.onreadystatechange = function () {
              if(xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
					 	 //alert(action+idd);
   					     document.getElementById(div).innerHTML =xmlHttp.responseText;
                       } else {
                         document.getElementById(div).innerHTML = "Error";
                     }
                }            
            };
       xmlHttp.send(null);
			 
}

 function select_value2_fix(action,idd,div,div2) {
		      createXMLHttpRequest();
              xmlHttp.open("get", "ajax_action_script.php?action_script="+action+'&id='+idd , true);
              xmlHttp.onreadystatechange = function () {
              if(xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
					 	 //alert(action+idd);
   					     document.getElementById(div).innerHTML =xmlHttp.responseText;
                         select_value2("change_fix",idd,div2);
                       } else {
                         document.getElementById(div).innerHTML = "Error";
                     }
                }            
            };
       xmlHttp.send(null);
			 
}

 
 

function select_country_zone() {
		      createXMLHttpRequest();
			  employee_country=document.getElementById("employee_country").value;
			  if(employee_country==98){
                  var action_type="country_th";
			  }else{
                  var action_type="country_other";
			  }
              xmlHttp.open("get", "ajax_action_script.php?action_script="+action_type, true);
              xmlHttp.onreadystatechange = function () {
              if(xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
					 	 //alert(action+idd);
   					     document.getElementById("div_countey").innerHTML =xmlHttp.responseText;
							 if(employee_country==98){
								 dochange( '' );
							 }
                       } else {
                         document.getElementById("div_countey").innerHTML = "Error";
                     }
                }            
            };
       xmlHttp.send(null);
			 
}



function select_country_zone_edit() {
		      createXMLHttpRequest();
			  employee_country=document.getElementById("employee_country").value;
			  action_type_process=document.getElementById("action_type").value;
			  employee_address_id=document.getElementById("employee_address_id").value;
			  if(employee_country==98){
                  var action_type="country_th_edit";
			  }else{
                  var action_type="country_other_edit";
			  }
              xmlHttp.open("get", "ajax_action_script.php?action_script="+action_type+'&action_type='+action_type_process+'&employee_address_id='+employee_address_id, true);
              xmlHttp.onreadystatechange = function () {
              if(xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
					 	 //alert(action+idd);
   					     document.getElementById("div_country").innerHTML =xmlHttp.responseText;
							 if(employee_country==98){
								 dochange( '' );
							 }
                       } else {
                         document.getElementById("div_country").innerHTML = "Error";
                     }
                }            
            };
       xmlHttp.send(null);
			 
}




 function check_user_email(div,action,idd) {
		      createXMLHttpRequest();
              if(idd==""){
                 alert('ท่านยังไม่ได้ระบุอีเมล์');
				 return false;
			  }
              xmlHttp.open("get", "ajax_action_script.php?action_script="+action+'&id='+idd , true);
              xmlHttp.onreadystatechange = function () {
              if(xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
					 	 //alert(action+idd);
   					      document.getElementById(div).innerHTML =xmlHttp.responseText;
                       } else {
                          document.getElementById(div).innerHTML = "Error";
                     }
                }            
            };
       xmlHttp.send(null);
			 
}
 
// Address Tumbon Aumphur Province

function Inint_AJAX()
{
	try{
		return new ActiveXObject( "Msxml2.XMLHTTP" );
	}
	catch ( e ){
	};

	try{
		return new ActiveXObject( "Microsoft.XMLHTTP" );
	}
	catch ( e ){
	};

	try{
		return new XMLHttpRequest();
	}
	catch ( e ){
	};

	alert( "XMLHttpRequest not supported" );
	return null;
};

function dochange( obj )
{
	var req = Inint_AJAX();
	var province = document.getElementById( 'province' ).value;
	var tumbon = document.getElementById( 'tumbon' ).value;
	// alert('Pro'+province+' - Tu'+tumbon);
	if ( obj && obj.name == 'province' ) //เมื่อทำการเลือที่จังหวัดมา ให้เคลียร์ค่าอำเภอ
	{
		var amphur = "";
	}
	else //เลือกรายการอื่น
	{
		var amphur = document.getElementById( 'amphur' ).value;
	};
	var data = "province=" + province + "&amphur=" + amphur + "&tumbon=" + tumbon;
	req.onreadystatechange = function()
	{
		if ( req.readyState == 4 )
		{
			if ( req.status == 200 )
			{
				var datas = eval( '(' + req.responseText + ')' ); // JSON
				document.getElementById( 'provinceDiv' ).innerHTML = datas[0].province;
				document.getElementById( 'amphurDiv' ).innerHTML = datas[0].amphur;
				document.getElementById( 'tumbonDiv' ).innerHTML = datas[0].tumbon;
			};
		};
	};
	req.open( "post" , "province.php" , true ); //สร้าง connection
	req.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" ); // set Header
	req.send( data ); //ส่งค่า
};

