document.write('<script type="text/javascript" src="https://apis.google.com/js/plusone.js">{lang: \'pl\'}</script>');


jQuery(document).ready(function()  {

    jQuery('.sendEmail').click(function() {
        var windowW=400;
        var windowH=300;
        var windowX = Math.floor((screen.availWidth/2)-(windowW/2));
        var windowY = Math.floor((screen.availHeight/2)-(windowH/2));
        config='toolbar=0,location=0,directories=0,status=0,scrollbars=3,resizable=0'
        config +=',width=' + windowW + ',height=' + windowH + ',left=' + windowX + ',top=' + windowY + ',menubar=0' ;

        var modTab = jQuery(this).attr('id');
        modTab = modTab.split('-');
        
        emailWindow = window.open('/task/email/' + modTab[0] + '/' + modTab[1], 'Wyślij_powiadomienie', config);

        return false;
    });
	
    jQuery('.remove_quantity').click(function() {
        var val = jQuery(this).next('input.quantity_value').attr('value');
        val = parseInt(val);
        val = val - 1;
        if(val > 0)
        {
            jQuery(this).next('input.quantity_value').attr('value', val);
        }
    });

    jQuery('.add_quantity').click(function() {
        var val = jQuery(this).prev('input.quantity_value').attr('value');
        val = parseInt(val);
        val = val + 1;
        jQuery(this).prev('input.quantity_value').attr('value', val);
    });

    jQuery('.add_to_cart_form .add_quantity_min').click(function() {
        var val = jQuery('#cart_quantity').attr('value');
        val = parseInt(val);
        val = val + 1;
        jQuery('#cart_quantity').attr('value', val);
        return false;
    });

    jQuery('.add_to_cart_form .remove_quantity_min').click(function() {
        var val = jQuery('#cart_quantity').attr('value');
        val = parseInt(val);
        val = val - 1;
        if(val > 0)
        {
            jQuery('#cart_quantity').attr('value', val);
        }
        return false;
    });

    jQuery('#shippingdata').click(function() {
        if(jQuery(this).attr('checked'))
        {
            var name = jQuery('#invoice_name').attr('value');
            var city = jQuery('#invoice_city').attr('value');
            var street = jQuery('#invoice_street').attr('value');
            var code = jQuery('#invoice_post_code').attr('value');
            var house = jQuery('#invoice_house_no').attr('value');
            var flat = jQuery('#invoice_flat_no').attr('value');
            var phone = jQuery('#invoice_phone').attr('value');

            jQuery('#shipment_name').attr('value', name);
            jQuery('#shipment_city').attr('value', city);
            jQuery('#shipment_street').attr('value', street);
            jQuery('#shipment_post_code').attr('value', code);
            jQuery('#shipment_house_no').attr('value', house);
            jQuery('#shipment_flat_no').attr('value', flat);
            jQuery('#shipment_phone').attr('value', phone);
        }
        else
        {
            jQuery('#shipment_name').attr('value', '');
            jQuery('#shipment_city').attr('value', '');
            jQuery('#shipment_street').attr('value', '');
            jQuery('#shipment_post_code').attr('value', '');
            jQuery('#shipment_house_no').attr('value', '');
            jQuery('#shipment_flat_no').attr('value', '');
            jQuery('#shipment_phone').attr('value', '');
        }
    });

    //shipment + cat price
    jQuery('#shipment_type_shipment_id').change(function() {
        changeValuePrice(jQuery(this).val());
    });   

    function changeValuePrice(id)
    {
        var cart_price = parseInt(jQuery('#cart_sum_price_brutto').text());
        var shimpent_price = parseInt(jQuery('#shipment_type_shipment_value_' + id).val());
        var all = cart_price + shimpent_price;
        all = all.toString();
        var cnt = all.length;
        var front = all.substr(0, (cnt-2));        
        var back = all.substr(cnt-2);
        all = front + ',' + back;
        jQuery('#summary_price_brutto').html(all + ' zł');
    }

    changeValuePrice(jQuery('#shipment_type_shipment_id').val());
        
});



