// JavaScript Document
function checkContact() {

	visitorName = trimSpaces(document.forms[0].visitorName.value);
	visitorEmail = trimSpaces(document.forms[0].visitorEmail.value);
	visitorPhone = trimSpaces(document.forms[0].visitorPhone.value);
	visitorComments = trimSpaces(document.forms[0].visitorComments.value);
	
	if(visitorName.length <= 0) {
		alert("Please provide your name before submitting the form");
		document.forms[0].visitorName.focus();
		return false;
	}
	
	if(visitorEmail.length <= 0) {
		alert("Please provide your email address before submitting the form");
		document.forms[0].visitorEmail.focus();
		return false;
	}
	
	if(!checkEmail(visitorEmail)) {
		document.forms[0].visitorEmail.focus();
		return false;
	}
	
	if(visitorComments.length <= 0) {
		alert("Please mention your queries or suggestions before submitting the form");
		document.forms[0].visitorComments.focus();
		return false;
	}
	document.forms[0].frmAction.value = "send";
}

function checkNewsletter() {
	newsletter = trimSpaces(document.newsletterform.newsletter.value);
		
	if(newsletter.length <= 0) {
		alert("Please enter your email");
		document.newsletterform.newsletter.focus();
		return false;
	}
	
	if(!checkEmail(newsletter)) {
		document.newsletterform.newsletter.focus();
		return false;
	}
	
}

function checkNewsletterDetails() {
	fname = trimSpaces(document.forms[0].fname.value);
	lname = trimSpaces(document.forms[0].lname.value);
		
	if(fname.length <= 0) {
		alert("Please enter your First name");
		document.forms[0].fname.focus();
		return false;
	}
	if(lname.length <= 0) {
		alert("Please enter your Last name");
		document.forms[0].lname.focus();
		return false;
	}
	document.forms[0].frmAction.value = "send";
}

function checkUser() {
	custUsername = trimSpaces(document.loginform.custUsername.value);
	custPassword = trimSpaces(document.loginform.custPassword.value);
		
	if(custUsername.length <= 0) {
		alert("Please enter your Username");
		document.loginform.custUsername.focus();
		return false;
	}
	if(custPassword.length <= 0) {
		alert("Please enter your Password");
		document.loginform.custPassword.focus();
		return false;
	}
	document.loginform.frmAction.value = "login";
}
function checktellus() {
	senderName = trimSpaces(document.forms[0].uname.value);
	senderEmail = trimSpaces(document.forms[0].umail.value);
	receiverEmail = trimSpaces(document.forms[0].rmail.value);
	receiverName = trimSpaces(document.forms[0].rname.value);
	
	if(senderName.length <= 0) {
		alert("You have to enter your name.");
		document.forms[0].uname.focus();
		return false;
	}
	if(senderEmail.length <= 0) {
		alert("You have to enter your email address.");
		document.forms[0].umail.focus();
		return false;
	}
	if(!checkEmail(senderEmail)) {
		document.forms[0].umail.focus();
		return false;
	}
	
	if(receiverName.length <= 0) {
		alert("You have to enter your friend's name.");
		document.forms[0].rname.focus();
		return false;
	}
	
	if(receiverEmail.length <= 0) {
		alert("You have to enter your friend's email address.");
		document.forms[0].rmail.focus();
		return false;
	}
	if(!checkEmail(receiverEmail)) {
		document.forms[0].rmail.focus();
		return false;
	}
	
	document.forms[0].frmAction.value = "yes";
	document.forms[0].submit();
}

function searchFromHome(page)
{
	if(page == 'home') {
		val = 'php/';
	}else {val = '';}
	searchKey = trimSpaces(document.forms[0].searchKey.value);
	if(searchKey == '') {
		alert("Enter search string");
		document.forms[0].searchKey.focus();
		if(page=='home')
			return false;
		else
    		return false;
	}
	document.forms[0].action = val+"displaySearch.php";
	document.forms[0].submit();
}

function goNext()
{
	page = parseInt(document.form2.page.value) + 1 
	document.form2.page.value = page;
	document.form2.submit();
}
// function to go previous page
function goPrevious()
{
	document.form2.page.value = document.form2.page.value - 1;
	i1=parseInt(document.form2.i1.value);
	i1=i1+5;
	document.form2.i.value = document.form2.i.value - i1;
	document.form2.submit();
}
function searchFromHome(page)
{
	if(page == 'home') {
		val = 'php/';
	}else {val = '';}
	searchKey = trimSpaces(document.searchForm.searchKey.value);
	if(searchKey == '') {
		alert("Enter search string");
		document.searchForm.searchKey.focus();
		if(page=='home')
			return false;
		else
    		return false;
	}
	document.searchForm.action = val+"displaySearch.php";
	document.searchForm.submit();
}
function searchFromHead(page)
{
	if(page == 'home') {
		val = 'php/';
	}else {val = '';}
	searchKey = trimSpaces(document.searchForm1.searchKey.value);
	if(searchKey == '') {
		alert("Enter search string");
		document.searchForm1.searchKey.focus();
		if(page=='home')
			return false;
		else
    		return false;
	}
	document.searchForm.action = val+"displaySearch.php";
	document.searchForm.submit();
}

function checkhomeLogin() {
	cust_username = trimSpaces(document.loginform.cust_username.value);
	cust_password = trimSpaces(document.loginform.cust_password.value);
		
	if(cust_username.length <= 0) {
		alert("Please enter your Username");
		document.loginform.cust_username.focus();
		return false;
	}
	if(cust_password.length <= 0) {
		alert("Please enter your Password");
		document.loginform.cust_password.focus();
		return false;
	}
	document.loginform.frmAction.value = "login";
}

function checkEnquiry() {
	
	name = trimSpaces(document.enquiry.name.value);
	if(name.length <= 0) {
		alert("Please enter your Name.");
		document.enquiry.name.focus();
		return false;
	}
	email = trimSpaces(document.enquiry.email.value);
	if(email.length <= 0) {
		alert("Please enter your E-mail address.");
		document.enquiry.email.focus();
		return false;
	}
	if(email.length > 0){
		if(!checkEmail(email)){
			document.enquiry.email.focus();
			return false;
		}
	}
	resume = trimSpaces(document.enquiry.resume.value);
	if(resume.length <= 0) {
		alert("Please enter your Queries/Suggestions.");
		document.enquiry.resume.focus();
		return false;
	}
	
	document.enquiry.frmAction.value = "send";
}
function checkTerms() {
if (document.termfrm.terms.checked==false)
	{
		alert("Please accept terms and conditions");
		document.termfrm.terms.focus();
		return false;
	}
}