function is_Alpha(string) {
  var isAlpha = /^([a-zA-Z]+)$/;
if (string.search(isAlpha)==-1)
		{
		return false;
		}
return true;
}                  
function isEmail(strng) 
{
 var emailFilter=/^.+@.+\..{2,3}$/;
 if (!(emailFilter.test(strng))) 
	{ 
		return false;
	}
	return true;		
}

function isNumber(string) {
		
   if (!string) return false;
   var iChars = "1234567890";

   for (var i = 0; i < string.length; i++) {
      if (iChars.indexOf(string.charAt(i)) == -1)
         return false;
		  
   }
   if(string.length<5 || string.length>=15)
	  return false;
   return true;
   
}      

function isMobile(strng) {
				
   var re10digit=/^\d{10}$/
   if (strng.search(re10digit)==-1)
                {
                return false;
                }
return true;
}

function isMobile2(strng) {
				
   var re10digit=/^\d{10}$/
   if (strng.search(re10digit)==-1)
                {
                return false;
                }
return true;
}
//to check 6 digit pin code

function isPinCode(strng) {
	var re10digit=/^\d{6}$/ 
	
   if (strng.search(re10digit)==-1)
		{
		return false;
		}

return true;
}

function isPerson(strng) {
	var re10digit=/^\d{2}$/ 
	if(strng==0)
  		{
		return false;
		}

return true;
}

function is_Beta(string) {
		
   if (!string) return false;
   var iChars = "*|,\"<:>[]{}`\';()@&$#%1234567890";

   for (var i = 0; i < string.length; i++) {
      if (iChars.indexOf(string.charAt(i)) != -1)
         return false;
		  
   }
   return true;
   
}      

function is_Date(string) {
		
   if (!string) return false;
   var iChars = "*|,\"\<:>[]{}`\.';()@&$#%abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

   for (var i = 0; i < string.length; i++) {
      if (iChars.indexOf(string.charAt(i)) != -1)
         return false;
		  
   }
   return true;
   
}     

function isDuration(string) {
	 if (!string) return false;
   var iChars = "1234567890";

   for (var i = 0; i < string.length; i++) {
      if (iChars.indexOf(string.charAt(i)) == -1)
         return false;
		  
   }
   if(string.length<0 || string.length>=3)
	  return false;
   return true;
}




function isValid(f)
{
var e=document.forms[""+f].elements;
var l=e.length;
var fn=document.forms[""+f];
var errors='';
//alert(document.BookHotel.comment.value);
	for(i=0; i<=l-2; i++)
	{
		if(e[i].value=='' && e[i].id!='' && e[i].title=='Alphanum')	
		{
		errors += '- '+e[i].id+' is Required. \n';
		}
		if(e[i].title=='Beta' && !is_Beta(e[i].value))
		{
		errors += '- '+e[i].id+'- Only alphabets are allowed. \n';
		}
		if(e[i].title=='Alpha' && !is_Alpha(e[i].value))
		{
		errors += '- '+e[i].id+'- Only alphabets without spaces are allowed. \n';
		}
		if(e[i].title=='Alpha2' && e[i].value=='')
		{
		errors += '- '+e[i].id+'- is Required. \n';
		}

		

		if(e[i].title=='Alpha2' && e[i].value.length<3 && e[i].value.length > 0)
		{
		errors += '- '+e[i].id+'- should be greater than two character \n';
			
		}
		
		if(e[i].title=='Mobile' && !isMobile(e[i].value))
		{
		errors += '- '+e[i].id+'- Please enter a valid 10 digit mobile number \n';
		}

		if(e[i].title=='pincode' && !isPinCode(e[i].value))
		{
		errors += '- '+e[i].id+'- Please Enter a 6 Digit Valid Pin Code \n';
		}
		if(e[i].title=='Person' && !isPerson(e[i].value))
		{
			
				errors += '- '+e[i].id+'- Enter number of Persons. \n';
			
		}
		if(e[i].title=='Email' && !isEmail(e[i].value))
		{
		errors += '- '+e[i].id+'-  Enter a valid email address . \n';
		}

		if(e[i].title=='Date' && !is_Date(e[i].value))
		{
		errors += '- '+e[i].id+'-  Enter a Date . \n';
		}

		if(e[i].title=='Duration' && !isDuration(e[i].value))
		{
			
				errors += '- '+e[i].id+'- Enter Duration of stay \n';
			
		}
		
		

	}
	


	/*
	=================================================================
	Credi Card Validaiton start here 
	=================================================================
	*/
	if (f=='BookHotel')
	{
		//alert(document.BookHotel.paymode.value);
		//var cc=fn.card_number.value.substr(0,1)
		//var clen=fn.card_number.value.length;
		//var cvv=fn.card_cvv.value.length;
		//alert(dc);
		/*
		if(!fn.card_type[0].checked && !fn.card_type[1].checked && !fn.card_type[2].checked)
		{
			errors += '- Please Choose a valid card type option \n';
		}
		
		if(document.BookHotel.paymode.value==''){
			errors += '- Please Select Your Payment Mode. \n';
		}

		if(document.BookHotel.paymode.value=='CREDIT CARD'){
			if(cc.indexOf('4')==-1 || clen!=16)
			{
				errors += '- Please Enter a 16 Digit valid Visa Credit Card Number \n';
			}
		}
		
		if(!document.BookHotel.nationachk.checked){
			errors += '- Please Check the Terms & Conditions. \n';
		}*/

	}
	/*
	=================================================================
	End Credi Card Validaiton start here 
	=================================================================
	*/
	if(errors)
	{
	alert('The following error(s) occurred:\n\n'+errors);
	return false
	}
	else
	{
                if (f=='BookHotel'){
                        document.getElementById('continue').disabled=true;
                }
	return true;
	}
}
