function scProgBar() {
	/*
		scProgBar - Public - Generates a progress indicator bar object
		PARAMETERS: none
		RETURN: none
	*/
	
	// Build HTML objects
	var progBar = document.createElement("div"); 
	with (progBar) {
		className = "scProgBar";
		with (style) {
			overflow = "hidden";
			position = "relative";
			zIndex = "0";
		}
		appendChild(document.createElement("div"));
		firstChild.className = "progBarBg";
		with (firstChild.style) {
			width = "0";
		}
		appendChild(document.createElement("div"));
		childNodes[1].className = "progBarFg";
		with (childNodes[1].style) {
			position = "absolute";
			top = "0";
			left = "0";
			zIndex = "1";
			width = "100%";
			textAlign = "center";
		}
		childNodes[1].appendChild(document.createTextNode("0%"));
	}
	
	// Initialize Progress var
	var currProg = 0;
	
	// Initialize Interval vars	
	var throbInt = null;
	var throbTime = 100;
	
	this.setPseudoTime = function ( num ) {
		/*
			setPseudoTime - Public - Sets the interval time (throbTime) for the pseudo progress bar
			PARAMETERS: num - should be a positive integer value
			RETURN: none
		*/
		var tmpNum = SC.forceInt(num);
		if (tmpNum > 0) {
			throbTime = tmpNum;
		}
	};
	
	this.pseudoStart = function ( num ) {
		/*
			pseudoStart - Public - Initializes the pseudo progress bar interval
			PARAMETERS: num - should be a positive integer value; if it is not set, throbTime will be used
			RETURN: none
		*/
		var tmpNum = SC.forceInt(num);
		throbInt = setInterval(pseudoUpdate, ((tmpNum > 0)? tmpNum : throbTime));
	};
	
	function readNum() {
		/*
			getNum - Private - Gets the current progress [percent] value from the prog bar HTML object
			PARAMETERS: none
			RETURN: an integer value for the current progress percentage
		*/
		var num = -1;
		try {
			num = SC.forceInt(progBar.childNodes[1].firstChild.nodeValue);
		} catch (err) {}
		return num;
	}
	
	function pseudoUpdate() {
		/*
			pseudoUpdate - Private - Iterates the progress bar randomly; will slow as current percent approaches 99%
			PARAMETERS: none
			RETURN: none
		*/
		var num = currProg;
		if (-1 < num < 100) {
			var diff = 100 - num;
			var ran = Math.ceil(Math.random() * 100);
			var adj = Math.abs(diff - ran);
			num += Math.floor(diff / ((adj > 0)? adj : 1) / 2);
			setPercent(num);
		} else {
			clearInterval(throbInt);
		}
	}
	
	function killPseudo() {
		/*
			killPseudo - Private - Stops the iteration of the pseudo progress bar
			PARAMETERS: none
			RETURN: none
		*/
		if (throbInt) clearInterval(throbInt);
	}
	
	function setPercent( num ) {
		/*
			setPercent - Private - Sets and writes the current progress percent information to the prog bar HTML object
			PARAMETERS: num - should be a positive integer value
			RETURN: none
		*/
		var tmpNum = SC.forceInt(num);
		if (tmpNum > -1) {
			currProg = tmpNum;
			try {
				progBar.childNodes[1].firstChild.nodeValue = progBar.firstChild.style.width = tmpNum + "%";
			} catch (err) {}
		}
	}
	
	this.setProg = function( num ) {
		/*
			setProg - Public - Forces the current percent to the value specified; stops a running pseudo bar
			PARAMETERS: num - should be a positive integer value
			RETURN: none
		*/
		killPseudo();
		setPercent(num);
	};
	
	this.resetProg = function() {
		/*
			resetProg - Public - Resets the current percent value to 0; stops a running pseudo bar
			PARAMETERS: none
			RETURN: none
		*/
		killPseudo();
		setPercent(0);
	};
	
	this.getProg = function() {
		/*
			getProg - Public - Gets the percent value for the current progress completed
			PARAMETERS: none
			RETURN: a string value of the current percentage
		*/
		return currProg + "%";
	};

	this.getObj = function() {
		/*
			getProg - Public - Gets an HTML object for the progress bar 
			PARAMETERS: none
			RETURN: an HTML object (div) containing the progress information
		*/
		return progBar;
	};	
}

