


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(strng) {
	var re10digit=/^\d{10}$/ 
   if (strng.search(re10digit)==-1)
		{
		return false;
		}
return true;
}

function isMobile(strng) {
				
   //if(strng='')return false
   var re10digit=/^\d{10}$/
   if (strng.search(re10digit)==-1)
                {
                return false;
                }
return true;
}
// Removes leading whitespaces
function trim(inputString) {
   
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   
   return retValue;
  
   // Return the trimmed string back to the user
} // Ends the "trim" function


//to check 6 digit pin code

function isPinCode(strng) {
	var re10digit=/^\d{5}$/ 
	
   if (strng.search(re10digit)==-1)
		{
		return false;
		}

return true;
}

/* Added  for BUG#1019   */

function is_Add(string) {
		
   if (!string) return false;
   var iChars = "*^~%<>";

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

function is_Add2(string) {
		
   
   var iChars = "*^~%<>";

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

/* Added  for BUG#1019   */



function isLandline(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 isDigit(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>=10)
	  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 isValid(f,ptype)
{
var e=document.forms[""+f].elements;
var l=e.length;
var fn=document.forms[""+f];
var errors='';


	/* phone number validation end here */
	if (f=='contactForm')
	{
			//alert('hi');
			if(document.contactForm.contact_mobile.title=='Mobile' && !isMobile(document.contactForm.contact_mobile.value))
			//if(document.contactForm.mobile2.title=='Mobile' && !isDigit(document.contactForm.mobile2.value))
			{
					//alert('hi2');
				errors += '- '+document.contactForm.contact_mobile.id+'- Please enter your valid cell number \n';
			}
			
			if(document.contactForm.contact_phone.title=='phone_home' && !isLandline(document.contactForm.contact_phone.value)) 
				{
				//alert('hi4');
				errors += '- '+document.contactForm.contact_phone.id+'- Please Enter a Valid Home Phone Number   \n';
				}
		
	}
	/* phone number validation end here */


	
	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';
		}

		/* Added  for BUG#1019 start  */
		if(trim(e[i].value)=='' && e[i].id!='' && e[i].title=='AlphanumAdd')	
		{
		errors += '- '+e[i].id+' is Required. \n';
		}
		if(e[i].value!=''){
		if(e[i].title=='AlphanumAdd' && !is_Add(e[i].value))
		{
		errors += '- '+e[i].id+'- Following special characters *^~%<> are not allowed. \n';
		}
		}
		if(e[i].title=='AlphanumAdd2' && !is_Add2(e[i].value))
		{
		errors += '- '+e[i].id+'- Following special characters *^~%<> are not allowed. \n';
		}
		/* Added  for BUG#1019 end  */

		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' && !is_Alpha(e[i].value) && e[i].value.length > 0)
		{
		errors += '- '+e[i].id+'- special character are not allowed. \n';
		}

		if(e[i].title=='Beta' && !is_Beta(e[i].value))
		{
		errors += '- '+e[i].id+'- Only alphabets are allowed. \n';
		}

		/*
		if(e[i].title=='Mobile' && !isMobile(e[i].value))
		{
			errors += '- '+e[i].id+'- Please Enter a 11 Digit Valid Number   \n'

		}
		
		if(e[i].title=='Number' && !isNumber(e[i].value))
		{
		errors += '- '+e[i].id+'- Please Enter a 10 Digit Valid Number   \n';
		}

		if(e[i].title=='Landline' && !isLandline(e[i].value))
		{
		errors += '- '+e[i].id+'- Please Enter Valid Landline Number   \n';
		}
		*/
		if(e[i].title=='pincode' && !isPinCode(e[i].value))
		{
		errors += '- '+e[i].id+'- Please Enter a 5 Digit Valid Zip Code \n';
		}
		
		if(e[i].title=='Email' && !isEmail(e[i].value))
		{
		errors += '- '+e[i].id+'-  Enter a valid email address . \n';
		}

		if(e[i].title=='isBlank'  && e[i].value=='')
		{
		errors += '- '+e[i].id+'-  is Required. \n';
		}

		//if(e[i].FFN.value!=="" && e[i].FFAIR.value==""){
		//	errors += '- Please select the Airline. \n';
		//}
		if(e[i].title=='FreqFly' && document.contactForm.FFN.value!=="" && document.contactForm.FFAIR.value==""){
			errors += '- '+e[i].id+'-  Please select the Airline. \n';
		}

		if(e[i].title=='FreqFly_CHD1' && document.contactForm.FFN_CHD1.value!=="" && document.contactForm.FFAIR_CHD1.value==""){
			errors += '- '+e[i].id+'-  Please select the Airline. \n';
		}

		if(e[i].title=='FreqFly_CHD2' && document.contactForm.FFN_CHD2.value!=="" && document.contactForm.FFAIR_CHD2.value==""){
			errors += '- '+e[i].id+'-  Please select the Airline. \n';
		}

		if(e[i].title=='FreqFly_CHD3' && document.contactForm.FFN_CHD3.value!=="" && document.contactForm.FFAIR_CHD3.value==""){
			errors += '- '+e[i].id+'-  Please select the Airline. \n';
		}

		if(e[i].title=='FreqFly_INF1' && document.contactForm.FFN_INF1.value!=="" && document.contactForm.FFAIR_INF1.value==""){

			errors += '- '+e[i].id+'-  Please select the Airline. \n';
		}
		if(e[i].title=='FreqFly_INF2' && document.contactForm.FFN_INF2.value!=="" && document.contactForm.FFAIR_INF2.value==""){

			errors += '- '+e[i].id+'-  Please select the Airline. \n';
		}
		if(e[i].title=='FreqFly_INF3' && document.contactForm.FFN_INF3.value!=="" && document.contactForm.FFAIR_INF3.value==""){

			errors += '- '+e[i].id+'-  Please select the Airline. \n';
		}
		
	}

	
	
	/*
	=================================================================
	Email Confirmation Validaiton start here 
	=================================================================
	*/
	/*
	if (f=='contactForm')
	{
		if(document.contactForm.email.value!=document.contactForm.confirm_email.value){
			errors += '- Please make sure "Email Id" and "Confirm email Id" are the same. \n';
		}
	}
	
	if (f=='contactForm')
	{
		//alert(document.contactForm.FFN.value);
		if(document.contactForm.FFN.value!=="" && document.contactForm.FFAIR.value==""){
			errors += '- Please select the Airline. \n';
		}
	}
*/



	/*
	=================================================================
	Credi Card Validaiton start here 
	=================================================================
	*/
	if (f=='confirmBooking' && ptype!='AD')
	{
		var cc=fn.ccnumber.value.substr(0,1)
		var clen=fn.ccnumber.value.length;
		var cvv=fn.CVV.value.length;
		if(!fn.CardType[0].checked && !fn.CardType[1].checked && !fn.CardType[2].checked)
		{
			errors += '- Please Choose a valid card type option \n';
		}
		if(fn.CardType[0].checked && (cc.indexOf('4')==-1 || clen!=16))
		{
			errors += '- Please Enter a 16 Digit valid Visa Credit Card Number \n';
		}
		if(fn.CardType[1].checked && (cc.indexOf('5')==-1 || clen!=16))
		{
			errors += '- Please Enter a 16 Digit valid Master Credit Card Number \n';
		}
		if(fn.CardType[2].checked && (cc.indexOf('3')==-1 || clen!=15))
		{
			errors += '- Please Enter a 15 Digit valid American Express Credit Card Number \n';
		}
		if((fn.CardType[0].checked || fn.CardType[1].checked) && cvv!=3)
		{
			errors += '- Please Enter a 3 Digit CVV Number \n';
		}
		if(fn.CardType[2].checked && cvv!=4)
		{
			errors += '- Please Enter a 4 Digit CVV Number \n';
		}
	}

	/*
	=================================================================
	End Credi Card Validaiton start here 
	=================================================================
	*/

	if(errors)
	{
		alert('The following error(s) occurred:\n\n'+errors);
		return false
	}else{
                if (f=='confirmBooking'){
                /*        document.getElementById('continue').disabled=true;*/
                }
		return true;
	}
}
