
function isEven(n) {
	return( 0 == (n % 2));
}

function trim(str) {
	return str.replace(/^\s+|\s+$/g, '')
};

function isNumeric(str) {
	var validChars = "0123456789";
	var isNumber=true;
	var cchar;
 
	for (i=0; i<str.length; i++) { 
		cchar = str.charAt(i); 
		if (validChars.indexOf(cchar) == -1) {
         isNumber = false;
			break;
		}
	}

	return(isNumber);
}
   
function isEmail(s) {
	var i = 1;
	var sLength = s.length;

	// look for @
	while ((i < sLength) && (s.charAt(i) != "@")) { 
		i++; 
	}

	if ((i >= sLength) || (s.charAt(i) != "@")) {
		return false;
	} else {
		i += 2;
	}

	// look for .
	while ((i < sLength) && (s.charAt(i) != ".")) { 
		i++; 
	}

	// there must be at least one character after the .
	if ((i >= sLength - 1) || (s.charAt(i) != ".")) {
		return false;
	} else {
		return true;
	}
}

function hasValue(val) {
    if (val == null) {
        return(false);
    }

    var s = trim(val);

    if (s == "") {
        return(false);
    }

    return(true);

}

function isBlank(val) {
	return(!hasValue(val));
}

function showRegisterForm(form) {
	var target = "/response.php?action=registerform";
	win = window.open(target, "Register", "toolbar=no,scrollbars=yes,width=400,height=300,resizable");
}

function checkRegistration(form) {
	var email = form.email.value;

	if (!hasValue(email)) {
		alert("Please enter your email address");
		form.email.focus();
		return;
	}

	if (!isEmail(email)) {
		alert("Your email address appears to be invalid, please re-enter it.");
		form.email.focus();
		return;
	}

	form.submit();
}

function memberRegister(form) {

	var account_number = trim(form.account_number.value);
	var fname = trim(form.fname.value);
	var sname = trim(form.sname.value);
	var company_name = trim(form.company_name.value);
	var address1 = trim(form.address1.value);
	var email_1 = trim(form.email_1.value);
	var email_2 = trim(form.email_2.value);
	var countyIndex = form.county.selectedIndex;

	if (account_number.length != 8) {
		alert("Please provide your 8 digit customer account number.");
		form.account_number.focus();
		return;
	}

	if (!isNumeric(account_number)) {
		alert("Your account number appears to be invalid. Note that this must be an 8 digit number.");
		form.account_number.focus();
		return;
	}

	if (fname == "") {
		alert("Please provide your first name.");
		form.fname.focus();
		return;
	}

	if (sname == "") {
		alert("Please provide your surname.");
		form.sname.focus();
		return;
	}

	if (company_name == "") {
		alert("Please provide your company name.");
		form.company_name.focus();
		return;
	}

	if (address1 == "") {
		alert("Please provide your company address.");
		form.address1.focus();
		return;
	}

	if (countyIndex <= 0) {
		alert("Please select your county");
		return;
	}

	if (email_1 == "") {
		alert("Please provide your email address.");
		form.email_1.focus();
		return;
	}

	if (email_2 == "") {
		alert("Please re-enter your email address.");
		form.email_2.focus();
		return;
	}

	if (email_1 != email_2) {
		alert("Note that your email address has been re-entered differently.\nPlease enter the same email address in both fields.");
		form.email_1.focus();
		return;
	}

	if (!isEmail(email_1)) {
		str = "Your address " + email_1 + " does not look like a valid email adddress.\nPlease re-enter your email address.";
		alert(str);
		form.email_1.focus();
		return;
	}

	form.submit();
}

function terms() {
	target = "/terms.html";
	win = window.open(target, "TermsAndConditions", "toolbar=no,scrollbars=yes,width=400,height=450")
}

function size_chart() {
	target = "/size/size.html";
	win = window.open(target, "Size Chart", "toolbar=no,scrollbars=yes,width=400,height=450")
}

function color_chart(id) {
	target = "/color/color.php?id=" + id;
	win = window.open(target, "Color Chart", "toolbar=no,scrollbars=yes,width=400,height=450")
}


// Returns a random positive integer > 0 <= upperBound
function randomInt(upperBound) {
	return( Math.round((Math.random()*upperBound) + 0.5) );
}

function randomBanner() {
	var idx = randomInt(5);
	var imageName = "/images/banner" + idx + ".jpg";
	return("<img alt='Tower Interactive' src='" + imageName + "'/>");
}

function loginhelp() {
	msg = "For assistance logging in, please contact webmaster@tower.ie.\nThank You";
	alert(msg);
}

	function validateAddCart(form) {
		option = form.option.value;
		color = form.color.value;
		
	   if ( option == 'null') {
	      alert("Please select size.");
	      return(false);
	   }
			
	   if ( color == 'null' ) {
	      alert("Please select color.");
	      return(false);
	   }
	

		form.submit();
	}
	
/*function memberLogin(form) {
   email = form.email.value;
   passwd = form.passwd.value;

   if ( ! hasValue(email) ) {
      alert("Please Supply Your Email Address.");
      form.email.focus();
      return(false);
   }

   if (! isEmail(email)) {
      alert("Your email address appears to be invalid, please re-enter it.");
      form.email.focus();
      return(false);
   }

   if ( ! hasValue(passwd) ) {
      alert("Please Supply Your Password.");
      form.passwd.focus();
      return(false);
   }

   form.submit();
}*/

function memberLogin(form) {
   var email = form.email.value;
   var name = form.name.value;

   if ( ! hasValue(name) ) {
      alert("Please Supply Your Name.");
      form.passwd.focus();
      return(false);
   }
   
   if ( ! hasValue(email) ) {
      alert("Please Supply Your Email Address.");
      form.email.focus();
      return(false);
   }

   if (! isEmail(email)) {
      alert("Your email address appears to be invalid, please re-enter it.");
      form.email.focus();
      return(false);
   }

   form.submit();
}

function moveSection(id) {
   target="movesectionform.php?sid=" + id;
   win = window.open(target, "MoveSection", "toolbar=no,scrollbars=yes,width=300,height=250")
}

function deleteSection(id, parent_id, cnt) {
   nonEmptyMsg = "This section contains other subsections.\nYou must delete these before proceeding.";
   confirmMsg = "Are you sure you wish to delete this section?";

   if (cnt > 0) {
      alert(nonEmptyMsg);
      return(false);
   }

   if (confirm(confirmMsg)) {
      target="deletesection.php?sid=" + id + "&parent_id=" + parent_id;
      win = window.open(target, "DeleteSection", "toolbar=no,scrollbars=yes,width=300,height=150")
   }
}

