/**********************************************************************/
/* common.js
/* notice: 原型为/luosi/include/js/FUNCTION.JS，修改原先一些不兼容（特别是和jquery）,删除原一些不通用函数
/* modify by : 风尘仆仆,09-07-10
/* getElementsByClassName(clsName,htmltag),使用Class获取节点，2010-1-11,wish
/* showorhideTag([''|'hidden'],htmltag),隐藏或显示一组节点,1010-1-11,wish
/**********************************************************************/

var Numbers="0123456789";
var UpperLetters="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var LowerLetters="abcdefghijklmnopqrstuvwxyz";
var SpecialChar="`~!@#$%^&*()_-+={}[]|\:;<>,.?/'";
var EmailChar= Numbers + UpperLetters + LowerLetters + "@-_.";
var EnglishChar= Numbers + UpperLetters + LowerLetters + "`~!@#$%^&()_-+={}[];,.'";

var Letters=UpperLetters + LowerLetters ;
var Alphanumeric=Numbers + Letters ;

// Gets a element by its Id. Used for shorter coding.
function GetE( elementId ){
	return document.getElementById( elementId )  ;
}

function ShowE( element, isVisible ){
	if ( typeof( element ) == 'string' )
		element = GetE( element ) ;
	element.style.display = isVisible ? '' : 'none' ;
}

function SetAttribute( element, attName, attValue ){
	if ( attValue == null || attValue.length == 0 )
		element.removeAttribute( attName, 0 ) ;			// 0 : Case Insensitive
	else
		element.setAttribute( attName, attValue, 0 ) ;	// 0 : Case Insensitive
}

function GetAttribute( element, attName, valueIfNull ){
	var oAtt = element.attributes[attName] ;

	if ( oAtt == null || !oAtt.specified )
		return valueIfNull ? valueIfNull : '' ;

	var oValue = element.getAttribute( attName, 2 ) ;

	if ( oValue == null )
		oValue = oAtt.nodeValue ;

	return ( oValue == null ? valueIfNull : oValue ) ;
}

function SelectField( elementId, isselect ){
	var element = GetE( elementId ) ;
	element.focus() ;

	if(isselect){
		// element.select may not be available for some fields (like <select>).
		if ( element.select ){ element.select();}
	}
}

// Functions used by text fields to accept numbers only.
var IsDigit = ( function(){
	var KeyIdentifierMap =
	{
		End			: 35,
		Home		: 36,
		Left		: 37,
		Right		: 39,
		'U+00007F'	: 46		// Delete
	} ;

	return function ( e )
		{
			if ( !e )
				e = event ;

			var iCode = ( e.keyCode || e.charCode ) ;

			if ( !iCode && e.keyIdentifier && ( e.keyIdentifier in KeyIdentifierMap ) )
					iCode = KeyIdentifierMap[ e.keyIdentifier ] ;

			return (
					( iCode >= 48 && iCode <= 57 )		// Numbers
					|| (iCode >= 35 && iCode <= 40)		// Arrows, Home, End
					|| iCode == 8						// Backspace
					|| iCode == 46						// Delete
					|| iCode == 9						// Tab
			) ;
		}
} )() ;

String.prototype.trim = function(){ return this.replace( /(^\s*)|(\s*$)/g, '' );}

function getElementsByClassName(clsName,htmltag){   
    var arr = new Array();   
    var elems = document.getElementsByTagName(htmltag);  
    for ( var cls, i = 0; ( elem = elems[i] ); i++ ){if(elem.className == clsName ){arr[arr.length] = elem; }}  
    return arr;  
};

function showorhideTag(visibility,htmltag){
	var els = document.getElementsByTagName(htmltag);
	for (var i = 0; i < els.length; i++) {
		els[i].style.visibility=visibility; 
	}
}

function setTextFocus(formKey,theText){	
	document.forms[formKey].elements[theText].select();
	document.forms[formKey].elements[theText].focus();	
}

function isNumeric(theString){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Validate whether the string is numeric
//  Return Type         :   boolean
//--------------------------------------------------------------------------------
	var num=theString;
	num=num*1 + "";
	if(num=="NaN")
		return false;
	else
		return true;
}

