jQuery('document').ready(function(){
    //sets maraton lookup val to -1
    jQuery('#idMaraton').val("-1");
    //disables track length by default
    jQuery('#idTrackLength').attr('disabled', true);
    //sets the value for dropdown which contains countries, to slovenia
    jQuery('#country').val('SI');

    //disables dropdown for length if there is no maraton selected
    var elem = jQuery('#idMaraton');
    elem.bind('change', function(){
        /*
        //if submitions are locked show message
        for(j in lockedMaratons){
            if (this.value == lockedMaratons[j]){
                jQuery('#errorLockedMaraton').slideDown();
                jQuery('#submitButton').attr("disabled", "true");
                return false;
            }
        }
        //unlock form, selected maraton is not locked
        jQuery('#submitButton').attr("disabled", "");
        jQuery('#errorLockedMaraton').slideUp();
*/
        if (elem.val()=='-1'){
            //removes all options
            jQuery('#idTrackLength > option').remove();

            jQuery('#idTrackLength').append(
                jQuery("<option></option>").val('null').html('Izberi maraton!')
                );
            //if there is no maraton selected disable length dropdown
            jQuery('#idTrackLength').attr('disabled', true);
        }else{
            //enables dropdown
            jQuery('#idTrackLength').attr('disabled', false);
			
            //removes all options
            jQuery('#idTrackLength > option').remove();

            //fills dropdown with correct distances for maraton
            var lengthVal = lengthArr[elem.val()];
            jQuery.each(lengthVal,function(val,text){
                jQuery('#idTrackLength').append(
                    jQuery("<option></option>").val(val).html(text)
                    );
            });
        }
    });
});