﻿// ph导航

$("#menuph").click(function(e){
    e.stopPropagation();

    $(this).find(".point").toggleClass("active");

    $(".xialaph").slideToggle();

    $(".phonemeng").toggleClass('active');

    $("body,html").animate({

        scrollTop:0

    },500);

});

// ph导航二级

$(".xialaph  h4").click(function(){

    $(this).siblings(".ul2").slideToggle();

    $(this).parent().parent().siblings().find(".ul2").slideUp();

    $(this).toggleClass("active");

    $(this).parent().parent().siblings().find("h4,h5").removeClass('active');

});

/*ph导航三级*/

$(".xialaph h5").click(function(){

    $(this).siblings(".ul3").slideToggle();

    $(this).parent().siblings().find(".ul3").slideUp();

    $(this).toggleClass("active");

    $(this).parent().siblings().find("h4,h5").removeClass('active');

});



// 导航吸顶

$(window).on('scroll', function () {

    if ($(window).scrollTop() > 0) {

        $(".g_syhead").stop().addClass('act');

    } else {

        $(".g_syhead").stop().removeClass('act');

    }

  });

  // pc导航下拉

$('.he_navnli').hover(function(){

    $(this).find('.he_naverul').stop().slideDown();

  }, function(){

    $(this).find('.he_naverul').stop().slideUp();

  })



  var Modal = {

    $html: $("html"),

    $body: $(document.body),

    originalBodyPad: null,

    scrollbarWidth: 0,

    show: function () {

        this.checkScrollbar()

        this.setScrollbar()

        this.$html.addClass('modal-open')

    },

    hide: function () {

        this.$html.removeClass('modal-open')

        this.resetScrollbar();

    },

    checkScrollbar: function () {

        var fullWindowWidth = window.innerWidth

        if (!fullWindowWidth) { // workaround for missing window.innerWidth in IE8

            var documentElementRect = document.documentElement.getBoundingClientRect();

            fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left);

        }

        this.bodyIsOverflowing = document.body.clientWidth < fullWindowWidth;

        this.scrollbarWidth = this.measureScrollbar();

    },

    setScrollbar: function () {

        var bodyPad = parseInt((this.$body.css('padding-right') || 0), 10)

        this.originalBodyPad = document.body.style.paddingRight || ''

        if (this.bodyIsOverflowing) this.$body.css('padding-right', bodyPad + this.scrollbarWidth)

    },

    measureScrollbar: function () {

        var scrollDiv = document.createElement('div');

        scrollDiv.className = 'modal-scrollbar-measure';

        this.$body.append(scrollDiv);

        var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;

        this.$body[0].removeChild(scrollDiv);

        return scrollbarWidth;

    },

    resetScrollbar: function () {

        this.$body.css('padding-right', this.originalBodyPad);

    }

}



$('.he_navnlsr').click(function(){

    $('.mengcen').fadeIn();

    Modal.show();

})

$('.guanbi').click(function(){

    $('.mengcen').fadeOut();

    Modal.hide();

})



  // 回到顶部

  $('.he_banfto').click(function () {

    $("html,body").animate({

        scrollTop: 0

    }, 1000);

});
$('.he_xinjtp').click(function () {

    $("html,body").animate({

        scrollTop: 0

    }, 1000);

});



$(function(){

    $('.he_fobet').click(function(){

        $(this).parents('.he_tij').fadeOut();

    })

})

$(function(){

    $('.he_bangb').click(function(){

        $(this).parents('.he_banfr').fadeOut();

    })

})

$(function(){

    $('.he_syp4bg').click(function(){

        $(this).parents('.he_foph').find('.he_fophtfo').fadeOut();

        Modal.hide();

        $('.he_xinjtp').fadeIn();


    })

})

$(function(){

    $('.he_foph .he_fobet').click(function(){

        $(this).parents('.he_foph').find('.he_fophtfo').fadeOut();

        Modal.hide();

    })

})



$(function(){

    $('.he_fophte').click(function(){

        $(this).siblings('.he_fophtfo').fadeIn();

        Modal.show();

        $('.he_xinjtp').fadeOut();

    })

})
/*
验证码倒计时
 */
var wait=60;
function time(classa) {
    if (wait == 0) {
        $('#'+classa).attr("disabled",false);
        $('#'+classa).text("get verification code");
        wait = 60;
    } else {
        $('#'+classa).attr("disabled", true);
        $('#'+classa).text("Resend(" + wait + ")");
        wait--;
        setTimeout(function() {
                time(classa)
            },
            1000)
    }
}
function get_code(formid,classa){
    var form = $('#'+formid);
    if(!form.find("input[name='phone']").val()){
        layer.alert('Please enter the phone number', {

                                'title':'Message',

                                'btn':['OK']

                            });
        return false;
    }
    // if(!/^1[\d]{10}$/.test(form.find("input[name='phone']").val())){
    //     layer.alert('手机号码格式错误');
    //     return false;
    // }
    time(classa);
    $.ajax({
        type:"POST",
        data:{'phone':form.find("input[name='phone']").val()},
        url:"/Cn/Index/get_code",
        success:function(data){
            if(data.code == 1){
                layer.alert('The SMS verification code has been sent, please check it', {

                                'title':'Message',

                                'btn':['OK']

                            });
                return false;
            }else{
                alert(data.msg);
            }
            
        }
    })
}

