var ListingID_EmailTOFriend_Detail=0;
var ListingDetail_EmailToFriend='';
var SavedSearchID=new Array();
var setSaveCookie=false;
var strSearchText="boston";
var path;
var ListingID=new Array();
var UpdateFlag=false;
var LINKID=new Array();
var ListingInfo=new Array();

var evalScript="";
var redirect=false;
var recent=false;
var action='';


function JumpToPage()
{
	var arg;
	arg=JumpToPage.arguments;
	var d = new Date();//used to avoid caching in IE
	//document.getElementById("divFirstScript").innerHTML="";
	removeMarkers();
	ajaxManager('load_page','BindGrid.aspx?PageNo=' + arg[0] +'&d=' + d,'divBindGrid','divSearchCriteria');
	//alert(arg[0]);
	return false;
}

function btnSearchClick()
{
	var frm;
	frm=document.frm;
	var d = new Date();//used to avoid caching in IE
	var Options, Max, MIn, Size,Area;
	Options = frm.SelectOptions.options[frm.SelectOptions.selectedIndex].value
	Max = frm.SelectMax.options[frm.SelectMax.selectedIndex].value
	MIn = frm.SelectMIn.options[frm.SelectMIn.selectedIndex].value
	Size = frm.SelectSize.options[frm.SelectSize.selectedIndex].text
	Area = frm.SelectArea.options[frm.SelectArea.selectedIndex].value
	removeMarkers();
	ajaxManager('load_page','BindGrid.aspx?Options=' + Options + '&Max=' + Max + '&MIn=' + MIn + '&Size=' + Size + '&Area=' + Area +'&d=' + d,'divBindGrid');
	return false;
}


	 //var marker = new GMarker(point);
	// ====== This function displays the tooltip ======
	// it can be called from an icon mousover or a sidebar mouseover
	function showTooltip(marker) 
	{
		//eval(evalScript);
		
		if(marker)
		{	
      		tooltip.innerHTML = marker.tooltip;
			var point=mapX.getCurrentMapType().getProjection().fromLatLngToPixel(mapX.fromDivPixelToLatLng(new GPoint(0,0),true),mapX.getZoom());
			var offset=mapX.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),mapX.getZoom());
			var anchor=marker.getIcon().iconAnchor;
			var width=marker.getIcon().iconSize.width;
			var height=tooltip.clientHeight;
			var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height)); 
			pos.apply(tooltip);
			tooltip.style.visibility="visible";
			tooltip.style.width="100";
			
		}
		//alert(tooltip.style.width);
	}

	// ===== This function is invoked when the mouse goes over an entry in the sidebar =====
	// It launches the tooltip on the icon      
	function mymouseover(i) 
	{
		if(flagclick[i]!=1)
		{
			setBorder(i,'#FFBC79','5','SOLID');
			showTooltip(gmarkers[i]);
		}
		else{tooltip.style.visibility="hidden";gmarkers[i].openInfoWindowHtml(htmls[i]);}
	}
	// Creates a marker at the given point with the given number label
		function createMarker(point, number, counter, toolTip) {
		var marker = new GMarker(point);
		marker.tooltip = '<div class="tooltip">'+toolTip+'</div>';
		// save the info we need to use later for the sidebar
		gmarkers[i] = marker;
		var html="<table class='MLS_M'><tr valign='top'><td align='left'>" + number + "</td></tr></table>";
		htmls[i] = html;
		i=i+1;
		if (!marker.point) {marker.point = marker.getPoint();}
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(html);
		});
		GEvent.addListener(marker, "mouseover", function() {
			setBorder(counter,'#FFBC79','5','SOLID');
			//document.getElementById("idTb"+counter).style.borderColor="#FF0000";
			mymouseover(counter);
			//marker.openInfoWindowHtml(html);
		});
		GEvent.addListener(marker, "mouseout", function() {
			setBorder(counter,'','','');
			tooltip.style.visibility="hidden";
			//document.getElementById("idTb"+counter).style.borderColor="";
			//mapX.closeInfoWindow();	
		});
		return marker;
		}
	// ====== set up marker mouseover tooltip div ======
	
	
	/*alert("Length of htmls.length " +htmls.length)
	for(i=0;i<htmls.length;i++)
	{
		alert(htmls[i]);
	}*/	
	
	// This function picks up the click and opens the corresponding info window
	function myclick1(i) {
		try
		{
		gmarkers[i].openInfoWindowHtml(htmls[i]);									
		}
		catch(e)
		{}
	}
	function setBorder(i,color, width, style)
	{
		//alert(document.getElementById("idTdtp"+i).className);
		try
		{
			if(color=='#0000FF')
			{
				document.getElementById("idTdtp"+i).className="blueTD";
				document.getElementById("idTddn"+i).className="blueTD";
				document.getElementById("idTrtp"+i).className="blueTD";
				document.getElementById("idTrdn"+i).className="blueTD";			
				//document.getElementById("idTb"+i).className="blue";
			}	
			else if(color=='#FFBC79')
			{
				document.getElementById("idTdtp"+i).className="orangeTD";
				document.getElementById("idTddn"+i).className="orangeTD";
				document.getElementById("idTrtp"+i).className="orangeTD";
				document.getElementById("idTrdn"+i).className="orangeTD";
				//document.getElementById("idTb"+i).className="orange";
			}			
			else
			{	if(document.getElementById("idTdtp"+i))		
				{
					document.getElementById("idTdtp"+i).className="blankTD";
					document.getElementById("idTddn"+i).className="blankTD";
					document.getElementById("idTrtp"+i).className="blankTD";
					document.getElementById("idTrdn"+i).className="blankTD";
					//document.getElementById("idTb"+i).className="blank";		
				}
			}	
		}
		catch(e)
		{}	
		/*document.getElementById("idTb"+i).style.borderColor=color;
		document.getElementById("idTb"+i).style.borderLeftWidth=width;
		document.getElementById("idTb"+i).style.borderRightWidth=width;
		document.getElementById("idTb"+i).style.borderStyle=style;
		*/
	}
	// This function picks up the click and opens the corresponding info window
	function myover(i) 
	{
		if(flagclick[i]!=1)
		{
			setBorder(i,'#FFBC79','5','SOLID');	
			gmarkers[i].openInfoWindowHtml(htmls[i]);								
		}	
		else{gmarkers[i].openInfoWindowHtml(htmls[i]);}
	}
	function myout(i) {
		if(flagclick[i]!=1)
		{
			setBorder(i,'','','');
			tooltip.style.visibility="hidden";
			mapX.closeInfoWindow();	
		}	
	}
	function myclick(i) 
	{
		for(k=0;k<flagclick.length;k++)
		{
			flagclick[k]=0;
			setBorder(k,'','','');
		}
		setBorder(i,'#0000FF','5','SOLID');
		flagclick[i]=1;									
		gmarkers[i].openInfoWindowHtml(htmls[i]);
		tooltip.style.visibility="hidden";
	}
	function SetUpZoom()
	{
		var maxLat,minLat;
		maxLat=-1000.00;
		minLat=1000.00								
		//alert('LEngth '+latArray.length)
		for(i=0;i<latArray.length;i++)
		{
			//alert(i);
			for(j=0;j<15;j++)
			{	
				alert(mapX.getBounds().getSouthWest().lat() + " < " + latArray[i] +" < " +mapX.getBounds().getNorthEast().lat() +" "+latArray[i])
			
				if((mapX.getBounds().getSouthWest().lat()<latArray[i]) && (latArray[i]<mapX.getBounds().getNorthEast().lat()) && (mapX.getBounds().getSouthWest().lng()<lngArray[i]) && (lngArray[i]<mapX.getBounds().getNorthEast().lng()))
				{	//alert('Break');
					break;}
				else
				{	//alert('ZoomOut');
					mapX.zoomOut();	}
			}		
		}
	}
	
	function removeMarkers()
	{
		for(i=0;i<latArray.length;i++)
		{
			//mapX.removeOverlay(new GLatLng(latArray[i],lngArray[i]))
			mapX.removeOverlay(gmarkers[i]);
		}	
		latArray.length=0;
		lngArray.length=0;		
		flagclick.length=0;	
		htmls.length=0;
		gmarkers.length=0;	
		i=0;					
	}
	
	/*	For Weblink and RV2		*/
