function validateForm()
{
	if(name() && email() && country() && countrycode() && areacode() && phone() && checkmonth() && checkdate() && checkyear()  && validateDate() && adult() && dayinhand() && comment() && verifcode() )
	{
		document.frm1.submit();
	}
	return false;	
}

function  verifcode()
{
	 verifObj = document.getElementById("verif_number");

	if (verifObj.value == "")
	{
		alert("Please Enter Verification Code ?");
		verifObj.focus(); 
		return false;		
	}
	else
	{
		return true;		
	}

}

function name() 
{
//	alert("Rajnish.....");
	var str = document.frm1.name.value;
	
	if (str =="")
	{
		alert("\nThe Name field is blank .\n\nPlease enter your Name");
		document.frm1.name.focus();
		return false;
	}

	if( (str.substring(0,1)<"a" || str.substring(0,1)>"z") && (str.substring(0,1)<"A" || str.substring(0,1)>"Z"))
	{
		alert("The Name should begin with an alphabetic character.");
		document.frm1.name.select();
		document.frm1.name.focus();
		return false;
	}

	for (var i = 1; i < str.length; i++) 
	{
		var ch = str.substring(i, i + 1);
		if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) &&(ch != '')) 
		{
			alert("\nThe Name field  accepts only letters.\n\nPlease re-enter your Name.");
			document.frm1.name.select();
			document.frm1.name.focus();
			return false;
		}

	}

	return true;

}

//Email

function email()

{

var str = document.frm1.email.value;

var str1 = document.frm1.email.value.length;

if(str == "")

	{

		alert("\nThe Email field is blank .\n\nPlease re-enter your Email id.")

		document.frm1.email.focus();

		return false;

	}

if (str.indexOf("@")== -1 || str.indexOf(".")== -1)

{

alert("Please enter the correct E-mail ID");

document.frm1.email.select();

document.frm1.email.focus();

return false;

}

if((str.substring(0,1) == "@" || str.substring(0,1)== ".") || str.substring(0,1)=="-" || str.substring(0,1)=="_")

	{

		alert("The Email ID can not begin with @ or . or - or _ ");

		document.frm1.email.select();

		document.frm1.email.focus();

		return false;

	}

if ((str.substring(str1-1,str1)=="@" || str.substring(str1-1,str1)=="."))

{

		alert("The email ID can not end with @ or . ");

		document.frm1.email.select();

		document.frm1.email.focus();

		return false;

}

var index1 = str.indexOf("@");
var index2 = str.indexOf(".");
var index3=str.indexOf("-");
var index4=str.indexOf("_");
if(str.substring(index1+1,index1+2) =="."){
alert(". can not come immidately after @");
document.frm1.email.select();
document.frm1.email.focus();
return false;
}
if ( ( index3==index1+1) || ( index4==index1+1))
{
alert("please enter the correct email ID as no two special chars can come in sequence");
document.frm1.email.select();
document.frm1.email.focus();
return false;
}
for (var i = 0; i < str.length; i++){
		var ch = str.substring(i, i + 1);
		if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && (ch != '_') && ch !='-' && ch !='@' && ch !='.')
		{
			alert("\nThe email field  accepts letters,numbers & underscore.\n\nPlease re-enter your email id Name.");
			document.frm1.email.select();
			document.frm1.email.focus();
			return false;
		}
	}
	return true;
}
function country(){
//alert("Rajnish....");
//alert(document.frm1.country.value);
if(document.frm1.country.value==""){
 alert("Select country name")
	return false;
	}
	else return true; 
}
function countrycode(){
var str = document.frm1.countrycode.value;
if ( isNaN(str)){ 
alert("Please enter the numeric value in Country code Number field");
document.frm1.countrycode.select();
document.frm1.countrycode.focus();
return false;
}
if (str == ""){
		alert("\nThe Country code Number field is blank .\n\nPlease re-enter your Country code Number.")
		document.frm1.countrycode.focus();
		return false;
	}
	if((str.substring(0,1)<"0" || str.substring(0,1)>"9")){
		alert("The Work Country code should begin with an numeric character.");
		document.frm1.countrycode.focus();
		return false;
		}
		return true; 
}
function areacode(){
var str = document.frm1.areacode.value;
if ( isNaN(str)){ 
alert("Please enter the numeric value in Area code Number field");
document.frm1.areacode.select();
document.frm1.areacode.focus();
return false;
}
if (str == ""){
		alert("\nThe Area code Number field is blank .\n\nPlease re-enter your Area code Number.")
		document.frm1.areacode.focus();
		return false;
	}
	if((str.substring(0,1)<"0" || str.substring(0,1)>"9")){
		alert("The Work Area code should begin with an numeric character.");
		document.frm1.areacode.focus();
		return false;
		}
		return true; 
}
function phone(){
var str = document.frm1.phone.value;
if ( isNaN(str)){ 
alert("Please enter the numeric value in Phone or Mobile Number field");
document.frm1.phone.select();
document.frm1.phone.focus();
return false;
}
if (str == ""){
		alert("\nThe Phone or Mobile Number field is blank .\n\nPlease re-enter your Phone or Mobile Number.")
		document.frm1.phone.focus();
		return false;
	}
	if((str.substring(0,1)<"0" || str.substring(0,1)>"9")){
		alert("The Work phone should begin with an numeric character.");
		document.frm1.phone.focus();
		return false;
		}
		return true; 
}

