function checkForSpecialCourse(v){
    if(v == 182){
        document.location = "cvvs_courses_preregister_special.php?cid="+v;
    }
}

$j = jQuery.noConflict();

$j(document).ready(function(){
    PSID = $j('#phpsessid')[0] && $j('#phpsessid')[0].value;
        
    // watermark
    var focusHnd = function(event) {
        $j("label[for="+$j(this).attr("id")+"]").addClass('dNone'); 
    };    
    var blurHnd = function(event) {
        if ( !$j(this)[0].value ) $j("label[for="+$j(this).attr("id")+"]").removeClass('dNone'); 
    };
    
    $j('#ppLoginUser').focus(focusHnd);
    $j('#ppLoginPass').focus(focusHnd);
    
    $j('#ppLoginUser').blur(blurHnd);
    $j('#ppLoginPass').blur(blurHnd);
    
    // office
    
    var officeLoad = function(what) {
        $j("#officeLoading").show();
        $j("#officeContent").html("");
        
        $j.get("officeApi.php?w=" + what + "&PHPSESSID=" + PSID, null, 
           function(data){
               $j("#officeLoading").hide();
               $j("#officeContent").html(data);
               bindUI();
        });
    };
    
    var loginOffice = function() {
        var user = $j("#offLoginUser").val();
        var pass = $j("#offLoginPass").val();
        
        $j("#officeLoading").show();
        $j("#officeContent").html("");
        
        $j.ajax({type: 'POST', cache: false, url: "officeApi.php?do=login&PHPSESSID=" + PSID, 
        data: { user: user, pass: pass }, complete: function(response){
           $j("#officeLoading").hide();
           $j("#officeContent").html(response.responseText);
           bindUI();
        }});
    };
    
    var sendPasswd = function() {
        var email = $j("#offPasswdEmail").val();
        
        $j("#officeLoading").show();
        $j("#officeContent").html("");
        
        $j.ajax({type: 'POST', cache: false, url: "officeApi.php?do=passwdInit&PHPSESSID=" + PSID, 
        data: { email: email, send_passwd_start: 1 }, complete: function(response){
           $j("#officeLoading").hide();
           $j("#officeContent").html(response.responseText);
           bindUI();
        }});
    };
    
    var logoutOffice = function() {
        $j("#officeLoading").show();
        $j("#officeContent").html("");
        
        $j.ajax({type: 'POST', cache: false, url: "officeApi.php?do=logout&PHPSESSID=" + PSID, 
        data: { logout: 1 }, complete: function(response){
           $j("#officeLoading").hide();
           $j("#officeContent").html(response.responseText);
           bindUI();
        }});
    };
    
    var getFormData = function() {
        $j.getJSON("officeApi.php?w=data&PHPSESSID=" + PSID, function(data){
           fillForm(data);
        });
    };
    
    var fillForm = function(data) {
        $j(".f_o_firstname")[0].value = data.name;
        $j(".f_o_lastname")[0].value  = data.surname;
        $j(".f_o_title")[0].value     = data.titular_pre;
        $j(".f_o_phone")[0].value     = data.phone;
        $j(".f_o_fax")[0].value       = data.fax;
        $j(".f_o_email")[0].value     = data.email;
        $j(".f_o_function")[0].value  = data.position;
        $j(".f_o_office")[0].value    = data.o_title;
        $j(".f_o_street")[0].value    = data.o_street;
        $j(".f_o_city")[0].value      = data.o_city;
        $j(".f_o_psc")[0].value       = data.o_zip;
        $j(".f_o_ico")[0].value       = data.o_ico;
        $j(".f_o_dic")[0].value       = data.o_dic;
        $j(".f_o_bankname")[0].value  = data.o_bank;
        $j(".f_o_account")[0].value   = data.o_bank_account;
    };
    
    var bindUI = function() {
        // console.info('binding UI : ', $j(".officeRegisterLink"), $j(".officePasswdLink"), $j(".officeLoginLink"));
        
        $j(".officeRegisterLink").unbind();
        $j(".officePasswdLink").unbind();
        $j(".officeLoginLink").unbind();
        
        $j(".officeRegisterLink").click(function(e) {
            e.preventDefault();
            officeLoad.call(this, 'reg');
        });

        $j(".officePasswdLink").click(function(e) {
            e.preventDefault();
            officeLoad.call(this, 'passwdStart');
        });
        
        $j(".officeLoginLink").click(function(e) {
            e.preventDefault();
            officeLoad.call(this, 'login');
        });
        
        $j(".officeLogoutLink").click(function(e) {
            e.preventDefault();
            logoutOffice.call(this);
        });
                
        // registration
        $j('.officeRegEmail').keyup(function() {
            var email = $j('.officeRegEmail')[0].value;
            $j('.f_o_email')[0].value = email;
        });
        
        $j('.officeRegPass').change(function() {
            $j('.f_o_pass')[0].value = $j('.officeRegPass')[0].value;
        });
        
        // passwd
        $j(".officeButtonPasswd").click(function(e) {
            e.preventDefault();
            sendPasswd.call(this);
        });
        
        // login
        $j(".officeButtonLogin").click(function(e) {
            e.preventDefault();
            loginOffice.call(this);
        });
        
        if( $j("#loggedOffice").length > 0 && $j("#loggedOffice")[0].value > 0 ){
            getFormData.call(this);
        }
    };
    
    if( $j("#officeContent").length > 0 ){
        officeLoad.call(this, 'user');
    }
    
    /************ *************** ************/
    
    var validateJoin = function() {
        var a = false;
        
        $j(".join_require").each(function() {
            var e = $j(this);
            
            $j(".join_alert").innerHTML = '';
            $j(".join_alert").hide();
            e.removeClass("join_ok").removeClass("join_error");
            if( e.val().length < 2 ){
                e.addClass("join_error");
                a = true;
            }else{
                e.addClass("join_ok");
            }
        });
        
        if( a ){
            $j(".join_alert").each(function() {
                var e = $j(this)[0];
                e.innerHTML = 'Vyplňte prosím všechny povinné údaje.';
            });            
            $j(".join_alert").show();
        }else{
            submitJoin.call(this, 'submit');
        }
    };
    
    var submitJoin = function(how) {
        $j(".join_send").val(how);
        $j(".join_form").submit();
    };
    
    if( $j(".join_submit").length > 0 ){
        $j(".join_submit").click(function(e) {
            e.preventDefault();
            validateJoin.call(this);
        });
        
        $j(".join_add").click(function(e) {
            e.preventDefault();
            submitJoin.call(this, 'add');
        });
        
        $j(".join_sub").click(function(e) {
            e.preventDefault();
            submitJoin.call(this, 'sub');
        });
    }

});