function checkDate(formKey,elementName,Separation){	
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         07/18/2003   	the form element must no be blank
//	Return Type         :   boolean
//--------------------------------------------------------------------------------	
	var theDate=document.forms[formKey].elements[elementName].value;	
	var theYear,theMonth,theDay 
	var aryDate,intUbound
	var result;
	aryDate=theDate.split(Separation)
	intUbound=aryDate.length;
	if(intUbound!=3){
		result=false;
	}else{
		theYear=aryDate[0]*1;
		theMonth=aryDate[1]*1;
		theDay=aryDate[2]*1;
		if(isNumeric(theYear) && isNumeric(theMonth) && isNumeric(theDay) ){			// 各段必须是数字 
			if(theYear<1900 || theYear>2500){		//- 年
				result=false;
			}else{
				if(theMonth<1 || theMonth>12){		//- 月
					result=false;
				}else{
					if(theDay<1 || theDay>31){		//- 日
						result=false;
					}else{
						result=true;
					}
				}
			}
		}else{
			result=false;
		}
	}
	if(result==false){
		alert("请输入格式正确的日期，如【2004" + Separation +  "5" + Separation +  "5】！");
		setTextFocus(formKey,elementName);
	}
	return result;
}

function checkFile(formKey,fileElement,fileList,allowOrDeny){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         08/27/2003   	Check upload file type
//  Return Value        :   if check successfully return true ,otherwise return false
//	Return Type         :   boolean
//--------------------------------------------------------------------------------		
	var aryTemp;
	var fileName;
	var fileType;	
	var fileListString="," + fileList + ",";
	var theFile=document.forms[formKey].elements[fileElement];
	var theValue=theFile.value;
	var result;
	var promptString;
	var len;
	var chr;

	if(theValue*0==0) return true;
		
	fileListString=fileListString.toLowerCase();
		
	//文件名
	aryTemp=theValue.split("\\");	
	if(aryTemp.length==1){		//- 不是选择的文件路径，可能是手动胡乱输入字符 
		alert("请选择上传的文件！");
		setTextFocus(formKey,fileElement);
		return false;
	}
	fileName=aryTemp[aryTemp.length-1];
	
	
	/*
	//EnglishChar : validate all characters
	len=fileName.length;	
	
	for(var i=0;i<len;i++){
		chr=fileName.charAt(i);
		if(EnglishChar.indexOf(chr)==-1){
			//alert("The file name must be English!?);
			alert("文件名称不能够是中文！");			
			setTextFocus(formKey,fileElement);
			return false;
		}
	}
	*/
	
	//文件后缀
	aryTemp=fileName.split(".");	
	if(aryTemp.length==1 ){
		fileType="";
	}else{
		fileType=aryTemp[aryTemp.length-1];		
	}	
	
	//检查文件类型
	if(fileType==""){
		result=false;
	}else{
		fileType="," + fileType + ","
		fileType=fileType.toLowerCase();
		if(allowOrDeny==true){		//允许的文件的列表
			if(fileListString.indexOf(fileType)== -1){
				result=false;
				promptString="文件类型错误！\n文件后缀限制如下：\n" + fileList;
				//promptString="Invalid file type!\nOnly " + fileList;
			}else{				
				result=true;
			}
		}else{				////禁止的文件的列表
			if(fileListString.indexOf(fileType) != -1){
				result=false;
				promptString="文件类型错误！\n文件后缀不能是：\n" + fileList;
				//promptString="Invalid file type!\nPostfix can't be " + fileList;
			}else{
				result=true;
			}			
		}
	}	
	
	if(result==false){
		alert(promptString);
		setTextFocus(formKey,fileElement);
		return false;
	}else{
		return true;
	}
}

function isPositive(theString){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Validate whether the string is positive number(正数)
//  Return Value        :   true/false
//  Return Type         :   boolean
//--------------------------------------------------------------------------------
	if (isNumeric(theString)) {
		if (theString>=0){
			return true;
		}else{
			return false;
		}
	}else{
		return false;
	}
}

function isPositiveInteger(theString){	
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Validate whether the string is positive integer(正整数)
//  Return Value        :   true/false
//  Return Type         :   boolean
//--------------------------------------------------------------------------------
	//Is numeric?
	if (isNumeric(theString)) {
		var num=theString*1
		// >0 ?
		if (num>=0){
			num=num+"";
			//Include pointer "." ?
			if (num.indexOf(".")==-1){
				return true;
			}else{
				return false;
			}
		}else{
			return false;
		}
	}else{
		return false;
	}
}

