btnSuffix = "_tbl";  //for hiding entire button
txtSuffix = "_td";  //set to set innerHTML for button text

/*************************************
used in ds begin_nav.gsp in
the onmouseup event for the body tag

this function sends makes sure the
focus is always in the keyboard input
if there is one.

if page has keyboard input and
if the input's vis is either not set ( == empty string ) and is therefore visible
or it has been explicitly set to visible
***************************************/
function sendFocusToKb() {
  try {
    if(window.kb_input && ((window.kb_input.style.visibility == "visible") || (window.kb_input.style.visibility == ""))) {
      //this is really stupid
      if((window.event && window.event.srcElement) && event.srcElement.tagName == "INPUT") {
        //keeps cursor from jumping to the front
        window.event.cancelBubble=true;
      } else {
        kb_input.focus();
        kb_input.value+='';
        kb_input.focus();
      } 
    }
  } catch (error) {
  
  }
}

/************************************
paginator(firstItem)

  DESCRIPTION:
    This function handles generic nonscrolling pagination.
    It takes care of x of x text, prev/next buttons, and
    shows/hides item divs etc.
    
    firstItem = value indicating which page you are on
  
  DEPENDENCIES:
    set in the page:
    idPrefix set to some value which is used in the HTML IDs for items e.g. ver_itemInfo_0
    currentItem set to 0 on load to begin display with item 0
    itemsPerPage = the number of items per page
    
    somewhere (in a .js or in the page):
    placeData() must be defined which actually deals with how to populate data

*************************************/

  function paginator(firstItem) {
    startPagItem = currentItem+(firstItem*itemsPerPage);
    
    eval(idPrefix + "_btn_prev" + btnSuffix).style.display = (startPagItem) ? "inline" : "none";
    eval(idPrefix + "_btn_next" + btnSuffix).style.display = (items.length - (startPagItem + itemsPerPage) > 0) ? "inline" : "none";
    
    for(divNum=0;divNum<itemsPerPage;divNum++) {
      if(items[divNum + startPagItem]) {
        placeData();
      eval(idPrefix + "_row_" + divNum).style.display = 'block';

      } else {
        eval(idPrefix + "_row_" + divNum).style.display = 'none';
      }
    }
    currentItem = startPagItem;
      if(eval("window." + idPrefix + "_itemRange")) {
      lastInRange = (startPagItem + itemsPerPage < items.length) ? startPagItem + itemsPerPage : items.length;
      
      if(lastInRange - (startPagItem + 1) > 0) {
        theRange =  "s " + (startPagItem + 1) + " - " + lastInRange;
      } else {
        theRange = " " + lastInRange;
      }
      eval(idPrefix + "_itemRange").innerHTML = "Item" + theRange + " of " + items.length;
    }
  }
function testHeight(testElementID,testData,targetElement) {
  testElementID.innerHTML = testData;
if(parseInt(testElementID.clientHeight) > (parseInt(testElementID.style.height)+1)) {
    targetElement.style.overflow = 'hidden';
    targetElement.style.height = testElementID.style.height;
  } else {
    targetElement.style.height = '17px';
    targetElement.style.overflow = 'visible';
  }
}

/*
Used to prevent user from entering bad characters
from physical keyboard
theKeyCode = ASCII # of last key entered (e.g. from event.keyCode)
pat = regular expression of characters you want to allow in input

Function placed in this file so that it is defined before it
could ever be called
*/
function allowCharacter( theKeyCode, pat ) {
  allowedChars = pat || /[^\\\<\>\&\"]/g;
  allowEntry = false;
  if(allowedChars.test(String.fromCharCode(theKeyCode))) allowEntry = true;
  return allowEntry;
}

/**
 * This function toggles an element's visibility. Useful when wrapped
 * around setInterval() to fake element blinking.
 *
 * example: window.setInterval("toggleVisibility(searchText)", 250);
 *
 * @param element   The element ID that you want to toggle 
 *                  the visibility of.
 */
function toggleVisibility(element) {
  element.style.visibility = ( (element.style.visibility == 'visible') || (element.style.visibility == '') ) ? 'hidden' : 'visible';
}

/*
 * This function truncates a string and adds "..."
 * if it is longer than the specified length
 *  theText  = the string to check and possibly
 *             truncate
 *  theLimit = the number of characters you want
 *             allow before adding "..."
 */
function limitLength( theText, theLimit ) {
  if(theText.length > theLimit) {
    theOutput = theText.slice(0,theLimit) + "..."
  } else {
    theOutput = theText;
  }
  return theOutput;
}

/**
 * Global cookie functions
 */
function getCookie(name) {
  var re = new RegExp(name + "=([^;]+)");
  var value = re.exec(document.cookie);
  return (value != null) ? unescape(value[1]) : null;
}

function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

function deleteCookie (name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

/*
 * Creates HTML for rounded box
 * thePart = "top" | "bottom" - which half you want to print
 * theType  = the root name of the style and image
 *              e.g.
 *              the "note" in "cnr_note_top_left.gif"
 *              the "note" in box_note_top
 *            assumes the root is the same for both
 *            if empty makes the generic rounded box
 * theWidth/theHeight = (Optional) px width and height of table
 * cornerSize = if not specified assumes 15px
 */
function makeRoundedBox( thePart, theRoot, theWidth, theHeight, cornerSize ) {
  imgRootName = theRoot || "generic";
  styleRootName = theRoot || "gen";
  cornerSize = cornerSize || 15;
  boxWidth = ( theWidth ) ? "width: " + theWidth + "px;" : "";
  boxHeight = ( theHeight ) ? "height: " + theHeight + "px;" : "";
  roundedBoxHtml = "";
  if( thePart == "top" ) {
    roundedBoxHtml += "<table border=0 cellpadding=0 cellspacing=0 style=\"" + boxWidth + boxHeight + "\">";
    roundedBoxHtml += "  <tr>";
    roundedBoxHtml += "    <td><img src=\"/i/ds/corner/cnr_" + imgRootName + "_top_left.gif\" width=" + cornerSize + " height=" + cornerSize + "></td><td class=\"box_" + styleRootName + "_top\">&nbsp;</td><td><img src=\"/i/ds/corner/cnr_" + imgRootName + "_top_right.gif\" width=" + cornerSize + " height=" + cornerSize + "></td>";
    roundedBoxHtml += "  </tr>";
    roundedBoxHtml += "  <tr>";
    roundedBoxHtml += "    <td class=\"box_" + styleRootName + "_middle\" colspan=3  valign=top style=\"position: relative; " + boxWidth + "\">";
    roundedBoxHtml += "      <div class=\"txt_2_alt\">";
  }

  if( thePart == "bottom" ) {
    roundedBoxHtml += "      </div>";
    roundedBoxHtml += "    </td>";
    roundedBoxHtml += "  </tr>";
    roundedBoxHtml += "  <tr>";
    roundedBoxHtml += "    <td><img src=\"/i/ds/corner/cnr_" + imgRootName + "_bot_left.gif\" width=" + cornerSize + " height=" + cornerSize + "></td><td class=\"box_" + styleRootName + "_bottom\">&nbsp;</td><td><img src=\"/i/ds/corner/cnr_" + imgRootName + "_bot_right.gif\" width=" + cornerSize + " height=" + cornerSize + "></td>";
    roundedBoxHtml += "  </tr>";
    roundedBoxHtml += "</table>";
  }
  return roundedBoxHtml;
}

function getRebateDisclaimer(rebate) {
	return '<span class="promoLimitedTime">*Includes up to $' + parseFloat(rebate).toFixed(2) + ' instant rebate for qualified transactions.</span>';
}