function findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function roll(id, newSrc) {
    var theImage = findObj(id);
    if (theImage)theImage.src = newSrc;
}

function reloadPage(){
	location.reload();
}

function show(object) {
  var obj = findObj(object);
  if (obj != null)
	{
    obj = (obj.style) ? (obj.style):obj;
    obj.display = "block";
    obj.visibility = "visible";
   }
}

function hide(object) {
  var obj = findObj(object);
	if (obj != null)
	{
     obj = (obj.style) ? (obj.style):obj;
	  obj.display = "none";
     obj.visibility = "hidden";  	 
	}
}

function writeInnerHTML(objDiv,strHtml){
	var obj = findObj(objDiv);
	if (obj != null) obj.innerHTML = strHtml;
}
// Hides LexusVision div layer
function closeVision(){
	hide('LexusVision');
}

function browserDimensions(){
	var winW = 630, winH = 460;

	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
	  winW = window.innerWidth;
	  winH = window.innerHeight;
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	  winW = document.body.offsetWidth;
	  winH = document.body.offsetHeight;
	 }
	}
}

// Dynamically writes flash object code to LexusVision div layer
function writeVisionFlash(objFlashMovie, top) {
	// scroll position
	var intScrollTop = document.body.scrollTop;
	var strFlash;
	var windowmode;
	var intPaddingTop = 50;

	// Only transparent on PC as performance on mac is slow
	if(!isMac){windowmode="wmode=transparent";}
	strFlash = '<div id="flashDiv" style="position: absolute; top:' + (top-intPaddingTop) + '; left:-8px;width: 768px; height: 425px;">';
	strFlash += '<a name="#LexusVision" style="height: ' + intPaddingTop + 'px;">&nbsp;</a>';
	strFlash += '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="768" HEIGHT="425" id="flash2" ALIGN="">';
	strFlash += '<PARAM NAME=movie VALUE="' + objFlashMovie + '"><PARAM NAME=quality VALUE=high><PARAM NAME=wmode VALUE=transparent>';
	strFlash += '<EMBED src="' + objFlashMovie + '" quality=high ' + windowmode + ' WIDTH="768" HEIGHT="425" NAME="flash2" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">';
	strFlash += '</EMBED></OBJECT></div>';
	
	writeInnerHTML('LexusVision',strFlash);
	show('LexusVision');
}


var strErrorTxt = "Popup Blocker Detected.";
var strError = "";
function open_popup(theURL,width,height, scrollbars,errortxt) {
    x = (640 - width)/2, y = (480 - height)/2;

    if (screen) {
        y = (screen.availHeight - height)/2;
        x = (screen.availWidth - width)/2;
    }

	if(errortxt=="" || errortxt==null){
		strError = "to view blocked content."
	}else{
		strError = errortxt;
	}
    popwin = window.open(theURL,'lexusWin','width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+',scrollbars='+scrollbars+',status=no,resizable=no');
	strErrorTxt += " <a href=javascript:open_popup('"+theURL+"','"+width+"','"+height+"','"+scrollbars+"');><span style='text-decoration: underline;color:white;'>Click here</span></a> " + strError;
	// checks to see if popup blockers exist
	setTimeout("popupBlockerCheck()",700);
}

function popupBlockerCheck(errorTxt){
	if((popwin==null) ||(typeof(popwin)=="undefined")||(typeof(popwin.location.hash)!="string")){
		changeLabel("lblError",strErrorTxt);
		show('lblError');
		window.focus();
	}else{
	}
}

function changeLabel(obj,txt){
	var divLayer = findObj(obj);
	divLayer.innerHTML = txt;
}

function getData(formelement, elementdatatype){
//  var obj = this.document.forms[objform](formelement);
obj = findObj(formelement);
    switch (elementdatatype){
      case "string":
        if(obj.value!=''){
          return true;
        }else{
          return false;
        }
      break;  
      case "int":
        if(!isNaN(obj.value) && obj.value!=''){
          return true;
        }else{
          return false;
        }
      break;
      case "email":
        // reg expression
        var regExp = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");        
        return regExp.test(obj.value);                    
      break;
      case "dropdown":
        if(obj.selectedIndex!=0){
          return true;
        }else{
          return false;
        }
      break;
      case "radio":
        var isChecked = false;
        for(var i=0; i<obj.length; i++){
          if(obj[i].checked){ isChecked = true; }
        }       
        if(isChecked){
          return true;
        }else{
          return false;
        }       
      break;
      default:
		return false;
    }
  
}

function highlight(formElement, state){
	var colorOn = '#FF0000';
	var colorOff = '#333333';
	// remove 'Star' to get formElement name
	//objstar = findObj(formElement + "Star");
	objelement = findObj(formElement);
	//alert(objelement);
      
	if(state == "on"){
		// set asterix colour to colorOn
		//objstar.style.color=colorOn;
		// set border colour to colorOn
	    objelement.style.border = 'solid 1px ' + colorOn;
	}else{
		// set asterix colour to colorOff
		//objstar.style.color=colorOff;
		// set border colour to colorOff
		objelement.style.border = 'solid 1px #7F9DB9';
	}    
}

/*
 *
 * Given an id and a property (as strings), set
 * the given property of that id to the value provided.
 *
 * The property is set directly on the tag, not in the
 * stylesheet.
 *
 */
function setIdProperty( id, property, value )
{
    if (isNav6)
    {
        var styleObject = document.getElementById( id );
        if (styleObject != null)
        {
            styleObject = styleObject.style;
            styleObject[ property ] = value;
        }
        
    }
    else if (isNav4)
    {
        document[id][property] = value;
    }
    else if (isIE4)
    {
         document.all[id].style[property] = value;
    }
}

function writeDynFlash(objFlashMovie, width, height, top, styles) {
	// scroll positsion
	var intScrollTop = document.body.scrollTop;
	var strFlash;
	var windowmode;
	var intPaddingTop = 50;
	strFlash = '<div id="flashDiv" style="position: absolute; top:' + (top-intPaddingTop) + 'px; left:0px;width: ' + width + 'px; height: ' + height + 'px;' + styles + '">';
	strFlash += '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="' + width + '" HEIGHT="' + height + '" id="flash2" ALIGN="">';
	strFlash += '<PARAM NAME=movie VALUE="' + objFlashMovie + '"><PARAM NAME=quality VALUE=high>';
	strFlash += '<EMBED src="' + objFlashMovie + '" quality=high  WIDTH="' + width + '" HEIGHT="' + height + '" NAME="flash2" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">';
	strFlash += '</EMBED></OBJECT></div>';
	
	writeInnerHTML('DynFlash',strFlash);
	show('DynFlash');
}

function hideDynFlash(){
	writeDynFlash('','720','405','50');
	hide('DynFlash');
}