/*
Copyright 2006 Active Media Architects, Inc. - www.activema.com
Usage of these scripts is limited to their original intent as developed and deployed for Activa Commerce Website by Active Media Architects, Inc. Copying, selling or distributing of these scripts, in whole or in part, is strictly prohibited.
*/


	///////////////////////////////////////
	// Frame Buster
	///////////////////////////////////////

if (window != window.top)
  top.location.href = location.href;


	///////////////////////////////////////
	// On-Click-Pop-Center
	///////////////////////////////////////
	// Requires "onClick="NewWindow(this.href,'title','400','300','no');return false;"" in the A HREF tag
	// Example: <a href="doc.html" onClick="NewWindow(this.href,'title','400','300','no');return false;">LINK</a>

function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes,,toolbar=no,menubar=no'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}




	///////////////////////////////////////
	// Auto-Select Field
	///////////////////////////////////////
	// Requires "onLoad=ready()" in the BODY tag
	// Example: <body onLoad=ready()>
	// Requires form name to match where it reads "form" in script
	// Example: <form name="form">
	// Requires form field name to match where it reads "field" in script
	// Example: <input name="field">

function ready(){document.form.field.focus();}



	///////////////////////////////////////
	// Form Validation
	///////////////////////////////////////

function validateGiftCertificate ( form ) {
	return (
				 checkSelect(form.elements["amount"],"V","","Please enter an amount.",false) &&
				 checkSelect(form.elements["recipient_name"],"V","Please enter recipient's name",false) &&
				 checkSelect(form.elements["recipient_email"],"V","","Please enter your recipient's E-mail Address.",false) &&
				 checkEmail(form.elements["recipient_email"],false) &&
				 checkSelect(form.elements["recipient_email"],"V","joe@example.com","Please supply valid E-mail Address.",false));
}

function validateContact(form) {
	return (
				 checkSelect(form.elements["firstname"],"V","","Please enter your First Name.",false) &&
				 checkSelect(form.elements["lastname"],"V","","Please enter your Last Name.",false) &&
				 checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["email"],false) &&
				 checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
				 checkSelect(form.elements["message"],"V","","Please provide us with your Message.",false));
}

