function checkAction(obj,msg,field)
{
{
	var flag=0;
	var truthBeTold;
	for(i = 0; i < field.length; i++)
		{
			if(field[i].checked == true)
			{
				flag=1;
			}
		}

	if(field.length == null)
	{
		if(field.checked == true)
		{
			flag=1;
		}		
	}

	if (flag==0)
	{
		alert("请选择您要操作的记录!");
		return false;
	}
	else
	{
		return window.confirm("你确定要"+msg+"吗?");
	}
}
}

function getCheckBoxValue(field)
{
	var result = "";
	
	for(i = 0; i < field.length; i++)
	{
		if(field[i].checked == true)
			result += field[i].value + ","
	}
	if(field.length == null)
	{
		if(field.checked == true)
			result = field.value;
	}
	if(result.length > 0)
		result = result.substring(0,result.length-1);
	return result;
}

function isValidUserID(checkStr)
{
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
	var allValid = true;
	if(checkStr.length<6)
		return false;
	for (i=0;i<checkStr.length;i++)
	{
	ch=checkStr.charAt(i);
	for(j=0;j<checkOK.length;j++)
	if(ch==checkOK.charAt(j))
	break;
	if(j==checkOK.length)
	{
	allValid = false;
	break;
	}
	}
	return allValid;
}

Array.prototype.max = function()
{
	var i, max = this[0];
	
	for( i = 1; i < this.length; i++ )
	{
		if( max < this[i] )
		max = this[i];
	}
	
	return max;
}

// 为 String 类增加一个 trim 方法
String.prototype.trim = function()
{
    // 用正则表达式将前后空格用空字符串替代。
    return this.replace( /(^\s*)|(\s*$)/g, "" );
}

// 使用正则表达式，检测 s 是否满足模式 re
function checkExp( re, s )
{
	return re.test( s );
}

// 验证是否 字母数字
function isAlphaNumeric( strValue )
{
	// 只能是 A-Z a-z 0-9 之间的字母数字 或者为空
	return checkExp( /^\w*$/gi, strValue );
}

// 验证是否 日期
function isDate( strValue )
{
	// 日期格式必须是 2001-10-1/2001-1-10 或者为空
	if( isEmpty( strValue ) ) return true;

	if( !checkExp( /^\d{4}-[01]?\d-[0-3]?\d$/g, strValue ) ) return false;
	// 或者 /^\d{4}-[1-12]-[1-31]\d$/
	
	var arr = strValue.split( "-" );
	var year = arr[0];
	var month = arr[1];
	var day = arr[2];
	
	// 1 <= 月份 <= 12，1 <= 日期 <= 31
	if( !( ( 1<= month ) && ( 12 >= month ) && ( 31 >= day ) && ( 1 <= day ) ) )
		return false;
		
	// 润年检查
	if( !( ( year % 4 ) == 0 ) && ( month == 2) && ( day == 29 ) )
		return false;
	
	// 7月以前的双月每月不超过30天
	if( ( month <= 7 ) && ( ( month % 2 ) == 0 ) && ( day >= 31 ) )
		return false;
	
	// 8月以后的单月每月不超过30天
	if( ( month >= 8) && ( ( month % 2 ) == 1) && ( day >= 31 ) )
		return false;
	
	// 2月最多29天
	if( ( month == 2) && ( day >=30 ) )
		return false;
	
	return true;
}

function IsTime(str)
{
	var a = str.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/);
	if (a == null)
	{
		alert('输入的参数不是时间格式');
		return false;
	}
	if (a[1]>24 || a[3]>=60 || a[4]>=60)
	{
	  alert("时间格式不对");
	  return false
	}
	return true;
}

function isEmail( strValue )
{
	if( isEmpty( strValue ) ) return false;

	var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
	return checkExp( pattern, strValue );
	
}

// 验证是否 为空
function isEmpty( strValue )
{
	if( strValue == "" )
		return true;
	else
		return false;
}


function isNumeric( strValue )
{
	
	return checkExp( /^\d*$/g, strValue );
}

function isMoney( strValue )
{
	if( isEmpty( strValue ) ) return true;
	
	return checkExp( /^[+-]?\d+(,\d{3})*(\.\d+)?$/g, strValue );
}


function isPhone( strValue )
{
	if( isEmpty( strValue ) ) return true;
	
	return checkExp( /(^\(\d{3,5}\)\d{6,8}(-\d{2,8})?$)|(^\d+-\d+$)|(^(130|131|133|135|136|137|138|139)\d{8}$)/g, strValue );
}


function isMobile( strValue )
{
	if( isEmpty( strValue ) ) return true;
	
	return checkExp( /(^13[0-9]{9},13[0-9]{9}$)|(^13[0-9]{9}$)/g, strValue );
}

// 验证是否 邮政编码
function isPostalCode( strValue )
{
	// 邮政编码必须是6位数字
	return checkExp( /(^$)|(^\d{6}$)/gi, strValue )
}

