﻿// JScript File

        // Callback function invoked on successful 
// completion of the page method.
function OnSucceeded(result, userContext, methodName) 
{
    
    // alert("Succeeded : " + result);
    if( result == "" ) {
        document.getElementById("WatchListContent").innerHTML = "<a href=\"../../account/default.aspx\">Please Login/Register to save properties to your watchlist.</a>";
    } else { 
        document.getElementById("WatchListContent").innerHTML = "Saving Property To Watchlist...";
        PageMethods.AddToWatchlist(propID, AddedToWatchlist, OnFailed);
    }
    /*
    if (methodName == "GetSessionValue")
    {
        displayElement.innerHTML = "Current session state value: " + 
            result;
    }
    */
}


function loadFeed(feed){

    var loc = window.location.href;
    var loctwo = remove(loc, "&Feed=CO_002");
    var locthree = remove(loctwo, "&feed=CO_001");
var locfour = remove(locthree, "&feed=CO_002");
    cleanloc = remove(locfour, "&Feed=CO_001");
    i = loc.indexOf("area");
    var param = "&Feed=" + feed;

    if (i == -1){
        clocation = document.getElementById("ctl00_ucSearch_txtLocation");
        ddMinPrice = document.getElementById("ctl00_ucSearch_selectPriceMin");
        ddMaxPrice = document.getElementById("ctl00_ucSearch_selectPriceMax");
        comboBeds = document.getElementById("ctl00_ucSearch_selectBedrooms");
        comboBaths = document.getElementById("ctl00_ucSearch_selectBathrooms");
        comboSqFt = document.getElementById("ctl00_ucSearch_selectTotalSqft");       
        chkRes = document.getElementById("ctl00_ucSearch_chkRes");
        chkCondo = document.getElementById("ctl00_ucSearch_chkCondo");
        
        var p = "?area=" + clocation.value + "&minp=" + ddMinPrice.value + "&maxp=" + ddMaxPrice.value + "&bed=" + comboBeds.value + "&bath=" + comboBaths.value + "&sqft=" + 
comboSqFt.value + "&con=" + chkCondo.checked + "&res=" + chkRes.checked + "&p=0&se=Price&sd=Descending" + param;
        window.location = remove(cleanloc, "&Feed=CO_002") + p;
    } 
    else {
    window.location = remove(cleanloc, "&Feed=CO_002") + param;
    }
}

    
  
    


function remove(s, t) {
  /*
  **  Remove all occurrences of a token in a string
  **    s  string to be processed
  **    t  token to be removed
  **  returns new string
  */
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + remove(s.substring(i + t.length), t);
  return r;
  }

function Reset(){
    document.getElementById("ctl00_cphMain_txtSBox").value = "";
    document.getElementById("ctl00_cphMain_ddMinPrice").selectedIndex = 0;
    document.getElementById("ctl00_cphMain_ddMaxPrice").value = "No Max";
    document.getElementById("ctl00_cphMain_comboBeds").selectedIndex = 0;
    document.getElementById("ctl00_cphMain_comboBaths").selectedIndex = 0;
    document.getElementById("ctl00_cphMain_comboSqFt").selectedIndex = 0;
    document.getElementById("ctl00_cphMain_ddYearBuiltMin").selectedIndex = 0;
    document.getElementById("ctl00_cphMain_ddYearBuiltMax").selectedIndex = 0;
    document.getElementById("ctl00_cphMain_ddDays").selectedIndex = 0;
    document.getElementById("ctl00_cphMain_chkRes").checked = true;
    document.getElementById("ctl00_cphMain_chkCondo").checked = true;
    document.getElementById("ctl00_cphMain_chkAC").checked = false;
    document.getElementById("ctl00_cphMain_chkDishwasher").checked = false;
    document.getElementById("ctl00_cphMain_chkRefrigerator").checked = false;
    document.getElementById("ctl00_cphMain_chkWahser").checked = false;
    document.getElementById("ctl00_cphMain_chkLender").checked = false;
    document.getElementById("ctl00_cphMain_chkDeck").checked = false;
    document.getElementById("ctl00_cphMain_chkWoodFloors").checked = false;
    document.getElementById("ctl00_cphMain_chkMountainViews").checked = false;
    document.getElementById("ctl00_cphMain_chkRemodel").checked = false;
    document.getElementById("ctl00_cphMain_chkDryer").checked = false;
    document.getElementById("ctl00_cphMain_chkFireplace").checked = false;
    document.getElementById("ctl00_cphMain_chkStove").checked = false;
    document.getElementById("ctl00_cphMain_chkHUD").checked = false;
    document.getElementById("ctl00_cphMain_chkGolf").checked = false;
    document.getElementById("ctl00_cphMain_chkPool").checked = false;
    document.getElementById("ctl00_cphMain_chkCityViews").checked = false;
    document.getElementById("ctl00_cphMain_chkQuick").checked = false;
    document.getElementById("ctl00_cphMain_chkGarage").checked = false;
}


