function isEmail(strString) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strString)){
		return true;
	}
	return false;
}

function isDate(strString) {
	if (/^([0-3][0-9])\/([0-1][0-9])\/([0-9]{2,4})$/.test(strString)){
		return true;
	}
	return false;
}

function isDateTime(strString) {
	if (/^([0-3][0-9])\/([0-1][0-9])\/([0-9]{2,4}) ([0-2][0-9]):([0-5][0-9])$/.test(strString)){
		return true;
	}
	return false;
}

function isTime(strString) {
	if (/^([0-2][0-9]):([0-5][0-9])$/.test(strString)){
		return true;
	}
	return false;
}

function isText(strString) {
	if (strString.length <1) {
		return false;
	} else {
		return true;
	}
}

function isNumeric(strString) {
   var strValidChars = " 0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;
   for (i = 0; i < strString.length && blnResult == true; i++) {
	  strChar = strString.charAt(i);
	  if (strValidChars.indexOf(strChar) == -1) {
		 blnResult = false;
	  }
   }
   return blnResult;
}

function isPostcode(postcode) {
	
	var test = postcode; 

	size = test.length;
	
	if (size == 0) {
		return true;
	}
	
	test = test.toUpperCase(); //Change to uppercase
	
	while (test.slice(0,1) == " ") //Strip leading spaces
	{
		test = test.substr(1,size-1);
		size = test.length;
	}
	
	while(test.slice(size-1,size)== " ") //Strip trailing spaces
	{
		test = test.substr(0,size-1);
		size = test.length;
	}
	
	//document.find_venue_form.search_postcode.value = test; //write back to form field
	if ((size < 6 || size > 8)
	|| (!(isNaN(test.charAt(0))))
	|| (isNaN(test.charAt(size-3)))
	|| (!(isNaN(test.charAt(size-2))))
	|| (!(isNaN(test.charAt(size-1))))
	|| (!(test.charAt(size-4) == " ")))
	{ //Code length rule
		return false;
	}
	 
	count1 = test.indexOf(" ");
	count2 = test.lastIndexOf(" ");
	if (count1 != count2){//only one space rule
		return false;
	}
	
	return true;

}

function chkForm(form) {

	var errMessage = "";
	
	// check any required fields
	var fieldList = $(form.name).getElementsByClassName('req');

	for (var i = 0, j = fieldList.length; i < j; i++) {
		fieldList[i].removeClassName('checkfield');

		if(thisField = fieldList[i].hasClassName('text')) {
			if(!isText(fieldList[i].value)) {
				errMessage += fieldList[i].title + "\n";
				fieldList[i].addClassName('checkfield');
			}			
		}
		if(thisField = fieldList[i].hasClassName('numeric')) {
			if(!isNumeric(fieldList[i].value)) {
				errMessage += fieldList[i].title + "\n";
				fieldList[i].addClassName('checkfield');
			}
		}
		if(thisField = fieldList[i].hasClassName('email')) {
			if(!isEmail(fieldList[i].value)) {
				errMessage += fieldList[i].title + "\n";
				fieldList[i].addClassName('checkfield');
			}
		}
		if(thisField = fieldList[i].hasClassName('datetime')) {
			if(!isDateTime(fieldList[i].value)) {
				errMessage += fieldList[i].title + "\n";
				fieldList[i].addClassName('checkfield');
			}
		}
		if(thisField = fieldList[i].hasClassName('date')) {
			if(!isDate(fieldList[i].value)) {
				errMessage += fieldList[i].title + "\n";
				fieldList[i].addClassName('checkfield');
			}
		}
		if(thisField = fieldList[i].hasClassName('time')) {
			if(!isTime(fieldList[i].value)) {
				errMessage += fieldList[i].title + "\n";
				fieldList[i].addClassName('checkfield');
			}
		}
		if(thisField = fieldList[i].hasClassName('postcode')) {
			if(!isPostcode(fieldList[i].value)) {
				errMessage += fieldList[i].title + "\n";
				fieldList[i].addClassName('checkfield');
			}
		}
	}

	// check any optional fields
	var fieldList = $(form.name).getElementsByClassName('opt');

	for (var i = 0, j = fieldList.length; i < j; i++) {
		fieldList[i].removeClassName('checkfield');

		if(thisField = fieldList[i].hasClassName('text')) {
			if( (fieldList[i].value != '') && (!isText(fieldList[i].value)) ) {
				errMessage += fieldList[i].title + "\n";
				fieldList[i].addClassName('checkfield');
			}			
		}
		if(thisField = fieldList[i].hasClassName('numeric')) {
			if( (fieldList[i].value != '') && (!isNumeric(fieldList[i].value)) ) {
				errMessage += fieldList[i].title + "\n";
				fieldList[i].addClassName('checkfield');
			}
		}
		if(thisField = fieldList[i].hasClassName('email')) {
			if((fieldList[i].value != '') && (!isEmail(fieldList[i].value))) {
				errMessage += fieldList[i].title + "\n";
				fieldList[i].addClassName('checkfield');
			}
		}
		if(thisField = fieldList[i].hasClassName('datetime')) {
			if((fieldList[i].value != '') && (!isDateTime(fieldList[i].value))) {
				errMessage += fieldList[i].title + "\n";
				fieldList[i].addClassName('checkfield');
			}
		}
		if(thisField = fieldList[i].hasClassName('date')) {
			if((fieldList[i].value != '') && (!isDate(fieldList[i].value))) {
				errMessage += fieldList[i].title + "\n";
				fieldList[i].addClassName('checkfield');
			}
		}
		if(thisField = fieldList[i].hasClassName('time')) {
			if((fieldList[i].value != '') && (!isTime(fieldList[i].value))) {
				errMessage += fieldList[i].title + "\n";
				fieldList[i].addClassName('checkfield');
			}
		}
		if(thisField = fieldList[i].hasClassName('postcode')) {
			if((fieldList[i].value != '') && (!isPostcode(fieldList[i].value))) {
				errMessage += fieldList[i].title + "\n";
				fieldList[i].addClassName('checkfield');
			}
		}
	}
		
	if (errMessage != "") {
		alert(errMessage);
		return false;
	} else {
		return true;
	}

}

