document.write('<LINK HREF="/css/telcobuy_main.css" REL="stylesheet" TYPE="text/css">');

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 == "DEV")
  {
    merchantNum = getDevMerchantNum();
    wwtDomain = "https://www-dev.telcobuy.com/";
    wwtUnsecureDomain = "http://www-dev.telcobuy.com/";
  }
  else if (desiredDomain == "TEST")
  {
    merchantNum = getTestMerchantNum();
    wwtDomain = "https://www-test.telcobuy.com/";
    wwtUnsecureDomain = "http://www-test.telcobuy.com/";
  }
  else
  {
    merchantNum = getProdMerchantNum();
    wwtDomain = "https://www.telcobuy.com/";
    wwtUnsecureDomain = "http://www.telcobuy.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 = "<A HREF=\"" + wwtUnsecureDomain + "portalWeb/userSelfReg/begin.do\">Click here 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.telcobuy.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")
  {
    desiredDomain = "DEV";
  }
  else
  {
    desiredDomain = "PROD";
  }
  
  return desiredDomain;
}

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

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

function onKeyPressed()
{
document.logonform.isValueEncrypted.value = "false";
}

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 getTelcobuyCookieInfo() 
{
   var cookieInfo = getCookie("MACCredsTelcobuy");
   if (cookieInfo != null || cookieInfo != "") 
  { 
    var loginId = cookieInfo.substring(0, cookieInfo.indexOf("|"));     
    var password = cookieInfo.substring(cookieInfo.indexOf("|") + 1); 
    if (loginId!= "" && password != "") 
     {
        document.logonform.login.value = loginId;
        document.logonform.passwd.value = password;
        document.logonform.savedCredentials.checked = true; 
     }
    else 
     {
       document.logonform.login.value = "";
       document.logonform.passwd.value = "";
       document.logonform.savedCredentials.checked = false; 
     }
  }
 }

function submitForm(formName)
{
    var form;
    if(document.all)
    {
        form = document.all[formName];
    }
    else
    {
        form = document[formName];
    }

	  if((formName == "logonform") && (document.getElementById("login").value == ""))
 	  {
 	    alert("Please enter a username.");
 	  }
 	  else if((formName == "logonform") && (document.getElementById("passwd").value == ""))
 	  {
 	    alert("Please enter a password.");
 	  }
    else
    {
      if (document.logonform.savedCredentials.checked == true) 
      {
        document.logonform.savedCredentials.value = "true";
      }
      if (document.logonform.savedCredentials.checked == false)
      {
       document.logonform.savedCredentials.value = "false";
     }
      form.submit();
    }
}

function loadLoginPage()
{
    alert("loadLoginPage() - hit server");
    document.LoginForm.submit();
}

// Header Method include
// Telcobuy and default are the same, and should be

function getHeader(headerFor)
{
    var header = "";

    switch(headerFor)
    {
    case "telcobuy":
        header = header + "<tr class=\"header\">";
        header = header + "<th height=\"47\" colspan=\"3\" scope=\"col\"><div align=\"left\"><span class=\"nav1\"> <a href=\"/index.html\">Home</a></span><span class=\"nav1\"><a href=\"/about/\">About</a></span><span class=\"nav1\"><span class=\"nav1\"><a href=\"/services/\">Products & Services</a></span><span class=\"nav2\"><a href=\"/sitehelp/contactus.html\">Contact Us</a></span></div></th>";
        header = header + "</tr>";
        break;

    default:
        header = header + "<tr class=\"header\">";
        header = header + "<th height=\"47\" colspan=\"3\" scope=\"col\"><div align=\"left\"><span class=\"nav1\"> <a href=\"/index.html\">Home</a> </span><span class=\"nav1\"> <a href=\"/about/\">About</a> </span> <span class=\"nav1\"> <a href=\"/news.html\">News</a> </span> <span class=\"nav1\"> <a href=\"/services/\">Products & Services</a> </span><span class=\"nav2\"> <a href=\"/customer_support/\">Support</a></span></div></th>";
        header = header + "</tr>";
        break;
    }
    return(header);
}

