function calcTotal(){
    //	var qtyFields = new Array('qtyChalkboard','qtyFish','qtyGrill','qtyFlatware','qtyPizza','qtyLemonade','qtyMargerita','qtyCosmo','qtyWine','qtyBeer','qtyCrab');
    var total = 0;
	
    items = document.getElementsByName('hew');	
	
    for (x in items) {
        if (items[x].value != undefined) {
            qty = document.getElementById(items[x].value).value;
            if(qty == parseInt(qty)){
                total += parseInt(qty);
            }
        }
    }

    document.getElementById('attachments').innerHTML = '<em>[' + total + ' selected ]</em>';  	  

}

function incrementQty_OLDWHOLESALE(formId){
    if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
        return;
    }
    document.getElementById(formId).value = parseInt(document.getElementById(formId).value) + 4;
    calcTotal();
}

function decrementQty_OLDWHOLESALE(formId){
    if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
        return;
    }
    document.getElementById(formId).value = (document.getElementById(formId).value > 3 ? parseInt(document.getElementById(formId).value) - 4 : 0);
    calcTotal();
}


function incrementQty(formId){
    if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
        return;
    }
    document.getElementById(formId).value = parseInt(document.getElementById(formId).value) + 1;
    calcTotal();
}

function decrementQty(formId){
    if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
        return;
    }
    document.getElementById(formId).value = (document.getElementById(formId).value > 2 ? parseInt(document.getElementById(formId).value) - 1 : 0);
    calcTotal();
}

function incrementQtyMini_OLDWHOLESALE(formId,amount){
    if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
        return;
    }
    document.getElementById(formId).value = parseInt(document.getElementById(formId).value) + amount;
    calcTotal();
}

function decrementQtyMini_OLDWHOLESALE(formId,amount){
    if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
        return;
    }
    document.getElementById(formId).value = (document.getElementById(formId).value > (amount - 1) ? parseInt(document.getElementById(formId).value) - amount : 0);
    calcTotal();
}




function incrementQtyMini(formId){
    if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
        return;
    }
    document.getElementById(formId).value = parseInt(document.getElementById(formId).value) + 1;
    calcTotal();
}

function decrementQtyMini(formId){
    if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
        return;
    }
    document.getElementById(formId).value = (document.getElementById(formId).value > 2 ? parseInt(document.getElementById(formId).value) - 1 : 0);
    calcTotal();
}


function incrementPlateQty_OLDWHOLESALE(formId){
    if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
        return;
    }
    document.getElementById(formId).value = parseInt(document.getElementById(formId).value) + 3;
}

function decrementPlateQty_OLDWHOLESALE(formId){
    if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
        return;
    }
    document.getElementById(formId).value = (document.getElementById(formId).value > 2 ? parseInt(document.getElementById(formId).value) - 3 : 0);
}


function incrementPlateQty(formId){
    if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
        return;
    }
    document.getElementById(formId).value = parseInt(document.getElementById(formId).value) + 1;
}

function decrementPlateQty(formId){
    if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
        return;
    }
    document.getElementById(formId).value = (document.getElementById(formId).value > 1 ? parseInt(document.getElementById(formId).value) - 1 : 0);
}

function addwheeltocart() {
    total = 0;
    hap_ev = document.getElementById('HAP_EV').value;	
    items = document.getElementsByName('hew');	
    total += parseInt(hap_ev);
		
    idata = "";
    for (x in items) {
        if (items[x].value != undefined) {
            qty = document.getElementById(items[x].value).value;
            if (parseInt(qty) > 0) {
                idata += items[x].id + "|" + qty + "$";
                total += parseInt(qty);
            }
        }
    }
    inputString = hap_ev+"^"+idata;	
    document.getElementById('CARTRESULTS').innerHTML = total + " items added to your cart<br /><br /><a href='checkout.php'><img src='images/checkout.gif' alt='check out' /></a>";
    $.post("cart_ajax/addwheeltocart.php", {
        queryString: ""+inputString+""
    }, function(data){
        if (data != "") alert(data);
    });
}
	
function addminitocart() {
    total = 0;
    hap_ev = document.getElementById('HAPEV-9.25PL').value;	
    items = document.getElementsByName('hew');	
    total += parseInt(hap_ev);
		
    idata = "";
    for (x in items) {
        if (items[x].value != undefined) {
            qty = document.getElementById(items[x].value).value;
            if (parseInt(qty) > 0) {
                idata += items[x].id + "|" + qty + "$";
                total += parseInt(qty);
            }
        }
    }
    inputString = hap_ev+"^"+idata;	
    document.getElementById('CARTRESULTS').innerHTML = total + " items added to your cart<br /><br /><a href='checkout.php'><img src='images/checkout.gif' alt='check out' /></a>";
    $.post("cart_ajax/addwheeltocart.php", {
        queryStringMini: ""+inputString+""
    }, function(data){
        if (data != "") alert(data);
    });
}


