var xmlHttp=null;
var phpFilePath = '';
function init_ajax ()
{
	phpFilePath = '../';
}

function populate (pObj, iObj)
{
	//alert(pObj+' - '+iObj);
	
	this.obj = pObj;
	this.iobj = iObj;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
//	alert (phpFilePath);
	 var url="http://www.ro-imobiliare.ro/getvalsDropdown.php";
	//var url="http://www.ro-imobiliare.w2w.ro/getvalsDropdown.php";
	url=url+"?q="+Math.random();
	//alert('obj '+this.iobj);
	if (this.iobj != null)
	{
		
		url=url+"&"+this.obj.name+"="+this.obj.value;
	}
//	alert (url);
	if (this.obj.name=='id_judet')
	{
		var obj1 = document.getElementById ('loc_s'), obj2 = document.getElementById ('cart_s');
		if (obj1 != null)
		{
			if (obj1.options)
			for (var i=1; i<obj1.options.length; i++)
			 while (obj1.options[i])
				obj1.options[i] = null;
		}
		if (obj2 != null)
		{			
			if (obj2.options)		
			for (var i=1; i<obj2.options.length; i++)
			 while (obj2.options[i])
				obj2.options[i] = null;
		}
	}
	if (this.obj.name=='id_localitate')	
	 {
		var obj1 = document.getElementById ('cart_s');
 		if (obj1 != null)
		{			
			for (var i=1; i<obj1.options.length; i++)
			 while (obj1.options[i])
				obj1.options[i] = null;
		}
	 }	
	var oThis = (this.iobj == null ? this.obj : this.iobj);
	xmlHttp.onreadystatechange = function ()
	{
		var colectie = [];		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			colectie = eval (xmlHttp.responseText);
//		alert (colectie.length);
			if (colectie.length)
			for (var i=1; i<colectie.length+1; i++)
				oThis.options[i] = new Option(colectie[i-1][0],colectie[i-1][1]);
			//alert(colectie);
		}
	}
	xmlHttp.open("GET",url,true)
	//document.writeln('url: '+url);
	xmlHttp.send(null);	
};

function populare_cu_cartiere (pObj, iObj)
{
	this.obj = pObj;
	this.iobj = iObj;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
//	alert (phpFilePath);
	var url="http://www.ro-imobiliare.ro/getvalsCartiere.php";
	//var url="http://www.ro-imobiliare.w2w.ro/getvalsCartiere.php";
	url=url+"?q="+Math.random();
	url=url+"&loc="+this.obj.value;
//	alert (url);
	if (this.obj.name=='id_localitate')	
	 {
		 this.iobj.innerHTML = '';
	 }	
	var oThis = this.iobj;
	xmlHttp.onreadystatechange = function ()
	{   	    
		var colectie = [];		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			oThis.innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null);
};

function populate_by_judet (pObj, iObj1, iObj2)
{
	this.obj = pObj;
	this.iobj1 = iObj1;
	this.iobj2 = iObj2;	
	if (this.iobj1 == null)
		return;
	if (this.iobj2 == null)
		return;

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
//	alert (phpFilePath);
	var url="http://www.ro-imobiliare.ro/getvalsFirme.php";
	//var url="http://www.ro-imobiliare.w2w.ro/getvalsFirme.php";
	url += '?j='+this.obj.value;
	url=url+"&q="+Math.random();
//	alert (url);
	if (this.iobj1 != null)
	{			
		for (var i=1; i<this.iobj1.options.length; i++)
		 while (this.iobj1.options[i])
			this.iobj1.options[i] = null;
	}

	if (this.iobj2 != null)
	{			
		for (var i=1; i<this.iobj2.options.length; i++)
		 while (this.iobj2.options[i])
			this.iobj2.options[i] = null;
	}
	var objSp = document.getElementById ('cart_s');
	if (objSp != null)
	{
		if (objSp.options)
		for (var i=1; i<objSp.options.length; i++)
			 while (objSp.options[i])
				objSp.options[i] = null;

	}
	var oThis1 = this.iobj1;
	var oThis2 = this.iobj2;
	xmlHttp.onreadystatechange = function ()
	{   	    
		var colectie = [];
		var respTxt = '';
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			respTxt = xmlHttp.responseText;
//			alert (respTxt);
			colectie = eval (respTxt.substring (0, respTxt.indexOf ('@#@')));
//			alert (colectie);
			if (colectie.length)
			for (var i=1; i<colectie.length+1; i++)
				oThis1.options[i] = new Option(colectie[i-1][0],colectie[i-1][1]);
			colectie = eval (respTxt.substring (respTxt.indexOf ('@#@')+3, respTxt.length));
			if (colectie.length)
			for (var i=1; i<colectie.length+1; i++)
				oThis2.options[i] = new Option(colectie[i-1][0],colectie[i-1][1]);				
		}
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null);	
};

function GetXmlHttpObject()
{ 
	var objXMLHttp=null;
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else 
 	 if (window.ActiveXObject)
	 {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	 }
	return objXMLHttp;
} 
