

//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//

//		FUNCTION CATALOG 

//

//		+ function CHECK_NUMBER_FIELD(InputField,AllowNull, MinValue, MaxValue, FieldLabel)

//		+ function IS_DATE(argDate, DateType)

//		+ function CHECK_DATE_FIELD(InputField, AllowNull, MinValue, MaxValue, FieldLabel)

//		+ function IS_CHECKED(InputField, FieldLabel)

//		+ function CLICK_CHECK_ALL(InputFieldCheckAll, InputFieldArray)

//		+ function GREATER_DATE(Date1, Date2)

//  	+ function EQUAL_DATE(Date1, Date2)

//		+ function LESS_THAN_DATE(Date1, Date2)

//		+ function TRIM( s )

//		+ function CHECK_STRING_FIELD(InputField, AllowNull, MaxLength, FieldLabel)

//		+ function TO_DAY()

//		+ function TO_DATE(argDate)

//		+ function DATE_TO_STRING(d)

//		+ function durationValidate(txtDuration)

//		+ function trim(strString)

//		+ function CHECK_DATE_FROM_TO(InputField1, InputField2, FieldLabel)

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::





//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   CHECK_NUMBER_FIELD

//   PURPOSE         :   Check if the number in field is correct or not.

//   ARGUMENTS       :   + InputField : input number field 

//                       + AllowNull : 1 = allow null; 0 = not allow null

//                       + MinValue : Min of input rangle - Optional

//                       + MaxValue : Max of input rangle - Optional

//						 + FieldLabel : Label for that Field - Optional

//   RETURNS         :   true - InputField is a number

//    				   	 false - InputField not a number

//   AUTHOR          :   AnhNT

//------------------------------------------------------------------------------------------------------------------------------------------

function CHECK_NUMBER_FIELD(InputField, AllowNull, MinValue, MaxValue, FieldLabel)

{

	InputField.value = TRIM(InputField.value)

	if ((InputField.value == "") && (AllowNull == 1))

		return true;

	

	if (InputField.value == "") {

		MSG_ALERT(FieldLabel, "Please input value into " + FieldLabel + "!", "Ch°a nh­p " + FieldLabel + " !");

		InputField.focus();

		return (false);

	}

	

	

	if (!IS_NUMBER(InputField.value)) {

		MSG_ALERT(FieldLabel, FieldLabel + " must be a number !", FieldLabel + " phai la so !");

		InputField.focus();

		return (false);

	

	}

	

	if (IS_NUMBER(MinValue)) {

		if (InputField.value<MinValue) {

			InputField.focus();

			MSG_ALERT(FieldLabel, FieldLabel + " must be >= " + MinValue + " !", FieldLabel + " phai >= " + MinValue + " !");

			return (false);

		}

	}

	

	if (IS_NUMBER(MaxValue)) {

		if (InputField.value>MaxValue) {

			InputField.focus();

			MSG_ALERT(FieldLabel, FieldLabel + " must <= " + MaxValue + " !", FieldLabel + " phai <= " + MaxValue + " !");

			return (false);

		}

	}

	

	return (true);

}





//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   IS_DATE

//   PURPOSE         :   Check if the date in field is correct or not.

//   ARGUMENTS       :   + argDate : input date

//   RETURNS         :   true - InputField is date

//    				     false - InputField is not date

//   AUTHOR          :   AnhNT

//------------------------------------------------------------------------------------------------------------------------------------------

function IS_DATE(argDate)

{

	

	var date_split;

	var i;

	var tday, tmonth, tyear;

	var DateType = APP_DATE_TYPE;

	var tmp;

	var strDate = trim(argDate);

	date_split = strDate.split(APP_DATE_DELIMITER);

	

	//check for date parts

	if (date_split.length != 3)

		return(false);

	

	//check for 4-digit year

	if (date_split[2].length != 4)

		return(false);

	

	//check for valid date, e.g. 02/29/1997

	if (DateType== ENGLISH_DATE) {

		tday = parseFloat(date_split[1]);

		tmonth = parseFloat(date_split[0]);

	}

	else {

		tday = parseFloat(date_split[0]);

		tmonth = parseFloat(date_split[1]);

	}	

	if (tday.length==1) tday = "0"+tday;

	if (tmonth.length==1) tmonth = "0"+tmonth;

	tyear = parseFloat(date_split[2]);

	

	var date = new Date(tyear,tmonth-1,tday);

	

	if (date.getDate() != tday)

		return(false);

	

	if (date.getMonth() != (tmonth-1))

		return(false);



	if (date.getFullYear() != tyear)

		return(false);

	

	if (DateType==ENGLISH_DATE) strDate = tmonth + APP_DATE_DELIMITER + tday + APP_DATE_DELIMITER + tyear;

	if (DateType==FRENCH_DATE) strDate = tday + APP_DATE_DELIMITER + tmonth + APP_DATE_DELIMITER + tyear;

	

	return(true);

}



//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   CHECK_DATE_FROM_TO

//   PURPOSE         :   Check if the date in field is correct or not.

//   ARGUMENTS       :   + InputField1 : input date field from

//                       + InputField2 : input date field to

//						 + FieldLabel : Label for that Field - Optional

//   RETURNS         :   true - InputField is date

//    				     false - InputField is not date

//   AUTHOR          :   AnhNT

//------------------------------------------------------------------------------------------------------------------------------------------

function CHECK_DATE_FROM_TO(InputField1, InputField2, FieldLabel)

{

		dFrom = TRIM(InputField1.value);

		dTo = TRIM(InputField2.value);

		if((dTo != null) &&  (dFrom != null) && (dTo < dFrom) )

		{

			alert(FieldLabel);

			InputField1.focus();

			return (false);

		}

		return(true);

}



