function killerrors() {
	return true;
}
window.onerror = killerrors;

$(function() {
	//从头部获取公司名称
	try {
		var topFrames = $(top.frames['topFrame'].document.body);
		var companyName = topFrames.find("#_companyName");
		var h1Html = '<div class="companyName"><div>单位名称：<strong>' + companyName
				.val() + '</strong></div></div>';
		$("h1").prepend(h1Html);
	} catch (error) {
	}
	$(".inputStyleBox input").attr("readonly", "readonly")
	$(".FilletBox")
			.append(
					"<div class='filletLT'></div><div class='filletRT'></div><div class='filletLB'></div><div class='filletRB'></div>");
	$(".popTitle").mouseover(function() {
		$(this).attr("title", $(this).text());
	});
	$(".filletModule")
			.append(
					"<div class='topLeft'></div><div class='topRight'></div><div class='bottomLeft'></div><div class='bottomRight'></div>")
	$(".tablenoborder tr:even").css("background", "#F0F5FB");
})
function Loading() {
	$("body")
			.append(
					"<div id='loading'></div><div class='loading_img'><img src='http://www.mybaoku.com/common/images/global/loadingAnimation.gif' title='http://127.0.0.1:8080/baokubiz/common/images/global/loadingAnimation.gif'/></div>");
	$("body").css( {
		"overflow" : "scroll",
		"overflow-y" : "hidden"
	});
	$("select").hide();
	$("#loading").css("top", document.body.scrollTop)
	$(".loading_img").css("top", document.body.scrollTop + 250)

}
function closePopBg(popDivId) {
	$("#" + popDivId).remove();
	$(".blackBg").hide();
}

$(function() {
	jQuery
			.extend( {
				/**
				 * @author Jacky
				 * @param bathPath
				 * @param key
				 *            资源文件中的key
				 * @param resSimpleName
				 *            资源文件的简称 BookAirResources 取 BookAir
				 * @param values
				 *            参数传递是一个数组 new Object[]={...}
				 * 
				 */
				alertMessageResource : function(bathPath, key, resSimpleName,
						values) {
					if (null == bathPath || bathPath == '<%=bathPath%>') {
						bathPath = (null == getURL() || '' == getURL()) ? document.location.href
								: getURL();
					}
					jQuery.ajax( {
						type : "POST",
						url : bathPath
								+ "/loaclAction.do?method=getMessageResource",
						data : {
							key : key,
							bundle : resSimpleName,
							values : (null == values) ? null : values
						},
						success : function(msg) {
							if (null != msg && "" != msg) {
								alert(msg);
							} else {
								alert("Warning! No" + key + "In "
										+ resSimpleName + "Resources");
							}
						},
						dataType : "text"
					});
				},
				/**
				 * @author Jacky
				 * @param bathPath
				 * @param key
				 *            资源文件中的key
				 * @param resSimpleName
				 *            资源文件的简称 BookAirResources 取 BookAir
				 * @param values
				 *            参数传递是一个数组 new Object[]={...}
				 * @callback 回调方法 点击确定时要做调用方法
				 * 
				 */

				confirmMessageResource : function(bathPath, key, resSimpleName,
						values, callback) {
					if (null == bathPath || bathPath == '<%=bathPath%>') {
						bathPath = (null == getURL() || '' == getURL()) ? document.location.href
								: getURL();
					}
					jQuery.ajax( {
						type : "POST",
						url : bathPath
								+ "/loaclAction.do?method=getMessageResource",
						data : {
							key : key,
							bundle : resSimpleName,
							values : (null == values) ? null : values
						},
						success : function(msg) {
							if (null != msg && "" != msg) {
								if (confirm(msg)) {
									jQuery(callback);
								}
							} else {
								callback = confirm("Warning! No" + key + "In "
										+ resSimpleName + "Resources");
								jQuery(callback);
							}
						},
						dataType : "text"
					});
				}
			});
});

/**
 * 
 * @return {}
 */
function getURL() {
	return location.protocol + "//" + location.host + "/";
	// window.location.pathname.split("/")[1] + "/"
}

