// zooku


$(document).ready(function() {
    
    // domenii

    $.each($('.domenii_checkbox'), function(){
        toggleClass(this)
    })

    $('.domenii_checkbox').change(function(){
        toggleClass(this)
        updatePrice()
    })
    
    $('.domenii.comanda').submit(function(e) {
        var total = updatePrice()
        if(total == 0.00) {
            e.preventDefault()
            alert('Nu ați selectat nici un domeniu')
        }
    })
    
    
    // gazduire
    
    $('.domenii_cmd').submit(function(){
        domain = $('.domain-search').val()

        if($('#status1').attr('checked')) {
            $('form').attr('action', 'hosting-domain.html')
        }
        if ($('#status2').attr('checked')) {
            $('form').attr('action', 'cmd.html?domcmd1=' + domain)
        }
    })
    
    btn = $('.verifica-numele')
    
    $('#status1').change(function(){
        btn.css('background-position', '0 -96px')
        
        btn.mouseleave(function(){
            $(this).css('background-position', '0 -96px')
        })
        btn.mouseenter(function(){
            $(this).css('background-position', '0 -144px')
        })
    })
    
    $('#status2').change(function(){
        btn.css('background-position', '0 -191px')
        
        btn.mouseleave(function(){
            $(this).css('background-position', '0 -191px')
        })
        btn.mouseenter(function(){
            $(this).css('background-position', '0 -239px')
        })
        
    })

})


function updatePrice() {
    
    var total = 0
    
    $.each($('.selected .preturi'), function(){
        total += parseFloat(this.textContent.replace(',','.'))
    })
    
    var integer = parseInt(total)
    var decimal = total - integer
    decimal = decimal.toFixed(2).toString().slice(2,4)
    
    var outTotal = integer + ',<small><sup>' + decimal + '</sup></small>'
    $('.total_price').replaceWith('<strong class="total_price">'+outTotal+' ron</strong>')
    
    return total.toFixed(2)
}


function toggleClass(box) {

    var parent = $(box).parent().parent()

    if($(box).attr('checked')) {
        parent.addClass('selected')
    } else {
        parent.removeClass('selected')
    }

}


function selectAll(formname, thestate){
    var el_collection=eval("document.forms."+formname)
    for (c=0;c<el_collection.length;c++){
        if (el_collection[c].type=='checkbox' && el_collection[c].name != 'priv_all')
            el_collection[c].checked= thestate;
    }
}

