/* This function validates if the 'required' form field has a value */
function validate_req(element,strErrorField,strErrorMsg)
{
	if(eval(element.value.length) == 0) 
	{
	
		add_error(strErrorField,strErrorMsg);
		return false;
	}
		
	return true;
}

function validate_requireSelected(element,strErrorField,strErrorMsg)
{
	var selectedIndex = element.selectedIndex;
	if (selectedIndex == 0) {
		add_error(strErrorField,strErrorMsg);
		return false;
	}
	return true;
}

/* This function validates if the default text is being submitted */
function validate_notdefault(element,strErrorField,strErrorMsg,defaulttext)
{
	if(element.value == defaulttext) 
	{
		add_error(strErrorField,strErrorMsg);
		return false;
	}
	return true;
}

/* This function validates the 'maxLength' feature of the value entered for a field */
function validate_maxlen(element,strErrorField,strErrorMsg,len)
{
	if(eval(element.value.length) > len) 
	{ 
		add_error(strErrorField,strErrorMsg);
		return false; 
	}
	return true;
}

/* This function validates the 'minLength' feature of the value entered for a field */
function validate_minlen(element,strErrorField,strErrorMsg,len)
{
	if(eval(element.value.length) < len) 
	{ 
		add_error(strErrorField,strErrorMsg);
		return false; 
	}
	return true;
}

/* This function validates if a form field has an alpha-numeric value */
function validate_alpha(element,strErrorField,strErrorMsg)
{
	var charpos = element.value.search("[^A-Za-z0-9]"); 
	if(element.value.length > 0 &&  charpos >= 0) 
	{ 
		add_error(strErrorField,strErrorMsg);
		return false; 
	}
	return true;
}


/* This function validates if a form field has an alpha-space value */
function validate_alphaspace(element,strErrorField,strErrorMsg)
{
	var charpos = element.value.search("[^A-Za-z\\s]"); 
	if(element.value.length > 0 &&  charpos >= 0) 
	{ 
		add_error(strErrorField,strErrorMsg);
		return false; 
	}
	return true;
}

/* This function validates if a form field has an alpha-numeric value in the position provided*/
function validate_alpha_inpos(element,strErrorField,strErrorMsg,pos)
{
	var charpos = element.value.substring(pos,pos+1).search("[^A-Za-z0-9]"); 
	if(element.value.length > 0 &&  charpos >= 0) 
	{ 
		add_error(strErrorField,strErrorMsg);
		return false; 
	}
	return true;
}

/* This function validates if a form field has an alphabetical value */
function validate_letter(element,strErrorField,strErrorMsg)
{
	if(!element.value.match("[a-zA-Z]"))
	{
		add_error(strErrorField,strErrorMsg);
		return false; 
	}
	return true;
}

/* This function validates if a form field has an numeric value, e.g. zip code, phone numbers */
function validate_numeric(element,strErrorField,strErrorMsg)
{
	if(!element.value.match(/[0-9]/im))
	{
		add_error(strErrorField,strErrorMsg);
		return false; 
	}
	return true;
}