function JumpToPage_Combine()
{
	var arg;
	arg=JumpToPage.arguments;
	var d = new Date();//used to avoid caching in IE
	//document.getElementById("divFirstScript").innerHTML="";
	removeMarkers();
	ajaxManager('load_page','../Combine/BindGrid.aspx?PageNo=' + arg[0] +'&d=' + d,'divBindGrid');
	//alert(arg[0]);
	return false;
}

function btnSearchClick_Combine()
{
	var frm;
	frm=document.frm;
	var d = new Date();//used to avoid caching in IE
	var Options, Max, MIn, Size,Area;
	Options = frm.ctlSearchBox_SelectOptions.options[frm.ctlSearchBox_SelectOptions.selectedIndex].value
	Max = frm.ctlSearchBox_SelectMax.options[frm.ctlSearchBox_SelectMax.selectedIndex].value
	MIn = frm.ctlSearchBox_SelectMIn.options[frm.ctlSearchBox_SelectMIn.selectedIndex].value
	Size = frm.ctlSearchBox_SelectSize.options[frm.ctlSearchBox_SelectSize.selectedIndex].text
	Area = frm.ctlSearchBox_SelectArea.options[frm.ctlSearchBox_SelectArea.selectedIndex].value
	removeMarkers();
	if(document.getElementById('divDetails'))
	{
		document.getElementById('divDetails').style.display="NONE";
		document.getElementById('divBindGrid').style.display="BLOCK";
	}		
	ajaxManager('load_page','../Combine/BindGrid.aspx?Options=' + Options + '&Max=' + Max + '&MIn=' + MIn + '&Size=' + Size + '&Area=' + Area +'&d=' + d,'divBindGrid');
	return false;
}


function evaluate()
{	
	eval(evalScript);
	myclick1(0); 
	CheckLogin();	
}
//********************************************************************************************************
//Added on Date Jully 13, 2006
//Used for the search with the street address Open Fields
function btnSearchClick_CombineWhole()
{
	var frm;
	frm=document.frm;
	var d = new Date();//used to avoid caching in IE
	var Options, Max, MIn, Size,Area, StreetAddres, CityState;
	Options = frm.ctlSearchBox_SelectOptions.options[frm.ctlSearchBox_SelectOptions.selectedIndex].value;
	Max = frm.ctlSearchBox_SelectMax.options[frm.ctlSearchBox_SelectMax.selectedIndex].value;
	MIn = frm.ctlSearchBox_SelectMIn.options[frm.ctlSearchBox_SelectMIn.selectedIndex].value;
	Size = frm.ctlSearchBox_SelectSize.options[frm.ctlSearchBox_SelectSize.selectedIndex].text;
	Area = frm.ctlSearchBox_SelectArea.options[frm.ctlSearchBox_SelectArea.selectedIndex].value;
	
	StreetAddres = frm.ctlSearchBox_txtStreetAddress.value;
	CityState = frm.ctlSearchBox_txtCityState.value;
	
	removeMarkers();
	
	if(document.getElementById('divDetails'))
	{
		document.getElementById('divDetails').style.display="NONE";
		document.getElementById('divBindGrid').style.display="BLOCK";
	}		
	ajaxManager('load_page','../Combine/BindGrid.aspx?Options=' + Options + '&Max=' + Max + '&MIn=' + MIn + '&Size=' + Size + '&Area=' + Area + '&SA=' + StreetAddres + '&CS=' + CityState +'&d=' + d,'divBindGrid');
	return false;
}
//********************************************************************************************************
//Added on Date Jully 14, 2006
//Used for the search with the single Open Fields
function LoadResult(strSerach,strBed,strbath,strMin,strmax,strSQ,strType)
{	
	var d = new Date();
	ajaxManager('load_page','../Combine/BindGrid.aspx?Search=' + strSerach +'&Bed='+strBed+'&Bath='+strbath+'&Min='+strMin+'&Max='+strmax+'&SQ='+strSQ +'&Tp='+strType +'&d=' + d,'divBindGrid');
	//ajaxManager('load_page','../Combine/BindGrid.aspx?Search=' + strSerach +'&Bed='+strBed+'&Bath='+strbath+'&Min='+strMin+'&Max='+strmax+'&SQ='+strSQ +'&Tp='+strType +'&d=' + d,'divBindGrid');
	return false;
}
function LoadResultListing(strSerach,strBed,strbath,strMin,strmax,strSQ,strType)
{	
	var d = new Date();
	ajaxManager('load_page','../listing/BindGrid.aspx?Search=' + strSerach +'&Bed='+strBed+'&Bath='+strbath+'&Min='+strMin+'&Max='+strmax+'&SQ='+strSQ +'&Tp='+strType +'&d=' + d,'divBindGrid','LoadNewSearchCriteria');
	//ajaxManager('load_page','../Combine/BindGrid.aspx?Search=' + strSerach +'&Bed='+strBed+'&Bath='+strbath+'&Min='+strMin+'&Max='+strmax+'&SQ='+strSQ +'&Tp='+strType +'&d=' + d,'divBindGrid');
	
	return false;
}
function LoadResultListing_Account(strSerach)
{	
	var d = new Date();
	window.location ='../listing/default.aspx?Search=' + document.frm.txtSearch.value;
	//ajaxManager('load_page','../Combine/BindGrid.aspx?Search=' + strSerach +'&Bed='+strBed+'&Bath='+strbath+'&Min='+strMin+'&Max='+strmax+'&SQ='+strSQ +'&Tp='+strType +'&d=' + d,'divBindGrid');
	
	return false;
}
function LoadListing()
{	
	removeMarkers();
	var frm;
	frm=document.frm;
	var d = new Date();//used to avoid caching in IE
	var strSerach,strBed,strbath,strMin,strmax,strSQ,strType;
	strSerach="";strBed="";strbath="";strMin="";strmax="";strSQ="";strType="";
	strSerach =frm.txtSearch.value	
	strType = frm.ddlType.options[frm.ddlType.selectedIndex].value;
	if(strType=="N") strType="";
	//if (frm.txtMin.value!="Min") strMin = frm.txtMin.value;
	if(frm.ddlMin.selectedIndex > 0)
		strMin = frm.ddlMin.options[frm.ddlMin.selectedIndex].value;
	if(frm.ddlMax.selectedIndex > 0)
		strmax = frm.ddlMax.options[frm.ddlMax.selectedIndex].value;
		
	//if (frm.txtMax.value!="Max")	strmax = frm.txtMax.value;
	if(frm.ddlBed.selectedIndex > 0)
		strBed = frm.ddlBed.options[frm.ddlBed.selectedIndex].value;		
	if(frm.ddlBath.selectedIndex > 0)
		strbath = frm.ddlBath.options[frm.ddlBath.selectedIndex].value;	
	if(frm.ddlSQ.selectedIndex > 0)
		strSQ = frm.ddlSQ.options[frm.ddlSQ.selectedIndex].value;
	setSaveCookie =true;
	ajaxManager('load_page','../listing/BindGrid.aspx?T=1&Search=' + strSerach +'&Bed='+strBed+'&Bath='+strbath+'&Min='+strMin+'&Max='+strmax+'&SQ='+strSQ +'&Tp='+strType +'&Ts=RemoveSession&d=' + d,'divBindGrid','LoadNewSearchCriteria');
	//ajaxManager('load_page','../Combine/BindGrid.aspx?Search=' + strSerach +'&Bed='+strBed+'&Bath='+strbath+'&Min='+strMin+'&Max='+strmax+'&SQ='+strSQ +'&Tp='+strType +'&d=' + d,'divBindGrid');
	return false;
}
function ShowResult(str)
{
	removeMarkers();
	
	var d = new Date();//used to avoid caching in IE
	
	if(document.getElementById('divDetails'))
	{
		document.getElementById('divDetails').style.display="NONE";
		document.getElementById('divBindGrid').style.display="BLOCK";
	}
	ajaxManager('load_page','../listing/BindGrid.aspx?' + str + '&T=Bind&d=' + d,'divBindGrid','LoadNewSearchCriteria');
	//ajaxManager('load_page','../Combine/BindGrid.aspx?Search=' + strSerach +'&Bed='+strBed+'&Bath='+strbath+'&Min='+strMin+'&Max='+strmax+'&SQ='+strSQ +'&Tp='+strType +'&d=' + d,'divBindGrid');
	return false;
}
/*function btnSearchClick_Home()
{
	var frm;
	frm=document.frm;
	var d = new Date();//used to avoid caching in IE
	var strSearch='';	
	strSearch = frm.txtSearch.value;		
	
	ajaxManager('load_page','Combine/Default.aspx?Search=' + strSearch +'&d=' + d,'divBindGrid');
	return false;
}
*/
function LoadListingDetails()
{
	//removeMarkers();
	//alert('redirecting');
	var d = new Date();//used to avoid caching in IE
	var frm;frm=document.frm;	
	var strSerach;
	strSerach="";
	strSerach =frm.txtSearch.value;
	window.location='default.aspx?PageNo=1&Search=' + strSerach +'&d=' + d;
	
	
		
	//ajaxManager('load_page','../listing/BindGrid.aspx?T=1&Search=' + strSerach +'&Ts=RemoveSession&d=' + d,'divBindGrid','LoadNewSearchCriteria');
	//ajaxManager('load_page','../Combine/BindGrid.aspx?Search=' + strSerach +'&Bed='+strBed+'&Bath='+strbath+'&Min='+strMin+'&Max='+strmax+'&SQ='+strSQ +'&Tp='+strType +'&d=' + d,'divBindGrid');
	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 FillCookie()
{
	//alert(getCookie('strResultBar'));	
	var UserID=getCookie('UserID')
	if(!redirect)
	{
	    if(document.getElementById('divResultBar'))
		    document.getElementById('divResultBar').innerHTML=getCookie('strResultBar');
		//setCookie("",document.getElementById('divResultBar').innerHTML,0)
	}
	else
	{
		if(UserID>0)
			document.getElementById('divResultBar').innerHTML="<div style=\'width:500px;\'><b>My VOXlia</b> —save your favorite properties, and set email alerts for new listings.</div>";	
		else
			document.getElementById('divResultBar').innerHTML="<div style=\'width:500px;\'><b>My VOXlia</b> —<div id=\'divLoginRB\' style=\'Z-INDEX: 1; LEFT: 20px; POSITION: absolute; BACKGROUND-COLOR: #ffffff\'></div><a href=\'#\' onClick=\'SignUp(\"divLoginRB\")\'>Sign up</a> with VOXlia to save your favorite properties and searches, manage your email alerts, and more. Already have an account? <a href=\'#\' onClick=\'Login(\"divLoginRB\")\'>Login</a>.</div>";		
	}		

	return false;
}
function Login(divID)
{
	var d = new Date();
	//document.getElementById(divID).innerHTML =document.getElementById('LoginForm').innerHTML
	ajaxManager('load_box',path+'Account/login.asp?d=' + d,divID);
	
}
function SignUp(divID)
{
	var d = new Date();
	//document.getElementById(divID).innerHTML =document.getElementById('LoginForm').innerHTML
	ajaxManager('load_box',path+'Account/signup.asp?d=' + d,divID);
	
}
function Forgot(divID)
{
	var d = new Date();
	//document.getElementById(divID).innerHTML =document.getElementById('LoginForm').innerHTML
	ajaxManager('load_box',path+'Account/forgot.htm?d=' + d,divID);
	
}
function show(f)
{
  if (document.getElementById(f))
    document.getElementById(f).style.display = 'BLOCK';
}

function hide(f)
{
  if (document.getElementById(f))
    document.getElementById(f).style.display = 'none';
}
function ShowHide(d)
{
	if(document.getElementById(d))
		if(document.getElementById(d).style.display == 'none' || document.getElementById(d).style.display == '')
			document.getElementById(d).style.display = 'BLOCK';
		else
			document.getElementById(d).style.display = 'none';	
}
function LoadInnerSavedMsg(SalesListingID,LinkID,i)
{
	var str='';
	try
	{
		if(document.getElementById('divSavedPropInfo'+i)&&document.getElementById('divAddress'+i))
		{
			var obj =document.getElementById('divSavedPropInfo'+i);
			str =str+"<div style=\'padding:5 5 5 5;\'><table class=\'ResultsSmall\' width=\'150\' height=\'100\'  border=\'0\' cellpadding=\'0\' cellspacing=\'0\'><tr valign=\'top\'><td valign=\'top\' align=\'right\'><img align=\'right\' style=\'cursor:pointer;\' src=\'../images/close_bubble.png\' alt=\'Close\' onclick=\'hide(\"divSavedPropInfo"+i+"\");\' /></td></tr>";
			str =str+"<tr><td valign=\'top\'><b>" + document.getElementById('divAddress'+i).innerHTML +"</b><br> has been saved to <a href=\'../Account/\'>My VOXlia</a></td></tr>";
			//str =str+"<tr><td  valign=\'top\' style=\'border-top:1px solid #C3C3C3;\'>&nbsp;</td></tr>";
			str =str+"<tr><td><a href=\'#\' onClick=\'Login(\"divLoginR\")\'>log in</a> or <a href=\'#\' onClick=\'SignUp(\"divLoginR\")\'>Sign up</a> to see all your favorite properties and saved searches.</td></tr></table></div>";
			obj.innerHTML=str;
			obj.style.display="BLOCK";
			//obj.className="ResultsSmall";
		}
	}
	catch(e)
	{}	
}

function DeleteProperty(SalesListingID,LinkID,i)
{
	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('SalesListingID'))
			    {	
				    setCookie('SalesListingID',SalesListingID,0);
			    }
			    else
			    {
				    setCookie('SalesListingID',SalesListingID+ '@!@' + getCookie('SalesListingID'),0);
			    }
	    }
	    UName=getCookie('UName')
	    UserID=getCookie('UserID')
    	
	    if(UserID>0)
	    {
		    ajaxManager('do_process','../Account/process.aspx?PT=deleteProperty&UserID='+UserID+'&ListingIDs=' + SalesListingID +'&LinkIDs='+ LinkID + '&d=' + d,'../Account/');	       
		        
	    }	
    }	
}

