var currentChild=0;
var guestbookStartID=0;
var gl_weatherZip="92831";
var hideNavChildInterval = 0;
/*
 * DateFormat.js
 * Formats a Date object into a human-readable string
 *
 * Copyright (C) 2001 David A. Lindquist (http://www.gazingus.org)
 */

Date.MONTHS = [
  'January', 'February', 'March', 'April', 'May', 'June', 'July',
  'August', 'September', 'October', 'November', 'December'
];

Date.DAYS = [
  'Sunday', 'Monday', 'Tuesday', 'Wednesday',
  'Thursday', 'Friday', 'Saturday'
];

Date.SUFFIXES = [
  'st','nd','rd','th','th','th','th','th','th','th',
  'th','th','th','th','th','th','th','th','th','th',
  'st','nd','rd','th','th','th','th','th','th','th',
  'st'
];

Date.prototype.format = function( mask ) {
  var formatted     = ( mask != null ) ? mask : 'DD-MMM-YY';
  var letters       = 'DMYHdhmst'.split( '' );
  var temp          = new Array();
  var count         = 0;
  var regexA;
  var regexB        = /\[(\d+)\]/;

  var day           = this.getDay();
  var date          = this.getDate();
  var month         = this.getMonth();
  var year          = this.getFullYear().toString();
  var hours         = this.getHours();
  var minutes       = this.getMinutes();
  var seconds       = this.getSeconds();

  var formats       = new Object();
  formats[ 'D' ]    = date;
  formats[ 'd' ]    = date + Date.SUFFIXES[ date - 1 ];
  formats[ 'DD' ]   = ( date < 10 ) ? '0' + date : date;
  formats[ 'DDD' ]  = Date.DAYS[ day ].substring( 0, 3 );
  formats[ 'DDDD' ] = Date.DAYS[ day ];
  formats[ 'M' ]    = month + 1;
  formats[ 'MM' ]   = ( month + 1 < 10 ) ? '0' + ( month + 1 ) : month + 1;
  formats[ 'MMM' ]  = Date.MONTHS[ month ].substring( 0, 3 );
  formats[ 'MMMM' ] = Date.MONTHS[ month ];
  formats[ 'Y' ]    = ( year.charAt( 2 ) == '0' ) ? year.charAt( 3 ) : year.substring( 2, 4 );
  formats[ 'YY' ]   = year.substring( 2, 4 );
  formats[ 'YYYY' ] = year;
  formats[ 'H' ]    = hours;
  formats[ 'HH' ]   = ( hours < 10 ) ? '0' + hours : hours;  
  formats[ 'h' ]    = ( hours > 12 || hours == 0 ) ? Math.abs( hours - 12 ) : hours;
  formats[ 'hh' ]   = ( formats[ 'h' ] < 10 ) ? '0' + formats[ 'h' ] : formats[ 'h' ];
  formats[ 'm' ]    = minutes;
  formats[ 'mm' ]   = ( minutes < 10 ) ? '0' + minutes : minutes;
  formats[ 's' ]    = seconds;
  formats[ 'ss' ]   = ( seconds < 10 ) ? '0' + seconds : seconds;
  formats[ 't' ]    = ( hours < 12 ) ?  'A' : 'P';
  formats[ 'tt' ]   = ( hours < 12 ) ?  'AM' : 'PM';

  for ( var i = 0; i < letters.length; i++ ) {
    regexA = new RegExp( '(' + letters[ i ] + '+)' );
    while ( regexA.test( formatted ) ) {
      temp[ count ] = RegExp.$1;
      formatted = formatted.replace( RegExp.$1, '[' + count + ']' );
      count++;
    }
  }

  while ( regexB.test( formatted ) ) {
    formatted = formatted.replace( regexB, formats[ temp[ RegExp.$1 ] ] );
  }

  return formatted;
}

function rgb(r,g,b){	
	return r.toString(16) + g.toString(16) + b.toString(16);
}

var ua = navigator.userAgent.toLowerCase(),
	isOpera = (ua.indexOf('opera') > -1),
	isSafari = (ua.indexOf('safari') > -1),
	isGecko = (!isOpera && !isSafari && ua.indexOf('gecko') > -1),
	isIE = (!isOpera && ua.indexOf('msie') > -1); 

function showNavChildren(ItemID) {
    var child = document.getElementById('navChildren_' + ItemID);
    
    if(currentChild != 0 && currentChild != ItemID){
		hideNavChildren(currentChild);
    }
	window.clearInterval(hideNavChildInterval);
    
    if(child){
    
        currentChild = ItemID;
        child.style.display="block";
        child.style.position="absolute";
        child.onmouseover = function() { 
			var myID = this.id.split('_');
			showNavChildren(parseInt(myID[1]));
		};
        
        hideNavChildInterval = window.setInterval("hideNavChildren(" + ItemID +")",3000);
    }
}

