// Based on Flash Player Version Detection - Rev 1.5
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var bhpIsIESP2 = false;
bhpIsIESP2 = (window.navigator.userAgent.indexOf("SV1") != -1);
var isIE7 = false;
if ( window.XMLHttpRequest&&window.ActiveXObject ) isIE7 = true;
var bhpDoFullScreen = false;
if ( isIE7||bhpIsIESP2 ) bhpDoFullScreen = true; // IE7, IE6onXPSP2
var bhpWindows = new Object();
var bhpWinLoaded = false;
//var bhpTop=window.top;
//var bhpLeft=window.left;
//var bhpHeight=window.height;
//var bhpWidth=window.width;


function bhpOpenWindow(sURL, bFocus) {
	var winParams = 'directories=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=yes';
	if (bhpDoFullScreen) winParams += ',fullscreen=yes';
	//else winParams += ',top=' + window.top + ',left=' + window.left; // + ',height=' + bhpHeight + ',width=' + bhpWidth
	var	nw = window.open(sURL,'BHPClient', winParams);
	//var date = new Date();
	//var curDate = null;
	bhpWindows['BHPClient'] = nw;
	return bhpCheckOpen('BHPClient', bFocus);
}

function bhpCloseWindow() {
	bhpWindows['BHPClient'].close();
}

function bhpCheckOpen(pageId, bFocus) {
	try {
        if ( (!bhpWindows[pageId]) || (bhpWindows[pageId].closed) ) {
			bhpWinLoaded = false;
		} else {
			if ((! bhpWinLoaded) && (! isIE)) { //On First Load only
				if ( (bhpWindows[pageId].outerHeight < screen.availHeight) || (bhpWindows[pageId].outerWidth < screen.availWidth) ){
					bhpWindows[pageId].moveTo(0,0);
					bhpWindows[pageId].outerHeight = screen.availHeight;
					bhpWindows[pageId].outerWidth = screen.availWidth;
				}
			}
			if (bFocus) bhpWindows[pageId].focus();
			else bhpWindows[pageId].blur();
			bhpWinLoaded = true;
		}
    }
	catch(e){bhpWinLoaded = false;}
	return bhpWinLoaded
}

