
//This function preloads the global navigation elements
var navRoll = false;
//Set this variable to false so no global rollovers will work until all preloading is done.
function plGnav()
{
	plImages();
	navRoll = true;
}

//This function preloads rollover images with a & i suffixes for active and inactive
//The function can preload any number of images.
//usage: uPreload( object name, directory of image, extension of image )
var imgSuffix = new Array('i', 'a');
function uPreload(imgName, imgPath, imgExt)
{
	for (i=0; i < imgSuffix.length; i++) {
		eval( imgName + imgSuffix[i] + " = new Image();" );
  		eval( imgName + imgSuffix[i] + ".src = '" + imgPath + '/' + imgName + imgSuffix[i] + imgExt + "';" );
    }
}

function plImages()
{
	var linkArray = document.getElementsByTagName("img");
    for (var loop=0; loop<linkArray.length; loop++)
    {
    	imgClassArray = linkArray[loop].className.split(' ');
        for (var i=0; i<imgClassArray.length; i++)
        {
         	if (imgClassArray[i] == "pl")
         	{
    			var imgPath = linkArray[loop].src.substring( 0, linkArray[loop].src.lastIndexOf( '/' ));
    			uPreload( linkArray[loop].id, imgPath, linkArray[loop].src.substring( linkArray[loop].src.lastIndexOf( '.' ) ) );
         	}
        }
    }
}

//This function is for navigation rollover images; uName is name of graphic, uState is on, off or over state
function nr(uName, uState)
{
   if(navRoll)
   {
      document.images[uName].src = self[uName + uState].src;
   }
}

//This is used to popup a new centered window with no chrome. The last variable can be passed in to make the window scrollable.
function wPop(url, winName, wWidth, wHeight, scrll)
{
   var scrollB;
   if(!scrll)
   {
      scrollB = 'no';
      var pWidth = wWidth;
   }
   else
   {
      scrollB = scrll;
      wWidth = parseInt(wWidth) + 20;
   }
   var iMyWidth;
   var iMyHeight;
   iMyWidth =(window.screen.width / 2) - (wWidth / 2 + 10);
   //half the screen width minus half the new window width (plus 5 pixel borders).
   iMyHeight =(window.screen.height /2) - (wHeight / 2 + 15);
   //half the screen height minus half the new window height (plus title and status bars).
   var zWin = window.open(url, winName, "status=no,width=" + wWidth + ",height=" + wHeight + ",resizable=no,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=" + scrollB);
  // zWin.focus();
}

function VideoPopToggle(videopath,videowidth,videoheight,toggle)
{
    var toggleParam="";
	if (toggle=="toggle")
	{
	toggleParam="true";
	}
    var url = "/templates/videopop.jsp?&path=" + videopath + "&w=" + videowidth + "&h=" + videoheight + "&toggle=" + toggleParam + "&ref=VideoDownloadLibrary";
    wPop(url,"video",313,419)
}

function demoPop(selection)
{
	var url = selection;
	detectFlash();
	if (haveFlashVer)
	{
		url = selection;
	}
	else
	{
		url = "/Downloads/NoFlash.html";
	}
	wPop(url,"demo",700,410)
}

var myWin = null;
function newsletter_window(url)
{
 if(!myWin || myWin.closed) {
  myWin = window.open(url, 'newsletter',"top=5,left=5,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=900,height=750");
 }
}
function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=612,height=597,left = 341.5,top = 247');");
}
function popUpMap(URL) {
var axel = Math.random()+"";
var a = axel * 10000000000000;
var trackingImage = new Image();
trackingImage.src="http://ad.doubleclick.net/activity;src=1139861;type=eladl705;cat=ladpa976;ord=" + a + "?";
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=612,height=597,left = 341.5,top = 247');");
}
function popUpDir(URL) {
var axel = Math.random()+"";
var a = axel * 10000000000000;
var trackingImage = new Image();
trackingImage.src="http://ad.doubleclick.net/activity;src=1139861;type=eladl705;cat=ladpa255;ord=" + a + "?";
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=612,height=597,left = 341.5,top = 247');");
}
function setCookiePopUp(cookie, URL) {


	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=612,height=597,left = 341.5,top = 247');");
}
function printWindow()
{
	if (window.print){
		window.print()
	}
	else{
		alert("Your browser does not support this function. Please click the Print button in your browser's toolbar.");
	}
}

