
function checkempty(form) {
      if ( form.search.value == "") {
         alert("Please enter a search criteria");
      }
      else {
         form.submit();
      }
   }


function openWin(url, width, height) {

          windowName  = "buttons";
          params      = "toolbar=0,";
          params     += "location=0,";
          params     += "directories=0,";
          params     += "status=0,";
          params     += "menubar=0,";
          params     += "scrollbars=0,";
          params     += "resizable=0,";

          params += "width="+width+",";
          params += "height="+height;

          win = window.open(url, windowName, params);
}



// Array of day names
var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

// Array of month Names
var monthNames = new Array(
"January","February","March","April","May","June","July","August","September","October","November","December");

var now = new Date();

var mdy = (monthNames[now.getMonth()] + " " + now.getDate() + ", " + now.getFullYear());

var dow = (dayNames[now.getDay()]);


ns=window.navigator.appName == "Netscape"
ie=window.navigator.appName == "Microsoft Internet Explorer"

function openIt(x) {
if(ns) {
   showbox = document.layers[x+1]
     showbox.visibility = "show";
       showbox.top=35;

    var items = 5;
     for (i=1; i<=items; i++) {
      elopen=document.layers[i]
        if (i != (x + 1)) {
          elopen.visibility = "hide" }
            }
  }

if(ie) {
   curEl = event.toElement
   curEl.style.background = "CE0000"

   showBox = document.all.box[x];
   showBox.style.visibility = "visible";
   showBox.style.top = 37;

   var items = 5
   for (i=0; i<items; i++) {
   elOpen=document.all.box[i]
   barEl=document.all.mnubar[i]
   if (i != x){
      elOpen.style.visibility = "hidden"
      barEl.style.background = "CE0000"
      }
   }
   }
}

function closeIt() {
   var items = 5
     for (i=0; i>items; i++) {
       if(ie){
        document.all.box[i].style.visibility = "hidden"
          barEl=document.all.mnubar[i]
           barEl.style.background = "CE0000"
       }
       if(ns){ document.layers[i+1].visibility = "hide"}
}
}

