// JavaScript Document
window.onload = fixClickMeObjProblem;
function fixClickMeObjProblem() {
 //Fix Eolas' patent ('Click to activate and use this control' problem in Opera/IE)
 var htmlObjects = document.getElementsByTagName("object");
 for (i = 0; i < htmlObjects.length; i++) {
  htmlObjects[i].outerHTML += "";
 }
}

function popUp(page, name, w, h, scroll) { 
	name = "foo";
	page = page.split(" ").join("%20");
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	//var resizable = false;
	winprop  = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes';
	win = window.open(page, name, winprop);
	//if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	//if (window.focus) { win.focus(); }
 }

function ShowMenu(n) {
	var menu, arrowImg;
	menu = document.getElementById("dTool" + n);
	// Determine if the menu is currently showing.
	if (menu.style.display == 'block'){
		// If it is showing, hide the menu and update the twisty image.
    menu.style.display = 'none';
    arrowImg = document.images['i' + n];
    arrowImg.src = "images/btn_tan_twisty_up.gif";
  }
	else
  {
  	// Hide all layers first.
    var divs = document.getElementsByTagName("div");

	/*       
    for (var i = 0; i < divs.length; i++)
    	if (divs[i].id.indexOf("dTool") >= 0)
          divs[i].style.display = 'none';
    */
     
    // Reset the images.
    /*
    for (var j = 0; j < document.images.length; j++)
    	if (document.images[j].src.indexOf("btn_tan_twisty_dn") > 0)
          document.images[j].src = "images/btn_tan_twisty_up.gif";
    */
       
    // Show the menus and update their twisty images.
    menu = document.getElementById("dTool" + n);
    arrowImg = document.images["i" + n];
    menu.style.display = "block";
    arrowImg.src = "images/btn_tan_twisty_dn.gif";

   }
}

function showHideCompare(layerName) {
	var DivRef = document.getElementById(layerName);
	var IfrRef = document.getElementById('divShim');
	var btnRef = document.getElementById('compareBtn');
	var imgRef = document.getElementById('compareImage');
	if (DivRef.style.display == "none"){
		DivRef.style.display = "block";
		imgRef.src = './images/btn_compareproperties_dn.gif';
		IfrRef.style.width = DivRef.offsetWidth;
		IfrRef.style.height = DivRef.offsetHeight;
		IfrRef.style.top = DivRef.currentStyle.top;
		IfrRef.style.left = DivRef.currentStyle.left;
		IfrRef.style.zIndex = DivRef.currentStyle.zIndex - 1;
		IfrRef.style.display = "block";
		btnRef.style.background = 'url(../images/btn_compareproperties_dn.gif)';		
 	}
	else
	{
		DivRef.style.display = "none";
		IfrRef.style.display = "none";
		imgRef.src = './images/btn_compareproperties_up.gif';
		btnRef.style.background = 'url(../images/btn_compareproperties_up.gif)';
	}
}

// Univeral method for javascript->flash setvariable


/* -----------------------------------------------------------
Supporting Browsers

_IE 5 and higher
_Netscape 6 and higher
_Moz/Firebird all
_Opera 7 and higher
_Safari
*/

var ua        = navigator.userAgent.toLowerCase(); 
var is_pc_ie  = ( (ua.indexOf('msie') != -1 ) && ( ua.indexOf('win') != -1 ) && ( ua.indexOf('opera') == -1 ) && ( ua.indexOf('webtv') == -1 ) );


function getXML(tagName, bracket) {

	var xmlNode = window.document.getElementsByTagName('xml');
	//var xmlHold = xmlNode[0].getElementsByTagName(tagName)[0].firstChild.nodeValue;
	var xmlLink = xmlNode[0].getElementsByTagName(tagName)[0].getAttribute("link");
	var myNum = parseInt(bracket);
	setFlashVariables("sendmovie","setText="+xmlLink);

}

function setFlashVariables(movieid, flashquery){
	var i,values;
	if(is_pc_ie){
		var chunk = flashquery.split("&");
		for(i in chunk){
			values = chunk[i].split("=");
			document[movieid].SetVariable(values[0],values[1]);
		}
	}else{
		var divcontainer = "flash_setvariables_"+movieid;
		if(!document.getElementById(divcontainer)){
			var divholder = document.createElement("div");
			divholder.id = divcontainer;
			document.body.appendChild(divholder);
		}
		document.getElementById(divcontainer).innerHTML = "";
		var divinfo = "<embed src='gateway.swf' FlashVars='lc="+movieid+"&fq="+escape(flashquery)+"' width='0' height='0' type='application/x-shockwave-flash'></embed>";document.getElementById(divcontainer).innerHTML = divinfo;
	}
}

function trim(sString)
{
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}

function disableEnterKey(e) {
	var keyCode = document.all ? window.event.keyCode : e.which;
	return keyCode != 13;
}
//document.onkeypress = disableEnterKey;

function SimulateButtonClickViaEnterKey(theEvent, theButtonTarget) {
	var keyCode = document.all ? window.event.keyCode : theEvent.which;
	if (keyCode == 13) {
		document.getElementById(theButtonTarget).click();
		return false;
	} else {
		return true;
	}
}

