﻿function AddCart(artid,mes){
    new Ajax.Request('/admin/webs.aspx', {
        method: 'post',
        parameters: { f: "Add2Cart",
            artid: artid
        }
                        , onFailure: function(transport) { alert(transport.responseText); }
                        , onSuccess: function(transport) { responseCart(mes) }
    });
		}					
		function WiewCart(){
		    window.open('/admin/order.aspx', '', 'width=400,height=450,resizable,scrollbars,status=yes');
		}
        function mailThisUrl(mess) {
            new Ajax.Request('/admin/webs.aspx', {
                method: 'post',
                parameters: { f: "mailThisUrl",
					mess:mess
                }
                        , onFailure: function(transport) {  }
                        , onSuccess: function(transport) { $("mailThisUrl").update(transport.responseText); }
            });
        }
		function responseCart(mes) {
		    if (mes.length != 0) { alert(mes) };
		}
		function ShowCart() {
		    new Ajax.Request('/admin/webs.aspx', {
		        method: 'post',
		        parameters: { f: "ShowCart" ,
		        messcart: $("messcart").innerHTML
		        }
                        , onFailure: function(transport) { $("cart_left").innerHTML = transport.responseText; }
                        , onSuccess: function(transport) { $("cartstatus").innerHTML = transport.responseText;  }
		    });
		}

		function Add2Cart(artid) {
		    new Ajax.Request('/admin/webs.aspx', {
		        method: 'post',
		        parameters: { f: "Add2Cart",
		            artid: artid
		        }
                        , onFailure: function(transport) { $("cart_left").innerHTML = transport.responseText; }
                        , onSuccess: function(transport) { $("cart_left").innerHTML = transport.responseText; tinhtoan(); }
		    });
		}
		function GetCart() {
		    new Ajax.Request('/admin/webs.aspx', {
		        method: 'post',
		        parameters: { f: "ShowCart" }
                        , onFailure: function(transport) { $("cart_left").innerHTML = transport.responseText; }
                        , onSuccess: function(transport) { $("cart_left").innerHTML = transport.responseText; tinhtoan(); }
		    });
		}
		function UpdateCart(artid, NewQty) {
			if(checkNumber(NewQty)){			
		    new Ajax.Request('/admin/webs.aspx', {
		        method: 'post',
		        parameters: { f: "UpdateCart",
		            artid: artid,
		            NewQty: NewQty
		        }
                        , onFailure: function(transport) { $("cart_left").innerHTML = transport.responseText; }
                        , onSuccess: function(transport) {tinhtoan()}
		    });
			}
		}
		function DeleteItem(artid) {
		    new Ajax.Request('/admin/webs.aspx', {
		        method: 'post',
		        parameters: { f: "DeleteItem",
		            artid: artid
		        }
                        , onFailure: function(transport) { $("cart_left").innerHTML = transport.responseText; }
                        , onSuccess: function(transport) { $("cart_left").innerHTML = transport.responseText; }
		    });
		}


		function tinhtoan() {
		    tot = 0;
		    ton = $("totals").value;
		    for (i = 1; i <= ton; i++) {
		        P_price = parseFloat($("P_price" + i).value);
		        soluong = parseInt($("soluong" + i).value);
		        if (isNaN(P_price)) { P_price = 0 }
		        if (isNaN(soluong)) { soluong = 0 }
		        $("thanhtien" + i).value = P_price * soluong;
		        tot += P_price * soluong;
		    }
		    $("tong").value = tot;
		}		
