/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function fast_shipping(shipping){
    var oscsid = $("#oscsid").html();
    //alert(oscsid);
    $.ajax({
        type:"post",
        url:"fast_checkout_shipping_process.php",
        data:"action=process&shipping="+shipping+"&"+oscsid,
        beforeSend:function(){
            shipping_click=false;
            payment_click=false;
            $('.shipping').attr("disabled", true);
            $('.payment').attr("disabled", true);
            $("#shipping_msg").html("<img src='images/loading.gif' border='0' />");
        },
        success:function(msg){
            
            $('.shipping').attr("disabled", false);
            $('.payment').attr("disabled", false);
            $("#shipping_msg").text("total order amount:"+msg);
            shipping_click=true;
            payment_click=false;     
            var  payment_type = $(".payment[@type=radio][@checked]").val();         
           //没有支付方式（没有类和没有id）
           if($(".payment").val() == undefined && $("#payment").val() == undefined ){               
               fast_payment('');
           }
           //有一个支付方式（没有类但是有id）
            if($(".payment").val() == undefined && $("#payment").val() != undefined ){
               fast_payment($("#payment").val());
           }
           //有两个支付方式以上（如果之前有选择支付方式就自动选择相应支付方式；页面自加载的时候不选择支付方式，让支付人自行选择）
           if(payment_type != undefined  ){              
               fast_payment(payment_type);
           }          
        }
    });
}

function fast_payment(payment){
    var oscsid = $("#oscsid").html();
    $.ajax({
        type:"post",
        url:"fast_checkout_payment_process.php",
        data:"action=process&payment="+payment+"&"+oscsid,
        beforeSend:function(){
            payment_click=false;
            payment_processing = true;
            $('.shipping').attr("disabled", true);
            $('.payment').attr("disabled", true);
            $("#payment_msg").html("<img src='images/loading.gif' border='0' />");
        },
        success:function(msg){
            $('.shipping').attr("disabled", false);
            $('.payment').attr("disabled", false);
            //$("#payment_msg1").text(msg);
            $("#payment_msg").html(msg);
            shipping_click=true;
            payment_click=true;
            payment_processing = false;
        }
    });
}

function paymentformsubmit(){
        //alert("payment_click="+payment_click);
    if (shipping_click==false && payment_click==false){
        alert("Please waitting shipping method processing!!!");
    }else if(shipping_click==true && payment_click==false){
        if (payment_processing == true){
            alert("Please waitting payment method processing!!!");
        }else{
            alert("Please select payment method!!!");
        }        
    }else{
        $("#checkout_confirmation").submit();
    }
        
}

var shipping_click=false;
var payment_click=false;
var payment_processing = false;
