$.include(jextpath + 'org/viewport.js', 750);
$href = location.href.replace(location.protocol+'//'+location.host,'');

function windowLoadingPage(){// 页面加载执行
	var winw = $(window).width();
	var winh = $(window).height();
	
	$('#header-block').height($('#header').outerHeight());
	$('#phone-nav').css({'top':$('#header').outerHeight()});
	
	if(winw<=980){
		$('[header-search-hover] .form').css({'top':$('#header').outerHeight()});
	}else{
		$('[header-search-hover] .form').css({'top':'100%'});
	}
	
}

$(window).off('load,resize').on({
	load: function(){
		windowLoadingPage();
	},
	resize: function(){
		windowLoadingPage();
	}
});

$(window).scroll(function(){

	var wins = $(window).scrollTop();

	/*if($('#ind-news').size()){// 首页
		if(wins>1){
			$('#header').addClass('cur');
		}else{
			$('#header').removeClass('cur');
		}
	}*/
	
	if($('#header').size()){// 头部
		if(wins>1){
			$('#header').addClass('border');
		}else{
			$('#header').removeClass('border');
		}
	}

});

$(window).ready(function(){
	
	/*提交表单*/
	$('[form-feedback]').form({
		url:'/api/web/feedback',
		check: function(c,f){
			this.load = $.alert('loading');
		},
		end: function(d,f){
			this.load.remove(function(){
				if(d.ret){
					$.alert({str:d.msg,time:1500,end:function(){
						window.location.reload();
					}});
				}else{
					$.alert({str:d.msg,btn:1});
				}
			});
		}
	});

	/*提交搜索*/
	$('[header-search-form]').submit(function(){
		
		var action = $(this).attr('action'),// 跳转页面
		Keyword = $(this).find("input[name='Keyword']").val(),// 搜索关键词
		placeholder = $(this).find("input[name='Keyword']").attr('placeholder');// 提示语
	
		if(!Keyword){
			$.alert({str:placeholder,btn:1});
			return false;
		}
		
		window.location.href = '/'+action+'/Keyword-'+Keyword+'/';
		return false;
		
	});
	
	/*提交翻页*/
	$('[data-page]').submit(function(){
		
		var page = $(this).find("input[name='page']").val();
		var url = ($(this).find("input[name='url']").val()||'').replace(/\/page-[0-9]+/i, '');
		
		window.location.href = url+'page-'+page+'/';
		return false;
		
	});

	if($(window).width()<=980){// 没鼠标了
		
		/*搜索*/
		$(document).on('click','[header-search-hover] .icon',function(){
			$(this).siblings('.form').toggle();
		});

	}else{

		/*头部搜索框鼠标移动过去显示、隐藏*/
		$('[header-search-hover]').hover(function(){
			$(this).find('.form').toggle();
		});

	}


	//手机版底部导航
	var wi = $(window).width();
	if(wi<=750){
		$("#footer .one .item .title").click(function(){
			$(this).parent().find(".ites").slideToggle();
			$(this).parent().siblings().children("#footer .one .item .ites").slideUp();
			$(this).toggleClass("on");
			$(this).parent().siblings().find(".title").removeClass("on");
		});
		
		/*$('[footer-tel]').click(function(){
			var tel = $(this).find('span').html().split(" "),
				html = '';
			
			for(var i in tel){
				html += `<a href="tel:${tel[i]}">拨打：${tel[i]}</a><br/>`;
			}
			
			$.alert({
				str:html,
				btn:1,
				init:function(t){
					t.move.remove();
				}
			});
		});*/
	}

})

/*头部产品切换*/
$(document).on('mouseover','[switch-header-products]',function(){
	var ProId = $(this).attr('ProId');
	$.post('/ajax/headerPro',{ProId:ProId},function(data){
		$('[switch-products-point]').html(data);
	});	
});

var alertOption = {// 弹窗

	alertShow:function(ProId){// 显示

		$.post('/ajax/alertProducts',{ProId:ProId},function(data){

			if($('#alertProducts').length){return false;}
			if(data=='false'){$.alert({str:jLang.inside_lang1,btn:1});}

			$('body').append(data);
			
			setTimeout(function(){
				$('#alertProducts').addClass('show');
			},100);
			
		});

	},

	alertShutdown:function(){// 关闭

		$('#alertProducts').removeClass('show');
		setTimeout(function(){
			$('#alertProducts').remove();
		},300);

	},

	/*alertPrev:function(ProId){// 上一页

		if(!ProId){
			$.alert({str:jLang.inside_lang2,time:1000});
			return false;
		}
		alertOption.alertShutdown();
		alertOption.alertShow(ProId);

	},

	alertNext:function(ProId){// 下一页

		if(!ProId){
			$.alert({str:jLang.inside_lang3,time:1000});
			return false;
		}
		alertOption.alertShutdown();
		alertOption.alertShow(ProId);

	},*/

};


// 上传简历
function upfile_jl(files){
	var _this = $(this);
	for(var i in files){
		var f = files[i];
		if (f.data && f.data.ret==1) {
			var job = _this.attr('job');
			var type = _this.attr('type');
			var path = f.data.msg.Path;
			
			$.post('/api/web/recruit',{job:job,type:type,path:path},function(d){
				if(d.ret==1){
					$.alert({
						str:d.msg,
						btn:1,
					});
				}
			},'json');	
		};
	};
}

