/* onload handler */
var window_onload = new Array;
var onloadRef = window.onload;

/*
    window.ie - will be set to true if the current browser is internet explorer (any).
	window.ie6 - will be set to true if the current browser is internet explorer 6.
	window.ie7 - will be set to true if the current browser is internet explorer 7.
	window.khtml - will be set to true if the current browser is Safari/Konqueror.
	window.gecko - will be set to true if the current browser is Mozilla/Gecko.
*/

if (window.ActiveXObject){ window.ie = window[window.XMLHttpRequest ? 'ie7' : 'ie6'] = true;
}else if (document.childNodes && !document.all && !navigator.taintEnabled){ window.khtml = true;
}else if (document.getBoxObjectFor != null){ window.gecko = true;};
	
	
window.onload = function() {
	
  if(onloadRef != null) {
	 
    onloadRef();
  }
	//for(var i =  window_onload.length; i >= 0; i--){ //Why is this running backwards?
	for(var i = 0; i < window_onload.length; i++){
    eval( window_onload[i]);

  }
};

function onload_register(func){
 window_onload.push(func);
 
}
/* end onload handler */

// the variable to hold the flash name
var flashName;
var seedID = Math.floor(Math.random()*11111);
/*Turn on rendering div*/
function showFlash(argSwf, argElement, argFlashVars, overrideLowBand) {
	if($(argElement)) {
		var individualID = Math.floor(Math.random()*11111);
		/*
			Prepare to load in the Flash rendering engine.
			Uses Unobtrusive Flash Objects by Bobby van der Sluis
			http://www.bobbyvandersluis.com/ufo/
		*/
		if(hasFlashMin() != false){
			userData.bandwidth = "high";
			Cookie.set('userdata', Json.toString(userData), {duration: 365, path: "/"});
		}else{
			userData.bandwidth = "low";
			Cookie.set('userdata', Json.toString(userData), {duration: 365, path: "/"});
		}
		var isSafari = "";
		navigator.userAgent.indexOf("Safari")>= 0 ? isSafari = true : isSafari = false;
	
		var isLTOpera92 = "";
		navigator.userAgent.indexOf("Opera") >= 0 && parseFloat(navigator.appVersion) < 9.2 ? isLTOpera92 = true : isLTOpera92 = false;
	
		//Should Flash even be shown? (does user want it / can their browser support Flash 8 functionality)
	
		if ((userData.bandwidth != "low" && isLTOpera92 == false) || overrideLowBand ) {

			var site_config = {
				'host':location.host,
				'src':location.href,
				'title':document.title,
				'isSafari':isSafari,
				'isLTOpera92':isLTOpera92,
				'EOF':'EOF'
			};
			
			var flash_vars = '';
			for (k in site_config) {
				if (k != "toJSONString") {
					flash_vars += "&"+k+"="+encodeURIComponent(site_config[k]);
				}
			}
			// deep link
			if (location.href.indexOf("?") != -1) {
				flash_vars += "&"+location.href.substr(location.href.indexOf("?")+1);
			}
			// add local connect sound vars 
			flash_vars += "&localconnect_seed="+seedID;
			flash_vars += "&localconnect_id="+individualID;
			
			//flash_vars += "&argMLC=" + hbx.mlc;
			if ($(argElement)) {
				var render_foo = document.getElementById(argElement);
				render_foo.style.display = 'block';
			}
			// set the name fo the flash based on the div 
			flashName = argElement+'_flash';
			if (argFlashVars != null) {
				flash_vars += argFlashVars;
			}
			var debug_html = getParameter('flash');
			var flash_version;
			if (debug_html == "false" && debug_html != "") {
				flash_version = 10;
			} else {
				flash_version = 8;
			}
			
			var FO = {
				movie:argSwf, 
				width:"100%", 
				height:"100%", 
				name:flashName, 
				id:flashName, 
				allowscriptaccess:"always", 
				bgcolor:"#FFFFFF", 
				scale:"noscale", 
				wmode:"transparent", 
				play:"true", 
				quality:"high", 
				menu:"false", 
				majorversion:flash_version, 
				build:"0", xi:"false", 
				flashvars:flash_vars
				};
				var altImage='<a href="http://www.adobe.com/go/getflashplayer" name="&lid=Download Flash Now"><img src="'+ assetId +'" width="605" border="0" name="main" /></a>';
				
			UFO.create(FO, argElement);
			
		} else {
			//$(argElement).style.visibility = 'visible';
			$(argElement).setHTML("<a href='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW' title='Get Flash'><img id='no_flash' src='"+assetId+"'/></a>");
						
			$(argElement).setStyles({visibility :'visible', height:parseInt($(argElement).getStyle('height'))});
			$('no_flash').setStyles({border:'none', padding:'0px', margin:'0px'});
			
			
		}
		
	}
}


var userData = new Object;
function getUserData(){

	cookieUserData = Cookie.get('userdata');

	if(cookieUserData) {
		//Decompress JSON values of userData
		userData = eval('(' + cookieUserData + ')');
	}

	if(Cookie.get('zipcode')) {
		userData.zipcode = Cookie.get('zipcode');
	}

	//Bake the userData cookie
	Cookie.set('userdata', Json.toString(userData), {duration: 365, path: "/"});

}

// External Interface hack for IE out of memory error
function nullFlashLoopFunction() { __flash_savedUnloadHandler = null; }
window.onbeforeunload = nullFlashLoopFunction;

function hasFlashMin(){
	var debug_html = getParameter('flash');
	var flash_version;
	if(debug_html == "false" && debug_html !=  ""){
		flash_version = 10;
	}else{
		flash_version = 8;
	}
	
	return(UFO.hasFlashVersion(flash_version,0));
}

/*Universal function to get parameter from url srting */
function getParameter(aP){var qS = new String(location.search.substring(1,location.search.length));var p = qS.split("&");var val = "";if(aP){for(i=0;i<p.length;i++){if(p[i].split( "=" )[0] == aP){val = p[i].split( "=" )[1];}}return val;}}


function check_hVal() {
var lVal = document.location.toString(); 
var hArray = new Array();
hArray = lVal.split(".org");
lVal = hArray[1];

if (lVal.length <= 1) {
hVal = true;
	}
else {
hVal = false;
	}
};

check_hVal();