function validateSubmitQuestion(form) {
	return (
				 checkSelect(form.elements["submitquestion[fullname]"],"V","","Please enter your Your Name.",false) &&
				 checkSelect(form.elements["submitquestion[email]"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["submitquestion[email]"],false) &&
				 checkSelect(form.elements["submitquestion[email]"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
				 checkSelect(form.elements["submitquestion[question]"],"V","","Please provide us with your Question.",false));
}

function validateSendToFriend(form) {
	return (
				 checkSelect(form.elements["to_name"],"V","","Please enter your Friend's Name.",false) &&
				 checkSelect(form.elements["to_email"],"V","","Please enter your Friend's E-mail.",false) &&
				 checkEmail(form.elements["to_email"],false) &&
				 checkSelect(form.elements["to_email"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
				 checkSelect(form.elements["to_name"],"V","","Please enter your Name.",false) &&
				 checkSelect(form.elements["from_email"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["from_email"],false) &&
				 checkSelect(form.elements["from_email"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
				 checkSelect(form.elements["message"],"V","","Please provide us with your Message.",false));
}

function validateEmailSignup(form) {
	return (
				 checkSelect(form.elements["fullname"],"V","","Please enter Your Name.",false) &&
				 checkSelect(form.elements["fullname"],"V","Your Name","Please enter your real Name.",false) &&
				 checkSelect(form.elements["fullname"],"V","your name","Please enter your real Name.",false) &&
				 checkSelect(form.elements["fullname"],"V","my name","Please enter your real Name.",false) &&
				 checkSelect(form.elements["fullname"],"V","name","Please enter your real Name.",false) &&
				 checkSelect(form.elements["fullname"],"V","asdf","Please enter your real Name.",false) &&
				 checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["email"],false) &&
				 checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false));
}

function validateUnsub(form) {
	return (
				 checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["email"],false) &&
				 checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false));
}

function validatePay(form) {
	return (
				//validateBillingAddress(form) &&
				 //checkSelect(form.elements["billing_id"],"V","","You must select a Credit Card",false) &&
				 checkCheckbox(form.elements['compliance_standards'], 'Please agree to our recycling compliance standards.') &&
				 checkSelect(form.elements["billing[fullname]"],"V","","Please enter the Name exactly as it appears on the Credit Card.",false) &&
				 checkSelect(form.elements["billing[cc_num]"],"V","","You have chosen to pay by Credit Card. Please enter your Credit Card Number before continuing.",false) &&
				 checkSelect(form.elements["billing[exp_month]"],"V","00","Please select the Month this credit card expires.",false) &&
				 checkSelect(form.elements["billing[exp_year]"],"V","00","Please select the Year this credit card expires.",false) &&
				 checkSelect(form.elements["billing[ccv]"],"V","","Please enter your credit card's 3-digit Identification Number.",false));
}

function checkCheckbox(ele, s, required) {
	required = required | false;
	// no element and its not required dont error
	if ( !ele && !required ) {
		return true;
	}
	return ele.checked? true : warnSelectInvalid(ele, s);
}

var copied_from_main = false;
function pailMailPickUpToggle(checked) {
	
	if(checked) {
		showID('pickup_company_div');
		showID('pickup_name_div');
		showID('pickup_address_div');
		showID('pickup_city_div');
		showID('pickup_state_div');
		showID('pickup_zip_div');
		showID('pickup_phone_div');
		showID('pickup_closing_time_div');
		showID('pickup_building_entrance_div');
		showID('pickup_location_div');
		
		if (!copied_from_main) {
			copy_value('company','pickup_company');
			copy_value('state','pickup_state');
			copy_value('city','pickup_city');
			copy_value('zip','pickup_zip');
			copy_value('phone','pickup_phone');
			did('pickup_name').value = did('firstname').value + ' ' + did('lastname').value;
			copied_from_main = true;
		}
		
	} else {
		hideID('pickup_company_div');
		hideID('pickup_name_div');
		hideID('pickup_address_div');
		hideID('pickup_city_div');
		hideID('pickup_state_div');
		hideID('pickup_zip_div');
		hideID('pickup_phone_div');
		hideID('pickup_closing_time_div');
		hideID('pickup_building_entrance_div');
		hideID('pickup_location_div');
	}
	
	function copy_value( from_id, to_id ) {
		try {
			did(to_id).value = did(from_id).value;
		} catch (e) { }
	}
}

function validateSignin(form) {
	return (
				 checkSelect(form.elements["loginemail"],"V","","Please enter your E-mail Address.",false) &&
				 checkEmail(form.elements["loginemail"],false) &&
				 checkSelect(form.elements["loginemail"],"V","joe@example.com","Please supply valid E-mail Address.",false) &&
				 checkSelect(form.elements["password"],"V","","Please enter your Password.",false));
}

function validatePO(form)
{
	return checkSelect(form.elements["po_number"],"V","","Please enter the PO Number.",false);

}//end validatePO

function validateExpress(form)
{
	if (
		checkSelect(form.elements["email_address"],"V","","Please enter your email address.",false)
	) {
		return validateShipping(form);
	}

	return false;
}

function validateNewAccount(form)
{
	if(form.elements["fullname"]) {
		if(! checkSelect(form.elements["fullname"],"V","","Please enter your full name.",false)) {
			return false;
		}
	}
	if(form.elements["firstname"]) {
		if(! checkSelect(form.elements["firstname"],"V","","Please enter your first name.",false)) {
			return false;
		}
	}
	if(form.elements["lastname"]) {
		if(! checkSelect(form.elements["lastname"],"V","","Please enter your last name.",false)) {
			return false;
		}
	}
	/*if(form.elements["client_code"]) {
		if(! checkSelect(form.elements["client_code"],"V","","Please enter your client code.",false)) {
			return false;
		}
	}*/
	if ( form.elements['state_id']) {
		if ( ! checkSelect(form.elements['state_id'], 'V', '', 'Please select your state.', false) ) {
			return false;
		}
	}
	return (
		checkSelect(form.elements["account[email]"],"V","","Please enter your E-mail.",false) &&
		checkEmail(form.elements["account[email]"],false) &&
		checkSelect(form.elements["account[email]"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
		checkSelect(form.elements["account[password1]"],"V","","Please create a Password.",false) &&
		checkSelect(form.elements["account[password2]"],"V","","Please confirm your Password.",false)
	);
}

function validateNewAccountAtCheckout(form) {
	return (validateNewAccount(form) && validateShipping(form));
}

function validateAddAddress(form) {
	switch (form.elements['address[country]'].value) {
		case 'US':
		case '213':
			state_field = 'address[state]'; break;
		case 'CA':
		case '38':
			state_field = 'address[province]'; break;
		default:
			state_field = 'address[other]'; break;
	}

	return (
		checkSelect(form.elements["address[country]"],"V","","Please select your Country.",false) &&
		checkSelect(form.elements["address[address]"],"V","","Please enter your Address.",false) &&
		checkSelect(form.elements["address[city]"],"V","","Please enter your City.",false) &&
		checkSelect(form.elements[state_field],"V","","Please enter your State/Province.",false) &&
		checkSelect(form.elements['address[zip]'],'V','','Please enter your Zip/Postal Code.', false) &&
		checkSelect(form.elements['address[phone]'],'V','','Please enter your Phone Number.', false)
	);
}

function validateShipping(form)
{
	var stateField = "shipping[state]";
	if ( form.elements["shipping[country]"].value == 38 || form.elements["shipping[country]"].value == 'CA' ) {
		stateField = "shipping[province]";
	} else if ( form.elements["shipping[country]"].value != 213 && form.elements["shipping[country]"].value != 'US' ) {
		stateField = "shipping[other]";
	}
	
	return (
		checkSelect(form.elements["shipping[country]"],"V","","Please enter the shipping country.",false) &&
		checkSelect(form.elements["shipping[fullname]"],"V","","Please enter the shipping full name.",false) &&
		checkSelect(form.elements["shipping[address]"],"V","","Please enter the shipping Address.",false) &&
		checkSelect(form.elements["shipping[city]"],"V","","Please enter the shipping City.",false) &&
		checkSelect(form.elements[stateField],"V","","Please enter the shipping State/Prov.",false) &&
		checkSelect(form.elements["shipping[zip]"],"V","","Please enter the shipping ZIP.",false) 
		//checkSelect(form.elements["shipping[phone]"],"V","","Please enter the shipping Phone.",false)
	);
}

function validateSearch(form)
{
	return (
		checkString(form.elements['keyword'], 'A keyword is required to search', false)
	);	
}

function validateStockNotification(form)
{
	return (
		checkSelect(form.elements["fullname"],"V","","Please enter Your Name.",false) &&
		checkSelect(form.elements["email"],"V","","Please enter your E-mail Address.",false) &&
		checkEmail(form.elements["email"],false) &&
		checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false)
	);
}

function validateProductComment(form){
	
	if (
		checkSelect(form.elements["customer"],"V","","Please enter your name.",false) &&
		checkSelect(form.elements["rating"],"V","","Please include a product rating.",false) &&
		checkSelect(form.elements["headline"],"V","","Please enter a headline.",false) &&
		checkSelect(form.elements["comment_text"],"V","","Please enter a comment.",false)
	){
		var x = form.elements['rating'].value;
		if(x >= 0 && x <= 10){
			return true;
		}
		alert('Your rating must be a number between 0 and 10.');
		
	}
	return false;
}

function LoginOptionCheck(myself, hasCookie) {

	frm = document.forms['new_login'];
	// if the new Customer item is checked
	var elem_pass_new = document.getElementById('newcustomerpassword');
	var elem_pass_old = document.getElementById('returningcustomerpassword');

	if ( myself.value == "new" ) {
		elem_pass_old.disabled = true;
		elem_pass_old.style.display = "none";
		elem_pass_new.disabled = true;
		elem_pass_new.style.display = "";
	} else {

		elem_pass_old.disabled = false;
		elem_pass_old.style.display = "";
		elem_pass_new.disabled = true;
		elem_pass_new.style.display = "none";
		frm.elements['loginemail'].focus();

	}

	frm.elements['loginemail'].focus();
}

function focusLoginField() {
	if ( typeof(document.new_login) != "undefined" ) {
		document.new_login.loginemail.focus();
	}
}

function loadPreview() {

	try {
		var body_obj = opener.document.getElementById("wysiPlainTextarea1");
		var headline_obj = opener.document.getElementById("headline");
		var child_head = document.getElementById("headline");
		var child_body = document.getElementById("body");

		var caption_value = window.opener.document.getElementById("caption").value;
		var child_caption = document.getElementById("img_caption");
	} catch (e) {
		try {
			console.debug(e);
		} catch (e2) {
			
		}
	}
		
	if ( caption_value != '' && child_caption != null ) {

		child_caption.innerHTML = caption_value;
	}
	child_head.innerHTML = headline_obj.value;
	child_body.innerHTML = body_obj.value;

}

function fadeout() {
	for (var iterator = 0; iterator < arguments.length; iterator++) {
		arguments[iterator].value = '';
		arguments[iterator].disabled = true;
	}
}

function fadein() {
	for (var iterator = 0; iterator < arguments.length; iterator++) {
		arguments[iterator].disabled = false;
	}
	arguments[1].focus();
	arguments[1].select();
}

function quantity_check(frm)
{
	if ( frm.elements['qty'].value < 1 || !validateInteger(frm.elements['qty'].value) ) {
		alert("Quantity must be an integer greater than 0");
		return false;
	}
}

function multiple_quantity_check(frm)
{
	for ( var i=0; i<arr_content_index.length; i++ ) {
		if ( !validateInteger(frm.elements['update[' + arr_content_index[i] + ']'].value) ) {
 			alert("Quantity must be an integer greater than 0");
			return false;
		}
	}
}

function validateInteger( strValue ) {

  var objRegExp  = /(^-?\d\d*$)/;

  return objRegExp.test(strValue);
}

/**
  * pops up a window a fraction of the size of the current one
  */
function popup(url) {
	var ratio = 0.75;
	var def_x = 800;
	var	def_y = 600;
	//get current window's dimensions
	parent_x = document.documentElement.clientWidth;
	if (!parent_x) parent_x = document.body.clientWidth;
	if (!parent_x) parent_x = window.innerWidth;
	if (!parent_x) parent_x = def_x;
	parent_y = document.documentElement.clientHeight;
	if (!parent_y) parent_y = document.body.clientHeight;
	if (!parent_y) parent_y = window.innerHeight;
	if (!parent_y) parent_y = def_y;
	//end get current window's dimensions
	//calculate child dimensions
	var child_x = ratio * parent_x;
	var child_y = ratio * parent_y;
	//end calculate child dimensions
	//popup the window
	window.open(url, "pop_window", "status=1, scrollbars=1, width="+child_x+", height="+child_y);
	//end popup the window
	return false;
}

//lu_unescape(_input) unescapes code which has been escaped for the live updater
function lu_unescape( _input) {
	output = _input;
	output = output.replace(/#lt#/g, "<");
	output = output.replace(/#rt#/g, ">");
	return output;
}

function cartAction(product_id, action)
{
	var frm = document.getElementById('frmCart');

	if ( frm.elements['product_id'] ) {
		frm.elements['product_id'].value = product_id;
	}

	if ( frm.elements['action'] ) {
		frm.elements['action'].value = action;
	}

	if ( multi_quantity_check(frm, false) ) {
		frm.submit();
	}
	return false;
}

function submitComment(product_id)
{
	var frm = document.getElementById('frmComment');

	if ( frm.elements['product_id'] ) {
		frm.elements['product_id'].value = product_id;
	}
	
	if(validateProductComment(frm)){
		frm.submit();
	}
	//return false;
	
}

function favoritesAction(product_id, option_id, action)
{
	var frm = document.getElementById('frmFavorites');

	if ( frm.elements['product_id'] ) {
		frm.elements['product_id'].value = product_id;
	}

	if ( frm.elements['option_id'] ) {
		frm.elements['option_id'].value = option_id;
	}

	if ( frm.elements['action'] ) {
		frm.elements['action'].value = action;
	}

	frm.submit();

	return false;
}

var xmlLoaded = false;
var xslLoaded = false;

function loadXSL()
{
	if ( document.implementation.createDocument ) {
		xslDoc = document.implementation.createDocument("", "", null);
		xslDoc.addEventListener("load", onXSLLoad, false);
		xslDoc.load('listview/products.xsl');
	} else if ( window.ActiveXObject ) {
		xslDoc = new ActiveXObject("Microsoft.XMLDOM");
		xslDoc.async = false;
		xslDoc.validateOnParse = false;
		xslDoc.load('listview/products.xsl');
		xslLoaded = true;
	}
}

function onXMLLoad()
{
	xmlLoaded = true;
	styleLoad();
}

function onXSLLoad()
{
	xslLoaded = true;
	styleLoad();
}
var timer;
var curr = 1;
function styleLoad()
{
	if ( xmlLoaded && xslLoaded ) {
		var processor = new XSLTProcessor();

		processor.importStylesheet(xslDoc);
		var doc = processor.transformToFragment(xmlDoc, document);

		var list = document.getElementById('list');

		if ( document.getElementById('list') ) {
			document.getElementById('list').parentNode.replaceChild(doc, document.getElementById('list'));
		}
		xmlLoaded = false;
		document.body.style.cursor = 'auto';
		clearTimeout(timer);
		curr = 1;
		//xslLoaded = false;
	}
}


var resorting_selected = false;
var lvhistinitted = false;

function refreshView(page, sort, dir, perpage)
{
	/*var waiting = document.createElement("div");
	waiting.id = 'list';
	waiting.innerHTML = "Loading...";
	document.getElementById('list').parentNode.replaceChild(waiting, document.getElementById('list'));*/

	try {
		if ( !xslLoaded ) {
			loadXSL();
		}
		if ( sort != undefined ) {
			var url = 'listview.php?ret&pg='+page+'&srt='+sort+'&dir='+dir+'&perpage='+perpage+'&viewtype='+ListviewType;
			for( x in lv_tracking) {
				url += "&tracking["+x+"]="+lv_tracking[x];
			}
			hist_set(url.substring(13));
		} else {
			var url = page;
		}

		if ( document.implementation.createDocument ) {
			timer = setTimeout("dotDot()", 0);
			document.body.style.cursor = 'progress';
			xmlDoc = document.implementation.createDocument("", "", null);
			xmlDoc.addEventListener("load", onXMLLoad, false);
			xmlDoc.load(url);

		} else if ( window.ActiveXObject ) {
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async = false;
			xmlDoc.validateOnParse = false;
			xmlDoc.load(url);
			document.getElementById('list').innerHTML = xmlDoc.transformNode(xslDoc);
		} else {
			return true;
		}
		return false;
	 } catch (e) {
		if ( resorting_selected ) {
			resorting_selected = false;
			throw "Resort";
		} else {
			if (window.location.toString().indexOf('product_search') > -1) {
				to_url = window.location.pathname+'?ret&pg='+page+'&srt='+sort+'&dir='+dir+'&perpage='+perpage+'&viewtype='+ListviewType;
				for( x in lv_tracking) {
					to_url += "&tracking["+x+"]="+lv_tracking[x];
				}

				window.location = to_url;
				return false;
			} else {
				return true;
			}
		}
	}
}

function refreshSort(page, sort, dir, perpage)
{
	resorting_selected = true;
	try {
		refreshView(page, sort, dir, perpage);
	} catch (e) {
		window.location = window.location.pathname+"?pg="+page+"&srt="+sort+"&dir="+dir+"&perpage="+perpage;
	}
}

function dotDot()
{
	if ( timer ) {
		clearTimeout(timer);
	}

	var dots = '';
	for ( var i=0; i < curr; i++ ) {
		dots = dots + '.';
	}

	curr += 1;
	if ( curr > 3 ) {
		curr = 1;
	}

	var str = 'Loading'+dots;
	if (document.getElementById('now_loading')) {
		document.getElementById('now_loading').innerHTML = str;
	}

	timer = setTimeout("dotDot()", 300);
}

function lv_hist_change() {
	if ( lvhistinitted ) {
		lvhistinitted = false;
		return;
	}
	var params = unFocus.History.getCurrent();
	if ( params == '' ) {
		params = 'viewtype='+ListviewType;
		for( x in lv_tracking) {
			params += "&tracking["+x+"]="+lv_tracking[x];
		}
		if(sort_value) {
			params += "&srt="+sort_value;
		}
	}
	refreshView('listview.php?'+params);
}

function hist_set(str)
{
	lvhistinitted = true;
	unFocus.History.addHistory(str);
}

var express = false;
var storeCC = false;

function doProfileChange(type) {
	var id = '';

	if ( $(type+'_id') ) {
		id = $(type+'_id').value;
	}

	if ( id != '' ) {
		if ( type == 'billingAddr' ) {
			if ( !express ) {
				if ( id == '0' ) {
					$(type+'_id').value = 'new';
					
					$('add_addr_profile').style.display = '';
					$('shipping_action').value = 'true';
					
					$('address_name').value = '';
				} else if ( id == 'new' ) {
					$('add_addr_profile').style.display = '';
					$('shipping_action').value = 'true';
				} else {
					$('update_addr_profile').style.display = '';
					$('shipping_action').value = 'true';
				}
			}
		} else if ( (type == 'billing' && storeCC) || type != 'billing' ) {
			$('update_profile').style.display = '';
		}
		
		$(type+'_action').value = 'true';
	} else {
		if ( type == 'billingAddr' ) {
			if ( !express ) {
				$('update_addr_profile').style.display = 'none';
			}
		} else if ( (type == 'billing' && storeCC) || type != 'billing' ) {
			$('update_profile').style.display = 'none';
		}
	}
}

function changeBilling(id)
{
	$('update_profile').style.display = 'none';
	
	if ( id == '' ) {
		$('add_profile').style.display = '';
		$('billing_action').value = 'true';
	} else {
		$('add_profile').style.display = 'none';
		$('billing_action').value = 'false';
	}
	
	$('add_billing_profile').checked = false;
	$('update_billing_profile').checked = false;
	
	$('name_profile').style.display = 'none';

	var uri = "ActivaUpdater.php";
	var data = "";

	data += nh.compressData("action", "changeBilling");
	data += nh.compressData("id", id);

	ActivaUpdater(uri, data);
}

function changeBillingAddr(id)
{
	$('update_addr_profile').style.display = 'none';

	if ( id == 'new' && !express ) {
		$('add_addr_profile').style.display = '';
		$('shipping_action').value = 'true';
	} else {
		$('add_addr_profile').style.display = 'none';
		$('shipping_action').value = 'false';
	}
	
	$('add_shipping_profile').checked = false;
	$('update_shipping_profile').checked = false;
	
	$('name_billing_addr').style.display = 'none';

	var uri = "ActivaUpdater.php";
	var data = "";

	data += nh.compressData("action", "changeBillingAddr");
	data += nh.compressData("id", id);

	ActivaUpdater(uri, data);
}

function changeShipping(id)
{
	$('update_profile').style.display = 'none';

	if ( id == '' ) {
		$('add_profile').style.display = '';
		$('shipping_action').value = 'true';
	} else {
		$('add_profile').style.display = 'none';
		$('shipping_action').value = 'false';
	}
	
	$('add_shipping_profile').checked = false;
	$('update_shipping_profile').checked = false;
	
	$('name_profile').style.display = 'none';

	var uri = "ActivaUpdater.php";
	var data = "";

	data += nh.compressData("action", "changeShipping");
	data += nh.compressData("id", id);

	ActivaUpdater(uri, data);
}

function showProfileName(type, checked, action) {
	var label = '';
	
	switch ( type ) {
		case 'shipping':
			label = 'Address';
			break;
		case 'billing':
			label = 'Saved Card';
			break;
	}
	
	switch ( action ) {
		case 'add':
			$('name_profile_label').innerHTML = 'Name this '+label;
			break;
		case 'update':
			$('name_profile_label').innerHTML = 'Name of '+label;
			break;
	}
	
	if ( checked ) {
		$('name_profile').style.display = '';
	} else {
		$('name_profile').style.display = 'none';
	}
}

function showBillingAddrName(checked, action) {
	switch ( action ) {
		case 'add':
			$('name_billing_addr_label').innerHTML = 'Name this Address';
			break;
		case 'update':
			$('name_billing_addr_label').innerHTML = 'Name of Address';
			break;
	}
	
	if ( checked ) {
		$('name_billing_addr').style.display = '';
	} else {
		$('name_billing_addr').style.display = 'none';
	}
}

function handleKeyPress(event)
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

	// Enter
	if ( keyCode == 13 ) {
		cartAction('', 'quantity_update');
	}
}

var paymentTypes = new Array('cc', 'pp', 'po', 'gg');

function switchPaymentType(type)
{
	for ( var x=0; x<paymentTypes.length; x++ ) {
		if ( type == paymentTypes[x] ) {
			if ( $(paymentTypes[x]+'_form') ) {
				$(paymentTypes[x]+'_form').style.display = '';
			}
		} else {
			if ( $((paymentTypes[x]+'_form')) ) {
				$(paymentTypes[x]+'_form').style.display = 'none';
			}
		}
	}
}

function multi_quantity_check(frm, popup)
{
	if ( document.getElementById('action') ) {
		if ( document.getElementById('action').value != 'remove_item' ) {
			for ( var i=0; i<frm.length; i++ ) {
				var element = frm.elements[i];
				if ( element.name.search(/qty/) >= 0 ) {
					if ( element.value < 1 || !validateInteger(element.value) ) {
						if ( popup ) {
							alert("Quantity must be an integer greater than 0");
						}
						return false;
					}
				}
			}
		}
	} else {
		for ( var i=0; i<frm.length; i++ ) {
			var element = frm.elements[i];
			if ( element.name.search(/qty/) >= 0 ) {
				if ( element.value < 1 || !validateInteger(element.value) ) {
					if ( popup ) {
						alert("Quantity must be an integer greater than 0");
					}
					return false;
				}
			}
		}
	}

	return true;
}

function getShipServices(carrier)
{
	var uri = "ActivaUpdater.php";

	var data = "";

	data += nh.compressData('action', "getShipServices");
	data += nh.compressData('target', "shiptype");
	data += nh.compressData('carrier', carrier);

	ActivaUpdater(uri, data);
}

function getShipPrice(service, carrier)
{
	$('shiptotalvalue').innerHTML = 'loading';
	$('gnd_total').innerHTML = 'loading';

	if ( $('grp_total') ) {
		$('grp_total').innerHTML = 'loading';
	}
	
	if ( $('pmo_total') ) {
		$('pmo_total').innerHTML = 'loading';
	}

	if ( $('gft_total') ) {
		$('gft_total').innerHTML = 'loading';
	}

	var uri = "ActivaUpdater.php";

	var data = "";

	data = nh.compressData("action", "getShipPrice");
	data += nh.compressData("service", service);
	data += nh.compressData("carrier", carrier);

	ActivaUpdater(uri, data);
}

function ltrim(string)
{
	return string.replace(/^\s*/, '');
}

function rtrim(string)
{
	return string.replace(/\s*$/, '');
}

function trim(string)
{
	return rtrim(ltrim(string));
}

var cleared = false;
function clearCCNum(input)
{
	if ( !cleared ) {
		input.value = '';
		cleared = true;
	}
}

function clearCart()
{
        var uri="ActivaUpdater.php";
        var data="";
        data = nh.compressData("action", "clear_cart");
        ActivaUpdater(uri, data);
}

function updateGoogle(comments)
{
    var uri="ActivaUpdater.php";
    var data="";
    data += nh.compressData("action", "update_google");
    data += nh.compressData("comments", comments);
    ActivaUpdater(uri, data);
}


function showSubMenu(span, menu) {

	return false;
		
	span.className = 'pop';
	showID(menu);
	elem = document.getElementById(menu);
	
    if ((elem.offsetTop + elem.clientHeight) > (document.body.scrollTop + document.body.clientHeight)) {
	
		if (elem.parentNode.childNodes[1].clientHeight) {
			offset = (elem.offsetTop - elem.clientHeight) + elem.parentNode.childNodes[1].clientHeight;
			if (offset >= document.body.scrollTop) {
				elem.style.top = (offset) + 'px';
			}
			return ;
		}
		
		next_node = elem.parentNode;
		
		attempts = 0;
		
		while (next_node.nextSibling && ++attempts < 5) {
			sib = next_node.nextSibling;
			if (sib.nodeType == 1 && sib.offsetTop) {
				offset = (elem.offsetTop - elem.clientHeight) + (sib.offsetTop - elem.parentNode.offsetTop);	
				if (offset >= document.body.scrollTop) {
					elem.style.top = (offset) + 'px';
				}
				return ;
			} else {
				next_node = sib;
			}
		}

		offset = (elem.offsetTop - elem.clientHeight);
		elem.style.top = (offset) + 'px';
		return ;
    }
}

function hideSubMenu(span, menu) {
	span.className = '';
	hideID(menu);
}

/**
 * Will copy all values from one form to another form
 * that uses the same ids, but with a 'prefix_id' format. Special
 * case for 'firstname' and 'lastname' which will be combined
 * and inserted into a 'prefix_contact_person' input.
 *  Example:  sameAsAbove(did('myform'),'pickup'); -called from anywhere
 *  	or sameAsAbove(this.form,'pickup'); -if used inline on an element
 *	Both will copy all inputs from 'myform' or this.form to any input element
 *	that uses an id like:  pickup_state, pickup_city, etc.
 *  
 * Note: Currently only supports the input element. (not select, might work with checkboxes or radios--untested)
 */
function sameAsAbove(frmEL,prefix) {  
	//var checked=(did('same_as_above').checked)?true:false; 
	var numEls = frmEL.elements.length;
	var elms = {'name':''};
	for(i=0;i < numEls;i++){
		if(frmEL.elements[i].id == 'same_as_above') { break; }
		if(frmEL.elements[i].id == 'firstname' || frmEL.elements[i].id == 'lastname'){
			elms['name'] += frmEL.elements[i].value+' ';
		}else{
			elms[frmEL.elements[i].id]=frmEL.elements[i].value;
		}
	}
	elms['name']=elms['name'].substr(0,elms['name'].length-1);
	for (elm in elms) {
		el = did(prefix+'_'+elm);
		if (el !== null){
			el.value = elms[elm];
			//el.className = (checked)?'gray':'text';
			//el.disabled = (checked)?true:false;
		}
	}
}

function validateOrderSmartRecycle(frmEL,prefix,dispPrefix) {
	var numEls = frmEL.elements.length;
	var errfields={'firstname':'first name','lastname':'last name','zip':'zip code','phone':'phone number'};
	var opt='your ';
	for(i=0;i < numEls;i++){
		if (!(frmEL.elements[i].value != '')) {
			errfield=frmEL.elements[i].name;
			for (field in errfields){
				if(errfield == field) { errfield = errfields[field]; }
				else if(errfield == (prefix+'_'+field)) { 
					opt='the ';
					if(errfields[field] != 'undefined') { errfield=errfields[field]; }   
				}else if(errfield.indexOf(prefix) != -1){
					opt='the ';
					errfield = errfield.replace(prefix+'_',dispPrefix+' ');
				}
			}
			alert('Please enter '+opt+errfield+'.'); frmEL[i].focus(); return false;
		}
	}
	return true;
}

function submitTheForm(frm){
	for(i=0;i < frm.elments.length;i++){
		frm.elements[i].disabled=false;
	}
}

function bulk_order_same_as_above(checked) {
	if(checked) {
		did('pickup_company').value = did('company').value;
		did('pickup_contact_person').value = did('firstname').value + ' ' + did('lastname').value;
		did('pickup_address').value = did('address').value;
		did('pickup_city').value = did('city').value;
		did('pickup_state').value = did('state').value;
		did('pickup_zip').value = did('zip').value;
		did('pickup_country').value = did('country').value;
		did('pickup_phone').value = did('phone').value;
		
		did('pickup_company').className = 'gray';
		did('pickup_contact_person').className = 'gray';
		did('pickup_address').className = 'gray';
		did('pickup_city').className = 'gray';
		did('pickup_state').className = 'gray';
		did('pickup_zip').className = 'gray';
		did('pickup_country').className = 'gray';
		did('pickup_phone').className = 'gray';
		
		did('pickup_company').disabled = true;
		did('pickup_contact_person').disabled = true;
		did('pickup_address').disabled = true;
		did('pickup_city').disabled = true;
		did('pickup_state').disabled = true;
		did('pickup_zip').disabled = true;
		did('pickup_country').disabled = true;
		did('pickup_phone').disabled = true;
	} else {
		did('pickup_company').className = 'text';
		did('pickup_contact_person').className = 'text';
		did('pickup_address').className = 'text';
		did('pickup_city').className = 'text';
		did('pickup_state').className = 'text';
		did('pickup_zip').className = 'text';
		did('pickup_country').className = 'text';
		did('pickup_phone').className = 'text';	
		
		did('pickup_company').disabled = false;
		did('pickup_contact_person').disabled = false;
		did('pickup_address').disabled = false;
		did('pickup_city').disabled = false;
		did('pickup_state').disabled = false;
		did('pickup_zip').disabled = false;
		did('pickup_country').disabled = false;
		did('pickup_phone').disabled = false;
	}
}



function submitBulkQuoteForm() {
	did('pickup_company').disabled = false;
	did('pickup_contact_person').disabled = false;
	did('pickup_address').disabled = false;
	did('pickup_city').disabled = false;
	did('pickup_state').disabled = false;
	did('pickup_zip').disabled = false;
	did('pickup_country').disabled = false;
	did('pickup_phone').disabled = false;
}

function validateBulkQuote() {
	return (
		checkSelect(did('firstname'),"V","","Please enter your First Name.",false) &&
		checkSelect(did('lastname'),"V","","Please enter your Last Name.",false) &&
		checkSelect(did('company'),"V","","Please enter your Company.",false) &&
		checkSelect(did('phone'),"V","","Please enter your Phone Number.",false) &&
		checkSelect(did('email'),"V","","Please enter your E-mail Address.",false)
	);
}

function validateUPSQuote() {
	return (
		checkSelect(did('firstname'),"V","","Please enter your First Name.",false) &&
		checkSelect(did('lastname'),"V","","Please enter your Last Name.",false) &&
		checkSelect(did('company'),"V","","Please enter your Company.",false) &&
		checkSelect(did('phone'),"V","","Please enter your Phone Number.",false) &&
		checkSelect(did('email'),"V","","Please enter your E-mail Address.",false)
	);
}

function validateInfoRequest() {
	return (
		checkSelect(did('firstname'),"V","","Please enter your First Name.",false) &&
		checkSelect(did('lastname'),"V","","Please enter your Last Name.",false) &&
		checkSelect(did('email'),"V","","Please enter your E-mail Address.",false) &&
		checkSelect(did('company'),"V","","Please enter your Company.",false) &&
		checkSelect(did('phone'),"V","","Please enter your Phone Number.",false)
	);
}

function validateContactMeRequest() {
	return (
		checkSelect(did('firstname'),"V","","Please enter your First Name.",false) &&
		checkSelect(did('lastname'),"V","","Please enter your Last Name.",false) &&
		checkSelect(did('company'),"V","","Please enter your Company.",false) &&
		checkSelect(did('phone'),"V","","Please enter your Phone Number.",false) &&
		checkSelect(did('email'),"V","","Please enter your E-mail Address.",false)
	);
}

function validatePailMailRequest() {
	return (
		checkSelect(did('firstname'),"V","","Please enter your First Name.",false) &&
		checkSelect(did('lastname'),"V","","Please enter your Last Name.",false) &&
		checkSelect(did('company'),"V","","Please enter your Company.",false) &&
		checkSelect(did('zip'),"V","","Please enter your Zip Code.",false) &&
		checkSelect(did('phone'),"V","","Please enter your Phone Number.",false) &&
		checkSelect(did('email'),"V","","Please enter your E-mail Address.",false) &&
		checkSelect(did('container_type'),"V","","Please enter the Container Type.",false) &&
		checkSelect(did('container_qty'),"V","","Please enter the Container Quantity.",false) &&
		(! did('schedule_pickup').checked || (
		checkSelect(did('pickup_company'),"V","","Please enter the Pick-Up Company.",false) &&
		checkSelect(did('pickup_name'),"V","","Please enter the Pick-Up Contact Person.",false) &&
		checkSelect(did('pickup_address'),"V","","Please enter the Pick-Up Street Address.",false) &&
		checkSelect(did('pickup_city'),"V","","Please enter the Pick-Up City.",false) &&
		checkSelect(did('pickup_state'),"V","","Please enter the Pick-Up State.",false) &&
		checkSelect(did('pickup_zip'),"V","","Please enter the Pick-Up Zip.",false) &&
		checkSelect(did('pickup_phone'),"V","","Please enter the Pick-Up Phone Number.",false) &&
		checkSelect(did('pickup_closing_time'),"V","","Please enter the Pick-Up Closing Time.",false) &&
		checkSelect(did('pickup_building_entrance'),"V","","Please enter the Pick-Up Building Entrance.",false) &&
		checkSelect(did('pickup_location'),"V","","Please enter the Pick-Up Location.",false) ) )
	);
}

function $(id) {
	return document.getElementById(id);
}

function $n(name, parent){
	return (parent || document).getElementsByName(name);
}

function $t(tag, parent){
	return (parent || document).getElementsByTagName(tag);
}

function did(id) {
	return document.getElementById(id);
}


function hideID(name) {
	if(did(name)) {
		did(name).style.display = 'none';
	}
}

function showID(name) {
	if(did(name)) {
		did(name).style.display = 'block';
	}
}

function toggleDisplayID(name) {
	if(did(name)) {
		if(did(name).style.display == 'none') {
			showID(name);
		} else {
			hideID(name);
		}
	}
}

function updateCountry() {
	if ( did('country').value == '' ) {
		return;
	}
	did('state').style.display = 'none';
	did('province').style.display = 'none';
	did('other').style.display = 'none';
	
	if ( did('country').value == 'US' || did('country').value == '213' ) {
		did('state').style.display = '';
	} else if ( did('country').value == 'CA' || did('country').value == '38' ) {
		did('province').style.display = '';
	} else {
		did('other').style.display = '';
	}
}

function changeProductOption(id)
{
	var uri="ActivaUpdater.php";
    var data="";
    
    data += nh.compressData("action", "changeProductOption");
    data += nh.compressData("id", id);
    
    ActivaUpdater(uri, data);
}

function isHidden(name) {
	if(did(name).style.display == "none") {
		return true; 
	}
	return false;
}

function toolbarRollDown(rollDownName, hideName) {
	if(isHidden(hideName)) {
		vRoll(rollDownName, '30');
	} else {
		hideID(hideName);
		showID(rollDownName);
	}
}

function pwFocus() {
	if ( did('password').type != 'password' ) {
		var IE = (navigator.userAgent.indexOf("MSIE")>=0) ? true : false;
		if ( !IE ) {
			did('password').type = 'password';
			did('password').value = '';
		} else {
			var newPassField = did('password').cloneNode(true);
			newPassField.type = 'password';
			newPassField.value = '';
			did('password').parentNode.replaceChild(newPassField, did('password'));
			setTimeout("document.getElementById('password').focus()",50);
		}
	}
	
}

function registerEvent(elem, event, callback) {
	if ( event == 'allchange' ) {
		registerEvent(elem, 'change', callback);
		registerEvent(elem, 'click', callback);
		registerEvent(elem, 'keyup', callback);
		return;
	}
	elem = domcheck(elem);
	
	if ( elem.addEventListener ) {
		elem.addEventListener(event, callback, true);
	} else {
		elem.attachEvent('on'+event, callback); 
	}
}

function domcheck(elem) {
	if ( typeof(elem) == 'object' ) {
		return elem;
	}
	
	return did(elem);
}

/**
 * fixEvent - Returns an event object with common properties/methods normalized for easier cross browser usage.
 * @param e		object	optional;Event object to normalize
 * @return		object	Event object after normalization
 */
function fixEvent(e){
	var evnt = e || window.event;
	if(!evnt.target){ evnt.target = evnt.srcElement; }
	evnt.preventDefault = (evnt.preventDefault)? evnt.preventDefault : function(){ this.returnValue = false; };
	evnt.stopPropagation = (evnt.stopPropagation)? evnt.stopPropagation : function(){ this.cancelBubble = true; }
	return evnt;
}

/**
 * slice - Shortcut for Array.prototype.slice.call(obj, idx)
 * @param obj	mixed		Object to call array.slice on
 * @param idx	integer		Index at which to begin slicing
 * @return		array		New array containing values from the idx to the end of the obj
 *		Note: Useful for transforming arguments object and collections into regular arrays
 *		ex.	function(){ var args = slice(arguments); alert(args instanceof Array); }
 */
function slice(obj,idx){
	var ret = obj;
	if(/internet\sexplorer/i.test(navigator.appName)){
		if(typeof obj.length=='undefined'){ obj.length = getLength(obj); }
		ret = Array.prototype.map.call(obj,function(item){return item;});
	}
	return Array.prototype.slice.call(ret,idx || 0);
}

/**
 * Array.indexOf - adds indexOf() support to browsers that don't have it.
 */
if(!Array.indexOf){
	Array.prototype.indexOf = function(obj,start){
		var len = this.length;
		start = Number(start) || 0;
		start = (start < 0) ? Math.ceil(start) : Math.floor(start);
		if(start < 0){ start+= len; }
		for(;start < len;start++){
			if(start in this && this[start]===obj){ return start; }
		}
		return -1;
	}
}
/**
 * Array.forEach - adds forEach() support to browsers that don't have it.
 */
if(!Array.forEach){
	Array.prototype.forEach = function(fn /*, bind*/){
		var len = this.length;
		if(typeof(fn) != 'function'){ throw new TypeError(); }
		var bind = arguments[1];
		for(var i=0;i < len;i++){
			if(i in this){ fn.call(bind, this[i], i, this); }
		}
	};
}
/**
 * Array.map - adds map() support to browsers that don't have it.
 */
if(!Array.map){
	Array.prototype.map = function(fn /*, bind*/){
		var len = this.length;
		if(typeof(fn) != 'function'){ throw new TypeError(); }
		var ret = [], bind = arguments[1];
		for (var i=0;i < len;i++){
			if(i in this){ ret[i] = fn.call(bind, this[i], i, this); }
		}
		return ret;
	};
}
/**
 * Array.filter - adds filter() support to browsers that don't have it
 */
if(!Array.filter){
	Array.prototype.filter = function(fn /*, bind*/){
		var len = this.length;
		if(typeof(fn) != 'function'){ throw new TypeError(); }
		var ret = [], bind = arguments[1], val=null;
		for(var i=0;i < len;i++){
			if(i in this){
				val=this[i];
				if(fn.call(bind,val,i,this)){ ret.push(val); }
			}
		}
		return ret;
	};
}