


		
		// remote scripting library
		// (c) copyright 2005 modernmethod, inc
		var sajax_debug_mode = false;
		var sajax_request_type = "POST";
		var sajax_target_id = "";
		var sajax_failure_redirect = "";
		
		function sajax_debug(text) {
			if (sajax_debug_mode)
				alert(text);
		}
		
 		function sajax_init_object() {
 			sajax_debug("sajax_init_object() called..")
 			
 			var A;
 			
 			var msxmlhttp = new Array(
				//'Msxml2.XMLHTTP.5.0',
				//'Msxml2.XMLHTTP.4.0',
				//'Msxml2.XMLHTTP.3.0',
				//'Msxml2.XMLHTTP',
				'Microsoft.XMLHTTP'
				);
			for (var i = 0; i < msxmlhttp.length; i++) {
				try {
					A = new ActiveXObject(msxmlhttp[i]);
				} catch (e) {
					A = null;
				}
			}
 			
			if(!A && typeof XMLHttpRequest != "undefined")
				A = new XMLHttpRequest();

			if (!A){
				sajax_debug("Could not create connection object.");
				if(typeof handleNoAjax == 'function'){
				    handleNoAjax();
				}else{
				    alert("Your browser does not support AJAX.  Please check your security settings.  This site requires Javascript and Cookies.");
				}
	        }
			return A;
		}
		
		var sajax_requests = new Array();
		
		function sajax_cancel() {
			for (var i = 0; i < sajax_requests.length; i++) 
				sajax_requests[i].abort();
		}
		
		function sajax_do_call(func_name, args) {
			var i, x, n;
			var uri;
			var post_data;
			var target_id;
			
			sajax_debug("in sajax_do_call().." + sajax_request_type + "/" + sajax_target_id);
			target_id = sajax_target_id;
			if (typeof(sajax_request_type) == "undefined" || sajax_request_type == "") 
				sajax_request_type = "GET";
			
			uri = "/cart/ajax.php";
			if (sajax_request_type == "GET") {
			
				if (uri.indexOf("?") == -1) 
					uri += "?rs=" + escape(func_name);
				else
					uri += "&rs=" + escape(func_name);
				uri += "&rst=" + escape(sajax_target_id);
				uri += "&rsrnd=" + new Date().getTime();
				
				for (i = 0; i < args.length-1; i++) 
					uri += "&rsargs[]=" + escape(args[i]);

				post_data = null;
			} 
			else if (sajax_request_type == "POST") {
				post_data = "rs=" + escape(func_name);
				post_data += "&rst=" + escape(sajax_target_id);
				post_data += "&rsrnd=" + new Date().getTime();
				
				for (i = 0; i < args.length-1; i++) 
					post_data = post_data + "&rsargs[]=" + escape(args[i]);
			}
			else {
				alert("Illegal request type: " + sajax_request_type);
			}
			
			x = sajax_init_object();
			if (x == null) {
				if (sajax_failure_redirect != "") {
					location.href = sajax_failure_redirect;
					return false;
				} else {
					sajax_debug("NULL sajax object for user agent:\n" + navigator.userAgent);
					return false;
				}
			} else {
				x.open(sajax_request_type, uri, true);
				//x.open(sajax_request_type, uri, false);
				// window.open(uri);
				
				sajax_requests[sajax_requests.length] = x;
				
				if (sajax_request_type == "POST") {
					x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
					x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				}
			
				x.onreadystatechange = function() {
					if (x.readyState != 4) 
						return;

					sajax_debug("received " + x.responseText);
				
					var status;
					var data;
					var txt = x.responseText.replace(/^\s*|\s*$/g,"");
					status = txt.charAt(0);
					data = txt.substring(2);

					if (status == "") {
						// let's just assume this is a pre-response bailout and let it slide for now
					} else {
					    if (status == "-") {
    						alert("Error: " + data);
					    }
						if (target_id != "") 
							document.getElementById(target_id).innerHTML = eval(data);
						else {
							//try {
								var callback;
								var extra_data = false;
								if (typeof args[args.length-1] == "object") {
									callback = args[args.length-1].callback;
									extra_data = args[args.length-1].extra_data;
								} else {
									callback = args[args.length-1];
								}
								if(status == "+"){
								    callback(eval(data), extra_data);
								}else{
								    callback(false, false);
								}
							//} catch (e) {
							    //alert(e);
							//	sajax_debug("Caught error " + e + ": Could not eval " + data );
							//}
						}
					}
				}
			}
			
			sajax_debug(func_name + " uri = " + uri + "/post = " + post_data);
			x.send(post_data);
			sajax_debug(func_name + " waiting..");
			delete x;
			return true;
		}
		
				
		// wrapper for acAddItem		
		function x_acAddItem() {
			sajax_do_call("acAddItem",
				x_acAddItem.arguments);
		}
		
				
		// wrapper for acDelItem		
		function x_acDelItem() {
			sajax_do_call("acDelItem",
				x_acDelItem.arguments);
		}
		
				
		// wrapper for acDelByIndex		
		function x_acDelByIndex() {
			sajax_do_call("acDelByIndex",
				x_acDelByIndex.arguments);
		}
		
				
		// wrapper for acQtyByIndex		
		function x_acQtyByIndex() {
			sajax_do_call("acQtyByIndex",
				x_acQtyByIndex.arguments);
		}
		
				
		// wrapper for aciAddItem		
		function x_aciAddItem() {
			sajax_do_call("aciAddItem",
				x_aciAddItem.arguments);
		}
		
				
		// wrapper for aciDelItem		
		function x_aciDelItem() {
			sajax_do_call("aciDelItem",
				x_aciDelItem.arguments);
		}
		
				
		// wrapper for aciAddBox		
		function x_aciAddBox() {
			sajax_do_call("aciAddBox",
				x_aciAddBox.arguments);
		}
		
				
		// wrapper for aciSetBox		
		function x_aciSetBox() {
			sajax_do_call("aciSetBox",
				x_aciSetBox.arguments);
		}
		
				
		// wrapper for aciGetBox		
		function x_aciGetBox() {
			sajax_do_call("aciGetBox",
				x_aciGetBox.arguments);
		}
		
				
		// wrapper for afgGetFormFields		
		function x_afgGetFormFields() {
			sajax_do_call("afgGetFormFields",
				x_afgGetFormFields.arguments);
		}
		
				
		// wrapper for getCheckoutValues		
		function x_getCheckoutValues() {
			sajax_do_call("getCheckoutValues",
				x_getCheckoutValues.arguments);
		}
		
		