// Sets cookie values. Expiration date is optional
//
function setCookie(name, value, expire) {
          document.cookie = name + "=" + escape(value)  + ";path=/"
          + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

function getCookie(Name) {
          var search = Name + "="
          if (document.cookie.length > 0) { // if there are any cookies
                    offset = document.cookie.indexOf(search)
                    if (offset != -1) { // if cookie exists
                              offset += search.length
                              // set index of beginning of value
                              end = document.cookie.indexOf(";", offset)
                              // set index of end of cookie value
                              if (end == -1)
                                        end = document.cookie.length
                              return unescape(document.cookie.substring(offset, end))
                    }
          }
}
function gotoLocation(location_name)
{

   //alert( document.location.hostname );
   //alert( getCookie("SUBSTORE") );

   this.document.location =  document.location.protocol+"//"+document.location.hostname+"/";
}

/**
 * This method returns a string representing a link to the estore.  It uses
 * the current domain to determine what environment to use.  The default is
 * PROD.  This method assumes that host names are of the form:
 * www-env.domainname.com.
 *
 * Valid linkType values are:
 *   - LOGON
 *   - PASSWORD
 *   - REGISTER
 *   - HIDDEN
 *
 * @param linkType String
 * @return String
 *
 */
function getEstoreHtml(linkType)
{
  var linkString = "";
  var desiredDomain = "";
  var domainName = "";
  var wwtDomain = "";
  var wwtUnsecureDomain = "";

  //get merchant number
  var merchantNum = "";

  //determine domain
  desiredDomain = getDomain();
  domainName = getBaseAddress();
  if((desiredDomain.substr(0,2) == "xp") || (desiredDomain.substr(0,2) == "XP"))
  {
    wwtDomain = "http://"+desiredDomain+".wwt.com/";
    wwtUnsecureDomain = "http://"+desiredDomain+".wwt.com/";
  }
  else if(desiredDomain == "DEV")
  {
    merchantNum = getDevMerchantNum();
    wwtDomain = "https://www-dev.wwt.com/";
    wwtUnsecureDomain = "http://www-dev.wwt.com/";
  }
  else if (desiredDomain == "TEST")
  {
    merchantNum = getTestMerchantNum();
    wwtDomain = "https://www-test.wwt.com/";
    wwtUnsecureDomain = "http://www-test.wwt.com/";
  }
  else
  {
    merchantNum = getProdMerchantNum();
    wwtDomain = "https://www.wwt.com/";
    wwtUnsecureDomain = "http://www.wwt.com/";
  }

  //create appropriate link string
  if (linkType == "LOGON")
  {
    linkString = "<FORM NAME=\"logonform\" METHOD=post ACTION=\"" + wwtDomain + "portalWeb/comergent/netpointLogin.do\" TARGET=_top><input type=\"hidden\" name=\"loginType\" value=\"remote\"";
  }
  else if(linkType == "NOLOGON")
  {
    linkString = "<FORM NAME=\"logonform\" METHOD=post ACTION=\"" + domainName + "cgi-bin/ncommerce3/ExecMacro/IKON/home.d2w/report\" TARGET=_top>";
  }
  else if (linkType == "HIDDEN")
  {
    linkString = "<INPUT TYPE=HIDDEN NAME=url VALUE=\"" + domainName + "cgi-bin/ncommerce3/ExecMacro/IKON/orderclup.d2w/report?OLD_SHOPPER_NUM=&USERREGISTERED=NO\">";
  }
  else if (linkType == "PASSWORD")
  {
    linkString = "<img src=\"/images/bullet.gif\" height=\"8\" width=\"8\"> &nbsp;<A class=\"funclink\" HREF=\"" + domainName + "cgi-bin/ncommerce3/ExecMacro/IKON/resetpass.d2w/report\">Forgot your Password?</A>";
  }
  else if (linkType == "REGISTER")
  {
    linkString = "<img src=\"/images/bullet.gif\" height=\"8\" width=\"8\">&nbsp;<A HREF=\"" + wwtUnsecureDomain + "portalWeb/userSelfReg/begin.do\">Need to Register?</A>";
  }
  else if (linkType == "MERCHANT_HIDDEN")
  {
    linkString = "<input type=\"hidden\" name=\"merchant_rn\" value=\"" + merchantNum + "\">";
  }
  return linkString;
}

/**
 * Returns the merchant number for the e-store as a string.
 *
 * @returns String merchant number
 */
function getDevMerchantNum()
{
  return "106426";
}
function getTestMerchantNum()
{
  return "105526";
}
function getProdMerchantNum()
{
  return "163442";
}


function getEstoreURL()
{
    location.href = 'https://www.wwtbuy.com/cgi-bin/ncommerce3/ExecMacro/IKON/home.d2w/report';
    if (location.host == 'www-test.ikonitsource.com')
    {
      location.href = 'https://wwtbuytest.wwt.com/cgi-bin/ncommerce3/ExecMacro/IKON/home.d2w/report';
    }
    else if (location.host == 'www-dev.ikonitsource.com')
    {
      location.href = 'https://wwtbuy-dev.wwt.com/cgi-bin/ncommerce3/ExecMacro/IKON/home.d2w/report';
    }
}

function getDomain()
{
  var desiredDomain = "";

  //determine domain
  var prefix = location.host.substr(0, location.host.indexOf("."));
  if(prefix.lastIndexOf("-") > 0)
  {
    desiredDomain = prefix.substr(prefix.lastIndexOf("-")+1, prefix.length);
    desiredDomain = desiredDomain.toUpperCase();
  }
  else if((prefix.substr(0,2) == "xp") || (prefix.substr(0,2) == "XP"))
  {
    desiredDomain = prefix.substr(0,3);	
  }
  else
  {
    desiredDomain = "PROD";
  }
  return desiredDomain;
}

function getBaseAddress()
{
  var desiredDomain = getDomain();

  if(desiredDomain == "DEV")
  {
    domainName = "https://wwtbuy-dev.wwt.com/";
  }
  else if (desiredDomain == "TEST")
  {
    domainName = "https://wwtbuytest.wwt.com/";
  }
  else
  {
    domainName = "https://www.wwtbuy.com/";
  }
  return domainName;
}

// Sets cookie values. Expiration date is optional
//
function setCookie(name, value, expire) {
          document.cookie = name + "=" + escape(value)  + ";path=/"
          + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

function getCookie(Name) {
          var search = name +"=";
          if (document.cookie.length > 0) { // if there are any cookies
                    offset = document.cookie.indexOf(search)
                    if (offset >= 0) { // if cookie exists
                              offset += search.length
                              // set index of beginning of value
                              end = document.cookie.indexOf(";", offset)
                              // set index of end of cookie value
                              if (end == -1)
                                        end = document.cookie.length
                              return unescape(document.cookie.substring(offset, end))
                    }
          }
}
function submitForm(formName)
{
    var form;
    if(document.all)
    {
        form = document.all[formName];
    }
    else
    {
        form = document[formName];
    }
    //Adding this so the dcx user can log in with username@dcx.com instead of username@daimlerchrysler.com
    var s = form.login.value;
    if(s.indexOf("@dcx.com")>0)
    {
      form.login.value = s.replace("@dcx.com","@daimlerchrysler.com");
    }

    form.submit();
}
function loadLoginPage()
    {
       document.LoginForm.submit();
    }

