function max(txarea){ 
	total = 99;
	tam = txarea.value.length;
	if (tam > total){ 
		aux = txarea.value; 
		txarea.value = aux.substring(0,total);
	} 
}

function maximum(txarea){ 
	total = 4000;
	tam = txarea.value.length;
	if (tam > total){ 
		aux = txarea.value; 
		txarea.value = aux.substring(0,total);
	} 
}

function setOptions(frm) {		
			o = frm.subject.options[frm.subject.selectedIndex].value;
			
			if (o == "Concern or Complaint") {
				document.getElementById('hiddenForm').style.display='block';
				frm.lotNumber.value='';
				frm.lotNumberExists.checked=false;
				frm.lotNumberExists.value='false';
				frm.upcCode.value='';
				frm.pricePaid.value='';
				frm.productName.value='';
				frm.wherePurchased.value='';
				frm.other.value='';
			} else {
				document.getElementById('hiddenForm').style.display='none';
				frm.lotNumber.value='';
				frm.lotNumberExists.value='false';
				frm.lotNumberExists.checked=false;
				frm.upcCode.value='';
				frm.pricePaid.value='';
				frm.productName.value='';
				frm.wherePurchased.value='';
				frm.other.value='';
			}
		}

function validateAgeCookie() {
	var ageOK = getCookie('over13');		    
	if (ageOK != null) {
		return false;
	}
	return true;
}

function isNumberKey(evt) {
   var charCode = (evt.which) ? evt.which : event.keyCode
   if (charCode > 31 && (charCode < 48 || charCode > 57))
      return false;

   return true;
}

function isEmail( string ) {
	if ( string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1 ) {
		return true;
	} else {
		return false;
	}
}

function ValidateAge(validAge,year,month,day) {



  var byear = parseInt(year);	// year entered	

  var bmonth = parseInt(month);	// month entered

  var bday = parseInt(day);		// day entered



  var today = new Date();								// full date of today

  var currYear = today.getFullYear();						// year of today

  var currMonth = today.getMonth();						// month of today (0-11)

  var currDay = today.getDate();						// day of today (1-31)



	// add 1 to curr month since it is zero based

  currMonth += 1;				

	// # years diff between date entered and today

  var yearsDiff = currYear - byear;		

  

  // debug info ...

  //alert (byear + " " + currYear + "\n" + bmonth + " " + currMonth + "\n" + bday + " " + currDay);

  

  if (yearsDiff > validAge) {			// if yearsdiff > the valid age, let it pass

    //alert ("ok you old fart");

    return true; }

  else if (yearsDiff < validAge) {		// yearsdiff < validage, fail

    return false; }

  else {								// same year as threshold; use month/day to determine

    if (bmonth < currMonth) {			// had birthday in prior month this year - pass

		return true; }

	else if (bmonth > currMonth)  {		// haven't had your birthday yet this year - fail

		return  false; }  

	else {								// birthday is this month		

		if (bday <=	currDay) {			// birthday earlier this month or today

			return true;  }				

		else {							// birthday later this month - fail

			return false;   } 

		}  

		return false; } 

	return  false; 

}

function isZip( zip ) {

	// 5 digit zips
	if(zip.match(/^\d\d\d\d\d$/)) {
	
		return true;
	}
		
	// 5+4 digit zips
	if((zip.match(/^\d\d\d\d\d\d\d\d\d$/)) || (zip.match(/^\d\d\d\d\d\-\d\d\d\d$/))) {
	
		return true;
	}
		
	return false;
}

function isDate(day, month, year) { 

    try  {
    
       if ((day < 1) || (day < 1 || day > 30) && (month == 4 || month == 6 || month == 9 || month == 11) || day > 31) { 
       
           return false; 
       } 
    
       if (month < 1 || month > 12) { 
       
           return false;
       } 
    
       if(year == '' || year < 1900)   {
       
           return false;
       }
           
       if (month == 2 && (day < 1 || day > 29 || (day > 28 && (parseInt(year / 4) != year / 4)))) { 
       
           return false;
       } 
   }
   catch(Exception) {
   
        return false;
   }
   
   return true; 
}

function isNumeric(field) {

	if (field == null || field == "") {
	
		return false;
	}
	
	var number = '0123456789';		
	
	for (i = 0; i < field.length; i++) {
	
		if(number.indexOf(field.charAt(i),0) == -1) {
		
			return false;
		}
	}
	
	return true;
}

function GetRadioValue(RadioName) {
	
	if(isObject(RadioName)) {	
	
		for (i=0;i < RadioName.length; i++) {
		
		    if (RadioName[i].checked == true){
		    
				return(RadioName[i].value);
		    }
		}
	}
		
	return null;
}

function isObject(a) {

    return (a && typeof a == 'object') || isFunction(a);
}