/* 弹出显示半透明背景 */
function showblackbg(divid, loading) {
	var bgwidth = $(document).width();
	var bgheight = $(document).height();
	var winW = $(window).width();
	var winH = $(window).height()
	var sL = $(window).scrollLeft();
	var sT = $(window).scrollTop();
	var bathpath = getURL();
	if (divid && typeof divid == "string" && divid != "") {
		var $div = $("#" + divid);
		var thisH = $div.height();
		var thisW = $div.width();
		var left = (winW - thisW) / 2 + sL;
		var top = (winH - thisH) / 2 + sT;
		$div.show().css( {
			left : left,
			top : top,
			"position" : "absolute",
			"z-index" : "500"
		});
	}

	var loadingimg = "<img src='"
			+ bathpath
			+ "company/common/images/page/0504314.gif' style='position:relative;left:-50%;top:-50%;'/>";
	var loadingDiv = $("<div id='loadingDiv'>" + loadingimg + "</div>").css( {
		"position" : "absolute",
		"width" : "89px",
		"height" : "90px",
		"z-index" : "11",
		"left" : winW / 2 + sL,
		"top" : winH / 2 + sT
	});
	if (loading && typeof loading == "string" && loading != "") {
		loadingDiv.appendTo("body")
	}
	;
	var div = $("<div id='blackBg'></div>").css( {
		"background" : "#000",
		"position" : "absolute",
		"width" : bgwidth,
		"height" : bgheight,
		"left" : "0",
		"top" : "0"
	}).fadeTo("fast", 0.55, function() {
		$(this).appendTo("body")
	})

}
function hideblackbg(div, remove) {
	$("#" + div).hide();
	if (remove == "remove") {
		$("#" + div).html("");
	}
	$("#blackBg , #loadingDiv").remove();
	$(".blackbg").remove();
}

/**
 * 设置cookie
 * 
 * @param {}
 *            name
 * @param {}
 *            value
 * @param {}
 *            options
 * @return {}
 */
jQuery.cookie = function(name, value, options) {
	if (typeof value != 'undefined') {
		// name and value given, set cookie
		options = options || {};
		if (value === null) {
			value = '';
			// clone object since it's
			options = $.extend( {}, options);
			options.expires = -1;
		}
		var expires = '';
		if (options.expires
				&& (typeof options.expires == 'number' || options.expires.toUTCString)) {
			var date;
			if (typeof options.expires == 'number') {
				date = new Date();
				date.setTime(date.getTime()
						+ (options.expires * 24 * 60 * 60 * 1000));
			} else {
				date = options.expires;
			}
			expires = '; expires=' + date.toUTCString();
		}
		var path = options.path ? '; path=' + (options.path) : '';
		var domain = options.domain ? '; domain=' + (options.domain) : '';
		var secure = options.secure ? '; secure' : '';
		document.cookie = [ name, '=', encodeURIComponent(value), expires,
				path, domain, secure ].join('');
	} else {
		var cookieValue = null;
		if (document.cookie && document.cookie != '') {
			var cookies = document.cookie.split(';');
			for ( var i = 0; i < cookies.length; i++) {
				var cookie = jQuery.trim(cookies[i]);
				// Does this cookie string begin with the name we want?
				if (cookie.substring(0, name.length + 1) == (name + '=')) {
					cookieValue = decodeURIComponent(cookie
							.substring(name.length + 1));
					break;
				}
			}
		}
		return cookieValue;
	}
};

/*
 * 日期格式化
 * */function getNowFormatDate(next) {
	var day = new Date();
	var Year = 0;
	var Month = 0;
	var Day = 0;
	var CurrentDate = "";
	// 初始化时间
	// Year= day.getYear();//有火狐下2008年显示108的bug
	Year = day.getFullYear();// IE火狐下都可以
	Month = day.getMonth() + 1;
	Day = day.getDate();
	// Hour = day.getHours();
	// Minute = day.getMinutes();
	// Second = day.getSeconds();
	CurrentDate += Year + "-";
	if (Month >= 10) {
		CurrentDate += Month + "-";
	} else {
		CurrentDate += "0" + Month + "-";
	}

	if (Day > 9) {
		if (next == "next") {
			var d = new Date(new Date().getTime() + 1000 * 60 * 60 * 24);
			CurrentDate = d.getFullYear() + "-" + (d.getMonth() + 1) + "-"
					+ d.getDate();
		} else {
			CurrentDate += Day;

		}
	} else {
		if (next == "next") {
			var d = new Date(new Date().getTime() + 1000 * 60 * 60 * 24);
			CurrentDate = d.getFullYear() + "-" + (d.getMonth() + 1) + "-"
					+ d.getDate();
		} else {
			CurrentDate += "0" + Day;
		}
	}

	return CurrentDate;
}
 /*格式化日期
 	formatDate(number)  number为数字时反回当前系统日期+number天，如果为负数则减number天，如果为0则返回今天
 	formatDate(string)  string格式为2010-2-2或2010-02-05，反回string参数的下一天
 */
