function clearDefault(el) {
	if (el.defaultValue==el.value) el.value = ""
}

function restoreDefault(el) {
	if (el.value=="") el.value = el.defaultValue
}

var numbers = "0123456789";
var letters = "abcdefghijklomnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

function verifyFormObjects() {
	frm = document["ordertrackingform"]
	errorMessage="The following essential form fields are missing.(Please note form fieldnames must be all lowercase.)\n\n";
	validData=true;
	if(!frm["email"]) {
		errorMessage+="email\n";
		validData=false;
	}
	if(!frm["reference"]) {
		errorMessage+="reference\n";
		validData=false;
	}
	if(!frm["type"]) {
		errorMessage+="type\n";
		validData=false;
	}
	if(!frm["campaign"]) {
		errorMessage+="campaign\n";
		validData=false;
	}
	if(!validData)
		alert(errorMessage)
}

function validate(frm) {
	validData = true;
	errorMessage="There were errors found with the data you have entered : \n\n"
	if(frm["email"]) {
		if(!checkEmail(frm["email"]))
		{	errorMessage+="The email address you have entered is invalid, it must be of the format myname@myaddress.co.uk.\n";
			validData=false;
		}
	}
	if(frm["reference"]) {
		reference = frm["reference"].value	
		// CHANGED LENGTH TO 8 TO ACCOMODATE 8 DIGIT REFERENCE NUMBERS ''' JEMAYNE 02/03/05
		if(!checkChars(reference,numbers)||!(reference.length==8||reference.length==7))
		{	errorMessage+="The reference number you have entered is invalid, it must be at least seven numeric digits long.\n";
			validData=false;
		}
	}
	
	if(!validData) {
		alert(errorMessage);
		return false;
	}
	else
		return true;
}

function checkEmail(fld) {
	testStr = fld.value

	if(!checkChars(testStr,letters+numbers+"@.-_")||testStr.length<5||testStr.indexOf("@")<0||testStr.indexOf(".")<0) {
		return false;
	}
	return true;
}

//functions to check all chars in first string are in second string
// eg to check first string is all numbers
function checkChars(str,validChars) {
	if(str!=null) {
		for(var i=0;i<str.length;i++) {
			if(!checkChar(str.charAt(i),validChars))
				return false;
		}
	}
	return true;
}

//function to check if a character is within a string of characters
function checkChar(ch,validChars) {	
	if(validChars.indexOf(ch)<0)
		return false;
	else
		return true;
}

function popup_venue() {window.open("","venue_box","top=5,left=5,toolbar=no,width=790,height=540,resizable=yes,scrollbars=yes,status=no");}
function popup_event() {window.open("","event_box","top=20,left=20,toolbar=no,width=710,height=460,resizable=yes,scrollbars=yes,status=no");}
function popup_email() {window.open("","event_box","top=20,left=20,toolbar=no,width=422,height=485,resizable=yes,scrollbars=yes,status=no");}
function popup2() {window.open("","mobile","toolbar=no,width=600,height=420,resizable=no,scrollbars=yes,status=no")}
function socbook() {window.open("","socbook","top=50,left=150,toolbar=no,width=700,height=420,resizable=yes,scrollbars=yes,status=no")}