﻿// JScript File
<!-- hide script from old browsers


function log(message) {

//    if (console) {
//        if (console.log) {
//            console.log(message);       
//        }
//    }    
}


function GetRequestObject() {
    var areq = false;

    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        try {
            areq = new XMLHttpRequest();
        } catch (e) {
            areq = false;
        }
        // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        try {
            areq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                areq = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                areq = false;
            }
        }
    }
    return areq;
}



/////////////////////////////////////////////////////////////////////////////////////////////
// called when user clicks a feature and is not logged in, will try to show the modal dialog
// In the aspx page so we can generate the client id for the modal server control
function ShowSubscriberBox()
{
   try{ 
      var moddialog = $find("pnlSubscribeBox");
      moddialog.show();
      // The following is a hacky fix for a problem in webkit browsers where the default z-index is auto.
      // Only thing that I could find to fix it!  C. Golob
      moddialog._foregroundElement.style.zIndex = 10001;
      var obj = document.getElementById('ctl00_ucModalLogin_tbModalLoginUN');
      if ( obj )
        obj.focus();
      
   }
   catch(ex){var i;}
}




function HideSubscriberBox()
{
   try{ 
      var moddialog = $find("pnlSubscribeBox");
      moddialog.hide();
   }
   catch(ex){var i;}
}



function HideSplashModal()
{
   try{ 
      var moddialog = $find("pnlSplashModal");
      moddialog.hide();
   }
   catch(ex){var i;}
}


function showFeedbackDialog()
{
  window.open(FeedbackURL, 'windowname1', 'left=350,top=175,width=400, height=400');
  return false;
}


function showTermsOfUseDialog()
{
  window.open('TermsPopup.aspx', 'TermsPopup', 'scrollbars=1,left=350,top=150,width=900, height=670');
  return false;
}



function ShowQuickLoginDialog()
{
   try{ 
      var moddialog = $find("pnlLoginDialog");
      // The following is a hacky fix for a problem in webkit browsers where the default z-index is auto.
      // Only thing that I could find to fix it!  C. Golob
      moddialog._foregroundElement.style.zIndex = 10001;
      moddialog.show();
      var obj = document.getElementById('ctl00_ucModalQuickLogin_tbModalLoginUN');
      if ( obj ) obj.focus();        
   }
   catch(ex){var i;}
}

function ShowQuickPropertyMarketDialog()
{
   try{ 
      var moddialog = $find("MarketCompareGraph");
      // The following is a hacky fix for a problem in webkit browsers where the default z-index is auto.
      // Only thing that I could find to fix it!  C. Golob
      moddialog.show();
      moddialog._foregroundElement.style.zIndex = 10001;
          
   }
   catch(ex){var i;}
}


function ShowPasswordResetDialog()
{
   try{ 
   
      var moddialog = $find("pnlLoginDialog");
      moddialog.hide();
      var moddialog2 = $find("pnlSubscribeBox");
      moddialog2.hide();
      
      var moddialog = $find("pnlPasswordResetDialog");
      // The following is a hacky fix for a problem in webkit browsers where the default z-index is auto.
      // Only thing that I could find to fix it!  C. Golob
      moddialog._foregroundElement.style.zIndex = 10001;
      moddialog.show();
      //var obj = document.getElementById('ctl00_ucModalQuickLogin_tbModalLoginUN');
      //if ( obj ) obj.focus();        
   }
   catch(ex){var i;}
}


function ShowNewsletterDialog()
{
   try{ 
      var moddialog = $find("pnlNewsletterDialog");
      // The following is a hacky fix for a problem in webkit browsers where the default z-index is auto.
      // Only thing that I could find to fix it!  C. Golob
      moddialog._foregroundElement.style.zIndex = 10001;
      moddialog.show();
   }
   catch(ex){var i;}
}

