
//http://www.biasecurities.com/blogs/jim/archive/2005/04/28/1794.aspx
function AttachEvent(elementObj, eventName, eventHandlerFunctionName)
{
  if (elementObj.addEventListener) 
  { // Non-IE browsers
    elementObj.addEventListener(eventName, eventHandlerFunctionName, false);		
  } 
  else if (elementObj.attachEvent) 
  { // IE 6+
    elementObj.attachEvent('on' + eventName, eventHandlerFunctionName);
  } 
  else 
  { // Older browsers 
    var currentEventHandler = elementObj['on' + eventName];
    if (currentEventHandler == null) 
    {
      elementObj['on' + eventName] = eventHandlerFunctionName;
    } 
    else 
    {
      elementObj['on' + eventName] = function(e) { currentEventHandler(e); eventHandlerFunctionName(e); }
    }
  }
}



  /* UTILITY FUNCTIONS */
  
function getObj(eventArgs){
 	var obj;
	
	if (eventArgs.target) {
		obj = eventArgs.target;
	} else if (eventArgs.srcElement) {
		obj = eventArgs.srcElement;
	}	
	/* For most browsers, obj would now be the object we're after; Safari however
		returns a text node so we need to check the node type to make sure */
	if (obj.nodeType == 3) {
	    obj = obj.parentNode;
	}
  
 	return obj;
}

function getObjID(eventArgs){
  var obj = getObj(eventArgs)
  return obj.id;
}
  
function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );

    while ( idx > -1 ) {
        str = str.replace( from, to );
        idx = str.indexOf( from );
    }
    return str;
}

function getElemRefs(id) {
    var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? getLyrRef(id,document): null;
    if (el) el.css = (el.style)? el.style: el;
    return el;
}




/* pop-up function. only needs a url and winName parameter -- attributes are defaulted. 
it is recommended that call to function at least include width and height attributes.
any attribute passed in will take precedence over default. -- dtw 8/5/05 */
function popUpWindow(url,winName,attributes) {
	if (attributes.indexOf("directories") == -1) { attributes += ",directories=0"; }
	if (attributes.indexOf("location") == -1) {	attributes += ",location=0"; }
	if (attributes.indexOf("menubar") == -1) { attributes += ",menubar=0"; }
	if (attributes.indexOf("resizable") == -1) { attributes += ",resizable=0"; }
	if (attributes.indexOf("scrollbars") == -1) { attributes += ",scrollbars=1"; }
	if (attributes.indexOf("status") == -1) { attributes += ",status=0"; }
	if (attributes.indexOf("toolbar") == -1) { attributes += ",toolbar=0"; }
	if (attributes.indexOf("top") == -1) { attributes += ",top=80";	}
	if (attributes.indexOf("left") == -1) { attributes += ",left=50"; }
	
	var newWindow = window.open(url,winName,attributes);
	if (window.focus && newWindow) { newWindow.focus() }
}


// We have a lot of popup windows that show up all over the site. 
// We define them commonly here, so that should a request come in to change a param of the window (say the size, or position), 
// we can update it in one place as opposed to accross the site.


function onstarHome() {
	popUpWindow('http://www.onstar.com/us_english/jsp/index.jsp?division=gc','onstar_win','width=785,height=650');	
}
function onstarDemo() {
	popUpWindow('http://www.onstar.com/us_english/jsp/idemo/index.jsp?division=gc','onstar_win','width=785,height=650');	
}
function openkbb() {
	popUpWindow('http://www.kbb.com/kb/ki.dll/ke.kb.sz?gmsg&&&zip;5945&1&GMC','kbb_win','width=795,height=650');	
}

function superPopUpWindow(url, window_name) {
	popUpWindow(url, window_name, 'width=605, height=580, scrollbars=no');	
}

function openNFTop(){
	window.open("http://www.gmfleet.com/email/email_updates.jsp");
}
	
//-- BEGIN tracking function ------------------------------------------------------------------------------
	
