function chooseSb(el, idrec) {
    loading;
    $.get("ajax/confer.php", {
            type:"chooseSb",
            idrec : idrec,
            idsb : $(el).val()
        }, function(txt) {
            stopLoading();
            if ( txt != "OK" ) {
                $.prompt(txt, {opacity:0.3});
            }
        });
}

function checkThomson(el, idrec) {
    loading;
    $.get("ajax/confer.php", {
            type:"checkThomson",
            idrec : idrec,
            thomson : $(el).attr("checked")
        }, function(txt) {
            stopLoading();
            if ( txt != "OK" ) {
                $.prompt(txt, {opacity:0.3});
            }
        });
}
function checkReklama(el, idrec) {
    loading;
    $.get("ajax/confer.php", {
            type:"checkReklama",
            idrec : idrec,
            reklama : $(el).attr("checked")
        }, function(txt) {
            stopLoading();
            if ( txt != "OK" ) {
                $.prompt(txt, {opacity:0.3});
            }
        });
}
function checkVystavka(el, idrec) {
    loading;
    $.get("ajax/confer.php", {
            type:"checkVystavka",
            idrec : idrec,
            vystavka : $(el).attr("checked")
        }, function(txt) {
            stopLoading();
            if ( txt != "OK" ) {
                $.prompt(txt, {opacity:0.3});
            }
        });
}

//pri entru prehodi na dalsi input
function isEnter(el, ev) {
    var code;
    if (!ev) var ev = window.event;
	if (ev.keyCode) code = ev.keyCode;
	else if (ev.which) code = ev.which; 
	if(code == 13) {
	   $(el).parent().parent().next().children().children("input, select").focus();
	   return false;
    } else {
	   return true;
	}
}

//nastavi pocet ucastniku u optionals
function setOptCount(el, idrec, idopt) {
    loading;
    $.get("ajax/confer.php", {
            type:"setOptCount",
            idrec : idrec,
            idopt : idopt,
            count : $(el).val()
        }, function(txt) {
            stopLoading();
            if ( txt != "OK" ) {
                $.prompt(txt, {opacity:0.3});
            }
        });
}

//uprava usera
function editUser(el, idvis, idconfer) {
    loading();
    $.get("ajax/confer.php", {
            type:"getEditUser",
            idvis : idvis
        }, function(txt) {
            stopLoading();
            $.prompt(txt, {opacity:0.3, buttons : { Ok: true, Cancel: false }, callback: function(v, m, f) {
                if ( v == true ) {
                    $.get("ajax/confer.php", {
                        type: "editUser",
                        name: f.name,
                        surname: f.surname,
                        degree: f.degree,
                        idvis: f.IDvis,
                        companyCZ: f.companyCZ,
                        companyEN: f.companyEN,
                        phone: f.phone,
                        email: f.email,
                        city: f.city,
                        IDcountry: f.IDcountry,
                        confer : idconfer
                    }, function(txt) {
                        $.prompt(txt, {opacity:0.3});
                    });
                }
            }});
        });
}


//zmeni ubytovani
function checkAcc(e, idacc, idrec){
    var state = $(e).attr("checked");
    
    $("select[rel='room"+idrec+"']").each(function(i, obj){
        $(obj).attr("disabled", "disabled");
        $(obj).val("0");
    });
    
    if ( state == true ) {
        $("#room"+idacc+"X"+idrec).removeAttr("disabled");
    } else {
        $("#room"+idacc+"X"+idrec).attr("disabled", "disabled");
        $("#room"+idacc+"X"+idrec).selectOptions("0");
    }
    if ( idacc == "0" ) {
        loading();
        $.get("ajax/confer.php", {
                type : "unsetAccom",
                idrec : idrec
            }, function(txt){
                totalPrice(idrec);
                stopLoading();
                if ( txt != "OK") {
                    $.prompt(txt, {opacity: 0.3});
                }
        });
    }
}

//rozbali form pro pridani nove osoby
function addPerson(e) {
    if ( $("#addPers").css("display") == "none" ) {
        hidePayment(e);
        $("#addPers").css("display", "block");
        $("#records").css("display", "none");

        $("#addPers").parent().css("height", "0px");
        $("#addPers").parent().animate({height: 350}, 500);
        $("#addPers").css("height", "0px");
        $("#addPers").animate( {height: 345}, 500, function(){
            
                if ( !$.browser.msie || parseInt($.browser.version, 10) > 7 ) {   CSBfleXcroll('content'); }
        });
    }
}