function isDate(theString){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Validate whether the string is date 
//  Return Value        :   true/false
//	Return Type         :   boolean
//--------------------------------------------------------------------------------
var theDate;
theDate=Date.parse(theString)+"";
if (theDate=="NaN" )
	return false;	
else
	return true;
}

function checkEmailList(formKey,Email,mustInput){
	var result=true;
	var EmailList=document.forms[formKey].elements[Email].value;				
	EmailList=StringReplace(EmailList," ","");	
	document.forms[formKey].elements[Email].value=EmailList;	
	
	if(EmailList!=""){			//- 输入不是空白
		var aryEmail=new Array(); 
		var i=0;
		var len=0; 
				
		aryEmail=EmailList.split(",");
		len=aryEmail.length;
		for(i=0;i<len;i++){
			if(checkEmail(aryEmail[i])==false){				
				result=false;
				break;
			}
		}		
	}else{		//- 输入是空白 
		if(mustInput==true){
			result=false;
		}else{
			result=true;
		}
	}
	
	if(result==false){
		alert("请输入正确的邮件地址，\n各个地址之间用半角逗号(,)分隔。");
		setTextFocus(formKey,Email); 
	}
	
	return result; 
}



function checkEmail(EmailAddress){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Validate whether the string is date
//	Return Type         :   boolean
//--------------------------------------------------------------------------------	
	var i=0;
	var chr;
	var len;
	
	len=EmailAddress.length;
	
	//validate all characters
	for(i=0;i<len;i++){
		chr=EmailAddress.charAt(i);
		if(EmailChar.indexOf(chr)==-1){			
			return false;
		}
	}
	
	//Email address must include "@"
	if(EmailAddress.indexOf("@")==-1) return false;		
	//Email address must include "."
	if(EmailAddress.indexOf(".")==-1) return false;	
	//Email address must include only one "@"
	if(EmailAddress.lastIndexOf("@")!=EmailAddress.indexOf("@")) return false;
	//"@" must not be the first or last character
	if(EmailAddress.indexOf("@")==0 || EmailAddress.lastIndexOf("@")==len-1 ) return false;
	//"." must be not the first or last character
	if(EmailAddress.indexOf(".")==0 || EmailAddress.lastIndexOf(".")==len-1 ) return false;
	
	//OK
	return true;
}

function mustNotBlank(formKey,elementName,minLen,maxLen,PromptString){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         07/18/2003   	the form element must no be blank
//  Parameters		:
//	formKey				Input		the name or index of the form
//	elementName			Input		the name or element
//	minLen				Input		the min length
//	maxLen				Input		the max length, -1 : infinite
//	PromptString		Input		the prompted string
//
//  Return Value        :   None
//	Return Type         :   None
//	Functions Called    :	setTextFocus
//
//--------------------------------------------------------------------------------	
	var element=document.forms[formKey].elements[elementName];
	var theValue=element.value;
	var len=theValue.length;
	var i;
	var beBlank=true;
	//- must not be blank	
	for(i=0;i<len;i++){
		if(theValue.charAt(i)!=" "){
			beBlank=false;
			break;
		}
	}
	if(beBlank==true){
		alert(PromptString);
		setTextFocus(formKey,elementName);
		return false;
	}	
	
	//- minimal length
	if(len<minLen){
		alert(PromptString);
		setTextFocus(formKey,elementName);
		return false;	
	}
	//- maximal length ,-1:infinite
	if(maxLen!=-1){
		if(len>maxLen){
			alert(PromptString);
			setTextFocus(formKey,elementName);
			return false;
		}
	}
	return true;
}


