var http;
var urls;

function handleHttpResponse_savehome()
{ 
	if (http.readyState == 4) 
	{	
     	isWorking = false;
     	if (http.responseText.indexOf('invalid') == -1) 
  		{
			var xmlDocument = http.responseXML;
			var cnt = xmlDocument.getElementsByTagName('cnt').item(0).firstChild.data;
			if(cnt == 1)
				alert("Home Saved Successfully.");
			setTimeout("parent.jQuery.fn.colorbox.close();",500);
			isWorking = false;
  		}
	}
}


function Save_Home()
{
	var str = '';
	var mlsid = document.getElementById("mlsid").value;
	str+="mlsid="+mlsid;
	urls = site_ajax_url+"savehome.php?"+str;
	//alert(urls);return false;
	var isWorking = false;
  	if (!isWorking)
    {
    	if (window.XMLHttpRequest)
      	{
      		http=new XMLHttpRequest()
      		http.open("GET",urls, true);
    	  	http.onreadystatechange=handleHttpResponse_savehome
    	  	http.send(null)
      	}
    	// code for IE
    	else if (window.ActiveXObject)
      	{
      		http=new ActiveXObject("Microsoft.XMLHTTP")
        	if (http)
        	{
        		http.open("GET",urls, true);
        		http.onreadystatechange=handleHttpResponse_savehome
        		http.send()
        	}
      	}
  	}
}

function myXMLHttpRequest() 
{
	  var xmlhttplocal;
	  try {
    		//xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
			xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
	   } 
	   catch (e) 
	   {
			try 
			{
				xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
			} 
			catch (E) 
			{
			    xmlhttplocal=false;
			}
		}

		if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') 
		{
			try 
			{
				var xmlhttplocal = new XMLHttpRequest();
			} 
			catch (e) 
			{
				var xmlhttplocal=false;
				alert('couldn\'t create xmlhttp object');
			}
		}
	return(xmlhttplocal);
}

var httpn;
var urlsn;

function handleHttpResponse_Notification()
{ 
	if (httpn.readyState == 4) 
	{	
     	isWorking = false;
     	if (httpn.responseText.indexOf('invalid') == -1) 
  		{
			
			var xmlDocument = httpn.responseXML;
			var msg = xmlDocument.getElementsByTagName('msg').item(0).firstChild.data;
			alert(msg);
			setTimeout("parent.jQuery.fn.colorbox.close();",500);
			isWorking = false;
  		}
	}
}


function Notification()
{
	var str = '';
	if(document.getElementById("searches").value != '')
		str = "?searches="+document.getElementById("searches").value;
	urlsn = site_ajax_url+"homenotification.php"+str;
//	alert(urlsn);return false;
	var isWorking = false;
  	if (!isWorking)
    {
    	if (window.XMLHttpRequest)
      	{
      		httpn=new XMLHttpRequest()
      		httpn.open("GET",urlsn, true);
    	  	httpn.onreadystatechange=handleHttpResponse_Notification
    	  	httpn.send(null)
      	}
    	// code for IE
    	else if (window.ActiveXObject)
      	{
      		httpn=new ActiveXObject("Microsoft.XMLHTTP")
        	if (httpn)
        	{
        		httpn.open("GET",urlsn, true);
        		httpn.onreadystatechange=handleHttpResponse_Notification
        		httpn.send()
        	}
      	}
	  	}

}


var new_http;
var new_url;

function handleHttpResponse_sort()
{ 
	if (new_http.readyState == 4) 
	{	
     	isWorking = false;
     	if (new_http.responseText.indexOf('invalid') == -1) 
  		{
			isWorking = false;
  		}
	}
}

function includeSort(mlsId,str,mode)
{
	var temp = '';
	if(str == 'Add')
	{
		if(document.getElementById(mlsId).checked)temp = 'checked';
		else temp = 'unchecked';
	}
	else
	{
		//document.getElementById(mlsId).checked = false;
		temp = 'unchecked';
	}
	new_url = site_ajax_url+"sort.php?mlsId="+mlsId+"&temp="+temp+"&mode="+mode;
	//alert(new_url);
	var isWorking = false;
  	if (!isWorking)
    {
    	if (window.XMLHttpRequest)
      	{
      		new_http=new XMLHttpRequest()
      		new_http.open("GET",new_url, true);
    	  	new_http.onreadystatechange=handleHttpResponse_sort
    	  	new_http.send(null)
      	}
    	// code for IE
    	else if (window.ActiveXObject)
      	{
      		new_http=new ActiveXObject("Microsoft.XMLHTTP")
        	if (new_http)
        	{
        		new_http.open("GET",new_url, true);
        		new_http.onreadystatechange=handleHttpResponse_sort
        		new_http.send()
        	}
      	}
	}
}

function removeData(val,mlsno,mode)
{
	input_box=confirm("Are you sure, want to Remove this property?");
	if (input_box==true)
	{
		var idlist = document.getElementById("homenum").value;
		str=idlist.split(",");
		if(str.length <= 2)
		{
			document.getElementById("data").style.display = 'none';
			document.getElementById("nodata").style.display = 'block';
		}
		var newstr = '';
		for(var k=0;k<str.length;k++)
		{
			if(str[k] != mlsno)
			{
				newstr+=str[k]+",";
			}
		}
		document.getElementById("homenum").value = '';
		document.getElementById("homenum").value = newstr.substring(0,newstr.length-1);
		document.getElementById("main").removeChild(document.getElementById("val_"+val));
		includeSort(mlsno,"delete",mode);
	}
	else
		return false;
}