function hideNavChildren(ItemID) {
	window.clearInterval(hideNavChildInterval);
    var child = document.getElementById('navChildren_' + ItemID);
    
    if(child){
        child.style.display="none";
    }
}


function hideAllChildren(object, itemID){
    
    /*if(object!=null){
        alert(object.parentNode.id);
    }*/
    
    
     
    /*if(itemID==0){
        alert('test');
    }*/
}

// Function to add a bookmark for all browsers
 function addClientSideBookmark(Url, Title) {
	if (window.sidebar) // Mozilla Firefox Bookmark
		window.sidebar.addPanel(Title, Url, '');
	else if (window.external) // IE Favorite
		window.external.AddFavorite(Url, Title);
    else
        alert('Your browser doesn\'t support this function.\nHowever, you may add the site to your bookmarks list manually.');
 }

//status flash code
var message=""; 
var speed=400; 
var visible=0; 

function Flash(flashtext,flashspeed) { 
    speed=flashspeed;
    message=flashtext;
    
    if (visible == 0) { 
        window.status=message; 
        visible=1; 
    } else { 
        window.status=""; 
        visible=0; 
    } 
    
    setTimeout('Flash()', speed); 
}

//status scroll code
var Count = 0; 
var Text = ""; 
var Speed = 90; 
var timerID = null; 
var TimerRunning = false; 
var i = 0; 

function Scroll() { 
    window.status = Text.substring(Count++, Text.length); 
    if (Count == Text.length) Count = 0; 
    timerID = setTimeout("Scroll()", Speed); 
    TimerRunning = true; 
}

function StartScroll(scrolltext,scrollspeed)
{ 
    Text=scrolltext;
    Speed=scrollspeed;
	if(Text != " "){
		while (i ++ < 140) Text = " " + Text; 

		Stop(); 
		Scroll(); 
	}
} 

function Stop(){ 
    if(TimerRunning) clearTimeout(timerID); 
    TimerRunning = false; 
}

//popup
function popUp(URL,options) 
{
    //alert(URL);
    day = new Date();
    id = day.getTime();
    var thisPopup = window.open(URL, id, options);
    
    //return false;
}

// JavaScript Document

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	//if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	//}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		learnMore1_over = newImage("images/learnMoreTeal-over.gif");
		learnMore2_over = newImage("images/learnMoreOrange-over.gif");
		preloadFlag = true;
	}
}

function closeMe(){
    if(window.opener.closed == false){
		window.close();
		window.opener.focus();
	}else if(window.opener.closed == true){
		window.open("index.htm");
		window.close();
	}
}

function addToFavorites(url,name) { 
    if (window.external) { 
        window.external.AddFavorite(url,name);
    } else { 
        alert("Sorry! Your browser doesn't support this function.");
    }
}

var lastXMLDocMethod="";

function loadXMLDoc(url,method,postType,postVars,processFunction){
    loadXMLDocAdv(url,method,postType,postVars,processFunction,true,"http://DiverseSolutions.com");
}

function loadXMLDoc(url,method,postType,postVars,processFunction,async){
    loadXMLDocAdv(url,method,postType,postVars,processFunction,async,"http://DiverseSolutions.com");
}



function AjaxHandler( strHandler ) {
    var request = null;
    var handler = strHandler;
    
    this.register = function( req ) {
        request = req;
        return this.change;
    };
    this.change = function() {
        //if(request.readyState == 4 && request.status != 200) alert(lastXMLDocMethod);
        handler(request);
    };
}

