function doCartAction(i, a) {
    var f = document.forms.frmCart;
    var f2 = document.forms.frmCardSearch;
    var today = new Date();
    var expires = new Date();

    f.CartItem.value = i;
    f.CartAction.value = a;

    switch(a) {
        case "AddItemQty":
            var x = eval('f2.qty' + i + '.value');
            f.CartQty.value = x;
            break
        case "AddItemFoilQty":
            var x = eval('f2.qtyf' + i + '.value');
            f.CartQty.value = x;
            break
        case "MinCart":
            expires.setTime(today.getTime() + 1000*60*60*24*365);
            setCookie("CartState", "minimized", expires);
            break
        case "MaxCart":
            expires.setTime(today.getTime() - 1000*60*60*24*365);
            setCookie("CartState", "", expires);
            break
        default:
            // do nothing
    }
    
    f.submit();
}

// add "confirm" to functions like clear cart and delete item

function doCheckout() {
    var f = window.document.forms.frmLogin;

    if (f.hidUser.value != "") {
        // user is signed in, proceed to checkout
        doCartAction(0, "Checkout1");
    } else {
        // redirect to registration page
        doCartAction(0, "Checkout0");
    }

    // if signed in, proceed to cart-confirm page
    // -- do first pass at "correcting" cart (items now out of stock)
    // -- calculate shipping costs for order
    // -- offer payment options (no PayPal under $5.00 total)
    // -- checkout: commit order to Pending table
    // ---- if PayPal payment, get confirmation, move order to Paid table
    // ---- send e-mail to buyer and to ebay@docangst.com

    // if not signed in, proceed to register page with new instructions
}


// -=-=-=-==-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-==-=-=-


// cookie.js
// Generic reusable cookie-handling code for JavaScript.

function setCookie(strName, strValue, dtExpires) {
	// Sets document.cookie equal to a single string value.

	document.cookie = strName + "=" + escape(strValue) + ((dtExpires == null) ? "" : ("; expires=" + dtExpires.toGMTString()));
}

function getCookie(strName) {
	// Retrieves a single value from document.cookie based on its
	// property name.

	var strNameEq = strName + "=";
	var dc = document.cookie;

	if (dc.length > 0) {  // any cookies home?
		offset = dc.indexOf(strNameEq);
		if (offset != -1) {  // does the sought cookie exist?
			offset += strNameEq.length;
			end = dc.indexOf(";", offset);
			if (end == -1)
				end = dc.length;
			return unescape(dc.substring(offset, end));
		} else {
			return "nocookie";
		}
	} else {
		return "nocookie";
	}
}

function makeComplexCookie(arrProperties, arrValues) {
	// Takes in two arrays, arrProperties and arrValues, and parses
	// them into a complex cookie of the form p1=v1+p2=v2+p3=v3+...

	var strCookie = "";

	for (i = 0; i < arrProperties.length; i++) {
		strCookie += arrProperties[i] + ":" + arrValues[i];
		if (i != arrProperties.length - 1)
			strCookie += "+";
	}
	return strCookie;
}

function getComplexCookie(strCookie) {
	// Takes in a complex cookie of the form p1=v1+p2=v2+p3=v3+...
	// and parses it into a single value-pair array.

	var arrCookiePairs = strCookie.split("+");
	var strPair = "";
	var arrCookie = new Array();

	for (i = 0; i < arrCookiePairs.length; i++) {
		strPair = arrCookiePairs[i];
		var arrPairSplit = strPair.split(":");
		var strProperty = arrPairSplit[0];
		var strValue = arrPairSplit[1];
		arrCookie[strProp] = strValue;
	}
	return arrCookie;
}