function SaveProperty_Results(SalesListingID,mlsid,i)
{
    ActivityTrack(12,SalesListingID,mlsid,'');
    SaveProperty(SalesListingID,0,i)
}

function SaveProperty(SalesListingID,LinkID,i, control)
{
	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('SalesListingID'))
				{	
					setCookie('SalesListingID',SalesListingID,0);
				}
				else
				{
					setCookie('SalesListingID',SalesListingID+ '@!@' + getCookie('SalesListingID'),0);
				}
		}
	UName=getCookie('UName')
	
	
	if(UserID>0)
		ajaxManager('do_process','../Account/process.aspx?PT=save&UserID='+UserID+'&ListingIDs=' + SalesListingID +'&LinkIDs='+ LinkID + '&d=' + d);
	    if(document.getElementById('spnSave'+i))
	    {
	        var strHTML=document.getElementById('spnSave'+i).innerHTML;
	        strHTML = replaceAll(strHTML,"Save","Delete");
            strHTML = replaceAll(strHTML,"<b>Delete</b>","<b>Remove from Saved List</b>");	        
	        document.getElementById('spnSave'+i).innerHTML=strHTML;
	    }
	}
	else
	{
	    alert('Please Login/Register to Save this listing!')
	    window.location='../login/?SalesListingID='+SalesListingID;    
	}
	return false;		
}
function Logout()
{
	setCookie('UName','',0);
	setCookie('UserID','',0);	
	setCookie('SalesListingID','',0);
	setCookie('LinkID','',0);
	setCookie("redirect","",0);
	if(document.getElementById('divUserName'))
		document.getElementById('divUserName').innerHTML='';
	ShowLogin();
	DisplayLoggedIn();
	var d = new Date();	
	ajaxManager('do_process',path+'Account/processing.aspx?PT=logout&d=' + d);	
	window.location =path;
}
function DisplayLoggedIn()
{
	var UName='';
	UName=getCookie('UName');
		
	if(UName!='' && UName!=null)
	{
		if(UName.indexOf('@')>0)
			UName =UName.substring(0,UName.indexOf('@'));
		document.getElementById('divUserName').innerHTML='';
		//alert('Setting username in Div');
		document.getElementById('divUserName').innerHTML='Welcome ' +UName;
	}
	if(redirect && getCookie("redirect")=="true")
	{
		setCookie("redirect","false",0);
		window.location=path+'Account/';
		redirect=false;
	}
	//window.location=path+'Account/?UserID=' +getCookie('UserID');	
	return false;
}
function CheckLogin()
{
	if(getCookie('UName'))
		{
			ShowLogout();
			DisplayLoggedIn();
		}
		else
		{
			ShowLogin();
		}	
}
function ShowLogin()
{
	
	document.getElementById('divLoginSigninLogout').innerHTML="<a href=\'"+path+"Account/\'>My VOXlia</a>&nbsp;<span style=\'font-weight:normal;\'>|</span>&nbsp;<a href=\'#\' onClick=\'Login(\"divLoginR\")\'>Login</a>&nbsp;<span style=\'font-weight:normal;\'>|</span>&nbsp;<a href=\'#\' onClick=\'SignUp(\"divLoginR\")\'>Sign up</a>";
	document.getElementById('divLoginSigninLogout').style.display="BLOCK";
}
function ShowLogout()
{
	var UserID=getCookie('UserID')
	if(UserID!='')
		document.getElementById('divLoginSigninLogout').innerHTML="<a href=\'"+path+"Account/\'>My VOXlia</a>&nbsp;<span style=\'font-weight:normal;\'>|</span>&nbsp;<a href=\'#\' onClick=\'Logout();\'>Log out</a>";
		//document.getElementById('divLoginSigninLogout').innerHTML="<a href=\'"+path+"Account/?UserID="+UserID+"\'>My</a>&nbsp;<span style=\'font-weight:normal;\'>|</span>&nbsp;<a href=\'#\' onClick=\'Logout();\'>Log out</a>";
	else
		document.getElementById('divLoginSigninLogout').innerHTML="<a href=\'"+path+"Account/\'>My VOXlia</a>&nbsp;<span style=\'font-weight:normal;\'>|</span>&nbsp;<a href=\'#\' onClick=\'Logout();\'>Log out</a>";
	document.getElementById('divLoginSigninLogout').style.display="BLOCK";
}

	
		