//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   CHECK_DATE_FIELD

//   PURPOSE         :   Check if the date in field is correct or not.

//   ARGUMENTS       :   + InputField : input date field

//                       + AllowNull : 1 = allow null; 0 = not allow null

//                       + MinValue : Min of input rangle

//                       + MaxValue : Max of input rangle

//						 + FieldLabel : Label for that Field - Optional

//   RETURNS         :   true - InputField is date

//    				     false - InputField is not date

//   AUTHOR          :   AnhNT

//------------------------------------------------------------------------------------------------------------------------------------------

function CHECK_DATE_FIELD(InputField, AllowNull, MinValue, MaxValue, FieldLabel)

{

	InputField.value = TRIM(InputField.value)

	

	var DateType = APP_DATE_TYPE;

	

	if ((InputField.value == "") && (AllowNull == 1))

		return true;

	

	if (InputField.value == "") {

		MSG_ALERT(FieldLabel, "Please input value into " + FieldLabel + "!", "Chua nhap " + FieldLabel + " !");

		InputField.focus();

		return (false);

	} 

	

	if (!IS_DATE(InputField.value)) {

		MSG_ALERT(FieldLabel, FieldLabel + " must be a date type !", FieldLabel + " phai la dinh dang ngay thang !")

		InputField.focus();

		return (false);

	}

	

	if (IS_DATE(MinValue)) {

		if (GREATER_DATE(MinValue, InputField.value)) {

		

			MSG_ALERT(FieldLabel, FieldLabel + " must >= " + MinValue, FieldLabel + " phai >= " + MinValue);

			InputField.focus();

			return (false);

		}

	}

	

	if (IS_DATE(MaxValue)) {

		if (GREATER_DATE(InputField.value, MaxValue)) {

			MSG_ALERT(FieldLabel, FieldLabel + " must <= " + MaxValue, FieldLabel + " phai <= " + MaxValue);

			InputField.focus();

			return (false);

		}

	}

	

	

	if (GREATER_DATE('1/1/1900', InputField.value)) {

		MSG_ALERT(FieldLabel, FieldLabel + " must >= 1/1/1900", FieldLabel + " phai >= 1/1/1900");

		InputField.focus();

		return (false);

	}

	

	return(true);

}





//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   IS_CHECKED

//   PURPOSE         :   Check if the checkbox is checked or not

//   ARGUMENTS       :   + InputField : input checkbox field

//						 + FieldLabel : Label for that Field - Optional

//   RETURNS         :   true - InputField is checked

//    				     false - InputField is not checked

//   AUTHOR          :   AnhNT

//------------------------------------------------------------------------------------------------------------------------------------------

function IS_CHECKED(InputField, FieldLabel)

{

	var blnReturn = false;

	var strReturn = "";

	if (InputField == null) return (false);

	if (isNaN(InputField.length)) {

		if ((InputField.checked)&&(!InputField.disabled)) {

			blnReturn = true;

			strReturn = InputField.value;

		}

	}

	else

	{

		for (i=0; i<InputField.length; i++) {

			if ((InputField[i].checked)&&(!InputField[i].disabled)) {

				blnReturn = true;

				strReturn = strReturn + "," + InputField[i].value;

			}

		}

	}

	if (blnReturn == false) {

		MSG_ALERT(FieldLabel, FieldLabel + " must be check !", FieldLabel + " ph£i °ăc chÍn !")

	}

	

	ReturnValue = strReturn;

	//alert(ReturnValue);

	return (blnReturn);

}



//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   GET_CHECK_VALUE

//   PURPOSE         :   Get checkbox value

//   ARGUMENTS       :   + InputField : input checkbox field

//   RETURNS         :   strReturn - value of checked box

//   AUTHOR          :   AnhNT

//------------------------------------------------------------------------------------------------------------------------------------------

function GET_CHECK_VALUE(InputField)

{

	var strReturn = "";

	if (InputField == null) return (false);

	if (isNaN(InputField.length)) {

		if ((InputField.checked)&&(!InputField.disabled)) {

			strReturn = ", " + InputField.value;

		}

	}

	else

	{

		for (i=0; i<InputField.length; i++) {

			if ((InputField[i].checked)&&(!InputField[i].disabled)) {

				strReturn = strReturn + "," + InputField[i].value;

			}

		}

	}

	return (strReturn);

}

	

//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   CLICK_CHECK_ALL

//   PURPOSE         :   Check if the checkbox is checked or not

//   ARGUMENTS       :   + InputFieldArray : checkbox field array

//						 + InputFieldCheckAll : checkbox CheckAll

//   RETURNS         :   true - InputField is checked

//    				     false - InputField is not checked

//   AUTHOR          :   AnhNT

//------------------------------------------------------------------------------------------------------------------------------------------

function CLICK_CHECK_ALL(InputFieldCheckAll, InputFieldArray)

{

	if (InputFieldArray == null) return (false);

	if (InputFieldCheckAll.checked) {

		if (isNaN(InputFieldArray.length)) InputFieldArray.checked=true;

		else {

			for (i=0; i<InputFieldArray.length; i++) {

				if (!InputFieldArray[i].disabled) InputFieldArray[i].checked=true;

			}

		}

	}

	else

	{

		if (isNaN(InputFieldArray.length)) InputFieldArray.checked=false;

		else {

			for (i=0; i<InputFieldArray.length; i++) {

				if (!InputFieldArray[i].disabled) InputFieldArray[i].checked=false;

			}

		}

	}

}

	

	

//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   GREATER_DATE

//   PURPOSE         :   Compare two date

//   ARGUMENTS       :   + Date1 

//						 + Date2

//   RETURNS         :   true - Date1 > Date2

