function parameters(w) { var p= location.search; if (p.length==0) return ""; p= p.substring(1, p.length); var pairs = p.split("&"); for (var i=0; i<pairs.length; i++) { var pv = pairs[i].split("="); if (pv[0] == w) return pv[1]; } return ""; }

function layerStatus (name, status)
{
	document.getElementById(name).style.display=status;
}

function layerContent (name, content)
{
	if (!document.getElementById(name)) return; 
	document.getElementById(name).innerHTML=content;
}

function removeproperty(id,uid,type,email)
{
	//this function is workin only when you remove property from certain directory level !!!!!!!!
	//thats why i've made removeproperty2 function PC
	rm2.doRequest ("handleRequest2", "../xml/removeproperty.php?id="+id+"&uid="+uid + "&type=" + type  + "&email="+email, id);
}

function removeproperty2(id,uid,type,email,site_url)
{
	rm2.doRequest ("handleRequest2", site_url+"/xml/removeproperty.php?id="+id+"&uid="+uid + "&type=" + type  + "&email="+email, id);
}

function saveproperty(id,uid,type,email,password, xmlpath)
{
	if (xmlpath==undefined || xmlpath=='undefined') {
		xmlpath = "../xml/";
	}
	if (password!="undefined" && password)
	{
	rm2.doRequest ("handleRequest", xmlpath + "saveproperty.php?id="+id+"&uid="+uid + "&type=" + type + "&email="+email+"&password="+password, id);
	//window.open("../xml/saveproperty.php?id="+id+"&uid="+uid + "&type=" + type + "&email="+email+"&password="+password);
	}
	else
	rm2.doRequest ("handleRequest", xmlpath + "saveproperty.php?id="+id+"&uid="+uid + "&type=" + type + "&email="+email, id);
}

function REQUESTMANAGER2() { this.div = ""; if(window.XMLHttpRequest) this.r = new XMLHttpRequest(); else if (window.ActiveXObject) try { this.r= new ActiveXObject("Msxml.XMLHTTP"); } catch(e) { this.r= new ActiveXObject("Microsoft.XMLHTTP"); } }

REQUESTMANAGER2.prototype.renew = function () 
{ 
if(window.XMLHttpRequest) this.r = new XMLHttpRequest(); else if (window.ActiveXObject) try { this.r= new ActiveXObject("Msxml.XMLHTTP"); } catch(e) { this.r= new ActiveXObject("Microsoft.XMLHTTP");}
}

REQUESTMANAGER2.prototype.doRequest = function (func,url,id) { this.renew(); this.id=id; if (this.r) this.r.abort(); this.r.open ("GET", url,"true"); this.r.onreadystatechange = function () {eval ("rm2."+func+"()"); }; try { this.r.send(null); } catch (e) { alert (e); } }

REQUESTMANAGER2.prototype.handleHTMLRequest = function () 
{ 
if (this.r.readyState == 4) 
{

document.getElementById(this.div).innerHTML=this.r.responseText; 
document.getElementById(this.div).style.display='block';
    
if( this.id == "pngfix" ) {
  pngfix();
  return;
}

}
}

/////////////////////////////////////////////////////////////////// comment by PC
var saved_b =0; // i've defined this here otherwise function saveproperty was failing with error saved_b not defined
var saved_r =0;
/////////////////////////////////////////////////////////////////// comment by PC

REQUESTMANAGER2.prototype.handleRequest = function ()
{
	
	if (this.r.readyState == 4)
        {
		 var rD = this.r.responseXML;
		
                if (rD)
                {
                if (rD.documentElement)
                {

			layerContent("addtolist" + this.id, addtolist_1);
			
			var ts = rD.documentElement.getElementsByTagName("saved");
			var val =  ts[0].getAttribute("value");

			var tst = rD.documentElement.getElementsByTagName("type");
			var valt =  tst[0].getAttribute("value");

			if (val=="2")
			layerContent("addtolist" + this.id, addtolist_2);
			else if (val=="1")
			{
				layerContent("addtolist" + this.id, addtolist_1);
				


						if(valt=='b') saved_b++;
						if(valt=='r') saved_r++;
						refresh_boxes();


				
			}
			else if (val=="0")
			layerContent("addtolist" + this.id, addtolist_0);

                        var ts = rD.documentElement.getElementsByTagName("login");
			if (ts[0])
			{
				feedbackLogin(ts[0].getAttribute("value"));
			}
		}}
	}
}

