//------------------------------------------------------------------------------*/
//                            Copyright Notice							        */
//                            ~~~~~~~~~~~~~~~~							        */
//		Copyright (C) 2003  By Yongchuang Electronic Commerce Co.,Ltd.			*/
//																				*/
//		All rights reserved. This material is confidential and	proprietary to	*/
//	Yongchuang Electronic Commerce Co.,Ltd. and no part	of this material should	*/
//	be reproduced,published in any form	by any means,electronic or mechanical	*/
//	including photocopy	or any information storage or retrieval system nor		*/
//	should the material be disclosed to third parties without the express		*/
//	written authorization of Yongchuang Electronic Commerce Co.,Ltd.			*/
//																				*/
//------------------------------------------------------------------------------*/

//================================================================
//
//	File Name	:	Function.js
//
//	File Type	:	javascript source file
//
//	Author		:	Andy Wang
//	E-mail		:	King_wda@163.net
//
//	Purpose		:	common javascript function
//
//	Date		:	05/20/2003
//
//	Modification:	05/20/2003
//
//================================================================


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 ;



function isNumeric(theString){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Validate whether the string is numeric
//  Parameters		:
//  Name				Mode		Description
//  theNumber			Input		the validated string
//
//  Return Value        :   true/false
//  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
//  Parameters		:
//	formKey				Input		the name or index of the form
//	elementName			Input		the name or element
//	Separation			Input		the separation of the date string 
//
//  Return Value        :   true or false
//	Return Type         :   boolean
//	Functions Called    :	setTextFocus 
//
//--------------------------------------------------------------------------------	
	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 isPositive(theString){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Validate whether the string is positive number
//  Parameters		:
//  Name				Mode		Description
//  theNumber			Input		the validated string
//
//  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
//  Parameters		:
//  Name				Mode		Description
//  theNumber			Input		the validated string
//
//  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
//  Parameters		:
//  Name				Mode		Description
//	theNumber			Input		the validated string
//
//  Return Value        :   true/false
//	Return Type         :   boolean
//--------------------------------------------------------------------------------
var theDate;
theDate=Date.parse(theString)+"";
if (theDate=="NaN" )
	return false;	
else
	return true;
}


function checkPassword(Password,HaveUpper,HaveLower,HaveSpecial,MinLen,MaxLen){	
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Validate format of the password 
//  Parameters		:
//  Name				Mode		Description
//	Password			Input		the validated password
//	HaveUpper			Input		indicate password must have uppercase letter
//	HaveLower			Input		indicate password must have lowercase letter
//	HaveSpecial			Input		indicate password must have special letter
//	MinLen				Input		indicate minimum length of password 
//	MaxLen				Input		indicate maximal length of password 
//
//  Return Value        :   true/false
//  Return Type         :   boolean
//--------------------------------------------------------------------------------
	var i;
	var chr;
	var blnFound;
	var len;
	
	len=Password.length;
	
	//length must be between MinLen and MaxLen
	if (len<MinLen ||len> MaxLen){
		return false;
	}
	
	//Must have uppercase letters	
	if (HaveUpper==true){
		blnFound=false;
		for(i=0;i<len;i++){
			chr=Password.charAt(i);
			if (UpperLetters.indexOf(chr)!=-1){			//Password include uppercaes letter
				blnFound=true;
				break;
			}
		}
		if (!blnFound){
			return false;
		}
	}
	
	//Must have lowercase letters	
	if (HaveLower==true){
		blnFound=false;
		for(i=0;i<len;i++){
			chr=Password.charAt(i);
			if (LowerLetters.indexOf(chr)!=-1){			//Password include uppercaes letter
				blnFound=true;
				break;
			}
		}
		if (!blnFound){
			return false;
		}
	}
	
	//Must have special letters	
	if (HaveSpecial==true){
		blnFound=false;
		for(i=0;i<len;i++){
			chr=Password.charAt(i);
			if (SpecialChar.indexOf(chr)!=-1){			//Password include uppercaes letter
				blnFound=true;
				break;
			}
		}
		if (!blnFound){
			return false;
		}
	}	
	//ok.
	return true;
}

function setTextFocus(formKey,theText){	
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Validate whether the string is date
//  Parameters		:
//  Name				Mode		Description
//	formKey				Input		the name or index of the form
//	theText				Input		the name of the selected control
//
//  Return Value        :   None
//	Return Type         :   None
//--------------------------------------------------------------------------------		
	document.forms[formKey].elements[theText].select();
	document.forms[formKey].elements[theText].focus();	
}


function SetOnlyRead(formKey,control){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Set control readonly
//  Parameters		:
//  Name				Mode		Description
//	formKey				Input		the name or index of the form
//	control				Input		the name of the control
//
//  Return Value        :   None
//	Return Type         :   None
//--------------------------------------------------------------------------------	
	var theContainer;
	theContainer=window.navigator.appName ;
	if(theContainer.indexOf("Microsoft")==-1){
		document.forms[formKey].elements[control].readOnly=true;
		document.forms[formKey].elements[control].style.backgroundColor="#E3E3E3";
	}else{		//Microsoft Internet Explorer	
		document.forms(formKey).elements(control).style.backgroundColor="#E3E3E3";	
		document.forms(formKey).elements(control).readOnly=true;
	}
}

function checkFormEmail(formKey,Email){
	var theEmail=document.forms[formKey].elements[Email].value;
	theEmail=StringReplace(theEmail," ","");
	document.forms[formKey].elements[Email].value=theEmail;
	if(!mustNotBlank(formKey,Email,1,100,"请填写邮件地址。")) return false;
	if(!checkEmail(document.forms[formKey].elements[Email].value)){
		alert("请填写正确的邮件地址。");
		setTextFocus(formKey,Email);
		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
//  Parameters		:
//  Name				Mode		Description
//	EmailAddress		Input		the email address
//
//  Return Value        :   true/false
//	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 refreshOpener(){	
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Refresh the opener of the current window
//  Parameters		:
//  None
//
//  Return Value        :   None
//	Return Type         :   None
//--------------------------------------------------------------------------------	
	window.opener.location=window.opener.location;	
}
*/


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 SaveSelectedIDS(formKey,checkBoxName,storeText){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         07/14/2003   	将选择项的编号保存在文本框storeText中,以“,”分隔
//  Parameters		:
//  Name				Mode		Description
//	formKey				Input		the name or index of the form
//	checkBoxName		Input		the name of the check box
//	storeText			Input		the text that store ID serial
//
//  Return Value        :   None
//	Return Type         :   None
//--------------------------------------------------------------------------------
	var i;
	var len;
	var IDS;
	IDS="";
	
	len=document.forms[formKey].elements.length;
	
	for(i=0;i<len;i++){
		if(document.forms[formKey].elements[i].name==checkBoxName){			
			if(document.forms[formKey].elements[i].checked){				
				if(IDS==""){
					IDS=document.forms[formKey].elements[i].value;
				}else{
					IDS=IDS+","+document.forms[formKey].elements[i].value;
				}
			}
		}
	}
	
	//alert(IDS);	
	//将选择的文章的编号保存在Text(Hidden)中
	document.forms[formKey].elements[storeText].value=IDS;	
}

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 selectAllCheckBox(checkBoxName){
	var i;
	var len;

	len=document.forms['theForm'].elements.length;

	for(i=0;i<len;i++){
		if(document.forms['theForm'].elements[i].name==checkBoxName&&document.forms['theForm'].elements[i].disabled!=true){
			document.forms['theForm'].elements[i].checked=true ;
		}
	}		
}

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 CheckUserNameChar(formKey,elementName,SpecChar,minLen,maxLen,PromptString){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         05/21/2003   	Check the user name
//								UpperLetters,LowerLetters,number is default.
//  Parameters		:
//  Name				Mode		Description
//	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        :   true/false
//	Return Type         :   boolean
//--------------------------------------------------------------------------------	
	var UserNameChars;
	var UserName=document.forms[formKey].elements[elementName].value;
	var len;
	var beBlank=true;
	var beChartOK=true;
	
	//Get valid characters
	UserNameChars=Alphanumeric + SpecChar;
	
	len=UserName.length;
	
	//- must not be blank	
	for(i=0;i<len;i++){
		if(UserName.charAt(i)!=" "){
			beBlank=false;
			break;
		}
	}
	if(beBlank==true){
		alert(PromptString);
		setTextFocus(formKey,elementName);
		return false;
	}	
	
	//validate all characters
	for(i=0;i<len;i++){
		chr=UserName.charAt(i);
		if(UserNameChars.indexOf(chr)==-1){			
			beChartOK=false;
			break;
		}
	}
	if(!beChartOK){
		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 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 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
//								
//  Parameters		:
//  Name				Mode		Description
//	formKey				Input		the name or index of the form 
//	elementName			Input		the radio control name
//	PromptString		Input		if have not selected,prompt user!
//
//  Return Value        :   true / false
//	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
//								
//  Parameters		:
//  Name				Mode		Description
//	formKey				Input		the name or index of the form 
//	elementName			Input		the radio control name
//
//  Return Value        :   true / false
//	Return Type         :   boolean
//
//--------------------------------------------------------------------------------
	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 "";
}

function maxWindow(){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         12/12/2004   	将窗体放到最大 
//								
//  Parameters		:
//  Name				Mode		Description
//
//  Return Value        :   none
//	Return Type         :   none
//
//--------------------------------------------------------------------------------
	
	window.moveTo(0,0);
	window.resizeTo(window.screen.width,window.screen.height);
}


function minWindow(){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         12/12/2004   	将窗体放到最大 
//								
//  Parameters		:
//  Name				Mode		Description
//
//  Return Value        :   none
//	Return Type         :   none
//
//--------------------------------------------------------------------------------
	
	window.moveTo(1400,1400);
	window.resizeTo(10,10);
}


function resizeWindow(wid,hei){
//--------------------------------------------------------------------------------
//  Author 		:       Andy Wang
//  Version     Date			Description
//  1.0         12/12/2004   	设置窗体尺寸，将窗体置于窗口正中 
//								
//  Parameters		:
//  Name				Mode		Description
//
//  Return Value        :   none
//	Return Type         :   none
//
//--------------------------------------------------------------------------------
	var x= (window.screen.width-wid)/2;
	var y= (window.screen.height-hei)/2; 
	window.moveTo(x,y); 
	window.resizeTo(wid,hei);	
}



//- ********************************************************************

function SelectToRegister(){
	var winHeight=318;
	var winWidth=318;
	var x= (window.screen.width-winWidth)/2;
	var y= (window.screen.height-winHeight)/2;		
	var URL;	
	URL="/TradeLeads/login.asp";
	window.open(URL,"winSelectToRegister","height=" + winHeight +",width="+ winWidth + ",toolbar=no,left=" +x +",top=" + y +",scrollbars=yes,resizable=no");	
}



function viewBigPicture(PicturePath){
	var winHeight=500;
	var winWidth=500;
	var x= (window.screen.width-winWidth)/2;
	var y= (window.screen.height-winHeight)/2;		
	var URL;	
	URL="/BigPicture.asp?PicturePath=" + PicturePath;
	window.open(URL,"winBigPicture","height=" + winHeight +",width="+ winWidth + ",toolbar=no,left=" +x +",top=" + y +",scrollbars=yes,resizable=no");	
}



function viewProduct(ProductID){
	var winHeight=460;
	var winWidth=450;
	var x= (window.screen.width-winWidth)/2;
	var y= (window.screen.height-winHeight)/2;		
	var URL;	
	URL="/admin/Product/ProductView.asp?ProductID=" + ProductID;
	window.open(URL,"winProduct","height=" + winHeight +",width="+ winWidth + ",toolbar=no,left=" +x +",top=" + y +",scrollbars=yes,resizable=no");	
}

function viewMember(MemberID){
	var winHeight=360;
	var winWidth=450;
	var x= (window.screen.width-winWidth)/2;
	var y= (window.screen.height-winHeight)/2;		
	var URL;
	URL="/admin/Member/MemberView.asp?MemberID=" + MemberID;
	window.open(URL,"winMember","height=" + winHeight +",width="+ winWidth + ",toolbar=no,left=" +x +",top=" + y +",scrollbars=no,resizable=no");	
}

function viewOrderLog(OrderID){
	var winHeight=500;
	var winWidth=480;
	var x= (window.screen.width-winWidth)/2;
	var y= (window.screen.height-winHeight)/2;		
	var URL;
	URL="/admin/Order/OrderRecord.asp?OrderID=" + OrderID;
	window.open(URL,"winOrderLog","height=" + winHeight +",width="+ winWidth + ",toolbar=no,left=" +x +",top=" + y +",scrollbars=yes,resizable=no");	
}

function sendCommonEmail(OrderID,Status){
	var winHeight=300;
	var winWidth=500;
	var x= (window.screen.width-winWidth)/2;
	var y= (window.screen.height-winHeight)/2;		
	var URL;
	URL="/admin/Order/CommonEmail.asp?OrderID=" + OrderID+ "&Status="+Status;
	window.open(URL,"winMember","height=" + winHeight +",width="+ winWidth + ",toolbar=no,left=" +x +",top=" + y +",scrollbars=no,resizable=no");	
}

function changeCancelReason(flag){
	var reasonDesc=getSelectedListText(0,"CancelReason"); 	
	if(reasonDesc.indexOf("其它")!=-1){		//- 其它原因 
		document.forms[0].OtherReason.style.display="block";
		setTextFocus(0,"OtherReason") ;
		blnOtherReason=true; 
		if(flag==1) document.forms[0].Content.value=mail1ContentTemplate.replace("#REASON#",document.forms[0].OtherReason.value) ;
	}else{
		document.forms[0].OtherReason.style.display="none";
		blnOtherReason=false;
		if(flag==1) document.forms[0].Content.value=mail1ContentTemplate.replace("#REASON#",reasonDesc) ;
	}
}

function changeOtherReason(){
	document.forms[0].Content.value=mail1ContentTemplate.replace("#REASON#",document.forms[0].OtherReason.value) ;
}

function singleDelivery(inforType,inforID){
	var winDeliveryPage = "/Admin/InfoDelivery/DeliveryPage.asp?InforType=" + inforType + "&InforID=" + inforID; 
	window.open(winDeliveryPage,"winDeliveryPage");
}




//- ********************************Title、Alt显示HTML内容***********************************
//- 调用代码：title="" onmouseover="showPopupText()" onmouseout="fadeIn()"
//- 透明设置
showPopStep = 99;
popOpacity = 99;


//- 函数变量声明 
sPop=null;
curShow=null;
tFadeOut=null;
tFadeIn=null;
tFadeWaiting=null;


function showIt(){
		dypopLayer.className = popStyle;
		dypopLayer.innerHTML = sPop;
		popWidth = dypopLayer.clientWidth;	
		popHeight = dypopLayer.clientHeight;
		
		if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24
			else popLeftAdjust=0;
		if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24
			else popTopAdjust=0;
			
		dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;
		dypopLayer.style.top=MouseY;
		
		//dypopLayer.style.filter="Alpha(Opacity=0)";
		dypopLayer.filters.Alpha.opacity = 0 ;
		dypopLayer.style.display = "block";
		fadeOut();
}


function fadeOut(){
	if(dypopLayer.filters.Alpha.opacity<popOpacity){
		dypopLayer.filters.Alpha.opacity+=showPopStep;
		tFadeOut=setTimeout("fadeOut()",1);
	}
}

function fadeIn(){
	dypopLayer.style.display = "none";
	dypopLayer.filters.Alpha.opacity = 0 ;
}


function showPopupText(){
	var o = event.srcElement;
	MouseX = event.x;
	MouseY = event.y + document.body.scrollTop;
	//alert("event.clientY=" + event.clientY + "\nevent.screenY=" + event.screenY + "\nevent.y=" + event.y+ "\nevent.offsetY=" + event.offsetY);
	//alert(document.body.scrollTop); 	

	if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};
    if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};
	
	sPop=o.dypop;
		
	if(sPop==null || sPop==""){
		dypopLayer.innerHTML="";
		dypopLayer.style.filter="Alpha()";
		dypopLayer.filters.Alpha.opacity=0;	
	}else{
		if(o.dyclass!=null)
			popStyle=o.dyclass; 
		else 
			popStyle="cPopText";
		showIt();
		
	}	
}

document.write("<style type='text/css' id='defaultPopStyle'>");
document.write(".cPopText {  background-color: #F8F8F5;color:#000000; border: 1px #000000 solid;font-color: font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(Opacity=0)}");
document.write("</style>");
document.write("<div id='dypopLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>");
//document.onmouseover=showPopupText;


//- *******************************************************************
 
