
// --- ROLLOVER SECTION ---------------------------------------

// W3C DOM rollovers

var FluxRollovers = new Array;

function InitialiseRollovers() {
	if (document.getElementsByTagName) {
		var aoImg = document.getElementsByTagName('IMG');
		for (var i=0; i<aoImg.length; ++i) {
			if (aoImg[i].className == "fluxnavover") {
				aoImg[i].onmouseover = FluxNavOver;		
				aoImg[i].onmouseout = FluxNavOut;
				var oPreload = new Image;
				oPreload.src = aoImg[i].src.replace("\/normal\/", "\/rollover\/");
				FluxRollovers[FluxRollovers.length] = oPreload;
			}
			else if (aoImg[i].className == "fluximgover") {
				aoImg[i].onmouseover = FluxImgOver;		
				aoImg[i].onmouseout = FluxImgOut;
				var oPreload = new Image;
				oPreload.src = aoImg[i].src.replace("\/images\/", "\/rollovers\/");
				FluxRollovers[FluxRollovers.length] = oPreload;
			}
		}
	}
}

function FluxNavOver() {
	if (this.fluxoldsrc == null) {
		this.fluxoldsrc = this.src;
	}
	this.src = this.fluxoldsrc.replace("\/normal\/", "\/rollover\/");
}

function FluxNavOut() {
	if (this.fluxoldsrc != null) {
		this.src = this.fluxoldsrc;
		this.fluxoldsrc = null;
	}
}

function FluxNavActiveRollover() {
	if (this.fluxoldsrc == null) {
		this.fluxoldsrc = this.src;
	}
	this.src = this.src.replace("\/rollover\/", "\/active\/");
}

function FluxNavActiveNormal() {
	if (this.fluxoldsrc == null) {
		this.fluxoldsrc = this.src;
	}
	this.src = this.src.replace("\/normal\/", "\/active\/");
}

function FluxImgOver() {
	this.src = this.src.replace("\/images\/", "\/rollovers\/");
}

function FluxImgOut() {
	this.src = this.src.replace("\/rollovers\/", "\/images\/");
}

AddOnloadHandler(InitialiseRollovers);


function FluxPreload(sImage) {
	var oPreload = new Image;
	oPreload.src = sImage;
	FluxRollovers[FluxRollovers.length] = oPreload;
}

function FluxRollover(oTrigger, sID, sImage) {
	var oImage = document.getElementById(sID);
	if (oImage.fluxoldsrc == null) {
		oImage.fluxoldsrc = oImage.src;
	}
	oImage.src = sImage;
	oTrigger.onmouseout = new Function("FluxRollout('"+sID+"')");
}

function FluxRollout(sID) {
	var oImage = document.getElementById(sID);
	if (oImage.fluxoldsrc != null) {
		oImage.src = oImage.fluxoldsrc;
		oImage.fluxoldsrc = null;
	}
}

// --- POPUP SECTION ---------------------------------------

var oPopupImage = null;
var oPopupPage = null;
var oPopupHelp = null;

var bPopupImageOpen = false;
var bPopupPageOpen = false;
var bPopupHelpOpen = false;

var iLoadingPopupX = 140;
var iLoadingPopupY = 100;
var bPopupComplete = false;
var iPopupMarginX = 0;
var iPopupMarginY = 0;
var iPopupMinX = 0;
var iPopupMinY = 0;

function aiScreenPosXY(iPopupX, iPopupY) {
	var iScreenPosX = (screen.availWidth>iPopupX) ? (screen.availWidth-iPopupX)/2 : 0;
	var iScreenPosY = (screen.availHeight>iPopupY) ? (screen.availHeight-iPopupY)/2 : 0;
	return [iScreenPosX, iScreenPosY];
}

function iPageX() {
	var iX;
	if (window.innerWidth) {
		iX = window.innerWidth;
	}
	else if (document.body.offsetWidth) {
		iX = document.body.offsetWidth;
	}
	return iX;
}

function iPageY() {
	var iY;
	if (window.innerHeight) {
		iY = window.innerHeight;
	}
	else if (document.body.offsetHeight) {
		iY = document.body.offsetHeight;
	}
	return iY;
}

function aiPageXY() {
	var iX, iY;
	if (window.innerWidth) {
		iX = window.innerWidth;
		iY = window.innerHeight;
	}
	else if (document.body.offsetWidth) {
		iX = document.body.offsetWidth;
		iY = document.body.offsetHeight;
	}
	return [iX,iY];
}

