//var mainserver = "";                                                      // Uncomment this for www.wdc.com
//if (typeof mainserver == "undefined") mainserver="";    // This is to make sure the mainserver is defined.

var mainserver = "http://support.wdc.com";                                                        // Uncomment this for support.wdc.com
if (typeof mainserver == "undefined") mainserver="http://support.wdc.com";        // This is to make sure the mainserver is defined.

var insection = 0;

// detect browser version
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById) ? true : false;
var ie4 = (document.all) ? true : false;

// detect platform
var agent = navigator.userAgent.toLowerCase();

var win = ((agent.indexOf("win") != -1) || (agent.indexOf("16bit") != -1)) ? true : false;
var mac = (agent.indexOf("mac") != -1) ? true : false;

if (win)
{
    if (ie4)
        document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + mainserver + "/wdstyle/win_ie.css\">");
    else
    {
        if (ns4)
            document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + mainserver + "/wdstyle/win_ns4.css\">");
        if (ns6)
                document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + mainserver + "/wdstyle/win_ns6.css\">");
    }
}
    
else if (mac)
{
    if (ie4)
        document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + mainserver + "/wdstyle/mac_ie.css\">");
    else
    {
        if (ns4)
            document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + mainserver + "/wdstyle/mac_ns4.css\">");
        else
            if (ns6)
                document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + mainserver + "/wdstyle/mac_ns6.css\">");
    }        
    
}


