function is_Alpha(string) {
  var isAlpha = /^([a-zA-Z]+)$/;
if (string.search(isAlpha)==-1)
		{
		return false;
		}
return true;
}     

function isEmail(strng) 
{
 var emailFilter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{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) {
        var re10digit=/^\d{11}$/
   if (strng.search(re10digit)==-1)
                {
                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{11}$/
   if (strng.search(re10digit)==-1)
                {
                return false;
                }
return true;
}
function isMobile2(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{6}$/ 
	
   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_Proof(string) {
	
   if (!string) return false;
   var iChars = "*|,\"<:>[]{}`\';()@&$#% ";

   for (var i = 0; i < string.length; i++) {
      if (iChars.indexOf(string.charAt(i)) != -1)
         return false;
		  
   }
  if(string.length<2 || string.length>=25)
	  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;
   
} 

function isCVV(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>=4)
	  return false;
    return true;
   
} 

function isCVV2(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 != 4) && (string.length != 3))
	  return false;
    return true;
   
}  

/* Added  for BUG#1019   */

function isValid(f,ptype,product,version)
{
var e=document.forms[""+f].elements;
var l=e.length;
var fn=document.forms[""+f];
var errors='';
/* Validations for Sixt start here  */
if (f=='contactForm')
	{
		if(document.contactForm.offer_mobile && document.contactForm.offer_mobile.title=='MobileOff' && !isMobile2(document.contactForm.offer_mobile.value) )
				{
					errors += '- '+document.contactForm.offer_mobile.id+'- Please Enter a 10 Digit Valid Number \n';
				}
		if (document.contactForm.offer_address && document.contactForm.offer_address.value=="" && document.contactForm.offer_address.title=='AlphanumAddS')
				{
					errors += '- '+document.contactForm.offer_address.id+' is Required. \n';
				}
		if (document.contactForm.offer_city && document.contactForm.offer_city.value=="")
				{
					errors += '- Please select the Pick up City. \n';
				}
		if(document.contactForm.offer_email && document.contactForm.offer_email.title=='EmailSixt' && !isEmail(document.contactForm.offer_email.value))
				{
				errors += '- '+document.contactForm.offer_email.id+'-  Enter a valid email address . \n';
				}
		if(document.contactForm.offer_pick_hrs && document.contactForm.offer_pick_hrs.value=="")
				{
				errors += '- Please select the pick up Hrs. \n';
				}
		if(document.contactForm.offer_pick_min && document.contactForm.offer_pick_min.value=="")
				{
				errors += '- Please select the pick up Mins. \n';
				}
		
	}
	
/* Validations for Sixt end here   */
if (f=='contactForm')
	{
			//alert('hi');
			if(document.contactForm.contact_mobile.title=='Mobile' && !isMobile2(document.contactForm.contact_mobile.value))
			{
					//alert('hi2');
				errors += '- '+document.contactForm.contact_mobile.id+'- Please Enter a 10 Digit Valid Number \n';
			}
			
			if(document.contactForm.contact_landline.value!="" && !isNumber(document.contactForm.contact_landline.value)) 
				{
				//alert('hi4');
				errors += '- '+document.contactForm.contact_landline.id+'- Please Enter a Valid Alternate Number   \n';
				}
		
	}
	if (f=='feedbackForm')
	{
		if(document.feedbackForm.contact_mobile.title=='Mobile' && !isMobile2(document.feedbackForm.contact_mobile.value) &&  document.feedbackForm.contact_mobile.value=="")
		{
				errors += '- '+document.feedbackForm.contact_mobile.id+'- Please Enter a 10 Digit Valid Number \n';
		}
		else
		{
			if(!isMobile2(document.feedbackForm.contact_mobile.value) && document.feedbackForm.contact_mobile.value.length!=='10')
			{
					errors += '- '+document.feedbackForm.contact_mobile.id+'- Please Enter a 10 Digit Valid Number  \n';
			}
		}
		if(document.feedbackForm.query && document.feedbackForm.query.value=="")
		{
			errors += '- Please select the Type of Queryssss. \n';
		}
		if(document.feedbackForm.subquery && document.feedbackForm.subquery.value=="")
		{
			errors += '- Please select the Type of Sub Query. \n';
		}
		if(document.feedbackForm.category && document.feedbackForm.category.value=="")
		{
			errors += '- Please select the Category. \n';
		}
	}
	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(f=='contactForm')
		{

			if(e[i].value=='' && e[i].id!='' && e[i].title=='DOBNumber')       
			{
			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';
		}



		if(e[i].title=='Alpha3' && e[i].value=='')
		{
		errors += '- '+e[i].id+'- is Required. \n';
		}
		if(e[i].title=='Alpha3' && !is_Alpha(e[i].value) && e[i].value.length > 0)
		{
		errors += '- '+e[i].id+'- special character and spaces are not allowed. \n';
		}
		if(e[i].title=='Alpha3' && e[i].value.length<2 && e[i].value.length > 0)
		{
		errors += '- '+e[i].id+'- should be greater than or equal to 2 characters \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 and spaces are not allowed. \n';
		}
		/* for moblile number and landline number code start here */
	if(f!='contactForm' && f!='feedbackForm')
		{
				if(e[i].title=='Mobile' && !isMobile2(e[i].value) && e[i].value.substring(1,0)!=='0')
				{
				errors += '- '+e[i].id+'- Please Enter a 10 Digit Valid Number \n';
				}

				if(e[i].title=='Mobile' && !isMobile(e[i].value) && e[i].value.substring(1,0)=='0' && e[i].value.length!=='11')
					{
						//alert('hi5');
						//e[i].value=e[i].value.substring(1,11)
						errors += '- '+e[i].id+'- Please Enter a 11 Digit Valid Number  \n';
					}

				if(e[i].title=='Number' && !isNumber(e[i].value) && document.contactForm.contact_mobile.value=="")
				{
				errors += '- '+e[i].id+'- Please Enter a Valid Land Line Number   \n';
				}
		}
		/* for moblile number and landline number code end here */



		/*
		if(e[i].title=='Mobile' && !isMobile(e[i].value))
		{
			errors += '- '+e[i].id+'- Please Enter a 10 Digit Valid Number   \n'

		}

		if(e[i].title=='Number' && !isNumber(e[i].value))
		{
		errors += '- '+e[i].id+'- Please Enter Digits only.\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=='Email' && !isEmail(e[i].value))
		{
		errors += '- '+e[i].id+'-  Enter a valid email address . \n';
		}

		if(e[i].value=='' && e[i].title=='isblank')	
		{
		errors += '- '+e[i].id+'- is Required. \n';
		}

		if(e[i].title=='Proof' && !is_Proof(e[i].value))
		{
		errors += '- '+e[i].id+'- Please Enter a valid ID Number\n without using special characters and spaces. \n';
		}
		
	}
	/* for staticpackage terms and conditions */
	if (f=='contactForm' && product=='STATICKPACKAGE')
				{
					if(document.contactForm.tnc && document.contactForm.tnc.checked!=true)
					{
						errors += '- Please check terms & condition. \n';
					}
				}
	
	/*
	=================================================================
	Email Confirmation Validaiton start here 
	=================================================================
	
	if (f=='contactForm')
		{

			if(document.contactForm.contact_email.value!=document.contactForm.confirm_email.value)
				{
				errors += '- Please make sure "Email Id" and "Confirm email Id" are the same. \n';
				}

		}*/



	/*
	=================================================================
	Credi Card Validaiton start here 
	=================================================================
	*/
	if (f=='confirmBooking' && ptype!='AD')
	{
		var cc=fn.card_number.value.substr(0,2)
		var dc=fn.card_number.value.substr(1,1)
			//alert(cc=fn.card_number.value.substr(0,2));
		var clen=fn.card_number.value.length;
		var cvv=fn.card_cvv.value.length;
		if(version != 'AMEX') 
		{
			if(!fn.card_type[2] && !fn.card_type[3]){
				// Case for HDFC Debit Card
				fn.card_type[2] = 'AX';
				fn.card_type[3] = 'DC';
			}
			if(!fn.card_type[0].checked && !fn.card_type[1].checked && !fn.card_type[2].checked && !fn.card_type[3].checked)
			{
				errors += '- Please Choose a valid card type option \n';
			}
			if(fn.card_type[0].checked && (cc.indexOf('4')==-1 || clen!=16))
			{
				errors += '- Please Enter a 16 Digit valid Visa Credit Card Number \n';
			}
			if(fn.card_type[1].checked && (cc.indexOf('5')==-1 || clen!=16))
			{
				errors += '- Please Enter a 16 Digit valid Master Credit Card Number \n';
			}
			if(fn.card_type[2].checked && (cc.indexOf('3')==-1 || clen!=15))
			{
				errors += '- Please Enter a 15 Digit valid American Express Credit Card Number \n';
			}
			if(fn.card_type[3].checked && (cc.indexOf('36')==-1 || clen!=14))
			{
				errors += '- Please Enter a 14 Digit valid Diners Club Credit Card Number \n';
			}
			if((fn.card_type[0].checked || fn.card_type[1].checked) && ( !isCVV(fn.card_cvv.value)))
			{
				errors += '- Please Enter a 3 Digit CVV Number without using special characters & alphabets \n';
			}
			if(fn.card_type[2].checked && !isCVV2(fn.card_cvv.value))
			{
				errors += '- Please Enter a 3 or 4 Digit CVV Number without using special characters & alphabets \n';
			}
			if(fn.card_type[3].checked && !isCVV(fn.card_cvv.value))
			{
				errors += '- Please Enter a 3 Digit CVV Number without using special characters & alphabets \n';
			}
			if (fn.card_type[2].checked && isAmex && (!fn.card_amexType[0].checked && !fn.card_amexType[1].checked))
			{
				
					errors += '- Please select the type of American Express Card \n';
			}
		}else{
			if(fn.card_type.checked && (cc.indexOf('3')==-1 || clen!=15))
			{
				errors += '- Please Enter a 15 Digit valid American Express Credit Card Number \n';
			}
			if(fn.card_type.checked && !isCVV2(fn.card_cvv.value))
			{
				errors += '- Please Enter a 3 or 4 Digit CVV Number without using special characters & alphabets \n';
			}
			if (fn.card_type.checked && isAmex && (!fn.card_amexType[0].checked && !fn.card_amexType[1].checked))
			{
				
					errors += '- Please select the type of American Express Card \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;
	}
}
