﻿// JScript File
	

var IMGPath	=new Array();
var StrInfo=new Array();
	
	
	
		
function getCookie(NameOfCookie)
	{// alert(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 ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) + 
	((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()) + "; path=/;";
}

function AddViewedListing(rv2id,mlsid,ImgPath,strInfo)
{ 
    //alert('dsdsdsdsd')
    var ImgPath=ImgPath;
    var PgLink=''
    var strInfo=strInfo;
    //---------------Set The MLSID Array---------------
        var Cookie_MLSID=getCookie('Cookie_MLSID');
        var Cookie_ListingId=getCookie('Cookie_ListingId');
    	    if(Cookie_MLSID == null )
			    Cookie_MLSID ='';
		    if(Cookie_ListingId == null )
			    Cookie_ListingId ='';
	
		if(Cookie_MLSID=='' && Cookie_ListingId=='')
		    {
		   
			    rv2id = rv2id;
			    mlsid = mlsid;					
			    setCookie('Cookie_MLSID',mlsid,99999);
			    setCookie('Cookie_ListingId',rv2id,99999);	
		    }
		else if(Cookie_MLSID!='' && Cookie_ListingId!='')		
		    {
    		
			    rv2id = Cookie_ListingId + 'ø' + rv2id;
			    mlsid = Cookie_MLSID + 'ø' + mlsid;					
			    setCookie('Cookie_MLSID',mlsid,99999);
			    setCookie('Cookie_ListingId',rv2id,99999);	
		    }	
	   //---------------------------------------------
        var Cookie_ImagePath=getCookie('Cookie_ImagePath');
       	var Cookie_info=getCookie('Cookie_Info');
		if(Cookie_ImagePath == null )
			Cookie_ImagePath ='';
		if(Cookie_info == null )
			Cookie_info ='';
			
		//var Link = Cookie_ImagePath.split('ø');
		//var Info = Cookie_info.split('ø');
		var flag=true;
	
		if(flag && Cookie_info=='' && Cookie_ImagePath=='')
		{
		   // alert(strInfo)
			ImgPath = ImgPath;
			strInfo = strInfo;					
			setCookie('Cookie_ImagePath',ImgPath,99999);
			setCookie('Cookie_Info',strInfo,45);	
			//alert(getCookie('Cookie_Info'));
		}
		else if(flag && Cookie_info!='' && Cookie_ImagePath!='')		
		{
		
			ImgPath = Cookie_ImagePath + 'ø' + ImgPath;
			strInfo = Cookie_info + 'ø' + strInfo;					
			setCookie('Cookie_ImagePath',ImgPath,99999);
			setCookie('Cookie_Info',strInfo,99999);	
		}	
		LoadRecentlyViewedListingInfo('divRecentlyViewed');
	}	


function LoadRecentlyViewedListingInfo(div)
{

    var i=0;
    var x=0;
    var j=0;
    var str='';
    if(getCookie('Cookie_ImagePath')!=null&& getCookie('Cookie_info')!=null && getCookie('Cookie_MLSID')!=null&& getCookie('Cookie_ListingId')!=null && document.getElementById(div))
    {
        if(getCookie('Cookie_ImagePath')!=''&& getCookie('Cookie_info')!='' && getCookie('Cookie_MLSID')!=''&& getCookie('Cookie_ListingId')!='' && document.getElementById(div))
        {
        
        //------------------Get The Cookie------------------------------
            var Cookie_ImagePath=getCookie('Cookie_ImagePath');
            var Cookie_info=getCookie('Cookie_Info');
    		var Cookie_MLSID=getCookie('Cookie_MLSID');
            var Cookie_ListingId=getCookie('Cookie_ListingId');
            
                //---------------------------------------------------------------
                //----------------Split the Array--------------------------------
		            var Link = Cookie_ImagePath.split('ø');
		            var Info = Cookie_info.split('ø');
    		        var mlsid=Cookie_MLSID.split('ø');
    		        var listingid=Cookie_ListingId.split('ø');
    	        //---------------------------------------------------------------
    	        //---------------------Check For Length Of Array-----------------	
		            if(Link.length>4)
		                {
        		       
			               j=Link.length
			               x=Link.length-4;
			             }
		            else
		                {
	                        x=0;
		                    j=Link.length;	
			            }
		                for(i=x;i<j;i++)
		                {
        		      
			                str +="<table border=\'0\' cellpadding=\'0\' id=\'tbl"+i+"\' cellspacing=\'5\' width=\'100%\'>"
                                    str +="<tr>"
                                    str +="<td align=\'left\' valign=\'top\' colspan=\'2\'>"
                                    str +="<strong>"+ Info[i] +"</strong></td>"
                                    str +="</tr>"
                                    str +="<tr>"
                                    str +="<td align=\'left\' valign=\'top\'>"
                                  
                                    str +="<img src=\'"+ Link[i] +"\' width=\'70\' height=\'70\' alt=\'\' title=\'\'  onerror=\'this.src=\"../images/nopic.gif\"\'  /></td>"
                                 
              
                                    str +="<td align=\'left\' valign=\'top\' style=\'line-height: 18px;\'>"
                                    str +="<a href=\'../MLSListings/details.aspx?ListingID="+ listingid[i] +"&mls="+ mlsid[i]+"\'>View Details</a><br />"
                                    
                                    if((getCookie('UserID')=='') ||(getCookie('UserID')==null))
                                        {
                                        str +="<a href=\'#textLoginLogout\' onclick=\'javascript:Ajax_Repeater1(\"../Login/Save_PopUp.aspx?SalesListingID="+ listingid[i] +"\")\' class=\'lnk-save\'>Save</a><br />"
                                        }
                                    else
                                        {
                                          str +="<div id=\'divsave"+i+"\'><a href=\'javascript:void(0);\' onclick=\'javascript:ajaxManager(\"do_process\",\"../Buyer_Seller/Process.aspx?PT=AddProperty&SalesListingID="+ listingid[i] +"\");ChangeSaveText("+ i +")\' class=\'lnk-save\'>Save</a></div><div id=\'divSaved"+i+"\' class=\'lnk-save\' style=\'display:none;\'><b>Saved</b></div>"
                                        }
                                    
                                    
                                    
                                    str +="<a href=\'javascript:void(0)\' class=\'lnk-clear\' onclick=\'javascript:DeleteListing("+ i +",\"tbl"+i+"\")\'>Clear</a>"
                                    str +="</td>"
                                    str +="</tr>"
                                    str +="</table>"
		                }
         	      
            	
    	        var strMain ='';
            		
    	        if (str!='')
    	        {
            	
                        strMain +="<table border=\'0\' cellpadding=\'0\' cellspacing=\'0\' width=\'100%\' class=\'box-grey\'>"
                        strMain +="<tr>"
                        strMain +="<td align=\'left\' valign=\'top\' style=\'border-bottom: 1px solid #C7C7C7;\'>"
                        strMain +="<img src=\'../images/recently_viewed.gif\' width=\'114\' height=\'29\' alt=\'Recently Viewed\' title=\'Recently Viewed\' /></td>"
                        strMain +="</tr>"
                        strMain +="<tr>"
                        strMain +="<td align=\'left\' valign=\'top\'>"+ str +""
                        strMain +="</td>"
                        strMain +="</tr>"
                        strMain +="</table>"
                	
   		            document.getElementById(div).innerHTML=strMain;
               }
    
         }
         else {loadNotYet();}
     }
     else
     {
             // ----If no recently listing viewed then Set the Div InnerHtml to no Properties text----
           
        loadNotYet()
     }	
    	
}	

function loadNotYet()
{
     var strMain='';
     var i=0;
            var str=''
            
             str +="<table border=\'0\' cellpadding=\'0\' id=\'tbl"+i+"\' cellspacing=\'0\' width=\'100%\'>"
             str +="<tr>"
             str +="<td align=\'center\' valign=\'middle\' colspan=\'2\' height=\'100px\'>"
             str+="<b>No Properties Viewed Yet</b></td>"
             str+="</tr>"
             str +="</table>"
            
            
            
            
            
              strMain +="<table border=\'0\' cellpadding=\'0\' cellspacing=\'0\' width=\'100%\' class=\'box-grey\'>"
                    strMain +="<tr>"
                    strMain +="<td align=\'left\' valign=\'top\' style=\'border-bottom: 1px solid #C7C7C7;\'>"
                    strMain +="<img src=\'../images/recently_viewed.gif\' width=\'114\' height=\'29\' alt=\'Recently Viewed\' title=\'Recently Viewed\' /></td>"
                    strMain +="</tr>"
                    strMain +="<tr>"
                    strMain +="<td align=\'left\' valign=\'top\'>"+ str +""
                    strMain +="</td>"
                    strMain +="</tr>"
                    strMain +="</table>"
           
    	        document.getElementById('divRecentlyViewed').innerHTML=strMain;
}
function DeleteListing(no,TblName)
{
//alert(no)

    var i,j,x,y;
    var strInfo='';
    var linkstr='';
    var mlsidstr='';
    var rv2idstr='';
    if(confirm('Are you sure you want to delete recently viewed properties?'))
    {
          var Cookie_ImagePath=getCookie('Cookie_ImagePath');
          var Cookie_info=getCookie('Cookie_Info');
          var Cookie_MLSID=getCookie('Cookie_MLSID');
          var Cookie_ListingId=getCookie('Cookie_ListingId');
          
          var Link = Cookie_ImagePath.split('ø');
          var Info = Cookie_info.split('ø');
          var mlsid=Cookie_MLSID.split('ø');
    	  var listingid=Cookie_ListingId.split('ø');
          if(Link.length>0)
          {
            if (Info.length>0)
              {
                  Info[no]=''
                  Link[no]=''
                  mlsid[no]=''
                  listingid[no]=''
                  
                  
                  //alert(Info[no])
                  // alert(Link[no])
                  //  alert( mlsid[no])
                   //  alert( listingid[no])
              }
          }
         
          if(Info.length>0)
          {
         
               for(j=0;j<Info.length;j++)
                { 
                    if (Info[j]!='')
                        {
                         strInfo +=Info[j]+ 'ø'
                           
                        }
                }
           // alert(strInfo)
             // ------------------Take Left Of the string-----------
                var strLen2=String(strInfo).length;
                strInfo= String(strInfo).substring(0, strLen2 -1);
            //--------------------------------------------------------
          }
      if(Link.length>0)
      {
     
        for(i=0;i<Link.length;i++)
        { 
          if (Link[i]!='')
          {
            linkstr +=Link[i]+ 'ø'
            
          }
         
        }
       // alert(linkstr)
        //-----------------Take Left Of the string------------------
           var strLen=String(linkstr).length;
           linkstr= String(linkstr).substring(0, strLen -1);
        //-----------------------------------------------------------
      }
      
      if (mlsid.length>0)
      {
           for(x=0;x<mlsid.length;x++)
            { 
              if (mlsid[x]!='')
              {
                mlsidstr +=mlsid[x]+ 'ø'
               // alert(mlsidstr)
              }
               
          } 
           // alert(mlsidstr)
          //-----------------Take Left Of the string------------------
               var strLen3=String(mlsidstr).length;
               mlsidstr= String(mlsidstr).substring(0, strLen3 -1);
              // alert(mlsidstr)
            //-----------------------------------------------------------
      }
      if (listingid.length>0)
      {
       for(y=0;y<listingid.length;y++)
        { 
          if (listingid[y]!='')
          {
            rv2idstr +=listingid[y]+ 'ø'
            
          }
            
      }
      // alert(rv2idstr)
      //-----------------Take Left Of the string------------------
           var strLen4=String(rv2idstr).length;
           rv2idstr= String(rv2idstr).substring(0, strLen4 -1);
        //-----------------------------------------------------------
     } 
      //---------------Set the Cookie Again---------------------
        	setCookie('Cookie_ImagePath',linkstr,99999);
			setCookie('Cookie_Info',strInfo,99999);
			setCookie('Cookie_MLSID',mlsidstr,99999);
			setCookie('Cookie_ListingId',rv2idstr,99999);	
            document.getElementById(TblName).style.display='none';
    //-----------------------------------------------------------------
    
    // ----If no recently listing viewed then Set the Div InnerHtml to no Properties text----
    var strMain='';
    var str=''
    
     str +="<table border=\'0\' cellpadding=\'0\' id=\'tbl"+i+"\' cellspacing=\'0\' width=\'100%\'>"
     str +="<tr>"
     str +="<td align=\'center\' valign=\'middle\' colspan=\'2\' height=\'100px\'>"
     str+="<b>No Properties Viewed Yet</b></td>"
     str+="</tr>"
     str +="</table>"
    
    
    
    
    
      strMain +="<table border=\'0\' cellpadding=\'0\' cellspacing=\'0\' width=\'100%\' class=\'box-grey\'>"
            strMain +="<tr>"
            strMain +="<td align=\'left\' valign=\'top\' style=\'border-bottom: 1px solid #C7C7C7;\'>"
            strMain +="<img src=\'../images/recently_viewed.gif\' width=\'114\' height=\'29\' alt=\'Recently Viewed\' title=\'Recently Viewed\' /></td>"
            strMain +="</tr>"
            strMain +="<tr>"
            strMain +="<td align=\'left\' valign=\'top\'>"+ str +""
            strMain +="</td>"
            strMain +="</tr>"
            strMain +="</table>"
    if (getCookie('Cookie_ImagePath')=='' && getCookie('Cookie_Info')=='' && getCookie('Cookie_MLSID')=='' && getCookie('Cookie_ListingId')=='')
    	{
    	document.getElementById('divRecentlyViewed').innerHTML=strMain;
    	}	
    
    }
}	


function ChangeSaveText(id)
    {

    document.getElementById('divsave'+id).style.display='none';
    document.getElementById('divSaved'+id).style.display='block';
    }







/*function GetPrint()
{
alert('print')
if (document.getElementById('header'))
{
document.getElementById('header').style.display='none';
document.getElementById('trNextStep').style.display='none';
document.getElementById('trAgent').style.display='none';
document.getElementById('trRecent').style.display='none';
document.getElementById('trSearch').style.display='none';
window.print();

return false;

}
}*/

