function initMaps() {
	if (document.getElementById) {
		var mapIds = initMaps.arguments;			// pass string IDs of containing map elements
		var i, j, area, areas;
		for (i = 0; i < mapIds.length; i++) {
			areas = document.getElementById(mapIds[i]).getElementsByTagName("area");
	
			for (j = 0; j < areas.length; j++) {	// loop thru img elements
				area = areas[j];
				area.onmouseout = imgSwap;
				area.onmouseover = imgSwap;
			}
		}
	}
}


// image swapping event handling
function imgSwap(evt) {
	evt = (evt) ? evt : event;
	var elem = (evt.target) ? evt.target : evt.srcElement;
	var imgClass = elem.parentNode.name;
	var coords = elem.coords.split(",");
	var clipVal = "rect(" + coords[1] + "px " +
							coords[2] + "px " +
							coords[3] + "px " +
							coords[0] + "px)";
	var imgStyle;
	
	switch (evt.type) {
		case "mouseout" :
			document.getElementById(imgClass + "Over").style.visibility = "hidden";
			//document.getElementById(imgClass + "Down").style.visibility = "hidden";
			break;
		case "mouseover" :
			imgStyle = document.getElementById(imgClass + "Over").style;
			imgStyle.clip = clipVal;
			imgStyle.visibility = "visible";
			break;
	}
	evt.cancelBubble = true;
	return false;
}



function initRollovers() {
  if (document.getElementById) {
      //var imgIds = initRollovers.arguments;			// pass string IDs of containing map elements
      var i, j, img, imgs, ros, ro;
      //for (i = 0; i < imgIds.length; i++) {
      ros = document.body.getElementsByTagName("ro");
      for (i = 0; i < ros.length; i++) {
          ro = ros[i];
          //alert('ro id of ' + ro.id);
          imgs = document.getElementById(ro.id).getElementsByTagName("img");
          for (j = 0; j < imgs.length; j++) {	// loop thru img elements
                  img = imgs[j];
                  //alert('one here ' + img.id);
                  img.onmouseout = imgSwapDirect;
                  img.onmouseover = imgSwapDirect;
          }
      }
  }
}


function imgSwapDirect(evt) {
	evt = (evt) ? evt : event;
	var elem = (evt.target) ? evt.target : evt.srcElement;
	var imgClass = elem.parentNode.id;
	//alert(imgClass);
	//alert(elem.width);
	
	
	var clipVal = "rect(0px 0px " + elem.width + "px " + elem.height + "px ";
	var imgStyle;
	
	switch (evt.type) {
		case "mouseout" :
			document.getElementById(imgClass + "Over").style.visibility = "hidden";
			//document.getElementById(imgClass + "Down").style.visibility = "hidden";
			break;
		case "mouseover" :
			imgStyle = document.getElementById(imgClass + "Over").style;
			//imgStyle.clip = clipVal;
			imgStyle.visibility = "visible";
			break
	}
	evt.cancelBubble = true;
	return false;
}




/////////////////////////////////////////////////////////////////////////////////

var currentTab = 1;

function selectTab(thetab, theone) {
  myItem = document.getElementById("tab" + currentTab);
  myItem.id = "tab" + thetab;
  currentTab = thetab;

  theparent = theone.parentNode;
  //alert(theparent.id);
  alltabs = document.getElementById(theparent.id).getElementsByTagName("a");
  //alert('here');
  for (j = 0; j < alltabs.length; j++) {
    tab = alltabs[j];
    if (tab == theone) {
      tab.className += " activeTab";
    } else {
      removeName(tab, "activeTab");
    }
  }


  for (i = 1; i < 8; i++) {
    myItem = document.getElementById("tab_detail_" + i);
    if (i == thetab) {
      ShowItem(myItem);
    } else {
      HideItem(myItem);
    }
  }
}

function ToggleVis(myItemID) { //v2.0
  myItem = document.getElementById(myItemID);
  if (myItem != null) {

    if (myItem.style.visibility != 'hidden') {
          HideItem(myItem);
    } else {
          ShowItem(myItem);
    }
  }
  return false;
}


function ToggleVisArray(myItemIDs) {
  for (i = 0; i < myItemIDs.length; i++) {
    myItem = document.getElementById(myItemIDs[i]);
    if (myItem != null) {
      if (myItem.style.visibility != 'hidden') {
            HideItem(myItem);
      } else {
            ShowItem(myItem);
      }
    }
  }
  return false;
}

function BlockItemArray(myItemIDs) {
  for (i = 0; i < myItemIDs.length; i++) {
    myItem = document.getElementById(myItemIDs[i]);
    if (myItem != null) {
      BlockItem(myItem);
    }
  }
  return false;
}