//    				     false - Date1 <= Date2

//   AUTHOR          :   AnhNT

//------------------------------------------------------------------------------------------------------------------------------------------

function GREATER_DATE(Date1, Date2)

{

	

	d1 = TO_DATE(Date1);

	d2 = TO_DATE(Date2);

	if ((d1 == null) || (d2 == null))

		return false;

	

	if (d1 > d2)

		return true;

	else

		return false;

	

/*

	  var nPos1, nPos2, nDate1, strDay1, strMonth1, strYear1, strDate1;

	  var nPos11, nPos12, nDate2, strDay2, strMonth2, strYear2, strDate2;

	  var DateType = APP_DATE_TYPE;

	 

	  if (!IS_DATE(Date1)) return false;

	  if (!IS_DATE(Date2)) return false;

	  

	  nPos1 = Date1.indexOf(APP_DATE_DELIMITER);

	  nPos2 = Date1.lastIndexOf(APP_DATE_DELIMITER);

	  

	  nPos11 = Date2.indexOf(APP_DATE_DELIMITER);

	  nPos12 = Date2.lastIndexOf(APP_DATE_DELIMITER);

	  

	  if (DateType==ENGLISH_DATE) {

	  	  strMonth1 = Date1.substring(0, nPos1);

		  strDay1 = Date1.substring(nPos1 + 1, nPos2);

		  strMonth2 = Date2.substring(0, nPos11);

		  strDay2 = Date2.substring(nPos11 + 1, nPos12);



	  }

	  else

	  {

	  	  strDay1 = Date1.substring(0, nPos1);

		  strMonth1 = Date1.substring(nPos1 + 1, nPos2);

		  strDay2 = Date2.substring(0, nPos11);

		  strMonth2 = Date2.substring(nPos11 + 1, nPos12);

	  }

	  

	  if (parseFloat(strMonth1)<10) strMonth1 = "0" + parseFloat(strMonth1) ;

	  if (parseFloat(strMonth2)<10) strMonth2 = "0" + parseFloat(strMonth2) ;

	  if (parseFloat(strDay1)<10) strDay1 = "0" + parseFloat(strDay1) ;

	  if (parseFloat(strDay2)<10) strDay2 = "0" + parseFloat(strDay2) ;

	  

	  strYear1 = Date1.substring(nPos2 + 1);

	  strYear2 = Date2.substring(nPos12 + 1);

	  

	  strDate1 = strYear1 + strMonth1 + strDay1;

	  strDate2 = strYear2 + strMonth2 + strDay2;

	  

	  nDate1 = parseFloat(strDate1, 10);

	  nDate2 = parseFloat(strDate2, 10);



	  if (nDate1 > nDate2) return true;

	  

	  return false;

*/

}





//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   EQUAL_DATE

//   PURPOSE         :   Compare two date

//   ARGUMENTS       :   + Date1 

//						 + Date2

//   RETURNS         :   true - Date1 = Date2

//    				     false - Date1 != Date2

//   AUTHOR          :   AnhNT

//------------------------------------------------------------------------------------------------------------------------------------------

function EQUAL_DATE(Date1, Date2)

{

	d1 = TO_DATE(Date1);

	d2 = TO_DATE(Date2)

	if ((d1 == null) || (d2 == null))

		return false;

	

	if (d1 == d2)

		return true;

	else

		return false;

/*	

	  var nPos1, nPos2, nDate1, strDay1, strMonth1, strYear1, strDate1;

	  var nPos11, nPos12, nDate2, strDay2, strMonth2, strYear2, strDate2;

	  var DateType = APP_DATE_TYPE;

	  

	  if (!IS_DATE(Date1)) return false;

	  if (!IS_DATE(Date2)) return false;

	  

	  nPos1 = Date1.indexOf(APP_DATE_DELIMITER);

	  nPos2 = Date1.lastIndexOf(APP_DATE_DELIMITER);

	  

	  nPos11 = Date2.indexOf(APP_DATE_DELIMITER);

	  nPos12 = Date2.lastIndexOf(APP_DATE_DELIMITER);

	  

	  if (DateType==ENGLISH_DATE) {

	  	  strMonth1 = Date1.substring(0, nPos1);

		  strDay1 = Date1.substring(nPos1 + 1, nPos2);

		  strMonth2 = Date2.substring(0, nPos11);

		  strDay2 = Date2.substring(nPos11 + 1, nPos12);

	  }

	  else

	  {

	  	  strDay1 = Date1.substring(0, nPos1);

		  strMonth1 = Date1.substring(nPos1 + 1, nPos2);

		  strDay2 = Date2.substring(0, nPos11);

		  strMonth2 = Date2.substring(nPos11 + 1, nPos12);

	  }

	  if (parseFloat(strMonth1)<10) strMonth1 = "0" + parseFloat(strMonth1) ;

	  if (parseFloat(strMonth2)<10) strMonth2 = "0" + parseFloat(strMonth2) ;

	  if (parseFloat(strDay1)<10) strDay1 = "0" + parseFloat(strDay1) ;

	  if (parseFloat(strDay2)<10) strDay2 = "0" + parseFloat(strDay2) ;

	  

	  strYear1 = Date1.substring(nPos2 + 1);

	  strYear2 = Date2.substring(nPos12 + 1);

	  

	  strDate1 = strYear1 + strMonth1 + strDay1;

	  strDate2 = strYear2 + strMonth2 + strDay2;

	  

	  nDate1 = parseFloat(strDate1, 10);

	  nDate2 = parseFloat(strDate2, 10);

	  

	  if (nDate1 == nDate2) return true;

	  return false;

*/

}





//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   LESS_THAN_DATE

//   PURPOSE         :   Compare two date