function AddedToWatchlist(result, userContext, methodName) {
    document.getElementById("WatchListContent").innerHTML = "Property Added To Watchlist<br />" + 
        "<a href=\"../../account/manage/watchlist.aspx\">Go To Watchlist&nbsp;>></a>";
}

// Callback function invoked on failure 
// of the page method.
function OnFailed(error, userContext, methodName) 
{
    alert(error.get_message());
    /*
    if(error !== null) 
    {
        displayElement.innerHTML = "An error occurred: " + 
            error.get_message();
    }
    */
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

       
       
       function HideAdvancedSearch(){
            document.getElementById("divAdvancedSearch").style.display = "none";
            document.getElementById("divAdvancedSearch").style.visibility = "hidden";
       }
       
       
       function ShowAdvancedSearch(event, elem, p){

//            if (document.getElementById("divAdvancedSearch").style.visibility == "visible"){
//                HideAdvancedSearch()
//                return;
//            }
            
            
            var xPos = findPosX(elem);
            var yPos = findPosY(elem);
            
            if (p == 0){
                xPos = xPos + 160;
                yPos = yPos - 93;
            }
            else {
                xPos = xPos + 160;
                yPos = yPos - 210;
            }

            document.getElementById("divAdvancedSearch").style.left = xPos + 'px'
            document.getElementById("divAdvancedSearch").style.top = yPos + 'px';
            document.getElementById("divAdvancedSearch").style.display = "Block";
            document.getElementById("divAdvancedSearch").style.visibility = "visible";
            document.getElementById("divAdvancedSearch").style.position = "absolute";
       }
       
       
    
        var propID = null;
    
        function HideWatchListDiv() {
            // alert(propID);
            document.getElementById("AddToWatchlistDiv").style.display = "none";
            document.getElementById("AddToWatchlistDiv").style.visibility = "hidden";
        }
    
        function ShowWatchListDiv(event, elem, p) {
            propID = p;
            var xPos = findPosX(elem);
            var yPos = findPosY(elem);
            
            // alert(propID);
            //alert("X :" + e.clientX);
            //alert("Y :" + e.clientY);
            document.getElementById("AddToWatchlistDiv").style.left = xPos + 'px'
            document.getElementById("AddToWatchlistDiv").style.top = yPos + 'px';
            document.getElementById("AddToWatchlistDiv").style.display = "Block";
            document.getElementById("AddToWatchlistDiv").style.visibility = "visible";
            document.getElementById("AddToWatchlistDiv").style.position = "absolute";
            
            // document.getElementById("WatchListContent").innerHTML = "Saving Property To Watchlist...";
            
            
            // now call web service to save the property to the watchllist
            // check to see if the user is logged in
            PageMethods.GetUserName(OnSucceeded,OnFailed);
        }
    
        function VerifyFormForWatchList() {
            if(!VerifyProperties()) {
                alert("Please select a few properties first");
                return false;
            } return confirm("Are you sure you want to add these properties to your watch list");                    
        }
        
         function VerifyProperties() {
            var isChecked = false;
            var theForm = document.forms['aspnetForm'];
            if (!theForm) {
                theForm = document.aspnetForm;
            }
            for(i = 0; i < theForm.elements.length;i++) {
                if(theForm.elements[i].type == "checkbox" 
                    && theForm.elements[i].name.indexOf("chkRes") == -1 
                        && theForm.elements[i].name.indexOf("chkCond") == -1 ) {
                    if(theForm.elements[i].checked == 1) {
                        isChecked = true;
                    }
                }
            }
            return isChecked;
        }
    
    
        function ResetSearchForm(txtArea,
                                ddMinPrice,
                                ddMaxPrice,
                                ddBed,
                                ddBath,
                                ddSqft,
                                chkRes,
                                chkCondo) {
            document.getElementById(txtSBox).innerHTML = "";
            document.getElementById(ddMinPrice).selectedIndex = 0;
            document.getElementById(ddMaxPrice).selectedIndex = document.getElementById(ddMaxPrice).length-1;
            document.getElementById(ddBed).selectedIndex = 0;
            document.getElementById(ddBath).selectedIndex = 0;
            document.getElementById(ddSqft).selectedIndex = 0;
            document.getElementById(chkRes).checked = true;
            document.getElementById(chkCondo).checked = true;
            return false;
        }
        
         function open_window2(url,w,h) {
            var status_string = "resizable=1,location=no,menubar=1,status=no,toolbar=1,scrollbars=1,left=10,top=10,width="+w+",height="+h;
            open(url, "_blank", status_string);
        }
        
        


// find the x position of an object
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

// find the y position of an object
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function searchByNewCriteria(sSearch){
    closeMod();
    this.theForm["ctl00$cphMain$txtSBox"].value = sSearch;
    __doPostBack('bSearch', sSearch);
}

function closeMod(){
$find("modKeyWords").hide(); 
    
}













function changeDD(sArea, sMinPrice, sMaxPrice, sBeds, sBaths, sSqft){

    clocation = document.getElementById("txtArea");
    ddMinPrice = document.getElementById("ddMinPrice");
    ddMaxPrice = document.getElementById("ddMaxPrice");
    comboBeds = document.getElementById("comboBeds");
    comboBaths = document.getElementById("comboBaths");
    comboSqFt = document.getElementById("comboSqFt");
    
    alert(ddMinPrice);
    alert(ddMaxPrice);
    alert(comboBeds);
    alert(comboBaths);
    alert(comboSqFt);
    
    matchDropDown(ddMinPrice, sMinPrice);
    matchDropDown(ddMaxPrice, sMaxPrice);
    matchDropDown(comboBeds, sBeds);
    matchDropDown(comboBaths, sBaths);
    matchDropDown(comboSqFt, sSqft);
    //matchDropDown(clocation, sArea);

}


function matchDropDown(dd, matchvalue){
for (var i = 0; i < dd.options.length; i++) {
    if (dd.options[i].value == matchvalue){
        dd.selectedIndex = i;
        break;
    }
}
}
     
function openHoodWindow(){

    sList = window.open("../Search/Maps/CustomMap.htm", "Neighborhoods", "width=800,height=690");


}




// new script code to support overlib
function ShowOverLib( picUrl ) {
    var overLibContent = "<div style='padding:5px 4px 4px 4px;'>" + 
        "<div style='height:30px;'><div style='float:left;'><img src='../../App_Themes/ReLogic1/Images/rollover_logo.png' /></div>" +
        "<div style='float:right;font-weight:bolder;color:#006699; padding-top:7px;padding-right:5px;'>1.866.697.3564</div></div>" +
        "<img src='" + picUrl + "' /></div>" +
        "<div align='center' style='padding-bottom:5px;color:#006699;font-weight:bolder;'>Click to see detailed property info<br /> and more pics</div>";
    return overlib( overLibContent, VAUTO, FGCOLOR, '#FFFFFF' );
}



 function doClear(theText,add) 
{
     if (theText.value == "Address, City, Zip Code, or MLS#")
    {
         theText.value = "";
     }
     
     ifSo (add == true && theText.value == ""){ theText.value = "Address, City, Zip Code, or MLS#"; }
 }
 

            var t1;
            
            function isValidEmail(email, required) {
        if (required==undefined) {   // if not specified, assume it's required
            required=true;
        }
        if (email==null) {
            if (required) {
                return false;
            }
            return true;
        }
        if (email.length==0) {  
            if (required) {
                return false;
            }
            return true;
        }
        if (! allValidChars(email)) {  // check to make sure all characters are valid
            return false;
        }
        if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
            return false;
        } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
            return false;
        } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
            return false;
        } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	    return false;
        } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	    return false;
        }
        return true;
    }

    function allValidChars(email) {
      var parsed = true;
      var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
      for (var i=0; i < email.length; i++) {
        var letter = email.charAt(i).toLowerCase();
        if (validchars.indexOf(letter) != -1)
          continue;
        parsed = false;
        break;
      }
      return parsed;
    }
    function ShowMotionTween() {
        // we also need to find the center of the browser
        // ..
        var elem = document.getElementById("divMarker");
        var x = findPosX(elem);

        // now do the stuff
        document.getElementById("motionDiv").style.top = -305 + 'px';
        document.getElementById("motionDiv").style.left = (x + 50) + 'px';
        document.getElementById("motionDiv").style.display = "block";
        document.getElementById("motionDiv").style.visibility = "visible";
        t1 = new Tween(document.getElementById("motionDiv").style, "top", Tween.strongEaseIn,-505, 200, 1, 'px');
        t1.onMotionFinished = function(){
            var e = document.getElementById("BottomMarker");
            var y = findPosY(e);
            
            document.getElementById("modalBG").style.height = y + 'px';
            document.getElementById("modalBG").style.display = "block";
           
        
        };
        t1.start();
    }
    function HideMotionTween() {
        t1 = new Tween(document.getElementById("motionDiv").style, "top", Tween.strongEaseIn, 200, -505, 1, 'px');
        t1.onMotionFinished = function() {
           document.getElementById("modalBG").style.display = "none";
        };
        t1.start();
    }
