//chyba pri ajaxe


$(document).ajaxError(function (request,settings,e) {
    // alert('Error requesting URL: '+e.url);
});

//messages - locale
function __(msgid, lang) {
    
    if(typeof(lang) == 'undefined') {
        //return msgid;
        if (typeof(locale[msgid]) == 'undefined' || locale[msgid] == '') {
            return msgid;
        } else {
            return locale[msgid];
        }
    } else {
        //return msgid;
        if (typeof(locale_lang[lang]) == 'undefined') {
            return msgid;
        } else {
            if (typeof(locale_lang[lang][msgid]) == 'undefined' || locale_lang[lang][msgid] == '') {
                return msgid;
            } else {
                return locale_lang[lang][msgid];
            }
        }
    }
}
// funkcia na ziskanie URL routera
var Router = function (route,params) {
    //parametre
    if (typeof(params) == 'object') {
        var p = '';
        $.each(params,function (name,value) {
            if (p != '') {
                p += '&';
            }
            p += escape(name)+'='+escape(value);
        });
        return Router(route)+'?'+p;
    }
    else {
        return registry.langroot + '/' + route;
    }
};
Router.route = function (route,params) {
    Router.gotoUrl(Router(route,params));
    return false;
};
Router.gotoUrl = function (url) {
    window.location.href = url;
    return false;
};
//ajax nastavenia
$.ajaxProgress.setImage(registry.webroot + '/public/images/loading.gif');

/*
//nastavenia pre blockUI
$(function () {
    $.extend($.blockUI.defaults.pageMessageCSS,{
        color: '#000',
        backgroundColor: 'transparent',
        border: 'none',
        margin: '0px'
    });
    
    $.extend($.blockUI.defaults.overlayCSS, { 
        backgroundColor: '#FFF', 
        opacity: '0.8' 
    });
});
*/
//periodicke volanie stavu portalu
$(function () {
    window.setInterval(function () {
        $.ajax({
            url: Router('joblife/portal/events'),
            type: 'GET',
            dataType: 'json',
            global: false,
            success: parseCurrentEvents
        });
    },5 * 60 * 1000);
});
function parseCurrentEvents(json) {
    //alert(json);
}