function LoadSavedListing(SalesListingIDs,LinkIDs)
{	
	var d = new Date();
	/*alert(SalesListingIDs);
	alert(LinkIDs);
	*/
	/*var SalesListingIDs='';
	var LinkIDs='';*/
	if(getCookie('SalesListingID'))
	{	
		if(SalesListingIDs=='')
			SalesListingIDs= getCookie('SalesListingID');
		else
			SalesListingIDs=SalesListingIDs+'@!@'+ getCookie('SalesListingID');
	}		
	
	if(getCookie('LinkID'))
	{
		if(LinkIDs=='')
			LinkIDs= getCookie('LinkID');		
		else
			LinkIDs= LinkIDs +'@!@'+getCookie('LinkID');		
	}	
	recent=false;	
	ajaxManager('load_page','../listing/Recent.aspx?ListingIDs=' + SalesListingIDs +'&LinkIDs='+LinkIDs +'&d=' + d,'divBindGrid','LoadNewSearchCriteria');
	/*if(document.getElementById('divRecentlyViewed'))
	{
		recent=true;
		ajaxManager('load_page','../listing/BindGrid.aspx?ListingIDs=' + SalesListingIDs +'&LinkIDs='+LinkIDs +'&d=' + d,'divRecentlyViewed','LoadNewSearchCriteria');
	}	
	//ajaxManager('load_page','../Combine/BindGrid.aspx?Search=' + strSerach +'&Bed='+strBed+'&Bath='+strbath+'&Min='+strMin+'&Max='+strmax+'&SQ='+strSQ +'&Tp='+strType +'&d=' + d,'divBindGrid');
	*/
	return false;
}
function CheckSaved()
{
	var divSaveID='';
	var i=0;
	var SalesListingIDs= getCookie('SalesListingID');
	var LinkIDs= getCookie('LinkID');
	if(action=='del')
	{	for(i=0;i<ListingID.length;i++)
		{
			if(document.getElementById('divSave'+i).innerHTML=='Delete')
				document.getElementById('divSave'+i).innerHTML='Delete'
		}
	}
	for(i=0;i<ListingID.length;i++)
	{
		if(SalesListingIDs!='' && SalesListingIDs!=null)
		{
			if(SalesListingIDs.toString().indexOf(ListingID[i])>=0)
			{
				if(document.getElementById('divSave'+i).innerHTML!='Delete')
				{
					document.getElementById('divSave'+i).innerHTML='Saved';
					document.getElementById('divSave'+i).className='saveYellow';
				}	
			}	
		}	
		if(LinkIDs!='' && LinkIDs!=null)
			if(SalesListingIDs.toString().indexOf('-'+ListingID[i])>=0)	
				if(document.getElementById('divSave'+i).innerHTML!='Delete')
				{
					document.getElementById('divSave'+i).innerHTML='Saved';
					document.getElementById('divSave'+i).className='saveYellow';
				}	
	}
}
function SortBy(val)
{
	removeMarkers();
	var d = new Date();
	if(val>0)
		ajaxManager('load_page','../listing/BindGrid.aspx?SortBy=' + val +'&d=' + d,'divBindGrid','LoadNewSearchCriteria');
	
}
function LoadMySearch()
{
	var d = new Date();
	/*var SalesListingIDs='';
	var LinkIDs='';*/
	/*if(getCookie('SalesListingID'))
	{	
		if(SalesListingIDs=='')
			SalesListingIDs= getCookie('SalesListingID');
		else
			SalesListingIDs=SalesListingIDs+'@!@'+ getCookie('SalesListingID');
	}		
	
	if(getCookie('LinkID'))
	{
		if(LinkIDs=='')
			LinkIDs= getCookie('LinkID');		
		else
			LinkIDs= LinkIDs +'@!@'+getCookie('LinkID');		
	}	
	recent=false;
	ajaxManager('load_page','../listing/BindGrid.aspx?ListingIDs=' + SalesListingIDs +'&LinkIDs='+LinkIDs +'&d=' + d,'divBindGrid','LoadNewSearchCriteria');
	
	if(document.getElementById('divRecentlyViewed'))
	{
		recent=true;
		ajaxManager('load_page','../listing/BindGrid.aspx?ListingIDs=' + SalesListingIDs +'&LinkIDs='+LinkIDs +'&d=' + d,'divRecentlyViewed','LoadNewSearchCriteria');
	}	
	//ajaxManager('load_page','../Combine/BindGrid.aspx?Search=' + strSerach +'&Bed='+strBed+'&Bath='+strbath+'&Min='+strMin+'&Max='+strmax+'&SQ='+strSQ +'&Tp='+strType +'&d=' + d,'divBindGrid');
	*/
	return false;	
}

