﻿/// <reference path="jquery-1.3.2-vsdoc.js" />

//UPDATE CART
//function updatecart(formid){  
//    $.post('/sc_addtocart.ashx', $('#' + formid).serialize(), function(data) {
//         var resp = transport.data.split("^");
//    })
//}

function updatecart(formid){  
    $.post('/sc_addtocart.ashx', $('#' + formid).serialize(), function(data) {
         //var resp = transport.data.split("^");
        refreshcart('minicartwrapper');
        var resp = data.split("^");
        $('#cartcountwrappertop').html(resp[0]);
        $('#carttotalwrappertop').html(resp[1]);
    })
}

//ADD TO CART
function addtoshoppingcart(formid, messageid) {
    messageid = '#' + messageid;
    var Digital = new Date();
    var refresh = Digital.getSeconds() + Digital.getHours() + Digital.getMinutes();
    $.post('/sc_addtocart.ashx?refresh=' + refresh, $('#' + formid).serialize() + '&sc_cart_add.x=1', function(data) {
        $("#addbutton").attr("src", "/images/buttons/added.gif");
        setTimeout(function() { $("#addbutton").attr("src", "/images/buttons/addtocart.gif"); }, 3000);
        setTimeout(function() {
            $(messageid).fadeOut(1000);
        }, 5000);

        refreshcart('minicartwrapper');

        var resp = data.split("^");
        $('#cartcountwrappertop').html(resp[0]);
        $('#carttotalwrappertop').html(resp[1]);

    })
}

//ADD TO CART
function addtoshoppingcart2(formid, messageid) {
    var keepgoing = false;
    $('#' + formid).find(':input').each(function() {
        if (this.name.indexOf('item_itemid') > -1) {
            if (this.value != '') {
                keepgoing = true;
            }
        }

    }); 
    if (keepgoing) {
        addtoshoppingcart(formid, messageid);
        
        } else {
            $('#' + messageid).html('<font color="red">Please enter a size.</font>');
        }
}

//CHECK QTY
function checkqty(formid) {
 
    
}

    
//REFRESH CART
function refreshcart(divid) {
    divid = '#' + divid;    
    var Digital = new Date()
    var refresh = Digital.getSeconds() + Digital.getHours() + Digital.getMinutes();
    $.get('/ajax/loadcart.aspx?refresh=' + refresh, '', function(data) {
        $(divid).html(data);
    });
}

//DELETE FROM CART
function remitem_cartpage(cartrow,cartitemid){
    $('#' + cartrow).fadeOut('normal');
    $.get('/sc_deletecartitem.ashx?id=' + cartitemid, '', function(data) {
        refreshcart('minicartwrapper');

        var resp = data.split("^");
        $('#cartcountwrappertop').html(resp[0]);
        $('#carttotalwrappertop').html(resp[1]);
        if ($('#carttotal')){
            $('#carttotal b').html(resp[1]);
        }
    });
   // 
}