function getStringCheckedValue(param) {

	var result = 'false';
	
	if (param) {	
	
		result = 'true';
	}
	
	return result;
}

function fixPostal( pc ) {

	var newpc = "";
	var output = "";

	// strip out non-alphanumeric
	for ( var i = 0; i < pc.value.length; i++ )
		if ( pc.value.charAt( i ).match(/\w/) )
			newpc += pc.value.charAt( i );
			if ( newpc ) {
				// rebuild number with space
				for ( var i = 0; i < 6; i++ ) {
					output += newpc.charAt( i )
					if ( i == 2 )
						output += " ";
				}
			}
			// return value in uppercase
			pc.value = output.toUpperCase();
}

function fixPhone( phone ) {

	var num = phone.value;
	var newnum = "";
	var output = "";

	// strip out non-numbers
	for ( var i = 0; i < num.length; i++ )
		if ( num.charAt( i ).match(/\d/) )
			newnum += num.charAt( i );
			if ( newnum ) {
				// rebuild number with hyphen
				for ( var i = 0; i < newnum.length; i++ ) {
					if ( i == 3 || i == 6 )
						output += "-";
					else if ( i == 10 )
						output += " ";
						output += newnum.charAt( i )
				}
			}
			// return value
			phone.value = output;
}

function isName( string ) {

	if ( string.match(/^[A-Za-z\'\- ]+$/) )
		return true;
	return false;
}

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 isEmailMulti( string ) {

	// email addresses separated by commas
	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 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 isPhone( phone ) {

	// 3+3+4 digit
	if( phone.match(/^\d\d\d\-\d\d\d\-\d\d\d\d$/) )
		return true;
	return false;
}

function isPostalCode( pc ) {

	// canadian postal codes (6 or 7 characters)
	if( ( pc.match(/^[A-Za-z]\d[A-Za-z]\d[A-Za-z]\d$/) ) || ( pc.match(/^[A-Za-z]\d[A-Za-z] \d[A-Za-z]\d$/) ) )
		return true;
	return false;
}

function CheckNumeric(frmEvent) {

   //Get ASCII value of key that the user typed
   var key;

	if ( "which" in frmEvent ) {
		key = frmEvent.which;
	} 
	else {
		if ( "keyCode" in window.event ){
			key = window.event.keyCode;
		}
	}    
	
	//Check is the key is a numeric character
	if ( key <= 47 || key >= 58 ) {
	    //Otherwise, don?t show it
	    frmEvent.returnValue = false; 
	}
}

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 GetCheckBoxValue(CheckboxName){

	var values = "";
	
	if(isObject(CheckboxName)){
		for (i=0;i < CheckboxName.length; i++) {
		    if (CheckboxName[i].checked == true) {
		    	if (values == "") {
			        values = CheckboxName[i].value;
			    }
			    else {
			        values = values + "," + CheckboxName[i].value;
			    }
		    }
		}
	}
	
	if (values == "") {
	    return null;
	}
	else {
	    return values;
	}
}

function setOptions(frm) {		
	o = frm.subject.options[frm.subject.selectedIndex].value;

	if (o == "Concern or Complaint") {
		document.getElementById('corctable').style.display='block';
		frm.lotNumber.value='';
		frm.lotNumberExists.checked=false;
		frm.lotNumberExists.value='false';
		frm.expMonth.value='';
		frm.expYear.value='';
		frm.upcCode.value='';
		frm.pricePaid.value='';				
//		frm.productName.value='';
		frm.wherePurchased.value='';
	} else {
		document.getElementById('corctable').style.display='none';
		frm.lotNumber.value='';
		frm.lotNumberExists.value='false';
		frm.lotNumberExists.checked=false;
		frm.expMonth.value='';
		frm.expYear.value='';
		frm.upcCode.value='';
		frm.pricePaid.value='';
//		frm.productName.value='';
		frm.wherePurchased.value='';
	}
}
		
function pickGender(frm) {

	switch(frm.salutation.value) {
		case "Mr.":
			frm.gender[0].checked = true;
			break;
		case "Ms.":
			frm.gender[1].checked = true;
			break;			
		case "Mrs.":
			frm.gender[1].checked = true;
			break;
		case "Dr.":
			frm.gender[0].checked = true;
			break;						
		default:	
			frm.gender[0].checked = false;
			frm.gender[1].checked = false;
			break;
	}
}
		
function validateInfo(frm) {
    
    var ageOK = getCookie('over13');		    
    
    if (ageOK != null) {
        alert ("Sorry, you must be at least 13 years of age to use this function of the website.");
        return false;
    }
    
    else if (frm.firstName.value == "") {
        alert ("Please enter your first name.");
        frm.firstName.focus();
        return false;		        
    } 
    
    else if (frm.lastName.value == "") {
        alert ("Please enter your last name.");
        frm.lastName.focus();
        return false;
    } 
    
    else if (frm.streetName.value == "") {
        alert ("Your address is incomplete. Please enter a street name.");
        frm.streetName.focus();
        return false;
    } 
		    
    else if (frm.city.value == "") {
        alert ("Please enter your city.");
        frm.city.focus();
        return false;
    } 
    
    else if (frm.state.value == "") {
        alert ("Please select your state.");
        frm.state.focus();
        return false;	
    } 
    
    else if (frm.zip.value == "") {
    	alert("Please enter your zip code.");
        frm.zip.focus();
        return false;  		        
    } 
    
    else if (!isZip(frm.zip.value)) {
        alert("Please enter a valid zip code.");
        frm.zip.focus();
        return false;		        	        
    } 
		     
    else if (frm.homePhone.value != "" && !isNumeric(frm.homePhone.value)) {
    	alert("Invalid home phone number.");
        frm.homePhone.focus();
        return false;
    }
    
    else if (frm.workPhone.value != "" && !isNumeric(frm.workPhone.value)) {
    	alert("Invalid work phone number.");
        frm.workPhone.focus();
        return false;
    }
    
    else if (frm.email.value == "") {
    	alert("Please enter your e-mail address.");
        frm.email.focus();
        return false;
    } 
    
    else if (!isEmail(frm.email.value)) {
    	alert("Invalid e-mail address.");
        frm.email.focus();
        return false;
    } 
		    
    else if (frm.email2.value == "") {
    	alert("Please re-enter your e-mail address.");
        frm.email2.focus();
        return false;
    } 
    
    else if (!isEmail(frm.email2.value)) {
    	alert("Invalid re-enter e-mail address.");
        frm.email2.focus();
        return false;
    } 
    
    else if ((frm.email.value) != (frm.email2.value)) {
        alert ("The e-mail and e-mail confirmation you typed in do not match. Please check.");
        frm.email.focus();
        return false;		        
    } 
    
    else if (frm.month.value == "") {
        alert ("Please pick your birth month.");
        frm.month.focus();
        return false;
    } 
		    
    else if (frm.day.value == "") {
        alert ("Please pick your birth day.");
        frm.day.focus();
        return false;
    } 
    
    else if (frm.year.value == "") {
        alert ("Please pick your birth year.");
        frm.year.focus();
        return false;
    } 
    
    else if (!isDate(frm.day.value, frm.month.value, frm.year.value)) {
        alert ("Invalid date of birth specified.");
        frm.month.focus();
        return false;
    } 
		    
    else if (frm.subject.value == "") {
        alert ("Please pick a subject for your message.");
        frm.subject.focus();
        return false;
    } 
    
    else if (frm.subject.options[frm.subject.selectedIndex].value == "Concern or Complaint" && frm.lotNumberExists.checked == false && frm.lotNumber.value == "") {
        alert ("Please, check if the lot number is not available.");
        frm.lotNumber.focus();
        return false;		        
    }
    
    else if (frm.lotNumber.value != "" && !isNumeric(frm.lotNumber.value)) {
    	alert("Invalid Lot Number.");
        frm.lotNumber.focus();
        return false;
    }
    
    else if (frm.upcCode.value != "" && !isNumeric(frm.upcCode.value)) {
    	alert("Invalid Upc Code.");
        frm.upcCode.focus();
        return false;
    }		    
		    
    else if (frm.comments.value == "") {
        alert ("You have not entered any comments.");
        frm.comments.focus();
        return false;	
    } 
    
    else if (GetRadioValue(frm.futurePromo) == null) {
        alert ("Please let us know if you want to be contacted in the future.");
        return false;		 
    } 
		    
    else if (!ValidateAge(13, frm.year.value, frm.month.value, frm.day.value)) {
    	setCookie('over13', 'yes');
		alert ("Sorry, you must be at least 13 years of age to use this function of the website.");
		return false;
	}
		    
	return true;
}

function resetForm(frm) {
    if (confirm("All fields above will be cleared.  Click OK to continue.")) {
        frm.reset();
    }
    return false;
}
   		
function openPopup (width, height, url, name) {
	var windowWidth = window.screen.width;
	var windowHeight = window.screen.height;
	
	var popupWidth = width;
	var popupHeight = height;
	
	var popupTop = (windowHeight - popupHeight) / 2;
	var popupLeft = (windowWidth - popupWidth) / 2;
	
	var features = "width=" +  popupWidth + ",height=" + popupHeight + ",top=" + popupTop + ",left=" + popupLeft;
	
	window.open(url, name, features);			
}   

function isNumberKey(evt) {
   var charCode = (evt.which) ? evt.which : event.keyCode
   if (charCode > 31 && (charCode < 48 || charCode > 57))
      return false;

   return true;
}

	function validatePage1(frm){		
		var els = frm.elements;

		for (var i = 0; i < els.length; i++) if (els[i].type == 'text') els[i].value = els[i].value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');

		if(frm.consumerId.value == 0  || frm.consumerId.value == ""){
			alert("An error occurred. The user's id is empty");
			return false;		
		} else if (GetRadioValue(frm.question1) == null){
			alert("Please, answer the first question.");
			return false;
		} else if (GetRadioValue(frm.question2) == null){
			alert("Please, answer the second question.");
			return false;
		} else if (frm.question3.value == ""){
			alert("Please, answer the first item of the third question.");
			frm.question3.focus();
			return false;
		} else if (!isNumeric(frm.question3.value)){
			alert("Invalid number.");
			frm.question3.focus();
			return false;			
		} else if (frm.question4.value == ""){
			alert("Please, answer the second item of the third question.");
			frm.question4.focus();
			return false;
		} else if (!isNumeric(frm.question4.value)){
			alert("Invalid number.");
			frm.question4.focus();
			return false;			
		} else if (frm.question5.value == ""){
			alert("Please, answer the third item of the third question.");
			frm.question5.focus();
			return false;
		} else if (!isNumeric(frm.question5.value)){
			alert("Invalid number.");
			frm.question5.focus();
			return false;			
		} else if (frm.question6.value == ""){
			alert("Please, answer the fourth item of the third question.");
			frm.question6.focus();
			return false;
		} else if (!isNumeric(frm.question6.value)){
			alert("Invalid number.");
			frm.question6.focus();
			return false;			
		} else if (frm.question7.value == ""){
			alert("Please, answer the fifth item of the third question.");
			frm.question7.focus();
			return false;
		} else if (!isNumeric(frm.question7.value)){
			alert("Invalid number.");
			frm.question7.focus();
			return false;
		} else {
			return true;
		}				
	}

	function validatePage2(frm){
		
		if(frm.consumerId.value == 0  || frm.consumerId.value == ""){
			alert("An error occurred. The user's id is empty");
			return false;		
		} else if (GetRadioValue(frm.question8) == null){
			alert("Please, answer the first item of the fourth question.");
			return false;
		} else if (GetRadioValue(frm.question9) == null){
			alert("Please, answer the second item of the fourth question.");
			return false;
		} else if (GetRadioValue(frm.question10) == null){
			alert("Please, answer the third item of the fourth question.");
			return false;
		} else if (GetRadioValue(frm.question11) == null){
			alert("Please, answer the fourth item of the fourth question.");
			return false;
		} else if (GetRadioValue(frm.question12) == null){
			alert("Please, answer the fifth item of the fourth question.");
			return false;
		} else {
			frm.submit();
			frm.subButton.disabled = "true";
			return true;
		}				
	}
		
-->