function ShowSaveSearchBox() { 
   try{ 
        
        if(!HasCheckProperty())
        {
            alert("Please select at least one property for this search.");
            return false;
        }
        else
        {
              var moddialog = $find("pnlSaveSearchDialog");
              // The following is a hacky fix for a problem in webkit browsers where the default z-index is auto.
              // Only thing that I could find to fix it!  C. Golob
              moddialog._foregroundElement.style.zIndex = 10001;
              moddialog.show();
              var obj = document.getElementById('ctl00_ContentPlaceHolder1_ModalSaveSearch1_txtSearchName');
              if ( obj ) obj.focus();  
      }
   }
   catch(ex){var i;}

}
function HideSaveSearchBox() { 
   try{ 
      var moddialog = $find("pnlSaveSearchDialog");
      moddialog.hide();
   }
   catch(ex){var i;}

}
function clickBtn(btn)
{
    if ( btn && btn != 'undefined' )
	{
	    if ( btn.setActive )
		    btn.setActive();
        if ( btn.click )
		    btn.click();
    }
}
function clickBtnById(btnID)
{
	var btn=document.getElementById(btnID);

    if ( btn && btn != 'undefined' )
	{
	    if ( btn.setActive )
		    btn.setActive();
        if ( btn.click )
		    btn.click();
    }
}

function submitNewsletter(emailControlID, nameControlID) {
    
    objForm = document.getElementById("aspnetForm");
    emailTextBox = document.getElementById(emailControlID);
    nameTextBox = document.getElementById(nameControlID);
    sourceTextBox = document.getElementById('SourceTextBox');
    emailVar = document.getElementById("l235206-235206");
    nameVar = document.getElementById("name");
   
    if ( nameTextBox ) {
        nameVar.value = nameTextBox.value;
       }
    if ( objForm && emailTextBox && emailVar) {
        emailVar.value = emailTextBox.value;
        objForm.action = "http://realtydatatrust.cmail1.com/s/235206/";
        objForm.submit();		        
        var sPath = window.location.pathname;
        var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
        objForm.action = sPage;
           
    }
}

/*this function can be called by the onKeyDown event of a textbox, 
and will trigger a specific button to fire when enter key is pressed*/
function fnTrapKD(btnID, event)
{
    //alert('fnTrapKD');  
	btn=document.getElementById(btnID);
	if ( !btn || btn == 'undefined') return;
	
	
	try 
	{
	
		if (event.keyCode == 13)
		{
			event.returnValue=false;
			event.cancel = true;
			if ( btn )
			{
				if ( btn.setActive )
				   btn.setActive();
				if ( btn.click )
                   window.setTimeout( btn.click(),1000);
				
				//   btn.click();
			}
		}
	}
	catch (er)
	{
	;
	}
}//fnTrapKD


function CancelClick()
{
    return false;
}


function ShowElement(ElementID)
{
    var d = document;
    var el=d.getElementById?d.getElementById(ElementID):d.all?d.all[id]:d.layers[id];
    el.style.visibility = "visible";
}

// hide document element
function HideElement(ElementID)
{
    var d = document;
    var el=d.getElementById?d.getElementById(ElementID):d.all?d.all[id]:d.layers[id];
    if (el)
    {
        el.style.visibility = "hidden";
    }
}

function ShowElement2(ElementID)
{
    var d = document;
    var el=d.getElementById?d.getElementById(ElementID):d.all?d.all[id]:d.layers[id];
    el.style.display = 'block';
}

// hide document element
function HideElement2(ElementID)
{
    var d = document;
    var el=d.getElementById?d.getElementById(ElementID):d.all?d.all[id]:d.layers[id];
    if (el)
    {
        el.style.display = 'none';
    }
}

function ToggleSection(sectionClass)
{
    var theSectionHeader = $('div.'+sectionClass + " > div.IndicesHeaderPanel");
    var theSectionImg = $('div.'+sectionClass + " > div.IndicesHeaderPanel > img");
    var theSectionContent = $('div.'+sectionClass + " > div.IndicesContentPanel");
    theSectionContent.toggle('slow', 
    function()
    {
        switch (this.style.display)
        {
            case 'none':
                theSectionImg[0].src = 'Images/rpcIconLeftArrow.gif';
                theSectionImg.attr("alt", "Expand");
                theSectionHeader.attr("title", "Expand");
                break;
            default:            
                theSectionImg[0].src = 'Images/rpcIconDownArrow.gif';
                theSectionImg.attr("alt", "Collapse");
                theSectionHeader.attr("title", "Collapse");
                break;
        }
    });
}