function sectionForm(id) {
   target = "sectionform.php?id=" + id;
   win = window.open(target, "SectionForm", "toolbar=no,scrollbars=yes,width=400,height=250")
}

function addSectionAttachment(form) {
   section_id = form.section_id.value;
   target = "addsectionattachmentform.php?section_id=" + section_id;
   win = window.open(target, "AddAttachment", "toolbar=no,scrollbars=yes,width=400,height=250")
}

function addSectionImage(form) {
   section_id = form.section_id.value;
   target = "addsectionimageform.php?section_id=" + section_id;
   win = window.open(target, "AddImage", "toolbar=no,scrollbars=yes,width=400,height=250")
}

function popup(link) {
	win = window.open(link, "popup")
}

function setColour(id,ON){
	var el = document.getElementById(id);
	if(ON){
		el.style.backgroundColor='#C6CFDC';
	} else {
		el.style.backgroundColor='transparent';
	}
}

function adminLogout() {
	if (confirm("Are you sure you wish to logout?")) {
		location = "logout.php";
	}
}

function checkSignup(form) {
	var signup_name = form.signup_name.value;
	var signup_email = form.signup_email.value;

	if (!hasValue(signup_name)) {
		alert("Please supply your name.");
		form.signup_name.focus();
		return(false);
	}

	if (!hasValue(signup_email)) {
		alert("Please supply your email address.");
		form.signup_email.focus();
		return(false);
	}

	if (!isEmail(signup_email)) {
		alert("Your email address appears not to be valid, please re-enter it.");
		form.signup_email.focus();
		return(false);
	}

	var signup_name_enc = escape(signup_name);
	var signup_email_enc = escape(signup_email);

	var target = "/signup.php?name="+signup_name_enc+"&email="+signup_email_enc;
	var win=window.open(target, "signup", "toolbar=no,scrollbars=yes,width=400,height=300,resizable");
}

function resetPassword(form) {
	var email = form.email.value;

	if (!hasValue(email)) {
		alert("Please enter your email address in order to register with HR.");
		form.email.focus();
		return;
	}

	if (!isEmail(email)) {
		alert("Your email address appears to be invalid, please re-enter it.");
		form.email.focus();
		return;
	}

	var email_enc = escape(email);
	var target = "/response.php?action=pwreset&email="+email_enc;
	var win=window.open(target, "Response", "toolbar=no,scrollbars=yes,width=400,height=300,resizable");
}

function hr_register(form) {
	var email = form.email.value;

	if (!hasValue(email)) {
		alert("Please enter your email address in order to register with HR.");
		form.email.focus();
		return(false);
	}

	if (!isEmail(email)) {
		alert("Your email address appears to be invalid, please re-enter it.");
		form.email.focus();
		return(false);
	}

	var email_enc = escape(email);
	var target = "/response.php?action=hr_register&email="+email_enc;
	var win=window.open(target, "Response", "toolbar=no,scrollbars=yes,width=400,height=300,resizable");
}

function register(form) {
	var email = form.email.value;

	if (!hasValue(email)) {
		alert("Please enter your email address in order to register for notifications.");
		form.email.focus();
		return(false);
	}

	if (!isEmail(email)) {
		alert("Your email address appears to be invalid, please re-enter it.");
		form.email.focus();
		return(false);
	}

	var email_enc = escape(email);
	var target = "/response.php?action=register&email="+email_enc;
	var win=window.open(target, "Response", "toolbar=no,scrollbars=yes,width=400,height=300,resizable");
}

function requestBrochure(form) {
	var email = form.email.value;
	var address = form.address.value;

	if (!hasValue(email)) {
		alert("Please enter your email address.");
		form.email.focus();
		return(false);
	}

	if (!isEmail(email)) {
		alert("Your email address appears to be invalid, please re-enter it.");
		form.email.focus();
		return(false);
	}

	if (!hasValue(address)) {
		alert("Please enter your postal address.");
		form.address.focus();
		return(false);
	}

	var email_enc = escape(email);
	var address_enc = escape(address);

	var target = "/response.php?action=brochure&email="+email_enc+"&address="+address_enc;
	var win=window.open(target, "Response", "toolbar=no,scrollbars=yes,width=400,height=300,resizable");
}

function requestDvd(form) {
	var email = form.email.value;
	var address = form.address.value;

	if (!hasValue(email)) {
		alert("Please enter your email address.");
		form.email.focus();
		return(false);
	}

	if (!isEmail(email)) {
		alert("Your email address appears to be invalid, please re-enter it.");
		form.email.focus();
		return(false);
	}

	if (!hasValue(address)) {
		alert("Please enter your postal address.");
		form.address.focus();
		return(false);
	}

	var email_enc = escape(email);
	var address_enc = escape(address);

	var target = "/response.php?action=dvd&email="+email_enc+"&address="+address_enc;
	var win=window.open(target, "Response", "toolbar=no,scrollbars=yes,width=400,height=300,resizable");
}

function sendContact(form) {
	var cname = form.cname.value;
	var email = form.email.value;
	var comment = form.comment.value;

	if (isBlank(cname)) {
		alert("Please enter your name.");
		form.cname.focus();
		return(false);
	}

	if (isBlank(email)) {
		alert("Please enter your email address.");
		form.email.focus();
		return(false);
	}

	if (!isEmail(email)) {
		alert("Your email address appears to be invalid, please re-enter it.");
		form.email.focus();
		return(false);
	}

	if (isBlank(comment)) {
		alert("Please enter your comments.");
		form.comment.focus();
		return(false);
	}

	form.submit();
}

function sendReservation(form) {
	var cname = form.cname.value;
	var phone = form.phone.value;
	var email = form.email.value;
	var rdate = form.rdate.value;
	var comment = form.comment.value;
	var venueName;


	if (!hasValue(cname)) {
		alert("Please enter your name.");
		form.cname.focus();
		return(false);
	}

	if (!hasValue(email)) {
		alert("Please enter your email address.");
		form.email.focus();
		return(false);
	}

	if (!isEmail(email)) {
		alert("Your email address appears to be invalid, please re-enter it.");
		form.email.focus();
		return(false);
	}

	if (!hasValue(rdate)) {
		alert("Please enter your required date.");
		form.rdate.focus();
		return(false);
	}

	for (i=0; i<form.venue.length; i++) {
		if (form.venue[i].checked) {
			venueName = form.venue[i].value;
		}
	}


	var cname_enc = escape(cname);
	var phone_enc = escape(phone);
	var email_enc = escape(email);
	var comment_enc = escape(comment);
	var venue_enc = escape(venueName);
	var rdate = escape(rdate);

	var target = "/response.php?action=reservation&cname="+cname_enc+"&phone="+phone_enc+"&email="+email_enc+"&phone="+phone_enc+"&venue="+venue_enc+"&rdate="+rdate+"&comment="+comment;

	var win=window.open(target, "Response", "toolbar=no,scrollbars=yes,width=400,height=300,resizable");
}

