﻿// JScript File
function ajaxManager()  
{
var args = ajaxManager.arguments;
var sendurl = "";
var message = "Loading..";
var imagenumber;
var responsetext = ""; 
var pageurl = "";
var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP"): new XMLHttpRequest();
sendurl = args[1];					
switch (args[0])
	{	
	case "do_process":		
		
		if (x)
			{
			x.onreadystatechange = function()
				{
					if (x.readyState == 4 && x.status == 200)
					{
					    /* new code for calling from inside  */
					    if(args[1].indexOf('PT=deleteTemp') > 0)
		                {
		                    ajaxManager1('load_box','../Register/Process.aspx?PT=update&UserID=0','ctl00_ctlHeader_divListingCnt');
                        }
					    /* */
					    var d = new Date();
	                    if(args.length>2)
						    window.location=args[2]+'?d='+d
					}
				}
			x.open("GET", sendurl, true);
			x.send(null);
			}
		break;	
		case "load_box":
		//document.getElementById(args[2]).innerHTML = "&nbsp;<b>Loading...</b>";
		if((args[1].indexOf('PT=display') > 0) || (args[1].indexOf('PT=update') > 0))
		{
		    document.getElementById('ctl00_ctlHeader_divListingCnt').innerHTML ='<span style=\'background-color:yellow\'>loading...</span>';
        }    
		if (x)
			{
			x.onreadystatechange = function()
				{
					if (x.readyState == 4 && x.status == 200)
					{
						el = document.getElementById(args[2]);
						responsetext = 	x.responseText.replace('\"','"');
						el.innerHTML =responsetext;						
						if(args.length>3)
							el.innerHTML='<B>'+args[2]+'</B>'						
					}
				}
			x.open("GET", sendurl, true);
			x.send(null);
			}
		break;		
	}
}
function ajaxManager1()  
{
var args = ajaxManager1.arguments;
var sendurl = "";
var message = "Loading..";
var imagenumber;
var responsetext = ""; 
var pageurl = "";
var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP"): new XMLHttpRequest();
sendurl = args[1];					
switch (args[0])
	{	
	case "do_process":		
		
		if (x)
			{
			x.onreadystatechange = function()
				{
					if (x.readyState == 4 && x.status == 200)
					{
					    var d = new Date();
	                    if(args.length>2)
						    window.location=args[2]+'?d='+d
					}
				}
			x.open("GET", sendurl, true);
			x.send(null);
			}
		break;	
		case "load_box":

        document.getElementById('ctl00_ctlHeader_divListingCnt').innerHTML ='<span style=\'background-color:yellow\'>loading...</span>';

		if (x)
			{
			x.onreadystatechange = function()
				{
					if (x.readyState == 4 && x.status == 200)
					{
						el = document.getElementById(args[2]);
						responsetext = 	x.responseText.replace('\"','"');
						el.innerHTML =responsetext;						
						if(args.length>3)
							el.innerHTML='<B>'+args[2]+'</B>'						
					}
				}
			x.open("GET", sendurl, true);
			x.send(null);
			}
		break;		
	}
}
function DeleteProperty(RentalListingID,LinkID,i,mlsid)
{
	var d = new Date();
	var UName='';
	var UserID='';
    if(confirm('Are you sure you want to delete this property?'))
    {
	    if(LinkID>0)
	    {
		    if(!getCookie('LinkID'))
		    {	
			    setCookie('LinkID',LinkID,0);					
		    }
		    else
		    {
			    setCookie('LinkID',LinkID+ '@!@' + getCookie('LinkID'),0);					
		    }
	    }
	    else
	    {
			    if(!getCookie('RentalListingID'))
			    {	
				    setCookie('RentalListingID',RentalListingID,0);
			    }
			    else
			    {
				    setCookie('RentalListingID',RentalListingID+ '@!@' + getCookie('RentalListingID'),0);
			    }
	    }
	    UName=getCookie('UName')
	    UserID=getCookie('UserID')
    	
	    if(UserID>0)
	    {
		    if(mlsid > 0)
		    {
		        ajaxManager('do_process','../Register/Process.aspx?PT=deleteProperty&UserID='+UserID+'&ListingIDs=' + mlsid +'&LinkIDs='+ LinkID + '&d=' + d,'../Register/MyFavorites.aspx');
		    }
		    else
		    {
		        ajaxManager('do_process','../Register/Process.aspx?PT=deleteProperty&UserID='+UserID+'&ListingIDs=' + RentalListingID +'&LinkIDs='+ LinkID + '&d=' + d,'../Register/MyFavorites.aspx');
		    }       	       
	    }	
    }	
}

function SaveProperty_Results(RentalListingID,mlsid,i,obj)
{
    //ActivityTrack(12,RentalListingID,mlsid,'');
    SaveProperty(RentalListingID,0,i,obj,mlsid)
}