//Toggles the MarketIndicies Sections.
function ToggleThematicSection(sectionClass)
{
    var theSectionHeader = $('#indices_container div.'+sectionClass + " > div.IndicesHeaderPanel");
    var theSectionImg = $('#indices_container div.'+sectionClass + " > div.IndicesHeaderPanel > img");
    var theSectionContent = $('#indices_container div.'+sectionClass + " > div.IndicesContentPanel");
    theSectionContent.toggle('slow', 
    function()
    {
        switch (this.style.display)
        {
            case 'none':
                theSectionImg[0].src = 'Images/rpcIconLeftArrow.gif';
                theSectionImg.attr("alt", "Expand");
                theSectionHeader.attr("title", "Expand");
                break;
            default:            
                theSectionImg[0].src = 'Images/rpcIconDownArrow.gif';
                theSectionImg.attr("alt", "Collapse");
                theSectionHeader.attr("title", "Collapse");
                break;
        }
    });
}


// Todo: I can find any place where this is used. Delete after deploy. C. Golob
function TabShow(ElementID)
{
    var d = document;
    var el=d.getElementById?d.getElementById(ElementID):d.all?d.all[id]:d.layers[id];
    el.style.display = "block";
}

// Todo: I can find any place where this is used. Delete after deploy. C. Golob
function TabHide(ElementID)
{
    var d = document;
    var el=d.getElementById?d.getElementById(ElementID):d.all?d.all[id]:d.layers[id];
    if (el)
    {
        el.style.display = "none";
    }
}


// Todo: I can find any place where this is used. Delete after deploy. C. Golob
function ManageTabPanelDisplay() {
//
// Between the parenthesis, list the id's of the div's that 
//     will be affected when tabs are clicked. List in any 
//     order. Put the id's in single quotes (apostrophes) 
//     and separate them with a comma -- all one line.
//
var idlist = new Array('Div_ShowGrid_Ready','Div_ShowGrid_Focus', 'Div_ShowGraph_Ready','Div_ShowGraph_Focus', 'Div_SaveSearch_Ready', 'Div_SaveSearch_Focus', 'Div_ShowIndices_Ready', 'Div_ShowIndices_Focus', 'Div_CustomSearch_Ready', 'Div_CustomSearch_Focus', 'grid_container','graph_container', 'savedSearch_container', 'customSearch_container', 'indices_container');

// No other customizations are necessary.
if(arguments.length < 1) { return; }
for(var i = 0; i < idlist.length; i++) {
   var block = false;
   for(var ii = 0; ii < arguments.length; ii++) {
      if(idlist[i] == arguments[ii]) {
         block = true;
         break;
         }
      }
   if(block) { document.getElementById(idlist[i]).style.display = "block"; }
   else { document.getElementById(idlist[i]).style.display = "none"; }
   }
}

// Todo: I think this will go away when the hide results does. C. Golob
function iterateThroughTableAndHideRows(oTableId,bShow)
{
	// Make sure we can get a reference to the tables
	if (document.getElementById(oTableId) == null) return;
	
	var oTable = document.getElementById(oTableId);
	var iRowCount = oTable.rows.length;
	for(var iCurrentRow = 0; iCurrentRow < iRowCount; iCurrentRow++)
	{		
	    var currentRow = oTable.rows[iCurrentRow];
	    var hideThisRow=false;
		if(currentRow.getAttribute('propertyid')!=null)
		{
		    hideThisRow=true;		    
		}else if (currentRow.cells[0].innerHTML=='&nbsp;'){
		    hideThisRow=true;
		}
		if (hideThisRow==true){
		    if(bShow==true){
	            if (whichBrs()=='IE')
				    currentRow.style.display = 'block';
			    else
    				currentRow.style.display = 'table-row';		        
	        }else{
	            currentRow.style.display = 'none';
	        }
	    }
	}   
}

