function setVar(item) {
	var theForm = document.accessories;
	if (theForm[item].checked == true) {
		Set_Cookie('acc[' + theForm[item].name + ']', 1, 30, "/");
	} else {
		Set_Cookie('acc[' + theForm[item].name + ']', 0, -5, "/");
	}
}

function setGuitarVar(item) {
	var theForm = document.guitarbuilder;
	var theItem=item.substring(4);
	if (theForm[item].checked == true) {
		Set_Cookie('acc[' + theItem + ']', 1, 30, "/");
	} else {
		Set_Cookie('acc[' + theItem + ']', 0, -5, "/");
	}
}

function setAccessoryAdded(product, item) {
	if (typeof setAccessoryAdded.idx == 'undefined') {
		setAccessoryAdded.idx=0;
	}
	var theForm = document.accessories;
	if (theForm[item].checked == true) {
		setAccessoryAdded.idx += 1;
	} else {
		setAccessoryAdded.idx -= 1;
	}
	if (parseInt(setAccessoryAdded.idx) > 0) {
		Set_Cookie('cartacc[' + product + ']',setAccessoryAdded.idx, 30, "/");
	} else {
		Set_Cookie('cartacc[' + product + ']',"", -5, "/");
	}
}

function unsetVar(item) {
	Set_Cookie('acc[' + item + ']', 0, -5, "/");
}

function Set_Cookie(name, value, expires, path, domain, secure) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime(today.getTime());

	/*
	 * if the expires variable is set, make the correct expires time, the current
	 * script below will set it for x number of days, to make it for hours, delete *
	 * 24, for minutes, delete * 60 * 24
	 */
	if (expires) {
		//expires = expires * 1000 * 60 * 60 * 24;
		expires = expires * 1000 * 60;
	}
	var expires_date = new Date(today.getTime() + (expires));

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

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ ) {
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );

		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 ) {
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) {
		return null;
	}
}

function computeNewPrices(item, newlst, newdir, newsale, newship, isflat) {
	if (typeof computeNewPrices.mylist == 'undefined') {
		computeNewPrices.mylist = parseFloat(parent.document.forms["priceform"].newlist.value);
	}
	if (typeof computeNewPrices.mydirect == 'undefined') {
		computeNewPrices.mydirect = parseFloat(parent.document.forms["priceform"].newdirect.value);
	}
	if (typeof computeNewPrices.mysale == 'undefined') {
		computeNewPrices.mysale = parseFloat(parent.document.forms["priceform"].newsale.value);
	}
	if (typeof computeNewPrices.myship == 'undefined') {
		computeNewPrices.myship = parseFloat(parent.document.forms["priceform"].newship.value);
	}
	if (typeof computeNewPrices.myflat == 'undefined') {
		computeNewPrices.myflat = parseFloat(parent.document.forms["priceform"].flatctr.value);
	}
	theForm=document.accessories;
	// Determine if we're Adding the new Prices 
	// or Subtracting them
	if (theForm[item].checked == true) {
		lstchg=(parseFloat(computeNewPrices.mylist) + newlst).toFixed(2);
		computeNewPrices.mylist=lstchg;
		dirchg=(parseFloat(computeNewPrices.mydirect) + newdir).toFixed(2);
		computeNewPrices.mydirect=dirchg;
		if (newsale==0 && computeNewPrices.mysale==0) {
			salchg=(parseFloat(computeNewPrices.mydirect) + (parseFloat(newdir) * .90)).toFixed(2);
		} else if (newsale==0) {
			salchg=(parseFloat(computeNewPrices.mysale) + (parseFloat(newdir) * .90)).toFixed(2);
		} else {
			salchg=(parseFloat(computeNewPrices.mysale) + (newsale * .90)).toFixed(2);
		}
		computeNewPrices.mysale=salchg;
		if (computeNewPrices.myflat < 1) {
			shpchg=(parseFloat(computeNewPrices.myship) + newship).toFixed(2);
			computeNewPrices.myship=shpchg;
		} else {
			shpchg=(parseFloat(computeNewPrices.myship)).toFixed(2);
		}
		cdtchg=Math.ceil(dirchg * .03);
		if (isflat) {
			++computeNewPrices.myflat;
			parent.resetPricing(lstchg,dirchg,salchg,shpchg,cdtchg,1);
		} else {
			parent.resetPricing(lstchg,dirchg,salchg,shpchg,cdtchg,0);
		}
	} else {
		lstchg=(parseFloat(computeNewPrices.mylist) - newlst).toFixed(2);
		dirchg=(parseFloat(computeNewPrices.mydirect) - newdir).toFixed(2);
		if (newsale==0 && (parseFloat(computeNewPrices.mysale) - (parseFloat(newdir) * .90).toFixed(2))==parseFloat(computeNewPrices.mydirect)) {
			salchg=parseFloat("0").toFixed(2);
		} else if (newsale==0) {
			salchg=(parseFloat(computeNewPrices.mysale) - (parseFloat(newdir) * .90)).toFixed(2);
		} else {
			salchg=(parseFloat(computeNewPrices.mysale) - (newsale * .90)).toFixed(2);
		}
		if (computeNewPrices.myflat == 1 || newship != 9.5) {
			shpchg=(parseFloat(computeNewPrices.myship) - newship).toFixed(2);
		} else {
			shpchg=(parseFloat(computeNewPrices.myship)).toFixed(2);
		}
		cdtchg=Math.ceil(dirchg * .03);
		computeNewPrices.mylist=lstchg;
		computeNewPrices.mydirect=dirchg;
		computeNewPrices.mysale=salchg;
		computeNewPrices.myship=shpchg;
		if (isflat) {
			--computeNewPrices.myflat;
			parent.resetPricing(lstchg,dirchg,salchg,shpchg,cdtchg,1);
		} else {
			parent.resetPricing(lstchg,dirchg,salchg,shpchg,cdtchg,0);
		}
	}
}
