jQ(document).ready(function(){
	var checkedFeedbackFocus = jQ("input[@name='feedback_focus']:checked").val();
	if(checkedFeedbackFocus == 'baggage') showPartsOfForm('baggage_issue');
	else if(checkedFeedbackFocus == 'flight_problems') showPartsOfForm('flight_issue');
	else if(checkedFeedbackFocus == 'other') showPartsOfForm('other_issue');
});

var regphone = new RegExp("^[0-9\-\/]+$");
var regNumber = new RegExp("^[0-9]+$");
var regemail = new RegExp("^([+]?[_a-zA-Z0-9\-]+([.][_a-zA-Z0-9\-]+)*@([0-9a-zA-Z][0-9a-zA-Z\-]*[.])+[a-zA-Z]{2,4})$");
var regWSDate = new RegExp("^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$");

var fc_reclamation = new Array();
fc_reclamation[fc_reclamation.length] = new Array("feedback_type", "value > ''", "Prosím, vyberte typ reklamace");
fc_reclamation[fc_reclamation.length] = new Array("feedback_focus", "value > ''", "Prosím, uveďte čeho se Vaše reklamace týká");
fc_reclamation[fc_reclamation.length] = new Array("baggage_issue", "checkBaggageIssue()", "Prosím specifikujte problém\r\n");
fc_reclamation[fc_reclamation.length] = new Array("flight_issue", "checkFlightIssue()", "Prosím specifikujte problém\r\n");
fc_reclamation[fc_reclamation.length] = new Array("pir_declared", "checkPirDeclared()", "Prosím, uveďte, zda jste již reklamoval/a Vaše zavazadlo na letišti");
fc_reclamation[fc_reclamation.length] = new Array("pir", "checkPir()", "Prosím, uveďte číslo PIR (referenční číslo přidělené na letišti)");
fc_reclamation[fc_reclamation.length] = new Array("ref_declared", "checkRefDeclared()", "Prosím, uveďte, zda jste již obdržel/a vyjádření z našeho oddělení Vztahů se zákazníky\r\n");
fc_reclamation[fc_reclamation.length] = new Array("ref", "checkInternalRef()", "Prosím, zadejte referenční číslo reklamace\r\n");
fc_reclamation[fc_reclamation.length] = new Array("flight_number", "checkNumberFlight()", "Prosím, zadejte číslo letu\r\n");
//fc_reclamation[fc_reclamation.length] = new Array("flight_date", "checkFeedbackMandatoryEle('#flight_date')", "No fill Flight date");
fc_reclamation[fc_reclamation.length] = new Array("flight_date", "checkDateFlight()", "Prosím, zadejte datum letu (formát RRRR-MM-DD)");
fc_reclamation[fc_reclamation.length] = new Array("title", "checked", "Prosím, vyberte oslovení\r\n");
fc_reclamation[fc_reclamation.length] = new Array("firstname", "value > ''", "Prosím, zadejte křestní jméno\r\n");
fc_reclamation[fc_reclamation.length] = new Array("lastname", "value > ''", "Prosím, zadejte příjmení\r\n");
fc_reclamation[fc_reclamation.length] = new Array("ffp_number", "checkFFPNumber()", "Prosím, zadejte Frequent flyer číslo!");
fc_reclamation[fc_reclamation.length] = new Array("street", "value > ''", "Prosím, zadejte název ulice\r\n");
fc_reclamation[fc_reclamation.length] = new Array("street_number", "regNumber.test(value)", "Prosím, zadejte číslo popisné\r\n");
fc_reclamation[fc_reclamation.length] = new Array("city", "value > ''", "Prosím zadejte město\r\n");
fc_reclamation[fc_reclamation.length] = new Array("postal_code", "checkNumberNoMandatory('postal_code')", "Prosím, zadejte směrovací číslo\r\n");
fc_reclamation[fc_reclamation.length] = new Array("country", "value > ''", "Prosím, vyberte zemi\r\n");
fc_reclamation[fc_reclamation.length] = new Array("phone", "checkNumberNoMandatory('phone')", "Prosím, zadejte telefonní číslo\r\n");
fc_reclamation[fc_reclamation.length] = new Array("email", "regemail.test(value)", "Prosím, zadejte email\r\n");
fc_reclamation[fc_reclamation.length] = new Array("comment", "testMaxLength()", "(Max. 2000 znaků)");