function GetHeight(myItemID) {
  myItem = document.getElementById(myItemID);
  if (myItem != null) {
    return (myItem.offsetHeight);
  }
}

function SetHeight(myItemID, value) {
  myItem = document.getElementById(myItemID);
  if (myItem != null) {
    myItem.height = value;
    myItem.style.height = value;
  }
}

function GetWidths(myItemIDs) {
  var thewidths = new Array(myItemIDs.length);
  for (i = 0; i < myItemIDs.length; i++) {
    myItem = document.getElementById(myItemIDs[i]);
    if (myItem != null) {
      thewidths[i] = myItem.offsetWidth;
    }
  }
  return (thewidths);
}

function GetWidth(myItemID) {
  myItem = document.getElementById(myItemID);
  if (myItem != null) {
    return (myItem.offsetWidth);
  }
}

function SetWidths(widths, myItemIDs) {
  for (i = 0; i < myItemIDs.length; i++) {
    myItem = document.getElementById(myItemIDs[i]);
    if (myItem != null) {
      myItem.width = widths[i];
      //alert('width of ' + myItemIDs[i] + ' is ' + myItem.width);
    }
  }
  return false;
}



function ShowItem(myItem) {
  if (myItem != null) {
    myItem.style.visibility = 'visible';
    myItem.style.display = '';
  }
}

function HideItem(myItem) {
  if (myItem != null) {
    myItem.style.visibility = 'hidden';
    myItem.style.display = 'none';
  }
}

function BlockItem(myItem) {
  if (myItem != null) {
    myItem.style.visibility = 'hidden';
    myItem.style.display = 'block';
  }
}

function doSubmit(myItemID) {
  myItem = document.getElementById(myItemID);
  myItem.submit();
  //document.forms["formbasket"].submit();
}

function change_bgcolor(myItemID, myColor) {
    myItem = document.getElementById(myItemID);
    myItem.bgColor = myColor;
    return true;
}

function menuredirect(myItemID) {
  myItem = document.getElementById(myItemID);
  var URL = myItem.options[myItem.selectedIndex].value;
  window.location.href = URL;
}

function openWindow(script,args,name) {
  var popupWindow = window.open(script,name,args);
}

function tabAct(imgName) {
       	if (document.images) {
       		document[imgName].src = eval(imgName + "_on.src");
       	}
}

function tabActF(imgName, srcName) {
       	if (document.images) {
       		document[imgName].src = eval(srcName + "_on.src");
       	}
}

function tabInact(imgName) {
	if (document.images) {
		document[imgName].src = eval(imgName + "_off.src");
	}
}

function tabInactF(imgName, srcName) {
	if (document.images) {
		document[imgName].src = eval(srcName + "_off.src");
	}
}





if(document.all && !document.getElementById) {
    document.getElementById = function(id) {
         return document.all[id];
    }
}

        function getAbsoluteLeft(o)
	{
		oLeft = o.offsetLeft
		while(o.offsetParent!=null)
		{
			oParent = o.offsetParent
			oLeft += oParent.offsetLeft
			o = oParent
		}
		return oLeft
	}

        function getAbsoluteRight(o)
	{
		oRight = o.offsetLeft
		while(o.offsetParent!=null)
		{
			oParent = o.offsetParent
			oRight += oParent.offsetLeft
			o = oParent
		}
		return oRight
	}

	function getAbsoluteTop(o)
	{
		oTop = o.offsetTop
		while(o.offsetParent!=null)
		{
			oParent = o.offsetParent
			oTop += oParent.offsetTop
			o = oParent
		}
		return oTop
	}

    var MenuFlag = 0;
    var MenuCloseDelay = 500;

    var DDMenuFlag = 0;
    var DDMenuCloseDelay = 500;
    var DDTimeout = 0;
    var DDTimeoutSet = 0;
    var DDWidth = 0;

	function setMenuFlagOn()
	{
		MenuFlag = 1;
	}

	function setMenuFlagOff()
	{
		MenuFlag = 0
	}

    function showMenu(o,html)
	{
		//document.getElementById('CategoryMenuP').innerHTML = html
		//alert("start A");
		//alert(document.getElementById(html).innerHTML);
		//document.getElementById('CategoryMenuP').innerHTML = document.getElementById(html).innerHTML;
		//alert("start B");
		//document.getElementById('CategoryMenuP') = document.getElementById(html);


                //alert(typeof(o));

                if (typeof(o) != 'object') {
                  //alert('getting o now');
                  o = document.getElementById(o);
                }
		
		
		var menu = document.getElementById('CategoryMenu');

                // save flicker?
                //if (menu.style.visibility == 'hidden') {

        		menu.style.left = getAbsoluteLeft(o) + 12;
	        	menu.style.top = getAbsoluteTop(o);
	        	menu.style.visibility = 'visible';
	        	menu.style.display = 'block';

	        	changeDiv(html);

		        //alert("gethere");

	        	setMenuFlagOn();
	        	window.setTimeout('checkMenu()', MenuCloseDelay);
                //}
	}

	function hideMenu()
	{
		var menu = document.getElementById('CategoryMenu')

		menu.style.visibility = 'hidden';
		menu.style.display = 'none';

		setMenuFlagOff();
	}
	
	function checkMenu()
	{
		var menu = document.getElementById('CategoryMenu')

		if(MenuFlag == 0)
		{
			menu.style.visibility = 'hidden';
			menu.style.display = 'none';
		}
		else
		{
			window.setTimeout('checkMenu()', MenuCloseDelay);
		}
	}


        function checkDDMenu()
	{
		var menu = document.getElementById('DropdownMenu')

		if(DDMenuFlag == 0)
		{
			menu.style.visibility = 'hidden';
			menu.style.display = 'none';
		}
		else
		{
			window.setTimeout('checkDDMenu()', DDMenuCloseDelay);
		}
	}