function LoadPaging()
{
	if(document.getElementById('ddlPagesHTML'))
	{
		if(document.getElementById('lnkPrev')&&document.getElementById('ddlPagesHTML'))
			if(document.getElementById('ddlPagesHTML').selectedIndex==0) 	
				document.getElementById('lnkPrev').style.display = "none";
			else
				document.getElementById('lnkPrev').style.display = "block";	
			
		if(document.getElementById('lnkNext')&&document.getElementById('ddlPagesHTML'))
			if(document.getElementById('ddlPagesHTML').selectedIndex==document.getElementById('ddlPagesHTML').options.length-1) 	
				document.getElementById('lnkNext').style.display = "none";
			else
				document.getElementById('lnkNext').style.display = "block";	
	}			
	LoadPagingUP();
}				
function nextClick() 
{
	if(document.getElementById('ddlPagesHTML').selectedIndex<document.getElementById('ddlPagesHTML').options.length-1)
	{
		document.getElementById('lnkPrev').style.display = "block";
		document.getElementById('ddlPagesHTML').options[eval(document.getElementById('ddlPagesHTML').selectedIndex+1)].selected=true ;				
	}
	else
	{
		document.getElementById('lnkNext').style.display = "none";
		document.getElementById('ddlPagesHTML').options[eval(document.getElementById('ddlPagesHTML').selectedIndex+1)].selected=true ;				
	}
	nextClickUP();
	JumpToPage(document.getElementById('ddlPagesHTML').options[document.getElementById('ddlPagesHTML').selectedIndex].value);
	return true;
	
}
function prevClick() 
{
	if(document.getElementById('ddlPagesHTML').selectedIndex-1!=0)
	{
		document.getElementById('lnkNext').style.display = "block";
		document.getElementById('ddlPagesHTML').options[eval(document.getElementById('ddlPagesHTML').selectedIndex-1)].selected=true ;
	}
	else
	{
		document.getElementById('lnkPrev').style.display = "none";
		document.getElementById('ddlPagesHTML').options[eval(document.getElementById('ddlPagesHTML').selectedIndex-1)].selected=true ;
	}
	prevClickUP(); 
	JumpToPage(document.getElementById('ddlPagesHTML').options[document.getElementById('ddlPagesHTML').selectedIndex].value);
	return true;
}
function LoadPagingUP()
{
	if(document.getElementById('ddlPagesUPHTML'))
	{
		if(document.getElementById('lnkPrevUP')&&document.getElementById('ddlPagesUPHTML'))
			if(document.getElementById('ddlPagesUPHTML').selectedIndex==0) 	
				document.getElementById('lnkPrevUP').style.display = "none";
			else
				document.getElementById('lnkPrevUP').style.display = "block";	
			
		if(document.getElementById('lnkNextUP')&&document.getElementById('ddlPagesUPHTML'))
			if(document.getElementById('ddlPagesUPHTML').selectedIndex==document.getElementById('ddlPagesUPHTML').options.length-1) 	
				document.getElementById('lnkNextUP').style.display = "none";
			else
				document.getElementById('lnkNextUP').style.display = "block";	
	}			
}				
function nextClickUP() 
{
	if(document.getElementById('ddlPagesUPHTML').selectedIndex<document.getElementById('ddlPagesUPHTML').options.length-1)
	{
		document.getElementById('lnkPrevUP').style.display = "block";
		document.getElementById('ddlPagesUPHTML').options[eval(document.getElementById('ddlPagesUPHTML').selectedIndex+1)].selected=true ;				
	}
	else
	{
		document.getElementById('lnkNextUP').style.display = "none";
		document.getElementById('ddlPagesUPHTML').options[eval(document.getElementById('ddlPagesUPHTML').selectedIndex+1)].selected=true ;				
	}
	//JumpToPage(document.getElementById('ddlPagesUPHTML').options[document.getElementById('ddlPagesUPHTML').selectedIndex].value);
	return true;
	
}
function prevClickUP() 
{
	if(document.getElementById('ddlPagesUPHTML').selectedIndex-1!=0)
	{
		document.getElementById('lnkNextUP').style.display = "block";
		document.getElementById('ddlPagesUPHTML').options[eval(document.getElementById('ddlPagesUPHTML').selectedIndex-1)].selected=true ;
	}
	else
	{
		document.getElementById('lnkPrevUP').style.display = "none";
		document.getElementById('ddlPagesUPHTML').options[eval(document.getElementById('ddlPagesUPHTML').selectedIndex-1)].selected=true ;
	}
	//JumpToPage(document.getElementById('ddlPagesUPHTML').options[document.getElementById('ddlPagesUPHTML').selectedIndex].value);
	return true;
}

function AddViewedListing(rv2id,mlsid,linkid,str)
{
	var i=0;
	i=LINKID.length;
	var strLink='';//'listing/Details.aspx?LINK=?'+linkid;
	var strInfo=str;
	if(linkid!='')
		strLink='listing/Details.aspx?LINK='+linkid;
	else
		strLink='listing/Details.aspx?BostonRealEstate=' + rv2id + '&mls='+ mlsid;
	//if(getCookie('Cookie_link')&& getCookie('Cookie_info'))
	{
		var Cookie_link=getCookie('Cookie_link');
		var Cookie_info=getCookie('Cookie_info');
		if(Cookie_link == null )
			Cookie_link ='';
		if(Cookie_info == null )
			Cookie_info ='';
			
		var Link = Cookie_link.split('@!@');
		var Info = Cookie_info.split('@!@');
		var flag=true;
		for(i=0;i<Link.length;i++)
		{
			if((Link[i]==strLink) && (Info[i]==strInfo))
			{
				flag=false;
				break;
			}
		}
		
		if(flag && Cookie_info=='' && Cookie_link=='')
		{
			strLink = strLink;
			strInfo = strInfo;					
			setCookie('Cookie_link',strLink,99999);
			setCookie('Cookie_info',strInfo,99999);	
		}
		else if(flag && Cookie_info!='' && Cookie_link!='')		
		{
			strLink = Cookie_link + '@!@' + strLink;
			strInfo = Cookie_info + '@!@' + strInfo;					
			setCookie('Cookie_link',strLink,99999);
			setCookie('Cookie_info',strInfo,99999);	
		}	
	}	
	
}
function LoadRecentlyViewedListingInfo(div)
{
	var i=0;
	var j=0;
	var str='';
	if(getCookie('Cookie_link')&& getCookie('Cookie_info') && document.getElementById(div))
	{
		var Cookie_link=getCookie('Cookie_link');
		var Cookie_info=getCookie('Cookie_info');
		var Link = Cookie_link.split('@!@');
		var Info = Cookie_info.split('@!@');
		if(Link.length>4)
			j=4;
		else
			j=Link.length;	
		for(i=0;i<j;i++)
		{
			str = str + " &bull; <a href=\'" + path + Link[i] + "\' title=\'" + Info[i].replace("<B>","").replace("</B>","") + "\'>" + Info[i] + "...</a><br>"
		}
		
	}
	if(str!='')
	{
		str= "<br><SPAN class=\'home_box_header_small\'>RECENT PROPERTIES</SPAN><span id=\'divReacentViewed\'><span class=\'smallText\'> (<a href=\'#\' onClick=\'DeleteRecent(\"divReacentViewed\");\'>delete all</a>)</span><br>" + str +"</span>";
		//str =str + "<br>Don\'t have an account? <a href=\'#\' onClick=\'SignUp(\"divLoginRS\")\'>Sign Up</a> to save your favorite properties and searches. It\'s fast and it\'s free!";
		document.getElementById(div).innerHTML=str;
	}
	//Load the Recently Searched Criteria
	LoadRecentlySearchedCriteria(div)
	
	CheckLogin();	
}

function DeleteRecent(div)
{
	if(confirm('Are you sure you want to delete all your recently viewed properties?'))
	{setCookie('Cookie_link','',999);
	setCookie('Cookie_info','',999);
	document.getElementById(div).innerHTML='<br>No recently viewed properties!<br>';
	}	
}
function DeleteRecentSearch(div)
{
	if(confirm('Are you sure you want to delete all your recently searches?'))
	{setCookie('CC_SSI','',999);
	setCookie('CC_SSL','',999);
	document.getElementById(div).innerHTML='<br>No recent search!<br>';	
	}
}


/***********/

function resetTEXT(id, resetval, ifval)
{ 
	
  var e = document.getElementById(id);  
  if (e && (e.value == ifval || trim(e.value) == ''))
    e.value = resetval;
}
function clearTEXT(id,val)
{
  var e = document.getElementById(id);
  if (e && e.value == val)
    e.value = '';
}
// misc. text-related functions
function trim(s)
{
  if (!s)
    return '';   
  return s.replace(/^\s*|\s*$/g,"");
}