function sendVoucherForm(form) {
	var cname = form.cname.value;
	var phone = form.phone.value;
	var email = form.email.value;
	var vname = form.vname.value;
	var vvalue = form.vvalue.value;

	var venueName;


	if (!hasValue(cname)) {
		alert("Please enter your name.");
		form.cname.focus();
		return(false);
	}

	if (!hasValue(email)) {
		alert("Please enter your email address.");
		form.email.focus();
		return(false);
	}

	if (!isEmail(email)) {
		alert("Your email address appears to be invalid, please re-enter it.");
		form.email.focus();
		return(false);
	}

	if (!hasValue(vname)) {
		alert("Please enter the name you wish to appear on your voucher.");
		form.vname.focus();
		return(false);
	}

	if (!hasValue(vvalue)) {
		alert("Please enter the value you require for your voucher.");
		form.vname.focus();
		return(false);
	}

	for (i=0; i<form.venue.length; i++) {
		if (form.venue[i].checked) {
			venueName = form.venue[i].value;
		}
	}


	var cname_enc = escape(cname);
	var phone_enc = escape(phone);
	var email_enc = escape(email);
	var vname = escape(vname);
	var vvalue = escape(vvalue);
	var venue_enc = escape(venueName);

	var target = "/response.php?action=voucher&cname="+cname_enc+"&phone="+phone_enc+"&email="+email_enc+"&venue="+venue_enc+"&vname="+vname+"&vvalue="+vvalue;

	var win=window.open(target, "Response", "toolbar=no,scrollbars=yes,width=400,height=300,resizable");
}

function siteSearch(form) {
	var keywords = form.keywords.value;
	var manufacturer = form.manufacturerterm.value;
	var theme = form.themeterm.value;

	if (!hasValue(keywords) && manufacturer == 0 && theme == 0) {
		alert("Please enter a term to search for.");
		form.keywords.focus();
		return(false);
	}

	form.submit();
}

function jobSearch(form) {
	var terms = form.terms.value;

	if (!hasValue(terms)) {
		alert("Please enter a term to search for.");
		form.terms.focus();
		return(false);
	}

	form.submit();
}

function registerProfile(form) {
	var minPasswordLength = 6;

	var pname = form.pname.value;
	var email = form.email.value;
	var password1 = form.password1.value;
	var password2 = form.password2.value;

	if (!hasValue(pname)) {
		alert("Please enter your name");
		form.pname.focus();
		return(false);
	}

	if (!hasValue(email)) {
		alert("Please enter your email address");
		form.email.focus();
		return(false);
	}

	if (!isEmail(email)) {
		alert("Your email address appears to be invalid, please re-enter it.");
		form.email.focus();
		return(false);
	}

	if (!hasValue(password1)) {
		alert("Please enter your password.");
		form.password1.focus();
		return(false);
	}

	if (password1.length < minPasswordLength) {
		alert("Please note, your password must be at least " + minPasswordLength + " characters.\nPlease re-enter your password.");
		form.password1.focus();
		return(false);
	}

	if (!hasValue(password2)) {
		alert("Please confirm your password.");
		form.password2.focus();
		return(false);
	}

	if (password1 != password2) {
		alert("Your passwords do not match, please re-enter your password");
		form.password2.focus();
		return(false);
	}
	
	form.submit();
}

function saveProfile(form) {
	form.submit();
}

function endSurvey() {
    setCookie("session_id", "");
    window.close();
}

function viewSurvey(sid) {
    target = "/survey.php?sid=" + sid;
	win = window.open(target, "Survey", "toolbar=no,scrollbars=yes,width=500,height=350,resizable")
}

function check(form) {
	var can_skip = parseInt(form.can_skip.value);

	if (can_skip > 0) {
		form.submit();
		return(true);
	}

	var option_count=parseInt(form.option_count.value);
	var question_type=parseInt(form.question_type.value);
	var has_answered=0;

	if (option_count > 0) {
		if (question_type == 0) {
			for (var i=0; i<form.answer.length; i++) {
				if (form.answer[i].checked) {
					has_answered = 1;
					break;
				}
			}
		} else {
			for (var i=0; i<option_count; i++) {
				check_option = "answer_" + i;
				if (form.elements[check_option].checked) {
					has_answered = 1;
					break;
				}
			}
		}
	} else {
		var textans = text_answer=form.text_answer.value;
		if ( (textans != null) && (textans.length > 0) ) {
			has_answered = 1;
		}
	}

	if (has_answered == 0) {
		alert("You must supply an answer to this question in order to proceed.");
		return(false);
	} else {
		form.submit();
		return(true);
	}
}







var hasReadTerms = 0;

function readTerms() {
	target = "/terms2.html";
	win = window.open(target, "Terms", "toolbar=no,scrollbars=yes,width=450,height=500")
	hasReadTerms = 1;
}

function product_msg(msg) {
   if (msg.length > 0 ) {
      alert(msg);
   }
}