//   ARGUMENTS       :   + Date1 

//						 + Date2

//						 + DateType : "0" - mm/dd/yyyy ; "1" - dd/mm/yyyy

//   RETURNS         :   true - Date1 < Date2

//    				     false - Date1 >= Date2

//   AUTHOR          :   AnhNT

//------------------------------------------------------------------------------------------------------------------------------------------

function LESS_THAN_DATE(Date1, Date2)

{

	d1 = TO_DATE(Date1);

	d2 = TO_DATE(Date2)

	if ((d1 == null) || (d2 == null))

		return false;

	

	if (d1 < d2)

		return true;

	else

		return false;

/*

 	  var nPos1, nPos2, nDate1, strDay1, strMonth1, strYear1, strDate1;

	  var nPos11, nPos12, nDate2, strDay2, strMonth2, strYear2, strDate2;

	  var DateType = APP_DATE_TYPE;

	  

	  if (!IS_DATE(Date1)) return false;

	  if (!IS_DATE(Date2)) return false;

	  

	  nPos1 = Date1.indexOf(APP_DATE_DELIMITER);

	  nPos2 = Date1.lastIndexOf(APP_DATE_DELIMITER);

	  

	  nPos11 = Date2.indexOf(APP_DATE_DELIMITER);

	  nPos12 = Date2.lastIndexOf(APP_DATE_DELIMITER);

	  

	  if (DateType==ENGLISH_DATE) {

	  	  strMonth1 = Date1.substring(0, nPos1);

		  strDay1 = Date1.substring(nPos1 + 1, nPos2);

		  strMonth2 = Date2.substring(0, nPos11);

		  strDay2 = Date2.substring(nPos11 + 1, nPos12);

	  }

	  else

	  {

	  	  strDay1 = Date1.substring(0, nPos1);

		  strMonth1 = Date1.substring(nPos1 + 1, nPos2);

		  strDay2 = Date2.substring(0, nPos11);

		  strMonth2 = Date2.substring(nPos11 + 1, nPos12);

	  }

	  

	  if (parseFloat(strMonth1)<10) strMonth1 = "0" + parseFloat(strMonth1) ;

	  if (parseFloat(strMonth2)<10) strMonth2 = "0" + parseFloat(strMonth2) ;

	  if (parseFloat(strDay1)<10) strDay1 = "0" + parseFloat(strDay1) ;

	  if (parseFloat(strDay2)<10) strDay2 = "0" + parseFloat(strDay2) ;

	  

	  strYear1 = Date1.substring(nPos2 + 1);

	  strYear2 = Date2.substring(nPos12 + 1);

	  

	  strDate1 = strYear1 + strMonth1 + strDay1;

	  strDate2 = strYear2 + strMonth2 + strDay2;

	  

	  nDate1 = parseFloat(strDate1, 10);

	  nDate2 = parseFloat(strDate2, 10);

	  

	  if (nDate1 < nDate2) return true;

	  return false;

*/

}



//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   TRIM

//   PURPOSE         :   TRIM a string

//   ARGUMENTS       :   s

//   RETURNS         :   TRIMmed string 

//   AUTHOR          :   AnhNT

//------------------------------------------------------------------------------------------------------------------------------------------

function TRIM( s )

{

    var i, sRetVal = "";

    i = s.length-1;

    while ( i>=0 && s.charAt(i) == ' ' )

         i--;

    s = s.substring( 0, i+1 ); 

    i = 0;

    while ( i< s.length && s.charAt(i) == ' ')

         i++;

    return s.substring( i );

}



//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   MSG_ALERT

//   PURPOSE         :   Alert a string in VietNamese or English

//   ARGUMENTS       :   + FieldLabel

//						 + ELMessage

//						 + VNMessage

//   AUTHOR          :   AnhNT

//------------------------------------------------------------------------------------------------------------------------------------------

function MSG_ALERT(FieldLabel, ELMessage, VNMessage)

{

	if ((FieldLabel)!="") {

		if (APP_LANGUAGE==0) alert(ELMessage)

		else  alert(VNMessage);

	}

}



//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   IS_NUMBER

//   PURPOSE         :   Alert a string in VietNamese or English

//   ARGUMENTS       :   + InputValue

//   AUTHOR          :   AnhNT

//------------------------------------------------------------------------------------------------------------------------------------------

function IS_NUMBER(InputValue)

{

	if ((InputValue == null)||(InputValue == "")) return (false); 

	var strValue = InputValue.toString();

	if (isNaN(strValue)||(TRIM(strValue)=="")) {

		return (false);

	}

	return (true);

}





//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   CHECK_STRING_FIELD

//   PURPOSE         :   Check if the string is out of length.

//   ARGUMENTS       :   + InputField : input number field 

//                       + AllowNull : 1 = allow null; 0 = not allow null

//                       + MaxLength : Max of input rangle - Optional

//						 + FieldLabel : Label for that Field - Optional

//   RETURNS         :   true - InputField is a correct string

//    				   	 false - InputField not a correct string

//   AUTHOR          :   BinhBT

//------------------------------------------------------------------------------------------------------------------------------------------

function CHECK_STRING_FIELD(InputField, AllowNull, MaxLength, FieldLabel)

{

	InputField.value = TRIM(InputField.value)

		

	if ((InputField.value == "") && (AllowNull == 1))

		return true;

	

	if (InputField.value == "") {

		MSG_ALERT(FieldLabel, "Please input value into " + FieldLabel + "!", "Chua nhap " + FieldLabel + " !");

		InputField.focus();

		return (false);

	}

	if (IS_NUMBER(MaxLength))

		if (InputField.value.length > MaxLength) {

			MSG_ALERT(FieldLabel, "The length of " + FieldLabel + " must <= " + MaxLength, "Do dai cua " + FieldLabel + " phai nho hon hoac bang " + MaxLength);

			InputField.focus();

			return (false);

		}

	return true;

}