function SplitSearch(str)
{alert(str)
	var strSearch=str.split(";,");
	var i=0;
	for(i=0;i<strSearch.length;i++)	
	{
		
		switch(i)
		{
			//Search string
			case 0:{	if(strSearch[i]!='' && document.getElementById("txtSearch"))
						document.getElementById("txtSearch").value = strSearch[i];
						break;}
			//Bedrooms			
			case 1:{	var obj=document.getElementById("ddlBed");
						if(strSearch[i]!='' && obj)
						{	for (var j = 0; j < obj.length; j++){ if (obj[j].value == strSearch[i]){ obj.selectedIndex = j; }}}
					break;
					}
			//Baths
			case 2:{	var obj=document.getElementById("ddlBath");
						if(strSearch[i]!='' && obj)
						{	for (var j = 0; j < obj.length; j++){ if (obj[j].value == strSearch[i]){ obj.selectedIndex = j; }}}					
					break;}
			//Min price		frm.ddlMin.options[frm.ddlMin.selectedIndex].value
			case 3:{	var obj=document.getElementById("ddlMin");						
						if(strSearch[i]!='' && obj)
						{	for (var j = 0; j < obj.length; j++){ if (obj[j].value == strSearch[i]){ obj.selectedIndex = j; }}}					
					break;}
			//Max price		
			case 4:{	var obj=document.getElementById("ddlMax");
						if(strSearch[i]!='' && obj)
						{	for (var j = 0; j < obj.length; j++){ if (obj[j].value == strSearch[i]){ obj.selectedIndex = j; }}}					
					break;}
			//SQ
			case 5:{	var obj=document.getElementById("ddlSQ");
						if(strSearch[i]!='' && obj)
						{	for (var j = 0; j < obj.length; j++){ if (obj[j].value == strSearch[i]){ obj.selectedIndex = j; }}}					
					break;}
			//Type
			case 6:{	var obj=document.getElementById("ddlType");
						if(strSearch[i]!='' && obj)
						{	for (var j = 0; j < obj.length; j++){ if (obj[j].value == strSearch[i]){ obj.selectedIndex = j; }}}					
					break;}
			
		}
		//strSearch[i];
	}
}

 function showtextbox()
{	
	if(document.getElementById('divForm').style.display=="block" )
	{
		if(document.getElementById('divMessage'))
			document.getElementById('divMessage').innerHTML=''
		document.getElementById('spupdate').innerHTML="Account Summary";
		document.getElementById('divForm').style.display="none"
		document.getElementById('divInformation').style.display="BLOCK"		
	}
	else
	{
		document.getElementById('spupdate').innerHTML="Update Setting";
		document.getElementById('divForm').style.display="BLOCK";
		document.getElementById('divInformation').style.display="none";	
	}
}


function ShowHideDiv(div,img)
{
	var divs = document.getElementById(div);
	if(divs)
	{
	if (divs.style.display == "none")
	{
		document.getElementById(img).src=document.getElementById(img).src.toString().replace("triangle_horiz.","triangle.");
		divs.style.display = "";
	}
	else 
	{
		document.getElementById(img).src=document.getElementById(img).src.toString().replace("triangle.","triangle_horiz.");
		divs.style.display = "none";
	}
	}
}
function ShowHideDivMyaccount(pass)
{
	var divs = document.getElementById(pass);
	if(divs)
	{
		if (divs.style.display == "none")
		{
			divs.style.display = "";
		}
		else 
		{
			divs.style.display = "none";
		}
	}
}
function FillAccountSetting()
{
	var args = FillAccountSetting.arguments;
	if(args.length>0)	
	{
		document.getElementById('txtEmail').value=args[0];
		document.getElementById('divEmail').innerHTML=args[0];
		
		document.getElementById('txtPassword').value=args[1];
		for(var i=0;i<args[1].length;i++)
			document.getElementById('divPassword').innerHTML +='*';
		
		document.getElementById('txtName').value=args[2];
		document.getElementById('divName').innerHTML=args[2];
		
		document.getElementById('txtLocation').value=args[3];
		document.getElementById('divLocation').innerHTML=args[3];
		if(args[4]=='Y')
		{
			document.getElementById('chk').checked=true;
			document.getElementById('divChk').innerHTML='Yes , send me occasional Boston Real Estate news and updates';
		}	
		else
		{			
			document.getElementById('chk').checked=false;
			document.getElementById('divChk').innerHTML='No ,Don\'t send me occasional Boston Real Estate news and updates';
		}		
	}
}
function CheckLoginAccountTimeOut()
{
	var UName=getCookie('UName')
	//alert(getCookie('UserID'));
	if(UName!='' && UName !=null)
	{
		hide('divLoginSignupMsgbox');
		hide('divForm');
		show('divInformation');
	}	
	else
	{
		show('divLoginSignupMsgbox');	
		hide('divForm');
		hide('divInformation');
		hide('spupdate');
	}	
	FillCookie();
	CheckLogin();	
	LoadRecentlySearchedCriteriaACCOUNT('divRecentSearchA');
	
	//LoadRecentlySearchedCriteriaACCOUNT('divABCD');

}
function CheckLoginAccount()
{
	setTimeout("CheckLoginAccountTimeOut()",6000);	
}
function CopyValues()
{

	if(document.getElementById('divEmail').innerHTML!=document.getElementById('txtEmail').value)
	{
		UpdateFlag=true;document.getElementById('divEmail').innerHTML=document.getElementById('txtEmail').value;
	}
	
	if(document.getElementById('divPassword').innerHTML.length !=document.getElementById('txtPassword').value.length)
	{
		UpdateFlag=true;
		document.getElementById('divPassword').innerHTML ='';
		for(var i=0;i<document.getElementById('txtPassword').value.length;i++)
			document.getElementById('divPassword').innerHTML +='*';
	}
	if(document.getElementById('divName').innerHTML!=document.getElementById('txtName').value)
	{
		UpdateFlag=true;
		document.getElementById('divName').innerHTML=document.getElementById('txtName').value;
	}		
	if(document.getElementById('divLocation').innerHTML!=document.getElementById('txtLocation').value)
	{	
		UpdateFlag=true;
		document.getElementById('divLocation').innerHTML=document.getElementById('txtLocation').value;
	}
	if(document.getElementById('chk').checked && document.getElementById('divChk').innerHTML!='Yes , send me occasional Boston Real Estate news and updates')
	{
		UpdateFlag=true;
		document.getElementById('divChk').innerHTML='Yes , send me occasional Boston Real Estate news and updates';
	}
	else if(!document.getElementById('chk').checked && document.getElementById('divChk').innerHTML!='No ,Don\'t send me occasional Boston Real Estate news and updates')
	{
		UpdateFlag=true;	
		document.getElementById('divChk').innerHTML='No ,Don\'t send me occasional Boston Real Estate news and updates';
	}	
}

/*************************************************************************/
//Save to Save list and remove from the viewed List
function SavePropertyRecentlyViewd(SalesListingID,LinkID,i)
{
	var d = new Date();
	var UName='';
	var UserID='';
	//Save the listing in Cookie and remove from Recently Viewed
	if(document.getElementById('divSave'+i).innerHTML=='Save')
	{
		document.getElementById('divSave'+i).innerHTML='Saved';	
		document.getElementById('divSave'+i).className='saveYellow';	
		//Open Small Window
		LoadInnerSavedMsg(SalesListingID,LinkID,i);
		if(LinkID>0)
		{
				if(!getCookie('LinkID'))
				{	
					setCookie('LinkID',LinkID,0);	
					RemoveRecentlyViewed(SalesListingID,LinkID);
				}
				else
				{
					setCookie('LinkID',LinkID+ '@!@' + getCookie('LinkID'),0);	
					RemoveRecentlyViewed(SalesListingID,LinkID,i);
				}
		}
		else
		{
				if(!getCookie('SalesListingID'))
				{	
					setCookie('SalesListingID',SalesListingID,0);
					RemoveRecentlyViewed(SalesListingID,LinkID,i);
				}
				else
				{
					setCookie('SalesListingID',SalesListingID+ '@!@' + getCookie('SalesListingID'),0);
					RemoveRecentlyViewed(SalesListingID,LinkID,i);
				}
		}
		UName=getCookie('UName')
		UserID=getCookie('UserID')
		if(UName!='' && UName!=null && UserID!='' && UserID!=null)
			ajaxManager('do_process','../Account/processing.aspx?PT=save&UserID='+UserID+'&ListingIDs=' + SalesListingID +'&LinkIDs='+ LinkID + '&d=' + d);
	}	
}

function RemoveRecentlyViewed(SalesListingID,LinkID,i)
{
	var d = new Date();
	var UName='';
	var UserID='';
	var i=0;
	var ar = new Array();
	
	var Cookie_link=getCookie('Cookie_link');
	var Cookie_info=getCookie('Cookie_info');
	
	if(Cookie_link == null )
		Cookie_link ='';
	if(Cookie_info == null )
		Cookie_info ='';
		
	var Link = Cookie_link.split('@!@');
	var Info = Cookie_info.split('@!@');
	
	var _Link = new Array();
	var _Info = new Array();
	
	var length =Link.length;
	var isSavedFlag=false;
	var j=0;
	for(i=0;i<length;i++)
	{
		isSavedFlag=false;
		if((Link[i].indexOf('='+SalesListingID+'&mls')!=-1) || (Link[i].indexOf('LINKID='+LinkID)!=-1))
		{
			isSavedFlag=true;
		}
		if(!isSavedFlag)
		{
			_Link[j]=Link[i];
			_Info[j]=Info[i];
			j++;
		}
	}
	var _strLink='';
	var _strInfo='';
	for(i=0;i<_Link.length;i++)
	{
		_strLink += '@!@' + _Link[i];
		_strInfo +='@!@'+_Info[i];
	}
	if(_strLink!='')
	{
		_strLink=_strLink.substring(2);
		_strInfo=_strInfo.substring(2);
	}
	if(_strLink!='')
	{	
		setCookie('Cookie_link',_strLink,0);
		setCookie('Cookie_info',_strInfo,0);
		window.location=path+'Account/';
	}	
}