function aiBrowserChrome() {
	top.resizeTo(200,200);
	var aiPageSize = aiPageXY();
	aiPageSize[0] = 200 - aiPageSize[0];
	if (aiPageSize[0] < 0) {
		aiPageSize[0] = 0;
	}
	aiPageSize[1] = 200 - aiPageSize[1];
	if (aiPageSize[1] < 0) {
		aiPageSize[1] = 0;
	}
	return aiPageSize;
}

function showError() {
	if (bPopupComplete == true) {
		return;
	}
	bPopupComplete = true;
	LayerPosHide("loading", 0, 0);
	LayerPosShow("error", 0, 0);
}

function showImage(bResize) {
	if (bPopupComplete == true) {
		return;
	}
	bPopupComplete = true;

	var oPic = (document.layers) ? document.layers.image.document.pic : document.pic;

	iPosLoadingX = oPic.width + 2*iPopupMarginX;
	if (iPosLoadingX < iPopupMinX)
		iPosLoadingX = iPopupMinX;

	iPosLoadingY = oPic.height + 2*iPopupMarginY + iPopupButtonY;
	if (iPosLoadingY < iPopupMinY)
		iPosLoadingY = iPopupMinY;

	LayerPosHide("loading",iPosLoadingX-140,iPosLoadingY-100); // position in lower right corner, used for oversize

	if (bResize == true) {
		var aiChrome = aiBrowserChrome();
		var iPopupX = oPic.width + aiChrome[0] + 2*iPopupMarginX;
		var iPopupY = oPic.height + aiChrome[1] + 2*iPopupMarginY + iPopupButtonY;
		if (iPopupX < iPopupMinX) {
			iPopupX = iPopupMinX;
		}
		if (iPopupY < iPopupMinY) {
			iPopupY = iPopupMinY;
		}
		if (window == top && (iPopupX > screen.availWidth-50 || iPopupY > screen.availHeight-50)) { // larger than screen
			location.href += "&type=oversize&xsize="+iPosLoadingX+"&ysize="+iPosLoadingY;
			return;	
		}	
		if (iPopupX > screen.availWidth - 50) {
			iPopupX = screen.availWidth - 50;
		}
		if (iPopupY > screen.availHeight - 50) {
			iPopupY = screen.availHeight - 50;
		}
		var aiScreenPos = aiScreenPosXY(iPopupX, iPopupY);	
		top.moveTo(aiScreenPos[0], aiScreenPos[1]);
		top.resizeTo(iPopupX,iPopupY);
	}

	var aiSize = aiPageXY();
	var iImagePosX = (aiSize[0] - oPic.width) / 2;
	var iImagePosY = (aiSize[1] - oPic.height - iPopupButtonY) / 2;

	if (iImagePosX < 0) {
		iImagePosX = iPopupMarginX;
	}
	if (iImagePosY < 0) {
		iImagePosY = iPopupMarginY;
	}

	if (document.layers) {
		setTimeout('LayerPosShow("image",'+iImagePosX+','+iImagePosY+')',200);
	}
	else {
		LayerPosShow("image",iImagePosX,iImagePosY);
	}
}

function popupImage(sImageURL, sTitle) {
	if (sTitle == null || sTitle == "") {
		sTitle = "Image Popup";
	}
	try {
		oPopupImage.close();
		bPopupImageOpen = false;
	}
	catch(e) {
	}
	aiScreenPos = aiScreenPosXY(iLoadingPopupX,iLoadingPopupY);
	oPopupImage = window.open("../common/popup.asp?image="+escape(sImageURL)+"&title="+escape(sTitle),"","scrollbars=no,resizable,width="+iLoadingPopupX+",height="+iLoadingPopupY+",screenX="+aiScreenPos[0]+",screenY="+aiScreenPos[1]+",left="+aiScreenPos[0]+",top="+aiScreenPos[1]);
	bPopupImageOpen = true;
	oPopupImage.focus();
}

