<!--
// generic functions for use across main site
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function getPrivacyPolicy(a) {
	var win = window.open("","privacy","scrollbars=yes,width=520,height=420,top=50,left=50"); 
	win.focus();	
}

function getPopup(obj) {
	var href   = obj.href.substring( obj.href.lastIndexOf("/") + 1 );
	var target = obj.target;
	var win = window.open("/File/popup.php?f="+href,target,"scrollbars=yes,width=520,height=420,top=50,left=50"); 
	win.focus();
	return false;
}


function process_frmMiniCourse(frm) {
	var name  = frm.category2.value;
	var email = frm.category3.value;
	if (isEmpty(name) || isEmpty(email) || ! isEmail(email) ) {
		alert("Please enter both:\n- your name and a valid email address");
		return false;		
	}
	return true;
}

function process_frmContact(frm) {
	var errors = new Array();
	if (isEmpty(frm.f_name.value)) { errors.push("Name"); }
	if (isEmpty(frm.f_email.value) || ! isEmail(frm.f_email.value)) { errors.push("Email (a valid address)"); }
	if (isEmpty(frm.f_phone.value)) { errors.push("Telephone No"); }
	if (isEmpty(frm.f_comments.value) || frm.f_comments.value=="Dear Franchise Group,") { errors.push("Comments"); }
	if (isEmpty(frm.f_captcha.value)) { errors.push("Validation image code"); }	
	return frmErrors(errors);
}

function process_frmEnquire(frm) {
	var errors = new Array();
	if (isEmpty(frm.f_fname.value)) { errors.push("First Name"); }
	if (isEmpty(frm.f_lname.value)) { errors.push("Last Name"); }
	if (isEmpty(frm.f_position.value)) { errors.push("Position"); }
	if (isEmpty(frm.f_company.value)) { errors.push("Company Name"); }
	if (isEmpty(frm.f_address.value)) { errors.push("Address"); }
	if (isEmpty(frm.f_city.value)) { errors.push("Town/City"); }
	if (isEmpty(frm.f_postcode.value)) { errors.push("Postcode"); }
	if (isEmpty(frm.f_phone.value)) { errors.push("Telephone"); }
	if (isEmpty(frm.f_mobile.value)) { errors.push("Mobile"); }
	if (isEmpty(frm.f_email.value) || ! isEmail(frm.f_email.value)) { errors.push("Email (a valid address)"); }
	if (isEmpty(frm.f_q1.value)) { errors.push("Question 1"); }
	if (isEmpty(frm.f_q2.value)) { errors.push("Question 2"); }
	if (isEmpty(frm.f_q3.value)) { errors.push("Question 3"); }
	if (isEmpty(frm.f_q4.value)) { errors.push("Question 4"); }
	if (isEmpty(frm.f_q5.value)) { errors.push("Question 5"); }
	if (isEmpty(frm.f_q6.value)) { errors.push("Question 6"); }
	if (getSelectValue(frm.f_q7)=="") { errors.push("Question 7"); }
	if (isEmpty(frm.f_captcha.value)) { errors.push("Validation image code"); }		
	return frmErrors(errors);
}


function frmErrors(errArray) {
	if (errArray.length == 0) { return true; }
	var str = "Please provide the following information:";
	for (i in errArray) { str += "\n - " + errArray[i]; }
	alert(str);
	return false;
}

function isEmpty(str) {
	return (str.trim() == "") ? true : false;
}

function isEmail(str) {
	return (str.match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i)!=null) ? true : false;
}

function getRadioValue(radio_elem) {
	for (i=0; i < radio_elem.length; i++) {
		if (radio_elem[i].checked) { return radio_elem[i].value; }
      }
	return null;
}

function getSelectValue(select_elem) {
	var idx = select_elem.selectedIndex;
	return (idx<0) ? null : select_elem[idx].value;
}

function preLoadImages() {
	if (!document.images) { return; }
	var imgCache = new Array();
	for (i=0; i<arguments.length; i++) {
		imgCache[i] = new Image;
		imgCache[i].src = arguments[i];
	}
}
//-->