var base_price;
var cotton_price;
var size_price;
var customizations_price;
var big_image_type;
var big_image_color;
var require_disclaimer_agreement = false;

function setSizePrice( price ) {
    size_price = parseFloat(price);
}

function setCustomizationsPrice( price ) {
    size_price = parseFloat(price);
}

function setCottonPrice( price ) {
    cotton_price = parseFloat(price);
}

function setBasePrice( price ) {
    base_price = parseFloat(price);
}

function getProductPrice () {
    return base_price + size_price + cotton_price + customizations_price;
}

function initProductPrice ( base, cotton, size, customizations ) {
    base_price = parseFloat(base);
    cotton_price = parseFloat(cotton);
    size_price = parseFloat(size);
    customizations_price = parseFloat(customizations);
}

function initBigImage (type, color) {
    big_image_type = type;
    big_image_color = color;
}

function setBigImageColor(color){
    big_image_color = color;
}

function setBigImageType(type){
    big_image_type = type;
}

function getBigImageOptions(){
    var x = "type="+big_image_type+"&color="+big_image_color;
    return x;
}

function getQuantity(){
    var x = document.getElementById("cart_item_quantity").value;
    return x;
}

function updatePrice(){
    var x = getProductPrice();
    var y = getQuantity();
	if (y < 1 ) {
		document.getElementById("cart_item_quantity").value = 1;
		y = getQuantity();
	}
    document.getElementById("cart_item_price").value = parseFloat(x);
    document.getElementById("product_price_box").innerHTML =  formatCurrency(x * y);
}

function setRequireDisclaimerAgreement(x){
    /* disabling this until I have time to debug */
	require_disclaimer_agreement = false;
}

function enableDisableAddToCart(){
    var enableDisable=false;
    if ( document.getElementById('cart_item_option_color').value == '')
        enableDisable = true;
    if ( document.getElementById('cart_item_option_style').value == '')
        enableDisable = true;
    if ( document.getElementById('cart_item_option_cotton').value == '')
        enableDisable = true;
    if ( document.getElementById('cart_item_option_size').value == '')
        enableDisable = true;
    if ( document.getElementById('cart_item_quantity').value == '' || document.getElementById('cart_item_quantity').value < 1)
        enableDisable = true;
    if (require_disclaimer_agreement == true && document.getElementById('disclaimer_read_and_agree').checked == false)
        enableDisable = true;
    document.getElementById('cart_item_add_to_cart').disabled = enableDisable;
}

function toggleCustomizedOptionEnabled(option_id, option_text){
    var enableDisable;
    if(document.getElementById('options_customized_'+option_id+'_enable').checked){
        if(document.getElementById('customized_'+option_id).type != "hidden"){
            document.getElementById('customized_'+option_id).value = "";
		}
		enableDisable = false;
		
    } else {
		if (document.getElementById('customized_' + option_id).type != "hidden") {
			document.getElementById('customized_' + option_id).value = option_text;
		}
		enableDisable = true;
    }
    document.getElementById('customized_'+option_id).disabled = enableDisable;
}

function updateCustomizationsPrice(option_id, option_price){
    if (document.getElementById('options_customized_' + option_id + '_enable').checked) {
        customizations_price = customizations_price + parseFloat(option_price);
    } else {
        customizations_price = customizations_price - parseFloat(option_price);
    }
}

function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/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);
}