/* This function validates if a form field has an alphabetical,numeric, and special characters */
function validate_characters(element,strErrorField,strErrorMsg)
{
	if(!element.value.match(/^[A-Z0-9 \-\#\,\.\!\?\@]+$/im))
	{
		add_error(strErrorField,strErrorMsg);
		return false; 
	}
	return true;
}

/* This function validates if the date entered is a future date, e.g. Credit Card Expiration Date */
function validate_date_greater(element,strErrorField,strErrorMsg,yearId,monthId,year2,month2)
{
	var yearElement =  document.getElementById(yearId);
	var monthElement =  document.getElementById(monthId);
	var yearNumber = eval(year2);
	var monthNumber = eval(month2);
	

	if (yearElement.value > yearNumber) return true;
		
	if (yearElement.value < yearNumber)
	{
		add_error(strErrorField,strErrorMsg);
		return false;
	}
	
	if (yearElement.value == year2 && monthElement.value < monthNumber)
	{
		add_error(strErrorField,strErrorMsg);
		return false;
	}
}

/* This function validates if the Month, Date and Year fields have a value, else shows the error message */
function validate_req_date(element,strErrorField,strErrorMsg,yearId,monthId,dateId)
{
	var monthElement = document.getElementById(monthId).value;
	var dateElement  = document.getElementById(dateId).value;
	var yearElement  = document.getElementById(yearId).value;
	
	if (monthElement == '' || dateElement == '' || yearElement == '')
	{
		add_error(strErrorField,strErrorMsg);
		return false;
	}
	
	return true;	
}

/* This function validates if the Month and Year fields have a value (typically the CC exp date), else shows the error message */
function validate_req_exp_date(element,strErrorField,strErrorMsg,yearId,monthId)
{
	var monthElement = document.getElementById(monthId).value;
	var yearElement  = document.getElementById(yearId).value;
	
	if (monthElement == '' || yearElement == '')
	{
		add_error(strErrorField,strErrorMsg);
		return false;
	}
	
	return true;	
}

/* This function validates if the checkbox is checked or not. If not, it shows the appropriate error */
function validate_checkbox(element,strErrorField,strErrorMsg)
{
	if(eval(!element.checked)) 
	{ 
		add_error(strErrorField,strErrorMsg);
		return false;
	}
	return true;
}

/* This function validates if at least one checkbox is checked. If not, it shows the appropriate error.
   The element argument should refer to any one checkbox element.
   The checkboxes should all reside within a div element with the id specified by container, and must
   all share the class specified by classname.
 */
function validate_checkboxes(element,strErrorField,strErrorMsg,container,classname)
{
	var filter = "div#" + container + ' .' + classname;
	var cboxes = $$(filter);	// get array of checkboxes
	var somethingChecked = false;
	cboxes.each(function(cbox) { if (cbox.checked) somethingChecked = true; });	
	if( ! somethingChecked ) 
	{ 
		add_error(strErrorField,strErrorMsg);
		return false;
	}
	return true;
}

/* This function validates if two inputs are same or not, the actual element (emailaddress) and another input element (confirm email address) should be passed as an argument */
function validate_equal_values(element,strErrorField,strErrorMsg,equalElementId,equalElementDivId)
{
	var element1 = element.value;
	var equalElement = document.getElementById(equalElementId);
	if (!equalElement)
	{
		equalElement = document.getElementsByName(equalElementId)[0];
	}
	var element2 = equalElement.value;
	
	if (element1 != element2) {
		add_error(strErrorField,strErrorMsg);
		//add_error(equalElementDivId,'');
		return false;
	}
	return true;
}

// added this function to check whether the current and new password are the same. This can be used for any fields
function validate_notequal_values(element,strErrorField,strErrorMsg,equalElementId,equalElementDivId)
{
	var element1 = element.value;
	var equalElement = document.getElementById(equalElementId);
	if (!equalElement)
	{
		equalElement = document.getElementsByName(equalElementId)[0];
	}
	var element2 = equalElement.value;
	
	if (element1 == element2) {
		add_error(strErrorField,strErrorMsg);
		add_error(equalElementDivId,'');
		return false;
	}
	return true;
}

/* This function validates the format of the email. If it is, it shows the appropriate error */
function validate_email(element,strErrorField,strErrorMsg)
{
	var validEmail = isValidEmail(element.value);

	if (validEmail == '11011' || validEmail == '11000' || validEmail == false) {
		add_error(strErrorField,strErrorMsg);
		return false;
	}

	return true;
}

function validate_pobox(element,strErrorField,strErrorMsg)
{
	var str = element.value;
	var reg = /^post office|^p o|^p.o|^po|^post box|^postbox|^fpo|^apo/; //all these are considered as PO Box addresses
	if (reg.test(str.toLowerCase())){
		add_error(strErrorField,strErrorMsg);
		return false;
	}
	return true;
}

/* This function validates the format of the email. If it is, it shows the appropriate error */
function validate_optional_email(element,strErrorField,strErrorMsg)
{
	if (element.value) {
		return validate_email(element,strErrorField,strErrorMsg);	
	}

	return true;
}

/* This function validates if the email is not an admin email. If it is, it shows the appropriate error */
function validate_adminemail(element,strErrorField,strErrorMsg)
{
	var validEmail = isValidEmail(element.value);

	if (validEmail == '11010') {
		add_error(strErrorField,strErrorMsg);
		return false;
	}

	return true;
}


/* This function validates if the zip code */
function validate_zip(element,strErrorField,strErrorMsg,countryRegionId)
{
	 v = element.value.toUpperCase();
    var regex = /(^\d{5}(\d{4})?([- |]\d{4})?$)/;
    
    if($(countryRegionId).value == 'CA')
    regex = /(^[A-Z]\d[A-Z]([ |])?\d[A-Z]\d$)/;
    
    
    if( regex.test(v)){        
        return true;
    }else{
    	add_error(strErrorField,strErrorMsg);
    }				
    return false;
}

/* This function validates if the zip code is valid for either US or Canada */
function validate_zipUSCA(element,strErrorField,strErrorMsg)
{
		
       var re = /^((\d{5}([- ])\d{4})|(\d{5})|([AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]\d[A-Za-z]\s?\d[A-Za-z]\d))$/;
       if (re.test(element.value))
       {
    		return true;
    	
   		}
   		else
   		{
   			add_error(strErrorField,strErrorMsg);
   			return false;
   			
   		}

}

/* This function validates US zipcode */
function validate_zipUS(element,strErrorField,strErrorMsg)
{
	v = element.value.toUpperCase();
    var regex = /(^\d{5}(\d{4})?([- |]\d{4})?$)/;
      
    if( regex.test(v)){        
        return true;
    }else{
    	add_error(strErrorField,strErrorMsg);
    }				
    return false;
}

/* This function validates if the zip code valid, when Canada is selected  */
function validate_zipCA(element,strErrorField,strErrorMsg,countryRegionId)
{
	if ($(countryRegionId).value == 'CA')
	{
		if ( eval(element.value.length) != 7) 
		{ 
			add_error(strErrorField,strErrorMsg);			
			return false; 
		}
		
		var charpos =(element.value.substring(1,2)+element.value.substring(4,5)+element.value.substring(6,7)).search("[^0-9]");
		var noncharpos = (element.value.substring(0,1)+element.value.substring(2,3)+element.value.substring(5,6)).search("[^A-Za-z]");
		if ( charpos>0 || noncharpos>0 ||element.value.substring(3,4)!=' ')
		{
			add_error(strErrorField,strErrorMsg);				
			return false; 		
		}
	}
	return true;
}


/* This function validates the state dropdown */
function validate_reqFormValues(element,strErrorField,strErrorMsg,element1Id,element1DivId,element2Id,element2DivId)
{


/*form validation*/
     if(element.value.length==0 && Trim($(element1Id).value).length == 0 && $(element2Id).value == 'state')  
          {
          //alert("inside all 3 empty...strErrorMsg is -> "+strErrorMsg);
          add_shipToStoreError(strErrorField,strErrorMsg);
          add_shipToStoreError(element1DivId,'');
          add_shipToStoreError(element2DivId,'');	
          return false;
          }
/*zipcode validation*/
      else  if(element.value.length>0  && eval(element.value.length) < 5)   
          {
          add_shipToStoreError(strErrorField,_ERR_CHECKOUT_ADDRESS_SHIPTOSTORE_ZIPCODE_REQ);
          return false;
          }  
/*state validation*/			 
	  else	if(Trim($(element1Id).value).length > 0 &&  $(element2Id).value == 'state' && (element.value.length==0))  
				{
				add_shipToStoreError(element2DivId,_ERR_SHIP_TO_STORE_CITY_VALID);
				return false;
				}
				             
//city validation         
       	else if(($(element1Id).value.length) == 0  &&  ($(element2Id).value != 'state')	&& (element.value.length==0)) 
		{	 
			//add_shipToStoreError(element1Id,Error_StoreLocatorPanel_StateCity);
			//add_shipToStoreError(element1Id,strErrorMsg);
			//alert("inside city and state empty...strErrorMsg is -> "+strErrorMsg);
			add_shipToStoreError(strErrorField,strErrorMsg);
			add_shipToStoreError(element1DivId,'');
			 return false;
			 }
	return true;
}

/* Validates ship to store selected */
function validate_shipToStoreSelected(element,strErrorField,strErrorMsg)
{
		add_error(strErrorField,strErrorMsg);
		return false;
}

/* Validates if the SSN typed by user is 0000 */
function validate_invalidSSN(element,strErrorField,strErrorMsg)
{
	if (element.value == 0)
	{
		add_error(strErrorField,strErrorMsg);
		return false;
	}
	return true;
}

/* Validate if the age is 18 based on the Date of Birth selected */
function validate_minimumAge(element,strErrorField,strErrorMsg,yearId,monthId,dateId)
{
	var monthElement = document.getElementById(monthId).value;
	var dateElement  = document.getElementById(dateId).value;
	var yearElement  = document.getElementById(yearId).value;
	var birthDate = new Date(yearElement + "/" + monthElement + "/" + dateElement);
	var minimumDate = new Date();
	minimumDate.setYear(minimumDate.getYear() - 18);
	if(minimumDate < birthDate)
	{
		add_error(strErrorField,strErrorMsg);
		return false;	
	}
	return true;
}

function isValidEmail(strEmail){
	var errorEmail = '';
	if (strEmail == null || strEmail == '') {
  		errorEmail = '11000';
		return errorEmail;
	}
		
	var str = strEmail;
  	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(^\#)|(^\*)|(^\@)|(^\&)|(^\^)|(%)/; //not valid 
  	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{1,3}|[0-9]{1,3})(\]?)$/; // valid
	var reg3 = /^www/;//not valid
	//var reg4 = /[^0-9](aol|yahoo|msn|hotmail)/;
	var reg4 = /^[0-9][a-zA-Z0-9\-\.]+\@(aol|yahoo|msn|hotmail)/;//not valid
	//As people generally know about some basic admin email addresses, they are not allowed.
	var reg5 = /^webmaster@|^administrator@|^support@|^admin@/; //not valid
	//Regular domain level checks & Country level domain checks
	var reg6 = /(\.aero|\.biz|\.cat|\.com|\.coop|\.edu|\.gov|\.info|\.int|\.jobs|\.mil|\.mobi|\.museum|\.name|\.net|\.org|\.pro|\.tel|\.travel|\.ac|\.ad|\.ae|\.af|\.ag|\.ai|\.al|\.am|\.an|\.ao|\.aq|\.ar|\.as|\.at|\.au|\.aw|\.ax|\.az|\.ba|\.bb|\.bd|\.be|\.bf|\.bg|\.bh|\.bi|\.bj|\.bm|\.bn|\.bo|\.br|\.bs|\.bt|\.bv|\.bw|\.by|\.bz|\.ca|\.cc|\.cd|\.cf|\.cg|\.ch|\.ci|\.ck|\.cl|\.cm|\.cn|\.co|\.cr|\.cu|\.cv|\.cx|\.cy|\.cz|\.de|\.dj|\.dk|\.dm|\.do|\.dz|\.ec|\.ee|\.eg|\.er|\.es|\.et|\.eu|\.fi|\.fj|\.fk|\.fm|\.fo|\.fr|\.ga|\.gb|\.gd|\.ge|\.gf|\.gg|\.gh|\.gi|\.gl|\.gm|\.gn|\.gp|\.gq|\.gr|\.gs|\.gt|\.gu|\.gw|\.gy|\.hk|\.hm|\.hn|\.hr|\.ht|\.hu|\.id|\.ie|\.il|\.im|\.in|\.io|\.iq|\.ir|\.is|\.it|\.je|\.jm|\.jo|\.jp|\.ke|\.kg|\.kh|\.ki|\.km|\.kn|\.kr|\.kw|\.ky|\.kz|\.la|\.lb|\.lc|\.li|\.lk|\.lr|\.ls|\.lt|\.lu|\.lv|\.ly|\.ma|\.mc|\.md|\.mg|\.mh|\.mk|\.ml|\.mm|\.mn|\.mo|\.mp|\.mq|\.mr|\.ms|\.mt|\.mu|\.mv|\.mw|\.mx|\.my|\.mz|\.na|\.nc|\.ne|\.nf|\.ng|\.ni|\.nl|\.no|\.np|\.nr|\.nu|\.nz|\.om|\.pa|\.pe|\.pf|\.pg|\.ph|\.pk|\.pl|\.pm|\.pn|\.pr|\.ps|\.pt|\.pw|\.py|\.qa|\.re|\.ro|\.ru|\.rw|\.sa|\.sb|\.sc|\.sd|\.se|\.sg|\.sh|\.si|\.sj|\.sk|\.sl|\.sm|\.sn|\.so|\.sr|\.st|\.su|\.sv|\.sy|\.sz|\.tc|\.td|\.tf|\.tg|\.th|\.tj|\.tk|\.tl|\.tm|\.tn|\.to|\.tp|\.tr|\.tt|\.tv|\.tw|\.tz|\.ua|\.ug|\.uk|\.um|\.us|\.uy|\.uz|\.va|\.vc|\.ve|\.vg|\.vi|\.vn|\.vu|\.wf|\.ws|\.ye|\.yt|\.yu|\.za|\.zm|\.zw)$/; //valid

  if (!reg1.test(str) && reg2.test(str) &&  !reg3.test(str) && !reg4.test(str.toLowerCase()) && !reg5.test(str.toLowerCase()) && reg6.test(str.toLowerCase())) { 
  		errorEmail = 'true';
    	return errorEmail;
 	} else {
 		errorEmail = '11000';
 		if (reg5.test(str.toLowerCase()))
 			errorEmail = '11010';
 		else if (!reg6.test(str.toLowerCase()))
 			errorEmail = '11011';
		return errorEmail;
	}
}


/* 
	This function validates a 4 part phone where the format is (phone1) phone2 - phone3 EXT: phone4
	
	required - true if the phone number is a required field
	part1 - area code is 3 digits
	part2 - second part of phone number is 3 digits
	part3 - third part of phone number is 4 digits
	part4 - extension and never required
*/
function validate_phone_4part(element,strErrorField,strErrorMsg,required,part1,part2,part3,part4)
{
	var part1Element =  document.getElementById(part1);
	var part2Element =  document.getElementById(part2);
	var part3Element =  document.getElementById(part3);
	var part4Element =  document.getElementById(part4);

	if (required == "true")
	{
		if(eval(part1Element.value.length) != 3) 
		{
			add_error(strErrorField,strErrorMsg);
			return false;
		}
	
		if(eval(part2Element.value.length) != 3) 
		{
			add_error(strErrorField,strErrorMsg);
			return false;
		}
	
		if(eval(part3Element.value.length) != 4) 
		{
			add_error(strErrorField,strErrorMsg);
			return false;
		}
	}
	
	if(part1Element.value.length > 0 && part1Element.value.search("[^0-9]") >= 0) 
	{
		add_error(strErrorField,strErrorMsg);
		return false; 
	}

	if(part2Element.value.length > 0 && part2Element.value.search("[^0-9]") >= 0) 
	{
		add_error(strErrorField,strErrorMsg);
		return false; 
	}

	if(part3Element.value.length > 0 && part3Element.value.search("[^0-9]") >= 0) 
	{
		add_error(strErrorField,strErrorMsg);
		return false; 
	}

	if(part4Element && part4Element.value.length > 0 && part4Element.value.search("[^0-9]") >= 0) 
	{
		add_error(strErrorField,strErrorMsg);
		return false; 
	}

	return true;


	return true;
}




/* 
	This function validates a 4 part phone where the format is (phone1) phone2 - phone3 EXT: phone4
	
	required - true if the phone number is a required field
	part1 - area code is 3 digits
	part2 - second part of phone number is 3 digits
	part3 - third part of phone number is 4 digits
	part4 - extension and never required
*/
function validate_phone_eachpart(element,strErrorField,strErrorMsg,required,part1,part2,part3,part4)
{
	var part1Element =  document.getElementById(part1);
	var part2Element =  document.getElementById(part2);
	var part3Element =  document.getElementById(part3);
	var part4Element =  document.getElementById(part4);

	if (required == "true")
	{
	if(eval(part1Element.value.length) == 0 &&  eval(part2Element.value.length) == 0 &&  eval(part3Element.value.length) ==0)
		{
			 
			return true;
		} 
		
		if(eval(part1Element.value.length) != 3 || eval(part2Element.value.length) != 3 || eval(part3Element.value.length) != 4)
		{
			add_error(strErrorField,strErrorMsg);
			return false;
		} 
	 return true;
	}
	
	 
}



/* 
	This function validates a 4 part phone where the format is (phone1) phone2 - phone3 EXT: phone4
	
	required - true if the phone number is a required field
	part1 - area code is 3 digits
	part2 - second part of phone number is 3 digits
	part3 - third part of phone number is 4 digits
	part4 - extension and never required
*/
function validate_phone_fullpart(element,strErrorField,strErrorMsg,required,part1,part2,part3,part4)
{
	var part1Element =  document.getElementById(part1);
	var part2Element =  document.getElementById(part2);
	var part3Element =  document.getElementById(part3);
	var part4Element =  document.getElementById(part4);

	if (required == "true")
	{
	if(eval(part1Element.value.length) == 0 &&  eval(part2Element.value.length) == 0 &&  eval(part3Element.value.length) ==0)
		{
			 
			add_error(strErrorField,strErrorMsg);
			return false;
		} 
		
		 
	 return true;
	}
	
	 
}

function validate_phone(element,strErrorField,strErrorMsg)
{	
	var regex = (/^([\d]{3})?[-]([\d]{3})?[-]([\d]{4})?$/);
	if( regex.test(element.value)){        
        return true;
    }else{
    	add_error(strErrorField,strErrorMsg);
    }				
    return false;
	 
}

function validate_phone_char(element,strErrorField,strErrorMsg)
{
	var regex = (/^[\d]+$/);
	if ( regex.test( element.value ) )
	{			 
		add_error(strErrorField,strErrorMsg);
		return false;
	} 	 
	 return true;
}

function validate_phone_ca(element,strErrorField,strErrorMsg)
{	
	var regex = /((^[\d]{3})?[-]([\d]{3})?[-]([\d]{4})?$)/;
	if ( !regex.test( element.value ) )
	{			 
		add_error(strErrorField,strErrorMsg);
		return false;
	} 
	var regex = /([\d-]+)/;
	if ( !regex.test( element.value ) )
	{			 
		add_error(strErrorField,strErrorMsg);
		return false;
	} 	 
 return true;
	 
}

function getCreditCardType(number)
{
	// American Express: length 15, prefix 34 or 37.
	if(number.match(/^3[4,7]\d{13}$/m))
		return 'American Express';
	// Mastercard: length 16, prefix 51-55.
	else if(number.match(/^5[1-5]\d{14}$/m))
		return 'Master Card';
	// Visa: length 13 or 16, prefix 4.
	else if(number.match(/^4(\d{12}|\d{15})$/m))
		return 'Visa';
	// Discover: length 16, prefix 6011.
	else if(number.match(/^6011\d{12}$/m))
		return 'Discover';
	// Catch all (PLCC?): length 16, prefix N/A.
	else if(number.match(/^\d{16}$/m))
		return 'unknown';
	return ''; //Doesn't match a valid pattern.
}

/* This function validates that the credit card number matches an acceptable credit card pattern. */
function validate_ccPattern(element,strErrorField,strErrorMsg)
{
      if (getCreditCardType(element.value) == '')
	  {
		add_error(strErrorField,strErrorMsg);
		return false;
	  }
	  return true;
} 

/* This function validates the credit card number with the Luhn check*/
function validate_ccLuhn(element,strErrorField,strErrorMsg)
{
	//Perform a standard Luhn validation on this number.
	var i = 0;
	var c = 0;
	var n = 0;
	var stripped = "";
	var digit_counter = 1;
	var digit_sum = 0;
	var input = element.value;
	for(i = (input.length - 1); i >= 0; i--)
	{
		c = input.charAt(i);
		if((n = parseInt(c)) >= 0 && n <= 9)
		{
			//Every other digit needs to be doubled.
			if(digit_counter % 2 == 0)
			{
				n = n * 2;
				if(n >= 10)
				{
					digit_sum = digit_sum + 1;
					n = n - 10;
				}
			}
			digit_sum = digit_sum + n;
			stripped = c + stripped;
			digit_counter++;
		}
	}
	
	if((digit_sum % 10) == 0)
	{
		element.value = stripped;
		return true;
	}
	
	add_error(strErrorField,strErrorMsg);
	return false;
} 

/* This function validates the length of the ccid for the given card number */
function validate_ccID(element,strErrorField,strErrorMsg,ccNum)
{
	var result = false;
	if(getCreditCardType($(ccNum).value) == 'American Express')
		result = element.value.match(/^\d{4}$/m);
	else
		result = element.value.match(/^\d{3}$/m);
	
	if (!result)
    {
		add_error(strErrorField,strErrorMsg);
		return false;
	}
	return true;
} 

/* This function checks a brand drop-down against the credit card number. */
function validate_ccBrand(element,strErrorField,strErrorMsg,ccNum)
{
	if(element.value != getCreditCardType($(ccNum).value))
	{
		add_error(strErrorField,strErrorMsg);
		return false;
	}
	return true;
}

/* This function validates that a credit card expiration date is not in the past.
(Unlike the "date_greater" validator above, this actually tests against the current date.) */
function validate_ccExpiresFuture(element,strErrorField,strErrorMsg,ccYear)
{
	var curDate = new Date();
	curDate = new Date(curDate.getFullYear() + "/" + (curDate.getMonth() + 1) + "/1");
	var expDate = new Date(parseInt($(ccYear).value) + "/" + parseInt(element.value) + "/1");
	
	if(expDate < curDate)
	{
		add_error(strErrorField,strErrorMsg);
		return false;
	}
	
	return true;
}


function validate_search(element,strErrorField,strErrorMsg)
{
	var str = element.value;
	str = str.replace(/^\s*(.*?)\s*$/,"$1");
	
	if(eval(str.length) == 0 || eval(str.length) < 3) 
	{
		add_error(strErrorField,strErrorMsg);
		return false;
	}
	
	return true;
} 

// This function checks if any character in the given string has more than 4 instances
function validate_max_instance(element,strErrorField,strErrorMsg)
{
	return true;	
}

// This function no longer checks for anything and returns true
function validate_max_occurrence_consecutive_char(element,strErrorField,strErrorMsg)
{
	return true;
}

/* This function validates if one of the radio buttons is checked or not. If not, it shows the appropriate error */
function validate_radio(elements,strErrorField,strErrorMsg)
{
	var i = 0;
	var found = false;
	for(i=0; i<elements.length; i++)
	{
		if(eval(elements[i].checked)) 
		{ 
			return true;
		}
	}
	add_error(strErrorField,strErrorMsg);
	return false;


}
