//...................................................................
//......Все используемые функции и плагины вынесены сюда.............
//...................................................................
/*
 * jQuery-Plugin "pngFix"
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<62?'':e(parseInt(c/62)))+((c=c%62)>35?String.fromCharCode(c+29):c.toString(36))};if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'([237-9n-zA-Z]|1\\w)'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(s(m){3.fn.pngFix=s(c){c=3.extend({P:\'blank.gif\'},c);8 e=(o.Q=="t R S"&&T(o.u)==4&&o.u.A("U 5.5")!=-1);8 f=(o.Q=="t R S"&&T(o.u)==4&&o.u.A("U 6.0")!=-1);p(3.browser.msie&&(e||f)){3(2).B("img[n$=.C]").D(s(){3(2).7(\'q\',3(2).q());3(2).7(\'r\',3(2).r());8 a=\'\';8 b=\'\';8 g=(3(2).7(\'E\'))?\'E="\'+3(2).7(\'E\')+\'" \':\'\';8 h=(3(2).7(\'F\'))?\'F="\'+3(2).7(\'F\')+\'" \':\'\';8 i=(3(2).7(\'G\'))?\'G="\'+3(2).7(\'G\')+\'" \':\'\';8 j=(3(2).7(\'H\'))?\'H="\'+3(2).7(\'H\')+\'" \':\'\';8 k=(3(2).7(\'V\'))?\'float:\'+3(2).7(\'V\')+\';\':\'\';8 d=(3(2).parent().7(\'href\'))?\'cursor:hand;\':\'\';p(2.9.v){a+=\'v:\'+2.9.v+\';\';2.9.v=\'\'}p(2.9.w){a+=\'w:\'+2.9.w+\';\';2.9.w=\'\'}p(2.9.x){a+=\'x:\'+2.9.x+\';\';2.9.x=\'\'}8 l=(2.9.cssText);b+=\'<y \'+g+h+i+j;b+=\'9="W:X;white-space:pre-line;Y:Z-10;I:transparent;\'+k+d;b+=\'q:\'+3(2).q()+\'z;r:\'+3(2).r()+\'z;\';b+=\'J:K:L.t.M(n=\\\'\'+3(2).7(\'n\')+\'\\\', N=\\\'O\\\');\';b+=l+\'"></y>\';p(a!=\'\'){b=\'<y 9="W:X;Y:Z-10;\'+a+d+\'q:\'+3(2).q()+\'z;r:\'+3(2).r()+\'z;">\'+b+\'</y>\'}3(2).hide();3(2).after(b)});3(2).B("*").D(s(){8 a=3(2).11(\'I-12\');p(a.A(".C")!=-1){8 b=a.13(\'url("\')[1].13(\'")\')[0];3(2).11(\'I-12\',\'none\');3(2).14(0).15.J="K:L.t.M(n=\'"+b+"\',N=\'O\')"}});3(2).B("input[n$=.C]").D(s(){8 a=3(2).7(\'n\');3(2).14(0).15.J=\'K:L.t.M(n=\\\'\'+a+\'\\\', N=\\\'O\\\');\';3(2).7(\'n\',c.P)})}return 3}})(3);',[],68,'||this|jQuery||||attr|var|style||||||||||||||src|navigator|if|width|height|function|Microsoft|appVersion|border|padding|margin|span|px|indexOf|find|png|each|id|class|title|alt|background|filter|progid|DXImageTransform|AlphaImageLoader|sizingMethod|scale|blankgif|appName|Internet|Explorer|parseInt|MSIE|align|position|relative|display|inline|block|css|image|split|get|runtimeStyle'.split('|'),0,{}))
////Исправляет показ png в ie

$(document).ready(function(){$(document).pngFix();});

$(document).ready(function(){
    $('#RememberMeCheckBox').attr('checked','checked');
});

//Плагин - запрещает ввод символов в поля
// http://itgroup.com.ph/alphanumeric/
// примеры:
//$('.sample1').alphanumeric(); - без спец-символов
//$('.sample2').alphanumeric({allow:"., "}); - Allow only alphanumeric characters, and some exceptions like dot(.), comma (,) and space
//$('.sample3').alpha({nocaps:true}); - Allow only lowercase alpha characters  
//$('.sample4').numeric(); - Allow only numeric characters 
//$('.sample5').numeric({allow:"."}); - Allow only numeric characters, and some exceptions like dot (.)
//$('.sample6').alphanumeric({ichars:'.1a'}); - Make a custom rule and define only certain characters to prevent, like dot (.), one (1), and a (a)
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(2($){$.c.f=2(p){p=$.d({g:"!@#$%^&*()+=[]\\\\\\\';,/{}|\\":<>?~`.- ",4:"",9:""},p);7 3.b(2(){5(p.G)p.4+="Q";5(p.w)p.4+="n";s=p.9.z(\'\');x(i=0;i<s.y;i++)5(p.g.h(s[i])!=-1)s[i]="\\\\"+s[i];p.9=s.O(\'|\');6 l=N M(p.9,\'E\');6 a=p.g+p.4;a=a.H(l,\'\');$(3).J(2(e){5(!e.r)k=o.q(e.K);L k=o.q(e.r);5(a.h(k)!=-1)e.j();5(e.u&&k==\'v\')e.j()});$(3).B(\'D\',2(){7 F})})};$.c.I=2(p){6 8="n";8+=8.P();p=$.d({4:8},p);7 3.b(2(){$(3).f(p)})};$.c.t=2(p){6 m="A";p=$.d({4:m},p);7 3.b(2(){$(3).f(p)})}})(C);',53,53,'||function|this|nchars|if|var|return|az|allow|ch|each|fn|extend||alphanumeric|ichars|indexOf||preventDefault||reg|nm|abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбю|String||fromCharCode|charCode||alpha|ctrlKey||allcaps|for|length|split|1234567890|bind|jQuery|contextmenu|gi|false|nocaps|replace|numeric|keypress|which|else|RegExp|new|join|toUpperCase|ABCDEFGHIJKLMNOPQRSTUVWXYZЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ'.split('|'),0,{}));

function update(dl) {
        $("dt:not(.active)", dl).css("cursor", "pointer");
        $("dt.active", dl).css("cursor", "");

        $("dd div", dl).hide(300);
        $("dd span.remark", dl).show();

        $("dt.active", dl).next().children("div").show(300);
        $("dt.active", dl).next().children("span.remark").hide();
    }

function showdiv() {
            jQuery.each(jQuery.browser, function(i, val) {
               if(i=="msie" && jQuery.browser.version=="5.0" && val == true)
                {
                       $('#iframefon').css("display","block"); 
                   }
               else {$("#divfon").fadeIn(300);}
             });}
function hidediv() {
    $("#sitydisplay").hide(300);
    $("#logindisplay").hide(300);
    $("#divfon").fadeOut(300);
}


//...................................................................
//......Tabs.........................................................
//...................................................................
$(function () {
			var tabContainers = $('div.tabs > div.tab');
            var second = $('#second');
            var first = $('#first');
            var three = $('#three');
			tabContainers.hide();
			second.hide();
            three.hide();
            //Делаем по-умолчанию видимым первую вкладку
            first.show();$('a.a_first').addClass('selected');

            $('div.tabs div.tabNavigation a.a_first').click(function () {
                first.show();
                second.hide();
                three.hide();
                $('div.tabs div.tabNavigation a').removeClass('selected');
				$(this).addClass('selected');
                return false;
            })
            $('div.tabs div.tabNavigation a.a_second').click(function () {
                first.hide();
                second.show();
                three.hide();    
                $('div.tabs div.tabNavigation a').removeClass('selected');
				$(this).addClass('selected');
                return false;
            })

             $('div.tabs div.tabNavigation a.a_three').click(function () {
                first.hide();
                second.hide();
                three.show();
                $('div.tabs div.tabNavigation a').removeClass('selected');
				$(this).addClass('selected');
                return false;
            })

            $('#opentab').click(function () {
                
                $('div.tabs div.tabNavigation a.a_first').click();
                return false;
            })
            
            //Просмотр вакансий в просмотре компаний
            //Выбираются первые три элемента - они видимые, остальные в страхе прячутся пока юзер не раскроет список
            
            $('#company_vacancy_show').toggle(
                function () {
                    if (jQuery.browser.msie) {
                        $('#search_result_div').css({'display':'block'}); return false;
                    }
                    /*$('#search_result_div').css({'display':'table-footer-group'}, 300); return false;*/
                    else {
                        $('#search_result_div').animate({opacity: "show"},400); return false;
                    }
            },
                function () {$('#search_result_div').animate({opacity: "hide"},300); return false;}
            );
            
            $('#company_courses_show').toggle(
                function () {
                    if (jQuery.browser.msie) {
                        $('#search_result_div').css({'display':'block'}); return false;
                    }
                    /*$('#search_result_div').css({'display':'table-footer-group'}, 300); return false;*/
                    else {
                        $('#search_result_div').animate({opacity: "show"},400); return false;
                    }
            },
                function () {$('#search_result_div').animate({opacity: "hide"},300); return false;}
            );

		});

