// JavaScript Document
function getXMLHTTPRequest()
{
	var req = false;
	try
	  {
		req = new XMLHttpRequest(); /* e.g. Firefox */
	  }
	catch(err1)
	  {
	  try
		{
		 req = new ActiveXObject("Msxml2.XMLHTTP");
	  /* some versions IE */
		}
	  catch(err2)
		{
		try
		  {
		   req = new ActiveXObject("Microsoft.XMLHTTP");
	  /* some versions IE */
		  }
		  catch(err3)
			{
			 req = false;
			}
		}
	  }
	return req;
}
var myRequest = getXMLHTTPRequest();

function addOption(selectbox,text,value,selected)
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
	if(selected) selectbox.selected = true;
}

function callAjax(id_tara) 
{
	// declare a variable to hold some information
	// to pass to the server
	// build the URL of the server script we wish to call
	var url = "select-oras.php?id_tara="+id_tara;
	// ask our XMLHTTPRequest object to open a
	// server connection
	myRequest.open("GET", url, true);
	// prepare a function responseAjax() to run when
	// the response has arrived
	myRequest.onreadystatechange = responseAjax;
	// and finally send the request
	myRequest.send(null);
}
function responseAjax() 
{
    if(myRequest.readyState == 4) 
	{
        // if server HTTP response is "OK"		
		 selectItem = document.formInregistrare.oras;
		 selectItem.length = 0;		 
		// addOption(selectItem,'---Select a city---','');		 
		 orase = myRequest.responseText;		 
		 orase = orase.split('_'); 		
		 for(i=0;i<orase.length;i++)	
		 if(orase[i])	
		 {
			if(orase[i] == '' ) addOption(selectItem,orase[i],orase[i],true);
			else addOption(selectItem,orase[i],orase[i]);
		 }	
	}	
}


function callAjaxC(id_tara) 
{	
	// declare a variable to hold some information
	// to pass to the server
	// build the URL of the server script we wish to call
	var url = "select-oras.php?id_tara="+id_tara;
	// ask our XMLHTTPRequest object to open a
	// server connection
	myRequest.open("GET", url, true);
	// prepare a function responseAjax() to run when
	// the response has arrived
	myRequest.onreadystatechange = responseAjaxC;
	// and finally send the request
	myRequest.send(null);
}
function responseAjaxC() 
{
    if(myRequest.readyState == 4) 
	{
        // if server HTTP response is "OK"		
		 selectItem = document.formInregistrare.oras;
		 selectItem.length = 0;		 
		 addOption(selectItem,'-','',true);		 
		 orase = myRequest.responseText;		 
		 orase = orase.split('_'); 		
		 for(i=0;i<orase.length;i++)	
		 if(orase[i])	
		 {
			if(orase[i] == '' ) addOption(selectItem,orase[i],orase[i],true);
			else addOption(selectItem,orase[i],orase[i]);
		 }	
	}	
}
function callAjaxSunt(sunt) 
{	
	// declare a variable to hold some information
	// to pass to the server
	// build the URL of the server script we wish to call
	var url = "select-caut.php?sunt="+sunt;
	// ask our XMLHTTPRequest object to open a
	// server connection
	myRequest.open("GET", url, true);
	// prepare a function responseAjax() to run when
	// the response has arrived
	myRequest.onreadystatechange = responseAjaxSunt;
	// and finally send the request
	myRequest.send(null);
}
function responseAjaxSunt() 
{
    if(myRequest.readyState == 4) 
	{
        // if server HTTP response is "OK"		
		 selectItem = document.formInregistrare.caut;
		 selectItem.length = 0;		 
		 //addOption(selectItem,'-','',true);		 
		 caut = myRequest.responseText;		 
		 caut = caut.split('_'); 		
		 for(i=0;i<caut.length;i++)	
		 if(caut[i])	
		 {
			if(caut[i] == '' ) addOption(selectItem,caut[i],caut[i],true);
			else addOption(selectItem,caut[i],caut[i],true);
		 }	
	}	
}