function changeHomePageContent(showLayer) {
	
	var elem, elem2, elem3, elem4, elem5, elem6, vis, vis2, vis3, vis4, vis5, vis6;
	
	if( document.getElementById ) {
		// this is the way the standards work
		elem = document.getElementById( showLayer );
		elem1 = document.getElementById( 'homemaincontent1' );
		elem2 = document.getElementById( 'homemaincontent2' );
		elem3 = document.getElementById( 'homemaincontent3' );
		elem4 = document.getElementById( 'homemaincontent4' );
		elem5 = document.getElementById( 'homemaincontent5' );
		elem6 = document.getElementById( 'homemaincontent6' );
	} else if( document.all ) {
		// this is the way old msie versions work
		elem = document.all[showLayer];
		elem1 = document.all['homemaincontent1'];
		elem2 = document.all['homemaincontent2'];
		elem3 = document.all['homemaincontent3'];
		elem4 = document.all['homemaincontent4'];
		elem5 = document.all['homemaincontent5'];
		elem6 = document.all['homemaincontent6'];
	} else if( document.layers ) {
		// this is the way nn4 works
		elem = document.all[showLayer];
		elem1 = document.layers['homemaincontent1'];
		elem2 = document.layers['homemaincontent2'];
		elem3 = document.layers['homemaincontent3'];
		elem4 = document.layers['homemaincontent4'];
		elem5 = document.layers['homemaincontent5'];
		elem6 = document.layers['homemaincontent6'];
	}
	
	vis = elem.style;
	
	vis1 = elem1.style;
	vis2 = elem2.style;
	vis3 = elem3.style;
	vis4 = elem4.style;
	vis5 = elem5.style;
	vis6 = elem6.style;
	
	vis1.display = 'none';
	vis2.display = 'none';
	vis3.display = 'none';
	vis4.display = 'none';
	vis5.display = 'none';
	vis6.display = 'none';
	
	// if the style.display value is blank we try to figure it out here
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
	vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
	vis.display = (vis.display==''||vis.display=='block')?'none':'block';

}

function changeHomePageRightArrow(showLayer) {
	
	var elem, elem2, elem3, elem4, elem5, elem6, vis, vis2, vis3, vis4, vis5, vis6;
	
	if( document.getElementById ) {
		// this is the way the standards work
		elem = document.getElementById( showLayer );
		elem1 = document.getElementById( 'homerightarrow1' );
		elem2 = document.getElementById( 'homerightarrow2' );
		elem3 = document.getElementById( 'homerightarrow3' );
		elem4 = document.getElementById( 'homerightarrow4' );
		elem5 = document.getElementById( 'homerightarrow5' );
		elem6 = document.getElementById( 'homerightarrow6' );
	} else if( document.all ) {
		// this is the way old msie versions work
		elem = document.all[showLayer];
		elem1 = document.all['homerightarrow1'];
		elem2 = document.all['homerightarrow2'];
		elem3 = document.all['homerightarrow3'];
		elem4 = document.all['homerightarrow4'];
		elem5 = document.all['homerightarrow5'];
		elem6 = document.all['homerightarrow6'];
	} else if( document.layers ) {
		// this is the way nn4 works
		elem = document.all[showLayer];
		elem1 = document.layers['homerightarrow1'];
		elem2 = document.layers['homerightarrow2'];
		elem3 = document.layers['homerightarrow3'];
		elem4 = document.layers['homerightarrow4'];
		elem5 = document.layers['homerightarrow5'];
		elem6 = document.layers['homerightarrow6'];
	}
	
	vis = elem.style;
	
	vis1 = elem1.style;
	vis2 = elem2.style;
	vis3 = elem3.style;
	vis4 = elem4.style;
	vis5 = elem5.style;
	vis6 = elem6.style;
	
	vis1.display = 'none';
	vis2.display = 'none';
	vis3.display = 'none';
	vis4.display = 'none';
	vis5.display = 'none';
	vis6.display = 'none';
	
	// if the style.display value is blank we try to figure it out here
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
	vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
	vis.display = (vis.display==''||vis.display=='block')?'none':'block';

}
