function checkCookie() {
   var oreo = new Cookie(document, "browsercheck");
   oreo.remove();
   oreo.favorite = "doublestuff";
   oreo.store();
   oreo.favorite = null;

   // now, let's try retrieving the cookie
   if(!oreo.load() || !oreo.favorite || oreo.favorite!="doublestuff") {
      return(false);
   } oreo.remove(); return(true);
} // checkCookie


function Cookie(document, name, hours, path, domain, secure) {
   // We use '$' to distinguish from actual properties.  Just bear with me.
   this.$document = document;
   this.$name = name;
   if(hours)
      this.$expiration = new Date((new Date()).getTime()+hours*3600000);
   else this.$expiration = null;
   if(path) this.$path = path; else this.$path = null;
   if(domain) this.$domain = domain; else this.$domain = null;
   if(secure) this.$secure = true; else this.$secure = false;

   this.store  = _Cookie_store;
   this.load   = _Cookie_load;
   this.remove = _Cookie_remove;
} // Cookie initializer

function _Cookie_store() {
   var cookieval = "";
   for(var prop in this) {
      if((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function'))
         continue;
      if(cookieval != "") cookieval += '&';
      cookieval += prop + ':' + escape(this[prop]);
   }

   var cookie = this.$name + '=' + cookieval;
   if(this.$expiration)
      cookie += '; expires=' + this.$expiration.toGMTString();
   if(this.$path) cookie += '; path=' + this.$path;
   if(this.$domain) cookie += '; domain=' + this.$domain;
   if(this.$secure) cookie += '; secure';

   this.$document.cookie = cookie
} // store() function of Cookie class

function _Cookie_load() {
   var allcookies = this.$document.cookie;
   if(allcookies=="") return(false);

   var start = allcookies.indexOf(this.$name + '=');
   if(start==-1) return(false); // undefined
   start += this.$name.length + 1;
   var end = allcookies.indexOf(';',start);
   if(end<0) end = allcookies.length;
   var cookieval = allcookies.substring(start, end);

   var a = cookieval.split('&');
   for(var i=0; i<a.length; i++)
      a[i]=a[i].split(':');

   for(var i=0; i<a.length; i++)
      this[a[i][0]] = unescape(a[i][1]);

   return(true);
} // load() function of Cookie class

function _Cookie_remove() {
   var cookie = this.$name + '=';
   if(this.$path) cookie += '; path='+this.$path;
   if(this.$domain) cookie += '; domain='+this.$domain;
   cookie += '; expires Fri, 02-Jan-1970 00:00:00 GMT';

   this.$document.cookie = cookie;
} // remove() function of Cookie clas

function verifyCookie() {
   if(checkCookie() == false){
      document.location.href="http://www.wd2c.com/nocookie.shtml";
   }
   if (document.forms[0]){
      if (document.forms[0].username){
         document.forms[0].username.focus();
      }
      if (document.forms[0].part_number){
         document.forms[0].part_number.focus();
      }
   }
}

function doIt(This, strUpdate, objForm, strRequestType)
{
   // If an element was specificed, disable it
   if(This != null){
      if(This.disabled == false){
         This.disabled = true
      }
   }

   // If a form was specified, submit it
   if (objForm != null){
      objForm.submit();
   }

   // If a DIV was specified, replace it was text
   if (strUpdate != ""){
      //var objHTML = document.all ( strUpdate );
      document.getElementById('objMenuBar').innerHTML = "<a class='error'>Processing your " + strRequestType + ", please wait..</a>";
   }

}

function hideThis(strObject)
{
    // Netscape?
    var NS4 = (document.layers) ? 1 : 0;
    // Get titlebar
    // Hide it
    if (NS4){
        var target = document.all( strObject );
        target.style.visibility = 'hidden';
    }
    else{
        var target = document.getElementById( strObject );
        target.style.display = 'none';
    }
}

function displayThis(strObject)
{
    // Netscape?
    var NS4 = (document.layers) ? 1 : 0;
    // Get titlebar
    // Re-display header
    if (NS4){
        var target = document.all( strObject );
        target.style.visibility = 'visible';
    }
    else{
        var target = document.getElementById( strObject );
        target.style.display = '';
    }
}


function verifyDelete(This)
{
    return confirm('Click OK if you are sure you want to delete\n ' + This);
}

function validateThis(This)
{
    var bAnswer = false;
    switch (This.call_type.value){
        case "DEL" : bAnswer = verifyDelete(This.user_customer_name.value);
                     break;
        default    : bAnswer = true;
    }


    return bAnswer;
}

// Page Print function removes header and footer to print
// only transaction
function printThis()
{
    hideThis('objMenuTop');
    hideThis('objFooter');

    // Print thing here
    window.print();

    displayThis('objMenuTop');
    displayThis('objFooter');

}

function highlightRow(This)
{
    This.style.backgroundColor = "#ffcc33";
}

//unhighlights table row
function unhighlightRow(This)
{
    This.style.backgroundColor = "";
}

function buildTable (iCol, sText, sAlign, sClass)
{
    var sTmp = '<tr><td ';

    if (iCol == 2){
        sTmp += 'colspan="2" ';
    }
    else{
       sTmp + 'align="right" valign="top"><img src="/images/paularrow.gif"/></td><td ';
    }

    sTmp += ' class="' + sClass + '" ';

    if (sAlign != ''){
        sTmp += ' align="' + sAlign +  '" ';
    }

    sTmp += '>' + sText + '</td>';
    sTmp += '</tr>';

    return sTmp;
}


function doRedirectCheck(doval)
{
    //DeleteCookie('pageViewed');

    var favorite = GetCookie('pageViewed');
    if (favorite != null){
        switch (favorite)
        {
        case 'no' :     url = 'http://www.wd2c.com/maintenance.html'; // change these!
                        break;
        case 'yes'  :   url = 'http://www.wd2c.com/xml/home.xml?producer=home&facility_id=WDC';
                        break;
        default     :   url = 'http://www.wd2c.com/maintenance.html';
        }
    }
    else{
        if (doval != ''){
            SetCookie('pageViewed', doval);
            url = 'http://www.wd2c.com/xml/home.xml?producer=home&facility_id=WDC';
        }
        else{
            url = 'http://www.wd2c.com/maintenance.html';
        }
    }

    //alert ('url: ' + url);

    window.location.href = url;
}


function loadXMLDoc(sURL)
{
    if (window.XMLHttpRequest){
        xmlhttp=new XMLHttpRequest()
        xmlhttp.onreadystatechange=state_Change
        xmlhttp.open("GET",sURL,true)
        xmlhttp.send(null)
    }
    else if (window.ActiveXObject){
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
        if (xmlhttp){
            xmlhttp.onreadystatechange=state_Change
            xmlhttp.open("GET",sURL,true)
            xmlhttp.send()
        }
    }
}

function state_Change()
{
    // if xmlhttp shows "loaded"
    if (xmlhttp.readyState==4){
      // if "OK"
      if (xmlhttp.status==200){
          //alert('here');
          //alert(xmlhttp.responseText);
          document.getElementById("objHTML").innerHTML=xmlhttp.responseText;
      }
      else{
          //alert("Problem retrieving data:" + xmlhttp.statusText)
          // Do nothing
          // Stick in potential error later.
          document.getElementById("objHTML").innerHTML="<table cellspacing=\"2\" cellpadding=\"5\" border=\"0\" width=\"717\"><tr><td>&nbsp; &nbsp;</td><td align=\"left\" class=\"headlineRed\"><B>Error!<br> You attempted to reach a page that does not exist.<br><br>Please try one of the links above or click our company logo to return to the main page. </B><br><br></td></tr></table>";

      }
    }
}

function getQueryVariable(variable) {
  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] == variable) {
      return pair[1];
    }
  }
  return '';
}





function newPage(sPage)
{

    docLoc = getQueryVariable('docLoc');
    current_qry = window.location.search;
    current_loc = window.location.pathname;

    // Default Page
    if ((sPage != '/docs/welcome.htm' && docLoc != sPage)){
        //pLoc = window.location.pathname;
        location.href = "http://www.wd2c.com/xml/home.xml?producer=home&facility_id=WDC&docLoc=" + sPage;
    }
    else if (sPage == '/docs/welcome.htm' && docLoc == ''){
        document.getElementById('objHTML').innerHTML="<a class='headlineRed'>Load document, please wait..</a>";
        loadXMLDoc(sPage);
    }
    else{
        document.getElementById('objHTML').innerHTML="<a class='headlineRed'>Load document, please wait..</a>";
        loadXMLDoc(docLoc);
    }
}




// SetCookie('pageViewed', 'yes');