function showDDMenu(ot, ddm)
	{
		//document.getElementById('CategoryMenuP').innerHTML = html
		//alert("start A");
		//alert(document.getElementById(html).innerHTML);
		//document.getElementById('CategoryMenuP').innerHTML = document.getElementById(html).innerHTML;
		//alert("start B");
		//document.getElementById('CategoryMenuP') = document.getElementById(html);

                //if (DDTimeoutSet == 1) {
                //  window.clearTimeout(DDTimeout);
                //  DDTimeout = 0;
                //  DDTimeoutSet = 0;
                //  alert('show: timeoutcleared');
                //}

                //alert('about to show' + DDTimeoutSet);

                var o = document.getElementById(ot);
		
		
		var menu = document.getElementById(ddm);



                if (DDWidth == 0) {
                  var table = document.getElementById('DDTable');
                  DDWidth = table.offsetWidth;
                }

                


		menu.style.left = getAbsoluteLeft(o) - (DDWidth - o.offsetWidth);
		menu.style.top = getAbsoluteTop(o)  + o.offsetHeight;
                //menu.style.height = o.style.height;
                //menu.style.width = o.style.width;
		menu.style.visibility = 'visible';
                menu.style.display = 'block';



	}

function hideDDMenu(ddm)
        {
                var menu = document.getElementById(ddm);
                if (menu.style.visibility == 'visible') {
        		menu.style.visibility = 'hidden';
	        	menu.style.display = 'none';
                        DDTimeout = 0;
                        DDTimeoutSet = 0;
                }
        }

function setDDTimeout(ddm) {
   var menu = document.getElementById(ddm);
   if (menu.style.visibility == 'visible') {
     //alert('about to set timeout because ' + ddm + ' ' + menu.style.visibility);
     DDTimeoutSet = 1;
     DDTimeout = window.setTimeout("hideDDMenu('DropdownMenu')", 150);
   }
}

	
	
function changeDiv(divid){ 
  // create object of all div tags in the document 
  var tag = document.getElementsByTagName('DIV') 
  // create the child layer object using the argument passed to the function 
  var elid = document.getElementById(divid); 
  //the show/hide layer has an attribute nav="yes" in it 
  // to distiguish it from other DIV elements in the page 
  // by determining if that DIV element has the attribute 
  // i can make sure i'm affecting the show/hide layer DIV 

    for(x=0; x<tag.length; x++) { 
      //hide all div layers with the 'nav' attribute 
      if(tag[x].getAttribute("nav")) { 
	    tag[x].style.visibility="hidden"; 
        tag[x].style.display="none"; 
      }
	}  
      // show only the layer with the id passed as the argument 
      //  by the main function 
	  elid.style.visibility="visible"; 
      elid.style.display="block"; 

} 	




function changeImage( type, num ) {
	if (document.getElementById) {
		if ( document.images ) {
			if ( type == "prev" ) {
				imgNum--;
				if (imgNum < 0) {
					imgNum = imgLength - 1;
				}
			}
			else if ( type == "next" ) {
				imgNum++;
				if (imgNum >= imgLength) {
					imgNum = 0;
				}
			}
			else if ( type == "disp" ) {
				imgNum = num;
			}
			document.getElementById('productimage').src = productImgs[imgNum];

			//if ( productCaps != null ) { productCaps[imgNum] != '' ) {
			//	document.getElementById('productimage').alt = productCaps[imgNum];
			//	document.getElementById('productcaption').innerHTML = productCaps[imgNum];
			//}
			//else {
				document.getElementById('productimage').alt = 'Picture ' + ( imgNum + 1 );
				document.getElementById('productcaption').innerHTML = 'Picture ' + ( imgNum + 1 );
	
			//}
			document.getElementById('productimagecount').innerHTML = '(' + ( imgNum + 1 ) + ' of ' + imgLength + ')';
			
		}
						
		if ( type == "disp" ) {
			if ( document.getElementById ) {
				var imgElement = document.getElementById('imgTop');
				if ( imgElement && imgElement.scrollIntoView ){
					imgElement.scrollIntoView(1);
				}
			} 
			else {
				window.scrollTo(0,0);
			}
		}
		return false;
	}
	return true;
}