function checkNumberNoMandatory(eleName){
    var eleVal = jQ("input[@name='"+eleName+"']").val();
    if(eleVal == '' || ( eleVal != '' && regNumber.test(eleVal) )) return true;
    return false;
}

function checkDateFlight(){
    var checkedVal = jQ("input[@name='feedback_focus']:checked").val();
    var dateVal = jQ("input[@name='flight_date']").val();
    if( (((checkedVal !== undefined && regWSDate.test(jQ("input[@name='flight_date']").val())) || (checkedVal == 'other' && (dateVal == '' || (dateVal != '' && regWSDate.test(dateVal)))) )) || checkedVal === undefined) return true;
    else return false;
}

function checkNumberFlight(){
    var checkedVal = jQ("input[@name='feedback_focus']:checked").val();
    if(checkedVal != '' && (jQ("#flight_number").val() != '' || checkedVal == 'other')) return true;
    else return false;
}

function checkFFPNumber(){
    var checkedVal = jQ("#ffp_type").val();
    if((checkedVal != '' && regNumber.test(jQ("input[@name='ffp_number']").val())) || checkedVal == '') return true;
    else return false;
}

function checkBaggageIssue(){
    var returned;
    if(jQ("input[@name='feedback_focus']:checked").val() == 'baggage' && jQ("#baggage_issue").val()!='') returned = true;
    else if(jQ("input[@name='feedback_focus']:checked").size() && jQ("input[@name='feedback_focus']:checked").val() != 'baggage') returned = true;
    else returned = false;
    
    return returned
}

function checkFlightIssue(){
    var returned;
    if(jQ("input[@name='feedback_focus']:checked").val() == 'flight_problems' && jQ("#flight_issue").val()!='') returned = true;
    else if(jQ("input[@name='feedback_focus']:checked").size() && jQ("input[@name='feedback_focus']:checked").val() != 'flight_problems') returned = true;
    else returned = false;
    
    return returned
}

function checkPirDeclared(){
    var returned;
    if(jQ("input[@name='feedback_focus']:checked").val() == 'baggage' && jQ("input[@name='pir_declared']:checked").size()) returned = true;
    else if(jQ("input[@name='feedback_focus']:checked").size() && jQ("input[@name='feedback_focus']:checked").val() != 'baggage') returned = true;
    else returned = false;
    
    return returned
}

function checkPir(){
    var returned;
    if( jQ("input[@name='feedback_focus']:checked").val() == 'baggage' && 
        (jQ("input[@name='pir_declared']:checked").val()=='yes' && jQ("input[@name='pir']").val()!='') || 
        (jQ("input[@name='pir_declared']:checked").val()=='no')) returned = true;
    else if(jQ("input[@name='feedback_focus']:checked").size() && jQ("input[@name='feedback_focus']:checked").val() != 'baggage') returned = true;    
    else if(jQ("input[@name='feedback_focus']:checked").size() && jQ("input[@name='feedback_focus']:checked").val() != 'baggage') returned = true;
    else returned = false;
    
    return returned
}

function checkInternalRef(){
    var returned;
    if( jQ("input[@name='feedback_focus']:checked").val() != '' && 
        (jQ("input[@name='ref_declared']:checked").val()=='yes' && jQ("input[@name='ref']").val()!='') || 
        (jQ("input[@name='ref_declared']:checked").val()=='no')) returned = true;
    else returned = false;
    
    return returned
}