function popupPage(sPageURL, iXsize, iYsize, bSeparate, bNoScrollbars, iXpos, iYpos) {
	if (oWindowOpener != null && oWindowOpener.flux2am) {
		aoArguments = new Array;
		for (var i=0; i<popupPage.arguments.length; ++i) {
			aoArguments[i] = popupPage.arguments[i];			
		}
		aoArguments[0] = "'"+aoArguments[0]+"'"; // wrap first arg in quotes
		oWindowOpener.setTimeout("popupPage("+aoArguments.join(",")+")",25);
		oWindowOpener.bPopupPageOpen = false;
		window.close();
		return;
	}

	if (iXsize == null) {
		iXsize = 500;
	}
	if (iYsize == null) {
		iYsize = 380;
	}
	var sScroll = (bNoScrollbars == true) ? "" : "scrollbars,";
	var aiScreenPos = aiScreenPosXY(iXsize, iYsize);	
	if (iXpos == null) {
		iXpos = aiScreenPos[0];
	}
	if (iYpos == null) {
		iYpos = aiScreenPos[1];
	}
	var sParameters	= sScroll+"resizable,width="+iXsize+",height="+iYsize+",screenX="+iXpos+",screenY="+iYpos+",left="+iXpos+",top="+iYpos;

	if (bSeparate == true) {
		window.open(sPageURL, "", sParameters);
	}
	else {
		try {
			oPopupPage.close();
			bPopupPageOpen = false;
		}
		catch(e) {
		}
		oPopupPage = window.open(sPageURL, "", sParameters);
		oPopupPage.focus();
		bPopupPageOpen = true;
	}
}

function popupHelp(sPageURL, iXsize, iYsize, bSeparate, bNoScrollbars, iXpos, iYpos) {
	if (iXsize == null) {
		iXsize = 350;
	}
	if (iYsize == null) {
		iYsize = 500;
	}
	var sScroll = "; scrollbars:yes";
	if (bNoScrollbars == true) {
		sScroll = "";
	}
	var aiScreenPos = aiScreenPosXY(iXsize, iYsize);	
	if (iXpos == null) {
		iXpos = aiScreenPos[0];
	}
	if (iYpos == null) {
		iYpos = aiScreenPos[1];
	}
	if (bSeparate == true) {
		window.showModelessDialog(sPageURL,window,"dialogWidth:"+iXsize+", dialogHeight:"+iYsize+", dialogLeft:"+iXpos+", dialogTop:"+iYpos+", help:no, resizable:yes, status:no"+sScroll);
	}
	else {
		if (bPopupHelpOpen == true) {
			oPopupHelp.close();
		}
		oPopupHelp = window.showModelessDialog(sPageURL,window,"dialogWidth:"+iXsize+"px; dialogHeight:"+iYsize+"px; dialogLeft:"+iXpos+"px; dialogTop:"+iYpos+"px; help:no; resizable:yes; status:no"+sScroll);
		bPopupHelpOpen = true;		
		oPopupHelp.focus();
	}
}

function InitialisePopups() {
	var oTarget = (oWindowParent != null && oWindowOpener != null) ? oWindowParent : window;
	if (oWindowOpener != null) {
		if (oWindowOpener.oPopupImage == oTarget) {
			oWindowOpener.bPopupImageOpen = true;
		}
		if (oWindowOpener.oPopupPage == oTarget) {
			oWindowOpener.bPopupPageOpen = true;
		}
	}
}

AddOnloadHandler(InitialisePopups);

function PopupsClose() {
	var oTarget = (oWindowParent != null && oWindowOpener != null) ? oWindowParent : window;
	if (oWindowOpener != null) {
		if (oWindowOpener.oPopupImage == oTarget) {
			oWindowOpener.bPopupImageOpen = false;
		}
		if (oWindowOpener.oPopupPage == oTarget) {
			oWindowOpener.bPopupPageOpen = false;
		}
	}
	
	if (bPopupImageOpen == true) {
		oPopupImage.close();
	}
	if (bPopupPageOpen == true) {
		oPopupPage.close();
	}
}

AddOnunloadHandler(PopupsClose);

// --- FORM SECTION ---------------------------------------

// returns null if element does not support a useful result
// otherwise, returns a string with current value of item
// string can be empty if no value is currently set
function sRetrieveValue(oElement) {
	var sElementValue = "";
	if (oElement.type == "text" || oElement.type == "textarea" || oElement.type == "password" || oElement.type == "file") {
		return String(oElement.value);
	}
	else if (oElement.type == "checkbox") {
		if (oElement.checked == true) {
			return String(oElement.value);
		}
		else {
			return "";			
		}
	}
	else if (oElement.type == "radio") {
		if (oElement != oElement.form[oElement.name][0]) {
			return null;
		}
		var oRadioElement = oElement.form[oElement.name];
		for (var j=0; j<oRadioElement.length; ++j) {
			if (oRadioElement[j].checked == true) {
				return String(oRadioElement[j].value);
			}
		}
		return "";
	}
	else if (oElement.type == "select-one" || oElement.type == "select-multiple") {
		if (oElement.selectedIndex >= 0) {
			return String(oElement.options[oElement.selectedIndex].value);
		}
	}
	return null;
}

