$(document).ready(function(){

    $('#reserved_button').click(function(){

       //alert('clicked on Reserved');
       getOptionalSum();
      // alert(getPersons());

    });
    var price = getOptionalSum() + getPersons() + parseInt($('input[name=single_p]').val());
	
    
    $('#you_price_number').html(price+'<span>&euro;</span>');

    

   

   
});

 function onChange(element){        
        
        var price = getOptionalSum() + getPersons() + parseInt($('input[name=single_p]').val());
        
        $('#you_price_number').html(price+'<span>&euro;</span>');

    }
    function onChangePerson(elem){

        var elemName = elem.name;

        alert($('input[name=single_p]').value);

        if ($('input[name='+elemName+']').is(':checked') == true){

            var price = getOptionalSum() + parseInt(elem.value) + parseInt($('input[name=single_p]').value);
            
            

        }

    }
    function getOptionalSum(){

        var sum = 0;

        $("input", $("#optionalList")).each(function(){

            if($(this).is(':checked') == true){              

                   if(typeof $(this).val() == 'string'){                     

                       sum += parseInt($(this).val());

                       //alert($(this).parent().parent().find('span').text());
                       

                   }
                   
            }
                   

        });
        return sum;

    }
    function getPersons(){

        var value = 0;
        var name = "";

        $("input", $("#personsForm")).each(function(){

            if($(this).is(':checked') == true){

                if(typeof $(this).val() == 'string'){

                    value = parseInt($(this).val());
                    
                    

                }
                

            }
            
        });

        return value;
        
    }

