<!--

// *** Price Specials ***
// global variables listed in prices.js
// see lines 310, 364
// see also cart.js

var itemList = new Array()
var listText = ''
var itemType = ''
var pp1 = 0; var pp2 = 0; var pp3 = 0
var f1 = 0; var f2 = 0
var numOfPriceBoxes = 1
var helpItem = 1

// refresh num of items in cart (1000 = 1 sec)
function reFresh() { 
  var x = document.getElementById('numItems')
  if (x) { numberOfItems() }
}  
window.setInterval("reFresh()", 1000);

// Display # of items in cart
function numberOfItems() { 

  var num = GetCookie("NumberOrdered")
  if (!num || num == null) { num = 0 }
  document.getElementById("numItems").innerHTML = num
  return
}

// 'd' is name of text box, contains the text to search for
function search_form() {

  var text = document.jse_Form.d.value
  var xx = text.length
  document.cookie = 'd=null; path=/'
  if (xx > 0) { document.cookie = 'd=' + text + '; path=/' }
  window.location.href = "../sr/search.html"
}

function toggleCounter (x) {

  if (x == 'on') { document.getElementById('counter').className = 'showCount' }
  if (x == 'off') { document.getElementById('counter').className = 'hideCount' }
}

function searchKey(e) {

  var key = window.event ? e.keyCode : e.which

  // trap alpha upper case key presses
  if (key >= 65 && key <= 90) { return }  
  
  // trap alpha lower case key presses
  if (key >= 97 && key <= 122) { return }  
 
  // trap keyboard and num pad key presses
  if (key >= 48 && key <= 57) { return }  
  
  // trap space key press
  if (key == 32) { return }  

  // trap enter key press
  if (key == 13) { search_form() }  
  
  return false  
}

function displayHeader(page) {

  var text = '<div id="logo">'
         + '<a class="pics" href="../../index.html" title="Headset Factory Logo">'
	     + '<img src="../pics/logo.jpg" /></a>'
         + '<img id="flag2" class="flag" src="../pics/flag.jpg" title="Canadian Dollars">'
         + '<img id="flag1" class="flag" src="../pics/flag.jpg" title="Canadian Dollars">'
         + '</div>'

	     + '<div id="iconBox">'
         + '<div class="icons">'
         + '<a class="pics" href="../../index.html" title="Headset Factory Home Page">'
	     + '<img src="../pics/house.gif" /><br />'
	     + 'Home</a></div>'

         + '<div class="icons">'
         + '<a class="pics" href="javascript:helpInfo(24)" title="Display Contact Page">'
	     + '<img src="../pics/mail.gif" /><br />'
	     + 'Contact</a></div>'

         + '<div class="icons">'
		 + '<a class="pics" href="../../ch.html" title="Display Help Page">'
	     + '<img src="../pics/help.gif" /><br />'
	     + 'Help</a></div>'
 
         + '<div class="icons">'
		 + '<a class="pics" href="../../sl.html" title="Display Site Map/Links Page">'
	     + '<img src="../pics/globe.gif" /><br />'
		 + 'Map/Links</a></div>'

         + '<div class="icons items">'
         + '<a class="pics" href="../cart.html" title="Display Shopping Cart">'
	     + 'Items<span id="numItems">0</span>in Cart</a></div>'

		 + '<div id="searchBox">'
		 + '<form name="jse_Form" onsubmit="return false">'
         + '<input type="text" name="d" size="18" id="search" value="Search" '
         + 'onFocus="this.value=&quot;&quot;" onkeypress="return searchKey(event)">'
         + '<a href="javascript:search_form()">'
         + '<img id="goPic" src="../pics/go.gif"></a>'
		 + '</form></div>'

  // build product page list
  var entry = '<div id="pageTextBox"><p id="text1">'		 
  var pgList = 'Wireless,Corded,Computer,'
             + 'Accessories,,'
			 + 'wb,cd,co,ac,sp'		 
  var pgArray = pgList.split(",");				 
  for (i = 0; i < 5; i++) {
    var pgName = pgArray[i];
	var titleText = 'Display ' + pgName + ' Product Page' 
    var pg = pgArray[i + 5]
    var start = '<a class="pageList" href="../'
    var end = pg + '/' + pg + '.html" title="' + titleText + '">'
    var anchor = start + end
    if (pg == page) { anchor = '<a class="currentPage">' }
    entry += anchor + pgName + ' </a>'
	if (i == 5) { entry += '<br />' }
  }		
  
  text += entry + '</p></div></div>'
  document.getElementById('header').innerHTML = text 
  numberOfItems()
}

function displayFooter() { 

  // get current year
  var d = new Date()
  var year = d.getFullYear()
  var text = '<br />Photos derived from stock photos obtained from manufacturer '
		   + 'web sites. All logos copyright by the respective companies.<br />'
		   + 'This site design, layout, company logo, content copyright ' 
           + year + ' by Headset Factory.<br /><br />'
		   
  document.write(text)
}