//...................................................................
//......Toggle.......................................................
//...................................................................

$(function () {

     $("div.toggle").toggle(
          function () { var el=this;$(el).next("div.toggle_content").slideDown(300); $(el).find("span.toggle_right").html(" <small class=\"arrow\">&#9650;</small>"); $(el).find("span.toggle_left").css("border-color","transparent"); },
          function () { var el=this;$(el).next("div.toggle_content").slideUp(300); $(el).find("span.toggle_right").html(" <small class=\"arrow\">&#9660;</small>"); $(el).find("span.toggle_left").css("border-bottom","1px dashed");}
        );
            
    $("div#charity_toggle").click()
    $("div#charity_toggle_2").click()

})

//Скругленные уголки
//window.onload=function(){
//      if(!NiftyCheck())
//        return;
//      Rounded("div.toggle","#CDE3FC","#B1D3FF");
//    }

$(document).ready
(function() {
            
            var w =$(document).width();
            if (w>1100) {
                $('#style_to_top').css("width","900px");
                $('#top_logo').html('<img src="/i/rabota.png">').show();
                $('#bottom_logo').hide();

            }
            else {
                $('#style_to_top').css("width","700px");
                $('#top_logo').hide();
                $('#bottom_logo').show();
            }
});


//...................................................................
//......Расширенный поиск............................................
//...................................................................