function checkSilimarText(formKey,prefix,checkBoxName,mixLen,MaxLen,promptString){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         07/18/2003   	the form element must no be blank
//  Parameters		:
//	formKey				Input		the name or index of the form
//	prefix				Input		the name prefix of the text
//	checkBoxName		Input		the name or check box control array
//	minLen				Input		the min length
//	maxLen				Input		the max length, -1 : infinite
//	PromptString		Input		the prompted string
//
//  Return Value        :   if check successfully return true ,otherwise return false
//	Return Type         :   boolean 
//	Functions Called    :	mustNotBlank
//
//--------------------------------------------------------------------------------	
	var theForm=document.forms[formKey];	
	var elementName;
	var i,len;
	var ID;
	len=theForm.elements[checkBoxName].length; 	
	for(i=0;i<len;i++){
		ID=theForm.elements[checkBoxName][i].value;
		if(theForm.elements[checkBoxName][i].checked){
			if(!mustNotBlank(formKey,prefix+ID,mixLen,MaxLen,promptString)){ 
				return false; 
				break;
			} 
		}	
	}	
	return true;
}


function selectAll(formKey,selectAll,checkBoxName){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         07/14/2003   	选择“全选”则将Checkbox数组全选
//  Parameters		:
//  Name				Mode		Description
//	formKey				Input		the name or index of the form
//	selectAll			Input		the name of the "select all" check box
//	checkBoxName		Input		the name of the check box
//
//  Return Value        :   None
//	Return Type         :   None
//--------------------------------------------------------------------------------	
	var i;
	var len;
	var selectedStatus;

	len=document.forms[formKey].elements.length;	
	if(document.forms[formKey].elements[selectAll].checked){
		selectedStatus=true;
	}else{
		selectedStatus=false;
	}
	
	for(i=0;i<len-1;i++){
		if(document.forms[formKey].elements[i].name==checkBoxName&&document.forms[formKey].elements[i].disabled!=true){
			document.forms[formKey].elements[i].checked=selectedStatus ;
		}
	}		
}

function getFileName(fullPath){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         07/14/2003   	Return file name according to the full path
//  Parameters		:
//  Name				Mode		Description
//	fullPath			Input		the full path of the file
//
//  Return Value        :   File name
//	Return Type         :   String
//--------------------------------------------------------------------------------	
	var index,len;
	var fileName;	
	len=fullPath.length;
	index=fullPath.lastIndexOf("\\");
	return(fullPath.substring(index+1,len).toLowerCase());
}

function getFilePostfix(fileName){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         07/14/2003   	Return file postfix according to the file name
//  Parameters		:
//  Name				Mode		Description
//	fileName			Input		File name
//
//  Return Value        :   File postfix
//	Return Type         :   String
//--------------------------------------------------------------------------------	
	var index,len;	
	len=fileName.length;	
	index=fileName.lastIndexOf(".");	
	return(fileName.substring(index+1,len).toLowerCase());	
}



function StringReplace(theString,reStr,newStr){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Check the user name
//								UpperLetters,LowerLetters,number is default.
//  Parameters		:
//  Name				Mode		Description
//	theString			Input		The string to be replaced
//	reStr				Input		Replaced string
//	newStr				Input		New string
//
//  Return Value        :   The new string
//	Return Type         :   String
//--------------------------------------------------------------------------------	

	var i,len;
	var result=theString;
	
	len=theString.length;
	for(i=0;i<len;i++){
		result=result.replace(reStr,newStr);
	}	
	return result;
}


function addToQueue(queue,subString,separator,append){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         02/26/2005   	Check the user name
//								Add the sub string to the string queue
//  Parameters		:
//  Name				Mode		Description
//	queue				Input		The queue string
//	subString			Input		The string to be added
//	separator			Input		The separator
//	append				Input		append sub string ,no cover the existing item
//
//  Return Value        :   The new string
//	Return Type         :   String
//--------------------------------------------------------------------------------	
	//- 删除空格
	var Queue=StringReplace(queue," ","");
	if(Queue==""){		
		return subString;		
	}else{	
		if(append){
			Queue += (separator + subString);
		}else{
			if((separator + Queue + separator).indexOf(separator + subString + separator)==-1){
				Queue += (separator + subString);
			}
		}
		return Queue;
	}		
	
}