function sCheckValue(oForm, sName, sValue, sRequired) {
	var sResult = "";
	
	var sDisplayName = sName.replace(/orderprofile/gi, '').replace(/address/g, 'address ').replace(/creditcard/g, 'credit card ').replace(/[!*]/g, '');
	
	if (sName != null && sName.charAt(0) == "!") { // leading ! in name indicates confirmation field
		var sName = sName.substring(1); // trim leading ! from name
		var sValueToConfirm = sRetrieveValue(oForm.elements[sName]);
		if (sValue != sValueToConfirm) {
			sResult += "Value for "+sDisplayName+" doesn't match confirmation\n\n";
		}
	}
	// leading * in name indicates required field	
	// also required if sName is in sRequired
	else if (sName != null && (sName.charAt(0) == "*" || sRequired.indexOf(' '+sName+' ') != -1 )) { 
		if (sName.charAt(0) == "*") {
			var sName = sName.substring(1); // trim leading * from name
		}
		if (sName.toLowerCase().indexOf("date") != -1) { // do extended date checking
			if (sValue == "") {
				sResult += "Please enter a date for "+sDisplayName+"\n\n";
			}
			else {
				var oDate = new Date(sValue);
				if (isNaN(oDate)) {
					sResult += "Please enter a valid date for "+sDisplayName+"\n\n";
				}
			}
		}
		else if (sName.toLowerCase().indexOf("email") != -1) { // do extended email checking
			if (sValue == "") {
				sResult += "Please enter an email address for "+sDisplayName+"\n\n";
			}
			else {
				var recheck = /\s/;
				if (recheck.test(sValue) == true) {
					sResult += "Email addresses cannot contain spaces\n\n";
				}
				if (sValue.indexOf("@") == -1) {
					sResult += "Email addresses must contain an @ symbol\n\n";
				}
				recheck = /[\w-]+@([\w-]+\.)+[a-zA-Z]{2,6}$/
				if (recheck.test(sValue) == false) {
					sResult += "There appears to be a mistake in the\nemail address you have typed.\nPlease check the address and try again.\n\n"; 
				}
			}
		}
		else if (sValue == "") {
			sResult += "Please enter a value for "+sDisplayName+"\n\n";
		}
	}
	return sResult;
}

function bValidateForm(oForm) {
	// find the field named "flux_required"
	var sRequired = oForm.flux_required ? oForm.flux_required.value : '';
	
	var sResult = "";
	var oFirstElement = null;
	for (var i=0; i<oForm.elements.length; ++i) {
		var oElement = oForm.elements[i];
		var sElementName = oElement.name;
		var sElementValue = sRetrieveValue(oElement);
		if (sElementName != null && sElementValue != null) {
			// check value, append any error messages returned
			sResult += sCheckValue(oForm, sElementName, sElementValue, sRequired);
			// if non-editable form item, and value starts with *, make that field mandatory
			if (sElementValue.charAt(0) == "*" && (oElement.type == "radio" || oElement.type == "checkbox")) {
				var oTemp = oElement.form[sElementValue.substring(1)];
				if (oTemp != null) {
					sResult += sCheckValue(oForm, sElementValue, sRetrieveValue(oTemp), sRequired);
				}
			}
			// if error save element for later focus
			if (oFirstElement == null && sResult != "") {
				oFirstElement = oElement;
			}
		}
	}
	if (oForm.elements["Origination_Email"] && oForm.elements["Origination_Email"].value == "") {
		oForm.elements["Origination_Email"].value = "UseFullSMTPHeaders";
	}
	if (sResult != "") {
		alert(sResult);
		if (oFirstElement != null && oFirstElement.focus != null) {
			oFirstElement.focus();
		}
		return false;
	}
	return true;
}

// --- NAVIGATION SECTION ---------------------------------------

function SetOpenerFrame(sURL) {
	if (oWindowOpener != null) {
		oWindowOpener.frame0.location = sURL;
		oWindowOpener.focus();
	}
	else {
		window.open(sURL);
	}
}

function SetOpenerPage(sURL) {
	if (oWindowOpener != null) {
		oWindowOpener.location = sURL;
		oWindowOpener.focus();
	}
	else {
		window.open(sURL);
	}
}

