	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) {
		
		var subtotal_prod = 149.85 * parseFloat(frm.QTY.value);
		var ship_cost = parseFloat(frm.SHIP_METHOD.value);
		
		//calc and write shipping subtotal
		frm.SUBTOTAL_SHIP.value = round_decimals(ship_cost,2);
		
		//calc and write grandtotal
		grand_total = ship_cost + subtotal_prod;
		frm.GRAND_TOTAL.value = round_decimals(grand_total,2); 
		
		//alert(typeof state_tax);
	}
	

	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'; 
			} 
		} 
	} 
	
	
//------------------ 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 isInvalidEmailField( f ) {
	if ( isBlank( f ) )
		return true;
	var address = f.value;
	var atLoc = address.indexOf( '@' );
	var dotLoc = address.lastIndexOf( '.' );
	if ( ( atLoc <= 0 ) || ( dotLoc <= 0 ) || ( dotLoc < atLoc ) || ( dotLoc-atLoc == 1 ) || ( ( dotLoc + 1 ) == address.length ) ) return true;
	else
		return false;
}

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 ( isInvalidEmailField( document.getElementById("email") ) ) {
		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 ( !isValidPhone( document.getElementById("phone").value) ){
		msg += "Phone Number is invalid.\n";
	}
	else if ( !isValidAreaCode(document.getElementById("phoneAreaCodeInput").value) || !isValidPhonePrefix(document.getElementById("phonePrefixInput").value) ){
		msg += "Phone Number is invalid.\n";
	}
	
	
	
	if ( msg.length > 0 ) {
		alert ( msg );
		return false;
	} else {
		return true;
	}
	

}
	
	
	
	
	
function validateBilling(){
	
	
	if ( document.getElementById('use_shipping_info').checked )
		alert( 'checked' );
	else
		alert( 'not checked');
		
		
	return false;
/*
	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 ( isInvalidEmailField( document.getElementById("email") ) ) {
		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 ( !isValidPhone( document.getElementById("phone").value) ){
		msg += "Phone Number is invalid.\n";
	}
	else if ( !isValidAreaCode(document.getElementById("phoneAreaCodeInput").value) || !isValidPhonePrefix(document.getElementById("phonePrefixInput").value) ){
		msg += "Phone Number is invalid.\n";
	}
	
	
	
	if ( msg.length > 0 ) {
		alert ( msg );
		return false;
	} else {
		return true;
	}
*/	

}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	