//prida novou osobu
function addNewPers(e, idconfer, lang) {
    var surname = $("#addPers [name=surname]");
    var name = $("#addPers [name=name]");
    var degree = $("#addPers [name=degree]");
    var city = $("#addPers [name=city]");
    var phone = $("#addPers [name=phone]");
    var email = $("#addPers [name=email]");
    var IDcountry = $("#addPers [name=IDcountry]");
    var company = $("#addPers [name=companyCZ]");
    var company2 = $("#addPers [name=companyEN]");
    var err = false;
    
    //VALIDACE POLI
    if ( $(surname).val().length < 2 ) {
        err = true;
        $(surname).css("background", "#FFDCE1");
    } else {
        $(surname).css("background", "");
    }
    if ( $(city).val().length < 2 ) {
        err = true;
        $(city).css("background", "#FFDCE1");  
    } else {
        $(city).css("background", "");
    }
    if ( $(name).val().length == 0 ) {
        err = true;
        $(name).css("background", "#FFDCE1"); 
    } else {
        $(name).css("background", "");
    }
    if ( $(email).val().length < 6 ) {
        err = true;
        $(email).css("background", "#FFDCE1");  
    } else {
        $(email).css("background", "");
    }
    
    if ( $(company).val().length == 0 ) {
        $(company).val($(company2).val()); 
    }
    if ( $(company2).val().length == 0 ) {
        $(company2).val($(company).val());  
    }
    
    if ( $(company).val().length < 2 ) {
        err = true;            
        $(company).css("background", "#FFDCE1");
        $(company2).css("background", "#FFDCE1");
    } else {
        $(company).css("background", "");
        $(company2).css("background", "");
    }
    //KONEC VALIDACE
    
    var sname = "";
    var gder = -1;
    if ( lang == "en" ) {
        sname = $("#name2").val();
        if ( $("#gender0").attr("checked")==true ) gder = 0;
        if ( $("#gender1").attr("checked")==true ) gder = 1;
        if ( $("#gender2").attr("checked")==true ) gder = 2;
    }
             
             
    if ( err ) return false;
    loading();
    $.post("ajax/confer.php", {
            type: 'addperson',
            surname: $(surname).val(),
            name: $(name).val(),
            degree: $(degree).val(),
            city: $(city).val(),
            phone: $(phone).val(),
            companyCZ: $(company).val(),
            companyEN: $(company2).val(),
            IDcountry: $(IDcountry).val(),
            email: $(email).val(),
            gender : gder,
            sname : sname,
            confer : idconfer
        }, function(txt){
            stopLoading();
            if ( txt.indexOf("OK") > -1  ) { 
                txt = txt.substr(2);
                add2Confer(idconfer, txt);
            } else {
                $.prompt(txt, {opacity: 0.3}); 
            }
        });
    return false;
}

//skryje form pro pridani osoby a vynuluju inputy
function stornoAddPerson() {
    $("#addPers").animate({height: "0"}, 500, function(){
            $("#addPers").css("display", "none");
            
                if ( !$.browser.msie || parseInt($.browser.version, 10) > 7 ) {   CSBfleXcroll('content'); }
    });
    $("#addPers").parent().animate({height: "0"}, 500);
    $("#addPers [name=surname]").val("");
    $("#addPers [name=surname]").css("background", "");
    $("#addPers [name=name]").val("");
    $("#addPers [name=name]").css("background", "");
    $("#addPers [name=degree]").val("");
    $("#addPers [name=degree]").css("background", "");
    $("#addPers [name=phone]").val("");
    $("#addPers [name=phone]").css("background", "");
    $("#addPers [name=email]").val("");
    $("#addPers [name=email]").css("background", "");
    $("#addPers [name=city]").css("background", "");
    $("#addPers [name=companyCZ]").css("background", "");
    $("#addPers [name=companyEN]").css("background", "");
}

//prihlasi uzivatele do konference
function add2Confer(idconfer, iduser) {
    if ( iduser == 0 ) {
        iduser = $("#IDvis").selectedValues();
    } 
    if ( iduser > 0 ) {
        loading();
        $.get("ajax/confer.php", {
                type: "add2Confer",
                iduser : iduser,
                idconfer : idconfer
            }, function(txt){
                stopLoading();
                if ( txt.substr(0,2) == "OK"  ) { 
                    txt = txt.substr(2);
                    location.href = "/index.php?load=confer&confer="+idconfer+"&type=join&goRec="+txt;
                } else {
                    $.prompt(txt, {opacity: 0.3});
                }
            });
    }
}
function getBookedList(idconfer) {
    $.get("ajax/confer.php", {
            type: "getBookedList",
            idconfer : idconfer
        }, function(txt){
            $("#booked").html(txt);
                if ( !$.browser.msie || parseInt($.browser.version, 10) > 7 ) {   CSBfleXcroll('content'); }
    })
}


//zmeni kategorii vstupneho uzivatele
function changePrice(e, idprice, idrec){
    loading();
    $.get("ajax/confer.php",{
            type: "changeprice",
            idprice : idprice,
            idrec : idrec
        }, function(txt) {
            stopLoading();
            totalPrice(idrec);
            if ( txt != "OK" ) {
                $.prompt(txt, {opacity: 0.3});
            }
        });
}

