﻿ function Binddata(drdParent,_txt,drdChild){
   clearDropDownList(drdChild,'Dòng xe','-');
   if(drdParent.selectedIndex>0){
    if((drdParent.options[drdParent.selectedIndex].value!="-")&&(drdParent.options[drdParent.selectedIndex].value!="-1")){
     var temp=_txt[drdParent.selectedIndex-1].split("~");
     for(i=0;i<temp.length;i++){
      var temp1=temp[i].split("()");
      addItem(drdChild,temp1[1],temp1[0]);
     }
    }
   }   
  }
 
 function clearDropDownList(drdlist,_text,_value){
  var i;
  for(i=drdlist.options.length;i>=0;i--){
   drdlist.remove(i);
  }
  var y=document.createElement("option");
  y.text=_text;
  y.value=_value;
  y.selected=true;
  try{
   drdlist.add(y,null);
  }catch(ex){
   drdlist.add(y);
  }
 }
 
 function resetDropDownList(drdlist,_texts,_values){
  var i;
  for(i=drdlist.options.length;i>=0;i--){
   drdlist.remove(i);
  }
  for(i=0;i<_texts.length;i++){
   var y=document.createElement("option");
   y.text=_texts[i];
   y.value=_values[i];
   try{
    drdlist.add(y,null);
   }catch(ex){
    drdlist.add(y);
   }
  }
 }
 
 function addItem(drdlist,_text,_value){
  var y=document.createElement("option");
  y.text=_text;
  y.value=_value;
  try{
   drdlist.add(y,null);
  }catch(ex){
   drdlist.add(y);
  }
 }
 
 
 //------------------- Hung -- Ajax-Post
 //url: trang chua du lieu cho toi
 //para: bien chuyen vao trang url de lay du lieu
 //tagdiv: the chua vung goi ajax
 function showAjax(url,para,tagdiv)
 { 
  var http;
  http=GetXmlHttpObject();
  if (http==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
  
  http.open("POST", url, true);
  //Send the proper header information along with the request
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", para.length);
  http.setRequestHeader("Connection", "close");
  http.onreadystatechange =function() {
  //Call a function when the state changes.
   if(http.readyState == 4&& http.status == 200 ){
    tagdiv.innerHTML= http.responseText;
   }
  } 
  http.send(para);
 }
 
 function GetXmlHttpObject()
 {
	var http=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		http=new XMLHttpRequest();
	}
	catch (e)
	{
	// Internet Explorer
		try
		{
			http=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) 
		{
			http=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return http;
 }
