/*
Author:Andyfoo
Email:andyfoo@163.com
Company:huacai.cn
*/


var donateurl = '/donate';
var cmsurl = '/cn';

var bbsurl = '/bbs/cn';

//取频道图片
function get_channel_banner(name){
	if(!name)name='慈善新闻';
	try{
		var str = document.location.href;
		if(str.indexOf('show.php') > 1 || str.indexOf('list.php') > 1){
			name='慈善新闻';
		}
	}catch(e){}
	name = encodeURI(name);
	var url = cmsurl + "/hc/api/index.php?mod=banner&channel="+name;
	load_script(url);
}
function set_channel_banner(str){
	if(str && str.length > 0)getID("channel_banner_box").innerHTML = str;
}

//跳转到帮助中心
function go_help(txt){
	txt = encodeURI(txt);
	window.open(cmsurl + "/jump.php?titletype=help&titletext=" + txt);
}
//跳转到项目介绍
function go_project_info(txt){
	txt = encodeURI(txt);
	window.open(cmsurl + "/jump.php?titletype=project_info&titletext=" + txt);
}
//跳转到捐助页面
function go_donate(id, name, id_str){
	var url = "";
	if(id){
		url = donateurl + '/donate.do?id='+id;
	}
	if(name){
		name = encodeURI(name);
		url = donateurl + '/donate.do?name='+name;
	}
	if(id_str){
		url = donateurl + '/donate.do?'+id_str;
	}
	if(url){
		x_open("在线捐助", url, 600,500,'center','middle');
	}
	
}

var x_confirm_msg = "";
var x_confirm_url = "";
function x_confirm(title, msg, url, w, h){
	if(!w)var w=360;
	if(!h)var h=240;
	x_open(title, "/confirm_small.html", w, h, "center","middle");
	x_confirm_msg = msg;
	x_confirm_url = url;
}

function reload_main_frame(url) {
	try {
		if(url){
			window.main_frame.location.href=url;
		}else{
			window.main_frame.location.href=window.main_frame.location.href;
		}
	} catch(e) {
	 
	}
	try {
		x_open_close();
	} catch(e) {
	}

}
function reload_window(url) {
	try {
		if(url){
			window.location.href=url;
		}else{
			window.location.href=window.location.href;
		}
	} catch(e) {
	 
	}
}

var Browser = {
	IE:     !!(window.attachEvent && !window.opera),
	Opera:  !!window.opera,
	WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
	Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1
}
function killErrors() {
	return true;
}
//window.onerror = killErrors;

//解决IE6下默认不缓存背景图片
try {

  document.execCommand('BackgroundImageCache', false, true);

} catch(e) {}
//取get变量的值 sProp 为要取的变量名称 var info = getParameter("info");
function getParameter( sProp ) {
	try {
		var str = document.location.search;
		str = unescape(str);
		var re = new RegExp( sProp + "=([^\&]*)", "i" );
		var a = re.exec( str );
		if ( a == null )
			return "";
		return a[1];
	} catch(e) {
		return "";
	}
};
//加入收藏夹
function addFavorite(title, url){
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
}

//x_alert("您要弹出的信息");
function x_alert(str){
	var msgw, msgh, titleHeight, borderColor, titleColor;
	msgw = 320; //提示窗口的宽度
	msgh = 120; //提示窗口的高度
	titleHeight = 20;  //提示窗口标题高度
	borderColor = "#000000"; //提示窗口的边框颜色
	titleColor = "#8B0F00"; //提示窗口的标题颜色

	var sWidth, sHeight;
	sWidth = document.body.offsetWidth;
	sHeight = document.body.offsetHeight;
	if (sHeight < screen.height){
		sHeight = screen.height;
	}

	var bgObj = document.createElement("div");
	bgObj.setAttribute('id', 'xAlertBgDiv');
	bgObj.style.position = "absolute";
	bgObj.style.top = "0";
	bgObj.style.left = "0";
	bgObj.style.background = "#000000";
	bgObj.style.filter = "Alpha(Opacity=30);";
	bgObj.style.opacity = "0.3";
	bgObj.style.width = sWidth + "px";
	bgObj.style.height = sHeight + "px";
	bgObj.style.zIndex = "10000";
	document.body.appendChild(bgObj);

	var msgObj = document.createElement("div");
	msgObj.setAttribute("id", "xAlertMsgDiv");
	msgObj.setAttribute("align", "center");
	msgObj.style.background = "white";
	msgObj.style.border = "1px solid " + borderColor;
	msgObj.style.position = "absolute";
	msgObj.style.left = "50%";
	msgObj.style.top = "50%";
	msgObj.style.font = "12px 宋体, Arial";
	msgObj.style.marginLeft = "-225px";
	msgObj.style.marginTop =  - 75+document.documentElement.scrollTop + "px";
	msgObj.style.width = msgw + "px";
	msgObj.style.height = msgh + "px";
	msgObj.style.textAlign = "center";
	msgObj.style.lineHeight = (msgh - titleHeight) + "px";
	msgObj.style.zIndex = "10001";

	var title = document.createElement("h4");
	title.setAttribute("id", "xAlertTitleDiv");
	title.setAttribute("align", "left");
	title.style.margin = "0";
	title.style.padding = "3px";
	title.style.background = titleColor;
	title.style.filter = "Alpha(Opacity=75);";
	title.style.opacity = "0.75";
	title.style.borderBottom = "1px solid " + borderColor;
	title.style.height = titleHeight + "px";
	
	title.style.font = "12px 宋体, Arial";
	title.style.color = "white";
	title.innerHTML = "<div style='float:left;line-height:" + titleHeight + "px'>提示信息</div>";

	var closeBtn = document.createElement("a");
	closeBtn.setAttribute("id", "xAlertCloseBtnDiv");
	closeBtn.style.cssFloat = "right";
	closeBtn.style.styleFloat = "right";
	closeBtn.style.display = "block";
	closeBtn.style.font = "12px 宋体, Arial";
	closeBtn.style.color = "white";
	closeBtn.style.cursor = "pointer";
	closeBtn.style.lineHeight = titleHeight + "px";
	closeBtn.innerHTML = "关闭";
	closeBtn.onclick = function(){
		document.body.removeChild(bgObj);
		document.getElementById("xAlertTitleDiv").removeChild(closeBtn);
		document.getElementById("xAlertMsgDiv").removeChild(title);
		document.body.removeChild(msgObj);
	}

	document.body.appendChild(msgObj);


	document.getElementById("xAlertMsgDiv").appendChild(title);
	document.getElementById("xAlertTitleDiv").appendChild(closeBtn);
	var txt = document.createElement("p");
	txt.style.margin = "1em 0";
	txt.setAttribute("id", "xAlertTxtDiv");
	txt.innerHTML = str;
	document.getElementById("xAlertMsgDiv").appendChild(txt);
}


//日历
var calendar_open = false;
function showCalendar(id, f){
	if(window.self.cPop)cPop.XCalendar(getID(id));
	return true;
}
function calendar(calendar_path){
	if(!calendar_open){
		if(!calendar_path)var calendar_path = "calendar/";
		document.write("<iframe width=172 height=168 name='gToday:normal' id='gToday:normal' ");
		document.write(" src='" + calendar_path + "calendar.htm' scrolling='no' frameborder='0' ");
		document.write(" style='visibility:visible; z-index:999; position:absolute; top:-500px; left:-500px;'>");
		document.write("</iframe>");
	}
	calendar_open=true;
}