function DecodeURL(oFormElement) {
	var sEncodedURL = sRetrieveValue(oFormElement);
	if (oFormElement.selectedIndex) {
		oFormElement.selectedIndex = -1;
	}
	if (sEncodedURL == null || sEncodedURL == "") {
		return;
	}
	var asURL = sEncodedURL.split("\x01");
	if (asURL[0] == "main") {
		if (window.parent != null && window.parent.frame0 != null) {
			window.parent.frame0.location.href = asURL[1];
		}
		else {
			window.location.href = asURL[1];
		}
	}
	else if (asURL[0] == "blank") {
		window.open(asURL[1]);
	}
	else if (asURL[0] == "top") {
		if (window.parent != null && window.parent.frame0 != null) {
			window.parent.location.href = asURL[1];
		}
		else {
			window.location.href = asURL[1];
		}
	}
	else if (asURL[0] == "openerframe") {
		SetOpenerFrame(asURL[1]);
	}
	else if (asURL[0] == "openerpage") {
		SetOpenerPage(asURL[1]);
	}
	else if (asURL[0] == "anchor") {
		if (window.parent != null && window.parent.frame0 != null) {
			window.parent.frame0.location.hash = asURL[1];
		}
		else {
			window.location.hash = asURL[1];
		}
	}
	else if (asURL[0] == "mailto") {
		window.location.href="mailto:"+asURL[1];
	}
	else if (asURL[0] == "alert") {
		alert(asURL[1]);
	}
}

// --- FLYUP SECTION ---------------------------------------

var iFlyupTimeout;
var sFlyupName;

function getXYpos(oImage) {
  var iX = 0;
  var iY = 0;
  if (document.layers) {
    iX = oImage.x;
    iY = oImage.y;
  }
  else {
    while (oImage.offsetParent != null) {
      iX += oImage.offsetLeft;
      iY += oImage.offsetTop;
      oImage = oImage.offsetParent;
    }
//    iX += parseInt(document.body.leftMargin); // Mac IE5
//    iY += parseInt(document.body.topMargin); // Mac IE5
  }
  return [iX,iY];
}

function getXY(sName) {
  var iX = 0;
  var iY = 0;
  var iXwidth;
  var iYheight;
  
  var oTemp = document[sName];  
  if (oTemp != null) {
    iXwidth = oTemp.width;
    iYheight = oTemp.height;
    var aiXY = getXYpos(oTemp);
  }
  else {  
    oTemp = document[sName+"_p2"];  
	var aiXY = getXYpos(oTemp); 
	iXwidth = aiXY[0];
  	iYheight = aiXY[1];
    oTemp = document[sName+"_p1"];  
    var aiXY = getXYpos(oTemp);
	iXwidth -= aiXY[0];
	iYheight -= aiXY[1];
  }	
  return [aiXY[0],aiXY[1],iXwidth,iYheight];
}

function LayerPosShow(layername, iPosX, iPosY) {
  oLayer = oFindLayer(layername);
  if (document.layers) {
    oLayer.left = iPosX;
    oLayer.top = iPosY;
    oLayer.visibility = "show";
  }
  else {
		var oUnits = (typeof oLayer.style.left == "string") ? "px" : 0;
		oLayer.style.left = iPosX + oUnits;
		oLayer.style.top = iPosY + oUnits;
    oLayer.style.visibility = "visible";
  }
}

function LayerPosHide(layername, iPosX, iPosY) {
  oLayer = oFindLayer(layername);
  if (document.layers) {
    oLayer.left = iPosX;
    oLayer.top = iPosY;
    oLayer.visibility = "hide";
  }
  else {
		var oUnits = (typeof oLayer.style.left == "string") ? "px" : 0;
		oLayer.style.left = iPosX + oUnits;
		oLayer.style.top = iPosY + oUnits;
    oLayer.style.visibility = "hidden";
  }
}

function FlyupShowPos(sLayer, iPosX, iPosY) {
  if (sFlyupName != null) {
    if (sLayer == sFlyupName) { // re-showing nav about to be hidden, cancel
      if (iFlyupTimeout != null) {
        clearTimeout(iFlyupTimeout);
        iFlyupTimeout = null;
      }
    }
    else {		     
      LayerPosHide(sFlyupName,-500,-500); // hide early
    }
  }
  LayerPosShow(sLayer,iPosX,iPosY);
  sFlyupName = sLayer;
}