function isURL( strValue )
{
	
	if( isEmpty( strValue ) ) return true;
	
	var pattern = /^(http|https|ftp):\/\/(\w+\.)+[a-z]{2,3}(\/\w+)*(\/\w+\.\w+)*(\?\w+=\w*(&\w+=\w*)*)*/gi;
	// var pattern = /^(http|https|ftp):(\/\/|\\\\)(\w+\.)+(net|com|cn|org|cc|tv|[0-9]{1,3})((\/|\\)[~]?(\w+(\.|\,)?\w\/)*([?]\w+[=])*\w+(\&\w+[=]\w+)*)*$/gi;
	// var pattern = ((http|https|ftp):(\/\/|\\\\)((\w)+[.]){1,}(net|com|cn|org|cc|tv|[0-9]{1,3})(((\/[\~]*|\\[\~]*)(\w)+)|[.](\w)+)*(((([?](\w)+){1}[=]*))*((\w)+){1}([\&](\w)+[\=](\w)+)*)*)/gi;

	return checkExp( pattern, strValue );
	
}


function checkLength( strValue, strParam )
{
	if( isEmpty( strValue ) )	return true;
	
	// 参数形如：L<10, L=5, L>117
	if( strParam.charAt( 0 ) != 'L' )	return false;
	
	var l = strValue.length;
	var ml = parseInt( strParam.substr( 2 ) );
	
	switch( strParam.charAt( 1 ) )
	{
		case '<' :
			if( l >= ml )
				return false;
			break;
			
		case '=' :
			if( l != ml )
				return false;
			break;
			
		case '>' :
			if( l <= ml )
				return false;
			break;
			
		default :
			return false
	}
	
	return true;
}


function ValidateMaxLength( strName, strDescription, strLength) {
	var strMsg = "";
	var strValue = document.all( strName ).value.trim();
	var strMaxLength = "L<" + strLength;
	if( !checkLength( strValue, strMaxLength ))
	strMsg = '"' + strDescription + '" 必须小于'+ strLength + '个字符\n';
	return strMsg;
}


function ValidateMinLength( strName, strDescription, strLength) {
	var strMsg = "";
	var strValue = document.all( strName ).value.trim();
	var strMaxLength = "L>" + strLength;
	if( !checkLength( strValue, strMaxLength ))
	strMsg = '"' + strDescription + '" 必须大于'+ strLength + '个字符\n';
	return strMsg;
}


function ValidateEquLength( strName, strDescription, strLength) {
	var strMsg = "";
	var strValue = document.all( strName ).value.trim();
	var strMaxLength = "L=" + strLength;
	if( !checkLength( strValue, strMaxLength ))
	strMsg = '"' + strDescription + '" 必须等于'+ strLength + '个字符\n';
	return strMsg;
}


function CheckValid( obj, strDescription, strType)
{
	var strMsg = "";
	var strValue = obj.value.trim();
	
	switch( strType )
	{
		case "AlphaNumeric" :	// 字母数字
			if( !isAlphaNumeric( strValue ) )
				strMsg = '"' + strDescription + '" 必须是字母或数字！\n';
			break;
			
		case "Date" :	// 日期
			if( !isDate( strValue ) ) 
				strMsg = '"' + strDescription + '" 必须具有正确的日期格式，如 2001-10-01\n';
			break;
				
		case "Email" :	// 电子邮件
			if( !isEmail( strValue ) )
				strMsg = '"' + strDescription + '" 必须具有正确的邮件格式，如 xx@yy.com\n';
			break;
				
		case "NotEmpty" :	// 不许空值
			if( isEmpty( strValue ) )
				strMsg = '"' + strDescription + '" 不能为空！\n';
			break;
				
		case "Numeric" :	//数字
			if( !isNumeric( strValue )  )
				strMsg = '"' + strDescription + '" 必须是数字！\n';
			break;
		
		case "Money" :	//货币
			if( !isMoney( strValue )  )
				strMsg = '"' + strDescription + '" 必须具有正确的货币格式，如 -123,456.789\n';
			break;
					
		case "Phone" :	// 电话
			if( !isPhone( strValue ) )
				strMsg = '"' + strDescription + '" 必须具有正确的电话格式，如 (0755)1234567-999\n';
			break;
		
		case "Mobile" : //手机
			if( !isMobile( strValue ) )
				strMsg = '"' + strDescription + '" 必须具有正确的手机号码格式，如 13800755500\n';
			break;
			
		case "PostalCode" :	// 邮政编码
			if( !isPostalCode( strValue ) )
				strMsg = '"' + strDescription + '" 必须是6位数字！\n';
			break;
			
		case "URL" :	// URL
			if( !isURL( strValue ) )
				strMsg = '"' + strDescription + '" 必须是正确的URL格式！\n';
			break;
				
		default :	// 其他
			if( arrType[i].charAt( 0 ) == 'L' )
			{
				if( !checkLength( strValue, arrType[i] ) )
					strMsg = '"' + strDescription + '" 的长度必须 ' + arrType[i].substr(1) + '\n';
			}
			else
				strMsg = '错误："' + strDescription + '" 的类型 "' + strType + '" 不能识别！\n';
	}
	
	if( strMsg != "" ) 
	{
		window.alert( strMsg );
		obj.focus();
	}
	
	return;
}