function login() {
    uname = document.getElementById('login_name').value;	
    upass = document.getElementById('login_password').value;
    inputString = uname+"^"+upass;	
    $.post("cart_ajax/login.php", {
        queryString: ""+inputString+""
    }, function(data){
        var update = new Array();
        if (data.indexOf("|") >= 0) {
            update = data.split('|');
            document.getElementById('login_error').innerHTML = update[1];	
        }
        else {
            window.location = "index.php";
        }
    });
}
	
function getpasswordhint() {
    uname = document.getElementById('login_name').value;	
    fname = document.getElementById('first_name').value;
    inputString = uname+"^"+fname;	
    $.post("cart_ajax/gethint.php", {
        queryString: ""+inputString+""
    }, function(data){
        var update = new Array();
        if (data.indexOf("|") >= 0) {
            update = data.split('|');
            document.getElementById('login_error').innerHTML = update[1];	
            document.getElementById('hint').innerHTML = "";	
        }
        else {
            document.getElementById('login_error').innerHTML = "";	
            document.getElementById('hint').innerHTML = data;	
        }
    });
}
	 
function addtocart(pid, qty, options, personal, qtyfield) {
    if (qtyfield != "") {
        qty2 = document.getElementById(qtyfield).value;	
    }
    else {
        qty2 = qty;
    }
    	
    var personal = document.getElementById(personal).value;
    
    var personal2 = '';
    var misc_other = $('#misc_other').val();
    
    $('#options_list input[name^=personal_]').each(function(){
        if($(this).attr('type') == 'text'){
            if($(this).val() != ''){
                personal2 += $(this).val()+'¯'+$(this).attr('name')+'¡'+$(this).attr('rel')+'£';
            }
        }
        if($(this).attr('type') == 'radio'){
            if($(this).val() != '' && $(this).is(':checked')){
                personal2 += $(this).val()+'¯'+$(this).attr('name')+'¡'+$(this).attr('rel')+'£'; 
            }
        }
    });
    
    $('#options_list textarea[name^=personal_]').each(function(){
        if($(this).val() != ''){
            personal2 += $(this).val()+'¯'+$(this).attr('name')+'¡'+$(this).attr('rel')+'£'; 
        }
    });
    
    $('#options_list select[name^=personal_]').each(function(){
        if($(this).val() != ''){
            personal2 += $(this).val()+'¯'+$(this).attr('name')+'¡'+$(this).attr('rel')+'£'; 
        }
    });    
    
    personal = urlencode(personal+'±'+personal2+'±'+misc_other);    
    
    inputString = pid+"^"+qty2+"^"+options+"^"+personal;    
        
    
    $.post("cart_ajax/addtocart.php", {
        queryString: ""+inputString+""
    }, function(data){
        $('#cart').jqmShow();
        window.scrollTo(0,0);
    });
}
	
function addqp(pid) {
    qty2 = 1;
    options = "";
    personal="";
    inputString = pid+"^"+qty2+"^"+options+"^"+personal;	
    $.post("cart_ajax/addtocart.php", {
        queryString: ""+inputString+""
    }, function(data){
        window.location = "checkout.php";
    });
}

function updateorder(pid, qty, options, personal) {
    itemcount = document.getElementById('itemcount').value;	
    crt = "";
    for (i = 1; i <= itemcount; i++) {
        pid = document.getElementById('ITEM'+i).value;	
        qty = document.getElementById('Q'+i).value;	
        options = document.getElementById('OPTION'+i).value;	
        personal = urlencode(document.getElementById('PERSONAL'+i).value);	
        crt += pid+"^"+qty+"^"+options+"^"+personal+"^|"
    }
    $.post("cart_ajax/updatecart.php", {
        queryString: ""+crt+""
    }, function(data){
        //alert(data);
        window.location = "checkout.php";
    });
}

function ccvalidate(ccnum) {
    $.post("cart_ajax/ccValidate.php", {
        ccnum: ""+ccnum+""
    }, function(data){
        if (data.length > 10) alert(data);
    });
}

function getorderemail(oid) {
    $.post("receipt-email.php", {
        id: ""+oid+""
    }, function(data){
        $.post("send-email.php", {
            id: ""+urlencode(data)+""
        }, function(data){
            });
    });
}

function urlencode (str) {
    str = (str+'').toString();
    
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}