function FlyupShow(sLayer) {
  if (sFlyupName != null) {
    if (sLayer == sFlyupName) { // re-showing nav about to be hidden, cancel
      if (iFlyupTimeout != null) {
        clearTimeout(iFlyupTimeout);
        iFlyupTimeout = null;
      }
    }
    else {		     
      LayerPosHide(sFlyupName,-500,-500); // hide early
    }
  }
  sFlyupName = sLayer;
}

function FlyupHide(sLayer) {
	if (iFlyupTimeout != null) {
		clearTimeout(iFlyupTimeout);
		iFlyupTimeout = null;
	}
	iFlyupTimeout = setTimeout("FlyupInstantHide('"+sLayer+"')",200);
}

function FlyupInstantHide(sLayer) {
  if (iFlyupTimeout != null) {
		clearTimeout(iFlyupTimeout);
		iFlyupTimeout = null;
	}
	LayerPosHide(sLayer,-500,-500);
	if (sLayer == sFlyupName) {
		sFlyupName = null; 
	}
}


// --- FLYUP MENU SECTION ---------------------------------------

var asFlyupMenuName = new Array;
var iFlyupMenuTimeout = null;

function FlyupMenuShow(sParent, sLayer, iPosX, iPosY, iDelay) {
	if (iFlyupMenuTimeout != null) {
		clearTimeout(iFlyupMenuTimeout);
		iFlyupMenuTimeout = null;
	}
	if (iDelay == 0) {
		FlyupMenuInstantShow(sParent, sLayer, iPosX, iPosY);
	}
	else {
		iFlyupMenuTimeout = setTimeout("FlyupMenuInstantShow('"+sParent+"','"+sLayer+"',"+iPosX+","+iPosY+")",iDelay);
	}
}

function FlyupMenuInstantShow(sParent, sLayer, iPosX, iPosY) {
	// check if already displayed
	for (var i=0; i<asFlyupMenuName.length; ++i) {
		if (asFlyupMenuName[i] == sLayer) { // already visible
			FlyupMenuMaintain(sLayer);
			LayerPosShow(sLayer, iPosX, iPosY);
			return;
		}	
	}
	// not already visible, hide any panels above parent
	for (var i=asFlyupMenuName.length-1; i>=0; --i) {
		if (asFlyupMenuName[i] == sParent) {
			break;
		}
    LayerPosHide(asFlyupMenuName[i],-500,-500);
		asFlyupMenuName.length = i;
	}
	// after previous operation, i+1 represents position to insert
	asFlyupMenuName[i+1] = sLayer;
  LayerPosShow(sLayer,iPosX,iPosY);
  sFlyupName = sLayer;
}

function FlyupMenuHide(sLayer, iDelay) {
	if (iFlyupMenuTimeout != null) {
		clearTimeout(iFlyupMenuTimeout);
		iFlyupMenuTimeout = null;
	}
	if (iDelay == null) {
		iDelay = 200;
	}
	if (iDelay == 0) {
		FlyupMenuInstantHide(sLayer);
	}
	else {
		iFlyupMenuTimeout = setTimeout("FlyupMenuInstantHide('"+sLayer+"')",iDelay);
	}
}

function FlyupMenuInstantHide(sLayer) {
	// find layer in currently displayed list
	for (var i=0; i<asFlyupMenuName.length; ++i) {
		if (asFlyupMenuName[i] == sLayer) { // already visible
			break;
		}
	}
	// hide all panels up from and including this one
	var iNewLength = i;
	for ( ; i<asFlyupMenuName.length; ++i) {
    LayerPosHide(asFlyupMenuName[i],-500,-500);
	}
	asFlyupMenuName.length = iNewLength;
}

function FlyupMenuMaintain(sLayer) {
	if (iFlyupMenuTimeout != null) {
		clearTimeout(iFlyupMenuTimeout);
		iFlyupMenuTimeout = null;
	}
	// find layer in currently displayed list
	for (var i=0; i<asFlyupMenuName.length; ++i) {
		if (asFlyupMenuName[i] == sLayer) { // already visible
			break;
		}
	}
	if (i < asFlyupMenuName.length) {
		++i;
		// hide all panels up from and including this one
		var iNewLength = i;
		for ( ; i<asFlyupMenuName.length; ++i) {
	    LayerPosHide(asFlyupMenuName[i],-500,-500);
		}
		asFlyupMenuName.length = iNewLength;
	}
}


// --- CART SECTION ---------------------------------------

function CartRemove(sFormName, sProductID) {
  document.forms[sFormName].cartaction.value = "remove";
  document.forms[sFormName].cartactionid.value = sProductID;
  document.forms[sFormName].submit();
}

