function addLoadEvent(func) { 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') { 
		window.onload = func; 
	} else { 
		window.onload = function() { 
			oldonload(); 
			func(); 
		}
	} 
}

startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("globalNavigation");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.childNodes.length > 0) {
				for (j=0; j<node.childNodes.length; j++) {
					thisChildNode = node.childNodes[j];
					if (thisChildNode.nodeName=="LI") {
						thisChildNode.onmouseover=function() {
							this.className+=" over";
						}
						thisChildNode.onmouseout=function() {
							this.className=this.className.replace(" over", "");
						}
					}
				}
			}
		}
	}
}
 
addLoadEvent(startList);

function validateForm(whichForm) {
	var boolIsValid = true;
	var strErrorMessage = "";
	//1) check for content with firstname, lastname, address, city, province, postalcode
	//2) if email is supplied, check format
	if (whichForm.firstname.value == "") {
		strErrorMessage += "Please enter your first name.\n";
		boolIsValid = false;
	}
	if (whichForm.lastname.value == "") {
		strErrorMessage += "Please enter your last name.\n";
		boolIsValid = false;
	}
	if (whichForm.company.value == "") {
		strErrorMessage += "Please enter your company.\n";
		boolIsValid = false;
	}
	if (whichForm.address.value == "") {
		strErrorMessage += "Please enter your address.\n";
		boolIsValid = false;
	}
	if (whichForm.city.value == "") {
		strErrorMessage += "Please enter the name of your city.\n";
		boolIsValid = false;
	}
	if (whichForm.province.value == "") {
		strErrorMessage += "Please enter the name of your province.\n";
		boolIsValid = false;
	}
	if (whichForm.postalcode.value == "") {
		strErrorMessage += "Please enter your postal code.\n";
		boolIsValid = false;
	}
	if (!validateEmail(whichForm.email.value)) {
		strErrorMessage += "Please enter a valid email address.\n";
		boolIsValid = false;
	}
	if (!boolIsValid) {
		alert(strErrorMessage);
	}
	return boolIsValid;
}

function submitForm(whichForm) {
	if (validateForm(whichForm)) {
		whichForm.submit();
	}
}

function validateEmail(strValue) {
	//var objRegExp = new RegExp(/(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i);
	var objRegExp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	return objRegExp.test(strValue);
}

function toggleItemVisibility(whichItem, fromWhichLink) {
	if (document.getElementById(whichItem).style.display == "none") {
		document.getElementById(whichItem).style.display = "block";
		fromWhichLink.innerHTML = "Hide";
	} else {
		document.getElementById(whichItem).style.display = "none";
		fromWhichLink.innerHTML = "More";
	}
}

function imagePop(url) {
 	var left = ((screen.width - 600)/2);
 	var top = ((screen.height - 600)/2);
	window.open(url,'main','width=500,height=500,resizable=yes,directories=0,location=0,menubar=0,scrollbars=0,status=0,toolbar=0,top=' + top + ',left=' + left);
}

function showMap(store_id) {
	var left = ((screen.width - 500)/2);
 	var top = ((screen.height - 400)/2);
	window.open('storeMap.cfm?store_id=' + store_id,'map','width=500,height=400,resizable=yes,directories=0,location=0,menubar=0,scrollbars=0,status=0,toolbar=0,top=' + top + ',left=' + left);
}
