var window_onload = new Array;
var onloadRef = window.onload;
var cur_section;
var populate_zip;
var audio_on_text;
var audio_off_text;
var es_confirm_apps;
var userData = new Object;
//alert('hello Global js');
/*

    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++) {
		//alert(window_onload);
		eval(window_onload[i]);
	}
	//window_onload[i] = "";
};

function onload_register(func) {
	window_onload.push(func);
	/*
	var notIn = false;
	//alert("onload_register: "+ func);
	alert(window_onload);
	for (var i = 0; i < window_onload.length; i++) {
        if (window_onload[i] == func) {
            notIn = true;
			i = window_onload.length + 2; // GET OUT
        }
    }
	if (!notIn){
		//alert("onload_register: "+ func);
		window_onload.push(func);
	}
	*/
}
/* end onload handler */

function setBandwidth(bandwidth) {
	userData.bandwidth = bandwidth;
	//Bake the userData cookie
	Cookie.set('userdata', Json.toString(userData), {duration: 365, path: "/"});
	//Refresh the page (requires JS 1.2)
	window.location.reload( false );
}



function getUserData(skipPrefSets){
	var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	if(hasReqestedVersion){
		userData.bandwidth = 'high';
	}else{
		userData.bandwidth = 'low';
	}
	Cookie.set('userdata', Json.toString(userData), {duration: 365, path: "/"});
	cookieUserData = Cookie.get('userdata');
	if(cookieUserData) {
		//Decompress JSON values of userData
		userData = eval('(' + cookieUserData + ')');
	}


	//Bake the userData cookie
	Cookie.set('userdata', Json.toString(userData), {duration: 365, path: "/"});
	// hold back calls
}






// 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,overrideFlashVersion){
	if($(argElement)) {
		//console.log("flash is in the house");

		
		// cache buster for IE7 redraw issues
		if(argElement == "promos") {
			argSwf+= "?r=" + new Date().getTime();
		}

		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/
		*/

		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)

	//	alert('userData.bandwidth :'+userData.bandwidth);
		if ((userData.bandwidth != "low" && isLTOpera92 == false) || overrideLowBand ) {
			//CHECK WITH JASON LAW FOR WHAT NEEDS TO GO HERE
			var site_config = {
				'host':location.host,
				'src':location.href,
				'title':document.title,
				'isSafari':isSafari,
				'isLTOpera92':isLTOpera92,
				//'asset_path':'en',
				'EOF':'EOF'
			};
			var flash_vars = '';
			for(k in site_config) {
				if (k != "toJSONString") {
					flash_vars += "&" + k + "=" + encodeURIComponent(site_config[k]);
				}
			}

			// deep link & query strings
			if(location.href.indexOf("?") != -1) {
				// if we have a src in the query we need to strip it out to avoid overwrite
				if(location.href.indexOf("src=") != -1) {
					// split on the src
					var queryCleanedArray = location.href.split("src=");
					// if we have additional values past the src value
					if(queryCleanedArray[1].indexOf("&") != -1) {
						// remove the src altogether
						queryCleanedArray[1] = queryCleanedArray[1].substring(queryCleanedArray[1].indexOf("&")+1, queryCleanedArray[1].length);
					} else {
						// set the val to empty
						queryCleanedArray[1] = "";
					}
					// join on empty
					var cleanedVersion = queryCleanedArray.join("");
					flash_vars += "&" + cleanedVersion.substr(location.href.indexOf("?")+1);
				} else {
					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';
		
			// pass the containing div height and width
			flash_vars += "&stageWidth="+parseInt($(argElement).getStyle('width'))+"&stageHeight=" + parseInt($(argElement).getStyle('height')); 
			
			if(argFlashVars != null) {
				flash_vars += argFlashVars;
			}

			var debug_html = getParameter('flash');
			var flash_version;
			if(debug_html == "false" && debug_html !=  ""){
				flash_version = 11;
			}else if (overrideFlashVersion != null){
				flash_version = overrideFlashVersion;
			}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
			};
			UFO.create(FO, argElement);

			//these 2 lines are handled in the UFO.create function.
			//var renderElement = document.getElementById(argElement);
			//renderElement.style.visibility = 'visible';
		} else {
			$(argElement).style.visibility = 'visible';
			$(argElement).addClass('staticbkg');
		//	alert('hello. I am low band');
			programStaticNav();
			//setLowBandNav(argElement);
			//alert("hello "+argElement+" - band : " + userData.bandwidth);

		}
	}
}

function setLowBandNav(argElement){
	alert("hello lowband set");
	$(argElement).addClass('staticbkg');
	updateDIV('home_content');
}

// External Interface hack for IE out of memory error
function nullFlashLoopFunction() { __flash_savedUnloadHandler = null; }
window.onbeforeunload = nullFlashLoopFunction;

function formToSend(paramBlock){

alert('Call is recieved');
alert('option:('+paramBlock["o"]+')');
alert('fn:('+paramBlock["firstName"]+')  ln:('+paramBlock["lastName"]+') e:('+paramBlock["email"]+')'+' phone:('+paramBlock["phone"]+')');
alert('city:('+paramBlock["city"]+')  state:('+paramBlock["state"]+') zip:('+paramBlock["zip"]+')');

}




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));
}
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 setUserPreferences(){

alert('hasFlashMin() :'+ hasFlashMin());
	if(userData.bandwidth == "low"){
		if ($('footer_links'))

		{

		var link = $('footer_links').getFirst().getNext();

		link.setHTML(glossary_label_high_band);

		link.title = glossary_label_high_band;


		if (!(hasFlashMin())){

			//$('get_flash_button').setHTML("<a href='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW' title='Get Flash'><img src='/shared/images/get_flash.gif' /></a>");

		}

		link.name="&lid=High Bandwidth Version&lpos=global_footer";

		link.href="javascript:setBandwidth('high');";

		}

	}

}