function checkURL(name) {

  var paraName = 'item'
  paraName = paraName.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]" + paraName + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var paraValue = regex.exec(window.location.href);
  if (paraValue == null) { return }
  if (paraValue[1] == 'chk') { return paraValue[1] }
  document.cookie = name + '=' + paraValue[1] + '; path=/'
}

function lastView(page, x) {

  var name = 'lastViewed' + page
  checkURL(name)
  var c = GetCookie(name)
 
  // if no cookie, default item is 1 or 40(wireless)
  if (!c || c == null) { 
    var d = 1
	if (page == 'wb') { d = 40 }
    document.cookie = name + '=' + d + '; path=/' 
  }
	
  if (x == 0) { c = GetCookie(name); control(page, c) }
  if (x > 0) { document.cookie = name + '=' + x + '; path=/' }
}

function control(page, x, y) {

  // if no cookie, default item is 1 or 40(wireless)
  if (!x || x == 'null' || x == 0) { 
    x = 1
	if (page == 'wb') { x = 40 }
 }
  
  // get and display description and prices
  document.getElementById('des').innerHTML = getDescription(x)
  
  // set horiz price position by changing class
  // numOfPriceBoxes is set in priceTable()
  var prodItem = 'item' + x
  newClass(numOfPriceBoxes, prodItem, page) 
  
  // get pic file name and diplay pic
  // info[] defined in 'page'.js file
  var itemInfo = info[x];    
  var itemArray = itemInfo.split(",");
  document.images.picture.src = itemArray[0]
  if (page == 'ac' || page == 'sp') { displayPicLabels(x) }
   
  // cookie current page
  lastView(page, x)
  
  // if a jabra last viewed, display jabra list
  // used primarily when page first displayed
  // var y is only set in the list() function
  // used so this statement is not called avoiding 
  // a loop 
  if (page == 'wb' && x < 20 && !y) { list('gn', 1) }
  
  return
}

function newClass(x, y, page) {

  // change class to reposition price boxes 
  if (x == 2) { document.getElementById('priceBox').className = 'priceBox2' }
  if (x == 3) { document.getElementById('priceBox').className = 'priceBox3' }
  
  // change class to display current prod item in highlighted colour 
  var name = 'lastViewed' + page
  var c = 'item' + GetCookie(name)
  document.getElementById(c).className = 'prodList' 
  document.getElementById(y).className = 'currentItem' 
}

function list(x, y) {

  if (x == 'gn') {
 	document.getElementById('showPL').className = 'hide' 
 	document.getElementById('showGN').className = 'show' 
 	document.getElementById('view').innerHTML = 'View Plantronics' 
 	document.getElementById('view').onclick = new Function("list('pl')") 
	// var y only called from control() function
	// used to avoid control() being run twice and
	// resetting to gn9125 when any gn headset selected
	if(!y) { control('wb', 2, 1) }
  }	  
  if (x == 'pl') {
 	document.getElementById('showPL').className = 'show' 
 	document.getElementById('showGN').className = 'hide' 
 	document.getElementById('view').innerHTML = 'View Jabra' 
 	document.getElementById('view').onclick = new Function("list('gn')")
	control('wb', 40, 1)
  }   
}

function showCords(yy) {

  if (yy != 'gn' && yy != 'pl') { return }
  if (yy == 'gn') { var x = 1 }
  if (yy == 'pl') { var x = 3 }
  document.cookie = 'lastViewedac=' + x + ';null;path=/'
  window.location.href = '../ac/ac.html'
}

function helpInfo(x) {

  document.cookie = 'lastViewedch=' + x + ';null;path=/'
  window.location.href = '../../ch.html'  
}

function priceLevel() {

  var y = GetCookie('priceLevel')
  if (!y || y == 1) { document.cookie = 'priceLevel=2;;path=/' }
  else { document.cookie = 'priceLevel=1;;path=/' }
  window.location.reload(false)
}

function buildList(prodNum, bullets) {

  var items = ''; i = 1
  
  // itemList array is filled in 'page' .js file
  for (i == 1; i <= bullets; i++) {
    items += '<li>' + itemList[i] + '</li>'
  }
  var text = '<div id="itemTxt"><ul>' + items + '</ul></div>'

  return text
}