// Header Method include
// Telcobuy and default are the same, and should be
// Decided that this was not needed
// Leaving in case future requirements dictate a need

function getFooter(footerFor)
{
    var footer = "";
    switch(footerFor)
    {

      case "telcobuy":
        footer = footer + "<tr>";
        footer = footer + "<td colspan=\"3\" class=\"footerContent\"><a href=\"/sitehelp/siteterms.html\">Terms & Conditions</a>&nbsp; |  &nbsp;<a href=\"/sitehelp/privacypolicy.html\">Privacy Policy</a></td>";
        footer = footer + "</tr>";
        break;

      case "telcobuyMain":
        footer = footer + "<tr>";
        footer = footer + "<td colspan=\"3\" class=\"footer\"><a href=\"/sitehelp/siteterms.html\">Terms & Conditions</a>&nbsp; |  &nbsp;<a href=\"/sitehelp/privacypolicy.html\">Privacy Policy</a></td>";
        footer = footer + "</tr>";
        break;

      default:
        footer = footer + "<tr>";
        footer = footer + "<td colspan=\"3\" class=\"footerContent\"><a href=\"/sitehelp/contactus.html\">Contact Us</a> &nbsp; |  &nbsp;<a href=\"/portalWeb/appmanager/mac\">Employee Portal</a>&nbsp; |  &nbsp;<a href=\"/sitehelp/siteterms.html\">Terms & Conditions</a></td>";
        footer = footer + "</tr>";
        break;

    }
    return(footer);
}

// Secondary content include
// On the right side on the home page
// On the left side below login on other pages

function getSecondaryContent(contentReq)
{
    var content = "";
    switch(contentReq)
    {

// Whats new section short
      case "redesign":
        content = content + "Telcobuy.com has been redesigned.";
        content = content + "<p>";
        break; 

// Whats new section 
      case "ciscoAnnouncement":
        content = content + "<h1>";
        content = content + "TELCOBUY.COM named CISCO'S DIVERSITY DISTIBUTOR";
        content = content + "</h1>";
        content = content + "<p>";
        content = content + "Effective February 18, 2008 TELCOBUY.COM will become CISCO SYSTEM, INC’s Specialty Diversity Distributor. This program will allow CISCO GOLD PARTNERS with a defined and measurable diversity spend program to purchase CISCO products through TELCOBUY.COM at direct and/or channel pricing with no additional mark-up.";
        content = content + "</p>";
        content = content + "<p>";
        content = content + "This means that CISCO GOLD PARTNERS will have the flexibility of direct and Channel fulfillment through the one convenient source TELCOBUY.COM.  Additionally, CISCO GOLD PARTNERS will have the ability to claim 100% Tier 1 minority spend credits for all spend sourced through this program.";
        content = content + "</p>";
        content = content + "<p>";
        content = content + "Additionally, CISCO GOLD PARTNERS will have the ability to claim 100% Tier 1 minority spend credits for all spend sourced through this program.";
        content = content + "</p>";
        content = content + "<p>";
        content = content + "<div class=\"ciscoImage\">";
        content = content + "<img src=\"/images/cisco.jpg\" alt=\"Cisco\" width=\"71\" height=\"43\" />";
        content = content + "</div>";
        content = content + "<a href=\"/whatsnew.html\">Read More...<a/>";
        content = content + "</p>";
        break;

// Whats new section short
      case "ciscoAnnouncementShort":
        content = content + "Effective February 18th, 2008, TELCOBUY.COM named CISCO'S DIVERSITY DISTRIBUTOR.";
        content = content + "<p>";
        content = content + "<div class=\"ciscoImage\">";
        content = content + "<img src=\"/images/cisco.jpg\" alt=\"Cisco\" width=\"71\" height=\"43\" />";
        content = content + "</div>";
        content = content + "<a href=\"/whatsnew.html\">Read More<a/>";
        content = content + "</p>";
        break; 



// Displayed on the majority of the pages
      case "ciscoRegistration":
        content = content + "Effective February 4, 2008, Cisco has launched a new Diversity Distribution model where companies with a defined and measurable diversity spend program may purchase Cisco products through Telcobuy.  Telcobuy will source product direct from Cisco as well as through the Broad-Based Distribution Channel.  To participate in this program, please follow the link to complete the application form.";
        break;

// Displayed on the cisco registration form page
      case "ciscoRegistrationForm":
        content = content + "Please use the form to the right to register for the new Cisco Diversity Distribution program. If you have questions, please use the contact us page.";
        break;

      default:
        content = content + "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam id enim sit amet metus varius ullamcorper. Ut dignissim quam in purus. Sed sit amet tortor. Integer ipsum leo, rhoncus sed, dapibus eget, aliquam nec, nibh.";
        break;

    }
    return(content);

}

