
function ajax_cities(DDL_States,DDL_Cities,WhereS)  
{
//alert("ajax_cities START: "+DDL_States+":"+DDL_Cities+":"+WhereS);

  var url = "http://www.spolujizda.com/SpolujizdaCOMService.asmx/GET_CITIES"  
  //var url = "http://localhost:1563/ZZZ/SpolujizdaCOMService.asmx/GET_CITIES"   //!?!?!?!?!?
  //var url = "http://www.occupationsguide.cz/psp3/SpolujizdaCOMService.asmx/GET_CITIES"   //!?!?!?!?!?
  if (window.ActiveXObject)
    {
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
  else
    {
    httpRequest = new XMLHttpRequest();
  }
  
//alert("tady");
//  var ListStateLL = document.getElementById("ctl00_ContentPlaceHolder1_"+DDL_States);//DropDownList"+Znak1);

  var ListStateLL = document.getElementById(DDL_States);    //DropDownList"+Znak1);
  var State="";
  State=ListStateLL[ListStateLL.selectedIndex].value;
  
//alert("state:"+State);  

  //GG=DDL_Cities;
   
 //BodyS="Key=LudekLinhartCities"+"&Term=Country='"+State+"'"+"&OrderBy=city_prestige DESC,name";
  //BodyS="Key=LudekLinhartCities"+"&Term=(Country='"+State+"') AND (active_from<>'0');
  BodyS="Key=LudekLinhartCities"+"&Term=(Country='"+State+"')";
  BodyS=BodyS+WhereS;
  BodyS=BodyS+"&OrderBy=city_prestige DESC,name";

  //alert("BodyS:"+BodyS+":");
  
  //alert(url); 
  
  httpRequest.open("POST", url, true);
  httpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  httpRequest.setRequestHeader("Content-Length", BodyS.length);
  httpRequest.onreadystatechange= function () {processRequest(DDL_Cities); } ;
  httpRequest.send(BodyS);

//alert("ajax_cities KONEC");
}

function processRequest(GG)
{
//alert("processRequest:");
  var sName="";
  var sCode="";
  var i=0;
  
//alert("processRequest:"+GG);
  if (httpRequest.readyState == 4)
  {
//alert("processRequest4:"+GG);
    if(httpRequest.status == 200)
    {
//alert("httpRequest.status == 200:"+GG);                                           
      var ListLL = document.getElementById(GG);
      ListLL.length=0;
      ListLL.options[ListLL.length] =  new Option("-","-");
     
//alert("RESULTAT:"+httpRequest.responseText);
      
      var xmldok = httpRequest.responseXML;
      var Xname =xmldok.getElementsByTagName("name");
      var Xcode =xmldok.getElementsByTagName("Code");

      for (var i=1;i<Xname.length;i++)
      {
        sName=Xname[i].firstChild.data;  
        sCode=Xcode[i].firstChild.data;        
        ListLL.options[ListLL.length] =  new Option(sName,sCode);
      }
      
      ListLL.width=150;
      
    }
    else
    {
        alert("Chyba pri nacitani stanky :"+ httpRequest.status +":"+ httpRequest.statusText);
    }
  }
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function GUnload()
{
// pomocne, protoze tuto fci pouizvam v Body v master
}

function readCookie(name) 
{
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