function homeFlash(xml)
{
    detectFlash();

	if (haveFlashVer)
	{
		flashBlock="<div id='hm_hdr'><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='758' height='198' VIEWASTEXT><param name='base' value='/_res/flash/swf/'><param name='movie' value='/_res/flash/swf/home_shell.swf?src=/_res/flash/xml/" + xml + ".xml' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><param name='SCALE' value='exactfit' /><embed src='/_res/flash/swf/home_shell.swf?src=/_res/flash/xml/" + xml + ".xml' width='758' height='198' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' wmode='transparent' base='/_res/flash/swf/' type='application/x-shockwave-flash' scale='exactfit'></embed></object></div>";
    }
    else
    {
        flashBlock="<div id='hdr'><div id='logo'><img src='/_res/i/logo.gif' alt='GM Goodwrench - Because who knows whats down the road' title='GM Goodwrench - Because who knows what's down the road' /></div><form id='search' action='/searchsite/' method='post'><div id='hsrch'><div><a href='/index.html' onmouseover='nr(\"unav01\",\"a\")' onmouseout='nr(\"unav01\",\"i\")'><img src='/_res/i/unav01i.gif' alt='Home' title='Home' id='unav01' class='pl' /></a></div><div class='unavbar'>&nbsp;</div><div><a href='/Newsletter/Signup.jsp' onmouseover='nr(\"unav02\",\"a\")' onmouseout='nr(\"unav02\",\"i\")'><img src='/_res/i/unav02i.gif' alt='Email Newsletter' title='Email Newsletter' id='unav02' class='pl' /></a></div><div class='unavbar'>&nbsp;</div><div><img src='/_res/i/unav03i.gif' alt='Search' title='Search' /></div><div class='sinput'><input type='text' name='q' maxlength='255'/></div><div><input type='image' src='/_res/i/unavgo.gif' alt='Go' title='Go' name='Search' id='navTopGo' /></div></div></form><div id='hsign'><img src='/_res/i/sign_top.gif' alt='Chevrolet, Pontiac, Buick, Cadillac, GMC, Hummer' title='Chevrolet, Pontiac, Buick, Cadillac, GMC, Hummer' /></div></div><div id='tnav'><div id='tn01'><a href='/Services/index.jsp' onmouseover='nr(\"tnav01\",\"a\")' onmouseout='nr(\"tnav01\",\"i\")'><img src='/_res/i/tnav01i.gif' alt='Goodwrench Services' title='Goodwrench Services' id='tnav01' class='pl' /></a></div><div id='tn02'><a href='/Tips/index.jsp' onmouseover='nr(\"tnav02\",\"a\")' onmouseout='nr(\"tnav02\",\"i\")'><img src='/_res/i/tnav02i.gif' alt='Goodwrench Tips' title='Goodwrench Tips' id='tnav02' class='pl' /></a></div><div id='tn03'><a href='/PartsAccessories/index.jsp' onmouseover='nr(\"tnav03\",\"a\")' onmouseout='nr(\"tnav03\",\"i\")'><img src='/_res/i/tnav03i.gif' alt='GM Parts &amp; Accessories' title='GM Parts &amp; Accessories' id='tnav03' class='pl' /></a></div><div id='sbtm'><img src='/_res/i/sign_btm.gif' alt='GM' title='GM' /></div></div>";
	}
	document.write(flashBlock);
}

function getParam(param)
{
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if (pair[0] == param) {
        return pair[1];
        }
    }
}
   function findOtherDealers()
   {
   var cookie_date = new Date ( );  // current date & time
   cookie_date.setTime ( cookie_date.getTime() - 1 );

   window.replace="/locatedealer/gmgoodwrench/dealersearch.jsp";
   document.location.href="/locatedealer/gmgoodwrench/dealersearch.jsp";
   }
function bPHeaderTracking(param)
{

}

function infoDrop(divId,divState)
{
	  var tDiv = document.getElementById(divId);
	  tDiv.style.display = divState;
}
String.prototype.replaceAll = function(findstring, newstring) {
	var newval = this;
	while(newval.indexOf(findstring) >= 0){
	newval = newval.replace(findstring, newstring);
}
return newval;
};
function flashInnerHTML(node) {
	var nodeNamesWeIgnore = "accessKey|coords|noWrap|dataFormatAs|disabled|dataSrc|object|dataFld|language|compact|contentEditable|inherit|tabIndex|align|clear|shape|charset|urn|dir|css";
    // that string doesn't let us ignore "hreflang" (href) of "hideFocus" (id)
    // it might be easier to search for the attributes we DO want instead of those we DON'T want.
    var result = "";
	switch (node.nodeType) {
	// http://www.zvon.org/xxl/DOM2reference/DOM2/Output/data/_glossary.html#NodeTypes
		case 3: // text node
			var textValue = node.nodeValue;
			textValue = textValue.replaceAll(/\t/g, "");
			textValue = textValue.replaceAll(/\n/g, "");
			textValue = textValue.replaceAll(/\r/g, "");
			result += textValue;
		break;
		case 1:
			result += "<" + node.nodeName.toLowerCase();
			if (node.attributes != null) {
				if (node.attributes.length > 0) {
					for (var i = 0;  i < node.attributes.length; i++) {
						var nodeName = node.attributes.item(i).nodeName;
						//if ((node.attributes.item(i).value != "null") && (node.attributes.item(i).value != "") && (nodeNamesWeIgnore.indexOf(nodeName) == -1)) {
						if ((node.attributes.item(i).value != "null") && (nodeNamesWeIgnore.indexOf(nodeName) == -1)) {
							result += " " + node.attributes.item(i).nodeName;
							result += "=\"";
							if(node.attributes.item(i).nodeName == "alt" || node.attributes.item(i).nodeName == "title"){
								node.attributes.item(i).value = node.attributes.item(i).value.replace("\"", "&#34;");
							}
							result += node.attributes.item(i).value +"\"";
						}
					}
				}
			}
			if (node.childNodes != null) {
				if (node.childNodes.length > 0) {
					result += ">";
					for (var j = 0;  j < node.childNodes.length; j++) {
						result += flashInnerHTML(node.childNodes[j]);
					}
					result += "</"+ node.nodeName.toLowerCase() +">";
				}
				else {
					result += "/>";
				}
			}
		break;
	}
	result = result.replaceAll("% ","%25 ");
	result = result.replaceAll("\"","%22");
	result = result.replaceAll("&amp;","%26");
	result = result.replaceAll("&","%26");
    return result;
}
