﻿// JScript File
/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

function showLogin()
{
    var dID, dSrc;
    //dID = "loginBox";
    dID = "ctl00_cph1_loginBox";
    dSrc = document.getElementById(dID);
    
    if(dSrc.style.display=="block")
    {
        dSrc.style.display = "none";
    }
    else
    {
        dSrc.style.display = "block";
    }
    
}

function hideLogin()
{
    var dID, dSrc;
    //dID = "loginBox";
    dID = "ctl00_cph1_loginBox";
    dSrc = document.getElementById(dID);
    dSrc.style.display = "none";
}

function saveProperty()
{
   
    var lID, lSrc;
    lID = "ctl00$cph1$ListingID";
    lSrc = document.getElementById(lID);
    
    var thisO, oSource;
    thisO = "ctl00_Navigation1_LoginView1_savedPropCount";
    oSource = document.getElementById(thisO);
    
    var msgID, msgSrc;
    msgID = "isPropertySaved";
    msgSrc = document.getElementById(msgID);
    
    if (window.XMLHttpRequest) { 
		    xmlhttp = new XMLHttpRequest(); 
	    } else if (window.ActiveXObject) { 
		    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	    } 
    	
    	if(lSrc.value=="0")
    	{
    	    alert("Property has already been saved");
    	}
    	else if(lSrc.value=="")
    	{
    	    alert("Property has already been saved");
    	}
    	else
    	{
	        var url = "../popSaveProperty.aspx?saveID=" + lSrc.value;
	        
	        xmlhttp.open("GET",url,false); 
	        xmlhttp.setRequestHeader('Accept','message/x-jl-formresult') 
	        xmlhttp.send(null); 
	        if (xmlhttp.status == 200) { 
	            oSource.innerHTML = xmlhttp.responseText;
	            msgSrc.innerHTML = "<br/>&nbsp; <font color=green><h3> &nbsp; Property Saved!</h3></font>";
	        } 
	        else { 
		        // handle different response status here 
		        //alert("err saving property");
		        url = "popSaveProperty.aspx?saveID=" + lSrc.value;
		        xmlhttp.open("GET",url,false); 
	            xmlhttp.setRequestHeader('Accept','message/x-jl-formresult') 
	            xmlhttp.send(null); 
	            if (xmlhttp.status == 200) { 
	                oSource.innerHTML = xmlhttp.responseText;
	                msgSrc.innerHTML = "<br/>&nbsp; <font color=green><h3> &nbsp; Property Saved!</h3></font>";
	            } 
	            else { 
	                alert("err saving property2");
	            }
	        } 
        }
}


function CheckMatchingResults()
{
    var pTypeID, pTypeSrc;
    pTypeID = "ctl00$cph1$ddl_iType";
    pTypeSrc = document.getElementById(pTypeID);
    
    var sID, sSrc;
    sID = "matchingResults";
    sSrc = document.getElementById(sID);
    
    //Get Price start
    var priceBID, priceBSrc;
    priceBID = "ctl00$cph1$ddl_priceBegin";
    priceBSrc = document.getElementById(priceBID);

    //Get End Price
    var priceEID, priceESrc;
    priceEID = "ctl00$cph1$ddl_priceEnd";
    priceESrc = document.getElementById(priceEID);

    //Get Bed
    var bedBID, bedBSrc;
    bedBID = "ctl00$cph1$ddl_iBeds";
    bedBSrc = document.getElementById(bedBID);

    //Get Bed Max
    var bedID, bedSrc;
    bedID = "ctl00$cph1$ddl_iBedsMax";
    bedSrc = document.getElementById(bedID);

    //Get Bath
    var bathBID, bathBSrc;
    bathBID = "ctl00$cph1$ddl_iBaths";
    bathBSrc = document.getElementById(bathBID);

    //Get Bed Max
    var bathID, bathSrc;
    bathID = "ctl00$cph1$ddl_iBathsMax";
    bathSrc = document.getElementById(bathID);
   
    var thisDDL, ddlSource;
    thisDDL = "iAreaID";
    ddlSource = document.getElementById(thisDDL);
   
    var thisDDL2, ddlSource2;
    thisDDL2 = "iSubAreaID";
    ddlSource2 = document.getElementById(thisDDL2);
    
    var cID, cSrc;
    cID = "ctl00$cph1$ddl_sCity";
    cSrc = document.getElementById(cID);
    
    
    if (window.XMLHttpRequest) { 
		    xmlhttp = new XMLHttpRequest(); 
	    } else if (window.ActiveXObject) { 
		    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	    } 
    	
	    var url = "matchingResults.aspx?t=" + getSelectedItem(pTypeSrc) + "&bPrice=" + getSelectedItem(priceBSrc) + "&ePrice=" + getSelectedItem(priceESrc) + "&bd=" + getSelectedItem(bedBSrc) + "&bdm=" + getSelectedItem(bedSrc) + "&ba=" + getSelectedItem(bathBSrc) + "&bam=" + getSelectedItem(bathSrc) + "&a=" + getSelectedItem(ddlSource) + "&sa=" + getMultiSelectedItem(ddlSource2) + "&c=" + getSelectedItem(cSrc) + ",0";
        //alert(url);
	    xmlhttp.open("GET",url,false); 
	    xmlhttp.setRequestHeader('Accept','message/x-jl-formresult') 
	    xmlhttp.send(null); 
	    if (xmlhttp.status == 200) { 
		    sSrc.innerHTML = xmlhttp.responseText;
	    } 
	    else { 
		    // handle different response status here 
		    alert("err matching props");
	    } 
  
}