function CartReset(sFormName) {
  document.forms[sFormName].cartaction.value = "reset";
  document.forms[sFormName].submit();
}

function CartUpdate(sFormName) {
  document.forms[sFormName].cartaction.value = "update";
  document.forms[sFormName].submit();
}

function CartCheckout(sFormName) {
  document.forms[sFormName].cartaction.value = "checkout";
  document.forms[sFormName].submit();
}

function CartUpdateView(sFormName, sPageURL) {
  document.forms[sFormName].cartaction.value = "cartview";
  document.forms[sFormName].submit();
}

function CartSinglePurchase(sFormName) {
  document.forms[sFormName].cartaction.value = "singlepurchase";
  document.forms[sFormName].submit();
}

function ActivateProductSelection(oSource) {
	location.href = "default.asp?name=" + oSource.form.productinfopage.value + "&productinfo=" + oSource.form.productinfo.value;
}

// --- LAYER SECTION ---------------------------------------

function oFindLayer(sLayer) {
	if (document.getElementById) {
		return document.getElementById(sLayer);
	}
	if (document.all) {
		return document.all[sLayer];
	}
	return eval("document."+sLayer);
}

function LayerShow(sLayer, iPosX, iPosY) {
	oLayer = oFindLayer(sLayer);
	if (oLayer.style) {
		var oUnits = (typeof oLayer.style.left == "string") ? "px" : 0;
//		oLayer.style.left = iPosX + oUnits;
//		oLayer.style.top = iPosY + oUnits;
		oLayer.style.visibility = "visible";
	}
	else if (document.layers) {
//		oLayer.left = iPosX;
//		oLayer.top = iPosY;
		oLayer.visibility = "show";
	}
}

function LayerHide(sLayer, iPosX, iPosY) {
	oLayer = oFindLayer(sLayer);
	if (oLayer.style) {
		oLayer.style.visibility = "hidden";
//		var oUnits = (typeof oLayer.style.left == "string") ? "px" : 0;
//		oLayer.style.left = iPosX + oUnits;
//		oLayer.style.top = iPosY + oUnits;
	}
	else if (document.layers) {
//		oLayer.left = iPosX;
//		oLayer.top = iPosY;
		oLayer.visibility = "hide";
	}
}

// --- PANEL SECTION ---------------------------------------

var asPanelName = new Array;
var iPanelTimeout = null;

function PanelShow(sParent, sLayer, iPosX, iPosY, iDelay) {
	if (iPanelTimeout != null) {
		clearTimeout(iPanelTimeout);
		iPanelTimeout = null;
	}
	if (iDelay > 0) {
		iPanelTimeout = setTimeout("PanelInstantShow('"+sParent+"','"+sLayer+"',"+iPosX+","+iPosY+")",iDelay);
	}
	else {	
		PanelInstantShow(sParent, sLayer, iPosX, iPosY);
	}
}

function PanelInstantShow(sParent, sLayer, iPosX, iPosY) {
	// check if already displayed
	for (var i=0; i<asPanelName.length; ++i) {
		if (asPanelName[i] == sLayer) { // already visible
			PanelMaintain(sLayer, 0);
			LayerShow(sLayer, iPosX, iPosY);
			return;
		}	
	}
	// not already visible, hide any panels above parent
	for (var i=asPanelName.length-1; i>=0; --i) {
		if (asPanelName[i] == sParent) {
			break;
		}
		LayerHide(asPanelName[i],-500,-500);
		asPanelName.length = i;
	}
	// after previous operation, i+1 represents position to insert
	asPanelName[i+1] = sLayer;
	LayerShow(sLayer,iPosX,iPosY);
}

function PanelHide(sLayer, iDelay) {
	if (iPanelTimeout != null) {
		clearTimeout(iPanelTimeout);
		iPanelTimeout = null;
	}
	if (iDelay > 0) {
		iPanelTimeout = setTimeout("PanelInstantHide('"+sLayer+"')",iDelay);
	}
	else {	
		PanelInstantHide(sLayer);
	}
}

function PanelInstantHide(sLayer) {
	var iIndex = 0;
	if (sLayer != "") {
		while (iIndex < asPanelName.length && asPanelName[iIndex] != sLayer) {
			++iIndex;
		}
	}
	var iNewLength = iIndex;
	while (iIndex < asPanelName.length) {
		LayerHide(asPanelName[iIndex], -500, -500);
		++iIndex;
	}
	asPanelName.length = iNewLength;
}

