/* onload handler */
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;

/*
    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 */




// browser detection
function browserStats() {
  var ua = " " + navigator.userAgent.toLowerCase();
  this.nn = ua.indexOf( "mozilla" ) > 0;
  this.safari = ua.indexOf( "safari" ) > 0;
  ua.indexOf( "compatible" ) > 0 ? this.nn = false : "";
  this.ie = ua.indexOf( "msie" ) > 0;
  this.version = parseInt( navigator.appVersion );
  this.mac = ua.indexOf( "mac" ) > 0;
  this.ie ? ua.indexOf( "msie 5" ) > 0 ? this.version = 5 : "" : "";
  this.ie ? ua.indexOf( "msie 6" ) > 0 ? this.version = 6 : "" : "";
  return this;
}

var b = new browserStats();

// get proper domain for global navigation images and links
function getDomain( argLink ) {
    var curUrl = document.location.href;
    var newUrl = "";
    if( curUrl.indexOf( "iw-mount" ) >= 0 ) {
        // preserve virtualization
        newUrl = "";
    } else if( curUrl.indexOf( "://test" ) >= 0 ) {
        newUrl = "http://test.chrysler.com";
    } else if( curUrl.indexOf( "://uat" ) >= 0 ) {
        newUrl = "http://uat.chrysler.com";
    } else {
        newUrl = "http://www.chrysler.com";
    }
    if( argLink ) {
        if( argLink.indexOf( "javascript:" ) >= 0 ) {
            return argLink;
        } else {
            return newUrl + argLink;
        }
    } else {
        return newUrl;
    }
}

// route PSAM function call thru getDomain()
function invokeURL(url){window.location=getDomain(url);}

//Tracking Functions
function trackHit(){
  _hbSend();
}

function trackNamedHit(argLid,argPos){
  var whiteSpace = / /g;
  var newId = argLid.replace(whiteSpace,"+"); 
  var newPos = argPos.replace(whiteSpace,"+"); 
  _hbSet('lid',newId);
  _hbSet('lpos',newPos);
  trackHit();
}

//DHTML FUNCTIONS
var dt=document; var _a=(dt.all)?1:0; var l=(!dt.getElementById && b.nn)?1:0;
function getE(e,f){if(l){f=(f)?f:self;V=f.document.layers;if(V[e])return V[e];for(W=0;W<V.length;)t=getE(e,V[W++]);return t;}if(_a)return dt.all[e];return dt.getElementById(e);}
function showE(e){e=getE(e);if(l)e.visibility='show';else e.style.visibility='visible';}
function hideE(e){e=getE(e);if(l)e.visibility='hide';else e.style.visibility='hidden';}
function getX(e){e=getE(e);if(l)return e.left;else return e.style.left;}
function setX(e,x){e=getE(e);if(l)e.left=x;else e.style.left=x;}
function getY(e){e=getE(e);if(l)return e.top;else return e.style.top;}
function setY(e,y){e=getE(e);if(l)e.top=y;else e.style.top=y;}
function setZ(e,z){e=getE(e);if(l)e.zIndex=z;else e.style.zIndex=z;}
function setW(e,w){e=getE(e);if(l)e.clip.width=w;else e.style.width=w;}
function getW(e){e=getE(e);if(l)return e.document.width;if(_a)return e.scrollWidth;return e.offsetWidth;}
function setH(e,h){e=getE(e);if(l)e.clip.height=h;else e.style.height=h;}
function getH(e){e=getE(e);if(l)return e.document.height;if(_a)return e.scrollHeight;return e.offsetHeight;}
function setC(e,t,r,b,x){e=getE(e);if(l){X=e.clip;X.top=t;X.right=r;X.bottom=b;X.left=x;}else e.style.clip='rect('+t+' '+r+' '+b+' '+x+')';}
function writeH(e,h){e=getE(e);if(l){Y=e.document;Y.write(h);Y.close();}else e.innerHTML=h;trackHit();}
function getMouseX(e){if(_a)return event.clientX;return e.pageX;}
function getMouseY(e){if(_a)return event.clientY;return e.pageY;}
function getScrollX(){if(_a)return dt.body.scrollLeft;return window.pageXOffset;}
function getScrollY(){if(_a)return dt.body.scrollTop;return window.pageYOffset;}


//
// 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 == "model_image") {
		var clone = $(argElement).getFirst().clone().injectAfter('colors');
		clone.addClass('print');
	}
	// 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/
	*/
	if(overrideLowBand){
			userData.bandwidth = "high";

	//Bake the userData cookie
	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 ) {
		//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,
				'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
			};
		UFO.create(FO, argElement);
		
	} else {
		$(argElement).style.visibility = 'visible';
		if (!(hasFlashMin())){
			$(argElement).setHTML("<a href='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW' title='Get Flash'><img src='"+assetId+"' /></a>");
		}
	}
	
	
}


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;}}