function Validate( strName, strDescription, strType)
{
	var strMsg = "";
	var strValue = document.all( strName ).value.trim();
	var arrType = strType.split( " " );
	
	for( var i = 0; i < arrType.length; i++ )
		switch( arrType[i] )
		{
			case "AlphaNumeric" :	// 字母数字
				if( !isAlphaNumeric( strValue ) )
					strMsg = '"' + strDescription + '" 必须是字母或数字！\n';
				break;
			
			case "Date" :	// 日期
				if( !isDate( strValue ) ) 
					strMsg = '"' + strDescription + '" 必须具有正确的日期格式，如 2001-10-1\n';
				break;
				
			case "Email" :	// 电子邮件
				if( !isEmail( strValue ) )
					strMsg = '"' + strDescription + '" 必须具有正确的邮件格式，如 webmaster@yuanyue.com\n';
				break;
				
			case "NotEmpty" :	// 不许空值
				if( isEmpty( strValue ) )
					strMsg = '"' + strDescription + '" 不能为空！\n';
				break;
				
			case "Numeric" :	//数字
				if( !isNumeric( strValue )  )
					strMsg = '"' + strDescription + '" 必须是数字！\n';
				break;
				
			case "Money" :	//货币
				if( !isMoney( strValue )  )
					strMsg = '"' + strDescription + '" 必须具有正确的货币格式，如 -123,456.789\n';
				break;
					
			case "Phone" :	// 电话
				if( !isPhone( strValue ) )
					strMsg = '"' + strDescription + '" 必须具有正确的电话格式，如 (0755)1234567-999\n';
				break;

			case "Mobile" : //手机
				if( !isMobile( strValue ) )
					strMsg = '"' + strDescription + '" 必须具有正确的手机号码格式，如 13800755500\n';
				break;
						
			case "PostalCode" :	// 邮政编码
				if( !isPostalCode( strValue ) )
					strMsg = '"' + strDescription + '" 必须是6位数字！\n';
				break;
				
			case "URL" :	// URL
				if( !isURL( strValue ) )
					strMsg = '"' + strDescription + '" 必须是正确的URL格式！\n';
				break;
				
			default :	// 其他
				if( arrType[i].charAt( 0 ) == 'L' )
				{
					if( !checkLength( strValue, arrType[i] ) )
						strMsg = '"' + strDescription + '" 的长度必须 ' + arrType[i].substr(1) + '\n';
				}
				else
					strMsg = '错误："' + strDescription + '" 的类型 "' + strType + '" 不能识别！\n';
		}
	
	return strMsg;
}


function confirm_delete( url )
{
	if( confirm( "您确实要删除吗？" ) )
	{
		window.location = ( url )
	}
}

function goToURL( url )
{
	window.location = url;
}

function openNewWin( url, width, height )
{
	var newwin = window.open( url, "NewWin", "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes,width=" + width + ",height=" + height +"" );
	if(newwin != null)
		newwin.focus();
	return false;
}

var checkboxflag = "false";
function check(field) 
{
	if (checkboxflag == "false") 
	{
		if(field.length == null)
		{
			if (field.disabled != true)
			{
				field.checked = true;
			}
		}
		else
		{
			for (i = 0; i < field.length; i++) 
			{
				if (field[i].disabled != true)
				{
					field[i].checked = true;
				}
			}
		}
		checkboxflag = "true";
		return "全不选"; 
	}
	else 
	{
		if(field.length == null)
		{
			if (field.disabled != true)
			{
				field.checked = false;
			}
		}
		else
		{
			for (i = 0; i < field.length; i++) 
			{
				if (field[i].disabled != true)
				{
					field[i].checked = false; 
				}	
			}
		}
		checkboxflag = "false";
		return "全　选"; 
	}
}

function chkinverse(field)
{
	if(field.length == null)
	{
		if (field.disabled != true)
		{
			if(field.checked == true)
			{
				field.checked = false;
			}
			else
			{
				field.checked = true;
			}
		}	
	}
	else
	{
		
		for(i = 0; i < field.length; i++)
		{
			if (field[i].disabled != true)
			{
				if(field[i].checked == true)
				{
					field[i].checked = false;
				}
				else
				{
					field[i].checked = true;
				}	
			}
		}
	}	
	return "反　选"
}


function ActionConfirm(form,msg,field) 
{
	var flag=0;
	var truthBeTold;
	for(i = 0; i < field.length; i++)
		{
			if (field[i].disabled != true)
			{
				if(field[i].checked == true)
				{
					flag=1;
				}
			}
		}

	if(field.length == null)
	{
		if(field.checked == true)
		{
			flag=1;
		}		
	}

	if (flag==0)
	{alert("请选择记录!");}
	else
	{
		truthBeTold =window.confirm("你确定要["+msg+"]吗?");
		if (truthBeTold) {
			form.DoType.value=msg;
			form.submit();
		} 
	}
}