function imgon(imgName) {
if (imgName != varChapter){
	if (document.images){
		document[imgName].src = eval(imgName + '1.src');
	}
}
}
function imgoff(imgName) {
if (imgName != varChapter){
	if (document.images){
		document[imgName].src = eval(imgName + '0.src');
	}
}
}
function setChapter(imgName) {
if (imgName != 'Btnb0'){
	if (document.images){
		document[imgName].src = eval(imgName + '1.src');
	}
}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function popUpWindow(strURL, strName, intHeight, intWidth) {
	window.open(strURL,strName,'dependent=1,toolbar=0,titlebar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=' + intWidth + ',height=' + intHeight);
}

function AddToBasket(lngProductID) {
  window.location.href='AddToBasket.aspx?ProductID=' + lngProductID + '&Quantity=' + document.getElementById('T'+lngProductID).value + '&referer='+location.href;
}

function IncTxtBox(objTxtBox, incM, maxV) {
  var intValue=document.getElementById(objTxtBox).value;
	intValue=intValue + incM;
	if (intValue<maxV) {
	document.getElementById(objTxtBox).value=intValue;
	}
	return true;
}

function DecTxtBox(objTxtBox, incM, minV) {
  var intValue=document.getElementById(objTxtBox).value;
    intValue=intValue - incM;
	if (intValue>=minV) {
    document.getElementById(objTxtBox).value=intValue;
	}
	return true;
}

function isNumberPress() {
  if (((event.keyCode > 47 && event.keyCode < 58) ||
       (event.keyCode > 95 && event.keyCode < 106)) && 
       !event.shiftKey       || 
       (event.keyCode == 37) ||
	     (event.keyCode == 39) || 
       (event.keyCode == 46) || 
       (event.keyCode == 8)  || 
       (event.keyCode == 9))
  {
    return true;
  }
  else
    return false;
}

function intDown() {
  if (navigator.appVersion.indexOf("Mac")==-1) {
    if (isNumberPress())
		  event.returnValue = true;
	  else
	  {
      event.keyCode      = 0; // Set to zero so don't handle
      event.cancelBubble = true;
      event.returnValue  = false;
    }
  }
}

function intDownWithPeriod() {
  if (isNumberPress() || ((event.keyCode == 190 || event.keyCode == 110)&& event.srcElement.value.indexOf(".")==-1))    
    event.returnValue  = true;
	else
	{
    event.keyCode = 0; // Set to zero so don't handle
    event.cancelBubble = true;        
    event.returnValue  = false;
  }
}

function textCounter(field, maxlimit) { 
  if (field.value.length > maxlimit) // if too long...trim it! 
    field.value = field.value.substring(0, maxlimit); 
    // otherwise, update 'characters left' counter 
  else 
    field.title = maxlimit - field.value.length; 
} 


function NewWindow(mypage,myname,w,h,scroll,pos) {
  if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
  if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
  else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
  settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
  win=window.open(mypage,myname,settings);
}

function changePic(objThis) {
  var thisCtrl;

document.tabDescription.src='../graphics/tabDescription-off.gif'
document.tabDetails.src='../graphics/tabdetails-off.gif'
	thisCtrl=eval("document." + objThis);
	thisCtrl.src='../graphics/' + objThis + '.gif';
	return true;
}

/*************************************************************************
  The following code is from Dynamic Web Coding at http://www.dyn-web.com/
  Copyright 2001-3 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

// resize fix for ns4
var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

var cur_lyr;	// holds id of currently visible layer
function swapLayers(id) {
  if (cur_lyr) hideLayer(cur_lyr);
  showLayer(id);
  cur_lyr = id;
}

function showLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "visible";
}

function hideLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "hidden";
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? getLyrRef(id,document): null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

// get reference to nested layer for ns4
// from old dhtmllib.js by Mike Hall of www.brainjar.com
function getLyrRef(lyr,doc) {
	if (document.layers) {
		var theLyr;
		for (var i=0; i<doc.layers.length; i++) {
	  	theLyr = doc.layers[i];
			if (theLyr.name == lyr) return theLyr;
			else if (theLyr.document.layers.length > 0) 
	    	if ((theLyr = getLyrRef(lyr,theLyr.document)) != null)
					return theLyr;
	  }
		return null;
  }
}