function SaveSearch(strLink,strInfo)
{
	var d = new Date();
	var UName='';
	var UserID='';
	//if(document.getElementById('divSave'+i).innerHTML=='Save')
	{
				if(!getCookie('CC_SSI') && !getCookie('CC_SSL'))
				{	
					setCookie('CC_SSI',strLink,0);
					setCookie('CC_SSL',strInfo,0);					
				}
				else
				{
					setCookie('CC_SSI',strLink+ '@!@' + getCookie('CC_SSI'),0);
					setCookie('CC_SSL',strInfo+ '@!@' + getCookie('CC_SSL'),0);
				}
		
	UName=getCookie('UName')
	UserID=getCookie('UserID')
	if(UName!='' && UName!=null && UserID!='' && UserID!=null)
		ajaxManager('do_process','../Account/processing.aspx?PT=saveSearch&Link='+strLink+'&Info=' + strInfo + '&UserID=' + UserID + '&d=' + d);
	}
	/*else if(document.getElementById('divSave'+i).innerHTML=='Delete')
	{
		if(confirm('Are you sure you want to delete this property?'))
		{
			if(LinkID>0)
			{
					if(!getCookie('LinkID'))
					{	
						setCookie('LinkID',LinkID,0);
					}
					else
					{
						setCookie('LinkID',getCookie('LinkID').toString().replace(LinkID,'0'),0);
					}
			}
			else
			{
					if(!getCookie('SalesListingID'))
					{	
						setCookie('SalesListingID',SalesListingID,0);
					}
					else
					{
						setCookie('SalesListingID',getCookie('SalesListingID').toString().replace(SalesListingID,'0'),0);
					}
			}
			UName=getCookie('UName')
			UserID=getCookie('UserID')
			if(UName!='' && UName!=null && UserID!='' && UserID!=null)
			{
				ajaxManager('do_process','../Account/processing.aspx?PT=delete&UserID='+UserID+'&ListingIDs=' + SalesListingID +'&LinkIDs='+ LinkID + '&d=' + d);
				//window.location='../Account/?UserID='+UserID +'&d='+d
				window.location='../Account/?d='+d
			}
			else
				window.location='../Account/?d='+d
		}	
		else
			return false;
	}*/
}

//Load the Recently Searched Criteria
function LoadRecentlySearchedCriteria(div)
{
	var i=0;
	var j=0;
	var str='';
	
	if(getCookie('CC_SSL')&& getCookie('CC_SSI') && document.getElementById(div))
	{
		var CC_SSL=getCookie('CC_SSL');
		var CC_SSI=getCookie('CC_SSI');
		var Link = CC_SSL.split('@!@');
		var Info = CC_SSI.split('@!@');
		if(Link.length>4)
			j=4;
		else
			j=Link.length;	
		for(i=0;i<j;i++)
		{
			str = str + " &bull; <a href=\'" + path + "listing/default.aspx?" + Link[i] + "\' title=\'" + Info[i] + "\'>" + Info[i] + "...</a><br>"
		}
		
	}
	if(str!='')
	{
		str= "<SPAN class=\'home_box_header_small\'>RECENT SEARCHES</SPAN><span id=\'divRecentSearch\'><span class=\'smallText\'> (<a href=\'javascript:DeleteRecentSearch(\"divRecentSearch\");\'>delete all</a>)</span><br>" + str +"</span><br>";
	}
	else
		str="<br>";
	str =str + "Don\'t have an account? <a href=\'#\' onClick=\'SignUp(\"divLoginRS\")\'>Sign Up</a> to save your favorite properties and searches. It\'s fast and it\'s free!";
	if(document.getElementById(div))
		document.getElementById(div).innerHTML =document.getElementById(div).innerHTML  +"<br>" + str;
	//else
		//alert('oject not Found !!!')	
}

//Load the Recently Searched Criteria
function LoadRecentlySearchedCriteriaACCOUNT(div)
{
	
	var i=0;
	var j=0;
	var str='';
	//alert(document.getElementById(div));
	if(getCookie('CC_SSL')&& getCookie('CC_SSI') && document.getElementById(div))
	{
		//alert('Inside');
		var CC_SSL=getCookie('CC_SSL');
		var CC_SSI=getCookie('CC_SSI');
		var Link = CC_SSL.split('@!@');
		var Info = CC_SSI.split('@!@');
		/*if(Link.length>4)
			j=4;
		else*/
			j=Link.length;	
		
		for(i=0;i<j;i++)
		{
			str = str + "<span class=\'ResultsSPAN\' style=\'width:50px;align:center;\' onclick=\'SaveSearchResult(\"" + i + "\")\'>SAVE</span>" + " <a href=\'" + path + "listing/default.aspx?" + Link[i] + "\' title=\'" + Info[i] + "\'><b>" + Info[i] + "...</b></a><br>"
		}
	}
	if(str!='')
	{
		str= "<span id=\'divRecentSearch\'><span style=\'padding-left:337px;\'></span><span class=\'smallText\'> <a href=\'javascript:DeleteRecentSearch(\"divRecentSearch\");\'>delete all</a></span><br><span id=\'divShowASS\'>" + str +"</span></span><br>";
	}
	str= "<span class=\'HomeLink\'><a href=\'javascript:ShowHideDiv(\"divShowASS\",\"imgTriangleASS\");\'><img id=\'imgTriangleASS\' src=\'../images/triangle.gif\' />	<b>Recent Searches</b></a>" + str;
	str =str + "<div class=\'smallText\'>Don\'t have an account? <a href=\'#\' onClick=\'SignUp(\"divLoginRS\")\'>Sign Up</a> to save your favorite properties and searches. It\'s fast and it\'s free!</div>";
	if(document.getElementById(div))
		//document.getElementById(div).innerHTML =document.getElementById(div).innerHTML  +"<br>" + str + "</span>";
		document.getElementById(div).innerHTML =str + "</span>";
	//return false;	
}