window.onbeforeunload = function(){
    //alert("checking ajax");
    for (var i = 0; i < sajax_requests.length; i++){
        while(sajax_requests[i].readyState == 2 || sajax_requests[i].readyState == 3){
            sleep(100);
        }
    }
}
function getTempCartRaw(){
    return _srv_tc_;
}

function loadCartItem(cookieBaseName /*, defaultSku*/ ){
    if (typeof cookieBaseName == "undefined") {
        cookieBaseName = "tc_";
    }
    var php = new PHP_Serializer();
    
    var i = 0;
    var buffer = "";
    var c = "";
//    while(c = getCookieRaw(cookieBaseName + i)){
      c = getTempCartRaw();
        buffer += c;
        i++;
//    }
    if(buffer > ""){
        return php.unserialize(stripslashes(unescape(buffer)));
        //return php.unserialize(buffer);
    }
    return new CartItem();    
}

function CartItem(sku, qty, numSubs, cookieName, pic){
    if (typeof cookieName == "undefined") {
        cookieName = "tc_";
    }
    if (typeof numSubs == "undefined") {
        numSubs = 0;
    }
    
    this.s = sku;
    this.q = qty;
    this.m = numSubs;
    this.i = new Array();
    this.c = cookieName;
    this.n = 0;
    this.p = pic;

    this.equals = function(ci, cmpQty){
        if(typeof cmpQty == "undefined"){
            if(this.getNumSubs() > 0){
                cmpQty = true;
            }else{
                cmpQty = false;
            }
        }
        
        var skuMatch = this.getSkus().toString() == ci.getSkus().toString();
        var qtyMatch = this.getQtys().toString() == ci.getQtys().toString();

        if(skuMatch == true && (qtyMatch == false && cmpQty == false || qtyMatch == true)){
            return true;
        }
        return false;
    }

    this.initIterators = function(){
        this.n = 0;
        for(x in this.i){
            this.i[x].initIterators();
        }
    }

    this.getPic = function(){
        return this.p;
    }
    
    this.setPic = function(pic){
        this.p = pic;
    }

    this.next = function(){
        if(this.getNumSubs() == 0 && this.n >= 0 || this.n >= this.getNumSubs()+1){
            return false;
        }else if(this.getNumSubs()+1 > this.n){
            this.n++;
            return true;
        }//else if(this.getNumSubs() == 0 && this.n == 0){
        //    return false;
        //}
    }

    this.getNextPic = function(){
        if(this.n == 0){
            return this.getPic();
        }else if(this.n < this.getNumSubs()+1){
            return this.i[this.n-1].getPic();
        }else{
            return false;
        }
    }

    this.getNextSku = function(){
        if(this.n == 0){
            return this.getSku();
        }else if(this.n < this.getNumSubs()+1){
            return this.i[this.n-1].getSku();
        }else{
            return false;
        }
    }

    this.getNextQty = function(){
        if(this.n == 0){
            return Number(this.getQty());
        }else if(this.n < this.getNumSubs()+1){
            return Number(this.i[this.n-1].getQty());
        }else{
            return false;
        }
    }

    this.getSkus = function(){
        var ret = new Array();
        ret.push(this.getSku());
        for(var x = 0; x < this.i.length; x++){
            ret.push(this.i[x].getSku());
        }
        return ret;
    }

    this.getQtys = function(){
        var ret = new Array();
        ret.push(this.getQty());
        for(var x = 0; x < this.i.length; x++){
            ret.push(this.i[x].getQty());
        }
        return ret;
    }

    this.getCookieName = function(){
        return this.c;
    }

    this.setCookieName = function(cookieName){
        this.c = cookieName;
    }

    this.getSku = function(){
        return this.s;
    }

    this.setSku = function(sku){
        this.s = sku;
    }

    this.getQty = function(){
        return Number(this.q);
    }

    this.setQty = function(qty){
        this.q = qty;
    }

    this.getMaxSubs = function(){
        return Number(this.m);
    }

    this.setMaxSubs = function(num){
        this.m = num;
    }

    this.getNumSubs = function(){
        return this.i.length;
    }

    this.getNumItems = function(){
        var ret = 0;
        for(x =0; x < this.i.length; x++){
            ret += this.i[x].getQty();
        }
        return Number(ret);
    }

    this.addItem = function(sub){
        var x = 0;
        for(x =0; x < this.i.length; x++){
            if(this.i[x].getSku() == sub.getSku()){
                this.i[x].setQty(this.i[x].getQty() + sub.getQty());
                break;   
            }
        }
        if(x == this.i.length){
            this.i.push(sub);
        }
        this.save();
    }

    this.delItem = function(sub){
        var x = 0;
        for(x in this.i){
            if(this.i[x].getSku() == sub.getSku()){
                break;
            }
        }
        if(this.i[x].getQty() == 1){
            this.i.splice(x,1);
        }else{
            this.i[x].setQty(this.i[x].getQty()-1);
        }
        this.save();
    }

    this.clearSubs = function(){
        this.i = new Array();
        this.n = 0; //maybe?
    }

    this.reset = function(){
        this.s = "";
        this.q = 0;
        this.m = 0;
        this.i = new array();
        this.n = 0;
    }

    this.serialize = function(){
        //var php = new PHP_Serializer();        
        //return php.serialize(this);
        return "";
    }

    this.upgradeToNextBigestContainer = function(){/*[jax, not ajax]*/}

    this.save = function(){
    }
}