function priceTable(x, page) {

  itemType = ''
  var itemInfo = info[x];   // info[] defined in 'page'.js file
  var itemArray = itemInfo.split(",");
	
  if (page != 1 && page != 2 && page != 3) { page = 0 }
  if (page == 3) {
    page = 0
    var picPath = itemArray[0]
	var picPathArray = picPath.split('/')
	if (picPathArray[2] == 'pl') { page = 2 }
  }	
 
  var xx = itemArray[1];
  if (!xx || xx == 0) { xx = 1 }
  numOfPriceBoxes = xx
	
  pp1 = itemArray[2]; 
  p1 = getPrice(pp1)
	  
  ppp2 = itemArray[3]; 
  pp2 = getPrice(ppp2); 
  p2 = parseInt(p1) + parseInt(pp2)
  if (page == 1) { p2 = pp2 }
	  
  ppp3 = itemArray[4]; 
  pp3 = getPrice(ppp3); 
  p3 = parseInt(p1) + parseInt(pp3)
  if (page == 1) { p3 = pp3 }
	  
  t1 = itemArray[5]; 
  t2 = itemArray[6]; 
  t3 = itemArray[7];
	
  f1 = itemArray[8]; 
  f2 = itemArray[9];

  var addCart = '<button class="buyButton" title="Place item in Shopping Cart" '
  text = '<div id="priceBox" class="priceBox1">'
       + '<div class="cart"><a href="../cart.html" title="Display Shopping Cart">' 
       + '<img border="0" src="../pics/cart1.gif"></a></div>'
	   
       + '<div class="pBox">' + t1 
	   + '<p class="price">$' + p1 + '</p>'
	   + addCart + 'onclick="AddToCart(pp1,0,0)">Put in Cart</button>'
	   + '</div>'

  if (xx == 2 || xx == 3) {	
    var addParam = 'onclick="AddToCart(pp1,f1,0)"'
    if (page == 1) { addParam = 'onclick="AddToCart(ppp2,0,0)"' }  
    text += '<div class="pBox">' + t2
          + '<p class="price">$' + p2 + '</p>'
          + addCart + addParam + '>Put in Cart</button>'
          + '</div>'
  }
  if (xx == 3) {		  
    var addParam = 'onclick="AddToCart(pp1,0,f2)"'
    if (page == 1) { addParam = 'onclick="AddToCart(ppp3,0,0)"' }  
    text += '<div class="pBox">' + t3
	      + '<p class="price">$' + p3 + '</p>'
          + addCart + addParam + '>Put in Cart</button>'
	      + '</div>'
  }
  text += '<div class="cart" ><a href="../cart.html" title="Display Shopping Cart">' 
        + '<img border="0" src="../pics/cart2.gif"></a>'
	    + '</div></div>'

  // display specials message if discount amount exists(also top, 364)
  var message = '<p class="discMess hideMe">$00 discount applied in cart</p>'
  if (itemType == 'wl' && wlspl > 0) { 
    message = '<p class="discMess showMe">$' + wlspl + ' discount applied in cart</p>'
  }
  if (itemType == 'hs' && hsspl > 0) {   
    message = '<p class="discMess showMe">$' + hsspl + ' discount applied in cart</p>'
  }

  helpItem = 1
  if (itemArray[6] == 'w/ Amp') { helpItem = 10 }
  if (itemArray[6] == 'w/ Lifter') { helpItem = 12 }

  var howToLink = '<a class="grayLink">' 
  if (helpItem > 1) { 
    howToLink = '<a class="infoLink" href="javascript:helpInfo(helpItem)" '
              + 'title="Display Help Info on Headset Selection">' 
  } 
  var xx = '<p class="link"><span style="color:black;">How to...</span>'
  howTo = xx  + howToLink
 	    + '&#160;&#160;Select a Headset</a>' + "&#160;/&#160;"
        + '<a class="infoLink" href="javascript:helpInfo(15)" '
        + 'title="Display Help Info on Price Quotes">' 
  		+ 'Print a Quote</a></p>'
			
  var text1 = message + text + howTo
  return (text1)
}

// -------- blink message text - initiated line 182 ------

  var blinkCount = 0; var t
function blink() {	return
  clearTimeout(t)
  var cc = document.getElementById('spMess').style.visibility
//  if (itemType != 'wl' && itemType != 'hs') { return }
  if (cc == 'visible') { 
	document.getElementById('spMess').style.visibility = 'hidden'
  } else {
    document.getElementById('spMess').style.visibility = 'visible' 
  }
  t = setTimeout('blink()', 400)
  blinkCount += 1
  if (blinkCount == 7) { blinkCount = 0; clearTimeout(t) }
}

// ----- Get and display item price -------

function getPrice(item) {

  if (item == 0) { return }
  var itemInfo = GetItemInfo(item)
  var itemArray = itemInfo.split(",");
  var type = itemArray[0]
  if (type == 'wl') { itemType = 'wl' } // used to display specials message (also top, 310)
  if (type == 'hs' && itemType != 'wl') { itemType = 'hs' } // used to display specials message
  var price = itemArray[3];  // web pricing is 2, instore is 3
  
  return (price)
}

//-->