//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   TO_DAY

//   PURPOSE         :   Return the date string of current day using define format

//   ARGUMENTS       :   

//   RETURNS         :   date string

//   AUTHOR          :   BinhBT

//------------------------------------------------------------------------------------------------------------------------------------------

function TO_DAY()

{

	var d

	var s = ""

	d = new Date();

	if (APP_DATE_TYPE == FRENCH_DATE)

	{

		if (parseInt(d.getDate(),10) < 10)

			s += "0" + d.getDate() + APP_DATE_DELIMITER;

		else

			s += d.getDate() + APP_DATE_DELIMITER;

		if (parseInt(d.getMonth(),10) < 9)	

	   		s += "0" + (d.getMonth() + 1) + APP_DATE_DELIMITER;

	   	else

	   		s += (d.getMonth() + 1) + APP_DATE_DELIMITER;

	}	

	else

	{

		if (parseInt(d.getMonth(),10) < 9)	

	   		s += "0" + (d.getMonth() + 1) + APP_DATE_DELIMITER;

	   	else

	   		s += (d.getMonth() + 1) + APP_DATE_DELIMITER;

	   	if (parseInt(d.getDate(),10) < 10)

			s += "0" + d.getDate() + APP_DATE_DELIMITER;

		else

			s += d.getDate() + APP_DATE_DELIMITER;

	}

   	s += d.getYear();

   	

   	return s;

}





//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   TO_DATE

//   PURPOSE         :   Convert string to date

//   ARGUMENTS       :   

//   RETURNS         :   date value

//   AUTHOR          :   BinhBT

//------------------------------------------------------------------------------------------------------------------------------------------

function TO_DATE(argDate)

{

	var date_split;

	var i;

	var tday, tmonth, tyear;

	var DateType = APP_DATE_TYPE;

	var tmp;

	

	date_split = argDate.split(APP_DATE_DELIMITER);

	

	//check for date parts

	if (date_split.length != 3)

		return(null);

	

	//check for 4-digit year

	if (date_split[2].length != 4)

		return(null);

	

	//check for valid date, e.g. 02/29/1997

	if (DateType== ENGLISH_DATE) {

		tday = parseFloat(date_split[1]);

		tmonth = parseFloat(date_split[0]);

	}

	else {

		tday = parseFloat(date_split[0]);

		tmonth = parseFloat(date_split[1]);

	}	

	if (tday.length==1) tday = "0"+tday;

	if (tmonth.length==1) tmonth = "0"+tmonth;	

	tyear = parseFloat(date_split[2]);

	

	var date = new Date(tyear,tmonth-1,tday);

	

	if (date.getDate() != tday)

		return(null);

	

	if (date.getMonth() != (tmonth-1))

		return(null);



	if (date.getFullYear() != tyear)

		return(null);

	

	if (DateType==ENGLISH_DATE) argDate = tmonth + APP_DATE_DELIMITER + tday + APP_DATE_DELIMITER + tyear;

	if (DateType==FRENCH_DATE) argDate = tday + APP_DATE_DELIMITER + tmonth + APP_DATE_DELIMITER + tyear;

	

	return(date);

}



//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   TO_DATE

//   PURPOSE         :   Convert string to date

//   ARGUMENTS       :   

//   RETURNS         :   date value

//   AUTHOR          :   BinhBT

//------------------------------------------------------------------------------------------------------------------------------------------

function DATE_TO_STRING(d)

{

	var s = ""



	if (APP_DATE_TYPE == FRENCH_DATE)

	{

		if (parseInt(d.getDate(),10) < 10)

			s += "0" + d.getDate() + APP_DATE_DELIMITER;

		else

			s += d.getDate() + APP_DATE_DELIMITER;

		if (parseInt(d.getMonth(),10) < 9)	

	   		s += "0" + (d.getMonth() + 1) + APP_DATE_DELIMITER;

	   	else

	   		s += (d.getMonth() + 1) + APP_DATE_DELIMITER;

	}	

	else

	{

		if (parseInt(d.getMonth(),10) < 9)	

	   		s += "0" + (d.getMonth() + 1) + APP_DATE_DELIMITER;

	   	else

	   		s += (d.getMonth() + 1) + APP_DATE_DELIMITER;

	   	if (parseInt(d.getDate(),10) < 10)

			s += "0" + d.getDate() + APP_DATE_DELIMITER;

		else

			s += d.getDate() + APP_DATE_DELIMITER;

	}

   	s += d.getYear();

   	

   	return s;

}



//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   REPLACE

//   PURPOSE         :   Replace sub string by other string in a input string

//   ARGUMENTS       :   + strInput : input string

//						 + strNeedReplace : string need to repalce by other

//						 + strReplaceBy : string replace for strNeedReplace

//   RETURNS         :   strInput string that has been replaced

//   AUTHOR          :   AnhNT

//------------------------------------------------------------------------------------------------------------------------------------------

function REPLACE(strInput, strNeedReplace, strReplaceBy)

{

	return strInput.split(strNeedReplace).join(strReplaceBy);

}



//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   CONV_NUMERIC

//   PURPOSE         :   Convert string to number

//   ARGUMENTS       :   s ; Ex : 100,000

//   RETURNS         :   Numeric value ; Ex : 100000

//   AUTHOR          :   AnhNT

//------------------------------------------------------------------------------------------------------------------------------------------

function CONV_NUMERIC(strInput)

{

	var strNeedReplace = ",";

	var strReplaceBy = "";

	return REPLACE(strInput, strNeedReplace, strReplaceBy);

}



