function validate_shopper_info()
{
    var shopper_name        = $("#cntnt01cart_shopper_name").val();
    var shopper_surname     = $("#cntnt01cart_shopper_surname").val();
    var shopper_born_date   = $("#cntnt01cart_shopper_born_date").val();
    var shopper_city        = $("#cntnt01cart_shopper_city").val();
    var shopper_adress      = $("#cntnt01cart_shopper_adress").val();
    var shopper_post_code   = $("#cntnt01cart_shopper_post_code").val();
    var shopper_email       = $("#cntnt01cart_shopper_email").val();
    var shopper_phone_nr    = $("#cntnt01cart_shopper_phone_nr").val();
    var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    
    var validation = true;
    var error_msg = "";
    // shooper name
    if ( (validation == true) && (shopper_name == '') )
    {
        error_msg += "Prošome įveskite vardą.<br/>"
        validation = false;
    }
    // shopper surname
    if ( (validation == true) && (shopper_surname == '') )
    {
        error_msg += "Prošome įveskite pavardę.<br/>"
        validation = false;
    }
    // shopper_city
    if ( (validation == true) && (shopper_city == '') )
    {
        error_msg += "Prošome įveskite miestą.<br/>"
        validation = false;
    }
    // shopper_adress
    if ( (validation == true) && (shopper_adress == '') )
    {
        error_msg += "Prošome įveskite adresą.<br/>"
        validation = false;
    }
    // shopper_post_code
    if ( (validation == true) && (shopper_post_code == '') )
    {
        error_msg += "Prošome įveskite pašto kodą.<br/>"
        validation = false;
    }
    // shopper_email
    if ( (validation == true) && (shopper_email == ''))
    {
        error_msg += "Prošome įveskite el. pašto adresą.<br/>"
        validation = false;
    }
    
    if ( (validation == true) && !(shopper_email.match(emailRegEx)))
    {
        error_msg += "Prošome įveskite teisingą el. pašto adresą.<br/>"
        validation = false;
    }
    // shopper_phone_nrs
    if ( (validation == true) && (shopper_phone_nr == '') )
    {
        error_msg += "Prošome įveskite telefono numerį.<br/>"
        validation = false;
    }
    if (error_msg == "")
    {
        error_msg = "&nbsp";
    }
    $("#shopper_info_msg_row").css("display", "block");
    $("#shopper_info_msg").html("");
    $("#shopper_info_msg").html(error_msg);
    return validation;
}

$(document).ready(function(){
    $("#eshop_add_to_cart").click(function(){
        $("#eshop_add_to_cart").attr("disabled", "disabled");
        var items_id = $("#eshop_items_id").val();   
        var sizes_id = $("#eshop_select_sizes").val();
        var post_url = $("#eshop_cart_post_url").val();
        //alert(items_id+"---"+sizes_id+"---"+post_url);
        $.ajax({
            type: "POST",
            url: post_url,
            data: "items_id="+items_id+"&sizes_id="+sizes_id,
            success: function(data){
                $("#eshop_cart_cnt:parent").css("display", "none");
                $("#eshop_cart_cnt:parent").html(data);
                $("#eshop_cart_cnt:parent").css("display", "block");
                $("#eshop_add_to_cart_msg").html("Prekė įdėta į Jūsų pirkinių krepšelį.");
                $("#eshop_add_to_cart").removeAttr("disabled");
                var added = $("#added_to_cart").val();
                if (added == "0")
                {
                    $("#eshop_add_to_cart_msg").html("Prekių likutis nepakankamas.");
                }
            }
        });
    });
    
    if ($("#webtopay_form"))
    {
        if ($("#webtopay_form").attr("title") == "true")
        {
            $("#webtopay_form").submit();
        }
    }

    $("#btn_submit").click(function(){
        var valid = validate_shopper_info();
        return valid;
    });
    // 
    var value = $(".payment_types").val();
    if (value == "cash")
    {
        $(".price_without_shipping").show();
        $(".price_with_shipping").hide();
    } else {
        $(".price_without_shipping").hide();
        $(".price_with_shipping").show();
    }
    $(".payment_types").click(function(){
        value = $(this).val();
        if (value == "cash")
        {
            $(".price_without_shipping").show();
            $(".price_with_shipping").hide();
        } else {
            $(".price_without_shipping").hide();
            $(".price_with_shipping").show();
        }
    });
});

