﻿//---------- 首页简介型模块溢出自动隐藏
$( function() {
	$("div[hide!='']").each( function() {
		$(this).css( { "height" : $(this).attr("hide") + "px" , "overflow" : "hidden" });
	} );
} );

//---------- 图片自动比例
$( function() {
	$(".PicAuto").each( function() {
		var BoxWidth = $(this).attr("width"),BoxHeight = $(this).attr("height");
		var img = new Image(),_this = $(this);
		img.src = $(this).attr("src");
		if ( img.complete ) {
			var RealWidth = img.width,RealHeight = img.height,Padding = 0;
			if ( RealWidth / RealHeight > BoxWidth / BoxHeight ) {
				RealHeight = parseInt( BoxWidth / RealWidth * RealHeight );
				RealWidth = parseInt( BoxWidth );
				Padding = parseInt( ( BoxHeight - RealHeight ) / 2 );
				_this.attr("width",RealWidth).attr("height",RealHeight).css("padding",Padding + "px 0");
			}
			else {
				RealWidth = parseInt( BoxHeight / RealHeight * RealWidth );
				RealHeight = parseInt( BoxHeight );
				Padding = parseInt( ( BoxWidth - RealWidth ) / 2 );
				_this.attr("width",RealWidth).attr("height",RealHeight).css("padding","0 " + Padding + "px");
			}
		}
		img.onload = function() {
			var RealWidth = img.width,RealHeight = img.height,Padding = 0;
			if ( RealWidth / RealHeight > BoxWidth / BoxHeight ) {
				RealHeight = parseInt( BoxWidth / RealWidth * RealHeight );
				RealWidth = parseInt( BoxWidth );
				Padding = parseInt( ( BoxHeight - RealHeight ) / 2 );
				_this.attr("width",RealWidth).attr("height",RealHeight).css("padding",Padding + "px 0");
			}
			else {
				RealWidth = parseInt( BoxHeight / RealHeight * RealWidth );
				RealHeight = parseInt( BoxHeight );
				Padding = parseInt( ( BoxWidth - RealWidth ) / 2 );
				_this.attr("width",RealWidth).attr("height",RealHeight).css("padding","0 " + Padding + "px");
			}
			return;
		};
	} );
} );

//---------- 内页图片自动缩放
$( function() {
	$(".PicLoad").hide().each( function() {
		var img = new Image(),_this = $(this),maxwidth = parseInt( $(this).attr("maxwidth") ),showtime = $(this).attr("showtime");
		img.src = $(this).attr("src");
		if ( /^[0-9]+$/.test(showtime) ) {
			showtime = parseInt(showtime);
		}
		if ( img.complete ) {
			if ( maxwidth > img.width ) {
				maxwidth = img.width;
			}
			$(this).attr("width",maxwidth).show(showtime);
		}
		img.onload = function() {
			if ( maxwidth > this.width ) {
				maxwidth = this.width;
			}
			_this.attr("width",maxwidth).show(showtime);
			return;
		};
	} );
} );
document.writeln("<style type=\"text/css\">")
document.writeln("	<!--")
document.writeln("		.PicLoad { display:none; }")
document.writeln("	-->")
document.writeln("</style>")

//---------- iframe自适应高度
function iframeHeight(Obj) {
	Obj.attr("height",Obj.contents().find("body").height());
}

//---------- 应聘表单验证
$( function() {
	$("#JobForm").submit( function() {
		var MyReturn = true,MyReturnWord = "";
		if ( $("#J_Work").val() == "" ) {
			MyReturnWord += "→ 应聘职位不能为空\n\n";
			MyReturn = MyReturn && false;
		}
		if ( $("#J_Name").val() == "" ) {
			MyReturnWord += "→ 真实姓名不能为空\n\n";
			MyReturn = MyReturn && false;
		}
		if ( $("#J_Birth_year").val() != "" ) {
			if ( !/^[0-9]{4}$/.test($("#J_Birth_year").val()) ) {
				MyReturnWord += "→ 出生日期的年必须是数字\n\n";
				MyReturn = MyReturn && false;
			}
		}
		if ( $("#J_Birth_month").val() != "" ) {
			if ( !/^[0-9]{1,2}$/.test($("#J_Birth_month").val()) ) {
				MyReturnWord += "→ 出生日期的月必须是数字\n\n";
				MyReturn = MyReturn && false;
			}
		}
		if ( $("#J_Birth_day").val() != "" ) {
			if ( !/^[0-9]{1,2}$/.test($("#J_Birth_day").val()) ) {
				MyReturnWord += "→ 出生日期的日必须是数字\n\n";
				MyReturn = MyReturn && false;
			}
		}
		if ( $("#J_Mobile").val() == "" ) {
			MyReturnWord += "→ 移动电话不能为空\n\n";
			MyReturn = MyReturn && false;
		}
		else if ( !/^[0-9\-]+$/.test($("#J_Mobile").val()) ) {
			MyReturnWord += "→ 移动电话格式不正确\n\n";
			MyReturn = MyReturn && false;
		}
		if ( $("#J_Mail").val() != "" ) {
			if ( !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test($("#J_Mail").val()) ) {
				MyReturnWord += "→ 电子邮件格式不正确\n\n";
				MyReturn = MyReturn && false;
			}
		}
		if ( !MyReturn ) {
			alert(MyReturnWord);
			return MyReturn;
		}
	} );
} );

//---------- 在页面载入结束后弹出提示框
function UnderAlert(Word,Url) {
	$( function() {
		alert(Word);
		if ( Url != "" && Url != null ) {
			window.location.href = Url;
		}
	} );
}