function formatDate(n) {
	if (typeof (n) == "number") {
		var uom = new Date();
		uom.setDate(uom.getDate() + n);
		var y = uom.getFullYear();
		var m = (uom.getMonth() + 1);
		var d = uom.getDate();
		m = m > 9 ? m : '0' + m;
		d = d > 9 ? d : '0' + d;
		uom = y + "-" + m + "-" + d;
	}
	if (typeof (n) == "string") {
		var chs = new Array();
		chs = n.split("-");
		var years = new Date(chs[0], chs[1] - 1, chs[2]);
		var strTimes = new Date(years - 0 + 1 * 86400000);
		var y = strTimes.getFullYear();
		var m = (strTimes.getMonth() + 1);
		var d = strTimes.getDate();
		m = m > 9 ? m : '0' + m;
		d = d > 9 ? d : '0' + d;
		uom = y + "-" + m + "-" + d;
	}
	return uom;
}

/*输入验证
 * 常振东
 * 2010-11-30
 * 调用方法<input disabled="disabled" type="text" id='userNameToEdit' onkeypress="TextValidate()" />
 */
function TextValidate(type) {
	var code;
	var character;
	var err_msg = "不可输入特殊字符";
	if (document.all) //判断是否是IE浏览器
	{
		code = window.event.keyCode;
	} else {
		code = arguments.callee.caller.arguments[0].which;
	}
	var character = String.fromCharCode(code);

	var txt = new RegExp(
			"[ ,\\`,\\~,\\!,\\@,\#,\\$,\\%,\\^,\\+,\\*,\\&,\\\\,\\/,\\?,\\|,\\:,\\.,\\<,\\>,\\{,\\},\\(,\\),\\',\\;,\\=,\"]");
	//特殊字符正则表达式
	if (txt.test(character)) {
		if (document.all) {
			window.event.returnValue = false;
		} else {
			arguments.callee.caller.arguments[0].preventDefault();
		}
	}
}

/*半透明背景
 * $(obj).transition();
 *  $(obj).transition("loading");
 */
