/*******************************************************************/
/* notes */
/*******************************************************************/

/* date formate: dd/mm/yyyy */
// if it has to be changed to mm/dd/yyyy,
// modify the lines with +++ at the end in the following functions:
// later_date()
// isValidDate()

/*******************************************************************/

function later_date(later, earlier)
{

	var laterstr = new Array()
	var earlierstr = new Array()
	var latermonth, laterday, earliermonth, earlierday
	
	laterstr = later.split("/")
	earlierstr = earlier.split("/")
	if(laterstr[2]<earlierstr[2])	// year
		return false;
	if(laterstr[2]>earlierstr[2])	// year
		return true;
		
	/* same year: */
	
	latermonth=laterstr[1];	// +++
	earliermonth=earlierstr[1];	// +++
	if(latermonth<earliermonth)
		return false;
	if(latermonth>earliermonth)
		return true;
	
	/* same year and month: */
	
	laterday=laterstr[0];	// +++
	earlierday=earlierstr[0];	// +++
	
	if(laterday<earlierday)
		return false;
	return true;
	
}

function isValid(parm,val)
{

	for(j=0; j<parm.length; j++){
		if(val.indexOf(parm.charAt(j),0) == -1)
			return false;
	}
	return true;
	
}

function isNum(parm)
{

	var numb = '0123456789';

	return isValid(parm,numb);
	
}

function isValidTime(str)
{
	// HH:MM:SS

	var substr = new Array()

	// check length:
	if(str.length!=8)
		return false;
	
	// check separator:
	if(str.charAt(2)!=':' || str.charAt(5)!=':')
		return false;
	substr = str.split(":")
	
	// check number:
	if(!isNum(substr[0]) || !isNum(substr[1]) || !isNum(substr[2]))
		return false;
		
	var hour = substr[0]	// +++
	var minute = substr[1]	// +++
	var second = substr[2]	// +++
	if(hour<0 || hour>23)
		return false;
	if(minute<0 || minute>59)
		return false;
	if(second<0 || second>59)
		return false;
	return true;
		
}

function isValidDate(str)
{
	// dd/mm/yyyy

	var substr = new Array()

	// check length:
	if(str.length!=10)
		return false;
	
	// check separator:
	if(str.charAt(2)!='/' || str.charAt(5)!='/')
		return false;
	substr = str.split("/")
	
	// check number:
	if(!isNum(substr[0]) || !isNum(substr[1]) || !isNum(substr[2]))
		return false;
		
	// check year:
	var curdate = new Date()
	var thisyear = curdate.getYear()
	var year = substr[2]	// +++
	
	if(year<2005)	// from 2005
		return false;
	var month = substr[1]	// +++
	var day = substr[0]	// +++
	
	// check month:
	if(month<1 || month>12)
		return false;	
	
	// check day:	
	var max = 28
	
	if(month==1 || month==3 || month==5 || month==7 ||
		month==8 || month==10 || month==12)
		max = 31;
	else{
		if(month==2){
			if(year%4==0)
				max = 29;		
		}
		else
			max = 30;	
	}	
	
	if(substr[0]<1 || substr[0]>max)
		return false;	
	return true;
		
}

/*******************************************************************/

function checkValidInput2(strCtlIDs, all, strDdlIDs, eng)
{
	// editc() and deletec() use this function!
	// user must input the textbox ("strCtlIDs" separated by ;)
	// if "all"==1, user must input all textboxes
	// "strDdlIDs" refers to dropdown list
	// all dropdownlists must be selected
	
	var val				
	var aryIDs = new Array()
	
	if(checkValidInput(strCtlIDs, all, eng)){
		if(strDdlIDs!=""){
			aryIDs = strDdlIDs.split(";")     
			for (i=0 ; i<aryIDs.length; i++){
				val= document.getElementById(aryIDs[i]).selectedIndex		
				if (val==0){
					if(eng==1)
						alert("Please select the dropdownlist.")
					else
						alert("请选择下拉列表");
					document.getElementById(aryIDs[i]).focus()
					Page_ValidationActive=false;
					return false;
				}
			}
		}
		Page_ValidationActive=true;
		return true;
	}
	Page_ValidationActive=false;
	return false;	
	
}		

function checkValidInput(strCtlIDs, all, eng)
{				
	// checkValidInput2() ,checkValidInputCallClearing() and deleteu() use this function!
	// user must input the textbox ("strCtlIDs" separated by ;)
	// if "all"==1, user must input all textboxes
				
	var aryIDs = new Array()
	
	if(strCtlIDs==""){
		Page_ValidationActive=true;
		return true;
	}
		
	aryIDs = strCtlIDs.split(";")     
	for(i=0 ; i<aryIDs.length; i++){
		val= document.getElementById(aryIDs[i]).value
		if(val=="" && all==1){
			if(eng==1)
				alert("Please fill in the textbox.")
			else
				alert("请填写文本框")
			Page_ValidationActive=false;
			document.getElementById(aryIDs[i]).focus()
			return false;
		}
		if(val!="" && all==0){
			Page_ValidationActive=true;
			return true;
		}
	}
	
	if(all==0){
		if(eng==1)
			alert("Please fill in the textbox.")
		else
			alert("请填写文本框")
		Page_ValidationActive=false;
		return false;
	}
	Page_ValidationActive=true;
	return true;

}

/*******************************************************************/

function resetInput(strCtlIDs, strDdlIDs)
{
	// "strCtlIDs" refers to textbox
	// "strDdlIDs" refers to dropdown list
	// all textboxes will be cleared and dropdownlists will be deselected
				
	var aryIDs = new Array()
	
	if(strCtlIDs!=""){
		aryIDs = strCtlIDs.split(";")     
		for(i=0 ; i<aryIDs.length; i++){
			document.getElementById(aryIDs[i]).value=""
		}
	}
	
	if(strDdlIDs!=""){
		aryIDs = strDdlIDs.split(";")     
		for (i=0 ; i<aryIDs.length; i++){
			document.getElementById(aryIDs[i]).selectedIndex=0
		}
	}

}

/*******************************************************************/
