	
	function trim(str)
	{	
		return str.replace(/^\s+|\s+$/g,"");	
	}
	
	function registerErrorMissingField (frm)
	{
	    var html = '<p class="v11-orange register-whoops"><strong>Whoops!</strong> Some of your information was missing.<br />Please complete all required fields.</p>';
			document.getElementById('errorbox').innerHTML = html;
			document.getElementById("register-1-left").style.paddingBottom = "20px";
		//frm.errorbox.innerHTML = html; 
	}
	
	function registerErrorUnder21 (frm)
	{
	   var html = '<p class="v11-orange register-whoops"><strong>Whoops!</strong><br />You must be at least 21 years of age to register for the website and enter the sweepstakes.<br />Please view our <a class="v11-orange register-whoops" href="privacy-policy.jsp" title="Privacy Policy">Privacy Policy</a> and <a class="v11-orange register-whoops" href="official-rules.jsp" title="Official Rules">Official Rules</a> </p>';
		//frm.errorbox.innerHTML = html;
		document.getElementById('errorbox').innerHTML = html; 
		document.getElementById("register-1-left").style.paddingBottom = "20px";
	}
	
	function myAccountErrorMissingField (frm)
	{
	    var html = '<p class="v11-orange register-whoops"><br /><strong>Whoops!</strong><br />Some of your information was missing.<br />Please complete all required fields.</p>'
	   			+  '<p class="v11-orange register-whoops">Thankyou!</p>'
				+	'<a class="link11-orange register-whoops" href="privacy-policy.jsp" title="Privacy Policy">Privacy Policy</a>';
			document.getElementById('message').innerHTML = html;			
		//frm.errorbox.innerHTML = html; 
	}
	
	
	
	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.expMonth.value='';
			frm.expYear.value='';
			frm.upcCode.value='';
			frm.productName.value='';
			frm.wherePurchased.value='';
		} else {
			document.getElementById('corctable').style.display='none';
			frm.lotNumber.value='';
			frm.expMonth.value='';
			frm.expYear.value='';
			frm.upcCode.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 resetForm(frm) {
	
	    if (confirm("All fields above will be cleared.  Click OK to continue.")) {
	    
	        frm.reset();
	    }
	    
	    return false;
	}
	
	function clearForm(frm) {
	
		if (frm != null) {
		
		    frm.reset();
		}
	}	
	 		
	function createAgeCookie(value) {
	 		
		age = (value != null && isNumeric(value)) ? value : 18;
		cookieName = "over" + age;   		
		setCookie(cookieName, 'yes');
	}
	 		
	function hasAgeCookie(value) {
	 		
		var age = (value != null && isNumeric(value)) ? value : 18;
		var cookieName = "over" + age;
	    var ageOK = getCookie(cookieName);		    
	    
	    if (ageOK == null) {
	    
	    	return false;
	    }
	    
	    return true;
	}
	 		
	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);			
	}
	
	/**
	 * Shows message, sets focus to desired element (if not focussed already), and returns "".
	 * If this is NS, or we cannot set focus, then an alert is displayed.
	 */
	function messageHelper(el, msg) {
		if (document.all == null || document.createElement == null || el == null || el.form.fancyValidation != true) return messageHelperOld(el, msg);
	
		if (el.select != null) el.select();
		if (el.form.focusEl == null) {
			if (el.formJsFocusProxy != null) {
				el.formJsFocusProxy.focus();
				el.form.focusEl = el.formJsFocusProxy; // don't repeatedly focus guys
			} else if (el.focus != null) {
				el.focus();
				el.form.focusEl = el; // don't repeatedly focus guys
			}
		}
	
		var pnm = el.name+SPAN_MESSAGE_PROMPT;
		var promptEl = document.all[pnm];
		if (promptEl == null) {
			promptEl = document.createElement("SPAN");
			el.parentElement.insertAdjacentElement("beforeEnd", promptEl);
			promptEl.className = "message";
			promptEl.id = pnm;
		}
		msg = replaceIllegals(msg, "\r\n", "  ");
		el.form.messageDisplayed = true;
		promptEl.innerText = msg;
		promptEl.style.display = 'inline';
	
		return true;
	}
	
	function limitCharOfTextarea(areaName, limit) {
		if (areaName.value.length>limit) {
			areaName.value = areaName.value.substring(0,limit);
		}
	}
	
	function cleanTextarea(areaName) {
		if (areaName.value == 'Please type your comments here (750 characters)') {
			areaName.value = '';
		}
	}
	
	
/** 
* Safe Submit - Just submit the form if the validate function returns true 
* and disable the onclick function form the tag that calls it, otherwise 
* do nothing 
* 
* aID = id name of the tag
* validateFuncRet = return from validate function used to submit the form
* form = form to be submit 
*
* Example: <a id= "abc" onclick = "javascript: safaSubmit ('abc',validateABC (document.formABC), document.formABC);"> imagem ou link </a> 
*/

function safeSubmit (aId, form)
{
	 var isValid = validateRegister();

     if (isValid == true)
     {
         document.getElementById(aId).onclick = '#';
     }
     
     return isValid;
}

function safeSubmitContactUs(form) {
	var isValid = validateContactUsForm(form);

    if (isValid) {
        form.submit();
    }
}