function PanelMaintain(sLayer, iDelay) {
	if (iPanelTimeout != null) {
		clearTimeout(iPanelTimeout);
		iPanelTimeout = null;
	}
	if (iDelay > 0) {
		iPanelTimeout = setTimeout("PanelInstantMaintain('"+sLayer+"')",iDelay);
	}
	else {
		PanelInstantMaintain(sLayer);
	}
}

function PanelInstantMaintain(sLayer) {
	// find layer in currently displayed list
	for (var i=0; i<asPanelName.length; ++i) {
		if (asPanelName[i] == sLayer) { // already visible
			break;
		}
	}
	if (i < asPanelName.length) {
		++i;
		// hide all panels up from this one
		var iNewLength = i;
		for ( ; i<asPanelName.length; ++i) {
			LayerHide(asPanelName[i], -500, -500);
		}
		asPanelName.length = iNewLength;
	}
}

// --- MENU SECTION ---------------------------------------

var asMenuLevels = [ ];
var oMenuTimeout = null;
var iMenuTimeoutLevel = 0;
var sMenuTimeoutName = "";

function MenuDisplay(sMenuName, bShow) {
	var oLayer = oFindLayer(sMenuName);
	if (oLayer) {
		oLayer.style.display = bShow ? "block" : "none";	
	}
}

function MenuShow(sParentName, sMenuName) {
	if (oMenuTimeout != null) {
		MenuInstantHide(sMenuTimeoutName);
		clearTimeout(oMenuTimeout);
		oMenuTimeout = null;
	}
	// check if already displayed
	for (var i = 0; i < asMenuLevels.length; ++i) {
		if (asMenuLevels[i] == sMenuName) { // already listed as visible
			MenuDisplay(sMenuName, true);
			return;
		}	
	}
	// not already visible, hide any panels above specified parent
	for (var i = asMenuLevels.length - 1; i >= 0; --i) {
		if (asMenuLevels[i] == sParentName) {
			break;
		}
		MenuDisplay(asMenuLevels[i], false);
		asMenuLevels.length = i;
	}
	// after previous operation, i+1 represents position to insert
	asMenuLevels[i+1] = sMenuName;
	MenuDisplay(sMenuName, true);
}

function MenuHide(sMenuName) {
	if (oMenuTimeout != null) {
		MenuInstantHide(sMenuTimeoutName);
		clearTimeout(oMenuTimeout);
		oMenuTimeout = null;
	}
	oMenuTimeout = setTimeout("MenuInstantHide('"+sMenuName+"')", 200);
	sMenuTimeoutName = sMenuName;
}

function MenuInstantHide(sMenuName) {
	// process upwards to ensure that layers are hidden only if specified menu actually exists in current levels
	var iIndex = 0;
	if (sMenuName != "") {
		while (iIndex < asMenuLevels.length && asMenuLevels[iIndex] != sMenuName) {
			++iIndex;
		}
	}
	var iNewLength = iIndex;
	while (iIndex < asMenuLevels.length) {
		MenuDisplay(asMenuLevels[iIndex], false);
		++iIndex;
	}
	asPanelName.length = iNewLength;
}

function MenuMaintain(sMenuName) {
/*	
	if (oMenuTimeout != null) {
		clearTimeout(oMenuTimeout);
		oMenuTimeout = null;
	}
	// find menu in currently displayed list
	for (var i = 0; i < asMenuLevels.length; ++i) {
		if (asMenuLevels[i] == sMenuName) { // already visible
			break;
		}
	}
	if (i < asMenuLevels.length) {
		++i;
		// hide all menus up from this one
		var iNewLength = i;
		for ( ; i < asMenuLevels.length; ++i) {
			MenuDisplay(asMenuLevels[i], false);
		}
		asMenuLevels.length = iNewLength;
	}
*/	
}

// useless-but-apparently-cool Add-To-Favourites function
// note: no method currently known to prevent Firefox adding to sidebar instead

function CreateBookmarkLink(oSource) {
	try {	
		if (window.sidebar) {
			// Firefox favourite
			window.sidebar.addPanel(document.title, document.location.href, "");
			return false;
		}
		else if (window.external) {
			// IE Favorite
			window.external.AddFavorite(document.location.href, document.title);
			return false;
		}
		else if (window.opera && window.print) {
			// Opera Hotlist
			// no need to do anything but allow it to proceed
			return true;
		}
	}
	catch (e) {
		// simply suppress normal error
	}
	alert("Unfortunately your web browser does not support this feature.");
	return false;
}