function scShippingCalculator(){
	/*
		scShippingCalculator - Public - Initializes the shipping calculator
		PARAMETERS: none
		RETURN: none
	*/
	
	function getOpt( sel ) {
		/*
			getOpt - Private - Gets the selected option for a given select box
			PARAMETERS: the select HTML element to check
			RETURN: the option HTML element that is currently selected
		*/
		return sel.options[sel.selectedIndex];
	}
	
	var cookieName = "scSMpresets-0148";
	var formEl = SC.$("shippingMgrForm-0148");
	var scriptEl = SC.$("shippingMgrScript-0148");
	var parentDiv = SC.$("shippingMgrDiv-0148");
	var zipIn = SC.$("shippingMgrZip-0148");
	var countrySel = SC.$("shippingMgrCountry-0148");
	var provinceIn = SC.$("shippingMgrProvince-0148");
	var provinceSpan = SC.$("caprovince-0148");
	var bttn = SC.$("shippingMgrSubmit-0148");
	var country = window.shippingMgrC || "US United States";
	
	function throb( parentDiv ) {
		/*
			throb - Private - Adds the progress bar to a parent element; starts running a pseudo bar
			PARAMETERS: parentDiv - should be an HTML element
			RETURN: none
		*/
		if (parentDiv && (parentDiv.nodeType == 1)) {
			SC.orphan(parentDiv);
			var progBar = new scProgBar();
			SC.appElem(progBar.getObj(), parentDiv);
			var adj = getQty().toString().length - 3;
			adj = (adj > 0)? (adj + adj) / 1.5 : 1;
			progBar.pseudoStart(100 * adj);
		}
	}
	
	function getQty() {
		var prodId = document.location.href.match(/\/([^\/]+)\.html$/);
		prodId = prodId ? prodId[1] : '';
		var vwItem = SC.filterByName(SC.getByTag('input'), 'vwitem');
		for (var i = 0, j = vwItem.length; i < j; i++) {
			if (!prodId || (vwItem[i].value == prodId)) {
				var vwQty = SC.filterByName(SC.getByTag('input', vwItem[i].form), 'vwquantity');
				if (vwQty.length) {
					return SC.forceInt(vwQty[0].value);
				}
			}
		}
		delete prodId, vwItem;
		return 1;
	}
	
	this.getShippingMgrZips = function(){
		/*
			getShippingMgrZips - Public - Finds shipping values (zip, etc), initializes the progress bar loading, and sets the iframe to start receiving data
			PARAMETERS: none
			RETURN: none
		*/
		var zip = zipIn.value.toString();
		var province = (provinceSpan && !SC.hasClass(provinceSpan, "hideMe-0148"))? provinceIn.value : "";
		if(countrySel) {
			country = getOpt(countrySel).value + " " + getOpt(countrySel).text;
		}
		SC.setCookie(cookieName, ("({zip:'" + zip + "', province:'" + province + "', country:'" + country + "'})"), '/', null, 30);
		
		if (!country.toLowerCase().match(/^usa?/) || (zip != "")) {
			var url = "sc-shipping-calculator-frame.html?country=" + country + "&province=" + province + "&unitPrice=" + shippingMgrUnitPrice + "&itemid=" + shippingMgrItemID + "&storeid=" + shippingMgrStoreID + "&zipcode=" + zip + "&qty=" + getQty();
			throb(parentDiv);
			scriptEl.src = url;
			if (!zip) {
				var noZipMsg = (window.scSCnoZipMsg)? scSCnoZipMsg : "Please consider entering a zip code value for complete results.";
				alert(noZipMsg);
				delete noZipMsg;
			}
		} else {
			var noZipMsg = (window.scSCnoZipUsMsg)? scSCnoZipUsMsg : "A zip code is required; please enter a value.";
				alert(noZipMsg);
				delete noZipMsg;
		}
		delete zip, province, url;
	};
	
	this.displayProvince = function(){
		/*
			displayProvince - Public - Finds shipping values (zip, etc) and displays the province input if the country is CA(nada)
			PARAMETERS: none
			RETURN: none
		*/
		country = getOpt(countrySel).value + " " + getOpt(countrySel).text;
		var tmpSelInd = countrySel.options.selectedIndex;
		if(countrySel.options[tmpSelInd].value=="CA") {
			if (SC.hasClass(provinceSpan, "hideMe-0148")) {
				SC.removeClass(provinceSpan, "hideMe-0148");
			}
		} else {
			if (!SC.hasClass(provinceSpan, "hideMe-0148")) {
				SC.addClass(provinceSpan, "hideMe-0148");
			}
		}
		delete tmpSelInd;
		refreshSubmit();
	};
	
	function refreshSubmit( ev ) {
		/*
			refreshSubmit - Private - Classes the submit button accordingly
			PARAMETERS: none
			RETURN: none
		*/
		if (country.toLowerCase().match(/^usa?/) && (zipIn.value.toString() == "")) {
			SC.addClass(bttn, "dimMe-0148");
		} else {
			SC.removeClass(bttn, "dimMe-0148");
		}
	}
	
	// Shows HTML objects that were hidden in case JS fails; Intializes values from the cookie
	try {
		formEl.style.display = parentDiv.style.display = "block";
		if (provinceSpan) {
			SC.addClass(provinceSpan, "hideMe-0148");
		}
		if (zipIn) {
			SC.addEvt(zipIn, "keyup", refreshSubmit);
		}
		var smCookie = eval(SC.getCookie(cookieName));
		if (smCookie) {
			zipIn.value = smCookie.zip;
			if (provinceIn) {
				provinceIn.value = smCookie.province;
			}
			if (smCookie.country) {
				country = smCookie.country;
			}
		}
		if (countrySel) {
			var cSelInd = countrySel.options.length;
			var cCode = country.substr(0,2);
			while (--cSelInd > 0 && (countrySel.options[cSelInd].value != cCode)) {}
			countrySel.options.selectedIndex = cSelInd;
			delete cSelInd, cCode;
		}
		delete smCookie;
		refreshSubmit();
	} catch (err) {}
}

