var pageName;

function initPage(page)
{
    pageName = page;

    // Pre-load images

    var buttonList = new Array ("home", "about", "directions", "expertise",
                                "promotions", "contact", "join",
                                "symptoms", "tips", "mycar", "appointment", 
                                "myshop", "crs", "corporate", "quicktour", 
                                "product1", "product2", "product3", "product4", "product5");

    PreLoadButtons (buttonList);
}

function PreLoadButtons(names) 
{
    var name, image;

    for (var count=0; count < names.length; count++) {
	name = names[count];

	image     = new Image();
        image.src = "/images/shop/ACDelco/off/"  + name + ".gif";
        image.src = "/images/shop/ACDelco/on/" + name + ".gif";
    }
}

function getDocument()
{
    if (navigator.appName == "Microsoft Internet Explorer")
	theDoc = document.all;
    else
        theDoc = document;

    return theDoc;
}

function switchImages(action,name)
{
    if (name == pageName)
        return;

    var theDoc, image;

    theDoc = getDocument();
    image  = name + ".gif";

    if (action == 'on') {
        theDoc[name].src  = "/images/shop/ACDelco/on/" + image;
    } else {
        theDoc[name].src = "/images/shop/ACDelco/off/" + image;
    }

    return true;
}

function toggleImage()
{
    var theDoc = getDocument();

    theDoc[pageName].src = "/images/shop/ACDelco/on/" + pageName + ".gif";

    return true;
}

function printACDelcocrsTopNav (which)
{
    var buttons = new Array ("home","crs","products","corporate","contact","shops");
    var alt     = new Array ('MechanicNet Home', 'Customer Retension', 'Products',
                             'Corporate Info', 'Contact Us', 'Customer Service');
    var links   = new Array ('/techconnect/index.html', '/techconnect/company/crs.html', 
                             '/techconnect/company/servicereminders.html',
                             '/techconnect/company/corporate.html', 
                             '/techconnect/company/contact.html',
                             '/techconnect/myshop_login.html');
     var i;
     var imgsrc = new Array();
     for (i = 0; i < buttons.length; i++) {
        if (which == buttons[i]) {
             imgsrc[i] = '/images/shop/ACDelco/on/'  + buttons[i] + '.gif';
         } else {
             imgsrc[i] = '/images/shop/ACDelco/off/' + buttons[i] + '.gif';
         }
     }

  
    navhtml  = '<table border="0" valign="top" width="800" ';
    navhtml += ' cellspacing="0" cellpadding="0">';
    navhtml += '<tr><td height="87" background="/images/shop/ACDelco/topbg.gif" width="80">';
    navhtml += '<img src="/images/shop/ACDelco/acdelcologoleft.gif" border="0"></td>';
    navhtml += '<td height="87"  bgcolor="#02036F" width="670">';
    navhtml += '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
    navhtml += '<tr><td align="left">';
    navhtml += '<font class="ShopName">MechanicNet CRS</font></td>';
    navhtml += '<td align="right"><font face="arial" size="1" color="#ffffff">';
    navhtml += '6210 Stoneridge Mall Rd, Ste 200&nbsp;<br>Pleasanton, CA 94588&nbsp;<br>1-800-825-5886 prompt 4&nbsp;';
    navhtml += '</font></td></tr>';
    navhtml += '</table>';
    navhtml += '</td></tr>';
    navhtml += '<tr>\n';
    navhtml += '<td align="left" colspan="2" background="/images/shop/ACDelco/leftredmock.gif">';
    navhtml += '<img src="/images/shop/ACDelco/leftredmock.gif" border="0">';
    for (i = 0; i < buttons.length; i++) {
        if (buttons[i]) {
        navhtml += '<a href="' + links[i] + '"';
        navhtml += ' onmouseover="switchImages(\'on\', \'' + buttons[i] + '\');" ';
        navhtml += ' onmouseout="switchImages(\'out\', \'' + buttons[i] + '\');">';
        navhtml += '<img src="' + imgsrc[i] + '" name="' + buttons[i] + '" border="0" ';
        navhtml += ' alt="[' + alt[i] + ']"></a>\n';
        navhtml += '<img src="/images/shop/ACDelco/bannersepa.gif" border="0">';
       }
    }
    navhtml += '<img src="/images/shop/ACDelco/leftredmock.gif"></td></tr>';
    navhtml += '</table>\n'

    document.getElementById('navbuttons').innerHTML = navhtml;
}