function deleteFromQueue(queue,subString,separator){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         02/26/2005   	Check the user name
//								Delete the sub string from the string queue
//  Parameters		:
//  Name				Mode		Description
//	queue				Input		The queue string
//	subString			Input		The string to be added
//	separator			Input		The separator
//
//  Return Value        :   The new string
//	Return Type         :   String
//--------------------------------------------------------------------------------	
	var Queue=StringReplace(queue," ","");
	if(Queue==""){
		return "";
	}else if(Queue==subString){
		return "";
	}else{		
		intIndex=(separator + Queue + separator).indexOf(separator + subString + separator);
				
		//- 子字符串必须存在
		if(intIndex != -1){
			//- 在开头			
			if(intIndex==0){
				Queue=StringReplace(separator + Queue,separator + subString + separator,"");				
			//- 在末尾
			}else if(intIndex==(separator + Queue + separator).length - subString.length - 2 * separator.length ){
				Queue=StringReplace(Queue + separator,separator + subString + separator,"");	
			}else{			//- 在中间
				Queue=StringReplace(Queue,separator + subString + separator,separator);			
			}
		}
		return Queue;
	}		
}



function checkNumber(formKey,elementName,PromptString,onlyInteger,onlyPositive){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Check value of the text is number
//								
//  Parameters		:
//  Name				Mode		Description
//	formKey				Input		the name or index of the form
//	elementName			Input		the name or element
//	PromptString		Input		the prompted string
//	onlyInteger			Input		only integer
//	onlyPositive		Input		only positive
//
//  Return Value        :   true/false
//	Return Type         :   boolean
//--------------------------------------------------------------------------------
	var i,len;
	var strValue=document.forms[formKey].elements[elementName].value;
	//- Delete all blank 
	strValue=StringReplace(strValue," ","");
	document.forms[formKey].elements[elementName].value=strValue;
	len=strValue.length;
		
	var beChartOK=true;	
	var strNumbers=Numbers;
	if(onlyInteger==false){
		strNumbers=strNumbers + ".";
	}	
	if(onlyPositive==false){
		strNumbers=strNumbers + "-";
	}	
	
	//Check each character
	for(i=0;i<len;i++){
		chr=strValue.charAt(i);
		if(strNumbers.indexOf(chr)==-1){			
			beChartOK=false;
		}
	}
		
	//Check whether is space string
	if(textIsBlank(formKey,elementName)) beChartOK=false;
	
	if(!beChartOK){
		alert(PromptString);
		setTextFocus(formKey,elementName);
		return false;
	}
	
	//must be numeric
	if(strValue*0 !=0){
		alert(PromptString);
		setTextFocus(formKey,elementName);
		return false;
	}
	
	// must be positive
	/*
	if(onlyPositive){
		if(strValue*1 ==0){
			alert(PromptString);
			setTextFocus(formKey,elementName);
			return false;
		}
	}
	*/
	
	return true;	
}


function checkSimilarNumber(formKey,NumberTextPrefix,checkBoxName,PromptString,onlyInteger,onlyPositive){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Check value of the text is number
//								
//  Parameters		:
//  Name				Mode		Description
//	formKey				Input		the name or index of the form
//	NumberTextPrefix	Input		the prefix of the number text 
//	checkBoxName		Input		the name or check box control array
//	PromptString		Input		the prompted string
//	onlyInteger			Input		only integer
//	onlyPositive		Input		only positive
//
//  Return Value        :   true/false
//	Return Type         :   boolean
//--------------------------------------------------------------------------------	
	var theForm=document.forms[formKey];	
	var elementName;
	var i,len;
	var ID;
	len=theForm.elements[checkBoxName].length; 	
	for(i=0;i<len;i++){
		ID=theForm.elements[checkBoxName][i].value;
		if(theForm.elements[checkBoxName][i].checked){
			if(!checkNumber(formKey,NumberTextPrefix+ID,PromptString,onlyInteger,onlyPositive)){ 
				return false; 
				break;
			} 
		}	
	}	
	return true;
}


function textIsBlank(formKey,theText){
	var ele=document.forms[formKey].elements[theText];
	var theValue=ele.value;
	var len=theValue.length;
	var i;
	var beBlank=true;

	for(i=0;i<len;i++){
		if(theValue.charAt(i)!=" "){
			beBlank=false;
			break;
		}
	}
	return beBlank;
}