//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   CHECK_NUMBER_FIELD_NO_ALERT

//   PURPOSE         :   Check if the number in field is correct or not.

//   ARGUMENTS       :   + InputField : input number field 

//                       + AllowNull : 1 = allow null; 0 = not allow null

//                       + MinValue : Min of input rangle - Optional

//                       + MaxValue : Max of input rangle - Optional

//						 + FieldLabel : Label for that Field - Optional

//   RETURNS         :   true - InputField is a number

//    				   	 false - InputField not a number

//   AUTHOR          :   AnhNT

//------------------------------------------------------------------------------------------------------------------------------------------

function CHECK_NUMBER_FIELD_NO_ALERT(InputField, AllowNull, MinValue, MaxValue, FieldLabel)

{

	InputField.value = TRIM(InputField.value)

	if ((InputField.value == "") && (AllowNull == 1))

		return true;

	

	if (InputField.value == "") {

		//MSG_ALERT(FieldLabel, "Please input value into " + FieldLabel + "!", "Ch°a nh­p " + FieldLabel + " !");

		InputField.focus();

		return (false);

	}

	

	

	if (!IS_NUMBER(InputField.value)) {

		//MSG_ALERT(FieldLabel, FieldLabel + " must be a number !", FieldLabel + " phai la so !");

		InputField.focus();

		return (false);

	

	}

	

	if (IS_NUMBER(MinValue)) {

		if (InputField.value<MinValue) {

			InputField.focus();

			//MSG_ALERT(FieldLabel, FieldLabel + " must >= " + MinValue + " !", FieldLabel + " phai >= " + MinValue + " !");

			return (false);

		}

	}

	

	if (IS_NUMBER(MaxValue)) {

		if (InputField.value>MaxValue) {

			InputField.focus();

			//MSG_ALERT(FieldLabel, FieldLabel + " must <= " + MaxValue + " !", FieldLabel + " phai <= " + MaxValue + " !");

			return (false);

		}

	}

	

	return (true);

}



//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   CHECK_STRING_FIELD

//   PURPOSE         :   Check if the string is out of length.

//   ARGUMENTS       :   + InputField : input number field 

//                       + AllowNull : 1 = allow null; 0 = not allow null

//                       + MaxLength : Max of input rangle - Optional

//						 + FieldLabel : Label for that Field - Optional

//   RETURNS         :   true - InputField is a correct string

//    				   	 false - InputField not a correct string

//   AUTHOR          :   BinhBT

//------------------------------------------------------------------------------------------------------------------------------------------

function CHECK_STRING_FIELD_NO_ALERT(InputField, AllowNull, MaxLength, FieldLabel)

{

	InputField.value = TRIM(InputField.value)

		

	if ((InputField.value == "") && (AllowNull == 1))

		return true;

	

	if (InputField.value == "") {

		//MSG_ALERT(FieldLabel, "Please input value into " + FieldLabel + "!", "Chua nhap " + FieldLabel + " !");

		InputField.focus();

		return (false);

	}

	if (IS_NUMBER(MaxLength))

		if (InputField.value.length > MaxLength) {

			//MSG_ALERT(FieldLabel, "The length of " + FieldLabel + " must <= " + MaxLength, "Do dai cua " + FieldLabel + " phai nho hon hoac bang " + MaxLength);

			InputField.focus();

			return (false);

		}

	return true;

}



//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   CHECK_DATE_FIELD

//   PURPOSE         :   Check if the date in field is correct or not.

//   ARGUMENTS       :   + InputField : input date field

//                       + AllowNull : 1 = allow null; 0 = not allow null

//                       + MinValue : Min of input rangle

//                       + MaxValue : Max of input rangle

//						 + FieldLabel : Label for that Field - Optional

//   RETURNS         :   true - InputField is date

//    				     false - InputField is not date

//   AUTHOR          :   AnhNT

//------------------------------------------------------------------------------------------------------------------------------------------

function CHECK_DATE_FIELD_NO_ALERT(InputField, AllowNull, MinValue, MaxValue, FieldLabel)

{

	InputField.value = TRIM(InputField.value)

	

	var DateType = APP_DATE_TYPE;

	

	if ((InputField.value == "") && (AllowNull == 1))

		return true;

	

	if (InputField.value == "") {

		//MSG_ALERT(FieldLabel, "Please input value into " + FieldLabel + "!", "Chua nhap " + FieldLabel + " !");

		InputField.focus();

		return (false);

	} 

	

	if (!IS_DATE(InputField.value)) {

		//MSG_ALERT(FieldLabel, FieldLabel + " must be a date type !", FieldLabel + " phai la dinh dang ngay thang !")

		InputField.focus();

		return (false);

	}

	

	if (IS_DATE(MinValue)) {

		if (GREATER_DATE(MinValue, InputField.value)) {

		

			//MSG_ALERT(FieldLabel, FieldLabel + " must >= " + MinValue, FieldLabel + " phai >= " + MinValue);

			InputField.focus();

			return (false);

		}

	}

	

	if (IS_DATE(MaxValue)) {

		if (GREATER_DATE(InputField.value, MaxValue)) {

			//MSG_ALERT(FieldLabel, FieldLabel + " must <= " + MaxValue, FieldLabel + " phai <= " + MaxValue);

			InputField.focus();

			return (false);

		}

	}

	

	

	if (GREATER_DATE('1/1/1900', InputField.value)) {

		//MSG_ALERT(FieldLabel, FieldLabel + " must >= 1/1/1900", FieldLabel + " phai >= 1/1/1900");

		InputField.focus();

		return (false);

	}

	

	return(true);

}

//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   dateValidate

//   PURPOSE         :   Validate the Date Time.