function SaveSearchResult(i)
{
	var d = new Date();
	var UserID='';	
	UserID=getCookie('UserID')
	if(UserID=='' || UserID == null)
	{
		alert('You must be logged in to save searches.\nClick OK to log in or sign up for an account - it only takes a minute!');
		Login('divLoginR');
	}
	else
	{
		if(getCookie('CC_SSL')&& getCookie('CC_SSI'))
		{
			var CC_SSL=getCookie('CC_SSL');
			var CC_SSI=getCookie('CC_SSI');
			var Link = CC_SSL.split('@!@');
			var Info = CC_SSI.split('@!@');
			if(Link.length>=i)
			{
				var strLink=Link[i];
				strLink = replaceAll(strLink,"=","@@");
				strLink =replaceAll(strLink,"&","!!");
				RemoveRecentlySearch(i)
				ajaxManager('do_process','../Account/processing.aspx?PT=SaveSearch&UserID='+UserID+'&Link=' + strLink  +'&Info='+ Info[i] + '&d=' + d);				
			}
		}
		window.location=path+'Account/?d='+d
	}
	
}
function RemoveRecentlySearch(k)
{
	var d = new Date();
	var UName='';
	var UserID='';
	var i=0;
	var ar = new Array();
	
	var CC_SSL=getCookie('CC_SSL');
	var CC_SSI=getCookie('CC_SSI');
	
	if(CC_SSL == null )
		CC_SSL ='';
	if(CC_SSI == null )
		CC_SSI ='';
		
	var Link = CC_SSL.split('@!@');
	var Info = CC_SSI.split('@!@');
	
	var _Link = new Array();
	var _Info = new Array();
	
	var length =Link.length;
	var isSavedFlag=false;
	var j=0;
	for(i=0;i<length;i++)
	{
		isSavedFlag=false;
		if(i==k)
		{
			isSavedFlag=true;
		}
		if(!isSavedFlag)
		{
			_Link[j]=Link[i];
			_Info[j]=Info[i];
			j++;
		}
	}
	var _strLink='';
	var _strInfo='';
	for(i=0;i<_Link.length;i++)
	{
		_strLink += '@!@' + _Link[i];
		_strInfo +='@!@'+_Info[i];
	}
	if(_strLink!='')
	{
		_strLink=_strLink.substring(2);
		_strInfo=_strInfo.substring(2);
	}
	//if(_strLink!='')
	{	
		setCookie('CC_SSL',_strLink,0);
		setCookie('CC_SSI',_strInfo,0);		
	}	
}
function replaceAll(str, find, replace) 
{
	var idx = str.indexOf(find);

	while ( idx > -1 ) {
		str = str.replace( find, replace );
		idx = str.indexOf( find );
	}
return str;
}
function DeleteAllSavedSearch()
{
	var UName='';
	var UserID='';
	var d = new Date();
	if(confirm('Are you sure you want to delete all saved searches?'))
	{
		
		UName=getCookie('UName')
		UserID=getCookie('UserID')
		if(UName!='' && UName!=null && UserID!='' && UserID!=null)
		{
			var strIDs='';
			var i=0;
			for(i=0;i<SavedSearchID.length;i++)
				strIDs = strIDs + ',' + SavedSearchID[i];
			if(strIDs!='')
				strIDs = strIDs.substring(1);
			if(strIDs!='')
			//	alert(strIDs);
				ajaxManager('do_process','../Account/processing.aspx?PT=DeleteAllSavedSearch&SavedSearchIDs='+ strIDs + '&d=' + d);
			//window.location='../Account/?UserID='+UserID +'&d='+d
			window.location='../Account/?d='+d
		}
		else
			window.location='../Account/?d='+d
	}
}



function LoadSearchTextOnly(str)
{
	var obj=document.getElementById('divSearchTextOnly');
	if(obj)
	{
		if(str!='')
			obj.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;<span style='BACKGROUND-COLOR:YELLOW;COLOR:BLACK'>We did not find any properties for sale in " + str + " that matched your search criteria.</span> Here are all the properties we found in " + str;
		else
			obj.innerHTML = "";	
	}
}
function ShowTotalNumberofProperties(count)
{
	
	var obj=document.getElementById('divNumberOfPropertiesOnMap');
	
	if(obj && count>0)
	{
		/*if(getCookie('CC_SSL')&& getCookie('CC_SSI'))
		{
			var CC_SSL=getCookie('CC_SSL');
			var CC_SSI=getCookie('CC_SSI');
			var Link = CC_SSL.split('@!@');
			var Info = CC_SSI.split('@!@');
			var j=0;
			var str='';	
			if(Link.length>=0)
			{
				str = Info[0];
				j=str.indexOf(',');
				if(j>0)
					str = str.substring(0,j)
				str = "<a href=\'" + path + "listing/default.aspx?" + Link[0] + "\' title=\'" + str + "\'>" + str + "</a>"
			}
			
		}*/
		//if(document.getElementById('txtSearch'))
		//if(str!='')
			obj.innerHTML ="Showing first " + count + " properties around " + document.getElementById('txtSearch').value + " matching your search";
	}
}
function DelComment(id,lID,MLSID)
{
	if(confirm('Are you sure you want to delete this comment?'))
	{
		var d = new Date();
		var UName='';
		var UserID='';
		UName=getCookie('UName')
		UserID=getCookie('UserID')
		if(UName!='' && UName!=null && UserID!='' && UserID!=null)
		{
			ajaxManager('do_process','../Account/processing.aspx?PT=DeleteComment&CommentID='+ id + '&d=' + d);
			//alert(lID);
			if(MLSID>0)
				window.location="details.aspx?BostonRealEstate="+lID+"&mls="+MLSID+"&d="+d;
			else
				window.location="Details.aspx?LINK="+lID+"&d="+d;
		}
	}
}

/*function CheckTimeOut()
{
	var d = new Date();
	ajaxManager('do_process','../Account/processing.aspx?PT=TimeOut&d=' + d);
	setTimeout("CheckTimeOut()",60000);
}
*/

function SearchUsingMap_Login()
{
    //ctl00_ContentPlaceHolder1_hidZip
    var strZips='';
    var strAreaName='';
    var cbCheckBoxs = document.getElementsByName('chkArea_GB');
    var obj_AreaName = document.getElementById('ctl00_ContentPlaceHolder1_hidAreaName');
    
    var obj_hidZip = document.getElementById('ctl00_ContentPlaceHolder1_hidZip');    
    var i=0;
    var j=0;
    if(cbCheckBoxs)
    {
        for( i = 0; i < cbCheckBoxs.length; i++ )
        {
            if(cbCheckBoxs[i].checked==true)
            {
                strZips +=cbCheckBoxs[i].value.split('||')[0]+',';
                strAreaName +=cbCheckBoxs[i].value.split('||')[1]+',';
                j++;    
            }
        }
        if(cbCheckBoxs.length==j)
        {
            strAreaName='ALL CITIES,';
        }        
//        if(strZips=='')
//        {
//             for( i = 0; i < cbCheckBoxs.length; i++ )
//             {
//                strZips +=cbCheckBoxs[i].value.split('||')[0]+',';
//                strAreaName +=cbCheckBoxs[i].value.split('||')[1]+',';
//             }
//        } 
        
     }
    obj_hidZip.value=strZips;
    obj_AreaName.value=strAreaName;
    
    /*alert(obj_hidZip.value)
    alert(obj_AreaName.value)
    */    
    return true;
}

function popAgentWindow(theURL)
{
       winName="EmailAgent";
       features="width=330,height=330,scrollbars=no";
       window.open(theURL,winName,features);
}
function ValidateEmail(str)
{
    bemail1=new RegExp(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/);
	bemail2 = bemail1.exec(str);
    return !(bemail2);
}
function ValidateEmailListings()
{

	    if(document.getElementById ("chkSendToFriend"))		 	
		{
		    if(document.getElementById("chkSendToFriend").checked)
		    {
		        if(document.getElementById ("txtFromEmailAddress").value=="")
 				{
 				    alert ('Enter From E-Mail Address');
 				    document.getElementById ("txtFromEmailAddress").focus();
 				    return (false);
 				} 			
 			    else
 			    {
		    		if(ValidateEmail(document.getElementById ("txtFromEmailAddress").value))
					{
					    alert("Invalid From Email Address");
					    document.getElementById ("txtFromEmailAddress").value="";
					    document.getElementById ("txtFromEmailAddress").focus();
					    return (false);
					}
			    }
			    
			    if(document.getElementById ("txtToEmailAddress").value=="")
 				{
 				    alert ('Enter To Email Address:');
 				    document.getElementById ("txtToEmailAddress").focus();
 				    return (false);
 				} 			
 			    else
 			    {
		    		if(ValidateEmail(document.getElementById ("txtToEmailAddress").value))
					{
					    alert("Invalid To Email Address:");
					    document.getElementById ("txtToEmailAddress").value="";
					    document.getElementById ("txtToEmailAddress").focus();
					    return (false);
					}
			    }
		    }
		    else
		    {
		         if(document.getElementById ("txtToSelfEmailAddress").value=="")
 				{
 				    alert ('Enter E-Mail Address');
 				    document.getElementById ("txtToSelfEmailAddress").focus();
 				    return (false);
 				} 			
 			    else
 			    {
		    		if(ValidateEmail(document.getElementById ("txtToSelfEmailAddress").value))
					{
					    alert("Invalid Email Address");
					    document.getElementById ("txtToSelfEmailAddress").value="";
					    document.getElementById ("txtToSelfEmailAddress").focus();
					    return (false);
					}
			    }
		    }
		}
				
    return true;
}


function ActivityTrack(ACTtype,ListingID,MLSID,strSearch)
{
	var d = new Date();
	ajaxManager('do_process','../login/process.aspx?ACTtype=' + ACTtype + '&ListingID='+ ListingID + '&MLSID='+ MLSID + '&strSearch='+ strSearch + '&d=' + d);
	
}