$(document).ready
(

    function() {
        //Действие после нажатия на расширенный поиск
        $(".slide1").click(function () {
            if ($("div.boo1").css("display") == "none") {
                $("div.boo1").slideDown(300);
                $("a.one").html(" <small class=\"arrow\">&#9650;</small>");
                $('#search_more_vacancy').val('true');
            } else {
                $("div.boo1").slideUp(300);
                $("a.one").html(" <small class=\"arrow\">&#9660;</small>");
                $('#search_more_vacancy').val('false');
            }
        });
            
        $(".slide2").click(function () {
            if ($("div.boo2").css("display") == "none") {
                $("div.boo2").slideDown(300);
                $("a.two").html(" <small class=\"arrow\">&#9650;</small>");
                $('#search_more_resume').val('true');
            } else {
                $("div.boo2").slideUp(300);
                $("a.two").html(" <small class=\"arrow\">&#9660;</small>");
                $('#search_more_resume').val('false');
            }
        });

        $(".slide3").click(function () {
            if ($("div.boo3").css("display") == "none") {
                $("div.boo3").slideDown(300);
                $("a.three").html(" <small class=\"arrow\">&#9650;</small>");
                $('#search_more_course').val('true');
            } else {
                $("div.boo3").slideUp(300);
                $("a.three").html(" <small class=\"arrow\">&#9660;</small>");
                $('#search_more_course').val('false');
            }
        });
//
//        $(".slide3").toggle(
//          function () {$("div.boo3").slideDown(300); $("a.three").html(" <small class=\"arrow\">&#9650;</small>"); $('#search_more_course').val('true')},
//          function () {$("div.boo3").slideUp(300); $("a.three").html(" <small class=\"arrow\">&#9660;</small>"); $('#search_more_course').val('false')}
//        );

        //В расширенном поиске вакансии - "зарплата"
        //Если поле "Желаемый заработок" пустое (т.е. форма загрузилась и в ней нет значения)
        var sal = $("#salary_vac");
        if (sal.val()=='') {
            sal.val('Желаемый заработок').focus(function () {if ($(this).val()=='Желаемый заработок') {$(this).val('')}});
            sal.blur(function () {if ($(this).val()=='') {$(this).val('Желаемый заработок')}});}
        //Проверка при вводе
        

        var salres = $("#salary_res");
        if (salres.val()=='') {
            salres.val('Предлагаемая оплата').focus(function () {if ($(this).val()=='Предлагаемая оплата') {$(this).val('')}});
            salres.blur(function () {if ($(this).val()=='') {$(this).val('Предлагаемая оплата')}});}

        var age = $("#age");
        if (age.val()=='') {
            age.val('Ваш возраст').focus(function () {if ($(this).val()=='Ваш возраст') {$(this).val('')}});
            age.blur(function () {if ($(this).val()=='') {$(this).val('Ваш возраст')}});}

        var st_old = $("#start_old");
        if (st_old.val()=='') {
            st_old.val('от').focus(function () {if ($(this).val()=='от') {$(this).val('')}});
            st_old.blur(function () {if ($(this).val()=='') {$(this).val('от')}});}

        var end_old = $("#end_old");
        if (end_old.val()=='') {
            end_old.val('до').focus(function () {if ($(this).val()=='до') {$(this).val('')}});
            end_old.blur(function () {if ($(this).val()=='') {$(this).val('до')}});}

        //Определяем что наши поля для ввода только числовые
        sal.numeric();
        salres.numeric();
        age.numeric();
        st_old.numeric();
        end_old.numeric();
    });