function MustBeNumber(formKey,elementName,SpecChar,PromptString){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Check value of the text is number
//								
//  Parameters		:
//  Name				Mode		Description
//	formKey				Input		the name or index of the form
//	elementName			Input		the name or element
//	SpecChar			Input		included special characters
//	PromptString		Input		the prompted string
//
//  Return Value        :   true/false
//	Return Type         :   boolean
//--------------------------------------------------------------------------------	

	var i,len;
	var strValue=document.forms[formKey].elements[elementName].value;
	var beChartOK=true;
	var strNumbers=Numbers + " " + SpecChar;
	len=strValue.length;
	
	//Check each character
	for(i=0;i<len;i++){
		chr=strValue.charAt(i);
		if(strNumbers.indexOf(chr)==-1){			
			beChartOK=false;
		}
	}
	
	//Check whether is space string
	if(textIsBlank(formKey,elementName)) beChartOK=false;
	
	if(!beChartOK){
		alert(PromptString);
		setTextFocus(formKey,elementName);
		return false;
	}
	return true;	
}


function SelectControlArrayAll(formKey,elementName,allSelected){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Check value of the text is number
//								
//  Parameters		:
//  Name				Mode		Description
//	formKey				Input		the name or index of the form
//	elementName			Input		the name or element
//	allSelected			Input		all selected status
//
//  Return Value        :   none
//	Return Type         :   none
//--------------------------------------------------------------------------------
	var ele =document.forms[formKey].elements[elementName];
	var i,len;
	if(ele.length *	 0 !=0){		//Only one ,not control array
		ele.checked=allSelected;
	}else{
		len=ele.length ;
		for(i=0;i<len;i++){
			ele[i].checked=allSelected ;
		}	
	}
}

function CheckControlArray(formKey,checkBoxName,promptString){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Check value of the text is number
//								
//  Parameters		:
//  Name				Mode		Description
//	formKey				Input		the name or index of the form
//	checkBoxName		Input		the name or check box control array
//	promptString		Input		the prompt string
//
//  Return Value        :   none
//	Return Type         :   none
//--------------------------------------------------------------------------------
	var ele =document.forms[formKey].elements[checkBoxName];
	var i,len;
	var blnOK=false;
	if(ele.length *	 0 !=0){		//Only one ,not control array
		blnOK=ele.checked;
	}else{
		len=ele.length ;
		for(i=0;i<len;i++){
			if(ele[i].checked){
				blnOK=true;
				break;
			}
		}	
	}
	
	if(!blnOK){
		alert(promptString);
		SetControlArrayFocus(formKey,checkBoxName);
	}
	return blnOK;
}


function CheckboxArrayIsSelected(checkBoxName,promptString){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	检查Checkbox数组是否选择（至少选择一个）
//								
//  Parameters		:
//  Name				Mode		Description
//	formKey				Input		the name or index of the form
//	checkBoxName		Input		the name or check box control array
//	promptString		Input		the prompt string
//
//  Return Value        :   none
//	Return Type         :   none
//--------------------------------------------------------------------------------	
	var ele = document.all[checkBoxName];
	var i,len ;
	var blnOK = false;
	if(ele.length *	 0 !=0){		//Only one ,not control array
		blnOK=ele.checked;
	}else{
		len=ele.length ;
		for(i=0;i<len;i++){
			if(ele[i].checked){
				blnOK=true;
				break;
			}
		}	
	}
	
	if(!blnOK){
		alert(promptString);		
		ele[0].focus();
	}
	return blnOK;
}


function GetSelectedCheckboxLength(formKey,checkBoxName){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Check value of the text is number
//								
//  Parameters		:
//  Name				Mode		Description
//	formKey				Input		the name or index of the form
//	checkBoxName		Input		the name or check box control array
//	promptString		Input		the prompt string
//
//  Return Value        :   none
//	Return Type         :   none
//--------------------------------------------------------------------------------
	var ele =document.forms[formKey].elements[checkBoxName];
	var i,len;
	var result=0;
	
	if(ele.length *	 0 !=0){		//Only one ,not control array
		if(ele.checked) result=1;
	}else{
		len=ele.length ;
		for(i=0;i<len;i++){
			if(ele[i].checked){
				result++;
			}
		}	
	}
	
	return result;
}