function copyText(obj) {
	ie = (document.all)? true:false;
	try{
		if(typeof(obj) == "string")var obj = getID(obj);
	}catch(e){}
	if (ie){
		var rng = document.body.createTextRange();
		rng.moveToElementText(obj);
		rng.scrollIntoView();
		rng.select();
		rng.execCommand("Copy");
		rng.execCommand("Unselect");
		rng.collapse(false);
		return true;
	}else{
		try{prompt("请复制以下内容:",obj.innerHTML); }catch(e){}
	}
	return false;
}
function disabled_menu(){
	var e = window.event;
	try{
		if(e.srcElement.type == 'text' || e.srcElement.type == 'textarea' || e.srcElement.type == 'password')
			window.event.returnValue=true;
		else 
			window.event.returnValue=false;
	}catch(e){}
	//return false;
}
function disabled_select(){ 
	var e = window.event;
	try{
		if(e.srcElement.type == 'text' || e.srcElement.type == 'textarea' || e.srcElement.type == 'password')
			window.event.returnValue=true;
		else 
			window.event.returnValue=false;
	}catch(e){}
	//return false;
} 


var document_domain = "";
try{
	document_domain = document.domain;
}catch(e){}
if(document_domain != "localhost"){
	//window.onerror = killErrors;
	//document.oncontextmenu = disabled_menu;
	//document.onselectstart = disabled_select;
}

//显示与隐藏帐户信息
function show_money(obj, t){
	var check = '';
	if(t == 'txt'){
		check = showhide_obj('div_account');
		check = check == 'hide' ? 'show' : 'hide';
		showhide_obj('div_cash');
		showhide_obj('div_handsel');
		showhide_obj('div_integral');		

		showhide_obj('div_account_hide');
		showhide_obj('div_cash_hide');
		showhide_obj('div_handsel_hide');
		showhide_obj('div_integral_hide');	

		
		if(check == 'hide'){
			obj.innerHTML = "隐藏";
		}else{
			obj.innerHTML = "显示";
		}

	}

}
function set_money(v){
	getID("div_account").innerHTML = v;
}
function show_money2(obj){
	var check = '';

	check = showhide_obj('div_account');
	check = check == 'hide' ? 'show' : 'hide';
	

	
	if(check == 'hide'){
		hide_obj('div_account_hide');
		obj.src = "images/checkbox_s.gif";
	}else{
		show_obj('div_account_hide');
		obj.src = "images/checkbox.gif";
	}


}

function input_onfocus(obj, c) {
	if(!c)var c = 'input_focus';
	obj.className = c;
}
function input_onblur(obj, c) {
	if(!c)var c = 'input';
	obj.className = c;
}
function textarea_onfocus(obj, c) {
	if(!c)var c = 'textarea_focus';
	obj.className = c;
}
function textarea_onblur(obj, c) {
	if(!c)var c = 'textarea_onblur';
	obj.className = c;
}

//保持会员登录状态
var keepLoginStatusTime = 300 * 1000;
function keepLoginStatus(){
	var url = "/keepLoginStatus.do?_t=" + new Date().getTime();
	load_script(url);
	window.setTimeout('keepLoginStatus()', keepLoginStatusTime);
}

function closeBrowser(){
	/*
	try{
		window.opener=null;
		window.close();
	}catch(e){
		window.opener=null;
		top.window.close();
	}
	*/
}


//改变列表颜色
function init_list_event(e){
	try{
		try{
			e = xalt_fixE(e);
			obj = e.srcElement.parentElement;

			obj.onmouseout = function (){
				this.className='list_item_out';
			}
			obj.onmouseover = function (){
				this.className='list_item_over';
				return;
			}
			this.className='list_item_over';
		}catch(e){}
	}catch(e){}
}
function get_width(obj){
	if(typeof(obj.offsetWidth) != "undefined" ){
		return parseInt(obj.offsetWidth, 10);
	}
	if(typeof(obj.style.width) != "undefined" ){
		return parseInt(obj.style.width, 10);
	}
	return 0;
}
function get_height(obj){
	if(typeof(obj.offsetHeight) != "undefined" ){
		return parseInt(obj.offsetHeight, 10);
	}
	if(typeof(obj.style.height) != "undefined" ){
		return parseInt(obj.style.height, 10);
	}
	return 0;
}

function get_page_width(){
	return document.body.clientWidth ? document.body.clientWidth  : get_scroll_left() + get_body_width(); 
}
function get_page_height(){
	return document.body.clientHeight ? document.body.clientHeight : get_scroll_top() + get_body_height();
}
function get_scroll_top(){
	var s; 
	if (typeof(window.pageYOffset) != 'undefined') { 
		s = window.pageYOffset; 
	} 
	else if (typeof(document.compatMode) != 'undefined' &&document.documentElement.scrollTop > 0) { 
		s = document.documentElement.scrollTop; 
	}  
	else if (typeof(document.body) != 'undefined') { 
		s = document.body.scrollTop; 
	} 
	
	return parseInt(s, 10);
}
function get_scroll_left(){
	var s; 
	if (typeof(window.pageXOffset) != 'undefined') { 
		s = window.pageXOffset; 
	} 
	else if (typeof(document.compatMode) != 'undefined' &&document.documentElement.scrollLeft > 0) { 
		s = document.documentElement.scrollTop; 
	}
	else if (typeof(document.body) != 'undefined') { 
		s = document.body.scrollLeft; 
	} 
	return parseInt(s, 10);
}
function get_body_width(){ 
	if (typeof(document.documentElement.clientWidth) != "undefined") {
		return parseInt(document.documentElement.clientWidth);
	}
	return parseInt(document.body.clientWidth, 10);
}
function get_body_height(){
	if (typeof(document.documentElement.clientHeight) != "undefined") {
		return parseInt(document.documentElement.clientHeight);
	}
	return parseInt(document.body.clientHeight, 10);
}

function get_left(obj) {
	return (obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft + get_left(obj.offsetParent));
}

function get_top(obj) {
	return (obj.offsetParent==null ? obj.offsetTop : obj.offsetTop + get_top(obj.offsetParent));
}
//转换为整数
function toInt(str){
	var result = parseInt(str);
	return isNaN(result) ? 0 : result;
}

//取unix时间戳
function get_timestamp(){
	var d = new Date();
	return Math.round(d.getTime()/1000);
}
//格式化时间, t=时间戳
function get_date(type, t){
	if(t){ 
		var o = new Date(parseInt(t) * 1000); 
	}else{
		var o = new Date();
	}
	var dd = new Array();
	dd['y'] = o.getYear();
	dd['Y'] = o.getFullYear();
	dd['n'] = (parseInt(o.getMonth())+1);
	dd['m'] = strPad(dd['n'], 2);
	dd['j'] = o.getDate();
	dd['d'] = strPad(dd['j'], 2);
	
	dd['g'] = o.getHours();//小时，12 小时格式，没有前导零 1 到 12 
	if(dd['g']>12)dd['g'] = dd['g'] - 12;
	dd['G'] = o.getHours() ;//小时，24 小时格式，没有前导零 0 到 23 
	dd['h'] = strPad(dd['g'], 2);//小时，12 小时格式，有前导零 01 到 12 
	dd['H'] = strPad(dd['G'], 2);//小时，24 小时格式，有前导零 00 到 23 

	dd['i'] = strPad(o.getMinutes(), 2);
	dd['s'] = strPad(o.getSeconds(), 2);
	
	
	var date = dd['Y'] + '-' + dd['m'] + '-' + dd['d'];
	var time = dd['H'] + ':' + dd['i'] + ':' + dd['s'];
	switch(type){
		case 'date':
			return date;
		break;
		case 'time':
			return time;
		break;
		case '':
		case 'datetime':
			return date + ' ' + time;
		break;
		default:
			var str = "Y-m-d H:i:s";
			if(typeof(type) == "string")str = type;
			for(var i in dd){
				str = str_replace (str, i, dd[i]);
			}
			return str;
		break;
	}
}

