//function to send the index to the next page (TOP )
function go(numberofpages) {
	if (trim(document.frmgo.pageindex.value)=="") {
		alert("Please enter the page number you wish to view.")
		document.frmgo.pageindex.focus();
		return false;
	}
	
	//if they enter 0 or negative value
	if (document.frmgo.pageindex.value < 1) {
		alert("Please enter a valid page number you wish to view.")
		document.frmgo.index.focus();
		return false;
	}

	//if they enter a number larger than the number of pages
	var numberofpages= parseInt( numberofpages ); 
	var page=parseInt(frmgo.pageindex.value);
	if (page > numberofpages) {
		alert("Please enter a valid page number you wish to view.")
		document.frmgo.pageindex.focus();
		return false;
	}

	if (document.frmgo.pageindex.value != "") {
		if (!chknumber(document.frmgo.pageindex.value)) {
			alert("Please enter only digits in the page field.");
			document.frmgo.pageindex.focus();
			return false;
		}
	}	
	document.frmgo.submit();
}

//function to send the index to the next page (BOTTOM )
function go1(numberofpages) {
	var result=document.frmgo1.pageindex.value
	if (trim(result)=="") {
		alert("Please enter the page number you wish to view.")
		document.frmgo1.pageindex.focus();
		return false;
	}

	//if they enter 0 or negative value
	if (frmgo1.pageindex.value < 1) {
		alert("Please enter a valid page number you wish to view.")
		document.frmgo1.pageindex.focus();
		return false;
	}

	//if they enter a number larger than the number of pages
	var numberofpages= parseInt( numberofpages ); 
	var index=parseInt(document.frmgo1.pageindex.value);
	if (index > numberofpages) {
		alert("Please enter a valid page number you wish to view.")
		document.frmgo1.pageindex.focus();
		return false;
	}

	if (document.frmgo1.pageindex.value != "") {
		if (!chknumber(document.frmgo1.pageindex.value)) {
			alert("Please enter only digits in the index field.");
			document.frmgo1.pageindex.focus();
			return false;
		}
	}		
	document.frmgo1.submit();
}

//function to validate the fields in contactus page
function validatecontact() {
	//Validating the company/school
	if (trim(document.frmcontact.company.value) == "") {
		alert("Please enter your company/school name.")
		document.frmcontact.company.focus();
		return false;
	}

	if (trim(document.frmcontact.tel.value)==""){
		alert("Please enter your contact number.");
		document.frmcontact.tel.focus();
		return false;
	}

	if (trim(document.frmcontact.tel.value) != "") {
		if (!chknumber(document.frmcontact.tel.value)) {
			alert("Please enter a valid contact number.");
			document.frmcontact.tel.focus();
			return false;
		}
	}

	//Validating the contactperson's email
	if (trim(document.frmcontact.email.value) == "") {
		alert("Please enter your E-mail address.")
		document.frmcontact.email.focus();
		return false;
	}

	if (document.frmcontact.email.value != "") {
		if (!chkmail(document.frmcontact.email.value)) {
			alert("Please enter a valid E-mail address.");
			document.frmcontact.email.focus();
			return false;
		}
	}

	//Validating the subjct
	if (trim(document.frmcontact.subject.value) == "") {
		alert("Please enter your subject.")
		document.frmcontact.subject.focus();
		return false;
	}

	//Validating the message
	if (trim(document.frmcontact.enquiry.value) == "") {
		alert("Please enter your enquiry.")
		document.frmcontact.enquiry.focus();
		return false;
	}

}// validatecontact function

