// JavaScript函数
//判断域是否为空
function isEmpty(s){
	var whitespace = " \t\n\r";
	var i;
	if((s == null) || (s.length == 0))
		return true;
	for(i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if(whitespace.indexOf(c) == -1)
			return false;
	}
	return true;
}
//使键盘只接受指定的字符集
function charsOnly(field,event,s){
	var key,keychar;
	if(window.event)
		key = window.event.keyCode;
	else if(event)
		key = event.which;
	else
		return true;
	keychar = String.fromCharCode(key);
	if((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27))
		return true;
	else if(s.indexOf(keychar) > -1)
		return true;
	else
		return false;
}
//判断是否为合法的身份证号
function isIdentityCard(s){
	var pattern1 = /^\d{15}$/;
	var pattern2 = /^\d{18}$/;
	return pattern1.test(s) || pattern2.test(s);
}
//判断是否为合法电话号码
function isTelephone(s){
	var pattern = /^\d{4,8}-?\d{1,8}$/;
	return pattern.test(s);
}
//判断是否是合法的邮政编码
function isPostalCode(s){
	var pattern = /^\d{6}$/;
	return pattern.test(s);
}
//判断是否是中文串
function isChinese(s){
	var i;
	for(i = 0;i < s.length; i++){
		var c;
		c = s.charAt(i);
		if(c < 0 )
			c += 65535;
		if(c <= '~' )
			return false;
	}
	return true;
}
//判断是否是合法的Email
function isEmail(s){
	var pattern = /\w+@\w+.\w{1,3}/;
	return pattern.test(s);
}
//判断是否是合法的日期格式（yyyy-mm-dd）
function isDate(s){
	var re = /-/gi;
	if(isNaN(Date.parse(s.replace(re,"/")))){
		return false;
	}
	return true;
}
//改变表格颜色
function changeto(highlightcolor){
	source=event.srcElement;
	if (source.tagName=="TR"||source.tagName=="TABLE")
		return;
	while(source.tagName!="TR")
		source=source.parentElement;
	if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
		source.style.backgroundColor=highlightcolor;
}
function changeback(originalcolor){
	if (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")
		return;
	if (event.toElement!=source)
		source.style.backgroundColor=originalcolor;	
}
//打开窗口,无滚动条
var newWindow = null
function openWindowCenter(loadpos,w,h){ 
	var wx = (window.screen.availWidth - w)/2;
	var wy = (window.screen.availHeight -h)/2;
	var style;
	style = "toolbar=0,resizable=0,scrollbars=0,dependent,width=" + w + ",height=" + h +",left=" + wx + ",top=" + wy
	if (! newWindow || newWindow.closed){
		newWindow = window.open(loadpos,"",style);
	}
	else{
		newWindow.focus();
	}
}
//打开窗口,有滚动条
var newWindow2 = null
function openWindowCenter2(loadpos,w,h){ 
	var wx = (window.screen.availWidth - w)/2;
	var wy = (window.screen.availHeight -h)/2;
	var style;
	style = "toolbar=0,resizable=0,scrollbars=1,dependent,width=" + w + ",height=" + h +",left=" + wx + ",top=" + wy
	if (! newWindow2 || newWindow2.closed){
		newWindow2 = window.open(loadpos,"",style);
	}
	else{
		newWindow2.focus();
	}
}