//替换字符串中的字符
function str_replace (str,replace_what,replace_with)   
{   
	var   ndx=str.indexOf(replace_what);   
	var   delta=replace_with.length - replace_what.length;   
	while(ndx >= 0)   
	{   
		str=str.substring(0,ndx)+replace_with+str.substring(ndx+replace_what.length);   
		ndx=str.indexOf(replace_what,ndx+delta+1);   
	}   
	return str;   
}
//字符串填充
function strPad(v, l){
	if(typeof(l) == 'undefined')var l = 2;
	var s = v + '';
	if(s.length < l){
		for(var i = s.length; i < l;i++){
			s = '0' + s;
		}
	}
	return s;
}

//判断是字符串是否在数组中存在
function inArray(v, arr){
	try{
		for(var i = 0; i < arr.length;i++){
			if(v == arr[i])return true;
		}
	}catch(e){}
	return false;
}
//判断是字符串是否在数组中存在
function searchArray(v, arr){
	try{
		for(var i = 0; i < arr.length;i++){
			var str = arr[i] + "";
			if(str.indexOf(v) != -1)return new Array(i, arr[i]);
		}
	}catch(e){}
	return false;
}

//删除数组中的一个元素
function arrayDeleteItem(v, arr){
	var new_arr = new Array();
	try{
		for(var i = 0; i < arr.length;i++){
			if(v != arr[i]){new_arr[new_arr.length] = arr[i]}
		}
	}catch(e){}
	return new_arr;
}
//是否为数字
function isNum(num){
	var rule = /^\d+$/; 
	if(rule.test(num))return true;
	return false;
}
//数组随机排序
function arrayRand(Arr){
	Arr.sort(function(){return Math.random()>0.5?-1:1;});
	return Arr;
}
//取min-max区间的随机数
function rand(min, max){
	var r = 0;
	switch(arguments.length){ 
		case 1: r = parseInt(Math.random()*min+1,10); 
		case 2: r = parseInt(Math.random()*(max-min+1) + min,10);  
	}
	return r > min && r < max ? r : 0;
}

//去除字符串两边的空格
function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { 
     temp = temp.replace(obj, '$2'); 
   }
   return temp;
}


//格式化数字
function format_number(num, dot, dec_point){
	try{
		num = parseFloat(num);
		if(typeof(dot) == 'undefined')var dot=2;
		if(typeof(dec_point) == 'undefined')var dec_point='';
		num = num.toFixed(dot);
		if(dec_point.length>0){
			var   re=/(\d+)(\d{3})/,s=num.toString();  
			while(re.test(s))s=s.replace(re,"$1" + dec_point + "$2");  
			return s;  
		}
	}catch(e){
		
	}
	if(isNaN(num))num = "";
	return num;  
}
//图片按钮变色
function x_fade(obj, t, v) {
	if(!v)var v = '75';
	if(document.all){
		try{
			if (t == true) {
				if(obj.filters.alpha.opacity > 30) obj.filters.alpha.opacity = v;
			} else {
				if(obj.filters.alpha.opacity <  100) obj.filters.alpha.opacity = 100;
			}	
		}catch(e){
			try{
				if (t == true) {
					obj.style.filter = "Alpha(Opacity=" + v + ")";
				} else {
					obj.style.filter = "Alpha(Opacity=100)";
				}
			}catch(e){
				alert(e.description);
			}
		}
	
		/*
		if (t == true) {
			if(obj.filters.alpha.opacity > 30) obj.filters.alpha.opacity = v;
		} else {
			if(obj.filters.alpha.opacity <  100) obj.filters.alpha.opacity = 100;
		}
		*/
	}
	else if(document.getElementById)
	{ 
		v = v/100;
		obj.style.MozOpacity = 1;
		if (t == true) {
			if(obj.style.MozOpacity > 0.1) obj.style.MozOpacity = v;
		} else {
			if(obj.style.MozOpacity < 1) obj.style.MozOpacity = 1;
		}
	}
}
//禁用、恢复图片按钮 btn=按钮ID, d=true OR false(禁用、恢复)
function disable_button(btn, d, opacity ){
	try{
		var btn = getID(btn);
	}catch(e){}
	if(btn){
		if(d){
				if(!opacity)var opacity = 30;
				btn.disabled = true;
				x_fade(btn, true, opacity); 
		}else{
				btn.disabled = false;
				x_fade(btn, false, 100); 
		}
	}
}


//限制只能输入金额
function onlyAmount(evt)
{
	var c = evt.charCode ? evt.charCode : evt.keyCode;

	if(evt.ctrlKey && c==88 || evt.ctrlKey && c==86)return true;
	if(c==8 || c==46 || c==190)return true;
	if(!((c>=48&&c<=57)||(c>=96&&c<=105)))return false;
	return true;
}
//限制只能输入数字
function onlyNum(evt)
{
	var c = evt.charCode ? evt.charCode : evt.keyCode;
	if(c==8 || c==46)return true;
	if(!((c>=48&&c<=57)||(c>=96&&c<=105)))return false;
	return true;
}

//限制只能输入英文
function onlyEng(evt)
{
	var c = evt.charCode ? evt.charCode : evt.keyCode;
	if(c==8 || c==46)return true;
	if(!(c>=65&&c<=90))return false;
	return true;
}

//限制只能输入金额
function replaceAmount(obj,dot)
{
	if(!dot)var dot = 2;
	var str = obj.value;
	var res = '';
	for(var i = 0; i < str.length ;i+=1){
		var s = str.substr(i,1);
		s = replace_number(s, true);
		s1 = parseInt(s, 10);
		if((s1>=0 && s1<=9) || s == "."){
			res+=(s+"");
		}else{
			break;
		}
	}
	
	obj.value=format_number(res, dot);
}
//限制只能输入数字
function replaceNum(obj, def)
{
	var str = obj.value;
	var res = '';
	for(var i = 0; i < str.length ;i+=1){
		var s = str.substr(i,1);
		s = parseInt(replace_number(s), 10);
		if(s>=0 && s<=9){
			res+=(s+"");
		}else{
			break;
		}
		
	}
	if(isNaN(res))res="";
	if(res == "" && def)res = def;
	obj.value=res;
}

//限制只能输入英文
function replaceEng(obj)
{
 
}

//替换中文数字为有效数字, s=要替换的内容，dot=true|false　是否替换小数点
function replace_number(s, dot)
{
	var c = s.charCodeAt(0);
	//alert(c);
	if(c>=48&&c<=57)return s;
	if(c>=65296&&c<=65305)return String.fromCharCode(c-65248);
	if((c==12290 || c==46) && dot)return '.';
	return '';
}