//function to validate the feedback
	function feedbackvalidate() {

		//ensure the name is not empty
		if (trim(document.frmfeedback.name.value) == "") {
			alert("Please enter your Company/School Name.")
			document.frmfeedback.name.focus();
			return false;
		}

		//ensure the email field is not empty
		if (trim(document.frmfeedback.email.value) == "") {
			alert("Please enter your email.")
			document.frmfeedback.email.focus();
			return false;
		}

		if (trim(document.frmfeedback.email.value) != "") {
			if (!chkmail(frmfeedback.email.value)) {
				alert("Please enter a valid email.");
				document.frmfeedback.email.focus();
				return false;
			}
		}

		if (trim(document.frmfeedback.tel.value) != "") {
			if (!chknumber(document.frmfeedback.tel.value)) {
				alert("Please enter a valid contact number.")
				document.frmfeedback.tel.focus();
				return false;
			}
		}

		//ensure the subject field is not empty
		if (trim(document.frmfeedback.subject.value) == "0") {
			alert("Please select a subject header.")
			document.frmfeedback.subject.focus();
			return false;
		}

		//ensure the comments is not empty
		var result=trim(document.frmfeedback.comments.value);
		if (result == "") {
			alert("Please enter your feedback.")
			document.frmfeedback.comments.focus();
			return false;
		}
	}

	//function to validate the advertise
	function advertisevalidate() {

		//ensure the name is not empty
		if (trim(document.frmadvertise.name.value) == "") {
			alert("Please enter your Company/School Name.")
			document.frmadvertise.name.focus();
			return false;
		}

		//ensure the email field is not empty
		if (trim(document.frmadvertise.contactperson.value) == "") {
			alert("Please state the person to contact.")
			document.frmadvertise.contactperson.focus();
			return false;
		}

		if (trim(document.frmadvertise.tel.value)==""){
			alert("Please enter your contact number.");
			document.frmadvertise.tel.focus();
			return false;
		}

		if (trim(document.frmadvertise.tel.value) != "") {
			if (!chknumber(frmadvertise.tel.value)) {
				alert("Please enter a valid contact number.");
				document.frmadvertise.tel.focus();
				return false;
			}
		}

		//ensure the email field is not empty
		if (trim(document.frmadvertise.email.value) == "") {
			alert("Please enter your email.")
			document.frmadvertise.email.focus();
			return false;
		}

		if (trim(document.frmadvertise.email.value) != "") {
			if (!chkmail(frmadvertise.email.value)) {
				alert("Please enter a valid email.");
				document.frmadvertise.email.focus();
				return false;
			}
		}

		if (trim(document.frmadvertise.tel.value) != "") {
			if (!chknumber(frmadvertise.tel.value)) {
				alert("Please enter a valid contact number.")
				document.frmadvertise.tel.focus();
				return false;
			}
		}

		if (trim(document.frmadvertise.contacttime.value) == "") {
			alert("Please state the suitable time for us to contact you.")
			document.frmadvertise.contacttime.focus();
			return false;
		}

	}//advertisevalidate

	//search result by searchcoursename
	function searchcoursenameindex() {
		
		if (trim(document.frmsearch1.search.value)=="") {
			alert("Please select a course to search.");
			document.frmsearch1.search.focus();
			return false;
		}

		var coursename=document.frmsearch1.search.value

		document.frmsearch1.action="results/coursename_results_all.asp?search="+coursename
		document.frmsearch1.submit();

	} // function searchcoursenameindex

	//search result by exambody
	function searchexambodyindex() {
		
		var exambody=document.frmsearch1.exam_body.value

		document.frmsearch1.action="results/exambody_results_all.asp?search="+exambody
		document.frmsearch1.submit();

	} // function searchexambodyindex

	//search result by searchcoursename
	function searchcoursename() {
		
		if (trim(document.frmsearch.search.value)=="") {
			alert("Please select a course to search.");
			document.frmsearch.search.focus();
			return false;
		}

		var coursename=document.frmsearch.search.value

		document.frmsearch.action="../../results/coursename_results_all.asp?search="+coursename
		document.frmsearch.submit();

	} // function searchexambody

	//search result by exambody
	function searchexambody() {
		
		var exambody=document.frmsearch.exam_body.value

		document.frmsearch.action="../../results/exambody_results_all.asp?search="+exambody
		document.frmsearch.submit();

	} // function 

		//search result by searchcoursename
	function searchcoursename1() {
		
		if (trim(document.frmsearch.search.value)=="") {
			alert("Please select a course to search.");
			document.frmsearch.search.focus();
			return false;
		}

		var coursename=document.frmsearch.search.value

		document.frmsearch.action="../results/coursename_results_all.asp?search="+coursename
		document.frmsearch.submit();

	} // function searchexambody

	//search result by exambody
	function searchexambody1() {
		
		var exambody=document.frmsearch.exam_body.value

		document.frmsearch.action="../results/exambody_results_all.asp?search="+exambody
		document.frmsearch.submit();

	} // function 


	//search result by hostels
	function hostelsearch() {
		
		var hostels=document.frmsearch.hostels.value;

		document.frmsearch.action="listings/hostels/hostels.asp?search="+hostels
		document.frmsearch.submit();

	} // function 

		//search result by hostels
	function hostelsearch2() {
		
		var hostels=document.frmsearchhostel.hostels.value

		document.frmsearchhostel.action="../hostels/hostels.asp?search="+hostels
		document.frmsearchhostel.submit();

	} // function 

	//search result by hostels
	function hostelsearch3() {
		
		var hostels=document.frmsearchhostel.hostels.value

		document.frmsearchhostel.action="../listings/hostels/hostels.asp?search="+hostels
		document.frmsearchhostel.submit();

	} // function 

		//search result by hostels
	function hostelsearch1() {
		
		var hostels=document.frmsearch.hostels.value

		document.frmsearch.action="hostels.asp?search="+hostels
		document.frmsearch.submit();

	} // function 


	//function to validate the fields
	function check() {

		//ensure the name is not empty
		if (trim(document.frm.name.value) == "") {
			alert("Please enter your name.")
			document.frm.name.focus();
		return false;
		}

		//ensure the email is not empty
		if (trim(document.frm.senderemail.value) == "") {
			alert("Please enter your e-mail address.")
			document.frm.senderemail.focus();
		return false;
		}

		if (frm.senderemail.value != "") {
			if (!chkmail(document.frm.senderemail.value)) {
				alert("Please enter a valid email.");
				document.frm.senderemail.focus();
				return false;
			}
		}

		//ensure the name is not empty
		if (trim(document.frm.friendname.value) == "") {
			alert("Please enter your friend's name.")
			document.frm.friendname.focus();
			return false;
		}

		//ensure the email field is not empty
		if (trim(document.frm.friendemail.value) == "") {
			alert("Please enter your friend's email.")
			document.frm.friendemail.focus();
			return false;
		}

		if (document.frm.friendemail.value != "") {
			if (!chkmail(document.frm.friendemail.value)) {
				alert("Please enter a valid email.");
				document.frm.friendemail.focus();
				return false;
			}
		}	

		document.frm.submit();
	}
	
	function chksubscribe() {

	if(trim(document.frmsubscribe.ssname.value)=="") {
		alert('Please enter your name.');
		document.frmsubscribe.ssname.focus();
		return false;
	}

	if(trim(document.frmsubscribe.ssemail.value)=="") {
		alert('Please enter your email address.');
		frmsubscribe.ssemail.focus();
		return false;
	}

	if (document.frmsubscribe.ssemail.value != "") {
		if (!chkmail(document.frmsubscribe.ssemail.value)) {
			alert("Please enter a valid email address.");
			document.frmsubscribe.ssemail.focus();
			return false;
		}
	}
	
	return true;
}

function chkask() {

	if(trim(document.frmask.ssname.value)=="") {
		alert('Please enter your name.');
		document.frmask.ssname.focus();
		return false;
	}

	if(trim(document.frmask.ssemail.value)=="") {
		alert('Please enter your email address.');
		document.frmask.ssemail.focus();
		return false;
	}

	if (document.frmask.ssemail.value != "") {
		if (!chkmail(document.frmask.ssemail.value)) {
			alert("Please enter a valid email address.");
			document.frmask.ssemail.focus();
			return false;
		}
	}
	
	var asklength=trim(document.frmask.ssask.value.length);
	if(asklength==0) {
		alert('Please enter your question.');
		document.frmask.ssask.focus();
		return false;
	}


	return true;
}