function SetControlArrayFocus(formKey,elementName){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Check value of the text is number
//								
//  Parameters		:
//  Name				Mode		Description
//	formKey				Input		the name or index of the form
//	elementName			Input		the name or element
//
//  Return Value        :   none
//	Return Type         :   none
//--------------------------------------------------------------------------------
	var ele =document.forms[formKey].elements[elementName];
	if(ele.length *	 0 !=0){		//Only one ,not control array
		ele.focus();
	}else{
		ele[0].focus();
	}
}


function getSelectedIDSList(formKey,checkBoxName){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         04/25/2004   	get selected checkbox value
//								
//  Parameters		:
//  Name				Mode		Description
//	formKey				Input		the name or index of the form
//	checkBoxName		Input		the name or checkbox control array
//
//  Return Value        :   none
//	Return Type         :   none
//--------------------------------------------------------------------------------
	var i,len;
	var result;
	var collection=document.forms[0].elements[checkBoxName];
	len=collection.length;
	result="";
	for(i=0;i<len;i++ ){
		if(collection[i].checked==true){
		if(result==""){
				result=collection[i].value;
			}else{
				result=result + "," +  collection[i].value;
			}
		}
	}
	return result;
}

function getSelectedIDSArray(formKey,checkBoxName){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         04/25/2004   	get selected checkbox value
//								
//  Parameters		:
//  Name				Mode		Description
//	formKey				Input		the name or index of the form
//	checkBoxName		Input		the name or checkbox control array
//
//  Return Value        :   none
//	Return Type         :   none
//--------------------------------------------------------------------------------
	var i,j,len;
	var aryResult=new Array();
	var collection=document.forms[formKey].elements[checkBoxName];
	len=collection.length;	
	j=0;
	for(i=0;i<len;i++ ){
		if(collection[i].checked==true){
			aryResult[j++]=collection[i].value;
		}
	}
	return aryResult;
}





function CompareDate(formKey,startDate,endDate){	
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         04/29/2004   	End date must be later than begin date
//								
//  Parameters		:
//  Name				Mode		Description
//	formKey				Input		the name or index of the form 
//	startDate			Input		start date form element
//	endDate				Input		end date form element
//
//  Return Value        :   true / false
//	Return Type         :   boolean
//
//--------------------------------------------------------------------------------
	var strFromDate=document.forms[formKey].elements[startDate].value ;
	var strToDate=document.forms[formKey].elements[endDate].value ;
	var theyear,theMonth,theDay;
	var aryDate;
	
	aryDate=strFromDate.split("-");
	theyear=aryDate[0];
	theMonth=aryDate[1];
	theDay=aryDate[2];	
	var fromDate=new Date(theyear,theMonth,theDay);
	
	aryDate=strToDate.split("-");
	theyear=aryDate[0];
	theMonth=aryDate[1];
	theDay=aryDate[2]; 	
	var toDate=new Date(theyear,theMonth,theDay);
	
	if(Date.parse(toDate.toGMTString())-Date.parse(fromDate.toGMTString())<0){
		alert("请检查日期时间是否正确！");
		setTextFocus(formKey,endDate);
		return false;
	}	
	return true;
}


function checkRadio(formKey,elementName,PromptString){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         04/29/2004   	End date must be later than begin date
//	Return Type         :   boolean
//--------------------------------------------------------------------------------
	var ele=document.forms[formKey]	.elements[elementName];
	
	if(ele.length *	 0 !=0){		//Only one ,not control array
		blnSelected=ele.checked;
	}else{	
		var len=ele.length;
		var blnSelected=false;
		for(i=0;i<len;i++){
			if(ele[i].checked){
				blnSelected=true;
				break;
			}
		}
	}
	
	if(!blnSelected){
		alert(PromptString);
		if(ele.length *	 0 !=0)
		{
			ele.focus();
		}
		else
		{
			ele[0].focus();
		}
		return false;
	}else{
		return true;
	}
}


function getRadioValue(formKey,elementName){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         04/29/2004   	End date must be later than begin date
//	Return Type         :   string
//--------------------------------------------------------------------------------
	var ele=document.forms[formKey]	.elements[elementName];	
	if(ele.length *	0 !=0){		//Only one ,not control array
		if(ele.checked)	return ele.value;
	}else{	
		var len=ele.length;
		var blnSelected=false;
		for(i=0;i<len;i++){
			if(ele[i].checked){
				return ele[i].value;
				break;
			}
		}
	}
		
	return "";
}