function printBottomNav()
{
    var html  = '<table border="0" valign="top" width="805">';
    html     += '<tr><td align="center" bgcolor="#00006B" height="23" width="750">';
    html     += '</td></tr></table>';
   
    document.getElementById('bottomnav').innerHTML = html;
}

function gradientBlue(content, fontclass)
{
    // This function is used to generate blue color gradient string
    // to match ACDelco style.
   
    var title  = new String(content);
    var stringLen = title.length;
    var c;
    var color;
    var i;
    var htmlString = '';

    var startBlue    = 'FF';
    var endBlue      = '60';
    var startBlueDec = HexToNum (startBlue);
    var endBlueDec   = HexToNum (endBlue);

    var gradient = parseInt((Math.abs(endBlueDec - startBlueDec)) / stringLen);

    // Find the blue value base on the position i
    //   1. Get dec value from start blue and end blue
    //   2. Get gradient value based on position i and total number of characters.
    //   3. Transfer (start blue value dec value + gradient value) to hex.

    for (i = 0; i < stringLen; i++) {
        c     = title.charAt(i);
	color = getColor (stringLen, i, gradient, startBlue, endBlue, startBlueDec, endBlueDec);
        htmlString += '<font class="' + fontclass + '" color="'  + color
	htmlString += '"><b>' + c + '</b></font>';
    }
    return  htmlString;
}

function getColor(stringLen, i, gradient, startBlue, endBlue, startBlueDec, endBlueDec)
{
    var R = '00';
    var G = '00';

    var currentBlueDec = parseInt(startBlueDec) - parseInt(gradient) * i;

    var B = NumToHex(currentBlueDec);

    if (i == 0)               { B = startBlue; }
    if (i == (stringLen - 1)) { B = endBlue;   }

    return (R + G + B);
}

function HexToNum (h)
{
   var n;
   if (h.length > 1) {
       var first = MakeNum(h.charAt(0));
       var second = MakeNum(h.charAt(1));

       // Formula: (F * 16 ^ 1) + (F * 16 ^ 0) = FF
       if (h.match(/[A-Z]/)) {
           n = first * 16 + second;   
       } else {
           n = parseInt (h);
       }
   } else {
       n = MakeNum (h);
   } 

   return n;
}

function MakeNum(str) 
{
   if((str >= 0) && (str <= 9)) {
      return str;
   } else {
      switch(str.toUpperCase()) {
         case "A": return 10;
         case "B": return 11;
         case "C": return 12;
         case "D": return 13;
         case "E": return 14;
         case "F": return 15;
      }
   }
}

function NumToHex(strNum)
{
   base = strNum / 16;
   rem = strNum % 16;
   base = base - (rem / 16);
   baseS = MakeHex(base);
   remS = MakeHex(rem);
  
   return (baseS + '' + remS);
}

function MakeHex(x) 
{
  if((x >= 0) && (x <= 9)) {
      return x;
  } else {
      switch(x) {
        case 10: return "A"; 
        case 11: return "B";  
        case 12: return "C";  
        case 13: return "D";  
        case 14: return "E";  
        case 15: return "F";  
      }
   }
}

function copyright()
{
    var date = new Date();
    var year = date.getFullYear();

    document.getElementById('copyright').innerHTML =
        '<font face="arial, verdana" size="1">' +
        'Copyright &copy; ' + year + ', MechanicNet Group, Inc. All Rights Reserved</font>';
}

function openSMS()
{
    var link = '/techconnect/sms.html';
    newwindow =window.open(link,
                "sms",
                "top=50,left=50,height=320,width=500,channelmode=0," +
                "dependent=0,directories=0,fullscreen=0,location=0," +
                "menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0");
    newwindow.focus();
}