function getSelectedItem(objSelect)   
{ 
    for(i=0;i<objSelect.length;i++)
     { 
        if(objSelect[i].selected)   
         { 
                 return   objSelect[i].value; 
         } 
     } 
     return   ""; 
} 

function getMultiSelectedItem(objSelect)   
{ 
    var selList;
    selList = "0";
    for(i=0;i<objSelect.length;i++)
     { 
        if(objSelect[i].selected)   
         { 
                 selList = selList + "," + objSelect[i].value; 
         } 
     } 
     return  selList; 
}


var offsetfrommouse=[0,0]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.

var defaultimageheight = 40;	// maximum image size.
var defaultimagewidth = 40;	// maximum image size.

var timer;

function gettrailobj(){
if (document.getElementById)
return document.getElementById("preview_div").style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("preview_div")
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function hidetrail(){	
	gettrailobj().display= "none";
	document.onmousemove=""
	gettrailobj().left="-50px"
	clearTimeout(timer);
}

function saveSearch()
{
    var pTitleID, pTitleSrc;
    pTitleID = "searchTitle";
    pTitleSrc = document.getElementById(pTitleID);
    
    //alert(pTitleSrc.value));
    
    if(pTitleSrc.value=="")
    {
        var errID, errSrc;
        errID = "errMsg";
        errSrc = document.getElementById(errID);
        
        errSrc.innerHTML = "Please enter a Title above."
    }
    else
    {
    
        var searchID, searchSrc;
        searchID = "searchString";
        searchSrc = document.getElementById(searchID);
        
        //alert(searchSrc.value);
        var thisO, oSource;
        thisO = "ctl00_Navigation1_LoginView1_savedSearchCount";
	    oSource = document.getElementById(thisO);
    	
    	
	    if (window.XMLHttpRequest) { 
		    xmlhttp = new XMLHttpRequest(); 
	    } else if (window.ActiveXObject) { 
		    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	    } 
    	
	    var url = "popSaveSearch.aspx?save=1&searchTitle=" + pTitleSrc.value + "&" + searchSrc.value;
	    xmlhttp.open("GET",url,false); 
	    xmlhttp.setRequestHeader('Accept','message/x-jl-formresult') 
	    xmlhttp.send(null); 
	    if (xmlhttp.status == 200) { 
		    oSource.innerHTML = xmlhttp.responseText;
	    } 
	    else { 
		    // handle different response status here 
		    alert("err 1");
	    } 
        
        hidetrail();
        
    }
}

function showtrail(imagename,title,width,height){
    i = imagename
	t = title
	w = width
	h = height
	timer = setTimeout("show('"+i+"',t,w,h);",20);
}
function show(imagename,title,width,height){
 
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) {
		( width == 0 ) ? width = defaultimagewidth: '';
		( height == 0 ) ? height = defaultimageheight: '';
			
		width+=30
		height+=55
		defaultimageheight = height
		defaultimagewidth = width
	
		//document.onmousemove=followmouse;
		//document.onclick=followmouse; 
				
		newHTML = '<div class="border_preview" style="width:'+  width +'px;height:'+ height +'px"><div id="loader_container"></div>'; //<div id="progress"> </div><div id="loader_bg"></div>
		newHTML = newHTML + '<h3 class="title_h2"><font color=black>Save Search</font></h3>'
		newHTML = newHTML + '<table width="100%"><tr><td width="20">&nbsp;</td><td valign="middle">Title: <input type="text" name="searchTitle" size="25" maxlength="50"></td><td><img src="_images/btnSaveSearchTitle.gif" onClick="saveSearch();" style="cursor: pointer;"> <img src="_images/btnCancelLogin.gif" onclick="hidetrail();" style="cursor: pointer;"></td></tr>'
		newHTML = newHTML + '<tr><td></td><td colspan="3"><font color="Red"><span id="errMsg"></span></font></td></tr></table>'
    	newHTML = newHTML + '</div>'; 
		
		if(navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1 ){
			//newHTML = newHTML+'<iframe src="about:blank" scrolling="no" frameborder="0" width="'+width+'" height="'+height+'"></iframe>';
			newHTML = newHTML+'<iframe scrolling="no" src="about:blank" frameborder="0" width="100%" height="100%"></iframe>';
		}		
   
		gettrailobjnostyle().innerHTML = newHTML;
		gettrailobj().display="block";
	}
}

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	//xcoord = xcoord - 440;
	//ycoord = ycoord - 90;
	
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}

function popSlideShow(thisType, thisID)
{
    var url, attribs;
    
    if(thisType=="PropertyDetail")
    {
        url = "PopSlideShow.aspx?type=PropertyDetail&id=" + thisID;
        attribs = "width=720px,height=478px,address=no,scroll=no,scrollbars=no,scrolling=no,resize=no,resizable=no,top=1";
    }
    else
    {
        url = "PopSlideShow.aspx?type=listing_res&id=" + thisID;
        attribs = "width=400px,height=242px,address=no,scroll=no,scrollbars=no,scrolling=no,resize=no,resizable=no,top=1";
    }
    
    window.open(url, "ssWin", attribs);
}