var validate = 0;
var close_notified = 0;
var srv_ga_acct = 'UA-1878449-3';
var srv_min_box = 0;
var srv_min_box_sku = '';
var srv_max_box = 0;
var srv_box = new CartItem('',1,0);
var srv_pay_forms = { 6: { 0: '<nobr><input type=\"hidden\" id=\"cc_num\" name=\"cc_num\" class=\"valid\" onfocus=\"return initVisa(this.form.cc_num_0,this.form.cc_num_1,this.form.cc_num_2,this.form.cc_num_3,this.form.cc_num);\" value=\"\" /><input class=\"valid\" type=\"text\" onkeyup=\"gc1(this.form.cc_num_0,this.form.cc_num_1,this.form.cc_num_2,this.form.cc_num_3,this.form.cc_num,4)\" name=\"cc_num_0\" value=\"\" max=\"4\" size=\"3\" />-<input class=\"valid\" type=\"text\" onkeyup=\"gc2(this.form.cc_num_0,this.form.cc_num_1,this.form.cc_num_2,this.form.cc_num_3,this.form.cc_num,4)\" name=\"cc_num_1\" value=\"\" max=\"4\" size=\"3\" />-<input class=\"valid\" type=\"text\" onkeyup=\"gc3(this.form.cc_num_0,this.form.cc_num_1,this.form.cc_num_2,this.form.cc_num_3,this.form.cc_num,4)\" name=\"cc_num_2\" value=\"\" max=\"4\" size=\"3\" />-<input class=\"valid\" type=\"text\" onkeyup=\"gc4(this.form.cc_num_0,this.form.cc_num_1,this.form.cc_num_2,this.form.cc_num_3,this.form.cc_num,4)\" name=\"cc_num_3\" value=\"\" max=\"4\" size=\"3\" /></nobr>', 1: '<nobr><select id=\"cc_exp_month\" name=\"cc_exp_month\" class=\"valid\" ><option value=\"\" selected=\"selected\" ></option><option value=\"01\" >01</option><option value=\"02\" >02</option><option value=\"03\" >03</option><option value=\"04\" >04</option><option value=\"05\" >05</option><option value=\"06\" >06</option><option value=\"07\" >07</option><option value=\"08\" >08</option><option value=\"09\" >09</option><option value=\"10\" >10</option><option value=\"11\" >11</option><option value=\"12\" >12</option></select></nobr>', 2: '<nobr><select id=\"cc_exp_year\" name=\"cc_exp_year\" class=\"valid\" ><option value=\"\" selected=\"selected\" ></option><option value=\"2010\" >2010</option><option value=\"2011\" >2011</option><option value=\"2012\" >2012</option><option value=\"2013\" >2013</option><option value=\"2014\" >2014</option><option value=\"2015\" >2015</option><option value=\"2016\" >2016</option><option value=\"2017\" >2017</option><option value=\"2018\" >2018</option><option value=\"2019\" >2019</option><option value=\"2020\" >2020</option></select></nobr>', 3: '<nobr><input type=\"text\" id=\"cc_cvv\" name=\"cc_cvv\" class=\"valid\" size=\"3\" value=\"\"  /><a href=\"#\" onclick=\"return window.open(\'fg_help.php?id=63\', 0,\'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=375,height=400,left = 490,top = 162\') && false;\">What\'s This?</a></nobr>', 4: 'Credit Card Number', 5: 'Credit Card Expiration', 6: 'Credit Card Expiration', 7: 'Credit Card CVV' }, 7: { 0: '<nobr><input type=\"hidden\" id=\"cc_num\" name=\"cc_num\" class=\"valid\" onfocus=\"return initAmex(this.form.cc_num_0,this.form.cc_num_1,this.form.cc_num_2,this.form.cc_num);\" value=\"\" /><input class=\"valid\" type=\"text\" onkeyup=\"gc1(this.form.cc_num_0,this.form.cc_num_1,this.form.cc_num_2,this.form.cc_num_3,this.form.cc_num,4)\" name=\"cc_num_0\" value=\"\" max=\"4\" size=\"3\" />-<input class=\"valid\" type=\"text\" onkeyup=\"gc2(this.form.cc_num_0,this.form.cc_num_1,this.form.cc_num_2,this.form.cc_num_3,this.form.cc_num,6)\" name=\"cc_num_1\" value=\"\" max=\"6\" size=\"5\" />-<input class=\"valid\" type=\"text\" onkeyup=\"gc3(this.form.cc_num_0,this.form.cc_num_1,this.form.cc_num_2,this.form.cc_num_3,this.form.cc_num,5)\" name=\"cc_num_2\" value=\"\" max=\"5\" size=\"4\" /></nobr>', 1: '<nobr><select id=\"cc_exp_month\" name=\"cc_exp_month\" class=\"valid\" ><option value=\"\" selected=\"selected\" ></option><option value=\"01\" >01</option><option value=\"02\" >02</option><option value=\"03\" >03</option><option value=\"04\" >04</option><option value=\"05\" >05</option><option value=\"06\" >06</option><option value=\"07\" >07</option><option value=\"08\" >08</option><option value=\"09\" >09</option><option value=\"10\" >10</option><option value=\"11\" >11</option><option value=\"12\" >12</option></select></nobr>', 2: '<nobr><select id=\"cc_exp_year\" name=\"cc_exp_year\" class=\"valid\" ><option value=\"\" selected=\"selected\" ></option><option value=\"2010\" >2010</option><option value=\"2011\" >2011</option><option value=\"2012\" >2012</option><option value=\"2013\" >2013</option><option value=\"2014\" >2014</option><option value=\"2015\" >2015</option><option value=\"2016\" >2016</option><option value=\"2017\" >2017</option><option value=\"2018\" >2018</option><option value=\"2019\" >2019</option><option value=\"2020\" >2020</option></select></nobr>', 3: '<nobr><input type=\"text\" id=\"cc_cvv\" name=\"cc_cvv\" class=\"valid\" size=\"3\" value=\"\"  /><a href=\"#\" onclick=\"return window.open(\'fg_help.php?id=66\', 0,\'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=375,height=400,left = 490,top = 162\') && false;\">What\'s This?</a></nobr>', 4: 'Credit Card Number', 5: 'Credit Card Expiration', 6: 'Credit Card Expiration', 7: 'Credit Card CVV' }, 9: { 0: '<nobr><input type=\"text\" id=\"check_bank\" name=\"check_bank\" class=\"valid\" size=\"20\" value=\"\"  /></nobr>', 1: '<nobr><input type=\"text\" id=\"check_routenum\" name=\"check_routenum\" class=\"valid\" size=\"9\" value=\"\"  /></nobr>', 2: '<nobr><input type=\"hidden\" id=\"check_hidden\" name=\"check_hidden\" class=\"valid\" size=\"1\" value=\"\"  /></nobr>', 3: '<nobr><input type=\"text\" id=\"check_acctnum\" name=\"check_acctnum\" class=\"valid\" size=\"20\" value=\"\"  /></nobr>', 4: 'Bank Name', 5: 'Routing Number', 6: '', 7: 'Account Number' }, 8: {  } };
var srv_pay_types = { 1: '6', 2: '6', 3: '6', 4: '7', 5: '9', 6: '8' };

