var priroda = {
	numb: /^\d+\.?\d*$/,
    submitFormDelay:function(formid){
        var form = $(formid);
        form.submit();
    },

    submitForm:function(formid){
        setTimeout("priroda.submitFormDelay('"+formid+"');", 50);
    },
    handleLongTitle:function(){
        if ($('#product #title').length > 0) {
            var height = $('#product #title').height();
            if (height > 75) {
                $('#product #author').css('padding-bottom', '10px');
                $('.prod-form #fb-lik').css('bottom', '-35px')
            }else if (height > 80) {
                $('#product #author').css('padding-bottom', '8px');
                $('#product #price').css('padding-bottom', '5px');
                $('.prod-form #fb-lik').css('bottom', '-35px')
            }
        }
    },
    getShippingPrice:function(localityID, type){
        if (localityID < 1) return false;
        $('#load_info').show();
        $.ajax({
            type: "POST",
            url: "/?cl=amount_discounts&iid=1&tset=ajax&tname=getprice",
            data: "localityID="+localityID,
            success: function(msg){
                if (type == 1) {
                    var price = parseFloat($('#ordPrice').val());
                    var shipping = parseFloat(msg);
                    var newPrice = (price + shipping).toFixed(2);
                    $('#ship').html((shipping + '').replace('.', ','));
                    $('#sumCart').html((newPrice + '').replace('.', ','));
                    $('#load_info').hide();
                }
            }
        });
    },
    getShippingPriceFast:function(localityID, type){
        if (localityID < 1) return false;
        $('#load_info').show();
        $.ajax({
            type: "POST",
            url: "/?cl=order_fast&iid=1&tset=ajax&tname=getprice",
            data: "localityID="+localityID,
            success: function(msg){
                if (type == 1) {
                    var price = parseFloat($('#ordPrice').val());
                    var shipping = parseFloat(msg);
                    var newPrice = (price + shipping).toFixed(2);
                    $('#ship').html((shipping + '').replace('.', ','));
                    $('#sumCart').html((newPrice + '').replace('.', ','));
                    $('#load_info').hide();
                }
            }
        });
    },
    fastOrderKeyUp:function(element){
    	var value = element.val();
    	if (value.search(priroda.numb)!=-1) {
    		$('.' + element.attr('class')).val(value);
    	}else $('.' + element.attr('class')).val('');
    },
    discountSelected:function(type){
    	var ordPrice = $('#ordPrice').val();
    	var ordShip = $('#ordShip').val();
    	if (type == 'percent') {
    		var newPrice = (parseFloat(ordPrice * 0.9) + parseFloat(ordShip)).toFixed(2);
    	}else{
    		var newPrice = ordPrice + ordShip;
    	}
    	$('#sumCart').html(newPrice.replace('.',','));
    }
}

priroda.layout = {
    init:function(){
    }
}
function doveraClick(){
    if ($('.dovera').val()==' registračné číslo poistencov Dôvery') {
        $('.dovera').val('');
        $('.dovera').removeClass('watermark');
    }
}
function addEmail(){
    var mail=$('#newsEmail').val();
    if (mail=='') {
        return false;
    }
    $.ajax({
        type: "POST",
        url: "/?cl=newsletters&iid=1&tset=ajax&tname=createEmail",
        data: "email="+mail,
        success: function(msg){
            $('#nInfo').html(msg);
        }
    });
}
function doveraBlur(){
    if ($('.dovera').val()=='') {
        $('.dovera').addClass('watermark');
        $('.dovera').val(' registračné číslo poistencov Dôvery');
    }
}

function addToCart(form_id){

    var oForm = $('#form_id');

    var url = oForm.attr('action');

    var data = 'itemsubmit';

    $.ajax({
        type: "POST",
        url: oForm.attr('action'),
        data: "localityID="+localityID,
        success: function(msg){
            if (type == 1) {
                var price = parseFloat($('#ordPrice').val());
                var shipping = parseFloat(msg);
                var newPrice = (price + shipping).toFixed(2);
                $('#ship').html((shipping + '').replace('.', ','));
                $('#sumCart').html((newPrice + '').replace('.', ','));
                $('#load_info').hide();
            }
        }
    });

}


function addedToCart() {

    if ($('#added_to_cart').length > 0) {

        var req_url = '/'+ $('#added_to_cart').val();

        $.fn.colorbox({
                    html:req_url,
                    innerWidth:400,
                    innerHeight:90
                });

        /*
        $.ajax({
            type: "POST",
            url: req_url,
            success: function(msg){
                $.fn.colorbox({
                    html:msg,
                    innerWidth:400,
                    innerHeight:90
                });
            }
        });
        */
    }

    /*
    $.fn.colorbox({
        href:$('#added_to_cart').val(),
        innerWidth:400,
        innerHeight:90
    });
    var html_content = "<div id=\"addedToCart\">\
                    <h3>Nákupný košík</h3>\
                    <p class=\"info\">Tovar bol pridaný do košíka</p>\
                    <a class=\"left gB gBll\">Pokračovať v nákupe</a>\
                    <a class=\"right gB gBrr\">Zobraziť košík</a>\
                </div>";

    */


}


$(document).ready(function() {
    //$('img[src$=.png]').ifixpng();
    $('#fMenu .rightCorner').height($('#fMenu').height());
    $("#logout .btn").css('position', 'absolute');

/*
    if ($('#added_to_cart').length > 0) {
        var url =  'http://www.priroda.sk/'+$('#added_to_cart').val();
        $.fn.colorbox({
            href:url,
            innerWidth:400,
            innerHeight:90
        });
    }
    */

    $("a[rel='fPass']").colorbox({
        iframe:true,
        innerWidth:425,
        innerHeight:325
    });
    priroda.layout.init();
    priroda.handleLongTitle();
    if ($('.dovera').length>0) {
        if ($('.dovera').val()=='') {
            $('.dovera').val(' registračné číslo poistencov Dôvery');
        }
    }
});
