function changeurl(whereTo){
	parent.location.href=whereTo;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
$(document).ready(function() {
	$(".topMenuAction").click( function() {
		if ($("#openCloseIdentifier").is(":hidden")) {
			$("#slider").animate({ 
				marginTop: "-166px"
				}, 500 );
			$("#topMenuImage").html('<img src="images/panel_button_down.jpg"  />');
			$("#openCloseIdentifier").show();
		} else {
			$("#slider").animate({ 
				marginTop: "0px"
				}, 500 );
			$("#topMenuImage").html('<img src="images/panel_button.jpg"  />');
			$("#openCloseIdentifier").hide();
		}
	});
	
});


function IsValidEmail(email) {
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}


function IsNumeric(sText) {
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
	for (i=1; i < sText.length && IsNumber == true; i=i+2) { 
		Char = sText.charAt(i); 
		
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}
function IsAlpha(sText) {
	var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	var IsAlpha=true;
	var Char;
	for (i=0; i < sText.length && IsAlpha == true; i=i+2) { 
		Char = sText.charAt(i); 
		
		if (ValidChars.indexOf(Char) == -1) {
			IsAlpha = false;
		}
	}
	return IsAlpha;
}

function validate(theForm) {
		if (theForm.firstname.value == ""){
			alert("Please enter your First Name.");
			theForm.firstname.focus();
			return (false);
		}
		if (theForm.lastname.value == ""){
			alert("Please enter your Last Name.");
			theForm.lastname.focus();
			return (false);
		}
		if (theForm.emailaddress.value == ""){
			alert("Please enter your Email Address.");
			theForm.emailaddress.focus();
			return (false);
		}
		
		if (theForm.emailaddress.value < 6 || !IsValidEmail(theForm.emailaddress.value)){
			alert("Please enter a valid E-mail Address.");
			theForm.emailaddress.focus();
			return (false);
		}
		if (theForm.telephone.value == ""){
			alert("Please enter the Telephone Number.");
			theForm.telephone.focus();
			return (false);
		}
		if (theForm.telephone.value.length != 10){
			alert("Please enter the 10-digit Telephone Number.");
			theForm.telephone.focus();
			return (false);
		}
		if (theForm.streetaddress.value == ""){
			alert("Please enter the Street Address.");
			theForm.streetaddress.focus();
			return (false);
		}
		if (theForm.city.value == ""){
			alert("Please enter the City.");
			theForm.city.focus();
			return (false);
		}
		if (theForm.province.selectedIndex < 1){
			alert("Please select your Province.");
			theForm.province.focus();
			return (false);
		}
		if (theForm.postalcode.value == ""){
			alert("Please enter the Postal Code.");
			theForm.postalcode.focus();
			return (false);
		}
		if (theForm.postalcode.value.length != 6){
			alert("Please enter the correct Postal Code without any spaces or hyphens.");
			theForm.postalcode.focus();
			return (false);
		} else {
			if (!IsNumeric(theForm.postalcode.value) || !IsAlpha(theForm.postalcode.value)) {
				alert("Please enter the correct Postal Code without any spaces or hyphens.");
				theForm.postalcode.focus();
				return (false);
			}
		}
		if (theForm.CCType.selectedIndex < 1){
			alert("Please select your Credit Card Type.");
			theForm.CCType.focus();
			return (false);
		}
		if (theForm.CCNumber.value.length < 15){
			alert("Please enter a valid Credit Card Number.");
			theForm.CCNumber.focus();
			return (false);
		}
		if (theForm.CCMonth.selectedIndex < 1){
			alert("Please select the Expiry Month.");
			theForm.CCMonth.focus();
			return (false);
		}
		if (theForm.CCYear.selectedIndex < 1){
			alert("Please select the Expiry Year.");
			theForm.CCMonth.focus();
			return (false);
		}
		if (theForm.Agreement.selectedIndex < 1){
			alert("You must read and agree to the Order/Delivery Policy before continuing the order process.");
			theForm.Agreement.focus();
			return (false);
		}
		return (true);
}