function loadXMLDocAdv(url,method,postType,postVars,processFunction,async,nameSpace) {
    //dalert(nameSpace);
    if(async+'' == "undefined") async = true;
    if(nameSpace+'' == "undefined") nameSpace = "http://DiverseSolutions.com";
    
    lastXMLDocMethod=method;
    var req=false;
    
    if (window.XMLHttpRequest) { 
    
        try {
                
            req = new XMLHttpRequest();
            
        } catch(e) {
        
            reg=false;
        }
        
        try {
            netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
        } catch(e) {
        
        }
    }
    else if(window.ActiveXObject) { 
            try {
            req = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(e) {
            req=false;
        }
    }
    
    if(req) {
    
        
		var soap=null;
		var ajax = new AjaxHandler( processFunction );
		
		if(postType!="POST"){
		    
		    req.onreadystatechange = ajax.register( req );
		    req.open(postType, url, async);
		    
		}
		else if(postVars==""){
		    req.onreadystatechange = ajax.register( req );	    
		    req.open(postType, url, async);
		    req.setRequestHeader("Content-Type","text/xml");	    
		    soap="";
		    
		    soap += "<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">\n";
            soap += "<SOAP:Header></SOAP:Header>\n";
            soap += "<SOAP:Body>\n";
            soap += "     <"+ method +" xmlns=\""+ nameSpace +"\">\n";
            soap += "     </"+ method +">\n";
            soap += "</SOAP:Body>\n";
            soap += "</SOAP:Envelope>\n";	
            //alert(soap);
		} 
		else 
		{
		    req.onreadystatechange = ajax.register( req );
		    req.open(postType, url, async);		
		    req.setRequestHeader("Content-Type","text/xml");
		    soap="";
		    
		    var vars=postVars.split("&");
		    var thisVar;
    		
		    soap += "<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">\n";
            soap += "<SOAP:Header>\n";
            soap += "     <SoapBoxHeader xmlns=\""+ nameSpace +"\">\n";
            for(var i=0;i<vars.length;i++){
                thisVar=vars[i].split("=");
                if(thisVar.length==3 && thisVar[0] == "header"){
                    soap+= "<"+ thisVar[1] +">"+ thisVar[2] +"</"+ thisVar[1] +">\n";
                }    
            }
            soap += "     </SoapBoxHeader>\n";
            soap += "</SOAP:Header>\n";
            soap += "<SOAP:Body>\n";
            soap += "     <"+ method +" xmlns=\""+ nameSpace +"\">\n";
            for(var i=0;i<vars.length;i++){
                thisVar=vars[i].split("=");
                
                             
                
                if(thisVar.length==2){
                    var cData = thisVar[0].split("|");
                    
                    if(cData.length == 2 && cData[1] == "cdata") {
                        thisVar[0] = cData[0];
                        thisVar[1] = "<![CDATA[" + unescape(thisVar[1]) + "]]>";
                    }
                
                    soap+= "<"+ thisVar[0] +">"+ thisVar[1] +"</"+ thisVar[0] +">\n";
                }    
            }
            soap += "     </"+ method +">\n";
            soap += "</SOAP:Body>\n";
            soap += "</SOAP:Envelope>\n";
            //alert(soap);
		}
		
		req.send(soap);
    }
}

function dsSelectSingleNode(obj,name){
    if(obj.childNodes){
        for(var i=0;i<obj.childNodes.length;i++){
            if(obj.childNodes[i].nodeName == name){
                return obj.childNodes[i];
            }
        }
    }
    return null;
}

function getNodeValue(node, name){
    //alert(valNode);
    var valNode = dsSelectSingleNode(node,name);//node.getElementsByTagName(name)[0];
    
    if(valNode && valNode.firstChild){
        return valNode.firstChild.nodeValue;
    } else {
        return "";
    }
}

// retrieve text of an XML document element, including
// elements using namespaces
function getElementTextNS(prefix, local, parentElem, index) {
    var result = "";
    if (prefix && isIE) {
        // IE/Windows way of handling namespaces
        result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
    } else {
        // the namespace versions of this method 
        // (getElementsByTagNameNS()) operate
        // differently in Safari and Mozilla, but both
        // return value with just local name, provided 
        // there aren't conflicts with non-namespace element
        // names
        result = parentElem.getElementsByTagName(local)[index];
    }
    if (result) {
        // get text, accounting for possible
        // whitespace (carriage return) text nodes 
        if (result.childNodes && result.childNodes.length > 1) {
            return result.childNodes[1].nodeValue;
        } else {
            if(result.firstChild) {
                return result.firstChild.nodeValue;    	
            } else {
                return "";
            }
        }
    } else {
        return "";
    }
}

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 checkListingsGuestBook(){
    guestbookStartID = parseInt(guestbookStartID);
    
    var cookie = readCookie("listingsGuestbook");
    
    if((cookie == "" || cookie == null) && guestbookStartID >= 1){
        location.href="/properties/listingsGuestBook.aspx?URL=" + location.href;
    }
}

function replaceSlideShow(){

    var img = document.getElementsByName('imgSlideShow');

    if(img){
        for(var i=0;i<img.length;i++){                        
            if (img[i].getAttribute("tag") != 'FeaturedProperties'){
				new Ajax.Request("/slideshows/slideshow" + img[i].getAttribute("tag") + ".xml",{
					method: 'get',
					onSuccess : processSlideshow.bind(this,img[i])
				});
            } else {
				new Ajax.Request("/homeshow.xml",{
					method: 'get',
					onSuccess : processSlideshow.bind(this,img[i])
				});
            }
        }
    }
}

function processSlideshow(img, req){
    var response=req.responseXML.documentElement;
	var width, height, slideshowID, slideshowUrl, resizePhotos, showNavigation;
	
    if ((document.all && response != null) || (!document.all && response.childNodes.length == 5)) {
        slideshowID = getElementTextNS("","slideShowID",response,0);
        slideshowUrl = '/slideshows/slideshow' + getElementTextNS("","slideShowID",response,0) + '.xml';
        width = getElementTextNS("","width",response,0);
        height = getElementTextNS("","height",response,0);
        resizePhotos = getElementTextNS("","resizePhotos",response,0);
        showNavigation = getElementTextNS("","showNavigation",response,0);
        photoPause = getElementTextNS("","photoPause",response,0);
    } else {
        slideshowID = "FeaturedProperties";
        slideshowUrl = '/homeshow.xml';
        resizePhotos = 'true';
        showNavigation = 'true';
        photoPause = 4;
        width = 0;
        height = 0;
    }
              
			
    if(img){
        if(img.getAttribute("tag") + "" == slideshowID + "" || img.getAttribute("tag") == "FeaturedProperties"){                        
			if(img.getAttribute("tag") == "FeaturedProperties"){
    			slideshowID = "FeaturedProperties";
    			slideshowUrl = '/homeshow.xml';
    			resizePhotos = 'true';
    			showNavigation = 'true';
    			photoPause = 4;
    			width = 0;
    			height = 0;
			}
			
			if( img.getAttribute("showNavigation") && typeof img.getAttribute("showNavigation") != "undefined" && img.getAttribute("showNavigation").toLowerCase() == 'false'){
				showNavigation = 'false';
			}
			
            var FlashMajorVersion = com.deconcept.FlashObjectUtil.getPlayerVersion("7", true).major;
            //alert(FlashMajorVersion);

            var oDiv = document.createElement("div");
            var RandomId = Math.floor(Math.random()*1000) + "";
            if (FlashMajorVersion == 0) {
                var oText = null;
                var oAnchor = null;
                var oImg = null;
                var sText = "";
                
                oDiv.style.width = "214";
                oDiv.style.textAlign = "center";
                
                oText = document.createElement("TEXT");
                sText = 'This website makes use of Macromedia<sup style="font-size: 7px;">(R)</sup> Flash<sup style="font-size: 7px;">(TM)</sup> software. <br />';
		        sText += 'Your current version of Macromedia Flash Player cannot display this site. <br />'
		        sText += '<br />'
		        sText += 'Downloading the latest version is free and will only take a moment. <br />'
		        sText += 'Be sure to come back and explore our site when you are finished. <br />'
		        sText += '<br />'
		        oText.innerHTML = sText;
		        
		        oDiv.appendChild(oText);
		        
		        oAnchor = document.createElement("A");
		        oAnchor.target = "_blank";
		        oAnchor.href = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
		        
		        oImg = document.createElement("IMG");
		        oImg.src = "/aimages/ui/get_flash_player.gif";
		        oImg.width = 88;
		        oImg.height = 31;
		        oImg.border = 0;
		        
		        oAnchor.appendChild(oImg);
		        oDiv.appendChild(oAnchor);
		        
                img.style.display="none";
		        
            } else if (FlashMajorVersion < 8) {
				var so = new SWFObject("/aimages/ExpressInstaller.swf", RandomId + "_movie", "214", "137", "8", "#FFFFFF");
				so.addParam("wmode", "transparent");
				so.addParam("align", "middle");
				so.addVariable("TextColor", "0x000000");
				so.write(RandomId + "_div");
	            
                img.style.display="none";
                
                oDiv.style.padding = "4px";
                
                if(img.style.cssFloat != "" && img.style.cssFloat + "" != "undefined"){
					oDiv.style.cssFloat = img.style.cssFloat;
                } else if(img.style.styleFloat != "" && img.style.styleFloat + "" != "undefined"){
					oDiv.style.styleFloat = img.style.styleFloat;
                }
            } else {
			
				if (width == "" || width == "0" || width == 0 || width + "" == "undefined"){
					width = img.offsetWidth;
				}
				if (height == "" || height == "0" || height == 0 || height + "" == "undefined"){
					height = img.offsetHeight;
				}
				var so = new deconcept.SWFObject("/globalForms/mainSlideShow.swf?id=" + RandomId, RandomId + "_movie", width, height, "8", "#FFFFFF");

				so.addVariable("photoPause", photoPause);
				so.addVariable("slideShowXML", slideshowUrl);
				so.addVariable("showNav", showNavigation.toLowerCase());
				so.addVariable("resizePhotos", resizePhotos.toLowerCase());
				so.addParam("wmode", "transparent");
								
				oDiv.innerHTML = so.getSWFHTML();
				
				oDiv.style.width = width + "px";
				oDiv.style.height = height + "px";
            }
			
            img.parentNode.insertBefore(oDiv, img.nextSibling);
        }
        
		img.style.display="none";
    }
}

function loadPropertySlideshow(parentNode, xmlFile) {
    /*var embed = document.createElement("EMBED");
    
    embed.setAttribute("src", "/globalForms/mainSlideShow.swf");
    embed.setAttribute("FlashVars", "slideShowXML=" + xmlFile +"&photoPause=1&showNav=false&resizePhotos=true");
    embed.setAttribute("quality","high");
    embed.setAttribute("pluginspage","http://www.macromedia.com/go/getflashplayer");
    embed.setAttribute("type","application/x-shockwave-flash");
    embed.setAttribute("width","300");
    embed.setAttribute("height","200");
    embed.setAttribute("align","middle");
    embed.setAttribute("wmode","transparent");
    
    parentNode.appendChild(embed);
	*/
    var RandomId = Math.floor(Math.random()*1000) + "";
	var fo = new deconcept.SWFObject("/globalForms/mainSlideShow.swf?id=" + RandomId, "movie_" + RandomId, "300", "200", "9", "#000000");
	fo.addVariable("slideShowXML", xmlFile);
	fo.addVariable("showNav", "false");
	fo.addVariable("resizePhotos", "true");
	fo.addVariable("photoPause", "1");
	fo.addParam("quality", "high");
	fo.addParam("AllowScriptAccess", "sameDomain");
	fo.addParam("wmode", "transparent");
	fo.write(parentNode.id);
}

function replaceNewsFeed(){

    var img = document.getElementsByName('imgRealEstateNews');

   for(var i=0;i<img.length;i++){
        img[i].style.display="none";
    }
    
    if(img.length != 0)
        loadXMLDocAdv("/globalforms/news.aspx","","GET","",processNews);
}


function processNews(req){
    if (req.readyState == 4) 
    {
        // only if "OK"
    
        if (req.status == 200) 
        {
            var response=req.responseXML.documentElement;
            var items=response.getElementsByTagName("item");
            var sHTML = "";
                        
            
            
            if(items!=null && items.length > 0){
                var cssClass = "newsItem";
                var pubDate = "";
                var lastPubDate = "";
                var tempDate;
                //sHTML = getElementTextNS("","description",items[0],0);
                
                for(var i=0;i<items.length;i++){
                    tempDate = new Date(getElementTextNS("","pubDate",items[0],0));
                    pubDate = tempDate.format("MMM D, YYYY");
                    
                    sHTML += "<tr><td class='"+ cssClass +"'>\r\n";
                    if(pubDate != lastPubDate) sHTML += "<span class='NewsPublishDate'>" + pubDate + "</span><br />\r\n";
                    sHTML += "<a href='/GlobalForms/link.aspx?link="+ encodeURIComponent(getElementTextNS("","link",items[i],0)) +"'>" + getElementTextNS("","title",items[i],0) + "</a><br>\r\n";
                    sHTML += "</td></tr>\r\n";
                    
                    if(cssClass=="newsItem") cssClass="newsOddItem";
                    else cssClass="newsItem";
                    
                    lastPubDate = pubDate;
                    
                    if(i==8) i=items.length;
                }
            }
            sHTML += "</table>";
            
            var img = document.getElementsByName('imgRealEstateNews');
            var showTitle = true;
            
           for(var i=0;i<img.length;i++){
				var sFinalHTML = sHTML;
				
                if(img[i].getAttribute("showTitle") + "" == "false") {
                    showTitle = false;
                } else {
                    showTitle = true;
                }
           
                var dvRealEstateNews = document.createElement("div");
                
                if(showTitle) {
                    sFinalHTML = "<table class='newsTable'><tr><th class='newsHeader' align=left>Real Estate News</th></tr>\r\n" + sFinalHTML;
                } else {
                    sFinalHTML = "<table class='newsTable'>\r\n" + sFinalHTML;
                }
                
                dvRealEstateNews.id = "dvRealEstateNews" + i;
                dvRealEstateNews.innerHTML = sFinalHTML;
                img[i].parentNode.insertBefore(dvRealEstateNews, img[i].nextSibling);
            }
        } 
        else 
        {
            
        }
    } 
    else 
    {
        //do nothing, waiting for readystate
    }
}

function replaceAgentChat(){
    
    var img = document.getElementsByName('imgAgentChat');
    
    var imgAgentChat = null;
    var myImg = null;
    
    
    if(!img){
    
    } else if(typeof(img.length) != "undefined"){
        for(var i=0;i<img.length;i++){
			imgAgentChat = document.createElement("a");
			imgAgentChat.href = "javascript:popUp('/jabber/default.aspx','width=380,height=320');";
			myImg = document.createElement("img");
			myImg.src = "/aimages/ui/rd_chatIcon.gif";
			myImg.border = 0;
			imgAgentChat.appendChild(myImg);
            
            img[i].style.display="none";
            img[i].parentNode.insertBefore(imgAgentChat, img[i]);
        }
    } else {
		imgAgentChat = document.createElement("a");
		imgAgentChat.href = "javascript:popUp('/jabber/default.aspx','width=380,height=320');";
		myImg = document.createElement("img");
		myImg.src = "/aimages/ui/rd_chatIcon.gif";
		myImg.border = 0;
		imgAgentChat.appendChild(myImg);
		
        img.style.display="none";
        img.parentNode.insertBefore(imgAgentChat, img);
    }
}

function replaceRatesFeed(){
    var img = document.getElementsByName('imgMortgageRates');
    
    for(var i=0;i<img.length;i++){
        img[i].style.display="none";
    }
    
    if (img.length != 0)
        loadXMLDocAdv("/globalforms/mortgage.aspx","","GET","",processRates);
}

function processRates(req){
    if (req.readyState == 4) 
    {
        // only if "OK"
    
        if (req.status == 200) 
        {
            var response=req.responseXML.documentElement;
            if(response != null){
                var items=response.getElementsByTagName("mortgageRate");
                var sHTML = "";
                var showTitle = true;
                
                    
                
                //sHTML = "<table class='ratesTable'>";
                if(items!=null && items.length > 0){
                    
                    
                    //var sRates = getElementTextNS("","description",items[0],0);
                        var cssClass = "ratesItem";
                    
                    for(var i=0;i<items.length;i++){
                        var rate = parseFloat(getNodeValue(items[i],"latestRate"));
                        
                        rate = rate * 100;
                        
                        var sRate = rate + "";
                        var sDec = sRate.split(".");
                        
                        if (sDec[0].length > 1) {
                        	sRate = sRate.substring(0, 5);
                        }
                        else {
                        	if (sRate.length > 4) {
                        		sRate = sRate.substring(0, 4);
                        	}
                        }
                        
                        if(sRate != "0"){
                            sHTML += "<tr><td onclick='launchMortLink()' class='"+ cssClass +" rateItemTitle' style=''>" + getNodeValue(items[i],"minorName") + "</td>";
                            sHTML += "<td onclick='launchMortLink()' class='"+ cssClass +" rateItemRate'>" + sRate + "%</td></tr>\r\n";
                        }
                        
                        if(cssClass=="ratesItem") cssClass="ratesOddItem";
                        else cssClass="ratesItem";
                    }                    
                }
                //sHTML += "</table>";

                var img = document.getElementsByName('imgMortgageRates');
        
                for(var i=0;i<img.length;i++){
                    
                    if(img[i].getAttribute("showTitle") + "" == "false") {
                        showTitle = false;
                    } else {
                        showTitle = true;
                    }
                    //alert(img[i].getAttribute("showTitle") + " " + showTitle);
                    sReplacement = "<table onclick='launchMortLink()' class='ratesTable' cellspacing='0' cellpadding='0'>";
                    if(showTitle){
                        sReplacement += "<tr><th onclick='launchMortLink()' class='ratesHeader' colspan=2 align=left style='font-size:12px'>Mortgage Rates</th></tr>\r\n";
                    } else {
                        //sReplacement = "<table class='ratesTable'>\r\n" + sHTML + "</table>";
                    }
                    sReplacement += "<tr><th onclick='launchMortLink()' class='ratesTitle' align='left' style=''>Product</th><th class='ratesTitle' align='left' style=''>Rate</th></tr>\r\n";
                    
                    sReplacement += sHTML + "</table>";
                    
                    var dvMortgageRates = document.createElement("div");
                    dvMortgageRates.className = "dvMortgageRates";
                    dvMortgageRates.id = "dvMortgageRates" + i;
                    dvMortgageRates.innerHTML = sReplacement;
                    
                    img[i].parentNode.insertBefore(dvMortgageRates, img[i].nextSibling);
                }
            }
            
        } 
        else 
        {
        }
    } 
    else 
    {
        //do nothing, waiting for readystate
    }
}

function launchMortLink(){
    if(gl_mortLink != ""){
        if(gl_mortLink.indexOf("/globalForms/link.aspx?link=") == 0){
            location.href = gl_mortLink;
        } else {
            location.href = unescape(gl_mortLink);
        }
    }
}

function updateWeather(zip){
    replaceWeatherFeed(zip);
}

function replaceWeatherFeed(zip){
    
    var img = document.getElementsByName('imgWeatherFeed');
    
    for(var i=0;i<img.length;i++){                    
        img[i].style.display="none";
    } 
    
    if(zip+"" == "undefined") zip =  gl_weatherZip;
    
    if(img.length != 0)
        loadXMLDocAdv("/globalforms/weather.aspx?zip=" + zip,"","GET","",processWeather);
}


function processWeather(req){
    if (req.readyState == 4) 
    {
        // only if "OK"
    
        if (req.status == 200 && req.responseXML.documentElement != null) 
        {
            var response=req.responseXML.documentElement;
            var items=response.getElementsByTagName("item");
            var sHTML = "";
                        
            sHTML = "<table class='weatherTable'><tr><th class='weatherHeader' colspan=2 align=left>Local Weather</th></tr>\n";
            
            sHTML += "<tr><td class='weatherItem'>";
            
            if(items!=null && items.length > 0){
                sHTML += getElementTextNS("","description",items[0],0);
            }
            
            sHTML += "<br />Feed provided by Yahoo! Weather.</td></tr></table>";
            
            var img = document.getElementsByName('imgWeatherFeed');
    
            for(var i=0;i<img.length;i++){
                var dvWeatherFeed = document.createElement("div");
                    
                dvWeatherFeed.id = "dvWeatherFeed" + i;
                dvWeatherFeed.innerHTML = sHTML;
                img[i].parentNode.insertBefore(dvWeatherFeed, img[i].nextSibling);
            }  
        } 
    } 
    else 
    {
        //do nothing, waiting for readystate
    }
}

function propertyResultOver(obj){
    obj.tempClassName = obj.className;
    obj.className = 'propertyResultsOver';
}

function propertyResultOut(obj){
    obj.className = obj.tempClassName;
}

/**
 * JAXED YUI - Returns the current height of the viewport.
 * @method getViewportHeight
 * @return {Int} The height of the viewable area of the page (excludes scrollbars).
 */
function getViewportHeight() {
    var height = self.innerHeight; // Safari, Opera
    var mode = document.compatMode;

    if ( (mode || isIE) && !isOpera ) { // IE, Gecko
        height = (mode == 'CSS1Compat') ?
                document.documentElement.clientHeight : // Standards
                document.body.clientHeight; // Quirks
    }

    return height;
}

/**
 * JAXED YUI - Returns the current width of the viewport.
 * @method getViewportWidth
 * @return {Int} The width of the viewable area of the page (excludes scrollbars).
 */
        
function getViewportWidth() {
    var width = self.innerWidth;  // Safari
    var mode = document.compatMode;
    
    if (mode || isIE) { // IE, Gecko, Opera
        width = (mode == 'CSS1Compat') ?
                document.documentElement.clientWidth : // Standards
                document.body.clientWidth; // Quirks
    }
    
    return width;
}


function showGoogEarthDiv(link){
    
    var googDiv;
    
    var x;
    var y;
    var width = 300;
    
    var table;
    var tbody;
    var tr;
    var td;
    
    var content = "";
    
    content = "<img src=\"http://earth.google.com/images/art.gif\"> <br><br>\r\n";
    content += "To view this link, you must have Google Earth<br><br>\r\n";
    content += "<b>If you have Google Earth installed click <a onclick=\"hideGoogDiv(this)\" href=\"" + link + "\" target=\"_blank\">here</a></b>.<br><br>\r\n";
    content += "<i>\"The idea is simple. It's a globe that sits inside your PC. You point and zoom to anyplace on the planet that you want to explore. Satelite images and local facts zoom into view. Tap into Google search to show local points of interest and facts. Zoom to a specific address to check out an apartment or hotel. View driving directions and even fly along your route. \"</i> - http://earth.google.com <br><br>";
    content += "<b>Click <a href=\"http://earth.google.com/download-earth.html\" target=\"_blank\">here</a> to be transported to the Google Earth download page.</b><br><br>";
    content += "<a onclick=\"hideGoogDiv(this)\" href=\"javascript:void(0);\">cancel</a>";
    
    var 
		frameWidth = getViewportWidth() , 
		frameHeight = getViewportHeight(), 
		frameScrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop), 
		frameScrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
        
        
    googDiv = document.getElementById("googDiv");
    
    if(!googDiv){
    
        googDiv = document.createElement("DIV");
            
        googDiv.id = "googDiv";
        googDiv.style.background = "#FFFFFF";
        googDiv.style.border = "solid 1px black";
        googDiv.style.position = "absolute";
		googDiv.style.width = width + "px";
		googDiv.style.left = "0px";
		googDiv.style.top = "0px";
        googDiv.style.zIndex = 20;
        
        table = document.createElement("TABLE");
        
        googDiv.background = "#FFFFFF";
        table.width = "100%";
        table.height = "100%";
        table.className = "propertyTable";
        table.cellSpacing = 0;
        table.cellPadding = 2;
        
        tbody = document.createElement("TBODY");
        tr = document.createElement("TR");
        td = document.createElement("TD");
        
        td.className = "propertyTableHead";
        td.innerHTML = "Google Earth";
        td.style.height = "12px";
        
        tr.appendChild(td);
        tbody.appendChild(tr);
        
        tr = document.createElement("TR");
        td = document.createElement("TD");
        
        td.id = "googTd";
        td.className = "propertyTableRow";
        td.innerHTML = content;
        td.align = "center";
        td.vAlign = "middle";
        
        tr.appendChild(td);
        tbody.appendChild(tr);
        
        table.appendChild(tbody);
        
        googDiv.appendChild(table);
        
        document.body.appendChild(googDiv);
    } else {
        td = document.getElementById("googTd");
        td.innerHTML = content;
        
        googDiv.style.display = "block";
    }
    
    x = (frameWidth / 2) - (googDiv.offsetWidth / 2) + frameScrollLeft;
    y = (frameHeight / 2) - (googDiv.offsetHeight / 2) + frameScrollTop;
    googDiv.style.left = x + "px";
    googDiv.style.top = y + "px";
}