function SaveProperty(RentalListingID,LinkID,i, objsrc,mlsid)
{
	var d = new Date();
	var UName='';
	var UserID='';
	UserID=getCookie('UserID')
	if(UserID>0)
	{
		if(LinkID>0)
		{
				if(!getCookie('LinkID'))
				{	
					setCookie('LinkID',LinkID,0);					
				}
				else
				{
					setCookie('LinkID',LinkID+ '@!@' + getCookie('LinkID'),0);					
				}
		}
		else
		{
				if(!getCookie('RentalListingID'))
				{	
					setCookie('RentalListingID',RentalListingID,0);
				}
				else
				{
					setCookie('RentalListingID',RentalListingID+ '@!@' + getCookie('RentalListingID'),0);
				}
		}
	UName=getCookie('UName')
	
	
	if(UserID>0)
		if(objsrc.src.toString().indexOf("images/b_add_to_my_tour.gif")>0)
	    {
		    if (mlsid > 0)
		    {
		        ajaxManager('do_process','../Register/Process.aspx?PT=save&UserID='+UserID+'&ListingIDs=' + mlsid +'&LinkIDs='+ LinkID + '&d=' + d);
		    }
		    else
		    {
		        ajaxManager('do_process','../Register/Process.aspx?PT=save&UserID='+UserID+'&ListingIDs=' + RentalListingID +'&LinkIDs='+ LinkID + '&d=' + d);
	        }
	        ajaxManager('load_box','../Register/Process.aspx?PT=display&UserID='+UserID+ '&ListingIDs=' + RentalListingID + '&MLSID=' + mlsid, 'ctl00_ctlHeader_divListingCnt')
	        objsrc.src="../images/b_remove_from_my_tour.gif";
	   }
	   else if(objsrc.src.toString().indexOf("images/b_remove_from_my_tour.gif")>0)
	   {
	        if(confirm('Are you sure you want to delete this property?'))
            {
	            if(LinkID>0)
	            {
		            if(!getCookie('LinkID'))
		            {	
			            setCookie('LinkID',LinkID,0);					
		            }
		            else
		            {
			            setCookie('LinkID',LinkID+ '@!@' + getCookie('LinkID'),0);					
		            }
	            }
	            else
	            {
			            if(!getCookie('RentalListingID'))
			            {	
				            setCookie('RentalListingID',RentalListingID,0);
			            }
			            else
			            {
				            setCookie('RentalListingID',RentalListingID+ '@!@' + getCookie('RentalListingID'),0);
			            }
	            }
	            UName=getCookie('UName')
	            UserID=getCookie('UserID')
            	
	            if(UserID>0)
	            {
		            if (mlsid > 0)
		            {
		                ajaxManager('do_process','../Register/Process.aspx?PT=deleteProperty&UserID='+UserID+'&ListingIDs=' + mlsid +'&LinkIDs='+ LinkID + '&d=' + d);
		            }
		            else
		            {
		                ajaxManager('do_process','../Register/Process.aspx?PT=deleteProperty&UserID='+UserID+'&ListingIDs=' + RentalListingID +'&LinkIDs='+ LinkID + '&d=' + d);	       
		            }    
        		     ajaxManager('load_box','../Register/Process.aspx?PT=update&UserID='+UserID,'ctl00_ctlHeader_divListingCnt')
        		    objsrc.src="../images/b_add_to_my_tour.gif";
	            }	
            }
	   }
	}
	else
	{
	    /*alert('Please Login/Register to Save this listing!')
	    window.location='../Register/?RentalListingID='+RentalListingID;*/
	    if(objsrc.src.toString().indexOf("images/b_add_to_my_tour.gif")>0)
	    {
	        if (mlsid > 0)
		    {
	            ajaxManager('do_process','../Register/Process.aspx?PT=saveTemp&ListingIDs=' + mlsid +'&LinkIDs='+ LinkID + '&d=' + d);    
	        }
	        else    
	        {
	            ajaxManager('do_process','../Register/Process.aspx?PT=saveTemp&ListingIDs=' + RentalListingID +'&LinkIDs='+ LinkID + '&d=' + d);    
	        }
	        ajaxManager('load_box','../Register/Process.aspx?PT=display&UserID='+UserID+ '&ListingIDs=' + RentalListingID + '&MLSID=' + mlsid,'ctl00_ctlHeader_divListingCnt')
	        objsrc.src="../images/b_remove_from_my_tour.gif";
        }
        else if(objsrc.src.toString().indexOf("images/b_remove_from_my_tour.gif")>0)
        {
            if (mlsid > 0)
		    {
                ajaxManager('do_process','../Register/Process.aspx?PT=deleteTemp&ListingIDs=' + mlsid +'&LinkIDs='+ LinkID + '&d=' + d);
            }
            else
            {
                ajaxManager('do_process','../Register/Process.aspx?PT=deleteTemp&ListingIDs=' + RentalListingID +'&LinkIDs='+ LinkID + '&d=' + d);
            }    
            //ajaxManager('load_box','../Register/Process.aspx?PT=update&UserID='+UserID,'ctl00_ctlHeader_divListingCnt')
            objsrc.src="../images/b_add_to_my_tour.gif";    
        }	        
	}
	return false;		
}
function savecookie(str)
{
	var intexpiredays;
	intexpiredays =99999;
	//alert(str);
	setCookie("strResultBar",str,intexpiredays);
	return true;
}
		
function getCookie(NameOfCookie)
	{ 
		if (document.cookie.length > 0) 
		{ 
			begin = document.cookie.indexOf(NameOfCookie+"="); 
			if (begin != -1) 
			{ 
				begin += NameOfCookie.length+1; 
				end = document.cookie.indexOf(";", begin);
				if (end == -1) end = document.cookie.length;
				return unescape(document.cookie.substring(begin, end)); 
			} 
		}
		return null; 
	}

function setCookie(NameOfCookie, value, expiredays) 
{	var ExpireDate = new Date ();
	if(expiredays==0)
		expiredays =99999;
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) + 
	((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()) + "; path=/;";
}
function replaceAll(str, find, replace) 
{
	var idx = str.indexOf(find);

	while ( idx > -1 ) {
		str = str.replace( find, replace );
		idx = str.indexOf( find );
	}
return str;
}