function clickTrack(oArg) {		

	if (typeof(oArg.s_pageName) == "string") { s_pageName = oArg.s_pageName; }
   if (typeof(oArg.s_lnk) == "boolean") {s_lnk = oArg.s_lnk;} else {s_lnk = true;}
   if (typeof(oArg.s_linkName) == "string") { s_linkName = oArg.s_linkName; }
   if (typeof(oArg.s_linkType) == "string") { s_linkType = oArg.s_linkType; } else { s_linkType="o"; }                                                            
   if (typeof(oArg.s_events) == "string") {s_events = oArg.s_events; }  
   if (typeof(oArg.s_prop1) == "string") { s_prop1 = oArg.s_prop1; }                                                           
   if (typeof(oArg.s_prop2) == "string") { s_prop2 = oArg.s_prop2; }                                                           
   if (typeof(oArg.s_prop3) == "string") { s_prop3 = oArg.s_prop3; } 
   if (typeof(oArg.s_prop4) == "string") { s_prop4 = oArg.s_prop4; } 
   if (typeof(oArg.s_prop5) == "string") { s_prop5 = oArg.s_prop5; } 
   if (typeof(oArg.s_prop11) == "string") { s_prop11 = oArg.s_prop11; }
   if (typeof(oArg.s_prop12) == "string") { s_prop12 = oArg.s_prop12; }
   if (typeof(oArg.s_prop13) == "string") { s_prop13 = oArg.s_prop13; }
   if (typeof(oArg.s_prop14) == "string") { s_prop14 = oArg.s_prop14; }
   if (typeof(oArg.s_prop15) == "string") { s_prop15 = oArg.s_prop15; }
   if (typeof(oArg.s_prop16) == "string") { s_prop16 = oArg.s_prop16; }
   if (typeof(oArg.s_prop17) == "string") { s_prop17 = oArg.s_prop17; }
   if (typeof(oArg.s_prop18) == "string") { s_prop18 = oArg.s_prop18; }
   if (typeof(oArg.s_prop19) == "string") { s_prop19 = oArg.s_prop19; }                                                           
   if (typeof(oArg.s_prop20) == "string") { s_prop20 = oArg.s_prop20; }
   if (typeof(oArg.s_prop21) == "string") { s_prop21 = oArg.s_prop21; }  
   if (typeof(oArg.s_prop24) == "string") { s_prop24 = oArg.s_prop24; }
   if (typeof(oArg.s_prop23) == "string") { s_prop23 = oArg.s_prop23; }
   if (typeof(oArg.s_prop25) == "string") { s_prop25 = oArg.s_prop25; }   
   if (typeof(oArg.s_prop28) == "string") { s_prop28 = oArg.s_prop28; }   
   if (typeof(oArg.s_prop30) == "string") { s_prop30 = oArg.s_prop30; }   
   if (typeof(oArg.s_eVar10) == "string") { s_eVar10 = oArg.s_eVar10; }   


   //alert(s_pageName+"~"+s_linkName+"~"+s_linkType+"~"+s_prop1+"~"+s_prop2+"~"+s_prop3+"~"+s_prop19+"~"+s_prop20+"~");
   //alert(s_account);
  // s_lnk=true;
   s_gs(s_account);
   s_pageName = "";
   s_prop1 = "";
   s_prop2 = "";
   s_prop3 = "";
   s_prop4 = "";
   s_prop5 = "";
   s_prop11 = "";
   s_prop12 = "";
   s_prop13 = "";
   s_prop14 = "";
   s_prop15 = "";
   s_prop16 = "";
   s_prop17 = "";
   s_prop19 = "";
   s_prop20 = "";
   s_prop21 = "";
   s_prop25 = "";
   s_prop24 = "";
   s_prop23 = "";
   s_prop28 = "";
   s_prop30 = "";
   eVar10="";
	
}
//-- END tracking function ------------------------------------------------------------------------------


/* as of today, this is only used by gvwr popup. it loads the url passed to it in a popup's parent window */
function gFlashBack(url) {
	if (window.opener && !window.opener.closed) {
		window.parent.opener.top.location.href = url;
		window.parent.opener.focus();
	} else {
		var NewWindow = window.open(url,'new_parent');
	}
}

function flashIsReady() {
	if (typeof isFlashReady != "undefined") {
		isFlashReady = true; 
	}
}

function changeBtnImage(srcImage, newImage)
{
   var e= document.getElementById(srcImage);
   e.src= newImage;
}
function openFeaturesAndSpecs(url){
	window.location.href =url;
}

/* Sets the length of zip field in left navigator */
function SetZipFieldLength(pEvent, e)
{
   mZip= document.getElementById(e);
   if (pEvent=="focus")
   {
      mZip.setAttribute('maxLength', 5);
      mZip.value="";
   }
   else
   {
      mZip.setAttribute('maxLength', 10);
      mZip.value="Enter ZIP";
   }
}