
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid email")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid email")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid email")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid email")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid email")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid email")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid email")
		    return false
		 }

 		 return true					
	}

 		
// this function checks the entire form		
	function ValidateForm(){
		var emailID=document.contactform.email
		var fullName=document.contactform.fullname
		
		if ((fullName.value==null)||(fullName.value=="")){
							alert("Please enter your full name")
							fullName.focus()
							return false
		}
		if ((emailID.value==null)||(emailID.value=="")){
			alert("Please enter your email")
			emailID.focus()
			return false
		}
		if (echeck(emailID.value)==false){
			emailID.value=""
			emailID.focus()
			return false
		}
		return true
	 }
	 

// JavaScript on/off script 
	 function revealContactName() {
		 //This will exit the function if JS not fully supported
		 if (!document.getElementById) return false;

		 //This will exit the function if the two required DIV's are not on the page
		 if (!document.getElementById("contact_name_display_No")) return false;
		 if (!document.getElementById("contact_name_display_Yes")) return false;

		 //Find & hold the targetted DIVs
		 var contactNameHide = document.getElementById("contact_name_display_No");
		 var contactNameShow = document.getElementById("contact_name_display_Yes");

		 //The magic (not really)
		 contactNameHide.style.display = 'none';
		 contactNameShow.style.display = 'inline';
}
window.onload = revealContactName;

	
// this function retrieves the contact name
function getContactName() {

	var contactName = getParm('contact_name');
	
	var contactField = document.getElementById('contact_name_field');
	contactField.value = contactName;
	var contactDiv = document.getElementById('contact_name_display');
	contactDiv.innerHTML = contactName;	
} 



function getParm(paramName) {

	var idx1, idx2;
	var qs;

	qs = location.search;
	idx1 = qs.indexOf(paramName + '=');
	if (idx1 != -1) {
		idx1 += paramName.length + 1;
		idx2 = qs.indexOf('&', idx1);
		if (idx2 == -1) idx2 = qs.length;
	}

	return unescape(qs.substring(idx1, idx2));

}

function runSearch(){

	var Srch=document.search.Query.value;
	
	if(Srch==0){ 
		alert("Please enter a word or phrase into the search box.");}
	else {
		self.location.href='/uk/ghrs/rewardt/rewardtimes.nsf/SearchView?SearchView&Query=' + Srch
	}
}