function check_store_enabled(){
    }


/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setSCookie(name, value, expires, path, domain, secure) {
    x_setServerCookie(name, value, setSCookie_cb);
}

function setSCookie_cb(ret){
    return;
}

function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function setSCookieRaw(name, value, expires, path, domain, secure) {
    x_setServerCookie(name, value, setSCookieRaw_cb);
}

function setSCookieRaw_cb(ret){
    return;
}

function setCookieRaw(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + value +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function getCookieRaw(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return (dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteSCookie(name, path, domain) {
    x_delServerCookie(name, deleteSCookie_cb);
}

function deleteSCookie_cb(ret){
    return;
}


function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function stripslashes(s){
    s = s.replace("\\\\", "\\");
    s = s.replace("\\\"", "\"");
    s = s.replace("\\\'", "\'");
    return s;
}
var subtotal_counter = 0;

function adjustShipDate(){
    var time_dd;
    if(time_dd = document.getElementById("ship_date_time")){
        service = document.getElementById("shipper");
        var ship_name = service.options[service.selectedIndex].text;
        if(ship_name.indexOf('In Store') > -1){
            time_dd.style.visibility = "visible";
            time_dd.style.width = "";
        }else{
            time_dd.style.visibility = "hidden";
            time_dd.style.width = "0px";
        }
    }
}

function setCheckoutValues(val){
    if(!val){
        document.getElementById("ajax_ship").innerHTML = "ERROR!";
        document.getElementById("tax_amount").innerHTML = "ERROR!";
        document.getElementById("order_total").innerHTML = "ERROR!";
        return;
    }

    //TAX
    document.getElementById("tax_amount").innerHTML = usd(val.tax);
    if(Number(val.tax) != 0){
        //document.getElementById("tax_descr").innerHTML = "State Tax";
        document.getElementById("ajax_tax1").className = "tax_show";
    }else{
        document.getElementById("ajax_tax1").className = "tax_hide";
    }

    //SHIPPING
    document.getElementById("ajax_ship").innerHTML = usd(val.shipping);

    //HANDLING
    var value_fee_total = 0;
    var x = 0;
    for(x = x; val.handling[x]; x++){
        document.getElementById("handle_amount" + Number(x +1)).innerHTML = usd(val.handling[x].fee);
        document.getElementById("handle_descr" + Number(x +1)).innerHTML = val.handling[x].descr;
        value_fee_total += Number(val.handling[x].fee);
        document.getElementById("ajax_handling" + Number(x +2)).className = "handle_show";
    }
    for(x = x; x < 5; x++){
        document.getElementById("ajax_handling" + Number(x +2)).className = "handle_hide";
        document.getElementById("handle_amount" + Number(x +1)).innerHTML = "0";
    }

    //SUB TOTAL - added to allow qty change from checkout.php
    document.getElementById("subtotal").innerHTML = usd(val.sub_total);

    //MAINTENANCE
    var total = getOrderTotal();
	document.getElementById("order_total").innerHTML = total + "<input name=\"chk_total\" type=\"hidden\" value=\""+remDol2(total)+"\" />";
    nothingStatus(true);
}

function getFieldValue(fld){
    fld = document.getElementById(fld);
    if(fld){
        return fld.value;
    }else{
        return "";
    }
}

function getCheckoutValues2(){
    if(!checkUniqueCall(true)){
        return;
    }

    adjustShipDate();

    state = getFieldValue("state");
    shipper = getFieldValue("shipper");
    zip = getFieldValue("zip");
    alt_address = getFieldValue("alt_address");
    email = getFieldValue("email");
    exempt = getFieldValue("exempt");

    if(!zip || zip.lnegth == 0){
        return;
    }
    
    nothingStatus(false);
    document.getElementById("tax_amount").innerHTML = "Calculating..."; 
    document.getElementById("ajax_ship").innerHTML = "Calculating...";
    x_getCheckoutValues(state, shipper, zip, alt_address, email, exempt, setCheckoutValues);
}

function getCheckoutValues(){
    if(!checkUniqueCall(false)){
        return;
    }
    sajax_cancel();
    getCheckoutValues2();
}

function checkUniqueCall(save){
    state = getFieldValue("state");
    shipper = getFieldValue("shipper");
    zip = getFieldValue("zip");
    alt_address = getFieldValue("alt_address");
    email = getFieldValue("email");
    exempt = getFieldValue("exempt");

    //alert("got form values: state="+state+"; shipper="+shipper+"; zip="+zip+"; alt="+alt_address+"; email="+email+"; exempt="+exempt);
    //alert("static values: state="+this.state2+"; shipper="+this.shipper2+"; zip="+this.zip2+"; alt="+this.alt_address2+"; email="+this.email2+"; exempt="+this.exempt2);
    
    ret = false;
    
    //Only continue if we are send a request with different input, this is more efficient, doesn't re-show the same errors over and over if they occur
    if(this.state2 != state || this.shipper2 != shipper || this.zip2 != zip || this.alt_address2 != alt_address || this.email2 != email || this.exempt2 != exempt || this.subtotal_counter2 != subtotal_counter){
        ret = true;
        //alert("go");
    }else{
        //alert("stop");
    }

    if(save){
        //Keep track of values from call to compare for next time:
        this.state2 = state;
        this.shipper2 = shipper;
        this.zip2 = zip;
        this.alt_address2 = alt_address;
        this.email2 = email;
        this.exempt2 = exempt;
        this.subtotal_counter2 = subtotal_counter;
    }
    
    return ret;
}

function handleNoAjax(){
    alert("Your browser does not support AJAX.  Please check your security settings.  This site requires Javascript and Cookies.");
    location.href = "problem.php?err=AX1";
}

function toggleTextCounter(textAreaId, counterDivId, maxlimit) {
    var textarea = document.getElementById(textAreaId);
    var div = document.getElementById(counterDivId);
    
    if (textarea.value.length > maxlimit) {
        // if too long...trim it!
        textarea.value = textarea.value.substring(0, maxlimit);
    }
    else { 
        // update 'characters left' counter
        var len = maxlimit - textarea.value.length;
        if (len > 999) {
            div.innerHTML = formatNumber(len, "##,###") + ' characters left';
        }
        else if (len == 0) {
            div.innerHTML = "You have reached the limit for this field (" + formatNumber(maxlimit, "##,###") + " characters).";
        }
        else {
            s = (len == 1 ? "" : "s");
            div.innerHTML = len + ' character' + s + ' left';
        }
    }
    div.style.display = (textarea.value.length > 0) ? 'block' : 'none';
}

function showCartContents(par){
    return false;
    var elem = document.getElementById("mini_cart");
    elem.style.top = par.offsetTop;
    elem.style.right = par.offsetLeft;
    elem.className = "mini_cart_show";
}

function hideCartContents(){
    document.getElementById("mini_cart").className = "mini_cart_hide";
}

function doXHRProxy(func) {
    setTimeout(func, 5);
}

function var_dump(obj) {
   if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
   } else {
      return "Type: "+typeof(obj)+"\nValue: "+obj;
   }
}

function remDol(num){
	return num.toString().replace(/\$|\,/g,'');
}

function remDol2(num){
	return num.toString().replace(/\$/g,'');
}

function usd(num) {
	//num = num.toString().replace(/\$|\,/g,'');
	num = num.toString().replace(/\$|\,|\&nbsp\;/g,'');
	if(isNaN(num))
		num = "0";
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
			num.substring(num.length-(4*i+3));
	
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function nothingStatus(bool){
    var n = 0;
    while(obj = document.getElementById("nothing" + n)){
        obj.disabled = !bool;
        n++;
    }
}

function setDynamicForm(fields_obj){
    var prefix = "ajax_pay";
    var fields = new Array();
    var y = 0;
    for(x in fields_obj){
        fields[y] = fields_obj[x];
        y++;
    }
    //alert(fields);
    for(i =0; i < fields.length/2; i++){
        var fXa = document.getElementById(prefix + i + "a");                    
        var fXb = document.getElementById(prefix + i + "b");
        
        if(fields[i] && (fXb || fXa)){
            if(fXa)
                fXa.innerHTML = fields[i+(fields.length/2)];
            if(fXb)
                fXb.innerHTML = fields[i];
        }else if(fXa || fXb){
            if(fXa)
                fXa.innerHTML = "";
            if(fXb)
                fXb.innerHTML = "";
        }
    }
    for(i=i; i < 15; i++){
        var fXa = document.getElementById(prefix + i + "a");
        var fXb = document.getElementById(prefix + i + "b");
                                    
        if(fXa || fXb){
            if(fXa)
                fXa.innerHTML = "";
            if(fXb)
                fXb.innerHTML = "";                        
        }
    }
}

function setPaymentType(ptype_id){
    setDynamicForm(srv_pay_forms[srv_pay_types[ptype_id]]);
    return true;    
}

function addGiftMessage(){
    var handle = window.open('pop_gift.php', 0, 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=375,height=250,left = 490,top = 262');
    if(!handle){
        alert("The gift message window could not be opened due to a popup blocker.  Please disable it and try again");
    }
    return false;
}

function addBoxGiftMessage(){
    var handle = window.open('pop_gift.php?gift_box=1', 0, 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=375,height=250,left = 490,top = 262');
    if(!handle){
        alert("The gift message window could not be opened due to a popup blocker.  Please disable it and try again");
    }
    return false;
}

function addNotes(){
    var handle = window.open('pop_notes.php', 0, 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=375,height=250,left = 490,top = 262');
    if(!handle){
        alert("The notes window could not be opened due to a popup blocker.  Please disable it and try again");
    }
    return false;
}

function setAltAddress(addr_id, mode){
    //alert(addr_id);
    if(!addr_id){
        obj = document.getElementById("alt_address");
        addr_id = obj.options[obj.selectedIndex].value;
        //alert(addr_id);
    }
	if((addr_id == 0 && mode != "quiet") || mode == "edit"){
	    //document.getElementById("alt_address").value = 0;
		var handle = window.open('alt_address.php?id='+addr_id, 0, 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=375,height=310,left = 490,top = 262');
		if(!handle){
			alert("The shipping address window could not be opened due to a popup blocker.  Please disable it and try again");
		}
		if(mode != "edit"){
			document.getElementById("ajax_alt_ship").innerHTML = "";
		}
	}else if(addr_id <= 0){
		document.getElementById("ajax_alt_ship").innerHTML = "";
	}else{
		document.getElementById("ajax_alt_ship").innerHTML = "&nbsp;&nbsp;<a href=\"#\" onclick=\"return setAltAddress("+addr_id+", 'edit');\">Edit</a>";
	}
	zip_f = document.getElementById('zip');
	isCart = document.getElementById("order_total");
	//if(isCart && zip_f && (zip_f.value != "") && (mode != "edit")){
    	//getShippingRate(document.getElementById('zip'), document.getElementById('shipper'));
    //}
    //getHandlingFees(document.getElementById('state'), document.getElementById('zip'), document.getElementById('email'), document.getElementById('shipper'));
    //getTaxFromState(document.getElementById('state'));
    getCheckoutValues();
}

function getAltAddress(addr_id){
	location.href = "?id="+addr_id;
	return true;
}

function cancelPopup(){
	window.close();
	return true;
}

function getTaxFromState(state){
    getCheckoutValues();
}

function getShippingRate(zip_dd, service){
    getCheckoutValues();
}

function getOrderTotal(){
    var handling_fees = false;
    var handling = 0;
    for(var x = 1; x < 6; x++){
        handling_fees = document.getElementById("handle_amount" + x);
        if(handling_fees && handling_fees.innerHTML > ""){
            handling += Number(remDol(handling_fees.innerHTML));
        }
    }
    return usd(handling + Number(remDol(document.getElementById("ajax_ship").innerHTML)) + Number(remDol(document.getElementById("tax_amount").innerHTML)) + Number(remDol(document.getElementById("subtotal").innerHTML)));
}

function getHandlingFees(state_dd, zip_dd, email_dd, service_dd){
    getCheckoutValues();
}

function delItem(item, descr, qtd){
    if(qtd == "" || qtd == null){
        qtd = 1;   
    }
    if(confirm("Are you sure you want to remove "+qtd+"x "+descr+" from your cart?")){
        var ci = new CartItem(item, qtd);
        x_acDelItem(item,qtd,null);
        location.reload();
    }
}

function delItemByIndex(index, descr, qtd){
    if(qtd == "" || qtd == null){
        qtd = 1;   
    }
    if(confirm("Are you sure you want to remove "+qtd+"x "+descr+" from your cart?")){
        x_acDelByIndex(index,reloadMe);
    }
}

function qtyByIndex(index, qtd, recompute){
    if(qtd == "" || qtd == null){
        qtd = 1;
    }
    if(recompute == "" || recompute == null){
        recompute = false;
    }
    if(isNaN(qtd) || qtd < 1 || qtd != Math.floor(qtd)){
        alert("Invalid quantity, please re-enter the desired quantity and try again.");
    }else{
        if(recompute){ // specifically for checkout.php
            var old_q = document.getElementById("cart_item_qty_"+index).innerHTML;
            var old_p = document.getElementById("cart_item_amount_"+index).innerHTML;
            var up = old_p/old_q;
            
            document.getElementById("cart_item_qty_"+index).innerHTML = qtd;
            document.getElementById("cart_item_amount_"+index).innerHTML = remDol(usd(qtd*up));
            //document.getElementById("subtotal").innerHTML = "Calculating...";
            subtotal_counter++;
            
            x_acQtyByIndex(index,qtd,getCheckoutValues2);
        }else{
            x_acQtyByIndex(index,qtd,reloadMe);
        }
    }
}

function qtyByIndexFromCheckout(index, qtd){
    qtyByIndex(index, qtd, true);
}

function reloadMe(){
    location.reload();
}

function addItem(item, descr, qtd){
    if(qtd == "" || qtd == null){
        qtd = 1;   
    }
    if(isNaN(qtd) || qtd < 1 || qtd != Math.floor(qtd)){
        alert("Invalid quantity, please re-enter the desired quantity and try again.");
        return false;
    }
	if(confirm("Are you sure you want to add " + qtd + "x " + descr + " to your cart?")){
          x_acAddItem(item, qtd, null);
	}
	return false;
}


function cart_noneOnSubmit(sbutton){
    sbutton.disabled = true;
    sbutton.form.submit();
    return true;
}

function cart_existOnSubmit(sbutton){
    sbutton.disabled = true;
    sbutton.form.submit();
    return true;
}

function cart_newOnSubmit(sbutton){
    sbutton.disabled = true;
    sbutton.form.submit();
    return true;
}

function alt_addressOnSubmit(sbutton){
	sbutton.disabled = true;
    sbutton.form.submit();
	return true;
}

function commit_cart_existOnSubmit(sbutton){
	sbutton.disabled = true;
    sbutton.form.submit();
	return true;
}

function commit_cart_newOnSubmit(sbutton){
      sbutton.disabled = true;
    sbutton.form.submit();
      return true;
}

function commit_cart_noneOnSubmit(sbutton){
      sbutton.disabled = true;
    sbutton.form.submit();
      return true;
}

function giftOnSubmit(sbutton){
      sbutton.disabled = true;
    sbutton.form.submit();
      return true;
}

function notesOnSubmit(sbutton){
      sbutton.disabled = true;
    sbutton.form.submit();
      return true;
}