function setformfield(fieldname, fieldvalue) {
  //alert("Hello there");
  var myItem = document.getElementById(fieldname);
  //var myItem = eval("document." + fieldname);
  myItem.value = fieldvalue;
  //alert("Hello there again");
  //formSubmit(formname);
  //myItem.value = 0;
  //document.forms[formname].submit();
  //return false;
}

function setformfielda(fromfield, tofield) {
  var myFrom = document.getElementById(fromfield);
  var myTo   = document.getElementById(tofield);
  myTo.value = myFrom.value;
  return false;
}

function formSubmit(formname) {
  //alert("got here");
  document.forms[formname].submit();
  //alert("got here");
  //document.getElementById(formname).submit();
}



function getSelect(s) {
  return s.options[s.selectedIndex].value;
}



function round (n, d) {
  n = n - 0;
  d = d || 2;
  var f = Math.pow(10, d);
  n = Math.round(n * f) / f;
  n += Math.pow(10, - (d + 1));
  n += '';
  return d == 0 ? n.substring(0, n.indexOf('.')) : n.substring(0, n.indexOf('.') + d + 1);
}




function synchTab(frameName) {

  var elList, i;

  // Exit if no frame name was given.

  if (frameName == null)
    return;

  // Check all links.

  elList = document.getElementsByTagName("A");
  for (i = 0; i < elList.length; i++)

    // Check if the link's target matches the frame being loaded.

    if (elList[i].target == frameName) {

      // If the link's URL matches the page being loaded, activate it.
      // Otherwise, make sure the tab is deactivated.

      if (elList[i].href == window.frames[frameName].location.href) {
        elList[i].className += " activeTab";
        elList[i].blur();
      }
      else
        removeName(elList[i], "activeTab");
    }
}

function removeName(el, name) {

  var i, curList, newList;

  if (el.className == null)
    return;

  // Remove the given class name from the element's className property.

  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}





function theParent(myItemID) {
  return document.getElementById(myItemID).offsetParent;
  //if (myItem.offsetParent!=null) {
  //  alert('yes, something');
  //} else {
  //  alert('no, nothing');
  //}
  //  alert(myItem.offsetParent.id);
  //}
}



function glospop(link) {
  var ht = 400;
  var wd = 400;
  var top=(screen.height-ht)/2;
  var left=(screen.width-wd)/2;
  openWindow(link, 'width='+wd+',height='+ht+',left='+left+',top='+top+',resizable=yes,scrollbars=yes,toolbar=no');
}




function hide_atbs() {
  for (i = 0; i < 8; i++) {
    //myItemHide = document.getElementById("atb_" + i);
    //myItemShow = document.getElementById("atb_msg_" + i);
    HideItem(document.getElementById("atb_" + i));
    ShowItem(document.getElementById("atb_msg_" + i));
  }
}


function dropdown(mySel)
{
var myWin, myVal;
myVal = mySel.options[mySel.selectedIndex].value;
if(myVal)
   {
   if(mySel.form.target)myWin = parent[mySel.form.target];
   else myWin = window;
   if (! myWin) return true;
   myWin.location = myVal;
   }
return false;
}


function CombineParamsAndSet(target, prefix, myItemIDs) {
  myTotal = '';
  for (i = 0; i < myItemIDs.length; i++) {
    myItem = document.getElementById(prefix + myItemIDs[i]);
    if (myItem != null) {
      myTotal = myTotal + myItemIDs[i] + '|' + myItem.value + '||';
    }
  }
  //alert('total is ' + myTotal);
  myItem = document.getElementById(target);
  myItem.value = myTotal;
  return false;
}

function CheckNotNull(target, prefix, myItemIDs) {
  myTotal = 1;
  for (i = 0; i < myItemIDs.length; i++) {
    myItem = document.getElementById(prefix + myItemIDs[i]);
    if (myItem != null) {
      if (myItem.value == '') {
        myTotal = 0;
        break;
      }
    }
  }
  myItem = document.getElementById(target);
  myItem.value = myTotal;
  return false;
}


function CheckFormParam(id, match) {
  myItem = document.getElementById(id);
  if (myItem.value == match) {
    return true;
  } else {
    return false;
  }
}


function ProductOptionsFail() {
  alert('Please ensure that all the options fields have been completed before adding this product to your basket.');
}