//打开css网址
function load_css(url){
	var fileref=document.createElement("link");
	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("type", "text/css");
	fileref.setAttribute("href", url);
	document.getElementsByTagName("head")[0].appendChild(fileref)
}


//打开Js网址

function load_script(url) {
	try{
		//if(url.indexOf('?') != -1){url += "&timestamp=" + new Date().getTime();}
		var script = document.createElement("script");
		script.type = "text/javascript";
		script.src = url;
		document.getElementsByTagName("head")[0].appendChild(script);
	}catch(e){
		//alert(e);
	}

}
 

function load_script2(url, callback) {
	//if(url.indexOf('?') != -1){url += "&timestamp=" + new Date().getTime();}
	var f = arguments.callee;
	if (!("queue" in f))
		f.queue = {};
	var queue =  f.queue;
	if (url in queue) { // script is already in the document
		if (callback) {
			if (queue[url]) // still loading
				queue[url].push(callback);
			else // loaded
				callback();
		}
		return;
	}
	queue[url] = callback ? [callback] : [];
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.onload = script.onreadystatechange = function() {
		if (script.readyState && script.readyState != "loaded" && script.readyState != "complete")
			return;
		script.onreadystatechange = script.onload = null;
		while (queue[url].length)
			queue[url].shift()();
		queue[url] = null;
	};
	
	script.src = url;
	document.getElementsByTagName("head")[0].appendChild(script);
}

function getID(obj){
	var element = null;
	if(document.getElementById){
		element = document.getElementById(obj);
	}
	else if(document.all){
		element = document.all[obj];
	}
	else if(document.layers){
		element = document.layers[obj];
	} 
	return element;

} 
if(typeof($) == 'undefined')$=getID;

function set_html(id, html)
{
	document.getElementById(id).innerHTML=html;
}
function set_text(id, text)
{
	document.getElementById(id).innerTEXT=text;
}
function hide_obj(id){
	document.getElementById(id).style.display='none'
}
function show_obj(id){
	document.getElementById(id).style.display=''
}
function showhide_obj(id){
	if(document.getElementById(id).style.display==''){
		document.getElementById(id).style.display='none';
		return 'hide';
	}else{ 
		document.getElementById(id).style.display='';
		return 'show';
	}
}
function set_src(id, value){
	document.getElementById(id).src=value
}

function select_checkbox(form, sel, s)
{
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if (e.name.substring(0, sel.length) == sel)
			e.checked = s;
	}
}
function select_checkbox_id(form, sel, s)
{
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		try{
			if (e.id.substring(0, sel.length) == sel)
				e.checked = s;
		}catch(e){}
	}
}
function select_all(form, s, sel)
{
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if (e.name.substring(0, sel.length) == sel)
		e.checked = s.checked;
	}
}
function unselect_all(form,  sel)
{
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if (e.name.substring(0, sel.length) == sel)
		e.checked = !e.checked;
	}
}
function select_submit(form, action)
{
	form.action = action;
	form.submit();
}


