/* -------------------------------------------------------------------
Filename : jscript.js
Title : Primary JavaScript file for Namxan River Tours Website
Author : Aloundeth Panekham
URL : http://www.namxanrivertours.com
License : Copyright 2007, , All Rights Reserved.
Description : This base JavaScript provides basic functions for form elements validate for the Namxan River Tours website.
----------------------------------------------------------------------- */

var invalids="/:,;!~$";			//lists the characters that shouldn't be included 

function isValid(string){
	for(var i=0; i<string.length; i++){
	  if(invalids.indexOf(string.charAt(i)) != -1)
		return false;
	}
	return true;
}
function validateBookingFm(){

	var errmsg = "";
	
	// Check check-in date
	var tmpname = document.booking.bname.value;
	if(tmpname=="") errmsg += "Please provide your name\n";
	if(!isValid(tmpname)) errmsg += "\"" + invalids + "\" characters are invalid for name";
	// Check email
	var tmpemail=document.booking.bemail.value;
	if (tmpemail=="") errmsg += "Please provide your email address\n";
	if(!isValid(tmpemail)) errmsg += "The email you provided is not in valid format\n";
	if(tmpemail.indexOf("@") == -1) errmsg += "The valid email format is name@domain.ext \n";
	if(tmpemail.indexOf(".") == -1) ;
	//Country
	var tmpcountry = document.booking.bcountry.value;
	if(tmpcountry=="") errmsg += "Please provide your Country Name\n";
	if(!isValid(tmpcountry)) errmsg += "\"" + invalids + "\" characters are invalid for Country Name";
	// Check message
	var tmpcode = document.booking.bcode.value;
	if(tmpcode=="") errmsg += "Please provide the valid package code of your inquiry\n";
	
	var tmparrDate = document.booking.barrDate.value;
	if(tmparrDate=="") errmsg += "Please provide the valid arrival date of your inquiry\n";
	
	var tmparrMonth = document.booking.barrMonth.value;
	if(tmparrMonth=="") errmsg += "Please provide the valid arrival month of your inquiry\n";
	
	var tmparrYear = document.booking.barrYear.value;
	if(tmparrYear=="") errmsg += "Please provide the valid arrival year of your inquiry\n";
	
	var tmpdepartDate = document.booking.bdepartDate.value;
	if(tmpdepartDate=="") errmsg += "Please provide the valid departure date of your inquiry\n";
	
	var tmpdepartMonth = document.booking.bdepartMonth.value;
	if(tmpdepartMonth=="") errmsg += "Please provide the valid departure month of your inquiry\n";
	
	var tmpdepartYear = document.booking.bdepartYear.value;
	if(tmpdepartYear=="") errmsg += "Please provide the valid departure year of your inquiry\n";
	
	var tmppax = document.booking.bpaxNo.value;
	if(tmppax=="") errmsg += "Please provide the Pax Number of your inquiry\n";
	
	// Display error message if any	
	if(errmsg!=""){
		alert(errmsg);
		return false;
	}else{
		document.booking.submit();
	}
}

function validateContactFm(){

	var errmsg = "";
	
	// Check Name
	var tmpname = document.contact_form.contact_name.value;
	if(tmpname=="") errmsg += "Please provide your name\n";
	if(!isValid(tmpname)) errmsg += "\"" + invalids + "\" characters are invalid for name";
	// Check email
	var tmpemail = document.contact_form.contact_email.value;
	if (tmpemail=="") errmsg += "Please provide your email address\n";
	if(!isValid(tmpemail)) errmsg += "The email you provided is not in valid format\n";
	if(tmpemail.indexOf("@") == -1) errmsg += "The valid email format is name@domain.ext \n";
	if(tmpemail.indexOf(".") == -1);
	// Check message
	var tmpmessage = document.contact_form.contact_message.value;
	if(tmpmessage=="") errmsg += "Please provide your message or comment\n";
	
	// Display error message if any	
	if(errmsg!=""){
		alert(errmsg);
		return false;
	}else{
		document.contact_form.submit();
	}
}


function resetBookingFm(){
	document.booking.reset();
}