function whichBrs() {
	var agt=navigator.userAgent.toLowerCase();

	if (agt.indexOf("opera") != -1) return 'Opera';
	if (agt.indexOf("staroffice") != -1) return 'Star Office';
	if (agt.indexOf("beonex") != -1) return 'Beonex';
	if (agt.indexOf("chimera") != -1) return 'Chimera';
	if (agt.indexOf("netpositive") != -1) return 'NetPositive';
	if (agt.indexOf("phoenix") != -1) return 'Phoenix';
	if (agt.indexOf("firefox") != -1) return 'Firefox';
	if (agt.indexOf("safari") != -1) return 'Safari';
	if (agt.indexOf("skipstone") != -1) return 'SkipStone';
	if (agt.indexOf("msie") != -1) return 'IE';
	if (agt.indexOf("netscape") != -1) return 'Netscape';
	if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
	if (agt.indexOf('\/') != -1) {
		if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
			return navigator.userAgent.substr(0,agt.indexOf('\/'));}
		else
			return 'Netscape';}
	else if (agt.indexOf(' ') != -1)
		return navigator.userAgent.substr(0,agt.indexOf(' '));
	else
		return navigator.userAgent;
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


function MouseCoords()
{
	this.X = 0;
	this.Y = 0;
}


function captureMouseCoords(e, obj) {
  // CRED: http://www.howtocreate.co.uk/tutorials/javascript/eventinfo
  // BEGIN:
  obj.X=0;
  obj.Y=0;
  
  if( !e ) 
  { 
    e = window.event; 
  }
  if( !e ) 
  { 
    return; 
  }
  if( typeof( e.pageX ) == 'number' ) 
  {
    obj.X = e.pageX;
    obj.Y = e.pageY;
  } 
  else if( typeof( e.clientX ) == 'number' ) 
  {
    obj.X = e.clientX;
    obj.Y = e.clientY;
    if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
    {
      obj.X += document.body.scrollLeft;
      obj.Y += document.body.scrollTop;
    } 
    else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
    {
      obj.X += document.documentElement.scrollLeft;
      obj.Y += document.documentElement.scrollTop;
    }
  }
  // catch possible negative values in NS4
  if (obj.X < 0){obj.X = 0}
  if (obj.Y < 0){obj.Y = 0}  
}


//formats a number in the format of $1,000.00
function formatCurrency(num, showDecimal) {
    var dec = formatDecimal ( num, showDecimal )
    if (dec.indexOf('-') >= 0) 
        return '-' + '$' + dec.substring(1,150);
    else
        return '$' + dec;
    
}


//formats a number in the format of 1,000.00
function formatDecimal(num, showDecimal) {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));
    if (showDecimal) 
        return (((sign)?'':'-')  + num + '.' + cents);
    else
        return (((sign)?'':'-') + num );
    
}

function formatSliderText(str, source) {
    if ( str.indexOf('-') >0 ) {
        var parts = str.split("-");
        if ( source.indexOf('sqft') > 0 ) 
        	str = formatCurrency(parts[0], false).replace('$','') + " - " + formatCurrency(parts[1], false).replace('$','');
        else if ( source.indexOf('rent') > 0 )	
        	str = formatCurrency(parts[0], false) + " - " + formatCurrency(parts[1], false);
    }
    else {
        if ( source.indexOf('sqft') > 0  ) 
 	        str = formatCurrency(str, false).replace('$','');	
        else if ( source.indexOf('rent') > 0 )	
 	        str = formatCurrency(str, false);	
        else if (source.indexOf('date') > 0 )
     	    str = '<= ' + str; 
    }
 	return str;
}


function getQueryStringByKey(searchKey) {
 var qrStr = window.location.search;
    var spQrStr = qrStr.substring(1);
    var arrQrStr = new Array();
    // splits each of pair
    var arr = spQrStr.split('&');

    for (var i=0;i<arr.length;i++)  {
        // splits each of field-value pair
        var index = arr[i].indexOf('=');
        var key = arr[i].substring(0,index);
        var val = arr[i].substring(index+1);
        // saves each of field-value pair in an array variable
        if ( key == searchKey )  {
            return val;
        }
    }
    return '';

}