function ControlVersion(){
	var version;
	var axo;
	var e;
	try {
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {}
	if (!version) {
		try {
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			version = "WIN 6,0,21,0";
			axo.AllowScriptAccess = "always";
			version = axo.GetVariable("$version");
		} catch (e) {}
	}
	if (!version) {
		try {
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {}
	}
	if (!version) {
		try {
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {}
	}
	if (!version) {
		try {
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {version = -1;}
	}
	return version;
}

function bhp_GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;			
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

function bhp_DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision){
	versionStr = bhp_GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}


function bhpHideFlash(iStatus) {
	//iStatus: 0=Complete;1=Cancelled;2=Failed
	document.getElementById('bhpexpressinstall').style.display = 'none';
	document.getElementById('bhppluginmask').style.display = 'none';
}

function bhpNeedFlash9() {
	alert('Flash Player 9 Required!\n\nBestHomePro\'s advanced functionality\nrequires this plugin to be installed.\nPlease follow the on-screen instructions\nor links to install.');
	return false;
}

var requiredMajorVersion = 9;
var requiredMinorVersion = 0;
var requiredRevision = 0;
var hasProductInstall = bhp_DetectFlashVer(6, 0, 65);
var hasRequestedVersion = bhp_DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
var bhpContent = "";
var MMredirectURL = window.location;
var MMdoctitle = document.title;
if (hasRequestedVersion) {
	//Show Full Flex2 Plugin
	bhpContent = '<div id="myBHPPlugin">';
	if (window.ActiveXObject) bhpContent += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="180" height="300" align="middle" id="bhpplugin" name="bhpplugin" ><param name="allowScriptAccess" value="always" /><param name="movie" value="http://plugin.besthomepro.com/flash/badge/badge.swf" />				<param name="quality" value="high" /><param name="allowScriptAccess" value="always" /><param name="bgcolor" value="'+bhp_plugin_bgcolor+'" />				<param name="FlashVars" value="agentid='+bhp_plugin_agentid+'&officeid='+bhp_plugin_officeid+'&brokerageid='+bhp_plugin_brokerageid+'&state='+bhp_plugin_state+'&maplat='+bhp_plugin_maplat+'&maplon='+bhp_plugin_maplon+'&mapscale='+bhp_plugin_mapscale+'&rotation='+bhp_plugin_rotation+'" />			</object>';
	else bhpContent += '<embed type="application/x-shockwave-flash" src="http://plugin.besthomepro.com/flash/badge/badge.swf" id="bhpplugin" name="bhpplugin" bgcolor="'+bhp_plugin_bgcolor+'" quality="high" allowscriptaccess="always" flashvars="agentid='+bhp_plugin_agentid+'&officeid='+bhp_plugin_officeid+'&brokerageid='+bhp_plugin_brokerageid+'&state='+bhp_plugin_state+'&maplat='+bhp_plugin_maplat+'&maplon='+bhp_plugin_maplon+'&mapscale='+bhp_plugin_mapscale+'&rotation='+bhp_plugin_rotation+'" height="300" width="180">';
	bhpContent += '</div>';
	document.write(bhpContent);
} else {
	//Show base HTML version of Plugin
	bhpContent = '<div id=bhpplugindiv style=position:relative;width:180px;><table border=0 cellpadding=0 cellspacing=0 width=180 style=z-index:99998;><tr><td colspan=3><img src=http://www.besthomepro.com/images/plugin/BHP_Plugin_Blank_Top.png width=180 height=28 border=0 alt=BestHomePro /></td></tr><tr><td width=4 bgcolor=#097DA9><img src=http://www.besthomepro.com/images/1x1.gif width=4 height=264 /></td><td width=172 bgcolor=#FFFFFF valign=top style="font-family:Tahoma, Arial, Helvetica, sans-serif;font-size:12px;padding:4px;"><span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px;font-weight:bold;">Search MLS Listings</span><br /><span style=font-size:10px;font-weight:bold;line-height:16px;>Enter Location to Search:</span><br><form action="" onsubmit="return bhpNeedFlash9();" name=bhpmlssearch style="display:inline;padding-top:4px;width:160px;"><table width=100% border=0 cellpadding=0 cellspacing=0><tr><td valign=top><input name=searchstring type=text style="width:126px;height:22px;font:11px Tahoma, Arial, Helvetica, sans-serif;background-color:#FFFFCC;" title="Enter State, City, ZipCode, Street Address" maxlength=50 /></td><td valign=top align=right><input type=Button name=Go value=Go style="width:30px;height:24px;font:bold 10px Verdana, Arial, Helvetica, sans-serif;" onClick=javascript:bhpNeedFlash9(); /></td></tr></table></form><table border=0 cellspacing=2 cellpadding=0 width=100% style="font-family:Tahoma, Arial, Helvetica, sans-serif;font-size:12px;"><tr><td nowrap=nowrap>Existing Users:</td><td width=60><form name=bhplogin style=display:inline;padding-top:4px;><input type=button name=login onClick=javascript:bhpNeedFlash9(); value="Sign In" style="width:60px;height:24px;padding:0;margin:0;font:bold 10px Verdana, Arial, Helvetica, sans-serif" /></form></td></tr><tr><td nowrap=nowrap>New Users:</td><td width=60><form name=bhpregister onClick=javascript:bhpNeedFlash9(); style=display:inline;><input type=button name=Register value=Register style="width:60px; height:24px; font:bold 10px Verdana, Arial, Helvetica, sans-serif;" /></form></td></tr></table><br /><center><b>Flash Plugin 9 Required!</b><br><span style=font-size:10px;>For enhanced functionality,<br>please <a href=http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash target=_blank>install  Flash Player 9</a><br /><br /></center>';
	if ( hasProductInstall && !hasRequestedVersion ) {
		bhpContent += '<center><a href=http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash target=_blank><img src=http://www.besthomepro.com/images/Logos/get_flash_player.gif alt="Get Adobe Flash Player" width=88 height=31 border=0 /></a><br><br><a href=javascript:window.location.reload(true); >reload</a></span></center>';
		//Express Install swf
		bhpContent += '<div id="bhpexpressinstall" name="bhpexpressinstall" style="position:absolute; top:75px; z-index: 100000; visibility:visible; left: -17px;">';
		if (window.ActiveXObject) bhpContent += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,65,0" width="215" height="138" align="middle" id="BHPPlayerInstall" ><param name="allowScriptAccess" value="always" /><param name="movie" value="http://www.besthomepro.com/flash/BHPPlayerInstall.swf" /><param name="quality" value="high" /><param name="allowScriptAccess" value="always" /><param name="bgcolor" value="#ffffff" /><param name="FlashVars" value="MMredirectURL='+MMredirectURL+'&MMplayerType=ActiveX&MMdoctitle='+MMdoctitle+'" /></object>';
		else bhpContent += '<embed src="http://www.besthomepro.com/flash/BHPPlayerInstall.swf" flashvars="MMredirectURL='+MMredirectURL+'&MMplayerType=PlugIn&MMdoctitle='+MMdoctitle+'" quality="high" bgcolor="#ffffff" name="bhppluginupdate" allowscriptaccess="always" pluginspage="http://www.adobe.com/go/getflashplayer" type="application/x-shockwave-flash" align="middle" height="138" width="215" wmode="transparent">';
		bhpContent += '</div><img id=bhppluginmask name=bhppluginmask src="http://www.besthomepro.com/flash/badge/greymask.png" width="180" height="300" style="position:absolute; top:0px; z-index: 99999; visibility:visible; left:0;"/>';
	} else {
		versionStr = bhp_GetSwfVer();
		if (versionStr == -1 ) {
			//No Flash Player at all, use Default Browser Beahvior w/Redirect swf
			if (window.ActiveXObject) bhpContent += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="162" height="76" id="bhpRedirect" ><param name="allowScriptAccess" value="always" /><param name="FlashVars" value="redirectURL='+MMredirectURL+'" /><param name="movie" value="http://www.besthomepro.com/flash/Redirect.swf" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="low" /><param name="bgcolor" value="#ffffff" /></object>';
			else bhpContent += '<embed src="http://www.besthomepro.com/flash/Redirect.swf" FlashVars="redirectURL='+MMredirectURL+'" loop="false" menu="false" quality="low" bgcolor="#ffffff" width="162" height="76" name="bhpRedirect" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		} else {
			//Old version of Flash Player, show link to Upgrade Page
			bhpContent += '<center><a href=http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash target=_blank><img src=http://www.besthomepro.com/images/Logos/get_flash_player.gif alt="Get Adobe Flash Player" width=88 height=31 border=0 /></a><br><br><a href=javascript:window.location.reload(true); style=font-size:10px;>reload</a></center>';
		}
	}
	bhpContent += '</td><td width=4 bgcolor=#097DA9><img src=http://www.besthomepro.com/images/1x1.gif width=4 height=264 /></td></tr><tr><td colspan=3><img src=http://www.besthomepro.com/images/plugin/BHP_Plugin_Blank_Bottom.png width=180 height=8 border=0 alt= /></td></tr></table></div>';
	document.write(bhpContent);
	//IE5&6 make plugin disabled mask transparent
	if (/MSIE [56].*Windows/.test(navigator.userAgent)) (function() {
		var blank = new Image;
		blank.src = 'http://www.besthomepro.com/images/blank.gif';
		var img = document.getElementById("bhppluginmask");
		var src = img.src;
		var s = img.runtimeStyle;
		s.width = img.offsetWidth + "px";
		s.height = img.offsetHeight + "px";
		s.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
		img.src = blank.src;
	})();
}