function checkmonth(){
//alert("Rajnish....");
//alert(document.frm1.country.value);
if(document.frm1.check_month.value==""){
 alert("Select the Check Month from Arrival Date");
  document.frm1.check_month.focus();
	return false;
	}
	else return true; 
}
function checkdate(){
//alert("Rajnish....");
//alert(document.frm1.country.value);
if(document.frm1.check_date.value==""){
 alert("Select the Check Date from Arrival Date");
 document.frm1.check_date.focus();
	return false;
	}
	else return true; 
}
function checkyear(){
//alert("Rajnish....");
//alert(document.frm1.country.value);
if(document.frm1.check_year.value==""){
 alert("Select the Check Year from Arrival Date");
 document.frm1.check_year.focus();
	return false;
	}
	else return true; 
}



function validateIndDate( strValue ) 
{	
  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
 
	if(!objRegExp.test(strValue))
		return false; //doesn't match pattern, bad date
	else
	{
		if(strValue.length < 10)
		{
			return false;
		}
		var strSeparator = strValue.substring(2,3) 
		var arrayDate = strValue.split(strSeparator); 
		var intDay = parseInt(arrayDate[0],10); 

		//create a lookup for months not equal to Feb.
		var arrayLookup = { '01' : 31,'03' : 31, 
							'04' : 30,'05' : 31,
							'06' : 30,'07' : 31,
							'08' : 31,'09' : 30,
							'10' : 31,'11' : 30,'12' : 31}

		// check if month value and day value agree
		if(arrayLookup[arrayDate[1]] != null) 
		{
			if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
			return true; //found in lookup table, good date
		}
    
		var intMonth = parseInt(arrayDate[1],10);

		if (intMonth == 2) 
		{ 
			var intYear = parseInt(arrayDate[2]);
			if (intDay > 0 && intDay < 29) 
			{
				return true;
			}
			else if (intDay == 29) 
			{
				if ((intYear % 4 == 0) && (intYear % 100 != 0) || (intYear % 400 == 0))
				{
					// year div by 4 and ((not div by 100) or div by 400) ->ok
					return true;
				}   
			}
		}
	}
	return false; //any other values, bad date
}


function validateDate()
{
	arrMonth = new Array( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

	currentDate = new Date();
	var arrivalDate;
	// var departureDate;

	var validArrivalDate = false;
	//var validDepartureDate = false;

	var arrmonthObj = document.frm1.check_month;
	var arrdateObj	= document.frm1.check_date;
	var arryearObj	= document.frm1.check_year;

	if(arrmonthObj.value!="" && arrdateObj.value!="" && arryearObj.value!="" )
	{	
		var month;
		var days = arrdateObj.value;
		var year = arryearObj.value;

		for( var i=0; i<12; i++)
		{
			if( arrmonthObj.value == arrMonth[i] )
			{
				if(i<9) { month = "0" + (i+1);	
				} else { month = (i+1);	}
			}
		}

		if(validateIndDate( days + "/" + month + "/" + year) == false)
		{
			alert("Plz select valid arrival date.....");
			validArrivalDate = false;
			arrdateObj.focus();
			return false;
		}
		else
		{
			validArrivalDate = true;
		}

		arrivalDate = new Date( month +"/" + days + "/" + year);

		if(arrivalDate < currentDate)
		{
			alert("Arrival date should be atleast 1 days later than current date... "); 
			return false;
		}

	}
	

	return true;
}
/*

function dd(){
if(document.frm1.dd.value=="")
{
  alert("Select Date ");
  document.frm1.dd.focus();
  return false;
	}
	else return true; 
}
function mm(){
if(document.frm1.mm.value=="")
{
 alert("Select Month ");
 document.frm1.mm.focus();
 return false;
	}
	else return true; 
}
function yyyy(){
if(document.frm1.yyyy.value=="")
{
 alert("Select Year ");
 document.frm1.yyyy.focus();
 return false;
	}
	else return true; 
} */
function adult(){
var str = document.frm1.adult.value;
if ( isNaN(str)){ 
alert("Please enter the numeric value in Adult Number field");
document.frm1.adult.select();
document.frm1.adult.focus();
return false;
}
if (str == ""){
		alert("\nThe Adult Number field is blank .\n\nPlease re-enter your Adult Number.")
		document.frm1.adult.focus();
		return false;
	}
	if((str.substring(0,1)<"0" || str.substring(0,1)>"9")){
		alert("The Work Adult should begin with an numeric character.");
		document.frm1.adult.focus();
		return false;
		}
		return true; 
}

/*function children(){
var str = document.frm1.children.value;
if ( isNaN(str)){ 
alert("Please enter the numeric value in Adult Number field");
document.frm1.children.select();
document.frm1.children.focus();
return false;
}
if (str == ""){
		alert("\nThe Children Number field is blank .\n\nPlease re-enter your Children Number.")
		document.frm1.children.focus();
		return false;
	}
	if((str.substring(0,1)<"0" || str.substring(0,1)>"9")){
		alert("The Work Children should begin with an numeric character.");
		document.frm1.children.focus();
		return false;
		}
		return true; 
} */
function dayinhand(){
var str = document.frm1.dayinhand.value;
if ( isNaN(str)){ 
alert("Please enter the numeric value in Day in hand Number field");
document.frm1.dayinhand.select();
document.frm1.dayinhand.focus();
return false;
}
if (str == ""){
		alert("\nThe Day in hand Number field is blank .\n\nPlease re-enter your Day in hand Number.")
		document.frm1.dayinhand.focus();
		return false;
	}
	if((str.substring(0,1)<"0" || str.substring(0,1)>"9")){
		alert("The Work Day in hand should begin with an numeric character.");
		document.frm1.dayinhand.focus();
		return false;
		}
		return true; 
}
function comment(){
if(document.frm1.comment.value=="")
{
 alert("Please enter Travel Related Comments");
 document.frm1.comment.focus();
   return false;
	}
	else return true; 
}