function $$(){var C=new Array();for(var B=0;B<arguments.length;B++){var A=arguments[B];if(typeof A=="string"){A=document.getElementById(A);}if(arguments.length==1){return A;}C.push(A);}return C;}function showhide(A){if($$(A).style.display=="block"){$$(A).style.display="none";}else{$$(A).style.display="block";}}

function css(A,H,E,D){switch(A){case"swap":H.className=!css("check",H,E)?H.className.replace(D,E):H.className.replace(E,D);break;case"add":if(!css("check",H,E)){H.className+=H.className?" "+E:E;}break;case"remove":var G=H.className.match(" "+E)?" "+E:E;H.className=H.className.replace(G,"");break;case"check":var F=false;var B=H.className.split(" ");for(var C=0;C<B.length;C++){if(B[C]==E){F=true;}}return F;break;}}function simpleTrim(A){return A.replace(/^\s*|\s*$$/g,"");}

function getAnchorPosition(B){var E=false;var J=new Object();var I=0,G=0;var D=false,F=false,H=false;if($$){D=true;}else{if(document.all){F=true;}else{if(document.layers){H=true;}}}if(D&&document.all){I=AnchorPosition_getPageOffsetLeft(document.all[B]);G=AnchorPosition_getPageOffsetTop(document.all[B]);}else{if(D){var A=$$(B);I=AnchorPosition_getPageOffsetLeft(A);G=AnchorPosition_getPageOffsetTop(A);}else{if(F){I=AnchorPosition_getPageOffsetLeft(document.all[B]);G=AnchorPosition_getPageOffsetTop(document.all[B]);}else{if(H){var K=0;for(var C=0;C<document.anchors.length;C++){if(document.anchors[C].name==B){K=1;break;}}if(K==0){J.x=0;J.y=0;return J;}I=document.anchors[C].x;G=document.anchors[C].y;}else{J.x=0;J.y=0;return J;}}}}J.x=I;J.y=G;return J;}function getAnchorWindowPosition(B){var C=getAnchorPosition(B);var A=0;var D=0;if($$){if(isNaN(window.screenX)){A=C.x-document.body.scrollLeft+window.screenLeft;D=C.y-document.body.scrollTop+window.screenTop;}else{A=C.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;D=C.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;}}else{if(document.all){A=C.x-document.body.scrollLeft+window.screenLeft;D=C.y-document.body.scrollTop+window.screenTop;}else{if(document.layers){A=C.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;D=C.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;}}}C.x=A;C.y=D;return C;}function AnchorPosition_getPageOffsetLeft(B){var A=B.offsetLeft;while((B=B.offsetParent)!=null){A+=B.offsetLeft;}return A;}function AnchorPosition_getWindowOffsetLeft(A){return AnchorPosition_getPageOffsetLeft(A)-document.body.scrollLeft;}function AnchorPosition_getPageOffsetTop(A){var B=A.offsetTop;while((A=A.offsetParent)!=null){B+=A.offsetTop;}return B;}function AnchorPosition_getWindowOffsetTop(A){return AnchorPosition_getPageOffsetTop(A)-document.body.scrollTop;}

function log(){if(window.console&&window.console.log){window.console.log.apply(window.console,arguments);}}var tit=new Array();var tmpOpenedMenu;function showMenu(B,C){if(!$$("menuLayer["+C+"]")){return ;}window.clearTimeout(tit[C]);tit[C]=null;if(B==false){$$("menuLayer["+C+"]").style.display="none";css("remove",$$("menuButton["+C+"]"),"hover");tmpOpenedMenu=null;}else{var A=getAnchorPosition("menuButton["+C+"]").x;if(tmpOpenedMenu&&C!=tmpOpenedMenu){$$("menuLayer["+C+"]").style.display="none";css("remove",$$("menuButton["+C+"]"),"hover");tmpOpenedMenu=null;}tmpOpenedMenu=C;$$("menuLayer["+C+"]").style.display="block";css("add",$$("menuButton["+C+"]"),"hover");}}function hideMenu(A){tit[A]=setTimeout("showMenu(false,'"+A+"')",225);}
