var xmlHttp,gMode

function ajaxData(mode,str)
{
	gMode = mode
	if (str.length==0)
	  { 
	  	//  document.getElementById("cbx_Branch").innerHTML="";
		// document.getElementById("cbx_Branch").selectedIndex = 0;
	  	return;
	  }
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; }        

	var url="/lib/getdata.asp";
	url=url+"?mode="+mode+"&obj="+str;
	if (gMode =="team" || gMode =="team_beta"){
		document.all["cbx_Staff"].disabled = true;
	}else if (gMode =="ad_branch"){
		document.all["cbx_media_Team"].disabled = true;
	}else if (gMode =="downteam"){
		document.all["cbx_Sale"].disabled = true;
	}else if (gMode =="getAmphur"){
		document.all["cbx_PropAumphur"].disabled = true;
	}else if (gMode =="getAmphur_view"){
		document.all["cbx_amphr1"].disabled = true;
	}else if (gMode =="getThumbl"){
		document.all["txt_PropTumbon"].disabled = true;
		url=url+"&chngwtcd="+document.all["cbx_PropProvince"].value
	}else if (gMode =="getThumbl_post"){
		document.all["txt_PropTumbon"].disabled = true;
		url=url+"&chngwtcd="+document.all["cbx_PropProvince"].value
	}else{
	}
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = stateChanged ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		str = xmlHttp.responseText;
		if (gMode =="branch"){
			//   document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
			str_array = str.split(",");
			da["cbx_Team"].removeNode(true);
			da["tdTeam"].innerHTML = "<select name=cbx_Team><option value=''>------------ เลือกสำนักงาน -----------</option></select>"
			for (i=0;i<str_array.length;i++) {
				valueLabelPair = str_array[i].split(",");
				if (valueLabelPair != ""){
					document.getElementById('cbx_Team').options[i+1] = new Option(valueLabelPair[0], valueLabelPair[0]);
				}
			}
		}else if(gMode =="ad_branch"){
			str_array = str.split(",");
			da["cbx_media_Team"].removeNode(true);
			da["td_media_team"].innerHTML = "<select name=cbx_media_Team class=m8><option value=''></option></select>"
			for (i=0;i<str_array.length;i++) {
				valueLabelPair = str_array[i].split(",");
				if (valueLabelPair != ""){
					strData = valueLabelPair[0].split("||");
					document.getElementById('cbx_media_Team').options[i+1] = new Option(strData[0], strData[1]);
				}
			}
			document.getElementById('cbx_media_Team').style.width = "100%"
		}else if(gMode =="team" || gMode =="team_beta"){
			str_array = str.split(",");
			da["cbx_Staff"].removeNode(true);
			da["tdStaff"].innerHTML = "<select name=cbx_Staff class=m8 onchange=javascript:setStaffName()><option value=''></option></select>"
			for (i=0;i<str_array.length;i++) {
				valueLabelPair = str_array[i].split(",");
				if (valueLabelPair != ""){
					strData = valueLabelPair[0].split("||");
					document.getElementById('cbx_Staff').options[i+1] = new Option(strData[0], strData[1]);
				}
			}
			document.getElementById('cbx_Staff').style.width = "100%"
		}else if(gMode =="downteam"){
			str_array = str.split(",");
			da["cbx_Sale"].removeNode(true);
			da["tdSale"].innerHTML = "<select name=cbx_Sale class=m8><option value=''></option></select>"
			for (i=0;i<str_array.length;i++) {
				valueLabelPair = str_array[i].split(",");
				if (valueLabelPair != ""){
					strData = valueLabelPair[0].split("||");
					document.getElementById('cbx_Sale').options[i+1] = new Option(strData[0], strData[1]);
				}
			}
			document.getElementById('cbx_Sale').style.width = "90%"
		}else if(gMode =="getAmphur"){
			str_array = str.split(",");
			objOnchange = da["cbx_PropAumphur"].onchange
			da["cbx_PropAumphur"].removeNode(true);
			da["tdAmphr"].innerHTML = "<select name=cbx_PropAumphur class=headline14data><option value=''>--- เลือกอำเภอ ---</option></select>"
			for (i=0;i<str_array.length;i++) {
				valueLabelPair = str_array[i].split(",");
				if (valueLabelPair != ""){
					strData = valueLabelPair[0].split("||");
					document.getElementById('cbx_PropAumphur').options[i+1] = new Option(strData[1], strData[0]);
				}
			}
			document.getElementById('cbx_PropAumphur').style.width = "120pt"
			document.getElementById('cbx_PropAumphur').onchange= objOnchange ;
		}else if(gMode =="getAmphur_view"){
			str_array = str.split(",");
			objOnchange = da["cbx_amphr1"].onchange
			da["cbx_amphr1"].removeNode(true);
			da["sp_Amphr"].innerHTML = "<select name=cbx_amphr1><option value=''>------------ เลือกอำเภอ -----------</option></select>"
			for (i=0;i<str_array.length;i++) {
				valueLabelPair = str_array[i].split(",");
				if (valueLabelPair != ""){
					strData = valueLabelPair[0].split("||");
					document.getElementById('cbx_amphr1').options[i+1] = new Option(strData[1], strData[0]);
				}
			}
			document.getElementById('cbx_amphr1').style.width = "120pt"
			document.getElementById('cbx_amphr1').onchange= objOnchange ;
		}else if(gMode =="getThumbl"){
			str_array = str.split(",");
			objOnchange = da["txt_PropTumbon"].onchange
			da["txt_PropTumbon"].removeNode(true);
			da["tdTumbon"].innerHTML = "<select name=txt_PropTumbon class=headline14data><option value=''>--- เลือกตำบล ---</option></select>"
			for (i=0;i<str_array.length;i++) {
				valueLabelPair = str_array[i].split(",");
				if (valueLabelPair != ""){
					strData = valueLabelPair[0].split("||");
					document.getElementById('txt_PropTumbon').options[i+1] = new Option(strData[1], strData[0]);
				}
			}
			document.getElementById('txt_PropTumbon').style.width = "120pt"
			document.getElementById('txt_PropTumbon').onchange= objOnchange ;
		}else if(gMode =="getThumbl_post"){
			str_array = str.split(",");
			objOnchange = da["txt_PropTumbon"].onchange
			da["txt_PropTumbon"].removeNode(true);
			da["tdTumbon"].innerHTML = "<select name=txt_PropTumbon class=headline14data><option value=''>--- เลือกตำบล ---</option></select>"
			for (i=0;i<str_array.length;i++) {
				valueLabelPair = str_array[i].split(",");
				if (valueLabelPair != ""){
					strData = valueLabelPair[0].split("||");
					document.getElementById('txt_PropTumbon').options[i+1] = new Option(strData[1], strData[0]);
				}
			}
			document.getElementById('txt_PropTumbon').style.width = "120pt"
			document.getElementById('txt_PropTumbon').onchange= objOnchange ;
		}
	   }
}

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;
}