function checkFeedbackMandatoryEle(jQ_form_ele){
    if(jQ("input[@name='feedback_focus']:checked").val() != '' && jQ(jQ_form_ele).val() != '') return true;
    else return false;
}

function checkRefDeclared(){
    var returned;
    if(jQ("input[@name='feedback_focus']:checked").val() != '' && jQ("input[@name='ref_declared']:checked").val() !== undefined) returned = true;
    else returned = false;
    
    return returned
}

function showPartsOfForm(active_reclamation){
    checkShowNote();
    var arr_reclamation = new Array('baggage_issue','flight_issue','other_issue');
    var arr_spolecny_blok = new Array('spolecny_blok1','spolecny_blok2','spolecny_blok3','spolecny_blok4');
    var baggage_blok = 'baggage_blok1';
    var baggage_blok_pir = 'baggage_blok2';
    
    if(jQ("#"+arr_spolecny_blok[0]).attr("style") != 'display: none;'){
        for(var i = 0; i < arr_spolecny_blok.length;i++){
            jQ("#"+arr_spolecny_blok[i]).show();
        }
    }
    

    if(active_reclamation == 'baggage_issue'){      //pokud je pozadavek na blok baggage_issue
        jQ("#"+baggage_blok).show();
        if(jQ("[@name='pir_declared']:checked").val() == 'yes') jQ("#"+baggage_blok_pir).show();
    }else{                                          //pokud je pozadavek na jiny blok - baggage_issue blok skryt
        jQ("#"+baggage_blok).hide();
        jQ("#baggage_blok2").hide();      
    }
    
    jQ("#"+active_reclamation).show();
    for(var i = 0; i < arr_reclamation.length;i++){
        if((arr_reclamation[i] != active_reclamation) && (jQ("#"+arr_reclamation[i]).attr("style") != 'display: block;')) jQ("#"+arr_reclamation[i]).hide();
    }
    jQ(".no_border").removeAttr("class");
    
    // pokud je hodnota other_issue - Flight number a date nejsou povinne - skryti hvezdicky
    if(active_reclamation == 'other_issue') {
        jQ("#mandatory_flight_number").hide();
        jQ("#mandatory_flight_date").hide();
    } else {
        jQ("#mandatory_flight_number").show();
        jQ("#mandatory_flight_date").show();
    }
}

function showPIR(){
    jQ("#baggage_blok2").show();
}

function hidePIR(){
    jQ("#baggage_blok2").hide();
}

/*function checkShowNote(hide){
    if(hide === undefined && jQ("#note").css("display") == 'none'){ 
        jQ("#note").show();
    }else if(hide == 'hide' && jQ("#note").css("display") != 'none'){
        jQ("#note").hide();
    }
}*/

function checkShowNote(){
    if(jQ("input[@name='feedback_type']:checked").val() == 'complaint' && jQ("input[@name='feedback_focus']:checked").val() == 'baggage'){ 
        jQ("#note").show();
    }else if(jQ("#note").css("display") != 'none'){
        jQ("#note").hide();
    }
    
    // zobrazeni textu na zaklade zaskrtnuteho radio buttonu
    if(jQ("input[@name='feedback_type']:checked").val() == 'complaint'){
        jQ("#text_radio_other").empty();
        jQ("#text_radio_other").append('Ostatní stížnosti');
    }
    if(jQ("input[@name='feedback_type']:checked").val() == 'compliment'){
        jQ("#text_radio_other").empty();
        jQ("#text_radio_other").append('Ostatní\r\n');
    }
}

function testMaxLength(){
    var sizeText = jQ("#comment").val().length;
    if(sizeText > 2000) return false;
    else return true;
}

function setMandatoryRef(){
    if(jQ("input[@name='ref_declared']:checked").val() == 'yes') jQ("#ref_mandatory").show();
    else jQ("#ref_mandatory").hide();
}