REQUESTMANAGER2.prototype.handleRequest2 = function ()
{
	if (this.r.readyState == 4)
        {
		var rD = this.r.responseXML;
                if (rD)
                {
                if (rD.documentElement)
                {
                        var ts = rD.documentElement.getElementsByTagName('saved');
			var val =  ts[0].getAttribute("value");
                        	
			if (val=="1")
			layerContent("addtolist" + this.id, removetolist_1);
			else if (val=="0")
			layerContent("addtolist" + this.id, removetolist_0);
		}}
	}
}

REQUESTMANAGER2.prototype.handleRequestGeneric = function ()
{
	if (this.r.readyState == 4)
    {
		if (this.id=="showSlide")
		{
			showSlide(this.r.responseText);

			return;
		}
		// added for open house day - date 2009-09-10
		if (this.id=="updateProperties")
		{
			var ids = this.r.responseText;
			updateProperties(ids);
		}
		// end open house day update
    
		 var rD = this.r.responseXML;
                if (rD)
                {
                if (rD.documentElement)
                {
			if (this.id=="showPassword")
			{
                        	var ts = rD.documentElement.getElementsByTagName('status');
				showPassword (ts[0].getAttribute("val"));
			}

			if (this.id=="parsePlaces")
			{
                        	var ts = rD.documentElement.getElementsByTagName('total');
				var ids = new Array();
                        	var ts2 = rD.documentElement.getElementsByTagName('p');
				for (i=0; i<ts2.length; i++)
				{
				ids[ids.length]=ts2[i].getAttribute("name")+","+ts2[i].getAttribute("lat")+","+ts2[i].getAttribute("lng");
				}
				eval (this.id + "('"+ts[0].getAttribute("number")+"',ids)");
			}

			if (this.id=="updateOfficesOnLonResi")
			{
				var ids="";
				var comma="";
                        	var ts = rD.documentElement.getElementsByTagName('p');
				for (i=0; i<ts.length; i++)
				{
				ids+=comma+ts[i].getAttribute("name")+"="+ts[i].getAttribute("total");
				comma=",";
				}
				updateOfficesOnLonResi(ids);
			}

			if (this.id=="updatePlaces")
			{
				var ids="";
				var comma="";
                        	var ts = rD.documentElement.getElementsByTagName('p');
				for (i=0; i<ts.length; i++)
				{
				ids+=comma+ts[i].getAttribute("name")+"="+ts[i].getAttribute("total");
				comma=",";
				}
				updatePlaces(ids);
			}

			if (this.id=="numProps" || this.id=="numProps2")
			{
                        	var ts = rD.documentElement.getElementsByTagName('total');
				var lat = ts[0].getAttribute('lat');
				var lng = ts[0].getAttribute('lng');
				var ids = new Array();
                        	var ts2 = rD.documentElement.getElementsByTagName('id');

				var comma="";
				for (i=0; i<ts2.length; i++)
				{
				ids+=comma+ts2[i].getAttribute("value");
				comma=",";
				}

                        	var ts3 = rD.documentElement.getElementsByTagName('rad');
				for (i=0; i<ts3.length; i++)
				{
					ids[ids.length]=ts3[i].getAttribute("number")
				}

				eval (this.id + "('"+ts[0].getAttribute("number")+"',ids,lat,lng)");
			}
                        	
		}}
	}
}

var rm2 = new REQUESTMANAGER2();
