// JavaScript Document
function doSearch()
{
	searchstring = trimSpaces(document.searchfrm.searchstring.value);
	if(searchstring.length <= 0)
	{
		alert("Please enter a search string.");
		document.searchfrm.searchstring.focus();
		return;
	}
		
	if(document.searchfrm.searchstring.value !="")
	{ 
		var str=document.searchfrm.searchstring.value;
		for (var i=0;i<str.length;i++)
		{
			if (str.substring(i,i+1) == "<"  || str.substring(i,i+1) == ">" || str.substring(i,i+1) == "%" || str.substring(i,i+1) == "~" || str.substring(i,i+1) == "!" || str.substring(i,i+1) == "@" || str.substring(i,i+1) == "#" || str.substring(i,i+1) == "$" || str.substring(i,i+1) == "^" || str.substring(i,i+1) == "&" || str.substring(i,i+1) == "*" || str.substring(i,i+1) == "(" || str.substring(i,i+1) == ")" || str.substring(i,i+1) == "|")
			{
				alert("Enter valid search string");
				document.searchfrm.searchstring.focus();
				return;
			}
			else
			{
				document.searchfrm.submit();
			}
		}
	}
}

function checkGuestbook(){
	guestName = trimSpaces(document.guestbook.guestName.value);
	guestEmail = trimSpaces(document.guestbook.guestEmail.value);
	guestComment = trimSpaces(document.guestbook.guestComment.value);
	
	if(guestName.length <= 0){
		alert("Please enter your name.");
		document.guestbook.guestName.focus();
		return false;
	}
	if(!checkEmail(guestEmail)){
		document.guestbook.guestEmail.focus();
		return false;
	}
	if(guestComment.length <= 0){
		alert("Please enter your valuable comment.");
		document.guestbook.guestComment.focus();
		return false;
	}

	document.guestbook.frmAction.value = "yes";	
}


function checkLogin(){
	username = trimSpaces(document.loginfrm.username.value); 
	password = trimSpaces(document.loginfrm.password.value);
	
	if(username.length <= 0){
		alert("Please specify your username.");
		document.loginfrm.username.focus();
		return;
	}
	if(password.length <= 0){
		alert("Please specify your password.");
		document.loginfrm.password.focus();
		return;
	}
	alert("This functionality is currently not available.");
	document.loginfrm.username.value = "";
	document.loginfrm.password.value = "";
	document.loginfrm.username.focus();
	return;
}

function doReset(){
	document.loginfrm.username.value = "";
	document.loginfrm.password.value = "";
	document.loginfrm.username.focus();
	return;
}

function checkContact()
	{
	contactname = trimSpaces(document.contact.contactname.value);
	if(contactname.length <=0){
		alert("Please enter name.");
		document.contact.contactname.focus();
		return false;
	}
	var regName		=/^[a-zA-Z\s]*$/;
	var regAlphabets		=/^[a-zA-Z]*$/;
	var regAlphaNumericWithSpace = /^[a-zA-Z0-9 /]+$/;
	var regNumbers =  /^[0-9]*$/;
	//var checkEmail	= /^([a-zA-Z0-9_-\.])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(!regName.test(contactname))
	{
		alert("Name Should Accepts only alphabets & space!");
		document.contact.contactname.focus();
		return false;
	}
	email = trimSpaces(document.contact.email.value);
	if(!checkEmail(email)) {
		document.contact.email.focus();
		return false;
	} 
	street = trimSpaces(document.contact.street.value);
	if(street.length <=0){
		alert("Please enter street.");
		document.contact.street.focus();
		return false;
	}
	if(!regAlphaNumericWithSpace.test(street))
	{
		alert("Street Address Should Accepts only alpha-numeric & space!");
		document.contact.street.focus();
		return false;
	}
	city = trimSpaces(document.contact.city.value);
	if(city.length <=0){
		alert("Please enter city.");
		document.contact.city.focus();
		return false;
	}
	if(!regAlphabets.test(city))
	{
		alert("City Should Accepts only alphabets!");
		document.contact.city.focus();
		return false;
	}
	state = trimSpaces(document.contact.state.value);
	if(state.length <=0){
		alert("Please enter state.");
		document.contact.state.focus();
		return false;
	}
	if(!regAlphabets.test(state))
	{
		alert("State Should Accepts only alphabets!");
		document.contact.state.focus();
		return false;
	}
	postal = trimSpaces(document.contact.postal.value);
	if(postal.length <=0){
		alert("Please enter postalcode.");
		document.contact.postal.focus();
		return false;
	}
	if(!regNumbers.test(postal))
	{
		alert("Postal Code Should Accepts only Numbers!");
		document.contact.postal.focus();
		return false;
	}
	country = trimSpaces(document.contact.country.value);
	if(country.length <=0){
		alert("Please enter country.");
		document.contact.country.focus();
		return false;
	}
	if(!regAlphabets.test(country))
	{
		alert("Country Should Accepts only alphabets!");
		document.contact.country.focus();
		return false;
	}
	telephone = trimSpaces(document.contact.telephone.value);
	if(telephone.length <=0){
		alert("Please enter telephone number.");
		document.contact.telephone.focus();
		return false;
	}
	if(!regNumbers.test(telephone))
	{
		alert("Telephone Should Accepts only Numbers!");
		document.contact.telephone.focus();
		return false;
	}
	fax = trimSpaces(document.contact.fax.value);
	if(fax.length <=0){
		alert("Please enter fax number.");
		document.contact.fax.focus();
		return false;
	}
	if(!regNumbers.test(fax))
	{
		alert("Fax Should Accepts only Numbers!");
		document.contact.fax.focus();
		return false;
	}	
	comment = trimSpaces(document.contact.comment.value);
	if(comment.length <=0){
		alert("Please enter comment.");
		document.contact.comment.focus();
		return false;
	}
	if(!regAlphaNumericWithSpace.test(comment))
	{
		alert("Complaints Should Accepts only alpha-numeric & space!");
		document.contact.comment.focus();
		return false;
	}
	document.contact.frmAction.value="yes";
}