$(function () {
    
    $('#lang-switch-btn, .actual_lang').hover(function () {
        $('.actual_lang').css('text-decoration','underline');
    }, function () {
        $('.actual_lang').css('text-decoration','none');
    });
    
    $('#lang-switch-btn, .actual_lang').click(function () {
        if ($('#langswitch').hasClass('bb')) {
            $('.other_lang').css('display','none');
            $('#langswitch').removeClass('bb');
        } else {
            $('.other_lang').css('display','block');
            $('#langswitch').addClass('bb');
        }
        
    });
    
    $('#langswitch').hover(function () {
        
    }, function () {
        
        $('.other_lang').css('display','none');
        $('#langswitch').removeClass('bb');
    })
    
    
    $("#ajaxProgress").ajaxStart(function () {
        var scrollXY = getScrollXY();
        $(this).css({
            top: scrollXY[1],
            right: '0px'
        }).show(0);
    }).ajaxStop(function () {
        $(this).hide(0);
        $(this).text(__('loading...'));
    });
    
    //highliteList table
    //vytvorime hover divka do prveho a posledneho elementu TD
    $('table.highliteList tr').each(function (idx,tr) {
            
        var tds = $('td',tr);
        var ths = $('th',tr);
        var div1 = null;
        var div2 = null;
        var inside = null;
        
        if ($(this).hasClass('nohighlite')) {
            if (tds.length) {
                $('<td class="noborder" />').insertBefore(tds.eq(0));
                $('<td class="noborder" />').insertAfter(tds.eq(tds.length - 1));
            }
            if (ths.length) {
                $('<th class="noborder" />').insertBefore(ths.eq(0));
                $('<th class="noborder" />').insertAfter(ths.eq(ths.length - 1));
            }
        } else {
            if (ths.length) {
                $('<th class="hl_insert_left" />').insertBefore(ths.eq(0));
                $('<th class="hl_insert_right" />').insertAfter(ths.eq(ths.length - 1));
            }
            if (tds.length) {
                div1 = $('<div class="hover hl_insert_left"></div>');
                $('<td class="hl_insert_left" />').append(div1).insertBefore(tds.eq(0));
                
                tds.eq(tds.length - 1).css({
                    paddingRight: 0
                });
                div2 = $('<div class="hover hl_insert_right"></div>');
                $('<td class="hl_insert_right" />').append(div2).insertAfter(tds.eq(tds.length - 1));
            }
        }
    });
    
    $('table.highliteList tr').hover(function () {
        var tds = $('td',this);
        if (!$(this).hasClass('noHighlighte')) {
            if (tds.length) {
                tds.addClass('hover');
                tds.eq(0).addClass('hoverfirst');
                tds.eq(tds.length - 1).addClass('hoverlast');
            }
        }
    },function () {
        $('td',this).removeClass('hover')
                    .removeClass('hoverfirst')
                    .removeClass('hoverlast');
    });
    
    // tabulka ktora nema highlite 
    $('table.noHighliteList tr', 'table.highliteList').each(function (idx,tr) {
        var ntds = $('td',tr);
        var nths = $('th',tr);
        if (nths.length) {
            $('th.hl_insert_left', 'table.noHighliteList').remove();
            $('th.hl_insert_right', 'table.noHighliteList').remove();
        }
        if (ntds.length) {
            $('td.hl_insert_left', 'table.noHighliteList').remove();
            $('td.hl_insert_right', 'table.noHighliteList').remove();
        }
    });
    
    $('table.noHighliteList tr').hover(function () {
        var tds = $('td', this);
        if (tds.length) {
            tds.removeClass('hover');
            tds.eq(0).removeClass('hoverfirst');
            tds.eq(tds.length - 1).removeClass('hoverlast');
        }
    }, function () {
        $('td',this).removeClass('hover')
                    .removeClass('hoverfirst')
                    .removeClass('hoverlast');
    });
    
    //hlavne menu
    $('#panelMenu ul.menu li, #panelMenu dl.menu dt').hover(function () {
        var $this = $(this);
        if (!$this.is('.active')) {
            $this.addClass('hover');
        }
    },function () {
        $(this).removeClass('hover');
    });
    
    //reporty
    // $('div.report').each(function (idx,report) {
    //     report = $(report);
    //     Report(report.attr('rel'),$('.report_text',report).html());
    // });
    
    if ($('#globalSearchQ').length) {
        $('#globalSearchQ').globalsearch();
    }
});

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement &&
      	( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

// kliknutie na registraciu
$(function () {
    $('.register_now').click(function () {
        // showPopupWindow('registration', Router('joblife/registration/'), function () {
        //     $.getScript('/public/js/registration.js');
        // });
        registrationPopupWindow();
    });
});

$(document).ready(function () {
    // zobrazenie popup okien
    var content = $('.pp_inlineForm_profile');
    if (content.size() > 0) {
        var dialogContent = new Dialog.content();
        dialogContent.setHtmlContent(content);
        
        var dialog = new Dialog('ProfileEditDialog',{
            size:'small',
            onShow: function (d) {
                d.center();
                // ak je to zakladny profil, tak nacitam jeho skript
                if (content.attr('class') == 'pp_inlineForm_profile baseprofileform') {
                    $.getScript('/public/js/myjoblife/baseprofile.js');
                }
                if (content.attr('class') == 'pp_inlineForm_profile jobform') {
                    $.getScript('/public/js/myjoblife/job.js');
                }
                if (content.attr('class') == 'pp_inlineForm_profile registrationform') {
                    $.getScript('/public/js/registration.js');
                }
            },
            onContentLoad: function (d) {
                d.center();
            },
            content: dialogContent
        });
        dialog.show();
    }
    
    // confirm na vytvorenie profilu ak neexistuje
    var elm = $('.pp_userProfileNotFound');
    if (elm.size() > 0) {
        var lang = $('#profileCurrentLang').val();
        var defaultLang = $('#defaultLang').val();
        Confirm(__('JS_userProfileNotFound'),function () {
            Router.route('joblife/myjoblife/create-empty-profile/?lang_id=' + lang);
            return false;
        },function () {
            Router.route('joblife/myjoblife/myprofile/');
            return;
        });
    }
    
    
    //if (form.size() > 0) {
    //    var width = 395;
    //    var height = 470;
    //    form.css({
    //        cursor: 'default'
    //    });
    //    $.blockUI(form, {
    //        border: 'none',
    //        width: width + 'px'
    //    });
    //    $.getScript('/public/js/myjoblife/baseprofile.js');
    //}
    //$('.blockUI.blockMsg').css({
    //    top: Math.round(($(window).height() - height) / 2) + 'px'
    //});
    
    
    // // zobrazenie reportov
    // $('.report').each(function () {
    //     var typ = $('.ico', $(this)).attr('class');
    //     var text = $('.report_text', $(this)).text();
    //     if (typ == 'ico ico_OK') {
    //         Info(text);
    //     }
    // });
    
    var srf = $('#showRegistrationForm').size();
    if (typeof(srf) != 'undefined' && srf != '') {
        showPopupWindow('registration', Router('joblife/registration/'), function () {
            $.getScript('/public/js/registration.js');
        });
    };
    
    var jpc = $('#jobPositionChangedForm').size();
    if (typeof(jpc) != 'undefined' && jpc != '') {
        var currentProfileLang = $('#jobPositionChangedForm').attr('rel');
        showPopupWindow('profile', Router('joblife/myjoblife/edit-job-position/lang/' + currentProfileLang + '/'), function () {
            
        });
    }
    
    // helpy
    $('.joblifeHelper').hover(function (e) {
        var helpDialogCount = $('.helpDialog').size();
        if (helpDialogCount > 0) {
            $('.helpDialog').hide();
        }
        
        var help_id = $(this).attr('rel');
        
        var thisHelpDialogCount = $('#helpDialog_' + help_id).size();
        
        if (thisHelpDialogCount > 0) {
            var l = e.pageX - $('#helpDialog_' + help_id).width() + 20;
            var t = e.pageY + 20;
            
            l = l < 0 ? 0 : l;
            t = t < 0 ? 0 : t;
            
            $('#helpDialog_' + help_id).css({
                left: l + 'px',
                top: t + 'px'
            });
            $('#helpDialog_' + help_id).show();
        }
        else {
            var helpDialogContent = new HelpDialog.content({
                url: Router('joblife/portal/load-joblife-help/help/' + help_id + '/')
            });
            helpDialogContent.setHtmlContent('<p>toto je content</p>');
            
            var helpDialog = new HelpDialog('helpDialog_' + help_id, {
                onShow: function (d) {
                    d.center(e.pageX, e.pageY);
                },
                onContentLoad: function (d) {
                    d.center(e.pageX, e.pageY);
                },
                content: helpDialogContent
            });
            helpDialog.show();
        }
    }, function (e) {
        var helpDialogCount = $('.helpDialog').size();
        if (helpDialogCount > 0) {
            $('.helpDialog').hide();
        }
    });
});

function showPopupWindow(type, url, load_callback, callback) {
    if (type == 'medium') {
        var dialogContent = new Dialog.content({
            url: url
        });
        var dialog = new Dialog('ProfileEditDialog',{
            size:'medium',
            onShow: function (d) {
                d.center();
                if (typeof(callback) == 'function') {
                    callback();
                }
            },
            onContentLoad: function (d) {
                d.center();
                if (typeof(load_callback) == 'function') {
                    load_callback();
                }
            },
            content: dialogContent
        });
        dialog.show();
    }
    if (type == 'profile') {
        var dialogContent = new Dialog.content({
            url: url
        });
        var dialog = new Dialog('ProfileEditDialog',{
            size:'small',
            onShow: function (d) {
                d.center();
                if (typeof(callback) == 'function') {
                    callback();
                }
            },
            onContentLoad: function (d) {
                if (typeof(load_callback) == 'function') {
                    load_callback();
                }
                d.center();
            },
            content: dialogContent
        });
        dialog.show();
    }
    if (type == 'registration') {
        var dialogContent = new Dialog.content({
            url: url
        });
        var dialog = new Dialog('RegistrationDialog', {
            size: 'registration',
            onShow: function (d) {
                d.center();
                if (typeof(callback) == 'function') {
                    callback();
                }
            },
            onContentLoad: function (d) {
                d.center();
                if  (typeof(load_callback) == 'function') {
                    load_callback();
                }
            },
            content: dialogContent
        });
        dialog.show();
        
        // var window_id = 'registrationWindow';
        //var width = 674;
        //var height = 470;
        //
        //var win = $('<div id="' + window_id + '">').css({
        //    cursor: 'default',
        //    width: width + 'px'
        //}).load(url, {}, function () {
        //    if (typeof(load_callback) == 'function') {
        //        load_callback();
        //    }
        //});
        //$.blockUI(win, {
        //    border: 'none',
        //    width: width + 'px'
        //});
        //
        //$('.blockUI.blockMsg').css({
        //    top: Math.round(($(window).height() - height) / 2) + 'px'
        //});
        //
        //if (typeof(callback) == 'function') {
        //    callback();
        //} 
    }
    return dialog;
}

function closePopupWindow() {
    $('#popupWindow').hide();
    //$.unblockUI();
}

function Info(msg, callback) {
    Alert(msg);
    if (typeof(callback) == 'function') {
        callback();
    }
}

var Alert_counter = 0;
Alert = function (msg,callback) {
    Alert_counter++;
    var dialogContent = new Dialog.content({
        header: __('JS_Alert'),
        html: msg
    }).addButton(__('JS_OK'),function (d) {
        d.close();
        var ret = true;
        if (typeof(callback) == 'function') {
            ret = callback();
        }
    });
    var dialog = new Dialog('alert' + Alert_counter,{
        size:'small',
        onShow: function (d) {
            d.center();
        },
        content: dialogContent
    });
    dialog.show();
};

var RegOkAlert_counter = 0;
RegOkAlert = function (msg, callback) {
    RegOkAlert_counter++;
    var dialogContent = new Dialog.content({
        header: __('JS_registrationOk'),
        html: msg
    }).addButton(__('JS_OK'), function (d) {
        d.close();
        var ret = true;
        if (typeof(callback) == 'function') {
            ret = callback();
        }
    });
    var dialog = new Dialog('ok_alert' + RegOkAlert_counter, {
        size: 'small',
        onShow: function (d) {
            d.center();
        },
        content: dialogContent
    });
    dialog.show();
};

var Confirm_counter = 0;
Confirm = function (msg,fcnYes,fcnNo) {
    Confirm_counter++;
    var dialogContent = new Dialog.content({
        header: __('JS_Confirm'),
        html: msg
    }).addButton(__('JS_Yes'),function (d) {
        d.close();
        var ret = true;
        if (typeof(fcnYes) == 'function') {
            ret = fcnYes();
        }
        return ret;
    }).addButton(__('JS_No'),function (d) {
        d.close();
        var ret = true;
        if (typeof(fcnNo) == 'function') {
            ret = fcnNo();
        }
        return ret;
    });
    var dialog = new Dialog('alert' + Alert_counter,{
        size:'small',
        onShow: function (d) {
            d.center();
        },
        content: dialogContent
    });
    dialog.show();
};

var Report_counter = 0;
Report = function (type,msg) {
    Report_counter++;
    var dialogContent = new Dialog.content({
        html: '<div class="report"><div class="reportIco reportIco-' + type + '">&#160;</div><div class="reportText">' + msg + '</div></div>'
    }).addButton(__('JS_OK'),function (d) {
        d.close();
    });
    var dialog = new Dialog('report' + Report_counter,{
        size:'small',
        onShow: function (d) {
            d.center();
        },
        content: dialogContent
    });
    dialog.show();
};

function jobPopupWindow(url) {
    var dialogContent = new Dialog.content({
        url: url
    });
    var dialog = new Dialog('JobFormDialog', {
        size: 'small',
        onShow: function (d) {
            d.center();
        },
        onContentLoad: function (d) {
            d.center();
            
            $('#q_firm_name').focus();
            $('#q_firm_name').attr("autocomplete", "off");
            
            //vyhladavac firiem
            $('#q_firm_name').similarFirmSearch({
                onSelect: function (holder,firma) {
                    $('#q_firm_name').val(firma.name);
                    $('#firm_id').val(firma.id);
                    // return false;
                }
            });
            
            $('#till_now').click(function () {
                if (this.checked) {
                    $('#month_to').attr('disabled', 'disabled');
                    $('#year_to').attr('disabled', 'disabled');
                }
                else {
                    $('#month_to').removeAttr('disabled');
                    $('#year_to').removeAttr('disabled');
                }
            });
        },
        content: dialogContent
    });
    dialog.show();
}

function registrationPopupWindow() {
    Router.route('joblife/registration/');
    if($.browser.msie){
        window.event.returnValue=false;
    }
    return false;
    //var dialogContent = new Dialog.content({
    //    url: Router('joblife/registration/')
    //});
    //var dialog = new Dialog('RegistrationDialog', {
    //    size: 'registration',
    //    onShow: function (d) {
    //        d.center();
    //    },
    //    onContentLoad: function (d) {
    //        $('.t', '#RegistrationDialog').css({
    //            'background': 'url(/public/themes/images/dialog/reg2_form_bottom.gif) no-repeat left bottom'
    //        });
    //        d.center();
    //        
    //        $('#forename').focus();
    //        
    //        $('#password1').keyup(function () {
    //            var pass_val = $(this).val();
    //            // $.get(Router('joblife/portal/password-strength-meter/'), {
    //            //     q: pass_val
    //            // }, function (percentage) {
    //            //     $('#psm_bar').css({
    //            //         'width': percentage + '%'
    //            //     });
    //            //     $('#psm_pctg').text(percentage + '%');
    //            // });
    //            var percentage = passwordStrengthMeter(pass_val);
    //            $('#psm_bar').css({
    //                'width': percentage + '%'
    //            });
    //            $('#psm_pctg').text(percentage + '%');
    //        });
    //        
    //        $('#eduToggle').click(function () {
    //            $('#rf_security').hide();
    //            $('#rf_education').show();
    //        });
    //    },
    //    content: dialogContent
    //});
    //dialog.show();
}

function submitJobForm(form) {
    var firm_name    = $('#q_firm_name').val();
    var job_position = $('#job_position').val();
    var month_from   = $('#month_from').val();
    var year_from    = $('#year_from').val();
    var month_to     = $('#month_to').val();
    var year_to      = $('#year_to').val();
    var till_now     = $('#till_now')[0].checked == true ? 1 : 0;
    var description  = $('#description').val();
    
    var valid = true;
    var years_valid = true;
    
    if (typeof(firm_name) == 'undefined' || firm_name == '') {
        valid = false;
        $('#firm_name_label').addClass('required');
    }
    else {
        $('#firm_name_label').removeClass('required');
    }
    
    if (typeof(job_position) == 'undefined' || job_position == '') {
        valid = false;
        $('#job_position_label').addClass('required');
    }
    else {
        $('#job_position_label').removeClass('required');
    }
    
    if ((typeof(month_from) == 'undefined' || month_from == '') || (typeof(year_from) == 'undefined' || year_from == '')) {
        valid = false;
        $('#date_from_label').addClass('required');
    }
    else {
        $('#date_from_label').removeClass('required');
    }
    
    if (((typeof(month_to) == 'undefined' || month_to == '') || (typeof(year_to) == 'undefined' || year_to == '')) && till_now == 0) {
        valid = false;
        $('#date_to_label').addClass('required');
    }
    else {
        $('#date_to_label').removeClass('required');
    }
    
    if (!till_now) {
        if (parseInt(year_from,10) > parseInt(year_to,10)) {
            years_valid = false;
            Alert(__('JS_badJobYears'));
        }
        if (parseInt(year_from,10) == parseInt(year_to,10)) {
            if (parseInt(month_from,10) > parseInt(month_to,10)) {
                years_valid = false;
                Alert(__('JS_badJobYears'));
            }
        }
    }
    
    if (!valid) {
        $('#formEmptyFields').show();
    }
    else {
        $('#formEmptyFields').hide();
        if (years_valid) {
            form.submit();
        }
    }
}

function passwordStrengthMeter(q) {
    // PRAVIDLA:
    //    +9% - 6 a viac znakov
    //    +9% - 8 a viac znakov
    //    +7% - 1. číslo v hesle
    //    +7% - 2. číslo v hesle
    //    +7% - 3. číslo v hesle
    //    +7% - 1. písmeno v hesle
    //    +7% - 2. písmeno v hesle
    //    +7% - 3. písmeno v hesle
    //    +8% - 1. iný znak v hesle (všetky okrem písmen a čísel)
    //    +8% - 2. iný znak v hesle (všetky okrem písmen a čísel)
    //    +8% - 1. veľké písmeno v hesle
    //    +8% - 2. veľké písmeno v hesle
    //    +8% - medzera v hesle
    
    var percentage = 0;
    var matches = Array();
    
    if (q.length >= 6) {
        percentage += 9;
    }
    if (q.length >= 8) {
        percentage += 9;
    }
    
    var number_count = q.match(/[0-9]/g);
    if (number_count != null) {
        if (number_count.length > 0) {
            percentage += 7;
        }
        if (number_count.length > 1) {
            percentage += 7;
        }
        if (number_count.length > 2) {
            percentage += 7;
        }
    }
    
    var letters_count = q.match(/[a-zA-Z]/g);
    if (letters_count != null) {
        if (letters_count.length > 0) {
            percentage += 7;
        }
        if (letters_count.length > 1) {
            percentage += 7;
        }
        if (letters_count.length > 2) {
            percentage += 7;
        }
    }
    
    var other_chars_count = q.match(/[^a-zA-Z0-9\s]/g);
    if (other_chars_count != null) {
        if (other_chars_count.length > 0) {
            percentage += 8;
        }
        if (other_chars_count.length > 1) {
            percentage += 8;
        }
    }
    
    var uppercase_letter_count = q.match(/[A-Z]/g);
    if (uppercase_letter_count != null) {
        if (uppercase_letter_count.length > 0) {
            percentage += 8;
        }
        if (uppercase_letter_count.length > 1) {
            percentage += 8;
        }
    }
    
    var spaces_count = q.match(/[\s]/g);
    if (spaces_count != null) {
        if (spaces_count.length > 0) {
            percentage += 8;
        }
    }
    
    return percentage;
}

function noschool_addNewSchool(school_type, user_name, user_surname, user_email) {
    if (typeof(school_type) == 'undefined' || school_type == '') {
        var type = $('#school_type').val();
    }
    else {
        type = school_type;
    }
    if (typeof(type) == 'undefined' || type == '') {
        Alert(__('JS_setSchoolType'));
    }
    else {
        if (typeof(user_name) != 'undefined' && user_name != '') {
            var u_name = user_name;
        }
        else {
            var u_name = '';
        }
        
        if (typeof(user_surname) != 'undefined' && user_surname != '') {
            var u_surname = user_surname;
        }
        else {
            var u_surname = '';
        }
        
        if (typeof(user_email) != 'undefined' && user_email != '') {
            var u_email = user_email;
        }
        else {
            var u_email = '';
        }
        
        var dialog_content = new Dialog.content({
            url: Router('joblife/myjoblife/add-codebook-school/type/' + type + '/')
        });
        var dialog = new Dialog('AddCodebookSchool', {
            size: 'small',
            onShow: function (d) {
                d.center();
            },
            onContentLoad: function (d) {
                d.center();
                $('#n_country_id').change(function () {
                    // var citySelect = $('#n_city_id')[0];
                    // while (citySelect.childNodes.length > 0) {
                    //     citySelect.removeChild(citySelect.childNodes[0])
                    // }
                    $('#n_city_id').empty();
                    var country_id = $('#n_country_id').val();
                    if (country_id != '') {
                        if ($('#n_school_type').val() != 'UNIVERSITY') {
                            $.getJSON(Router('joblife/portal/load-cities-json'), {
                                country_id: country_id
                            }, function (json) {
                                var citySelect = $('#n_city_id')[0];
                                citySelect.options[0] = new Option('   ', '');
                                for (var i=0; i<json.length; i++) {
                                    citySelect.options[i + 1] = new Option(json[i].city, json[i].city_id);
                                }
                                citySelect.options[i + 1] = new Option(__('JS_ohterItemInSelect'), 'OTHER');
                            });
                        }
                    }
                });
                
                $('#n_city_id').change(function () {
                    var city_id = $(this).val();
                    if (city_id == 'OTHER') {
                        $('#n_city_id_txt').show();
                    }
                });
                
                $('#noschool_submit').click(function () {
                    var n_school_type  = $('#n_school_type').val();
                    var n_country_id   = $('#n_country_id').val();
                    var n_city_id      = $('#n_city_id').val();
                    var n_city_id_txt  = $('#n_city_id_txt').val();
                    var n_school_name  = $('#n_school_name').val();
                    var n_faculty_name = $('#n_faculty_name').val();
                    
                    var valid = true;
                    
                    if (typeof(n_country_id) == 'undefined' || n_country_id == '') {
                        valid = false;
                    }
                    
                    if (typeof(n_school_name) == 'undefined' || n_school_name == '') {
                        valid = false;
                    }
                    
                    if (n_school_type == 'HIGHSCHOOL') {
                        if (typeof(n_city_id) == 'undefined' || n_city_id == '' || n_city_id == 'OTHER') {
                            if (typeof(n_city_id_txt) == 'undefined' || n_city_id_txt == '') {
                                valid = false;
                            }
                        }
                    }
                    // if (n_school_type == 'UNIVERSITY') {
                    //     if (typeof(n_faculty_name) == 'undefined' || n_faculty_name == '') {
                    //         valid = false;
                    //     }
                    // }
                    
                    if (valid) {
                        $.getJSON(Router('joblife/myjoblife/save-codebook-school-ajax/'), {
                            n_school_type: n_school_type,
                            n_country_id: n_country_id,
                            n_city_id: n_city_id,
                            n_city_id_txt: n_city_id_txt,
                            n_school_name: n_school_name,
                            n_faculty_name: n_faculty_name,
                            u_name: u_name,
                            u_surname: u_surname,
                            u_email: u_email
                        }, function (json) {
                            if (json.error) {
                                Alert(json.error);
                            }
                            else if (json.ok) {
                                d.close();
                                //Alert(__('JS_schoolAdded'));
                                if (typeof(school_type) == 'undefined' || school_type == '') {
                                    Alert(json.ok, function () {
                                        Router.route('joblife/myjoblife/myprofile/');
                                    });
                                    countryOnchange(n_country_id);
                                }
                                else {
                                    Alert(json.ok);
                                }
                            }
                            else {
                                d.close();
                            }
                        });
                    }
                    else {
                        Alert(__('JS_emptyFields'));
                    }
                });
            },
            content: dialog_content
        });
        dialog.show();
    }
}

var browserPopup1Win = null;
function browserPopup1(href,w,h) {
    if (browserPopup1Win) {
        browserPopup1Win.close();
    }
    if (browserPopup1Win==null || browserPopup1Win.closed) {
        var top = screen.height/2 - h/2;
        var left = screen.width/2 - w/2;
        var settings =
            "left=" + left + "px,"
            +"top=" + top + "px,"
            +"width=" + w + "px,"
            +"height=" + h + "px,"
            +"toolbar=no,"
            +"location=no,"
            +"directories=no,"
            +"status=yes,"
            +"menubar=no,"
            +"scrollbars=yes,"
            +"resizable=no";
        browserPopup1Win = window.open(href,'okno',settings);
    }
    browserPopup1Win.focus();
}
/*
//divoka karta - preblikavanie buttonu
$(function () {
    var dreamJobWildcardBtn1 = $('#dreamJobWildcardBtn1');
    if (dreamJobWildcardBtn1.length) {
        dreamJobWildcardBtn1Anim(0);
    }
    var dreamJobWildcardBtn2 = $('#dreamJobWildcardBtn2');
    if (dreamJobWildcardBtn2.length) {
        dreamJobWildcardBtn2Anim(0);
    }
    var dreamJobWildcardBtn3 = $('#dreamJobWildcardBtn3');
    if (dreamJobWildcardBtn3.length) {
        dreamJobWildcardBtn3Anim(0);
    }
    $('#dreamJobWildcardBtn2 a, #dreamJobWildcardBtn3 a, #dreamJobWildcardBtn4 a').click(function () { //#dreamJobWildcardBtn1 a - NIE!
        if ($('#dreamJobWildcardBanner').length) {
            $('#dreamJobWildcardBanner').remove();
        }
        var wc = $('<div></div>');
        wc.attr('id','dreamJobWildcardBanner');
        var w = 566;
        var h = 211;
        wc.width(566);
        wc.height(211);
        wc.css({
                position: 'absolute',
                top: ($(window).height() - h) / 2 + $(document).scrollTop(),
                left: ($(window).width() - w) / 2 + $(document).scrollLeft(),
                zIndex: 1000,
                background: 'URL(/public/themes/dreamjob/images/wildcard53.png) no-repeat top left',
                cursor: 'pointer'
        });
        wc.click(function () {
            location.href = '/joblife/dreamjob/vyberove-konanie';
            return false;
        });
        var wcclose = $('<a></a>');
        wcclose.css({
                display: 'block',
                width: '15px',
                height: '15px',
                position: 'absolute',
                top: '21px',
                right: '23px',
                cursor: 'pointer'
        });
        wcclose.click(function () {
            $('#dreamJobWildcardBanner').remove();
        });
        wc.append(wcclose);
        wc.appendTo($('body'));
        return false;
    });
});
function dreamJobWildcardBtn1Anim(status) {
    var interval = 1000;
    if (status == 0) {
        $('#dreamJobWildcardBtn1').css('background-position','0px 0px');
        window.setTimeout(function () {
            dreamJobWildcardBtn1Anim(1)
        },interval);
    } else {
        $('#dreamJobWildcardBtn1').css('background-position','-134px 0px');
        window.setTimeout(function () {
            dreamJobWildcardBtn1Anim(0)
        },interval);
    }
}
function dreamJobWildcardBtn2Anim(status) {
    var interval = 1000;
    if (status == 0) {
        $('#dreamJobWildcardBtn2').css('background-position','-2px 0px');
        window.setTimeout(function () {
            dreamJobWildcardBtn2Anim(1)
        },interval);
    } else {
        $('#dreamJobWildcardBtn2').css('background-position','-196px 0px');
        window.setTimeout(function () {
            dreamJobWildcardBtn2Anim(0)
        },interval);
    }
}
function dreamJobWildcardBtn3Anim(status) {
    var interval = 1000;
    if (status == 0) {
        $('#dreamJobWildcardBtn3').css('background-position','0px 0px');
        window.setTimeout(function () {
            dreamJobWildcardBtn3Anim(1)
        },interval);
    } else {
        $('#dreamJobWildcardBtn3').css('background-position','-190px 0px');
        window.setTimeout(function () {
            dreamJobWildcardBtn3Anim(0)
        },interval);
    }
}
*/
