	function addLoadEvent(func) {
	  var oldonload = window.onload;
	  if (typeof window.onload != 'function') {
		window.onload = func;
	  } else {
		window.onload = function() {
		  if (oldonload) {
			oldonload();
		  }
		  func();
		}
	  }
	}
	
	
	function CalculateTotal(frm) {
		
		// Update product subtotal
		frm.SUBTOTAL_PROD.value = round_decimals(parseFloat(frm.price.value) * parseFloat(frm.QTY.value), 2);
		
		// Update shipping
		frm.SUBTOTAL_SHIP.value = round_decimals(parseFloat(frm.SHIP_METHOD.value), 2);
		
		// Update grand total
		frm.GRAND_TOTAL.value = round_decimals(parseFloat(frm.SUBTOTAL_PROD.value) + parseFloat(frm.SUBTOTAL_SHIP.value), 2); 
	}

	function round_decimals(original_number, decimals) {
		var result1 = original_number * Math.pow(10, decimals)
		var result2 = Math.round(result1)
		var result3 = result2 / Math.pow(10, decimals)
		return pad_with_zeros(result3, decimals)
	}

	function pad_with_zeros(rounded_value, decimal_places) {

		// Convert the number to a string
		var value_string = rounded_value.toString()
		
		// Locate the decimal point
		var decimal_location = value_string.indexOf(".")

		// Is there a decimal point?
		if (decimal_location == -1) {
			
			// If no, then all decimal places will be padded with 0s
			decimal_part_length = 0;
			
			// If decimal_places is greater than zero, tack on a decimal point
			value_string += decimal_places > 0 ? "." : "";
		}
		else {

			// If yes, then only the extra decimal places will be padded with 0s
			decimal_part_length = value_string.length - decimal_location - 1;
		}
		
		// Calculate the number of decimal places that need to be padded with 0s
		var pad_total = decimal_places - decimal_part_length;
		
		if (pad_total > 0) {
			
			// Pad the string with 0s
			for (var counter = 1; counter <= pad_total; counter++) 
				value_string += "0";
			}
		return value_string;
	}
	
	
	
	function hidehtml(pass) { 
  
		var divs = document.getElementsByTagName('div'); 

		for(i=0;i<divs.length;i++){ 
			if(divs[i].id.match(pass)){//if they are 'see' divs 

			if (document.getElementById) // DOM3 = IE5, NS6 
				divs[i].style.display='none';// show/hide 

			else 
				if (document.layers) // Netscape 4 
					document.layers[divs[i]].display = 'hidden'; 
				else // IE 4 
					document.all.hideShow.divs[i].visibility = 'hidden'; 

			} 
		} 
	} 


	function showhtml(pass) { 

		var divs = document.getElementsByTagName('div'); 
		for(i=0;i<divs.length;i++){ 
			if(divs[i].id.match(pass)){ 
				if (document.getElementById) 

					divs[i].style.display='';// show/hide 

				else 
				if (document.layers) // Netscape 4 
					document.layers[divs[i]].display = 'visible'; 
				else // IE 4 
					document.all.hideShow.divs[i].visibility = 'visible'; 
			} 
		} 
	} 
	
	
	function paginate(pagi_x){	
			hidehtml('pagi_1');
			hidehtml('pagi_2');
			hidehtml('pagi_3');
			hidehtml('pagi_4');
			hidehtml('pagi_5');
			hidehtml('pagi_6');
			hidehtml('pagi_7');
			showhtml(pagi_x);
		}
	
	function paginateVideo(vid_x){
		hidehtml('vid_1');
		hidehtml('vid_2');
		hidehtml('vid_3');
		showhtml(vid_x);
	}
	
//------------------ FORM VALIDATORS  ----------------------//

var numb = '0123456789';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

function isBlank(field) {
	if ( field.value == null || field.value == "") {
		return true;
	} else {
		return false;
	}
}

function isValid(parm,val) {
	if (parm == "") return true;
		for (i=0; i<parm.length; i++) {
			if (val.indexOf(parm.charAt(i),0) == -1) return false;
		}
	return true;
}

function isNum(parm) {return isValid(parm,numb);}
function isLower(parm) {return isValid(parm,lwr);}
function isUpper(parm) {return isValid(parm,upr);}
function isAlpha(parm) {return isValid(parm,lwr+upr);}
function isAlphanum(parm) {return isValid(parm,lwr+upr+numb);}

function isNumeric( fText ) {
	var lowCode = 48;
	var highCode = 57;
	var isNumber = true;
	var charCode;

	for (i = 0; i < fText.length && isNumber == true; i++) {
		charCode = fText.charCodeAt(i);
		if ( charCode < lowCode || charCode > highCode ) {
			isNumber = false;
		}
	}
	return isNumber;
}