$(document).ready(function() {
    BindToggleRowEnabled();
});

function BindToggleRowEnabled()
{
    $('.RowEnabledToggler input').click(ToggleRowEnabled);  
    $('.RowEnabledToggler input').each(ToggleRowEnabled);
}

function ToggleRowEnabled()
{
    var tr =  $(this).parent().parent().parent();
    
    if(tr.length == 1)
    {
        if(this.checked)
        {
            tr.find('input:not(#'+ this.id +')').filter(':not(.TogglerIgnore)').removeAttr("disabled");
            tr.find('select:not(#'+ this.id +')').filter(':not(.TogglerIgnore)').removeAttr("disabled");
        }
        else
        {
            tr.find('input:not(#'+ this.id +')').filter(':not(.TogglerIgnore)').attr("disabled", "true");
            tr.find('select:not(#'+ this.id +')').filter(':not(.TogglerIgnore)').attr("disabled", "true");
        }
        tr.find(":hidden").removeAttr("disabled");
    }
    
    
}


/*  
===============================================================================
WResize is the jQuery plugin for fixing the IE window resize bug
...............................................................................
Copyright 2007 / Andrea Ercolino
-------------------------------------------------------------------------------
LICENSE: http://www.opensource.org/licenses/mit-license.php
WEBSITE: http://noteslog.com/
===============================================================================
*/

(function($) {
    $.fn.wresize = function(f) {
        version = '1.1';
        wresize = { fired: false, width: 0 };

        function resizeOnce() {
            if ($.browser.msie) {
                if (!wresize.fired) {
                    wresize.fired = true;
                }
                else {
                    var version = parseInt($.browser.version, 10);
                    wresize.fired = false;
                    if (version < 7) {
                        return false;
                    }
                    else if (version == 7) {
                        //a vertical resize is fired once, an horizontal resize twice
                        var width = $(window).width();
                        if (width != wresize.width) {
                            wresize.width = width;
                            return false;
                        }
                    }
                }
            }

            return true;
        }

        function handleWResize(e) {
            if (resizeOnce()) {
                return f.apply(this, [e]);
            }
        }

        this.each(function() {
            if (this == window) {
                $(this).resize(handleWResize);
            }
            else {
                $(this).resize(f);
            }
        });

        return this;
    };

})(jQuery);


jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}

jQuery.fn.enabled = function(val) { 
    if(val)
    {
        this.enable();
    }
    else
    {    
        this.disable();
    }
} 

jQuery.fn.disable = function() { 
    return this.attr('disabled', true).addClass('disabled'); 
} 

jQuery.fn.enable = function() { 
    return this.removeClass('disabled').attr('disabled', false); 
} 

function showModalMessage(message)
{
    showModalMessage(message, false)
}


function showModalMessage(message, backgroundTrans)
{

    var hide = $('#modelContentBackground');
    var dialog = $('#modelContentDiv');
    
    if(hide.length == 0)
    {
        $('body').append("<div id='modelContentBackground' style='filter: alpha(opacity=10);opacity: 0.1;background:black;position:absolute;top:0;left:0;'></div>");
        hide = $('#modelContentBackground');
    }
    if(dialog.length == 0)
    {
        $('body').append("<div id='modelContentDiv' style='position:absolute;background:white;border:1px solid black;padding:5px;'></div>");
        dialog = $('#modelContentDiv');
    }
    
    if(!backgroundTrans)
    {
        hide.css({'background': 'black'});
    }
    else
    {
        hide.css({'background': 'transparent'});
    }

     //Get the screen height and width
     var hideHeight = $(document).height();
     var hideWidth = $(window).width();

     //Set heigth and width to hide to fill up the whole screen
         
    dialog.html(message);
    dialog.center();

    dialog.show();
    
    hide.css({'width':hideWidth,'height':hideHeight});    
    hide.show();   

 }
     

function hideModelMessage()
{
    var hide = $('#modelContentBackground');
    var dialog = $('#modelContentDiv');
    hide.hide();
    dialog.hide();

}