function hideGoogDiv(obj){
    var googDiv = document.getElementById("googDiv");
    
    if(googDiv) googDiv.style.display = "none";
}

function correctPNG() 
{
    for(var i=0; i<document.images.length; i++)
    {
        var img = document.images[i]
        var imgName = img.src.toUpperCase()
        
        if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
        {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement != null && img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
        }
    }
}

function addOnloadEvent(func) {
	var oldonload = window.onload;
	//alert(window.onload);
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

if(typeof(addOnUnloadEvent) == "undefined"){
	function addOnUnloadEvent(func){
		var oldonunload = window.onunload;
		
		if (typeof window.onunload != 'function') {
			window.onunload = func;
		}
		
		else {
			window.onunload = function() {
				oldonunload();
				func();
			}
		}
	}
}

//addOnloadEvent(fixIeActiveX);
if (document.all) addOnloadEvent(correctPNG);

function runGlobalEndHead(){
    
    try{replaceRatesFeed();} catch(e) { }
    
    try{replaceWeatherFeed();} catch(e) { }

    try{replaceNewsFeed();} catch(e) { }

    try{replaceSlideShow();} catch(e) { }

    try{replaceAgentChat();} catch(e) { }
}


// mortgage calc stuff, not sure how long this was missing for
function floor(number)
{
  return Math.floor(number*Math.pow(10,2))/Math.pow(10,2);
}

function dosum() {
	var years = parseFloat(document.getElementById('YR').value.replace(/[,a-zA-Z]/g, ''));
	var rate = parseFloat(document.getElementById('IR').value.replace(/[,a-zA-Z]/g, ''));
	var amount = parseFloat(document.getElementById('LA').value.replace(/[,a-zA-Z]/g, ''));
	var tax = parseFloat(document.getElementById('AT').value.replace(/[,a-zA-Z]/g, ''));
	var insurance = parseFloat(document.getElementById('AI').value.replace(/[,a-zA-Z]/g, ''));

	var mi = rate / 1200;
	var base = 1;
	var mbase = 1 + mi;
	for (i = 0; i < years * 12; i++) { base = base * mbase; }
	var dasum = (amount * mi / (1 - (1 / base))) + (tax / 12) + (insurance / 12);

	document.getElementById('PI').value = "$" + floor(amount * mi / (1 - (1 / base)));
	document.getElementById('MT').value = "$" + floor(tax / 12);
	document.getElementById('MI').value = "$" + floor(insurance / 12);
	document.getElementById('MP').value = "$" + floor(dasum);
}