function setCookie (name, value) { 

	var argv = setCookie.arguments; 
	var argc = setCookie.arguments.length; 
	var expires = (argc > 2) ? argv[2] : null; 
	var path = (argc > 3) ? argv[3] : null; 
	var domain = (argc > 4) ? argv[4] : null; 
	var secure = (argc > 5) ? argv[5] : false; 
	
	document.cookie = name + "=" + escape (value) + 
			((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
			((path == null) ? "" : ("; path=" + path)) + 
			((domain == null) ? "" : ("; domain=" + domain)) + 
			((secure == true) ? "; secure" : "");
}
	
		
function search_gtin13(form) {
    inum = form.iNumber.value;
    inum = inum.replace(" ", "");	// Remove whitespace

    target = "http://www.e-centre.org.uk/database/EPIntl.Gtin13?iNumber=" + inum;
    win = window.open(target, "Members", "toolbar=no,scrollbars=yes,width=450,height=400")
}

function search_gtin8(form) {
   inum = form.iNumber.value;
   inum = inum.replace(" ", "");	// Remove whitespace

   target = "http://www.e-centre.org.uk/database/EPIntl.Gtin8?iNumber=" + inum;
   win = window.open(target, "Members", "toolbar=no,scrollbars=yes,width=450,height=400")
}

function countrysearch(form) {
   var script_loc = "http://www.e-centre.org.uk/database/EPSearch.NameSearch";
   var sCountry = form.sCountry[form.sCountry.selectedIndex].value;
   var sCoName = form.sCoName.value;

   if (sCoName.length < 4) {
      alert("You must enter at least 4 characters for a company name search");
      return(false);
   }

   target = script_loc + "?sCoName="+sCoName+"&sCountry="+sCountry;
   win = window.open(target, "Members", "toolbar=no,scrollbars=yes,width=500,height=400")
}

function paybycheque(id, type) {
   var result = "PN";
   var message = "Cheque+to+be+sent+by+post";
   var pasref = "None"; 
   var authcode = "None"; 
   var timestamp = "Manual"; 
   var txn_type = type; 

   var newloc = "/?action=psresponse&ORDER_ID=" + id + "&RESULT=" + result + "&MESSAGE=" + message + "&PASREF=" + pasref + "&AUTHCODE=" + authcode + "&TIMESTAMP=" + timestamp + "&txn_type=" + txn_type;

   location = newloc;
}

function ean_search(form) {
	keyword = form.keywords.value;
	
	if ( (keyword == null) || (keyword.length == 0) ) {
		alert("Please Enter a Keyword to Search For.");
		form.keywords.focus();
	} else {
		form.submit();
	}
}

    function vfy_membership(form) {

       var len;
       var status;
       var member_num;

       len = form.elements.member_status.length;
       member_num = form.elements.member_number.value;
 
       for (var i = 0; i < len; i++) {
          if ( form.elements.member_status[i].checked) break;
       }

       if (i >= len) {
          alert("Please Select an Option.");
          return(false);
       } else {
          status = form.elements.member_status[i].value;
          if (status == "MEM") {
             if (member_num.length == 0) {
                alert("Please Supply a Membership Number"); 
                form.elements.member_number.focus();
                return(false);
             }
          } else {
             if (member_num.length > 0) {
                alert("If you are a member, please select this option and specify a membership number\nOtherwise, leave the membership number blank.");
                return(false);
             }
          }
       }

       form.submit();
    }

    function vfy_industry_info(form) {
 
       var len = form.elements.sc_pos.length;
       var sector = form.sector.value;
       var product_range = form.product_range.value;
 
       for (var i = 0; i < len; i++) {
          if ( form.elements.sc_pos[i].checked) break;
       }
 
       if ( i >= len) {
           alert("Please Select a Supply Chain Position.");
           return(false);
       }
 
       if ( (sector == null) || (sector.length == 0) ) { 
           alert("Please Describe Your Sector.");
           form.sector.focus();
           return(false);
       }
 
       if ( (product_range == null) || (product_range.length == 0) ) { 
           alert("Please Describe Your Product Range.");
           form.product_range.focus();
           return(false);
       }
 
       form.submit();
    }

    function vfy_cart(form) {
       var maxitems = form.maxitems.value;

       itemcount = 0;
       for (var i=0; i<maxitems; i++) {
          elementname = "qty_" + i;
          prod_elementname = "prod_" + i;
          is_spp_elementname = "is_spp_" + i;

          if (form.elements[elementname].checked) {
             itemId = form.elements[prod_elementname].value;
             is_spp = form.elements[is_spp_elementname].value;

             newlocation = "/?action=sppapplication&item="+itemId;

             if ( is_spp == 1 ) {
                if (form.sppId.value) {
			if (confirm("Your company is already registered as a solution provider.\nAre you sure you wish to proceed?")) {
                           location = newlocation;
                        }
                } else {
                   location = newlocation;
                }

		return;
             }

             itemcount++;
          }
       }

       if (itemcount == 0) {
          alert("Please select an item for purchase.");
          return(false);
       }

       form.submit();
    }


    function vfy_application(form) {
       var fields = new Array("company_name", "street", "city", "phone", "fax", "email", "website", "md", "acc_contact", "acc_phone");
       var field_desc = new Array("Company Name", "Street", "City", "Phone", "Fax", "Email", "Website", "Managing Director", "Accounts Contact", "Accounts Phone");

       for (var i =0; i< fields.length; i++) {
          field_value = form.elements[fields[i]].value;

          if ( (field_value == null) || (field_value.length == 0) ) {
             var warning = "Please Provide a Value For " + field_desc[i];
             alert(warning);
             form.elements[fields[i]].focus();
             return(false);
          }
       } 

       var county_idx = form.county.selectedIndex; 
       if (county_idx < 1) {
          alert("Please Select a County.");
          return(false);
       }

       var email = form.email.value;
       // If the user has provided an email then validate it
       if ( (email != null) && (email.length > 0) ) { 
          if(! isEmail(email)) {
             warning = "Your email address appears to be invalid, please re-enter it.";
             alert(warning);
             form.email.focus();
             return(false);
          }
       }

       form.submit(); 
    }

   function vfy_helpdesk(form) {
      var contactname = form.contactname.value;
      var phone = form.phone.value;
      var email = form.email.value;
      var query = form.query.value;

      if ( (contactname == null) || (contactname.length == 0) ) {
         warning = "Please Provide a Contact Name.";
         alert(warning);
         form.contactname.focus();
         return(false);
      }

      if ( (query == null) || (query.length == 0) ) {
         warning = "Please Provide The Text of Your Query.";
         alert(warning);
         form.query.focus();
         return(false);
      }

      if ( ((phone == null) || (phone.length == 0)) && ((email == null) || (email.length == 0))) { 
         warning = "Please Provide a Phone Number or Email Address.";
         alert(warning);
         form.email.focus();
         return(false);
      }

      // If the user has provided an email then validate it
      if ( (email != null) && (email.length > 0) ) { 
         if(! isEmail(email)) {
            warning = "Your email address appears to be invalid, please re-enter it.";
            alert(warning);
            form.email.focus();
            return(false);
         }
      }

      form.submit();
   }


   function vfy_contact(form) {
      var contactname = form.contactname.value;
      var phone = form.phone.value;
      var email = form.email.value;
      var query = form.query.value;

      if ( (contactname == null) || (contactname.length == 0) ) {
         warning = "Please Provide a Contact Name.";
         alert(warning);
         form.contactname.focus();
         return(false);
      }

      if ( ((phone == null) || (phone.length == 0)) && ((email == null) || (email.length == 0))) { 
         warning = "Please Provide a Phone Number or Email Address.";
         alert(warning);
         form.email.focus();
         return(false);
      }

      // If the user has provided an email then validate it
      if ( (email != null) && (email.length > 0) ) { 
         if(! isEmail(email)) {
            warning = "Your email address appears to be invalid, please re-enter it.";
            alert(warning);
            form.email.focus();
            return(false);
         }
      }
      
      if ( (query == null) || (query.length == 0) ) {
         warning = "Please Provide The Text of Your Query.";
         alert(warning);
         form.query.focus();
         return(false);
      }

      form.submit();
   }

   function vfy_login(form) {
      var login = form.username.value;
      var passwd = form.passwd.value;

      if ( (login == null) || (login.length == 0) ) {
         warning = "Please Provide a Login Name.";
         alert(warning);
         form.login.focus();
         return(false);
      }

      if ( (passwd == null) || (passwd.length == 0) ) {
         warning = "Please Provide A Password.";
         alert(warning);
         form.passwd.focus();
         return(false);
      }

      form.submit();
   }

	function login_prompt() {
		if ("y" == document.retryform.retry.value) {
			alert("Invalid Username or Password. Please try again.");
			document.loginform.login.focus();
		}
	}

   function addMemberContent(mid) {
      target = "/addmbrcontentform.php?mid=" + mid;
      win = window.open(target, "Members", "toolbar=no,scrollbars=yes,width=450,height=500")
    }


   function vfy_registration(form) {
      var fname = form.fname.value;
      var lname = form.lname.value;
      var company_name = form.company_name.value;
      var phone = form.phone.value;
      var email = form.email.value;
      var event_idx = form.event_id.selectedIndex;

      if ( ((fname == null) || (lname.length == 0)) || ((lname == null) || (lname.length == 0)) ) {
         warning = "Please Provide a Contact Name.";
         alert(warning);
         form.fname.focus();
         return(false);
      }

      if ( (company_name == null) || (company_name.length == 0) ) {
         warning = "Please Provide Your Company Name.";
         alert(warning);
         form.company_name.focus();
         return(false);
      }

      if (event_idx <= 0) {
         warning = "Please Select an Event.";
         alert(warning);
         return(false);
      }

      if ( ((phone == null) || (phone.length == 0)) && ((email == null) || (email.length == 0))) { 
         warning = "Please Provide a Phone Number or Email Address.";
         alert(warning);
         form.email.focus();
         return(false);
      }

      // If the user has provided an email then validate it
      if ( (email != null) && (email.length > 0) ) { 
         if(! isEmail(email)) {
            warning = "Your email address appears to be invalid, please re-enter it.";
            alert(warning);
            form.email.focus();
            return(false);
         }
      }

      form.submit();
   }

   function showevent(id) {
      target = "/event.php?eid=" + id;
      win = window.open(target, "Event", "toolbar=no,scrollbars=yes,width=450,height=500")
   }

   function ccpay(form) {
      //alert("We regret that we cannot currently take credit card payments. Please select Pay By Cheque or try again later.");
      //return(false);
		form.submit();
   }

	function attendee_advice(form) {
      var att_idx = form.attendees.selectedIndex;
		if (att_idx > 0) {
			alert("Please provide details of additional attendees in the attendee details box.");
			return(true);
		}
	}

function agree(form) {
	if ( ! form.elements.agree[1].checked) {
		alert("You must read and agree to the above terms before proceeding with your application.");
		return(false);
	}

	if ( form.elements.agree[1].checked) {
		if (hasReadTerms != 1) {
			alert("Please read the terms and conditions before you proceed.");
			return(false);
		}
		form.submit();
	}
}

function add_faq(id) {
	target = "/addfaqform.php?pid=" + id;
	win = window.open(target, "FAQ", "toolbar=no,scrollbars=yes,width=400,height=350,resizable")
}


function reminder(form) {

	var login = form.email.value;

	if (isBlank(login)) {
		alert("Please enter your email address.");
		form.email.focus();
		return(false);
	}

	if (!isEmail(login)) {
		alert("Your email address appears to be invalid, please re-enter it.");
		form.email.focus();
		return(false);
	}

	target = "/resetPassword.php?login="+login;
	win = window.open(target, "ResetPassword", "toolbar=no,scrollbars=yes,width=380,height=300,resizable")
}



function validateMembership(numStr) {
	if (!hasValue(numStr)) {
		return(false);
	}

	if (numStr.length != 6) {
		return(false);
	}

	var sum=0;
	var digit;
	var inc;

	var checkDigit = numStr.charAt(numStr.length-1); // Last digit is a check digit

	// Sum all digits except last 
	for (i=0; i<numStr.length-1; i++) {
		digit = numStr.charAt(i) * 1;	// Convert to number

		if (isEven(i)) {
			inc = 3 * digit;
		} else {
			inc = digit;
		}

		sum += inc;
	}

	var testDigit = (10 - (sum % 10)) % 10;
	//var tstr = "testDigit: " + testDigit + ", Sum: " + sum + ", checkDigit: " + checkDigit;
	//alert(tstr);
	return(testDigit == checkDigit);
}

function showSPP(form) {
	var sid = form.sid.value;
	var sppSectionIdx = form.sppSectionSelection.selectedIndex;
	var sppSectionId = form.sppSectionSelection[sppSectionIdx].value;

	var dest = "/?action=showspp&sid="+sid+"&sppSectionId="+sppSectionId;
	location = dest;
}

function clearform(form) {
	 form.elements["fname"].value = "";
	 form.lname.value = "";
	 form.street_addr.value = "";
	 form.street_addr2.value = "";
	 form.city.value = "";
	 form.zip.value = "";
	 form.phone.value = "";
	 form.fax.value = "";
	 form.email.value = "";
      }

function checkcreateprofile(form){
	var minPasswordLength = 6;
	
	var fname = form.elements["fname"].value;
	var lname = form.elements["lname"].value;
	var street_addr = form.elements["street_addr"].value;
	var city = form.elements["city"].value;
	var email = form.elements["email"].value;
	var country = form.country.options[form.country.selectedIndex].value;
	var county = form.county.options[form.county.selectedIndex].value;
	var zip = form.elements["zip"].value;
	var password1 = form.elements["passwd1"].value;
	var password2 = form.elements["passwd2"].value;

	 if ( !hasValue(fname) ) {
	    alert("Please supply your first name");
			form.fname.focus();
	    return(false);
	 }

	 if ( !hasValue(lname) ) {
	    alert("Please supply your surname");
			form.lname.focus();
	    return(false);
	 }
	 

	    if ( ! hasValue(email) ) {
	       alert("Please supply your email address");
	       form.email.focus();
	       return(false);
	    } else {
	       if (! isEmail(email)) {
		  alert("Your email address appears to be invalid.\nPlease re-enter your email address.");
		  form.email.focus();
		  return(false);
	       }
	    }
	 
	 
	if (!hasValue(password1)) {
		alert("Please enter your password.");
		form.password1.focus();
		return(false);
	}

	if (password1.length < minPasswordLength) {
		alert("Please note, your password must be at least " + minPasswordLength + " characters.\nPlease re-enter your password.");
		form.password1.focus();
		return(false);
	}

	if (!hasValue(password2)) {
		alert("Please confirm your password.");
		form.password2.focus();
		return(false);
	}

	if (password1 != password2) {
		alert("Your passwords do not match, please re-enter your password");
		form.password2.focus();
		return(false);
	}

	 if ( !hasValue(street_addr) ) {
	    alert("Please supply your street address");
			form.street_addr.focus();
	    return(false);
	 }

	 if ( !hasValue(city) ) {
	    alert("Please supply your city");
			form.city.focus();
	    return(false);
	 }

	 // Only check email for billing address

	 if(country == "US"){
		 if (!hasValue(zip) ){
		   alert("Please supply Zip Code");
	       form.zip.focus();
	       return(false);
		 }
	 }
	 if (country == "IE") {
	    if (county == "XX") {
	       msg = "Please select a county.";
	       alert(msg);
		   return(false);
	    } 
	 } else {
	    if (county != "XX") {
	       msg = "The county field applies only to Ireland. Please set this to Not Applicable which appears at the top of the drop down menu.";
	       alert(msg);
		   return(false);
		 }
	 }
	 
	 
	 form.submit();

}
	  
function checkaddr(form) {
	var fname = form.elements["fname"].value;
	var lname = form.elements["lname"].value;
	var street_addr = form.elements["street_addr"].value;
	var city = form.elements["city"].value;
	var email = form.elements["email"].value;
	var country = form.country.options[form.country.selectedIndex].value;
	var county = form.county.options[form.county.selectedIndex].value;
	var state = form.state.options[form.state.selectedIndex].value;
	var zip = form.elements["zip"].value;
	var orderline = form.elements["orderline"].value;

	 if ( !hasValue(fname) ) {
	    alert("Please supply your first name");
			form.fname.focus();
	    return(false);
	 }

	 if ( !hasValue(lname) ) {
	    alert("Please supply your surname");
			form.lname.focus();
	    return(false);
	 }

	 if ( !hasValue(street_addr) ) {
	    alert("Please supply your street address");
			form.street_addr.focus();
	    return(false);
	 }

	 if ( !hasValue(city) ) {
	    alert("Please supply your city");
			form.city.focus();
	    return(false);
	 }

	 // Only check email for billing address
	 if ( (!hasValue(orderline)) || (orderline == "0")) {
	    if ( ! hasValue(email) ) {
	       alert("Please supply your email address");
	       form.email.focus();
	       return(false);
	    } else {
	       if (! isEmail(email)) {
		  alert("Your email address appears to be invalid.\nPlease re-enter your email address.");
		  form.email.focus();
		  return(false);
	       }
	    }
	 }

	 
	 if (country == "IE") {
	    if ((county == "XX") && (state != "XX") ) {
	       msg = "Please select a county\nState field only applies to USA. Please set this to Not Applicable which appears at the top of the drop down menu";
	       alert(msg);
		   form.county.focus();
		   return(false);
	    } 
		
		if (county == "XX") {
	       msg = "Please select a county";
	       alert(msg);
		   form.county.focus();
		   return(false);
	    } 
	 } else {
	    if (county != "XX") {
	       msg = "The county field applies only to Ireland. Please set this to Not Applicable which appears at the top of the drop down menu.";
	       alert(msg);
		   form.county.focus();
		   return(false);
		 }
	 }
	 
	 if (country == "US") {
	    if ( (county != "XX") && (state == "XX")  ) {
	       msg = "Please select state\nCounty field only applies to Ireland. Please set this to Not Applicable which appears at the top of the drop down menu";
	       alert(msg);
		   form.state.focus();
		   return(false);
	    } 
		
		if (state == "XX") {
	       msg = "Please select state";
	       alert(msg);
		   form.state.focus();
		   return(false);
	    } 
		
		 if (!hasValue(zip) ){
		   alert("Please supply Zip Code");
	       form.zip.focus();
	       return(false);
		 }
	 } else {
	    if (state != "XX") {
	       msg = "The state field applies only to USA. Please set this to Not Applicable which appears at the top of the drop down menu.";
	       alert(msg);
		   form.state.focus();
		   return(false);
		 }
	 }
	 
	 
	 form.submit();
	 

}

function checkvoucheraddr(form) {
	var fname = form.elements["fname"].value;
	var lname = form.elements["lname"].value;
	var street_addr = form.elements["street_addr"].value;
	var city = form.elements["city"].value;
	var email = form.elements["email"].value;
	var country = form.country.options[form.country.selectedIndex].value;
	var county = form.county.options[form.county.selectedIndex].value;
	var amount = form.elements["amount"].value;
	// orderline = form.elements["orderline"].value;

	if ( !hasValue(amount) || amount==0) {
	    alert("Please enter Voucher value");
			form.amount.focus();
	    return(false);
	}
	
	if (!isNumeric(amount)){
		alert("Please use only full amounts e.g. 100");
			form.amount.focus();
	    return(false);
	}
	
	 if ( !hasValue(fname) ) {
	    alert("Please supply your first name");
			form.fname.focus();
	    return(false);
	 }

	 if ( !hasValue(lname) ) {
	    alert("Please supply your surname");
			form.lname.focus();
	    return(false);
	 }

	 if ( !hasValue(street_addr) ) {
	    alert("Please supply your street address");
			form.street_addr.focus();
	    return(false);
	 }

	 if ( !hasValue(city) ) {
	    alert("Please supply your city");
			form.city.focus();
	    return(false);
	 }

	 // Only check email for billing address

	    if ( ! hasValue(email) ) {
	       alert("Please supply your email address");
	       form.email.focus();
	       return(false);
	    } else {
	       if (! isEmail(email)) {
		  alert("Your email address appears to be invalid.\nPlease re-enter your email address.");
		  form.email.focus();
		  return(false);
	       }
	    }
	 
	 if (country == "IE") {
	    if (county == "XX") {
	       msg = "Please select a county.";
	       alert(msg);
		   return(false);
	    } 
	 } else {
	    if (county != "XX") {
	       msg = "The county field applies only to Ireland. Please set this to Not Applicable which appears at the top of the drop down menu.";
	       alert(msg);
		   return(false);
	    } 
	 }
	 
	  if(form.recipientcheck.checked){
		var recipfname = form.elements["recipientfname"].value;
		var reciplname = form.elements["recipientlname"].value;
		var recipemail = form.elements["recipientemail"].value;
		
		if ( !hasValue(recipfname) ) {
			alert("Please supply recipient's first name");
			form.recipfname.focus();
	    return(false);
		}

		if ( !hasValue(reciplname) ) {
			alert("Please supply recipient's surname");
			form.reciplname.focus();
	    return(false);
		}
		
		if ( ! hasValue(recipemail) ) {
	       alert("Please supply recipient's email address");
	       form.recipemail.focus();
	       return(false);
	    } else {
	       if (! isEmail(recipemail)) {
		  alert("Recipient's email address appears to be invalid.\nPlease re-enter your email address.");
		  form.recipemail.focus();
		  return(false);
	       }
	    }
	 }
	 
	 form.submit();
}

function checkCreateWeddingList(form) {
	  
	var bridefirstname = form.elements["bridefirstname"].value;
	var groomfirstname = form.elements["groomfirstname"].value;
	var bridesecondname = form.elements["bridesecondname"].value;
	var groomsecondname = form.elements["groomsecondname"].value;
	var date = form.elements["date"].value;
	var pass = form.elements["pass"].value;
	var passguest = form.elements["passguest"].value;


	 if ( !hasValue(bridefirstname) ) {
	    alert("Please supply Bride's first name");
			form.bridefirstname.focus();
	    return(false);
	 }

	 if ( !hasValue(bridesecondname) ) {
	    alert("Please supply Bride's surname");
			form.bridesecondname.focus();
	    return(false);
	 }
	 
	 if ( !hasValue( groomfirstname ) ) {
	    alert("Please supply Groom's first name");
			form.groomfirstname.focus();
	    return(false);
	 }

	 if ( !hasValue(groomsecondname) ) {
	    alert("Please supply Groom's surname");
			form.groomsecondname.focus();
	    return(false);
	 }

	 if ( !hasValue(date) ) {
	    alert("Please supply wedding date");
			form.date.focus();
	    return(false);
	 }
	 
	  if ( !hasValue(passguest) ) {
	    alert("Please supply 1st level password");
			form.passguest.focus();
	    return(false);
	 }

	 if ( !hasValue(pass) ) {
	    alert("Please supply 2nd level password");
			form.pass.focus();
	    return(false);
	 }
	 
	 if(pass == passguest){
		alert("1st and 2nd level passwords can not be the same");
			form.pass.focus();
	    return(false);
	 }
	 

	var street_addr = form.elements["street_addr"].value;
	var city = form.elements["city"].value;
	var email = form.elements["email"].value;
	var country = form.country.options[form.country.selectedIndex].value;
	var county = form.county.options[form.county.selectedIndex].value;
	var zip = form.elements["zip"].value;



	 if ( !hasValue(street_addr) ) {
	    alert("Please supply your street address");
			form.street_addr.focus();
	    return(false);
	 }

	 if ( !hasValue(city) ) {
	    alert("Please supply your city");
			form.city.focus();
	    return(false);
	 }


	  if ( ! hasValue(email) ) {
	       alert("Please supply your email address");
	       form.email.focus();
	       return(false);
	    } else {
	       if (! isEmail(email)) {
		  alert("Your email address appears to be invalid.\nPlease re-enter your email address.");
		  form.email.focus();
		  return(false);
	       }
	    }
	 
	 if(country == "US"){
		 if (!hasValue(zip) ){
		   alert("Please supply Zip Code");
	       form.zip.focus();
	       return(false);
		 }
	 }
	 if (country == "IE") {
	    if (county == "XX") {
	       msg = "Please select a county.";
	       alert(msg);
	    } else {
	       form.submit();
	    }
	 } else {
	    if (county != "XX") {
	       msg = "The county field applies only to Ireland. Please set this to Not Applicable which appears at the top of the drop down menu.";
	       alert(msg);
	    } else {
	       form.submit();
	    }
	 }
	 


}

function checkLoadWeddingList(form) {
	var name = form.elements["name"].value;
	var date = form.elements["date"].value;
	var pass = form.elements["pass"].value;


	 if ( !hasValue(name) ) {
	    alert("Please supply Bride's or Groom's surname");
			form.name.focus();
	    return(false);
	 }


	 if ( !hasValue(date) ) {
	    alert("Please supply wedding date");
			form.date.focus();
	    return(false);
	 }
	 

	 if ( !hasValue(pass) ) {
	    alert("Please supply 1st level password (to view the list)");
			form.pass.focus();
	    return(false);
	 }
	 
	form.submit();

}

function checkSchoolForm(form) {
	var name = form.elements["school_name"].value;
	var address = form.elements["school_address"].value;
	var contact = form.elements["school_contact"].value;
	var phone = form.elements["school_phone"].value;
	var email = form.elements["school_email"].value;
	var county = form.school_county.options[form.school_county.selectedIndex].value;
	var description = form.elements["school_description"].value;


	 if ( !hasValue(name) ) {
	    alert("Please supply school name");
			form.name.focus();
	    return(false);
	 }

	 if ( !hasValue(address) ) {
	    alert("Please supply school address");
			form.address.focus();
	    return(false);
	 }

	 if ( !hasValue(contact) ) {
	    alert("Please supply contact person");
			form.contact.focus();
	    return(false);
	 }

	 if ( !hasValue(phone) ) {
	    alert("Please supply phone number");
			form.phone.focus();
	    return(false);
	 }
	
	if ( ! hasValue(email) ) {
	       alert("Please supply school email address");
	       form.email.focus();
	       return(false);
	    } else {
	       if (! isEmail(email)) {
		  alert("Email address appears to be invalid.\nPlease re-enter your email address.");
		  form.email.focus();
		  return(false);
	       }
	    }
		
	 if ( !hasValue(description) ) {
	    alert("Please provide short description");
			form.description.focus();
	    return(false);
	 }
	 
    if (county == "XX") {
	       msg = "Please select a county.";
	       alert(msg);
		   return(false);
	  } 
	 
	 var checkbox_choices = 0
	 var els = form.elements;
	 for (var i=7,len=els.length; i<len;  i++){
		
		if(els[i].checked)
		{checkbox_choices = checkbox_choices + 1;}
	 }

	 if (checkbox_choices < 1 ){
		alert("Please select at least one school type");
			return (false);
	}
	 
	 form.submit();
	 

}

function checkContactForm(form) {
	var firstname = form.firstname.value;
	var lastname = form.lastname.value;
	var email = form.email.value;
	var comments = form.comments.value;

	if ( !hasValue(firstname) ) {
		alert("Please supply your first name.");
		form.firstname.focus();
		return(false);
	}

	if ( !hasValue(lastname) ) {
		alert("Please supply your last name.");
		form.lastname.focus();
		return(false);
	}


	if ( !hasValue(email) ) {
		alert("Please supply your email address.");
		form.email.focus();
		return(false);
	}

	if (!isEmail(email)) {
		alert("Your email address appears to be invalid, please re-enter it.");
		form.email.focus();
		return(false);
	}

	if ( !hasValue(comments) ) {
		alert("Please supply your comment.");
		form.comments.focus();
		return(false);
	}
	
	form.submit();
	
	return(true);
}

function checkLoadEditWeddingList(form) {
	var name = form.elements["name"].value;
	var pass = form.elements["pass"].value;


	 if ( !hasValue(name) ) {
	    alert("Please supply Bride's or Groom's surname");
			form.name.focus();
	    return(false);
	 }


	 if ( !hasValue(pass) ) {
	    alert("Please supply 2nd level password");
			form.pass.focus();
	    return(false);
	 }
	 
	form.submit();

}

function checkUseVoucher(form) {
	
	
	if(form.elements["voucheramount"].value && form.elements["voucheramountleft"].value){
		
		var voucheramount = form.elements["voucheramount"].value ;
		var billingtotal = form.elements["billingtotal"].value ;
		var voucheramountleft = form.elements["voucheramountleft"].value ;


		if ( voucheramount > voucheramountleft ) {
		    alert("Given value exceeds value left on your Voucher. Max amount you can use from the Voucher value:" + voucheramount + " E" + voucheramountleft);
				form.voucheramount.value = voucheramountleft;
				form.voucheramount.focus();
		    return(false);
		}

		if ( voucheramount > billingtotal ) {
		    alert("Voucher value is bigger than Total billing. Max amount you can use from the Voucher is E" + billingtotal);
				form.voucheramount.value = billingtotal;
				form.voucheramount.focus();
		    return(false);
		}
	}
	form.submit();

}
	  
function checkbirthreminder(form) {
	var name = form.elements["name"].value;
	var email = form.elements["email"].value;
	var date = form.elements["date"].value;



	 if ( !hasValue(name) ) {
	    alert("Please supply your first name");
			form.name.focus();
	    return(false);
	 }

	 if ( ! hasValue(email) ) {
	       alert("Please supply your email address");
	       form.email.focus();
	       return(false);
	    } else {
	       if (! isEmail(email)) {
			  alert("Your email address appears to be invalid.\nPlease re-enter your email address.");
			  form.email.focus();
			  return(false);
			}
		}
	
	 if ( !hasValue(date) ) {
	    alert("Please supply the date");
			form.date.focus();
	    return(false);
	 }

		var checkbox_choices = 0;


			if (form.reminder1.checked)
			{ checkbox_choices = checkbox_choices + 1; }
			if (form.reminder2.checked)
			{ checkbox_choices = checkbox_choices + 1; }
			if (form.reminder3.checked)
			{ checkbox_choices = checkbox_choices + 1; }



		if (checkbox_choices < 1 ){
			alert("Please select at least one Reminder date");
			return (false);
		}


	   form.submit();
	    
	 
}

 function checkCreditCard(form) {
	 var cc1 = trim(form.elements["cc1"].value);
	 var cc2 = trim(form.elements["cc2"].value);
	 var cc3 = trim(form.elements["cc3"].value);
	 var cc4 = trim(form.elements["cc4"].value);

	 var cc = cc1 + cc2 + cc3 + cc4;

	 var cctype = form.cctype.options[form.cctype.selectedIndex].value;
	 var ccname = form.cctype.options[form.cctype.selectedIndex].text;
	 var exp_month = form.exp_month.options[form.exp_month.selectedIndex].value;
	 var exp_year = form.exp_year.options[form.exp_year.selectedIndex].value;

	 var exp_month_text = form.exp_month.options[form.exp_month.selectedIndex].text;
	 var exp_year_text = form.exp_year.options[form.exp_year.selectedIndex].text;
 

	 if (cctype == "xx") {
	    alert("Please select your credit card type");
			form.cctype.focus();
	    return(false);
	 }

	 if (!hasValue(cc)) {
			alert("Please enter your credit card details.");
			form.cc1.focus();
	    return(false);
	 }

	/* if (!isValidCreditCardType(cctype, cc)) {
	    str = "Your credit card details appear not to match.\nPlease check the details below.\n\n";
	    str = str + "Card Type: " + ccname + "\n";
	    str = str + "Expires: " + exp_month + "/" + exp_year + "\n";
	    str = str + "Number: " + cc1 + " " + cc2 + " " + cc3 + " " + cc4 + " ";
	    alert(str);
	    return(false);
	 } */

	 // Submit for payment
	 //var purchaseButton = document.getElementById("purchasebutton");
	 //purchaseButton.value = "Please wait...";
	 //purchaseButton.src = "/images/pleasewait.gif";

	 form.submit();
}

     function isValidCreditCardType(cctype, cc) {
	  return( ((cctype == "VISA") && (isVisa(cc))) || 
		  ((cctype == "LASER") && (isLaser(cc))) || 
		  ((cctype == "MC") && (isMC(cc)))
		);
       }

 function isCreditCard(cc) {
   
	 // Encoding only works on cards with less than 19 digits
	 if (cc.length > 19)
	   return (false);
       
	 sum = 0; 
	 mul = 1; 
	 l = cc.length;
	 for (i = 0; i < l; i++) {
	   digit = cc.substring(l-i-1,l-i);
	   tproduct = parseInt(digit, 10) * mul;
       
	   if (tproduct >= 10) {
	     sum += (tproduct % 10) + 1;
	   } else {
	     sum += tproduct;
	   }
       
	   if (mul == 1) {
	     mul++;
	   } else {
	     mul--;
	   }
	 }
       
	 if ((sum % 10) == 0) {
	   return (true);
	 } else {
	   return (false);
	 }
       } 

       function isVisa(cc) {
	 if (((cc.length == 16) || (cc.length == 13)) && (cc.substring(0,1) == 4))
	   return isCreditCard(cc);
	 return false;
       }  
      
       function isMC(cc) {
	 firstdig = cc.substring(0,1);
	 seconddig = cc.substring(1,2);
	 if ((cc.length == 16) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5)))
	   return isCreditCard(cc);
	 return false;
       
       } 
       
       function isAmex(cc) {
	 firstdig = cc.substring(0,1);
	 seconddig = cc.substring(1,2);
	 if ((cc.length == 15) && (firstdig == 3) && ((seconddig == 4) || (seconddig == 7)))
	   return isCreditCard(cc);
	 return false;
       } 

       function isLaser(cc) {
          return(true);
       }
	   
function autoTab(elem, maxLength, nextElem, event) {
	var entry = elem.value;

	if (isBlank(entry)) {
		return(false);
	}

	if (event.keyCode == 9 || event.keyCode == 16) {
		/* Ignore tabs */
		return(false);
	}

	if (entry.length == maxLength) {
		nextElem.focus();
	}
}

function getschool(county, form) {
	// Get the checked school type
	for (var i = 0; i < form.schooltype.length; i++) {   
		if (form.schooltype[i].checked) { 
			break 
		}
	}
	type = form.schooltype[i].value;

	target = "/school/" + county + "/" + type;
	location = target;
}

function checkCountry(){
	var option = document.getElementById("country");
	var county_div = document.getElementById("county_div");
	
	if(option.value == "US"){
		county_div.style.display = 'none';
	} else {
		county_div.style.display = 'block';
	}
	

}
	   