//zmeni volitelne nastaveni
function checkOpt(e, idopt, idrec, idtype){
    var state = $(e).attr("checked");
    
    //u doprovodneho programu moznost vybrat jen jednu volbu
    if ( state == true && idtype==2 ) {
      var tbl = $(e).parent().parent().parent();
      $(tbl).children().children().children("input").each(function(i, element){
            if ( $(element).attr("id") != $(e).attr("id") ) {
               $(element).removeAttr("checked");
            }
         });  
    }
        
    loading();
    $.get("ajax/confer.php",{
            type: "checkOpt",
            state : state,
            idopt : idopt,
            idrec : idrec
        }, function(txt) {
            stopLoading();
            if ( txt != "OK" ) {
                $.prompt(txt, {opacity: 0.3});
                $(e).removeAttr("disabled");
                $(e).attr("checked", !state);
            } else {
                totalPrice(idrec);
                if ( state == true ) {
                    $("#note"+idopt+"X"+idrec).removeAttr("disabled");
                    $("#optCount"+idopt+"X"+idrec).removeAttr("disabled");
                } else {
                    $("#note"+idopt+"X"+idrec).attr("disabled", "disabled");
                    $("#note"+idopt+"X"+idrec).val("");
                    $("#optCount"+idopt+"X"+idrec).attr("disabled", "disabled");
                }
                if ( !$.browser.msie || parseInt($.browser.version, 10) > 7 ) {   CSBfleXcroll('content'); }
            }
        });
}
//zmeni poznamku volitelneho nastaveni
function changeNote(e, idopt, idrec){
    var note = $(e).val();
    loading();
    $.get("ajax/confer.php",{
            type: "changeOptNote",
            note : note,
            idopt : idopt,
            idrec : idrec
        }, function(txt) {
            stopLoading();
            if ( txt != "OK" ) {
                $.prompt(txt, {opacity: 0.3});
            }
        });
}


//povoli pridani reportu
function canAddReport(el, idrec) {
    $("#noreport"+idrec).css("display", "block");
    $("#btnAddReport"+idrec).removeAttr("disabled");
    $("#records").css("display", "block").animate({height: 60+$("#record"+idrec)[0].scrollHeight}, function(){
                if ( !$.browser.msie || parseInt($.browser.version, 10) > 7 ) {   CSBfleXcroll('content'); } }); 
}
//povoli pridani reportu
function cantAddReport(el, idrec) {
    $("#noreport"+idrec).css("display", "none");
    $("#btnAddReport"+idrec).attr("disabled", "disabled");
    $("#records").css("display", "block").animate({height: 60+$("#record"+idrec)[0].scrollHeight}, function(){
                if ( !$.browser.msie || parseInt($.browser.version, 10) > 7 ) {   CSBfleXcroll('content');}});
}
//zmeni zpusob platby
function changePayment(idconfer, idpay) {
    loading();
    $.get("ajax/confer.php", {
            type: "changePayment",
            idconfer: idconfer,
            idpay: idpay
        }, function(txt){
            stopLoading();
            if ( txt != "OK" ) {
                $.prompt(txt, {opacity: 0.3});
                $("#pay1").removeAttr("checked"); 
                $("#pay2").removeAttr("checked"); 
                $("#pay3").removeAttr("checked");
            }
    });
}
//zmeni s kym chce byt na pokoji (sam/s nekym)
function changeAccWithNo(el, idrec) {
    if ( $(el).val() == 1 ) {
        $("#accCount"+idrec).attr("disabled", "disabled");
        $("#accwith"+idrec).removeAttr("disabled");
    } else if ( $(el).val() == 2 ) {
        $("#accwith"+idrec).val("");
        $("#accwith"+idrec).attr("disabled", "disabled");
        $("#accCount"+idrec).removeAttr("disabled");
    } else {
        $("#accwith"+idrec).val("");
        $("#accwith"+idrec).attr("disabled", "disabled");
        $("#accCount"+idrec).attr("disabled", "disabled");
    }
    loading();
    $.get("ajax/confer.php", {
            type: "changeAccWithNo",
            idrec: idrec,
            acc: $(el).val()
        }, function(txt){
            stopLoading();
            if ( txt != "OK" ) {
                $.prompt(txt, {opacity: 0.3});
            }
    }); 
}
//zmeni s kym chce byt ubytovan
function changeAccWith(el, idrec) {
    loading();
    $.get("ajax/confer.php", {
            type: "changeAccWith",
            idrec: idrec,
            accwith: $(el).val()
        }, function(txt){
            stopLoading();
            if ( txt != "OK" ) {
                $.prompt(txt, {opacity: 0.3});
            }
    });   
}
//zmeni datum ubytovani
function changeDate(date, type) {
    loading();
    $.get("ajax/confer.php", {
            type: "changeDate",
            date: date,
            name: type
        }, function(txt){
            stopLoading();
            if (txt != "OK") {
                $.prompt(txt, {opacity: 0.3});
            }
    });
}
//celkova cena
function totalPrice(idrec) {
    loading();
    $.get("ajax/confer.php", {
            type: "totalPrice",
            idrec: idrec
        }, function(txt){
            stopLoading();
            $("#tprice"+idrec).html(txt);
    });
}