function injectChk(oField){

        re= /select|update|delete|exec|count|'|"|=|;|>|<|%/i;

        if ( re.test(oField) ){

            return false;

        }else{

            return true;

        }

    }

    checkForm={

        changeVerifyImg:function(obj){

            $(obj).attr("src","/Cn/Index/getVerifyImg?sid="+Math.random());

        },

        isEmpty:function(form,name,field){

            if(!$("#"+form).find('input[name="'+name+'"]').val()|| injectChk($("#"+form).find('input[name="'+name+'"]').val()) == false){

                layerHandel=layer.alert(

                        field+"Can not be empty！",

                        {

                            'title':'Message',

                            'btn':['OK']

                        },function(){

                            layer.close(layerHandel);

                            $('input[name="'+name+'"]').focus();

                        }

                );

                return true;

            }else{

                return false;

            }

        },

        notEmail:function(form,name,field){

            if(!/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/.test($("#"+form).find('input[name="'+name+'"]').val())){

                layerHandel=layer.alert(

                        field+"Incorrect format！",

                        {

                            'title':'Message',

                            'btn':['OK']

                        },function(){

                            layer.close(layerHandel);

                            $('input[name="'+name+'"]').focus();

                        }

                );

                return true;

            }else{

                return false;

            }

        },

        notPhone:function(form,name,field){

            if(!/^1[\d]{10}$/.test($("#"+form).find('input[name="'+name+'"]').val())){

                layerHandel=layer.alert(

                        field+"Incorrect format！",

                        {

                            'title':'Message',

                            'btn':['OK']

                        },function(){

                            layer.close(layerHandel);

                            $('input[name="'+name+'"]').focus();

                        }

                );

                return true;

            }else{

                return false;

            }

        }

    };

    function submitForm(formId){

        // alert(formId);

        if(checkForm.isEmpty(formId,"company"," Company Name ")){

            return false;

        }

        if(checkForm.isEmpty(formId,"name"," Name ")){

            return false;

        }
        if(checkForm.isEmpty(formId,"phone"," Phone ")){

            return false;

        }
        // if(checkForm.notPhone(formId,"phone","手机号码")){

        //     return false;

        // }

        if(checkForm.isEmpty(formId,"phone_code"," SMS verification code ")){

            return false;

        }

        if(checkForm.isEmpty(formId,"verify_code"," Captcha ")){

            return false;

        }
        $.ajax({

            url:"/En/Index/formView",

            data:$("#"+formId).serialize(),

            dataType:"json",

            type:"POST",

            success:function(data){

                

                

                if(data.status=="success"){
                   
                //     layer.alert(

                //         data.info,

                //         {

                //             'title':'消息',

                //             'btn':['好的']

                //         }

                // );
                    $(".he_tij").fadeIn();

                    setTimeout('location.reload(true)',2000);

                }else if(data.status=="error_img"){
                    checkForm.changeVerifyImg($("#"+formId+" img[name='verifyImg']"));
                    layer.alert(

                            data.info,

                            {

                                'title':'Message',

                                'btn':['OK']

                            }

                    );
                }else{

                     layer.alert(

                        data.info,

                        {

                            'title':'Message',

                            'btn':['OK']

                        }

                );

                }

            },

            error:function(data){

                layer.open({

                    title:"调试模式",

                    content:data.responseText

                })

            }

        });

    }

//获取城市

function get_shi(id){

    $("input[name='sheng']").val(id);

    $.ajax({

        type:"POST",

        data:{'id':id},

        url:"/En/Index/get_shi",

        success:function(data){

            if(data.length > 0){

                var str = '';
                str += '<div class="he_f1bxsc shi_list mCustomScrollbar _mCS_2 mCS_no_scrollbar">';
                $.each(data,function(i,v){

                    str += '<p class="he_lick" onclick="set_shi('+v.id+')">'+v.name+'</p>';

                })

                str += '</div>';
                $('.shi_list .mCSB_container').empty();

                $('.shi_list .mCSB_container').append(str);
                $('.he_lick').click(function () {
                    $(this).parent('.am_f1_cselcitbot').stop().slideToggle();
                
                    var textb = $(this).text();
                    console.log(textb)
                
                    $(this).parents('.am_f1_cselcitem').find('.am_f1_cselcittop').find('p').text(textb);
                    $(this).parents('.am_f1_cselcitem').find('.am_f1_cselcittop').find('p').val(con);
                    $(this).parent().siblings('.am_f1_cselcittop').toggleClass('on')
                
                })
            }

        }

    })

}
$('.he_lick').click(function () {
    $(this).parent('.am_f1_cselcitbot').stop().slideToggle();

    var textb = $(this).text();
    console.log(textb)

    $(this).parents('.am_f1_cselcitem').find('.am_f1_cselcittop').find('p').text(textb);
    $(this).parents('.am_f1_cselcitem').find('.am_f1_cselcittop').find('p').val(con);
    $(this).parent().siblings('.am_f1_cselcittop').toggleClass('on')

})

function set_shi(id){

    $("input[name='shi']").val(id);

}

function set_job_name(id){

    $("input[name='job_name']").val(id);

}

function set_job_type(id){

    $("input[name='job_type']").val(id);

}

function set_job_cate(id){

    $("input[name='job_category']").val(id);

}

function yxtop() {
        var test = (window.location.href).split('tp=');
        if (!isNaN(test[1])) {
            $("html,body").animate({
                scrollTop: $('[yxdatop-pag="' + test[1] + '"]').offset().top - 90
            }, 700);
        }
};

$('.he_bangb').click(function(e){
    e.stopPropagation();
    $(this).parents('.he_fophte').fadeOut();
})

$('body').click(function(){
    $('.xialaph').stop().slideUp();
    $('.point').removeClass('active');
})
$('.phxia').click(function(e){
    e.stopPropagation();
})