function btn_confirm(url, msg)
{
	if(confirm(msg))
		window.location=url;
	return false;
}
function get_value( label, t){  
	if(!label)return '';
	if(!label.length)return label.value;
	if(t == 'checkbox'){
		var v_list = new Array();
		var i=0;
		for(var j = label.length - 1; j >= 0; j--)
				if(label[j].checked)  v_list[i++] = label[j].value;
		return v_list.join(',');
	}

	for(var j = label.length - 1; j >= 0; j--)
		if(label[j].checked) return label[j].value;
	return label[0].value;


	
}
function set_default( form, label,value){
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		switch(e.type){
			case 'radio':
			case 'checkbox':if(e.name == label && e.value == value)e.checked = true;break;
			case 'multiple':
			case 'select':
			case 'select-one':
				if(e.name == label){
					for (var d=0; d<e.options.length; d++){
						if(e.options[d].value == value ){
							e.selectedIndex = d;
						}
					}
				}
				break;
			default:
			break;
		}			
		
	}
}
function flash(url, w, h, vars){
	document.write(flash_html(url, w, h, vars));
}
function flash_html(url, w, h, vars){
	var str = "";
	str += ('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ w +'" height="'+ h +'">');
	str += ('<param name="movie" value="' + url + '"><param name="quality" value="high">');
	str += ('<param name="menu" value="false"><param name=wmode value="opaque">');
	str += ('<param name="loop" value="true">');
	str += ('<param name="loop" value="true">');
	str += ('<param name="FlashVars" value="' + vars + '">');
	str += ('<embed src="' + url + '" width="'+ w +'" height="'+ h +'" wmode="opaque" loop="true" FlashVars="' + vars + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'); 
	str += ('</object>'); 
	return str;
}
// alert( readCookie("myCookie") );
function readCookie(name)
{
	var cookieValue = "";
	var search = name + "=";
	if(document.cookie.length > 0)
	{ 
		offset = document.cookie.indexOf(search);
		if (offset != -1)
		{ 
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
				cookieValue = unescape(document.cookie.substring(offset, end))
		}
	}
	return cookieValue;
}
// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours)
{
	var expire = "";
	if(hours != null)
	{
		expire = new Date((new Date()).getTime() + hours * 3600000);
		expire = "; expires=" + expire.toGMTString();
	}
	document.cookie = name + "=" + escape(value) + expire;
}


function removeEvent(obj, name, func) {
	name = name.toLowerCase();
	// Add the hookup for the event.
	if(typeof(obj.addEventListener) != "undefined") {
		if(name.length > 2 && name.indexOf("on") == 0) name = name.substring(2, name.length);
			obj.removeEventListener(name, func, true);
	} else if(typeof(obj.attachEvent) != "undefined"){
		obj.detachEvent(name, func);
	} else {
		eval("obj." + name) = null;
	}
}

function addEvent(obj, name, func) {
	name = name.toLowerCase();
	// Add the hookup for the event.
	if(typeof(obj.addEventListener) != "undefined") {
		if(name.length > 2 && name.indexOf("on") == 0) name = name.substring(2, name.length);
			obj.addEventListener(name, func, false);
	} else if(typeof(obj.attachEvent) != "undefined"){
		obj.attachEvent(name, func);
	} else {
		if(eval("obj." + name) != null){
			// Save whatever defined in the event
			var oldOnEvents = eval("obj." + name);
			eval("obj." + name) = function(e) {
				try{
					func(e);
					eval(oldOnEvents);
				} catch(e){}
			};
		} else {
			eval("obj." + name) = func;
		}
	}
}



//<<xalt
var cfg_fade_switch=true;       
var cfg_xoffset=9;         
var cfg_yoffset=20;        
var cfg_mouse_follow=true;
var cfg_hide_delay=8000;    
var cfg_txt_tag='alt';
var cfg_is_show=true;
var cfg_xalt_disabled=false;

document.write("<style>.navtext_div{PADDING-RIGHT: 6px; PADDING-LEFT: 6px;PADDING-TOP: 2px; PADDING-BOTTOM: 1px; FONT-SIZE: 12px; Z-INDEX: 99; VISIBILITY: hidden; COLOR: #333333; BORDER: 1px #8899AA solid;FONT-FAMILY: Courier New,tahoma,arial; POSITION: absolute; BACKGROUND-COLOR: #FFFFCC;}</style>");
document.write('<div id="navtext_div" class="navtext_div" style="visibility:hidden; position:absolute; top:0px; left:-400px; z-index:10000; padding:3px"></div>');

function xalt_props(){
	this.w3c=(document.getElementById)?true:false;
	this.ns4=(document.layers)?true:false;
	this.ie4=(document.all && !this.w3c)?true:false;
	this.ie5=(document.all && this.w3c)?true:false;
	this.ns6=(this.w3c && navigator.appName.indexOf("Netscape")>=0 )?true:false;
	this.w_y=0;
	this.w_x=0;
	this.navtxt=null;
	this.boxheight=0;
	this.boxwidth=0;
	this.ishover=true;
	this.ieop=0;
	this.op_id=0;
	this.oktomove=true;
	this.dy=0;
}
function xalt_kill_errors() {
	return true;
}

var XALT=new xalt_props();

function xalt_disabled(){
	cfg_xalt_disabled = true;
}
function xalt_enabled(){
	cfg_xalt_disabled = false;
}
function xalt_set_mouse_follow(mouse_follow){//true or false
	cfg_mouse_follow=mouse_follow;
}

function xalt_set_fade_switch(fade_switch){//true or false
	cfg_fade_switch=fade_switch;
	if(!cfg_fade_switch)XALT.ieop=100;
}

function xalt_get_window_dims(){
	XALT.w_y=(XALT.ie5||XALT.ie4)?document.body.clientHeight:window.innerHeight;
	XALT.w_x=(XALT.ie5||XALT.ie4)?document.body.clientWidth:window.innerWidth;
}

function xalt_get_box_width(){
	if(XALT.ns4)XALT.boxwidth=(XALT.navtxt.document.width)? XALT.navtxt.document.width : XALT.navtxt.clip.width;
	else if(XALT.ie4)XALT.boxwidth=(XALT.navtxt.style.pixelWidth)? XALT.navtxt.style.pixelWidth : XALT.navtxt.offsetWidth;
	else XALT.boxwidth=(XALT.navtxt.style.width)? parseInt(XALT.navtxt.style.width) : parseInt(XALT.navtxt.offsetWidth);
}

function xalt_get_box_height(){
	if(XALT.ns4)XALT.boxheight=(XALT.navtxt.document.height)? XALT.navtxt.document.height : XALT.navtxt.clip.height;
	else if(XALT.ie4)XALT.boxheight=(XALT.navtxt.style.pixelHeight)? XALT.navtxt.style.pixelHeight : XALT.navtxt.offsetHeight;
	else XALT.boxheight=parseInt(XALT.navtxt.offsetHeight);
}

function xalt_body_width(){ 
	var w = 0;
	if (!document.all) {
		w = document.body.clientWidth > document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
	}
	else{
		w = document.documentElement.clientWidth == 0 ? document.body.clientWidth : document.documentElement.clientWidth;
	}
	return parseInt(w, 10);
}
function xalt_body_height(){
	var h = 0;
	if (!document.all) {
		h = document.body.clientHeight > document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
	}
	else{
		h = document.documentElement.clientHeight == 0 ? document.body.clientHeight : document.documentElement.clientHeight;
	}
	return parseInt(h, 10);
}

function xalt_move_nav_txt(x,y){
	var w = xalt_get_box_width();
	var h = xalt_get_box_height();		
	
	var b_w = xalt_get_page_scrollx() + xalt_body_width() - w;
	var b_h = xalt_get_page_scrolly() + xalt_body_height() - h;
	//window.status="x=" + x + ",y="+ y;
	
	if(x >= b_w){
		x = b_w;
	}
	if(x <= 1){
		x = -1000;

	}

	if(y >= b_h){
		y = b_h;
	}

	if(y <= 1){
		y = -1000;
	}
	try{
		if(XALT.ns4){
			XALT.navtxt.moveTo(x,y);
		}else{
			XALT.navtxt.style.left=x+'px';
			XALT.navtxt.style.top=y+'px';
		}
	}catch(e){

	}
}
function xalt_get_left(obj) {
	return (obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft + xalt_get_left(obj.offsetParent));
}

function xalt_get_top(obj) {
	return (obj.offsetParent==null ? obj.offsetTop : obj.offsetTop + xalt_get_top(obj.offsetParent));
}
function xalt_get_page_scrolly(){
	if(XALT.ie5||XALT.ie4){
		if(document.documentElement.scrollTop > 0) return document.documentElement.scrollTop;
		return document.body.scrollTop;
	}else return window.pageYOffset;
}

function xalt_get_page_scrollx(){
	if(XALT.ie5||XALT.ie4){
		if(document.documentElement.scrollLeft > 0) return document.documentElement.scrollLeft;
		return document.body.scrollLeft;
	}else return window.pageXOffset;
}

function xalt_write_in_div(text){
	if(XALT.ns4){
		XALT.navtxt.document.open();
		XALT.navtxt.document.write(text);
		XALT.navtxt.document.close();
	}
	else XALT.navtxt.innerHTML=text;
}
/*
	onmouseover="xalt_show(this, '{row.catalog_name}')" onmouseout="xalt_show(this, 0)"
	onmouseover="xalt_show(this, '{row.catalog_name}')"
*/
function xalt_show(obj, text){
	xalt_write_txt(text);
	obj.onmouseout=function(){xalt_write_txt(0)};
}
function xalt_write_txt(text){
	if(cfg_xalt_disabled)return;
	if(cfg_fade_switch && (XALT.ie4||XALT.w3c))clearInterval(XALT.op_id);
	if(text!=0 && cfg_is_show ){
		if(!cfg_mouse_follow)clearTimeout(XALT.dy);
		XALT.oktomove=true;
		XALT.ishover=true;
		if(XALT.ns4)text='<div class="navtext_div">'+text+''+'</div>';
		if(XALT.w3c||XALT.ie4)XALT.navtxt.style.textAlign="left";
		xalt_write_in_div(text);
		if(XALT.ns4)XALT.navtxt.visibility="show";
		else{
			//XALT.navtxt.style.display="inline";
			XALT.navtxt.style.visibility="visible";
		}
		xalt_get_box_height();
		if((XALT.w3c||XALT.ie4) && cfg_fade_switch){
			if(XALT.ie4||XALT.ie5)XALT.navtxt.style.filter="alpha(opacity=0)";
			if(XALT.ns6)XALT.navtxt.style.MozOpacity=0;
			XALT.ieop=0;
			XALT.op_id=setInterval('xalt_do_opacity()',10);
		}
		cfg_is_show=false;
	}else{
		cfg_is_show=true;
		if(cfg_mouse_follow)xalt_hide_alt_txt();
		else XALT.dy=setTimeout('xalt_hide_alt_txt()',cfg_hide_delay);
	}
}

function xalt_hide_alt_txt(){
	if(XALT.ns4)XALT.navtxt.visibility="hide";
	else{
		//XALT.navtxt.style.display="none";
		XALT.navtxt.style.visibility="hidden";
	}
	xalt_move_nav_txt(-XALT.boxwidth-10,0);
	xalt_write_in_div('');
	
}

function xalt_do_opacity(){
	if(XALT.ieop<=100){
	XALT.ieop+=32;
	if(XALT.ie4||XALT.ie5)XALT.navtxt.style.filter="alpha(opacity="+XALT.ieop+")";
	if(XALT.ns6)XALT.navtxt.style.MozOpacity=XALT.ieop/100;
	}else clearInterval(XALT.op_id);
}
function xalt_fixE(e){
	if (typeof e == 'undefined') e = window.event;
	if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
	if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
	if (typeof e.srcElement == 'undefined') e.srcElement = e.target;
	return e;
}

function xalt_move_obj(evt){
	if(cfg_xalt_disabled || XALT.navtxt.style.visibility == 'hidden')return;
	evt = xalt_fixE((XALT.ie5||XALT.ie4) ? event : evt);
	var mx=evt.clientX;
	var my=evt.clientY;
	var d = false;
	var tagName = "";
	try{
		var tagName = evt.srcElement.tagName.toUpperCase();
	}catch(e){}
	
	//if(tagName == "DIV" || tagName == "IMG"|| tagName == "TABLE"|| tagName == "TD"){
	//	return ;
	//}
	try{
		d = evt.srcElement.getAttribute('disabled');
	}catch(e){
		d = true;
	}
	try{
		if(d){
				mx = xalt_get_left(evt.srcElement);
				my = xalt_get_top(evt.srcElement);			
		}
	}catch(e){
		
	}
	//window.status = d+'x='+mx + ',' + 'y='+my;

	if(XALT.ishover && XALT.oktomove){
		margin=(XALT.ie4||XALT.ie5)?5:25;
		if(XALT.ns6)if(document.height+27-window.innerHeight<0)margin=15;
		if(XALT.ns4)if(document.height-window.innerHeight<0)margin=10;
		if(XALT.ns4||XALT.ns6)mx-=xalt_get_page_scrollx();
		if(XALT.ns4)my-=xalt_get_page_scrolly();
		xoff=mx+cfg_xoffset;
		yoff=(my+XALT.boxheight+cfg_yoffset-((XALT.ns6)?xalt_get_page_scrolly():0)>=XALT.w_y)? -5-XALT.boxheight-cfg_yoffset: cfg_yoffset;
		xalt_move_nav_txt( Math.min(XALT.w_x-XALT.boxwidth-margin , Math.max(2,xoff))+xalt_get_page_scrollx(),
							my+yoff+xalt_get_page_scrolly());
	
		if(!cfg_mouse_follow)XALT.oktomove=false;
	}
}
function xalt_scan_dom(curNode) {
	while(curNode )	{
		if(curNode.nodeType == 1){
			var txt = curNode.getAttribute(cfg_txt_tag);
			if (curNode.alt) curNode.alt = "";
			if (curNode.title) curNode.title = "";
			if(txt != null && txt != ''){
				curNode.setAttribute('xalt_txt', txt);
				curNode.setAttribute(cfg_txt_tag, '');
				curNode.onmouseover = function() {
					xalt_write_txt(this.getAttribute('xalt_txt'));
					if(!cfg_mouse_follow)XALT.dy=setTimeout('xalt_hide_alt_txt()',cfg_hide_delay);
				}
				curNode.onmouseout = function() {
					xalt_write_txt(0); 
					if(!cfg_mouse_follow)clearTimeout(XALT.dy);
				}
			}
			try{
				var el = curNode;
				var className = '';
				try{
					className = el.className;
				}catch(e){}
				if(className == null || className == '' || className == 'input' || className == 'textarea')
				switch (el.tagName.toLowerCase()) {
					case "input":
						if (/text|file|password/.test(el.type)){
							el.className = "input";
							/*	
							addEvent(el, "onmouseover", function() {
									try{
										if(this.className!='input_focus')this.className = "input_over";
									}catch(e){
										this.setAttribute('className','input_over');
									}
									});
							addEvent(el, "onmouseout", function() {
									try{
										if(this.className!='input_focus')this.className = "input";
									}catch(e){
										this.setAttribute('className','input');
									}
									});
							*/
							addEvent(el, "onfocus", function() {
										var obj = document.all ? window.event.srcElement : this;
										
										obj.className = "input_focus";
									});
							addEvent(el, "onblur", function() {
										var obj = document.all ? window.event.srcElement : this;
										obj.className = "input";
									});
						}
						break;
					case "textarea":
						el.className = "textarea";
						/*
						addEvent(el, "onmouseover", function() {
								try{
									if(this.className!='textarea_focus')this.className = "textarea_over";
								}catch(e){
									this.setAttribute('className','textarea_over');
								}
								});
						addEvent(el, "onmouseout", function() {
								try{
									if(this.className!='textarea_focus')this.className = "textarea";
								}catch(e){
									this.setAttribute('className','textarea');
								}
								});
						*/
						addEvent(el, "onfocus", function() {
									var obj = document.all ? window.event.srcElement : this;
									obj.className = "textarea_focus";
								});
						addEvent(el, "onblur", function() {
									var obj = document.all ? window.event.srcElement : this;
									obj.className = "textarea";
								
								});
					break;
				}
			}catch(e){}
		}
		xalt_scan_dom(curNode.firstChild);
		curNode=curNode.nextSibling;
	}
}

function xalt_onload(){
	//window.onerror = xalt_kill_errors;
	if (!(XALT.w3c || XALT.ns4 || XALT.ie4 || XALT.ie5 || XALT.ns6)) return;
	if(XALT.ns4||XALT.ns6){
		window.document.captureEvents(Event.MOUSEMOVE);
		window.document.addEventListener("mousemove", xalt_move_obj, true);
		window.addEventListener("resize", xalt_get_window_dims, true);
	}else if(XALT.ie4||XALT.ie5||XALT.w3c){
		window.document.attachEvent("onmousemove", xalt_move_obj);
		window.attachEvent("onresize", xalt_get_window_dims);
	}
	
	XALT.navtxt=(XALT.ns4)?document.layers['navtext_div']:(XALT.ie4)?document.all['navtext_div']:(XALT.w3c)?document.getElementById('navtext_div'):null;
	xalt_get_box_width();
	xalt_get_box_height();
	xalt_get_window_dims();
	if(XALT.ie4||XALT.ie5&&cfg_fade_switch)XALT.navtxt.style.filter="alpha(opacity=100)";
	xalt_scan_dom(document.body);
	
}

if(XALT.ns4||XALT.ns6){
	window.addEventListener("load", xalt_onload, true);
}else if(XALT.ie4||XALT.ie5||XALT.w3c){
	 window.attachEvent("onload", xalt_onload);
}
//>>xalt

 /*
	autocheck 2.0
 */
 //form check
var first_error		=	"";
var check_error		=	'提示信息：';
var check_alt		=	'';
var check_alt_count	=	1;
var alert_num		=	6;
var msg_type = 0;
function autocheck(fm, disabled_button){
	check_alt_count			=	1;
	check_alt			=	'';
	var check_rule 			=	new Array();
	check_rule['email']		=	/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;    
	check_rule['number']  		=	/^\d+$/;  
	check_rule['url']		=	/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
	check_rule['tel']		=	 /^((\(\d{2,3}\))|(\d{3}[\-]{0,1}))?(\(0\d{2,3}\)|0\d{2,3}[\-]{0,1})?[1-9]\d{6,7}([\-]{0,1}\d{1,4})?$/;
	check_rule['mobile']		=	/^((\(\d{3}\))|(\d{3}\-))?(13|15)\d{9}$/;
	check_rule['domain']		=	/^[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
	check_rule['idcard']		=	/^\d{15}(\d{2}[A-Za-z0-9])?$/;
	check_rule['money']		=	/^\d+(\.\d+)?$/;
	check_rule['zip']		=	/^[0-9]{5,6}$/;
	check_rule['oicq']		=	/^[0-9]{4,10}$/;
	check_rule['int']		=	/^[-\+]?\d+$/;
	check_rule['double']		=	/^[-\+]?\d+(\.\d+)?$/;
	check_rule['english']		=	/^[A-Za-z0-9\. ]+$/;
	check_rule['chinese']		=	/^[\u0391-\uFFE5]+$/;
	check_rule['username']		=	/^[a-z]\w{3,32}$/i;
	check_rule['password']		=	/^[\w|\d|\s|\.;,'~!#@$%^&*()<>\-=:\?+|]+$/;
	check_rule['char']		=	/^[A-Za-z0-9_\-]+$/;

	try{
		msg_type = fm.imsg.value;
	}catch(e){
		msg_type = 0;
	}
	for(var i = 0; i < fm.elements.length; i++){
		with(fm.elements[i]){ 
			var form_item	=	fm.elements[i];
			var label_model	=	form_item.getAttribute('model');
			var msg		=	form_item.getAttribute('msg');
			var area = form_item.getAttribute('area');//form_item.getAttribute('area');22-33
			var area_max = 0;
			var area_min = 0;
			if(new RegExp("^[0-9\-\.]{1,}$","g").test(area)){
				var tmp = area.match(new RegExp("^([0-9\.]*)[-]{0,1}([0-9\.]*)$"));
				area_min = parseFloat(tmp[1]);
				area_max = parseFloat(tmp[2]);
				if((form_item.type != 'checkbox' && form_item.type != 'multiple') && (area_max < form_item.value && area_max != 0 && area_max != 'NaN') || (area_min > form_item.value && area_min != 0 && area_min != 'NaN')) {
					add_error(form_item.name, msg);
					continue;
				}
			}
			var len = form_item.getAttribute('len');
			var len_max = 0;
			var len_min = 0;
			if(new RegExp("^[0-9\-]{1,}$","g").test(len)){
				var tmp = len.match(new RegExp("^([0-9]*)[-]{0,1}([0-9]*)$"));
				len_min = parseInt(tmp[1]);
				len_max = parseInt(tmp[2]);
				if(len_min == 0 && form_item.value == ''){
					continue;
				}
				if((len_max < strlen(form_item.value) && len_max != 0 && len_max != 'NaN') || (len_min > strlen(form_item.value) && len_min != 0 && len_min != 'NaN')){ 
					add_error(form_item.name, msg);
					continue;
				}
			}
			var to = form_item.getAttribute('to');
			if(typeof(label_model) != "string")  continue;
			switch(label_model){
				case 'repeat':
					if(to != null)
						if(fm.elements[to].value != form_item.value)
							add_error(form_item.name, msg);
					break;
				case 'define':
					var rule = form_item.getAttribute('rule');
					if(!new RegExp(rule,"g").test(form_item.value))
						add_error(form_item.name, msg);
					break;
				case 'select': 
					var check_label = document.getElementsByName(form_item.name);
					var checked_count = 0;
					for(var j = check_label.length - 1; j >= 0; j--){
						if(check_label[j].selected || check_label[j].value != '') checked_count = 1;
					}
					if(checked_count == 0) 
						add_error(form_item.name, msg);
					break;
				case 'multiple': 
					var check_label = document.getElementsByName(form_item.name);
					var checked_count = 0;
					for(var j = check_label.length - 1; j >= 0; j--)
						if(check_label[j].selected) checked_count++;
					if(checked_count > area_max || checked_count < area_min) 
						add_error(form_item.name, msg);
					break;
				case 'radio': 
					var check_label = document.getElementsByName(form_item.name);
					var checked_count = 0;
					for(var j = check_label.length - 1; j >= 0; j--)
						if(check_label[j].checked) checked_count = 1;
					if(checked_count == 0) 
						add_error(form_item.name, msg);
					break;
				case 'checkbox': 
					var check_label = document.getElementsByName(form_item.name);
					var checked_count = 0;
					for(var j = check_label.length - 1; j >= 0; j--)
						if(check_label[j].checked) checked_count++;
					if(checked_count > area_max || checked_count < area_min) 
						add_error(form_item.name, msg);
					break;
				case 'y-m-d h:i:s':
					var tmp = form_item.value.match(new RegExp("^([0-9]{4})[-./]{1}([0-9]{1,2})[-./]{1}([0-9]{1,2})[ ]{1}([0-9]{2})[:]{1}([0-9]{1,2})[:]{1}([0-9]{1,2})$"));
					if(tmp != null ) {//year-month-day tmp[1]-tmp[2]-tmp[3]
						if(!check_date(tmp[1], tmp[2], tmp[3]) || !check_time(tmp[4], tmp[5], tmp[6])) {
							add_error(form_item.name, msg);
						}
					}else {
						add_error(form_item.name, msg);
					}
					break;
				case 'h:i:s':
					var tmp = form_item.value.match(new RegExp("^([0-9]{2})[:]{1}([0-9]{1,2})[:]{1}([0-9]{1,2})$"));
					if(tmp != null ) {//year-month-day tmp[1]-tmp[2]-tmp[3]
						if(!check_time(tmp[1], tmp[2], tmp[3])) {
							add_error(form_item.name, msg);
						}
					}else {
						add_error(form_item.name, msg);
					}
					break;
				case 'y-m-d':
					var tmp = form_item.value.match(new RegExp("^([0-9]{4})[-./]{1}([0-9]{1,2})[-./]{1}([0-9]{1,2})$"));
					if(tmp != null ) {//year-month-day tmp[1]-tmp[2]-tmp[3]
						if(!check_date(tmp[1], tmp[2], tmp[3])) {
							add_error(form_item.name, msg);
						}
					}else {
						add_error(form_item.name, msg);
					}
					break;
				default:
					if(!check_rule[label_model] || check_rule[label_model] == 'undefined') {
						continue ;
					}else{
						if(!check_rule[label_model].test(form_item.value)){
							add_error(form_item.name, msg);
						}else{

							try{
								if(label_model == 'idcard' && !validId(form_item.value)){
									add_error(form_item.name, msg);
								}
							}catch(e){}
						}


					}
					break;
			}
		}
	}
	if(check_alt.length < 4) {
		for(var i = 0; i < fm.elements.length; i++){
		with(fm.elements[i]){ 
			if(disabled_button != false && (fm.elements[i].type=='button' || fm.elements[i].type=='submit'))
				fm.elements[i].disabled = true;
		}}
		return true;
	}
	if(!msg_type){
		alert(check_error + '\n' + check_alt);
	}
	if(fm.elements[first_error].type != 'undefined' && fm.elements[first_error].type){
		try{
			fm.elements[first_error].focus();
		}catch(e){};
	}
	first_error = "";
	return false;
}
function add_error(label, err){
	if(check_alt_count <= alert_num){
		check_alt += (check_alt_count + '.' + err + '\n');
		check_alt_count++;

		if(first_error.length < 1 && msg_type){
			try{
				msg_show(err, msg_type);
			}catch(e){
				alert(err);
			}
		}
		if(first_error.length < 1){
			first_error = label;
			
		}	
	}
}
function check_date(y, m, d){
	if((y <= 0) || (m > 12 || m < 1) || (d > 31 || d < 1)) return false;
	return true;
}
function check_time(h, i, s){
	if((h > 23 || h < 1) || (i > 59 || i < 1) || (s > 59 || s < 1)) return false;
	return true;
}
function strlen(s){
	var i,str1,str2,str3,nLen;
	str1 = s;
	nLen = 0;
	for(i=1;i<=str1.length;i++){
			str2=str1.substring(i-1,i)
			str3=escape(str2);
			if(str3.length>3){
				nLen = nLen + 2;
			}else{
				nLen = nLen + 1;
			}
	}
	return nLen;
}
function set_rule(form_name, label_name, rule_str){
	var model = get_rule('model', rule_str);
	var msg = get_rule('msg', rule_str);
	var area = get_rule('area', rule_str);
	var len = get_rule('len', rule_str);
	var to = get_rule('to', rule_str);
	var rule = get_rule('rule', rule_str);
	if(document.forms[form_name] && document.forms[form_name][label_name]){
		var obj = document.forms[form_name][label_name];
		if(model) obj.setAttribute('model', model);
		if(msg) obj.setAttribute('msg', msg);
		if(area) obj.setAttribute('area', area);
		if(len) obj.setAttribute('len', len);
		if(to) obj.setAttribute('to', to);
		if(rule) obj.setAttribute('rule', rule);
	}else{
		alert( "document.forms[" + form_name + "][" + label_name + "] no defined!");
	}
}
function get_rule(attrib, rule_str){
	var preg = attrib + '=["|\']{1}([^"\']*)["|\']{1}';
	if(new RegExp(preg,"g").test(rule_str)){
		var tmp = rule_str.match(new RegExp(preg));
		return tmp[1];
	}else{
		return false;
	}
}
 
//检测身份证号
var powers=new Array("7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2");
var parityBit=new Array("1","0","X","9","8","7","6","5","4","3","2");
var idcard_sex="M";
//校验身份证号码的主调用
function validId(_id){
	if(_id=="")return false;
	var _valid=false;
	if(_id.length==15){
		_valid=validId15(_id);
		if(!_valid){
			return false;
		}
		_valid=validId18(validId15to18(_id));
	}else if(_id.length==18){
		_valid=validId18(_id);
	}
	if(_valid){
		_valid = validIdIsBan(_id);
	}
	if(!_valid){
		//alert("身份证号码有误,请检查!");
		return false;
	}
	return _valid;
}    

/*
	var str = "";
	str = "111111111111111";
	str = "555555555555551111";
	str = "123456789012345111";
	//str = "123456789012345";
	v = validIdIsBan(str);
	//alert(v+"");
*/
//检测是否为无效数字
function validIdIsBan(_id){
	_id =_id+"";
	for(var i = 0; i < 10; i++){
		var rule	= new RegExp("(["+i+"]{15,18})");
		if(rule.test(_id)){
			return false;
		}
	}
	var ban = [
		"0123456789",
		"1234567890",
		"123456789",
		"012345678901234",
		"012345678901234567",
		"123456789012345",
		"123456789012345789",
		"987654321987654",
		"987654321987654321",
		"098765432109876",
		"098765432109876543",
		];
	for(var i = 0; i < ban.length; i++){
		ban[i] = ban[i]+"";
		if(ban[i] == _id){
			return false;
		}
		if(ban[i] == _id.substr(0, ban[i].length)){
			return false;
		}
	}
	return true;
	
}
//15位转换为18位
function validId15to18(_id){
	_id =_id+"";
	_id = _id.substring(0,6) + "19" + _id.substring(6,15);
	var _num=_id;
	var _power=0;
	for(var i=0;i< 17;i++){
		//校验每一位的合法性

		if(_num.charAt(i)<'0'||_num.charAt(i)>'9'){
			return false;
			break;
		}else{
			//加权

			_power+=parseInt(_num.charAt(i))*parseInt(powers[i]);
			//设置性别

			if(i==16&&parseInt(_num.charAt(i))%2==0){
				idcard_sex="F";
			}else{
				idcard_sex="M";
			}
		}
	}
	//取模

	var mod=parseInt(_power)%11;
	return _id + parityBit[mod] + "";
	//alert(_id);
}
//校验18位的身份证号码

function validId18(_id){
	_id=_id+"";
	var _num=_id.substr(0,17);
	var _parityBit=_id.substr(17);
	var _power=0;
	for(var i=0;i< 17;i++){
		//校验每一位的合法性

		if(_num.charAt(i)<'0'||_num.charAt(i)>'9'){
			return false;
			break;
		}else{
			//加权

			_power+=parseInt(_num.charAt(i))*parseInt(powers[i]);
			//设置性别

			if(i==16&&parseInt(_num.charAt(i))%2==0){
				idcard_sex="F";
			}else{
				idcard_sex="M";
			}
		}
	}

	if(_parityBit == 'X' || _parityBit == 'x'){
		return true;
	}
	//取模
	var mod=parseInt(_power)%11; 
	if(parityBit[mod]==_parityBit){
		return true;
	}
	return false;
}
//校验15位的身份证号码

function validId15(_id){
	_id=_id+"";
	for(var i=0;i<_id.length;i++){
		//校验每一位的合法性

		if(_id.charAt(i)<'0'||_id.charAt(i)>'9'){
			return false;
			break;
		}
	}
	var year=_id.substr(6,2);
	var month=_id.substr(8,2);
	var day=_id.substr(10,2);
	var sexBit=_id.substr(14);
	//校验年份位

	if(year<'01'||year >'90')return false;
	//校验月份

	if(month<'01'||month >'12')return false;
	//校验日

	if(day<'01'||day >'31')return false;
	//设置性别

	if(sexBit%2==0){
		sex="F";
	}else{
		sex="M";
	}
	return true;
} 


 //判断键盘是否锁定大小写
function  checkCapsLock(event){
	var e = event||window.event;
	var o = e.target||e.srcElement;
	var keyCode  =  e.keyCode||e.which; // 按键的keyCode 
	var isShift  =  e.shiftKey ||(keyCode  ==   16 ) || false ; // shift键是否按住
	if (
	((keyCode >=   65   &&  keyCode  <=   90 )  &&   !isShift) // Caps Lock 打开，且没有按住shift键 
	|| ((keyCode >=   97   &&  keyCode  <=   122 )  &&  isShift)// Caps Lock 打开，且按住shift键
	){
		//msg_show("大写锁定键被按下，请注意大小写", msg_type);
		return true;
	}
	else{
		//msg_hide();
		return false;
	} 
}

function open_win(name, url,width,height)
{
	var popup = window.open(url, name, 'width='+width+',height='+height+',scrollbars=yes,resizable=no,status=yes');
    	if (!popup.opener) popup.opener = self;
	popup.focus();
}


function popup(url,width,height)
{
	var popup = window.open(url, '_blank', 'width='+width+',height='+height+',scrollbars=yes,resizable=yes,status=yes');
    	if (!popup.opener) popup.opener = self;
	popup.focus();
}




 