//   ARGUMENTS       :   + text box contain Date time value

//   RETURNS         :   true if text box contains true date time

//    				     false if text box contains false date time

//   AUTHOR          :   FSOFT

//------------------------------------------------------------------------------------------------------------------------------------------

function dateValidate(txtDate) {

    if (txtDate == null) {

        return false;

    }

    var bInvalid;

    var dateValue;

    var c1, c2, n1, n2;

    bInvalid = false;

    dateValue = trim(txtDate.value);

    n1 = 0;

    n2 = 0;

	

    if (dateValue.substring(2, 3) == '/') {

        n1 = 2;

    }

    if (dateValue.substring(1, 2) == '/') {

        n1 = 1;

    }

    if (dateValue.substring(3, 4) == '/') {

        n2 = 3;

    }

    if (dateValue.substring(4,5) == '/') {

        n2 = 4;

    }

    if (dateValue.substring(5,6) == '/') {

        n2 = 5;

    }

    if (n1 == 0 || n2 == 0) {

        bInvalid = true;

    }

    if (!bInvalid) {

        var nYearLen;

        nYearLen = dateValue.length - n2 - 1;

        if (nYearLen != 4) {

            bInvalid = true;

        }

    }

    

    

    if (!bInvalid) {

        sMonth = dateValue.substring(0, n1);

        nMonth = parseInt(sMonth, 10);

        sDay = dateValue.substring(n1+1, n2);

        nDay = parseInt(sDay, 10);

        sYear = dateValue.substring(n2+1, dateValue.length);

        nYear = parseInt(sYear, 10);

        if (nYear < 00 || nYear > 9999 || isNaN(sYear) || sYear.indexOf('.') != -1) {

            bInvalid = true;

        }

        if ((nMonth < 1 || nMonth > 12 || isNaN(sMonth) || sMonth.indexOf('.') != -1)) {

            bInvalid = true;

        }

        if ((nDay < 1 || nDay > 31 || isNaN(sDay) || sDay.indexOf('.') != -1)) {

            bInvalid = true;

        }

		

        if (nMonth == 4 || nMonth == 6 || nMonth == 9 || nMonth == 11) {

            if (nDay == 31) {

                bInvalid = true;

            }

        }

        if (nMonth == 2) {

            var g = parseInt(nYear / 4, 10);

            if (isNaN(g)) {

                bInvalid = true;

            }

            if (nDay > 29) {

                bInvalid = true;

            }

            if (nDay == 29 && ((nYear / 4) != parseInt(nYear / 4, 10))) {

                bInvalid = true;

            }

        }

        

        if (isNaN(nDay) || isNaN(nMonth) || isNaN(nYear)) {

            bInvalid = true;

        }

    }

    if (bInvalid) {

        alert('Invalid value for mm/dd/yyyy');

        txtDate.focus();

        return false;

    }

    return true;

}

//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   DURATIONVALIDATE

//   PURPOSE         :   Validate the duration. Duration is number and not more than 8 hours

//   ARGUMENTS       :   + text box contain duration

//   RETURNS         :   true if duration is valid

//    				     false if duration is not valid

//   AUTHOR          :   Fsoft

//------------------------------------------------------------------------------------------------------------------------------------------

function durationValidate(txtDuration) {

    var durationValue;

    durationValue = txtDuration.value;

    if (isNaN(durationValue)) {

        alert('The duration must be a correct number.');

        txtDuration.focus();

        return false;

    }

    var nDuration = new Number(durationValue);

    if (nDuration > 8 || nDuration < 0) {

        alert('The duration can not be more than 8 hours, and can not be negative number.');

        txtDuration.focus();

        return false;

    }

    return true;

}

//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   isDate

//   PURPOSE         :   Validate if string is date format

//   ARGUMENTS       :   String contains date time

//   RETURNS         :   true if if it is date

//    				     false if not is date

//   AUTHOR          :   Fsoft

//------------------------------------------------------------------------------------------------------------------------------------------

function isDate(strDate) {

    if (strDate == null) {

        return false;

    }

    strDate = trim(strDate);

    var sDay, sMonth, sYear, nMonth, nDay, nYear, nSep1, nSep2;

    if (strDate.length > 8) {

        return false;

    }

    nSep1 = strDate.indexOf("/");

    if (nSep1 < 0) {

        return false;

    }

    nSep2 = strDate.lastIndexOf("/");

    if (nSep2 < 0) {

        return false;

    }

    if (nSep1 == nSep2) {

        return false;

    }

    sMonth = strDate.substring(0, nSep1);

    sDay = strDate.substring(nSep1 + 1, nSep2);

    sYear = strDate.substring(nSep2 + 1);

    if (!sMonth.length || !sDay.length || !sYear.length) {

        return false;

    }

    if (isNaN(sMonth) || isNaN(sDay) || isNaN(sYear)) {

        return false;

    }

    nMonth = parseInt(sMonth, 10);

    nDay = parseInt(sDay, 10);

    nYear = parseInt(sYear, 10);

    if (nMonth <= 0 || nDay <= 0 || nYear < 0) {

        return false;

    }

    if (nMonth > 12) {

        return false;

    }

    if (nMonth == 1 || nMonth == 3 || nMonth == 5 || nMonth == 7 || nMonth == 8 || nMonth == 10 || nMonth == 12 ) {

        if (nDay > 31) {

            return false;

        }

    }

    if (nMonth == 4 || nMonth == 6 || nMonth == 9 || nMonth == 11 ) {

        if (nDay > 30) {

            return false;

        }

    }

    if (nMonth == 2) {

        if ((nYear % 4 == 0) || (nYear == 0)) {

            if (nDay > 29) {

                return false;

            }

        }

        else if (nDay > 28) {

            return false;

        }

    }

    return true;

}