//...................................................................
//......Поиск по каталогу............................................
//...................................................................
$(document).ready
(
function () {
    $("#catalog_list a").click(function () {
                
        var elt = this;
    //                var type=this.prev().find("#catalog_list").attr('class');

        ide = $(elt).attr("id");
        div = $("div#" + ide + "A");
        span = $(div).find('span').attr('class');
        var url;

        ajax = $("span#" + ide + "S");
        $().ajaxStart(function() { $("#" + ide + "S").show(300); });
        $().ajaxStop(function() { $("#" + ide + "S").hide(300); });
        if ($(elt).attr("open") == "1") {
            $(div).hide(500);
            $(elt).attr("open", "0");
        } else if ($(elt).attr("open") == "0") {


            if ( $(this).attr('class')=="loaded") {
                $(div).show(500);$(elt).attr("open", "1");
            } else {
                if (span =='resume')  {
                    url = "/includes/functions/ajax_get_res_professions.php";
                } else {
                    url = "/includes/functions/ajax_get_vac_professions.php";
                }

                $(div).load(url, {
                    id: ide,
                    region_id: $(elt).attr("region_id"),
                    sity_id: $(elt).attr("sity_id"),
                    catalog_type: $(elt).attr("catalog_type"),
                    url_parent: $(elt).attr("url_parent"),
                    all: $("span.all").attr("class")
                }).ajaxStop(function() {
                        $(div).show(500);
                        $(elt).addClass("loaded");
                        $(elt).attr("open", "1");
                })
        }}
        return false;
    })
})
//...................................................................
//......Выбор города.................................................
//...................................................................
function SetInputState(input, state) {
    $(input).removeClass("important valid common error").addClass(state);
}
function doAjax(url, params, onSuccess, onError) {
    $.ajax({
        type: "GET",
        dataType: "html",
        url: url,
        data: params,
        success: onSuccess,
        error: onError
    });
}

$(document).ready
(
    function() {
        // Ajax init
        $().ajaxStart(function() {
            $("#ajax-ind").show();
        });
        $().ajaxStop(function() {
            $("#ajax-ind").hide();
        });
        // Login init
        $("#sity-close").click(function() { 
            hidediv();
            return false;
        });
        
        

        //Действие после нажатия на город
        $(".EnterSity").click(function() {
            $("#sitydisplay").show(300);
            showdiv();
            return false
        })
        $("#divfon").click(function() {            
            hidediv();
        });

    }
);


//...................................................................
//......Вход для пользователя........................................
//...................................................................
var login_reg = /^[\w.-]+@([\w.-]+\.)+\w{2,6}$/i;
var pass_reg = /^.{6,32}$/;

function ValidateInput(input, reg) {
    var result = reg.test($(input)[0].value);
    if (!result) SetInputState(input, "error");
    else SetInputState(input, "valid");
    return result;
}
function SetInputState(input, state) {
    $(input).removeClass("important valid common error").addClass(state);
}
function doAjax(url, params, onSuccess, onError) {
    $.ajax({
        type: "POST",
        dataType: "html",
        url: url,
        data: params,
        success: onSuccess,
        error: onError
    });
}
function onLoginCheck(result) {
    if (result == "false"){
        SetInputState($("#email"), "error");
    }
        
}
function onLoginCheckError(error) {
    alert("Error");
}

var last_check = "";
$(document).ready
(
    function() {
        // Ajax init
        $().ajaxStart(function() {
            $(".ajax-ind").show();
        });
        $().ajaxStop(function() {
            $(".ajax-ind").hide();
        });
        // Login init

        $("#ld-close").click(function() { hidediv(); return false; });

        $("#email").blur(function() {
            ValidateInput(this, login_reg);
        });
        $("#pass").blur(function() {
            ValidateInput(this, pass_reg);
        });
       
        $(".EnterLink").click(function() {
            $("#logindisplay").show(300);
            $("#email").focus();
            showdiv()
            return false;
        })
        
        //Действие после нажатия "вход"
        //1) Проверяем логин и пароль
        $("#user_login_button").click(function() {
            
            $("#mydiv").load("/includes/functions/ajax_check_login.php",{
                user_login_button: "",
                email: $('#email').val(),
                pass: $('#pass').val(),
                remember_me: $('#RememberMeCheckBox').attr('checked')
            },
            onLoginSuccess
            )})


//...................................................................
//......После успешного входа........................................
//...................................................................
            function onLoginSuccess(result)
            { // Здесь мы получаем данные, отправленные сервером, меняем вид формы
              if (result==1) {
                  $("#loginon").show();
                  $("#loginoff").hide();
//                  $("a.head_login_email").text($('#email').val());
                  $("#user_email").text($('#email').val());
                  
                  $("#mydiv").hide();
                  hidediv();
              }

              else {$("#mydiv").text(result).fadeIn(300);}

            }
    }
);

