// JavaScript Document

//Preload images
function preloadImages() {
	CheckoutOn = new Image(76, 25);
	CheckoutOn.src = "images/nav/checkout_on.gif";
	
	CheckoutOff = new Image(76, 25);
	CheckoutOff.src = "images/nav/checkout_off.gif";
}



function imgOver(imgName) {
	imgOn = eval(imgName + "On.src");
	document.getElementById(imgName).src = imgOn;
}

function imgOff(imgName) {
	imgOff = eval(imgName + "Off.src");
	document.getElementById(imgName).src = imgOff;
}




function menupos(x) {
	p = parseInt(x.offsetWidth) + menu_popout_offset;
	return p;
}

function getLeft(x) {
	y = document.getElementById(x);
	val = 0;
	do {
		val += y.offsetLeft;
		y = y.offsetParent;
	} while (y.offsetParent != null)
	return val;
}

function getTop(x) {
	y = document.getElementById(x);
	val = 0;
	do {
		val += y.offsetTop;
		y = y.offsetParent;
	} while (y.offsetParent != null)
	return val;
}

function Delay(x) {
	p = new Date();
	timenow = p.getTime();
	do {
		
	} while (p.getTime() < (timenow + x))
	alert("done");
	history.go(-1);
}

function myfunction(s) {
	alert(s);
}

function PAED(p, q, topLevel, orientation) {
	setTimeout("positionAndExposeDiv('" + p + "', '" + q + "', '" +  topLevel + "', '" + orientation + "')", 300);
}
function positionAndExposeDiv(p, q, topLevel, orientation) {
	//positions p centrally below q
	if (orientation == "belowcentre") {
		document.all[p].style.left = ( temp = ((getLeft(q) + (document.all[q].offsetWidth/2)) - document.all[p].offsetWidth/2)) < 0 ? 0 : temp;
		document.all[p].style.top = getTop(q) + document.all[q].offsetHeight + parseInt(document.getElementById("menubuffer").vertgap) - ((topLevel == false) ? 20 : 30); //NO IDEA WHY IT IS TOO LOW!
		document.all[p].style.visibility = 'visible';
		
		//if not assignParent, it is the top link - the link is the parent, not the container of the link - otherwise this would get hidden
		if (topLevel == true) {
			document.all[p].firstlevel = "true";
		} else {
			document.all[p].menuparent = document.all[q].id;
		}
	}
}

function HD(x) {
	setTimeout("hideDiv('" + x + "')", 1000);
}
function hideDiv(x) {
//alert(x);
//alert(x.menuchild);
//alert('hideDiv -\n\nThis:' + x + '\nParent: ' + document.all[x].menuparent + '\nChild: ' + document.all[x].menuchild);

	//hide all parents
	document.all[x].style.visibility = 'hidden';
	y = document.all[x];
	while (y.menuparent != null) {
		z = y.menuparent;
		if (document.getElementById(y.menuparent).offsetParent.topdiv != "yes") {
			document.getElementById(z).style.visibility = 'hidden';
		}
		y = document.all[z];
	}
	//hide all children
	y = document.all[x];
	while (y.menuchild != null) {
		z = y.menuchild;
		//alert('z: ' + z);
		document.getElementById(z).style.visibility = 'hidden';
		y = document.all[z];
	}
}

function protectParent(x) {
	document.all[x].style.visibility = 'visible';
}

function makeVisible(x) {

	//alert('MakeVisible -\n\nThis:' + x + '\nParent: ' + document.all[x].menuparent + '\nChild: ' + document.all[x].menuchild);
	//make this one visible
	document.all[x].style.visibility = 'visible';
	
	//make all parents visible
	y = document.all[x];
	while (y.menuparent != null) {
		z = y.menuparent;
		document.getElementById(z).style.visibility = 'visible';
		y = document.all[z];
	}	
}