// Estore login 

function getEstoreLogin()
{
    if(getCookie('SHOWLOGON') == "FALSE")
    {
     	document.write( getEstoreHtml( "NOLOGON" ) );                
			document.write('                    <TR>');
			document.write('                      <TD>');
			document.write('                 <b> Enter Estore  </b>  </td><td>');
			document.write('                        <INPUT NAME="Logon" VALUE=LOGON TYPE=IMAGE SRC="/images/missouri/go.gif" ALIGN="MIDDLE" BORDER="0" ALT="Logon" width="25" height="25">');
			document.write('                      </TD>');
			document.write('                    </TR>');
			document.write('                </FORM>');
    }
    else
    {
      document.write(getEstoreHtml("LOGON"));
      document.write(getEstoreHtml("MERCHANT_HIDDEN"));
      document.write('                    <TR>');
      document.write('                      <TD>');
      document.write('                        <DIV CLASS="username">Username</DIV>');
      document.write('                        <div class="formInput"><INPUT TYPE="TEXT" id="login" NAME="login" SIZE=15 MAXLENGTH=60 onkeypress="onKeyPressed();checkKey()"></div>'); 
      document.write('                      </TD>');
      document.write('                    </TR>');
      document.write('                    <TR>');
      document.write('                      <TD>');
      document.write('                        <DIV CLASS="password">password</DIV>');
document.write('                        <div class="formInput"><INPUT TYPE="PASSWORD" id="passwd" NAME="passwd" SIZE=15 MAXLENGTH=60 onkeypress="onKeyPressed();checkKey()"></div>');
      document.write('                    </TR>');
      document.write('                    <TR>');
      document.write('                      <TD class="password">');
      document.write('                        <input type="checkbox" name="savedCredentials" id="savedCredentials" >');
      document.write('                        Save username/password');

       document.write(getEstoreHtml("HIDDEN"));

      document.write(' 			<input type=hidden name="cmd" value="directLogin" >');
      document.write(' 			<input type=hidden name="validate" value="true" >');
      document.write(' 			<input type=hidden name="isValueEncrypted" value="true" >');
      document.write('			<input type="hidden" name="LoginData-messageType" value="PartnerHomePageDisplay">');
      document.write('			<input type="hidden" name="LoginData-entryPoint" value="direct">');
      document.write('                      <span class="goimage"><a href="javascript:submitForm(\'logonform\')"><IMG SRC="/images/tbc_go_button.gif" ALIGN="MIDDLE" BORDER="0"></a></span>');
      document.write('                      </TD>');
      document.write('                    </TR>');
      document.write('                    <TR>');
      document.write('                        <TD>');
      document.write('<span class="regimage">');
      document.write(getEstoreHtml("REGISTER"));
      document.write('</span>');
      document.write('                      </TD>');
      document.write('                    </TR>');
    }

   document.write('                </FORM>');
   return"";
}