//...................................................................
//......Hover для меню вверху страницы...............................
//...................................................................
$(function () {
            var klas= $("div.head_menu_block a#selected").attr("class")
           
            var a1= $("div.head_menu_block a")
            
            $("div.head_menu_"+klas).css("background-color","#FFFFCC");
            $(a1).hover(
                  function () {
                      var a1klas = $(this).attr("class")
                      $("div.head_menu_"+a1klas).css("background-color","#FFFFCC");
                  },
                   function () {
                      var a1klas = $(this).attr("class")
                      //условия для подсветки 1) id=selected 2) У следующего элемента стоит id 3) У предыдущего элемента стоит id
                      if (($(this).attr("id") != "selected") & ($(this).prev().attr("id") != "selected") & ($(this).next().attr("id") != "selected")) {
                          $("div.head_menu_"+a1klas).css("background-color","#CDE3FC");
                      }
                      
                  }
                );
                
		});


        
$(document).ready(function(){
    $("#top_nav_jobseeker").click(function () {
        $("#employer_menu").css("display", "none");
        $("#education_menu").css("display", "none");
        if ( $("#jobseeker_menu").css("display") == "none" ) {
            $("#secondary_navigation").css("border-bottom", "1px solid silver");
            if (document.getElementById("top_nav_jobseeker").className != "current") {
                $("#top_nav_jobseeker").css("color", "gray");
            }
            if (document.getElementById("top_nav_employer").className != "current") {
                $("#top_nav_employer").css("color", "#558ED5");
            }
            if (document.getElementById("top_nav_education").className != "current") {
                $("#top_nav_education").css("color", "#558ED5");
            }
        } else {
            $("#secondary_navigation").css("border-bottom", "none");
            if (document.getElementById("top_nav_jobseeker").className != "current") {
                $("#top_nav_jobseeker").css("color", "#558ED5");
            }
        }
        $("#jobseeker_menu").slideToggle("normal");
    });
    $("#top_nav_employer").click(function () {
        $("#jobseeker_menu").css("display", "none");
        $("#education_menu").css("display", "none");
        if ( $("#employer_menu").css("display") == "none" ) {
            $("#secondary_navigation").css("border-bottom", "1px solid silver");
            if (document.getElementById("top_nav_jobseeker").className != "current") {
                $("#top_nav_jobseeker").css("color", "#558ED5");
            }
            if (document.getElementById("top_nav_employer").className != "current") {
                $("#top_nav_employer").css("color", "gray");
            }
            if (document.getElementById("top_nav_education").className != "current") {
                $("#top_nav_education").css("color", "#558ED5");
            }
        } else {
            $("#secondary_navigation").css("border-bottom", "none");
            if (document.getElementById("top_nav_employer").className != "current") {
                $("#top_nav_employer").css("color", "#558ED5");
            }
        }
        $("#employer_menu").slideToggle("normal");
    });
    $("#top_nav_education").click(function () {
        $("#jobseeker_menu").css("display", "none");
        $("#employer_menu").css("display", "none");
        if ( $("#education_menu").css("display") == "none" ) {
            $("#secondary_navigation").css("border-bottom", "1px solid silver");
            if (document.getElementById("top_nav_jobseeker").className != "current") {
                $("#top_nav_jobseeker").css("color", "#558ED5");
            }
            if (document.getElementById("top_nav_employer").className != "current") {
                $("#top_nav_employer").css("color", "#558ED5");
            }
            if (document.getElementById("top_nav_education").className != "current") {
                $("#top_nav_education").css("color", "gray");
            }
        } else {
            $("#secondary_navigation").css("border-bottom", "none");
            if (document.getElementById("top_nav_education").className != "current") {
                $("#top_nav_education").css("color", "#558ED5");
            }
        }
        $("#education_menu").slideToggle("normal");
    });
});

function show_cont_info(type) {
    $('#cont_info').show(200);
    $('#link_cont_info').attr('onClick', '');
    $.getJSON('/includes/functions/ajax_up_show_items_stat.php',{'type':type},function(){return false;});
    return false;
}