function isValidPhoneSegment( f, length ) {
	if ( ! isBlank( f ) && isNumeric( f.value ) && ( f.value.length == length ) ) {
		return true;
	} else {
		return false;
	}
}

function isValidAreaCode( f ) {
	if( !(/^[2-9]\d{2}$/.test(f)) || (/^[5]{3}$/.test(f)) )
		return false;
	else
		return true;
}

function isValidPhonePrefix( f ) {
	if(/^[5]{3}$/.test(f))
		return false;
	else
		return true;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
}

function isAnytown ( f ) {
	if( /anytown/.test( f.toLowerCase() ) ){
		return true;
	}else {
		return false;}
}

function isInteger(s)
{   var i;
	for (i = 0; i < s.length; i++)
	{   
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}


function stripCharsInBag(s, bag)
{   var i;
	var returnString = "";
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++)
	{   
		// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

function isValidPhone ( strPhone ) {

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- .";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

s=stripCharsInBag(strPhone,validWorldPhoneChars);

if ( !(/^[2-9]\d{9}$/.test(s)) || (/^[5]{3}\d{7}$/.test(s)) || (/^\d{3}[5]{3}\d{4}$/.test(s)) )
{
	return false;
}
else
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function isSwear ( f ) {
	// Enter the words to be filtered in the line below:
	var badwords=new Array("ass","arse","butt","assbang","assclown","assface","assfuck","asshole","asslicker","assmunch","asswipe","bastard","bitch","blowjob","blowme","boner","bullshit","chinc","chink","chode","clit","cock","cocksucker","cooter","cum","cunt","damn","dickhead","dickhole","dicks","dickwod","dildo","dipshit","dookie","douche","douchebag","dumbass","faggot","fagtard","fatass","fuck","fucker","fuckface","fuckhole","fuckin","fucking","fucktard","fuckwad","fuckwit","goddamn","gook","hell","jackass","jizz","kike","kootch","kyke","motherfucker","motherfucking","nigga","nigger","niglet","panooch","peckerhead","pissed","poon","poonany","prick","punta","pussy","puto","queef","queer","queerbait","rimjob","scrote","shit","shitface","shitfaced","shithead","shitter","shittiest","shitty","skank","slut","slutbag","spic","spick","thundercunt","titfuck","tit","tits","twat","twats","vagina","wank","whore","wop");
	
	var badwords_inline=new Array("assbang","assclown","assface","assfuck","asshole","asslicker","assmunch","asswipe","bastard","bitch","blowjob","blowme","bullshit","cocksucker","cooter","cunt","dickhead","dickhole","dickwod","dildo","dipshit","dookie","douchebag","dumbass","faggot","fagtard","fatass","fuck","goddamn","jackass","kyke","nigger","niglet","panooch","peckerhead","pissed","poonany","pussy","queef","queer","queerbait","rimjob","shit","slutbag","thundercunt","titfuck","vagina","whore");

	var booBad = 0;
	fvalue = f;  // entered words  

	wordsArray = fvalue.split(" ");
	wordsNospace = fvalue.toLowerCase();
	
	//check individual words
	for (i = 0; i < badwords.length; i++)
	{

		for ( j=0; j < wordsArray.length; j++)
		{
			if ( (wordsArray[j].toLowerCase() == badwords[i]))
			{
				booBad = 1;

			}
		}
	}
	
	//check for swears inside words
	for (k = 0; k < badwords_inline.length; k++)
	{

		for ( m = 0; m < fvalue.length; m++)
		{
			if (badwords_inline[k] == fvalue.substr(m, badwords_inline[k].length ) )
			{
				booBad = 1;

			}
		}
	}
	
	if (booBad != 1) { return false; }
	else {return true;}
} // end 

//-------Check fields for RFT landing page---------//




function validateShipping(){	
	
	var msg = "";
	
	//firstname
	if ( isBlank(document.getElementById('first_name')) ) {
		msg += "First Name is required.\n";
	}
	else if( document.getElementById("first_name").value.length < 2){
		msg += "First Name is invalid.\n";
	}
	else if( isSwear(document.getElementById("first_name").value)){
		msg += "First Name is invalid.\n";
	}
	
	//lastname
	if ( isBlank( document.getElementById("last_name") ) ) {
		msg += "Last Name is required.\n";
	}else if( document.getElementById("last_name").value.length < 2){
		msg += "Last Name is invalid.\n";
	}
	else if( isSwear(document.getElementById("last_name").value)){
		msg += "Last Name is invalid.\n";
	}
	
	//address
	if ( isBlank( document.getElementById("street1") ) && isBlank( document.getElementById("street2") ) ) {
		msg += "Street Address is required.\n";
	}else if( isSwear(document.getElementById("street1").value) || isSwear(document.getElementById("street2").value) ){
		msg += "Street Address is invalid.\n";
	}
	
	//city
	if ( isBlank( document.getElementById("city") ) ) {
		msg += "City is required.\n";
	}else if ( isAnytown( document.getElementById("city").value ) ) {
		msg += "City is invalid.\n";
	}
	else if( isSwear(document.getElementById("city").value)){
		msg += "City is invalid.\n";
	}
	
	//state
	if ( isBlank( document.getElementById("state") ) ) {
		msg += "State is required.\n";
	}else if (document.getElementById("state").value.length != 2){
		msg += "State is invalid.\n";
	}else if (!isAlpha(document.getElementById("state").value)){
		msg += "State is invalid.\n";
	}
	
	//zip
	if ( isBlank( document.getElementById("zip") ) ) {
		msg += "Zip code is required.\n";
	}else if (document.getElementById("zip").value.length < 5){
		msg += "Zip code is invalid.\n";
	}
	else if (!isNumeric(document.getElementById("zip").value)){
		msg += "Zip code is invalid.\n";
	}
	
	//country
	if ( isBlank( document.getElementById("country") ) ) {
		msg += "Country is required.\n";
	}
	else if( isSwear(document.getElementById("country").value)){
		msg += "Country is invalid.\n";
	}
	
	//email
	if( isBlank( document.getElementById("email") ) ) {
		msg += "Email is required.\n";
	}
	else if ( echeck( document.getElementById("email").value ) == false ) {
		msg += "Email Address is invalid.\n";
	}
	else if( isSwear(document.getElementById("email").value)){
		msg += "Email Address is invalid.\n";
	}
	
	//phone
	if ( !isValidPhoneSegment( document.getElementById("phone1"), 3 ) || !isValidPhoneSegment( document.getElementById("phone2"), 3 ) || !isValidPhoneSegment( document.getElementById("phone3"), 4 ) ) {
		msg += "Valid Phone Number is required.\n";
	}
	else if ( !isValidAreaCode(document.getElementById("phone1").value) || !isValidPhonePrefix(document.getElementById("phone2").value) ){
		msg += "Phone Number is invalid.\n";
	}
	
	
	
	if ( msg.length > 0 ) {
		alert ( msg );
		return false;
	} else {
		return true;
	}
	

}
	
	
	
	
	
function validateBilling(){
	
	var msg = "";
	
	if ( !document.getElementById('use_shipping_info').checked ) {
		//firstname
		if ( isBlank(document.getElementById('first_name')) ) {
			msg += "First Name is required.\n";
		}
		else if( document.getElementById("first_name").value.length < 2){
			msg += "First Name is invalid.\n";
		}
		else if( isSwear(document.getElementById("first_name").value)){
			msg += "First Name is invalid.\n";
		}
		
		//lastname
		if ( isBlank( document.getElementById("last_name") ) ) {
			msg += "Last Name is required.\n";
		}else if( document.getElementById("last_name").value.length < 2){
			msg += "Last Name is invalid.\n";
		}
		else if( isSwear(document.getElementById("last_name").value)){
			msg += "Last Name is invalid.\n";
		}
		//address
		if ( isBlank( document.getElementById("street1") ) && isBlank( document.getElementById("street2") ) ) {
			msg += "Street Address is required.\n";
		}else if( isSwear(document.getElementById("street1").value) || isSwear(document.getElementById("street2").value) ){
			msg += "Street Address is invalid.\n";
		}
		//city
		if ( isBlank( document.getElementById("city") ) ) {
			msg += "City is required.\n";
		}else if ( isAnytown( document.getElementById("city").value ) ) {
			msg += "City is invalid.\n";
		}
		else if( isSwear(document.getElementById("city").value)){
			msg += "City is invalid.\n";
		}
		//state
		if ( isBlank( document.getElementById("state") ) ) {
			msg += "State is required.\n";
		}else if (document.getElementById("state").value.length != 2){
			msg += "State is invalid.\n";
		}else if (!isAlpha(document.getElementById("state").value)){
			msg += "State is invalid.\n";
		}
		//zip
		if ( isBlank( document.getElementById("zip") ) ) {
			msg += "Zip code is required.\n";
		}else if (document.getElementById("zip").value.length < 5){
			msg += "Zip code is invalid.\n";
		}
		else if (!isNumeric(document.getElementById("zip").value)){
			msg += "Zip code is invalid.\n";
		}
		//country
		if ( isBlank( document.getElementById("country") ) ) {
			msg += "Country is required.\n";
		}
		else if( isSwear(document.getElementById("country").value)){
			msg += "Country is invalid.\n";
		}
		//email
		if( isBlank( document.getElementById("email") ) ) {
			msg += "Email is required.\n";
		}
		else if ( echeck( document.getElementById("email").value ) == false ) {
			msg += "Email Address is invalid.\n";
		}
		else if( isSwear(document.getElementById("email").value)){
			msg += "Email Address is invalid.\n";
		}
		
		//phone
		if ( !isValidPhoneSegment( document.getElementById("phone1"), 3 ) || !isValidPhoneSegment( document.getElementById("phone2"), 3 ) || !isValidPhoneSegment( document.getElementById("phone3"), 4 ) ) {
			msg += "Valid Phone Number is required.\n";
		}
		else if ( !isValidAreaCode(document.getElementById("phone1").value) || !isValidPhonePrefix(document.getElementById("phone2").value) ){
			msg += "Phone Number is invalid.\n";
		}
	}
	
	//card type
	if ( isBlank( document.getElementById("card_type") ) ) {
			msg += "Please select card type.\n";
	}
	
	if ( isBlank( document.getElementById("name_on_card") ) ) {
			msg += "Please enter your name as it appears on the card.\n";
	}
		
	if ( isBlank( document.getElementById("card_number") ) ) {
			msg += "Please enter the card number.\n";
	}else if(!isNumeric(document.getElementById("card_number").value) ){
			msg += "Card number is invalid.\n";
	}
		
	if ( isBlank( document.getElementById("card_exp") ) ) {
			msg += "Please enter the expiration date.\n";
	}else if(!isNumeric(document.getElementById("card_exp").value) || document.getElementById("card_exp").value.length < 4 ){
			msg += "Expiration date is invalid.\n";
	}
		
	
	
	if ( msg.length > 0 ) {
		alert ( msg );
		return false;
	} else {
		if ( !document.getElementById('agreeVerify').checked ) {
			alert("Please verify that you understand the terms of the Risk Free Trial");
			return false;
		}else{
			return true;
		}
	}
	
	

}
	
	
	
function validatePopup(){	
	
	var msg = "";
	
	//firstname
	if ( isBlank(document.getElementById('fname')) ) {
		msg += "First Name is required.\n";
	}
	else if( document.getElementById("fname").value.length < 2){
		msg += "First Name is invalid.\n";
	}
	else if( isSwear(document.getElementById("fname").value)){
		msg += "First Name is invalid.\n";
	}
	
	//lastname
	if ( isBlank( document.getElementById("lname") ) ) {
		msg += "Last Name is required.\n";
	}else if( document.getElementById("lname").value.length < 2){
		msg += "Last Name is invalid.\n";
	}
	else if( isSwear(document.getElementById("lname").value)){
		msg += "Last Name is invalid.\n";
	}
	
	//address
	if ( isBlank( document.getElementById("adr1") ) && isBlank( document.getElementById("adr2") ) ) {
		msg += "Street Address is required.\n";
	}else if( isSwear(document.getElementById("adr1").value) || isSwear(document.getElementById("adr2").value) ){
		msg += "Street Address is invalid.\n";
	}
	
	//city
	if ( isBlank( document.getElementById("city") ) ) {
		msg += "City is required.\n";
	}else if ( isAnytown( document.getElementById("city").value ) ) {
		msg += "City is invalid.\n";
	}
	else if( isSwear(document.getElementById("city").value)){
		msg += "City is invalid.\n";
	}
	
	//state
	if ( isBlank( document.getElementById("state") ) ) {
		msg += "State is required.\n";
	}else if (document.getElementById("state").value.length != 2){
		msg += "State is invalid.\n";
	}else if (!isAlpha(document.getElementById("state").value)){
		msg += "State is invalid.\n";
	}
	
	//zip
	if ( isBlank( document.getElementById("zip") ) ) {
		msg += "Zip code is required.\n";
	}else if (document.getElementById("zip").value.length < 5){
		msg += "Zip code is invalid.\n";
	}
	else if (!isNumeric(document.getElementById("zip").value)){
		msg += "Zip code is invalid.\n";
	}
	
	//email
	if( isBlank( document.getElementById("email") ) ) {
		msg += "Email is required.\n";
	}
	else if ( echeck( document.getElementById("email").value ) == false ) {
		msg += "Email Address is invalid.\n";
	}
	else if( isSwear(document.getElementById("email").value)){
		msg += "Email Address is invalid.\n";
	}
	
	//phone
	if ( !isValidPhoneSegment( document.getElementById("phone1"), 3 ) || !isValidPhoneSegment( document.getElementById("phone2"), 3 ) || !isValidPhoneSegment( document.getElementById("phone3"), 4 ) ) {
		msg += "Valid Phone Number is required.\n";
	}
	else if ( !isValidAreaCode(document.getElementById("phone1").value) || !isValidPhonePrefix(document.getElementById("phone2").value) ){
		msg += "Phone Number is invalid.\n";
	}
	
	
	
	if ( msg.length > 0 ) {
		alert ( msg );
		return false;
	} else {
		return true;
	}
	

}	
	
	
	
	
	
	
	
	
	

	
	
	
	
	
	
	