$.fn.transition = function(load) {
	var $this = $(this);
	var thisW = $this.width();
	var thisH = $this.height();
	var win = $(window);
	var bathpath = getURL(); //获取路径
	var winW;//当前对象的宽度
	var winH;//当前对象的高度
	var sL;//滚动条左侧距离
	var sT;//滚动条上面距离
	var imgL;//loading图片左侧距离
	var imgT;//loading图片右侧距离
	var thisL;//当前对象左侧距离
	var thisT;//当前对象右侧距离
	if (load && typeof load == "string") {
		var loadImg = $(
				"<img src='"
						+ getURL()
						+ "company/common/images/page/0504314.gif' id='loadingDiv'/>")
				.css( {
					position : "absolute",
					width : "100px",
					height : "100px",
					"z-index" : "10000"
				});
		loadImg.appendTo("body");
	}
	var divBg = $("<div />", {
		id : "blackBg",
		css : {
			background : "#000",
			position : "absolute",
			"z-index" : "10"
		}
	}).addClass("blackbg");
	position();
	divMove();
	$this.css( {
			left : thisL,
			top : thisT
		});
	$(window).resize(function() {
		position();
		divMove();
	})
	win.scroll(function() {
		position();
		divMove();
	})
	if ($("#blackBg").length < 1) {
		divBg.fadeTo("fast", 0.35, function() {
			$(this).appendTo("body");
		})
	}
	$this.css( {
		position : "absolute",
		"z-index" : "1000"
	}).show();
	//div位置计算
	function position() {
		winW = win.width();
		winH = win.height();
		sL = win.scrollLeft();
		sT = win.scrollTop();
		imgL = winW / 2 + sL - 50;
		imgT = winH / 2 + sT - 50;
		thisL = (winW - thisW) / 2 + sL;
		thisT = (winH - thisH) / 2 + sT;
	}
	//移动DIV
	function divMove() {
		if (loadImg) {
			loadImg.css( {
				left : imgL,
				top : imgT
			});
		}
		divBg.css( {
			left : sL,
			top : sT,
			width : winW,
			height : winH
		}).bgiframe();
		
	}
	return this;
}
//IE6背景
$.fn.bgiframe = function(s) {
	if ($.browser.msie && /6.0/.test(navigator.userAgent)) {
		s = $.extend( {
			top : 'auto',
			left : 'auto',
			width : 'auto',
			height : 'auto',
			opacity : true,
			src : 'javascript:false;'
		}, s || {});
		var prop = function(n) {
			return n && n.constructor == Number ? n + 'px' : n;
		}, html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'
				+ s.src
				+ '"'
				+ 'style="display:block;position:absolute;z-index:-1;'
				+ (s.opacity !== false ? 'filter:Alpha(Opacity=\'0\');' : '')
				+ 'top:'
				+ (s.top == 'auto' ? 'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')'
						: prop(s.top))
				+ ';'
				+ 'left:'
				+ (s.left == 'auto' ? 'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')'
						: prop(s.left))
				+ ';'
				+ 'width:'
				+ (s.width == 'auto' ? 'expression(this.parentNode.offsetWidth+\'px\')'
						: prop(s.width))
				+ ';'
				+ 'height:'
				+ (s.height == 'auto' ? 'expression(this.parentNode.offsetHeight+\'px\')'
						: prop(s.height)) + ';' + '"/>';
		return this.each(function() {
			if ($('> iframe.bgiframe', this).length == 0)
				this
						.insertBefore(document.createElement(html),
								this.firstChild);
		});
	}
	return this;
};
// 验证是否为数字方法－－－－－－－－－－－－－－－－－－
function checknumber(String) {
	var Letters = "1234567890.";
	var i;
	var c;
	for (i = 0; i < String.length; i++) {
		c = String.charAt(i);
		if (Letters.indexOf(c) == -1) {
			return true;
		}
	}
	return false;
}

//input 默认值 
/*input 默认值
 $().defaultVal(text);
 */
$.fn.defaultVal = function(text) {
	$(this).each(function() {
		var $this = $(this);
		var offset = $this.offset();
		var win = $(window);
		var left;
		var top;
		position();
		win.resize(function() {
			position();
			defaul.css( {
				left : left,
				top : top
			})
		})
		var defaul = $("<span/>").css( {
			position : "absolute",
			left : left,
			top : top,
			"font-size" : "12px",
			"color" : "#9D9D9D",
			"z-index" : "10000",
			"padding-left" : "10px",
			"line-height" : "25px"
		}).text(text);
		if($this.val()==""){
			appendSpan();
		};
		$this.focus(function() {
			defaul.remove();
		}).blur(function() {
			if ($this.val() == "") {
				appendSpan();
				defaul.click(function() {
					$(this).remove();
					$this.focus();
				})
			}
		})
		defaul.click(function() {
			$(this).remove();
			$this.focus();
		})
		function position() {
			left = $this.offset().left;
			top = $this.offset().top;
		}
		function appendSpan(){
			defaul.appendTo("body");
		}

	})

}
/**
 * 格式化数字
 * @param {Object} str1 格式化类型
 * @param {Object} str2 数值
 * @return {TypeName} 
 */
function NumberFormate(str1,str2){
			var num=str2;
			//1保留一位小数 2保留两位小数 3四舍五入 4进十位 5 舍小数
			if(str1=='1'){
				num=Math.round(str2*10)/10;
			}else if(str1=='2'){
				num=Math.round(str2*100)/100;
			}else if(str1=='3'){
				num=Math.round(str2);
			}else if(str1=='4'){
				num=Math.round(str2/10)*10;
			}else if(str1=='5'){
				num=str2.substring(0, str2.indexOf('.'));
			}
			return num
}

