// JavaScript Document
function btn_overs(sel, newImage){
	var theImage=document.getElementById(sel);
	theImage.src=newImage;
}

//auto clear a text field when clicked
function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}
//submit a start search form
function startSearchSubmit(){	
	var status='';	
	if (typeof(document.getElementById("status"))!='undefined'){
		status=document.getElementById("status").value;
		status=status!='' ? '/'+status : '';		
	}	
	var ui=document.getElementById("startSearchInput").value;
	if (ui!='Enter neighborhood or MLS#' && ui!=''){
		if (typeof(document.getElementById("searchBranding"))!="undefined" && document.getElementById("searchBranding")!=null){
			document.getElementById("agentBranding").value=document.getElementById("searchBranding").value;
			document.startSearchForm.submit();
			//return false;
		}else{
			if (ui == parseInt(ui)){
				window.location = '/'+ui+status;
			}else{
				window.location = '/search#search/'+ui+status;
			}
		}
	}else{
		alert ("Enter a neighborhood or MLS#");	
	}
	return false;
}
//parse <body> onload functions
function loaders(jsonStrFns){
	for (t=0;t<jsonStrFns.length;t++){
		valueStr='';
		for (v=0;v<jsonStrFns[t][1].length;v++){
			valueStr+="'"+jsonStrFns[t][1][v]+"'";
			if (v!=jsonStrFns[t][1].length-1){valueStr+=",";}	
		}
		functionStr=jsonStrFns[t][0]+"("+valueStr+")";
		eval(functionStr);		
	}
}
function popAdvantage(toggle){
	var advantageWrap=document.getElementById("advantageOverlay");
	var advantageDiv=document.getElementById("advantageContainer");
	if (toggle==1){
		var vpDim=getViewportDimmensions();
		var advDim=makeAdvantageRatio(vpDim);
		advantageDiv.style.width=advDim[0]+'px';
		advantageDiv.style.height=advDim[1]+'px';
		loadFlashInDiv('/advantage/flash/TheLakeAdvantage.swf','advantageContainer');
		advantageWrap.style.display='block';
	}else{
		advantageDiv.innerHTML='';
		advantageWrap.style.display='none';
	}
}
function makeAdvantageRatio(vpDim){
	//780x505
	var newH;
	var newW;
	newW=vpDim[0];
	newH=(505*vpDim[0])/780;	
	if (newH>vpDim[1]){
		newH=vpDim[1];
		newW=(780*vpDim[1])/505;
	}
	newW=Math.floor(newW);
	newW=Math.floor(newW);
	return new Array(newW,newH);
}
//load flash in a div after page is loaded
function loadFlashInDiv(flash,theDiv){
	//alert (theDiv);
	var flash_width="100%";
	var flash_height="100%";
	var version='8,0,24,0';
	var str='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+version+'" width="'+flash_width+'" height="'+flash_height+'">';
	str+='<param name="movie" value="'+flash+'"><param name="BGCOLOR" value="#000033"><param name="quality" value="high"><param name="wmode" value="transparent"><param name="SCALE" value="noborder">';
	str+='<embed src="'+flash+'" width="'+flash_width+'" height="'+flash_height+'" wmode="transparent" scale="noborder" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  bgcolor="#000033"></embed></object>';
	var theTarg=document.getElementById(theDiv);
	theTarg.innerHTML=str;
}

function getViewportDimmensions(){
	var viewportwidth;
	var viewportheight;	
	if (typeof window.innerWidth != 'undefined'){
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
	}else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0){
		viewportwidth = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
	}else{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}	
	return new Array(viewportwidth,viewportheight);
}