function MM_displayStatusMsg(msgStr)  { //v3.0
    status=msgStr; document.MM_returnValue = true;
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function setSection(server)
{
    var path = new String();
    var delim, stop, token, tokenlink;

     path = location.pathname;
    delim = "/";
    stop = 0;
    token = "";

    path = path.substring(stop+1, path.length);
    stop = path.indexOf(delim);
    token = path.substring(0, stop);

    switch(server)
    {
        case "websupport" : case "rightnow" : case "young-america" : case "support" :
            { insection = 2; strImage = "imgSupport"; break; }
        case "localInvestor" : case "jobpost" : case "investor" :
            { insection = 4; strImage = "imgCompany"; break; }
        case "wdcStore" :
            { insection = 3; strImage = "imgBuy"; break; }
            
        default :
            switch (token.toLowerCase())
            {
                case "products" :
                    { insection = 1; strImage = "imgProducts"; break;}
                case "support" : case "library" :
                    { insection = 2; strImage = "imgSupport"; break; }
                case "buy" : 
                    { insection = 3; strImage = "imgBuy"; break;}
                case "company" :
                    { insection = 4; strImage = "imgCompany"; break;}
                case "partners" :
                    { insection = 5; strImage = "imgPartners"; break;}
                default:
                    insection = 0;
            }
    }    
    
    if (insection != 0) 
        eval('document.images["'+strImage+'"].src="'+mainserver+'/images/header/on'+insection+'.gif"');    
}


// show today's date in the header part
function showDate(plaintext)
{
    var time = new Date();
    var intYear = time.getFullYear();
    var intMonth = time.getMonth();
    var intDate = time.getDate();
    var strToday;
    
    switch(intMonth)
    {
        case 0:
            strMonth = "January";
            break;
        case 1:
            strMonth = "February";
            break;
        case 2:
            strMonth = "March";
            break;
        case 3:
            strMonth = "April";
            break;
        case 4:
            strMonth = "May";
            break;
        case 5:
            strMonth = "June";
            break;
        case 6:
            strMonth = "July";
            break;
        case 7:
            strMonth = "August";
            break;
        case 8:
            strMonth = "September";
            break;
        case 9:
            strMonth = "October";
            break;
        case 10:
            strMonth = "November";
            break;
        case 11:
            strMonth = "December";
            break;
     }
         
    strToday = strMonth + " " + intDate + ", " + intYear;
    
    
    if (plaintext == 1) 
    {
        document.write(strToday);
    }
    else
    {         
        //document.write("<span class=date>" + strToday + "</span>");
        document.write(strToday);
    }
    
}


// showing the page's hierachy path
function showPath(server)
{
    var path = new String();
    var title, tokens, classname;
    var strBegin, strBody, strEnd, strText;
    var depth = 0;
    
    // get the document's path and title
    title = document.title;
    path = location.pathname;
    
    if ((path.indexOf("/products/") != -1) || (path.indexOf("/library/") == 0) || (server == "websupport") || (server == "rightnow") || (server == "young-america") || (server == "support"))
        classname = "whitepath";    // show white color
    else
        classname = "blackpath";    // show black color
    
    
    if ((server == "support") || (server == "websupport") || (server == "rightnow") || (server == "young-america"))
    {
        strBody = showPathSupport(path, classname, "http://support.wdc.com", server);  //defined in /support/includes/support.js
           document.write ("<span class=" + classname + ">&nbsp;&nbsp;<a href=\"http://www.wdc.com/\" class=\"" + classname + "\">Home</a> " + strBody + "</span>");
    }
    else if (server == "investor")
    {        
        document.write ("<span class=\"blackpath\">&nbsp;&nbsp;<a href=\"http://www.wdc.com\" class=\"blackpath\">Home</a> > <a href=\"http://www.wdc.com/company/\" class=\"blackpath\">About WD</a> > <a href=\"http://199.230.26.96/wdc/index.shtml\" class=\"blackpath\">Investor Relations</a> > " + title + "</span>");
    }    
    else if (server == "localInvestor")
    {
        document.write ("<span class=\"blackpath\">&nbsp;&nbsp;<a href=\"/\" class=\"blackpath\">Home</a> > <a href=\"/company/\" class=\"blackpath\">About WD</a> > <a href=\"http://199.230.26.96/wdc/index.shtml\" class=\"blackpath\">Investor Relations</a> > " + title + "</span>");
    }
    else if (server == "jobpost")
    {
        document.write ("<span class=\"blackpath\">&nbsp;&nbsp;<a href=\"http://www.wdc.com/\" class=\"blackpath\">Home</a> > <a href=\"http://www.wdc.com/company/\" class=\"blackpath\">About WD</a> > <a href=\"http://www.wdc.com/company/employment/\" class=\"blackpath\">Employment</a> > <a href=\"http://www.wdc.com/company/employment/jobpost/\" class=\"blackpath\">Job Posting</a> > " + title + "</span>");
    }
    else if (server == "wdcStore")
    {
        document.write ("<span class=\"blackpath\">&nbsp;&nbsp;<a href=\"http://www.wdc.com/\" class=\"blackpath\">Home</a> > <a href=\"http://www.wdc.com/buy/\" class=\"blackpath\">Where to Buy</a> > " + title + "</span>");
    }
    else 
    {
      delim = "/";
      stop = 0;
      token = "";
      tokenlink = "/";
      strBody = "";

      while (stop != -1)
      {
          strBody = strBody + "<a href=\"" + tokenlink + "\" class=" + classname + ">" + token + "</a> > ";
          
          if (++depth > 4) break;
          
          path = path.substring(stop+1, path.length);
          stop = path.indexOf(delim);
          token = path.substring(0, stop);
          tokenlink = tokenlink + token + "/";
          token = getDescription(token);
          if (token == "Fillrup")
              break;
      } 
      strBody = strBody + title ;
      document.write ("<span class=" + classname + ">&nbsp;&nbsp;<a href=\"/\" class=\"" + classname + "\">Home</a> " + strBody + "</span>");
    }
}

function getDescription(token)
{
    switch(token)
    {
        case "company":
            token = "About WD";
            break;
        case "buy":
            token = "Where to buy";
            break;
        case "products":
            token = "Products";
            break;
        case "support":
            token = "Service & Support";
            break;
        case "partners":
            token = "Partners";
            break;
        case "signup":
            token = "New member"
            break;
        case "jobpost":
            token = "Job posting"
            break;
        case "pr":
            token = "Press Room"
            break;
        case "releases":
            token = "Press Releases"
            break;
        case "uk":
            token = "UK"
            break;
        case "selectwd":
            token = "SelectWD"
            break;
        case "dlg":
            token = "Data Lifeguard"
            break;
        case "eide":
            token = "EIDE"
            break;
        case "firewire":
            token = "FireWire"
            break;
        case "ata":
            token = "ATA"
            break;
        case "ace":
            token = "ACE"
            break;
        case "faqs":
            token = "FAQs"
            break;
        case "techinfo":
            token = "Technical Information"
            break;
        case "scsi":
            token = "SCSI"
            break;
        case "ide":
            token = "IDE"
            break;
        case "mac":
            token = "For Macintosh"
            break;
        case "pc":
            token = "For PC"
            break;
        case "library":
            token = "Document Library"
            break;
        
        case "translate":
            token = "Translation"
            break;        
        case "fr":
            token = "French"
            break;
        case "de":
            token = "German";
            break;
        case "sp":
            token = "Spanish";
            break;
        case "jp":
            token = "Japanese"
            break;
        case "ch":
            token = "Chinese"
            break;        
        case "kr":
            token = "Korean";
            break;
        default:                
            token = capitalize(token);
    }
    return token;
}

function capitalize(token)
{
    token = token.toLowerCase();
    first = token.charAt(0).toUpperCase();
    token = first + token.substring(1, token.length);
    return token;
}

function checkSearch(form)
{
    if (form.args.value == "" ) 
    {
        alert("Please enter your search text to do the search!");
        form.args.focus();
        return false;
    }
    return true;
}