//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   trim

//   PURPOSE         :   Trim a string

//   ARGUMENTS       :   String 

//   RETURNS         :   String after trim

//   AUTHOR          :   Fsoft

//------------------------------------------------------------------------------------------------------------------------------------------

function trim(str)

{

return str.replace(/^\s*|\s*$/g,"");

} 

//------------------------------------------------------------------------------------------------------------------------------------------

//   FUNCTION        :   Check Email

//   PURPOSE         :   Check Email

//   ARGUMENTS       :   Input  

//   RETURNS         :   true/false

//   AUTHOR          :   Fsoft

//------------------------------------------------------------------------------------------------------------------------------------------

function checkMail(inObject){

	// checkMail() function

	var txt=inObject.value;
	
	if (txt.indexOf("@")<3){

		alert("Sorry!. This email address seems wrong. Please" + " check the prefix and '@' sign.");

		inObject.focus();
		
		return false;

	}

	j=0; 

	k=0;

	d=0;

	for(i=0;i<txt.length;i++){

		if(txt.charAt(i)=="@") j=j+1;

		if((txt.charAt(i-1)==".")&&(txt.charAt(i)==".")) k=1;

		if((txt.charAt(i-1)==".")&&(txt.charAt(i)=="@")) k=2;

		if((txt.charAt(i-1)=="@")&&(txt.charAt(i)==".")) k=3;

		if(txt.charAt(i)==" ") k=4;

		if(txt.charAt(i)==".") d=1;

		if(txt.charAt(txt.length-1)==".") d=2;

	}

	if(d==0){ 

		alert("Sorry!. This email address must have at least a dot. Please" + " input email again !");

		inObject.focus();

		return false;

	}

	if(d==2){ 

		alert("Sorry!.Email address can not contain any dot at the end. Please"	+" input again !");

		inObject.focus();

		return false;

	}

	if(j==2){ alert("Sorry!. This email address must have at least one @. Please"+" input again !.");

		inObject.focus();

		return false;

	}

	if(k==1){

		alert("Sorry!. This email address is not '. .'. Please"

			+" input again ."); 

		inObject.focus();

		return false;

	}

	if(k==2){

		alert("Sorry!. This email address is not ' . @'. Please"

			+" input again ."); 

		inObject.focus();

		return false;

	}

	if(k==3){

		alert("Sorry!. This email address is not '@ . '.  Please"

			+" input again ."); 

		inObject.focus();

		return false;

	}

	if(k==4){

		alert("Sorry!. This email address has spaces. Please"

		+" check email again .");

		inObject.focus();

		return  false;

	}	

	return true;

}
//function list box
	
function move(fbox,tbox) {
	var i = 0; 
	if(fbox.value != "") {
		var no = new Option();
		no.value = fbox.value;
		no.text = fbox.value;
		lindex = tbox.selectedIndex;
		alert(lindex);
		var selected = tbox.selectedIndex;
      	if (selected == -1) {
	         alert("You must select an entry to be moved!");
		} else {
			tbox.options[lindex].selected = false;
			tbox.options[tbox.options.length] = no;
			tbox.options[tbox.options.length-1].selected = true;
			for(var i = 0; i < tbox.options.length - lindex -2; i++) {
				Moveup(tbox);
			}
			fbox.value = "";
		}
   }
}
function remove(box) {
	for(var i=0; i<box.options.length; i++) {
	if(box.options[i].selected && box.options[i] != "") {
	box.options[i].value = "";
	box.options[i].text = "";
	   }
	}
	BumpUp(box);
	} 
	function BumpUp(abox) {
	for(var i = 0; i < abox.options.length; i++) {
	if(abox.options[i].value == "")  {
	for(var j = i; j < abox.options.length - 1; j++)  {
	abox.options[j].value = abox.options[j + 1].value;
	abox.options[j].text = abox.options[j + 1].text;
	}
	var ln = i;
	break;
	   }
	}
	if(ln < abox.options.length)  {
	abox.options.length -= 1;
	BumpUp(abox);
	   }
	}
	function Moveup(dbox) {
	for(var i = 0; i < dbox.options.length; i++) {
	if (dbox.options[i].selected && dbox.options[i] != "" && dbox.options[i] != dbox.options[0]) {
	var tmpval = dbox.options[i].value;
	var tmpval2 = dbox.options[i].text;
	dbox.options[i].value = dbox.options[i - 1].value;
	dbox.options[i].text = dbox.options[i - 1].text
	dbox.options[i-1].value = tmpval;
	dbox.options[i-1].text = tmpval2;
	//alert(i);
	dbox.options[i-1].selected = true;
	dbox.options[i].selected = false;
	//dbox.focus();
	      }
	   }
	}
	function Movedown(ebox) {
	for(var i = 0; i < ebox.options.length; i++) {
	if (ebox.options[i].selected && ebox.options[i] != "" && ebox.options[i+1] != ebox.options[ebox.options.length]) {
	var tmpval = ebox.options[i].value;
	var tmpval2 = ebox.options[i].text;
	ebox.options[i].value = ebox.options[i+1].value;
	ebox.options[i].text = ebox.options[i+1].text
	ebox.options[i+1].value = tmpval;
	ebox.options[i+1].text = tmpval2;
	ebox.options[i].selected = false;
	ebox.options[i+1].selected = true;
	break;
	      }
	   }
	}
function replace(s, t, u) {
  /*
  **  Replace a token in a string
  **    s  string to be processed
  **    t  token to be found and removed
  **    u  token to be inserted
  **  returns new String
  */
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += replace(s.substring(i + t.length, s.length), t, u);
  return r;
  }


//  End -->

