
//Ham tach ky tu phan ngin
//Input: so, ky tu phan cach
//Output: so da duoc phan cach
//ChungNN - 11/2005
//Exp: var tem=Convert_VCurrency("1500000",".") = 1.500.000
function Convert_VCurrency(lnValue, Seperater)
{
    
    var strTem1 = "", strTem2 = "", strTem3 = "";
    var lnNum1 = 0, lnNum2 = 0, lnNum3 = 0;
    
    strTem1 = lnValue + "";
    
    // <= xxxyyy
    if (strTem1.length > 3 && strTem1.length < 7)
    {                    
        lnNum1 = Math.floor(parseInt(lnValue)/1000);
        lnNum2 = parseInt(lnValue)%1000;   
        
        strTem2 = strTem1.substring((lnNum1+"").length,(lnNum1+"").length+3);         
        //alert(strTem2);                 
        strTem1 = lnNum1 + Seperater + strTem2;                                        
        
    }
    
        
    // <= xxxyyyzzz
    else if (strTem1.length > 6)
    {
        //Math.floor
        //3000000
        lnNum1 = Math.floor(parseInt(lnValue)/1000000);             
        lnNum2 = (parseInt(parseInt(lnValue)/1000)%1000);
        
        strTem2 = strTem1.substring((lnNum1+"").length,(lnNum1+"").length+3);
        strTem3 = strTem1.substring((lnNum1+"").length+strTem2.length,(lnValue+"").length);
        
        strTem1 = lnNum1 + "" + Seperater + strTem2 + Seperater + strTem3 ;
    }

    strTem2 = strTem1;

    return strTem2;
    
}            

//Ham loai bo ky tu ton tai trong chuoi
//Input:    strTem: chuoi ky tu
//          Separater: ky tu can loai bo
//Output: chuoi da duoc loai bo
//ChungNN - 11/2005
//Exp: var tem=fnReplace("1.500.000",".") = 1500000

function fnReplace(strTem, Separater)        
{
    var retVal = "";
    var Arr1 = strTem.split(Separater);
    
    for(i=0; i<Arr1.length; i++)               
            retVal += Arr1[i];                              
    
    return retVal;
}



//Ham doi thuoc tinh cua <tr> nhu: mau, font chu...
//Exp: <tr class="cls1" onmouseover="ChangeTo(this, 'cls2');" onmouseout="ChangeTo(this, 'cls1');"></tr>
//ChungNN - 9/2005
function ChangeTo(obj,strClass){
	if(strClass!=""){
		obj.className = strClass;
	}
}

//Ham check khi an phim Enter thi thuc hien 1 ham check khac
//Input: fnCheck - javascript function muon check du lieu
//Output: NA
//ChungNN 9-2005
//exp: <input type =text onkeypress="javascript:fn_CheckEnter('fnCheckDate()');">
function fn_CheckEnter(fnCheck)
{
    if(window.event.keyCode==13)
        eval(fnCheck);
}
    

//-------------------------------------------------------------------------------------
//Desc.  : Remove blank at most right and left of the input string
//Inputs : - s: the input string
//Outputs: string without blank at most right and left
//Example: JTrim(txtPassword.value)
//-------------------------------------------------------------------------------------
function JTrim(s)
{
		var i, sRetVal = "";
		i = s.length-1;
		while ( i>=0 && s.charAt(i) == ' ' ) i--;
		s = s.substring( 0, i+1 ); // trim blanks on the right
		i = 0;
		while ( i< s.length && s.charAt(i) == ' ') i++;
		return s.substring( i );
}

//-------------------------------------------------------------------------------------
//Desc.  : Remove blank at most right of the input string
//Inputs : - s: the input string
//Outputs: string without blank at most right 
//Example: JRTrim(txtPassword.value)
//-------------------------------------------------------------------------------------
function JRTrim(s)
{
		var i, sRetVal = "";
		i = s.length-1;
		while ( i>=0 && s.charAt(i) == ' ' ) i--;
		s = s.substring( 0, i+1 ); // trim blanks on the right
		return s;
}

//-------------------------------------------------------------------------------------
//Desc.  : Remove blank at most left of the input string
//Inputs : - s: the input string
//Outputs: string without blank at most left
//Example: JLTrim(txtPassword.value)
//-------------------------------------------------------------------------------------
function JLTrim(s)
{
		var i, sRetVal = "";
		i = 0;
		while ( i< s.length && s.charAt(i) == ' ') i++;
		return s.substring( i );
}
//-------------------------------------------------------------------------------------
//Desc.:	Check if input string is Number
//Example :	Onkeypress="javascript:FilterIntegerDigits();"
//-------------------------------------------------------------------------------------
function	FilterIntegerDigits()
{
	if ((window.event.keyCode >=48 && window.event.keyCode<=57) ||
		(window.event.keyCode ==46))
	{
	}
	else
		window.event.keyCode =	0;
}
//-------------------------------------------------------------------------------------
//Desc.  : Check if input string is in valid Number
//Inputs : - s: the input string
//Outputs: true (if input string is in valid Number), false (otherwise)
//Example: if(!isNumber(txtNumber.value)) return false;
//-------------------------------------------------------------------------------------
function	isNumber(strValue)
{
	if (!isFinite(strValue))
	{
		return	false;
	}
	return true;
}

//-------------------------------------------------------------------------------------
//Desc.  : Check if input string is in valid Date Format
//Inputs : - s: the input string
//Outputs: true (if input string is in valid Date Format), false (otherwise)
//Example: if(!isDate(txtActionDate.value)) return false;
//-------------------------------------------------------------------------------------
function isDate( s )
{
	var sDay, sMonth, sYear, nMonth, nDay, nYear, nSep1, nSep2;
	nSep1 = s.indexOf( "/" );	if ( nSep1 < 0 ) return false;
	nSep2 = s.lastIndexOf( "/" );	if ( nSep2 < 0 ) return false;
	if ( nSep1 == nSep2 ) return false;

	sMonth = s.substring( 0, nSep1  );
	sDay = s.substring( nSep1 + 1, nSep2 );
	sYear = s.substring( nSep2+1 );
	if ( !sMonth.length || !sDay.length || sYear.length <4) return false;
	if ( isNaN(sMonth) || isNaN(sDay) || isNaN(sYear) ) return false;
	nMonth = parseInt(sMonth,10); nDay = parseInt(sDay,10); nYear = parseInt(sYear,10);
	// DungNDV added 201 Aug 03rd to accept year in 2 digits
	if (nYear < 100)
	{
		if (nYear > 20)
			nYear = nYear + 1900;
		else
			nYear = nYear + 2000;
	}
    
	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 % 100 != 0)) { // leap year
			if ( nDay > 29 ) return false;
		} else if ( nDay > 28 ) return false;
	}
	return true;
}

//-------------------------------------------------------------------------------------
//Desc.  : Check if input string is in valid DOB (Date Of Birth)
//Inputs : - sTemp: the input string
//Outputs: true (if input string is in valid DOB (Date Of Birth)), false (otherwise)
//Example: if(!isDOB(txtDOB.value)) return false;
//-------------------------------------------------------------------------------------
function isDOB(sTemp)
{
	if(sTemp=='')	
	{
		alert('Date of Birth is not empty!');
		object.focus();
		return false;
	}
	if(!isDate(sTemp)|| new Date(sTemp)>new Date()) 
	{
		alert('Invalid Date of Birth!');
		object.focus();
		return false;
	}
	return true;
}

//-------------------------------------------------------------------------------------
//Desc.  : Get current date from the system
//Inputs : No
//Outputs: string that contains current date
//Example: sCurrenDate = GetCurrentDate();
//-------------------------------------------------------------------------------------
function	GetCurrentDate()
{
	var dt,month,day,year, st;
	dt	= new Date();
	month	= dt.getMonth()+1;
	day	= dt.getDate();
	year	= dt.getFullYear();
	st	= day + '/' + month + '/' + year;
	return	st;
}

//-------------------------------------------------------------------------------------
//Desc.  : Check if input string is in valid Email
//Inputs : - sTemp: the input string
//Outputs: true (if input string is in valid Email), false (otherwise)
//Example: if(!isEmailAddress(txtEmail1.value)) return false;
//-------------------------------------------------------------------------------------
function	isEmailAddress(strValue)
{
	var	j,strTemp;
	strTemp	=	strValue;
	if (strTemp != '') 
	{
		var nCountC = 0;
		for ( j = 0; j< strTemp.length; j++ ){
			c = strTemp.charAt(j);
			if ( !( c>='0' && c<='9' || c>='a' && c<='z' || c>='A' && c<='Z' || c == '@' || c == '.' || c =='_' || c =='-') ) 
				return false;
			if (c == '@') nCountC  = nCountC + 1;
		}// End for
	if (nCountC != 1)return false;
	if (strTemp.charAt(strTemp.length - 1) == '@' || strTemp.charAt(0) == '@' || strTemp.charAt(strTemp.length - 1) == '.' || strTemp.charAt(0) == '.')
		return false;
	}
	return	true;
}

//-------------------------------------------------------------------------------------
//Desc.  : Check if input string is in valid ZipCode
//Inputs : - sTemp: the input string
//Outputs: true (if input string is in valid ZipCode), false (otherwise)
//Example: if(!isZipCode(txtZip.value)) return false;
//-------------------------------------------------------------------------------------
function	isZipCode(strValue)
{
	var i;
	for (i=0;i<strValue.length;i++)
	{
		if (!(strValue.charCodeAt(i)<58 && strValue.charCodeAt(i)>47) && !(strValue.charCodeAt(i)<91 && strValue.charCodeAt(i)>64) && !(strValue.charCodeAt(i) == 45))
		return	false;
	}
	return	true;
}

//-------------------------------------------------------------------------------------
//Desc.  : Check if input string is in valid MaxMinStay
//Inputs : - sTemp: the input string
//Outputs: true (if input string is in valid MaxMinStay), false (otherwise)
//Example: if(!isMaxMinStay(txtMaxMinStay.value)) return false;
//-------------------------------------------------------------------------------------

function	isMaxMinStay(strValue)
{
	var i;
	for (i=0;i<strValue.length;i++)
	{
		if (!(strValue.charCodeAt(i)<58 && strValue.charCodeAt(i)>47) && !(strValue.charCodeAt(i)==77) && !(strValue.charCodeAt(i) == 89))
		return	false;
	}
	return	true;
}
//-------------------------------------------------------------------------------------
//Desc.  : Check if values of objects in form 'oParentForm' whose name is stored in 
//	   arrObjName are in correct Date format.	
//Inputs : - oParentForm: the HTML Form that contains objects to be checked
//	   - arrObjName : the array that contains name of objects to be checked
//	   - blnAlert	: true (show alert message to user), false (not show)
//Outputs: true (all objects's value are in correct Date format), false (otherwise)
//Example: 
//	if (!ValidDatesOld(document.frmEdit, new Array("SubmitDate"),true)) return false;
//-------------------------------------------------------------------------------------
function	ValidDatesOld(oParentForm, arrObjName, blnAlert)
{
	frmParent	=	oParentForm;
	intLength	=	arrObjName.length;
	var	i,stDate;
	for (i=0;i<intLength;i++)
	{
		if (frmParent(arrObjName[i])!=null)	
		{
			stDate	=	JTrim(frmParent(arrObjName[i]).value);
			if (stDate.length==0) break;
			if (!isDate(stDate))
			{
				if (blnAlert)
				{
					stName	=	frmParent(arrObjName[i]).name;
					stName	=	stName.replace(/txt/i,"");
					stName	=	stName.replace(/cbo/i,"");
					if (typeof(SeparateName)=='function')
						stName	=	SeparateName(stName);
					alert("Invalid "+ stName+"!");
					frmParent(arrObjName[i]).focus();
					return false;
				}
			}
			else
			{
				var	dt,year;
				dt = new Date(stDate);
				year = dt.getFullYear();
				if ((parseInt(year)<1753)||(parseInt(year)>9999))
				{
					if (blnAlert) alert("Year must be between 1753 and 9999");
					frmParent(arrObjName[i]).focus();
					return false;
				}
			}
		}
		else
		{
			if (!confirm("\""+arrObjName[i]+"\" is not a control of form "+frmParent.name+"!\nDo you want to continue?"))
				return	false;
		}
	}
	return	true;
}

//-------------------------------------------------------------------------------------
//Desc.  : Check if values of objects in form 'oParentForm' whose name is stored in 
//	   arrObjName are in correct Email format.	
//Inputs : - oParentForm: the HTML Form that contains objects to be checked
//	   - arrObjName : the array that contains name of objects to be checked
//	   - blnAlert	: true (show alert message to user), false (not show)
//Outputs: true (all objects's value are in correct Email format), false (otherwise)
//Example: 
//	if (!ValidEmails(document.frmEdit, new Array("Email1"),true)) return false;
//-------------------------------------------------------------------------------------
function	ValidEmails(oParentForm, arrObjName, blnAlert)
{
	frmParent	=	oParentForm;
	intLength	=	arrObjName.length;
	var	i,stEmail;
	for (i=0;i<intLength;i++)
	{
		if (frmParent(arrObjName[i])!=null)	
		{
			stEmail	=	JTrim(frmParent(arrObjName[i]).value);
			if (!isEmailAddress(stEmail))
			{
				if (blnAlert)
				{
					stName	=	frmParent(arrObjName[i]).name;
					stName	=	stName.replace(/txt/i,"");
					stName	=	stName.replace(/cbo/i,"");
					if (typeof(SeparateName)=='function')
						stName	=	SeparateName(stName);
					alert("Invalid"+stName+"!");
					frmParent(arrObjName[i]).focus();
					return false;
				}
			}
		}
		else
		{
			if (!confirm("\""+arrObjName[i]+"\" is not a control of form "+frmParent.name+"!\nDo you want to continue?"))
				return	false;
		}
	}
	return	true;
}

//-------------------------------------------------------------------------------------
//Desc.  : Check if values of objects in form 'oParentForm' whose name is stored in 
//	   arrObjName are in correct Number format.	
//Inputs : - oParentForm: the HTML Form that contains objects to be checked
//	   - arrObjName : the array that contains name of objects to be checked
//	   - blnAlert	: true (show alert message to user), false (not show)
//Outputs: true (all objects's value are in correct Number format), false (otherwise)
//Example: 
//	if (!ValidNumbers(document.frmEdit, new Array("Email1"),true)) return false;
//-------------------------------------------------------------------------------------


function	ValidNumbers(oParentForm, arrObjName, blnAlert)
{
	frmParent	=	oParentForm;
	intLength	=	arrObjName.length;
	var	i,stValue,stName;
	for (i=0;i<intLength;i++)
	{
		if (frmParent(arrObjName[i])!=null)	
		{
			stValue	=	JTrim(frmParent(arrObjName[i]).value);
			if (stValue.length==0)	break;
			if (!isNumber(stValue))
			{
				if (blnAlert)
				{
					stName	=	frmParent(arrObjName[i]).name;
					stName	=	stName.replace(/txt/i,"");
					stName	=	stName.replace(/_1/i,"");
					stName	=	stName.replace(/_2/i,"");
					stName	=	stName.replace(/_3/i,"");
					stName	=	stName.replace(/cbo/i,"");
					if (typeof(SeparateName)=='function')
						stName	=	SeparateName(stName);
					alert('Invalid '+ stName + '!\nOnly numbers are allowed.');
					frmParent(arrObjName[i]).focus();
					return false;
				}
				else
				{
					frmParent(arrObjName[i]).focus();
					return false;
				}
			}
		}
		else
		{
			if (!confirm("\""+arrObjName[i]+"\" is not a control of form "+frmParent.name+"!\nDo you want to continue?"))
				return	false;
		}
	}
	return	true;
}

//-------------------------------------------------------------------------------------
//Desc.  : Check if values of objects in form 'oParentForm' whose name is stored in 
//	   arrObjName are in correct Zip format.	
//Inputs : - oParentForm: the HTML Form that contains objects to be checked
//	   - arrObjName : the array that contains name of objects to be checked
//	   - blnAlert	: true (show alert message to user), false (not show)
//Outputs: true (all objects's value are in correct Zip format), false (otherwise)
//Example: 
//	if (!ValidZipCodes(document.frmEdit, new Array("Email1"),true)) return false;
//-------------------------------------------------------------------------------------
function	ValidZipCodes(oParentForm, arrObjName, blnAlert)
{
	frmParent	=	oParentForm;
	intLength	=	arrObjName.length;
	var	i,stValue;
	for (i=0;i<intLength;i++)
	{
		if (frmParent(arrObjName[i])!=null)	
		{
			stValue	=	JTrim(frmParent(arrObjName[i]).value);
			if (!isZipCode(stValue))
			{
				if (blnAlert)
				{
					stName	=	frmParent(arrObjName[i]).name;
					stName	=	stName.replace(/txt/i,"");
					stName	=	stName.replace(/cbo/i,"");
					if (typeof(SeparateName)=='function')
						stName	=	SeparateName(stName);
					alert("Invalid "+ stName + "!" + "\nOnly capital letters and numbers are allowed.");
					frmParent(arrObjName[i]).focus();
					return false;
				}
			}
		}
		else
		{
			if (!confirm("\""+arrObjName[i]+"\" is not a control of form "+frmParent.name+"!\nDo you want to continue?"))
				return	false;
		}
	}
	return	true;
}

//-----------------------------------------------------------------------------

function	ValidMStay(oParentForm, arrObjName, blnAlert){
	frmParent	=	oParentForm;
	intLength	=	arrObjName.length;
	var	i,stValue;
	for (i=0;i<intLength;i++)
	{
		if (frmParent(arrObjName[i])!=null)	
		{
			stValue	=	JTrim(frmParent(arrObjName[i]).value);
			if (!isMaxMinStay(stValue))
			{
				if (blnAlert)
				{
					stName	=	frmParent(arrObjName[i]).name;
					stName	=	stName.replace(/txt/i,"");
					stName	=	stName.replace(/cbo/i,"");
					if (typeof(SeparateName)=='function')
						stName	=	SeparateName(stName);
					alert("Invalid "+ stName + "!" + "\nOnly capital letters M or Y and numbers are allowed.");
					frmParent(arrObjName[i]).focus();
					return false;
				}
			}
		}
		else
		{
			if (!confirm("\""+arrObjName[i]+"\" is not a control of form "+frmParent.name+"!\nDo you want to continue?"))
				return	false;
		}
	}
	return	true;
}
//-------------------------------------------------------------------------------------
//Desc.  : Check if values of Password editbox and Confirm editbox are the same value
//Inputs : - oControlPassword: the edit box that contains Password
//	   - oControlConfirm : the edit box that contains Confirm Password
//Outputs: true (values of Password editbox and Confirm editbox are the same value), 
//	   false (otherwise)
//Example: 
//	if (!ValidPassword(txtPassword,txtConfirm,strMsg) return false;
//-------------------------------------------------------------------------------------
function	ValidPassword(oControlPassword, oControlConfirm,strMsg)
{
	if (oControlConfirm.value != oControlPassword.value)
	{
		alert(strMsg);
		oControlConfirm.focus();
		return	false;
	}
	return	true;
}


//-------------------------------------------------------------------------------------
//Desc.  : Check if values of objects in form 'oParentForm' whose name is stored in 
//	   arrObjName are not empty.	
//Inputs : - oParentForm: the HTML Form that contains objects to be checked
//	   - arrObjName : the array that contains name of objects to be checked
//	   - blnAlert	: true (show alert message to user), false (not show)
//Outputs: true (all objects's value are not empty), false (otherwise)
//Example: 
//	if (!ValidEmpties(document.frmEdit, new Array("txtEdit1,txtEdit2"),true)) return false;
//-------------------------------------------------------------------------------------
function ValidEmpties(oParentForm, arrObjName, blnAlert)
{
	function JTrim(s)
	{
		var i, sRetVal = "";
		i = s.length-1;
		while ( i>=0 && s.charAt(i) == ' ' ) i--;
		s = s.substring( 0, i+1 ); // trim blanks on the right
		i = 0;
		while ( i< s.length && s.charAt(i) == ' ') i++;
		return s.substring( i );
	}
	frmParent	=	oParentForm;
	intLength	=	arrObjName.length;
	var	i,stValue;
	for (i=0;i<intLength;i++)
	{
		if (frmParent(arrObjName[i])!=null)	
		{
			stValue	=	JTrim(frmParent(arrObjName[i]).value);
			if (stValue=="")
			{
				if (blnAlert)
				{
					stName	=	frmParent(arrObjName[i]).name;
					stName	=	stName.replace(/txt/i,"");
					stName	=	stName.replace(/cbo/i,"");
					stName	=	stName.replace(/_1/i,"");
					stName	=	stName.replace(/_2/i,"");
					stName	=	stName.replace(/_3/i,"");
					
					if (typeof(SeparateName)=='function')
						stName	=	SeparateName(stName);
					if (frmParent(arrObjName[i]).type=="chọn 1")
						alert("Bạn phải chọn "+ stName);
					else
						alert("Bạn phải nhập "+ stName);
					if(!frmParent(arrObjName[i]).disabled)
						frmParent(arrObjName[i]).focus();
					return false;
				}
				else
				{
					frmParent(arrObjName[i]).focus();
					return false;
				}
			}
		}
		else
		{
			if (!confirm("\""+arrObjName[i]+"\" không phải là đối tượng của form "+frmParent.name+"!\nBạn có muốn tiếp tục?"))
				return	false;
		}
	}
	return	true;
}


//-------------------------------------------------------------------------------------
//Desc.  : Check if values of objects in form 'oParentForm' whose name is stored in 
//	   arrObjName are not empty.	
//Inputs : - oParentForm: the HTML Form that contains objects to be checked
//	   - arrObjName : the array that contains name of objects to be checked
//	   - blnAlert	: true (show alert message to user), false (not show)
//Outputs: true (all objects's value are not empty), false (otherwise)
//Example: 
//	if (!ValidEmpties(document.frmEdit, new Array("txtEdit1,txtEdit2"),true)) return false;
//-------------------------------------------------------------------------------------
function V_ValidEmpties(oParentForm, arrObjName, blnAlert, strMsg)
{
	function JTrim(s)
	{
		var i, sRetVal = "";
		i = s.length-1;
		while ( i>=0 && s.charAt(i) == ' ' ) i--;
		s = s.substring( 0, i+1 ); // trim blanks on the right
		i = 0;
		while ( i< s.length && s.charAt(i) == ' ') i++;
		return s.substring( i );
	}
	frmParent	=	oParentForm;
	intLength	=	arrObjName.length;
	var	i,stValue;
	for (i=0;i<intLength;i++)
	{
		if (frmParent(arrObjName[i])!=null)	
		{
			stValue	=	JTrim(frmParent(arrObjName[i]).value);
			if (stValue=="")
			{
				if (blnAlert)
				{
					stName	=	frmParent(arrObjName[i]).name;
					stName	=	stName.replace(/txt/i,"");
					stName	=	stName.replace(/cbo/i,"");
					stName	=	stName.replace(/_1/i,"");
					stName	=	stName.replace(/_2/i,"");
					stName	=	stName.replace(/_3/i,"");
					
					if (typeof(SeparateName)=='function')
						stName	=	SeparateName(stName);
					if (frmParent(arrObjName[i]).type=="select-one")
						alert(strMsg);
					else
						alert(strMsg);
					if(!frmParent(arrObjName[i]).disabled)
						frmParent(arrObjName[i]).focus();
					return false;
				}
				else
				{
					frmParent(arrObjName[i]).focus();
					return false;
				}
			}
		}
		else
		{
			if (!confirm("\""+arrObjName[i]+"\" không phải là điều khiển của form "+frmParent.name+"!\nBạn có muốn tiếp tục không?"))
				return	false;
		}
	}
	return	true;
}

//-------------------------------------------------------------------------------------
//Desc.  : Check if date value stored in oToDate >= oFromDate
//Inputs : - oFromDate: the editbox that contains from date
//	   - oToDate  : the editbox that contains to date
//Outputs: true (ToDate >= FromDate), false (otherwise)
//Example: 
//	if (!ValidFromToDates(txtFromDate,txtToDate) return false;
//-------------------------------------------------------------------------------------

function	ValidFromToDates(oFromDate,oToDate)
{
	var dtFromDate, dtToDate;
	dtFromDate	=	new Date(oFromDate.value);
	dtToDate	=	new Date(oToDate.value);
	if (dtFromDate>dtToDate)
	{
		alert('Date From is less than or equal Date To ');
		return	false;
	}
	return	true;
}

//-------------------------------------------------------------------------------------
//Desc.  : Check if date value stored in oGreaterDate >= oSmallerDate
//Inputs : - oSmallerDate: the editbox that contains smaller date
//		   - oGreaterDate: the editbox that contains greater date
//Outputs: true (oGreaterDate >= oSmallerDate), false (otherwise)
//Example: 
//	if (!ValidGreaterSmallerDates(txtSmallerDate,txtGreaterDate,'Ticketing Date','Travel Date') return false;
//-------------------------------------------------------------------------------------
function	ValidGreaterSmallerDates(oSmallerDate,oGreaterDate,strSmallerDateName,strGreaterDateName)
{
	var dtSmallerDate, dtGreaterDate;
	dtSmallerDate	=	oSmallerDate.value;
	dtGreaterDate	=	oGreaterDate.value;
	
	/*dtSmallerDate	=	new Date(oSmallerDate.value);
	dtGreaterDate	=	new Date(oGreaterDate.value);
	if (dtSmallerDate>dtGreaterDate)
	{
		alert(strGreaterDateName + ' must be equal or greater than '+ strSmallerDateName);
		return	false;
	}*/
	if (CompareDate(dtSmallerDate,dtGreaterDate) == 1){
		alert(strGreaterDateName + ' must be equal or greater than '+ strSmallerDateName);
		return	false;
	}
	
	return	true;
}

//-------------------------------------------------------------------------------------
//Desc.  : Check if values of objects in form 'oParentForm' whose name is stored in 
//	   arrObjName are DOB (Date Of Birth).	
//Inputs : - oParentForm: the HTML Form that contains objects to be checked
//	   - arrObjName : the array that contains name of objects to be checked
//	   - blnAlert	: true (show alert message to user), false (not show)
//Outputs: true (all objects's value are  DOB (Date Of Birth)), false (otherwise)
//Example: 
//	if (!ValidDOBs(document.frmEdit, new Array("Date_Of_Birth"),true)) return false;
//-------------------------------------------------------------------------------------

function ValidDOBs(oParentForm, arrObjName, blnAlert)
{
    frmParent	=	oParentForm;
	intLength	=	arrObjName.length;
	var	i,stDate;
	for (i=0;i<intLength;i++)
	{
		if (frmParent(arrObjName[i])!=null)	
		{
			stDate	=	JTrim(frmParent(arrObjName[i]).value);
			if (stDate.length==0) continue;
			if ((stDate=="")||(!isDate(stDate)))
			{
				if (blnAlert)
				{
					stName	=	frmParent(arrObjName[i]).name;
					stName	=	stName.replace(/txt/i,"");
					stName	=	stName.replace(/cbo/i,"");
					if (typeof(SeparateName)=='function')
						stName	=	SeparateName(stName);
					//alert("Date of " + stName + " is not correct!");
					alert("Date is not correct!");
					frmParent(arrObjName[i]).focus();
					return false;
				}
			}
			else
			{
				var	dt, crdt, stAlert, oldY;
				stAlert	=	"";
				dt 		=	new Date(stDate);
				crdt	=	new Date();
				if (dt>crdt)
				{
					stAlert	=	"DOB can't larger current date!";
				}
				oldY	=	crdt.getFullYear()-dt.getFullYear();
				if (crdt.getFullYear()-dt.getFullYear()>=200)
				{
					stAlert	=	"It's too longivity: "+oldY+" old years!";
				}
				if (stAlert!="")
				{
					if (blnAlert) alert(stAlert);
					frmParent(arrObjName[i]).focus();
					return false;
				}
			}
		}
		else
		{
			if (!confirm("\""+arrObjName[i]+"\" is not a control of form "+frmParent.name+"!\nDo you want to continue?"))
				return	false;
		}
	}
	return	true;
}


//-------------------------------------------------------------------------------------
//Desc.  : Check if values of objects in form 'oParentForm' whose name is stored in 
//	   arrObjName are in French Date Format.	
//Inputs : - oParentForm: the HTML Form that contains objects to be checked
//	   - arrObjName : the array that contains name of objects to be checked
//	   - blnAlert	: true (show alert message to user), false (not show)
//Outputs: true (all objects's value are in French Date Format), false (otherwise)
//Example: 
//	if (!ValidDates(document.frmEdit, new Array("Date_Of_Birth"),true)) return false;
//-------------------------------------------------------------------------------------
function	ValidDates(oParentForm, arrObjName, blnAlert)
{
	frmParent	=	oParentForm;
	intLength	=	arrObjName.length;
	var	i,stDate;
	for (i=0;i<intLength;i++)
	{
		if (frmParent(arrObjName[i])!=null)	
		{
			stDate	=	JTrim(frmParent(arrObjName[i]).value);
			if (stDate.length==0)	continue;

			if (!isDateFrench(stDate))
			{
				if (blnAlert)
				{
					stName	=	frmParent(arrObjName[i]).name;
					stName	=	stName.replace(/txt/i,"");
					stName	=	stName.replace(/cbo/i,"");
					if (typeof(SeparateName)=='function')
						stName	=	SeparateName(stName);
					alert("Input date is not correct!");
					frmParent(arrObjName[i]).focus();
					return false;
				}
			}
			else
			{
				var	dt,year;
				dt = new Date(stDate);
				year = dt.getFullYear();
				if ((parseInt(year)<1753)||(parseInt(year)>9999))
				{
					if (blnAlert) alert("Year has to be between 1753 and 9999");
					frmParent(arrObjName[i]).focus();
					return false;
				}
			}
		}
		else
		{
			if (!confirm("\""+arrObjName[i]+"\" is not a control of form "+frmParent.name+"!\nDo you want to continue?"))
				return	false;
		}
	}
	return	true;
}



//-------------------------------------------------------------------------------------
//Desc.  : Check if values of objects in form 'oParentForm' whose name is stored in 
//	   arrObjName are in Money Format.	
//Inputs : - oParentForm: the HTML Form that contains objects to be checked
//	   - arrObjName : the array that contains name of objects to be checked
//	   - blnAlert	: true (show alert message to user), false (not show)
//Outputs: true (all objects's value are in Money Format), false (otherwise)
//Example: 
//	if (!ValidMoney(document.frmEdit, new Array("Income","COI"),true)) return false;
//-------------------------------------------------------------------------------------


function	ValidMoney(oParentForm, arrObjName, blnAlert)
{
	frmParent	=	oParentForm;
	intLength	=	arrObjName.length;
	var	i,stValue,stName;
	for (i=0;i<intLength;i++)
	{
		if (frmParent(arrObjName[i])!=null)	
		{
			stValue	=	JTrim(frmParent(arrObjName[i]).value);
			if (stValue.length==0)	continue;
			if (!isNumber(stValue))
			{
				if (blnAlert)
				{
					stName	=	frmParent(arrObjName[i]).name;
					stName	=	stName.replace(/txt/i,"");
					stName	=	stName.replace(/cbo/i,"");
					if (typeof(SeparateName)=='function')
						stName	=	SeparateName(stName);
					alert('Invalid '+ stName + '!\nOnly numbers are allowed.');
					frmParent(arrObjName[i]).focus();
					return false;
				}
				else
				{
					frmParent(arrObjName[i]).focus();
					return false;
				}
			}
			else
			{
				if (stValue>922335000000000)
					if (blnAlert)
					{
						stName	=	frmParent(arrObjName[i]).name;
						stName	=	stName.replace(/txt/i,"");
						stName	=	stName.replace(/cbo/i,"");
						if (typeof(SeparateName)=='function')
							stName	=	SeparateName(stName);
						alert('Invalid '+ stName + '!\nThis number is too big.');
						frmParent(arrObjName[i]).focus();
						return false;
					}
					else
					{
						frmParent(arrObjName[i]).focus();
						return false;
					}
			}
		}
		else
		{
			if (!confirm("\""+arrObjName[i]+"\" is not a control of form "+frmParent.name+"!\nDo you want to continue?"))
				return	false;
		}
	}
	return	true;
}

//-------------------------------------------------------------------------------------
//Desc.  : Check if date value input (sDate) < current Date
//Inputs : - sDate: the editbox that contains date input
//Outputs: true (sDate >= currentDate), false (otherwise)
//Example: if (CompareToToday(txtDate) == "-1") return false;

function CompareToToday(sDate)
{
	var d,n1,n2, nMonth, nYear, nDay, nCurrMonth, nCurrYear, nCurrDay;

	n1 = sDate.indexOf( "/" );
	n2 = sDate.lastIndexOf( "/" );
	nMonth = parseInt(  sDate.substring( 0, n1  ),10 );
	nDay = parseInt(  sDate.substring( n1+1, n2  ),10);
	nYear = parseInt(  sDate.substring(n2+1),10);

		if (nYear < 100)
		{
			if (nYear > 20)
				nYear = nYear + 1900;
			else
				nYear = nYear + 2000;
		}

	d = new Date();
	nCurrMonth = (d.getMonth() + 1);
	nCurrDay = d.getDate() ;
	nCurrYear = d.getFullYear();

	if ( nYear > nCurrYear ) return 1;
	if ( nYear < nCurrYear ) return -1;
	// Now nYear == nCurrYear
	if ( nMonth > nCurrMonth ) return 1;
	if ( nMonth < nCurrMonth ) return -1;
	// Now nMonth == nCurrMonth
	if ( nDay > nCurrDay ) return 1;
	if ( nDay < nCurrDay ) return -1;
	return 0;
}


//-------------------------------------------------------------------------------------
//Desc.  : Check if date value Start Date >= End Date
//Inputs : sStartDate: the editbox that contains from date
//			sEndDate  : the editbox that contains to date
//Outputs: true (StartDate >= EndDate), false (otherwise)
//Example: if (!ValidFromToDates(txtFromDate,txtToDate)== "0") return false;
//Edit date: 19/12/2003


function CompareDate( sStartDate, sEndDate){
var f, startDay, startMonth, startYear, endMonth, endDay, endYear, n1, n2,n3, n4;
n1 = sStartDate.indexOf( "/" );
n2 = sStartDate.lastIndexOf( "/" );
n3 = sEndDate.indexOf( "/" );
n4 = sEndDate.lastIndexOf( "/" );

startDay = parseInt( sStartDate.substring( 0, n1  ),10);
startMonth = parseInt( sStartDate.substring( n1 + 1, n2 ),10);
startYear = parseInt( sStartDate.substring( n2+1 ),10);

endDay = parseInt( sEndDate.substring( 0, n3  ),10);
endMonth = parseInt( sEndDate.substring( n3+1, n4 ),10);
endYear = parseInt( sEndDate.substring( n4+1 ),10);

if ( startYear > endYear ) return 1;
if ( startYear < endYear ) return -1;
// Now startYear == endYear
if ( startMonth > endMonth ) return 1;
if ( startMonth < endMonth ) return -1;
// Now startMonth == endMonth
if ( startDay > endDay ) return 1;
if ( startDay < endDay ) return -1;
return 0;
} // compareDate

//-------------------------------------------------------------------------------------
//Desc.  : Check if date value Start Date >= End Date
//Inputs : sStartDate: the editbox that contains from date
//			sEndDate  : the editbox that contains to date
//Outputs: true (StartDate >= EndDate), false (otherwise)
//Example: if (!ValidFromToDates(txtFromDate,txtToDate)== "0") return false;

function CompareDateOld( sStartDate, sEndDate){
var f, startDay, startMonth, startYear, endMonth, endDay, endYear, n1, n2,n3, n4;
n1 = sStartDate.indexOf( "/" );
n2 = sStartDate.lastIndexOf( "/" );
n3 = sEndDate.indexOf( "/" );
n4 = sEndDate.lastIndexOf( "/" );

startMonth = parseInt( sStartDate.substring( 0, n1  ),10);
startDay = parseInt( sStartDate.substring( n1 + 1, n2 ),10);
startYear = parseInt( sStartDate.substring( n2+1 ),10);

endMonth = parseInt( sEndDate.substring( 0, n3  ),10);
endDay = parseInt( sEndDate.substring( n3+1, n4 ),10);
endYear = parseInt( sEndDate.substring( n4+1 ),10);

if ( startYear > endYear ) return 1;
if ( startYear < endYear ) return -1;
// Now startYear == endYear
if ( startMonth > endMonth ) return 1;
if ( startMonth < endMonth ) return -1;
// Now startMonth == endMonth
if ( startDay > endDay ) return 1;
if ( startDay < endDay ) return -1;
return 0;
} // compareDate


//-----------------------------------------------------------------------------
//Desc.: Return Age when input a date of birth.
//Example: Age =  getAge(frmEdit.txtDate_Of_Birth.value)
//-----------------------------------------------------------------------------

function getAge(sDate)
{
var d,n1,n2, nMonth, nYear, nDay, nCurrMonth, nCurrYear, nCurrDay, nAge;

n1 = sDate.indexOf( "/" );
n2 = sDate.lastIndexOf( "/" );
nMonth = parseInt(  sDate.substring( 0, n1  ),10);
nDay = parseInt(  sDate.substring( n1+1, n2  ),10);
nYear = parseInt(  sDate.substring(n2+1),10);

		// DungNDV added 201 Aug 03rd to accept year in 2 digits
		if (nYear < 100)
		{
			if (nYear > 20)
				nYear = nYear + 1900;
			else
				nYear = nYear + 2000;
		}

d = new Date();
nCurrMonth = (d.getMonth() + 1);
nCurrDay = d.getDate() ;
nCurrYear = d.getFullYear();

nAge = nCurrYear - nYear - 1;
if ( (nCurrMonth > nMonth ) || (nCurrMonth == nMonth && nCurrDay >= nDay) ) nAge++;
return nAge;
}
//------------------------------
//-----------Check valid number
function	CheckIntegerDigits()
{
	if ((window.event.keyCode >=48 && window.event.keyCode<=57) ||
		(window.event.keyCode ==46) || (window.event.keyCode ==45))
	{
	}
	else
		window.event.keyCode =	0;
}
//-----------Check date is French
function isDateFrench(s)
{
	var sDay, sMonth, sYear, nMonth, nDay, nYear, nSep1, nSep2;
	nSep1 = s.indexOf( "/" );	if ( nSep1 < 0 ) return false;
	nSep2 = s.lastIndexOf( "/" );	if ( nSep2 < 0 ) return false;
	if ( nSep1 == nSep2 ) return false;

	sDay	= s.substring( 0, nSep1  );
	sMonth  = s.substring( nSep1 + 1, nSep2 );
	sYear	= s.substring( nSep2+1 );
	//alert(sMonth);
	if ( !sMonth.length || !sDay.length || sYear.length <4) return false;
	if ( isNaN(sMonth) || isNaN(sDay) || isNaN(sYear) ) return false;
	nMonth = parseInt(sMonth,10); nDay = parseInt(sDay,10); nYear = parseInt(sYear,10);

	if (nYear < 100)
	{
		if (nYear > 20)
			nYear = nYear + 1900;
		else
			nYear = nYear + 2000;
	}

	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 % 100 != 0)) { // leap year
			if ( nDay > 29 ) return false;
		} else if ( nDay > 28 ) return false;
	}
	return true;

}


//-------------------------------------------------------------------------------------
//Desc.  : kiem tra su ton tai cua mot ID
//Inputs : - txtItemList: the textbox that contains the ItemList
//		   - strAllItemList: the string that contains list of all item
//Outputs: No
//Example: CheckExistItem(txtItemList, strAllItemList, 'Spa Area')
//-------------------------------------------------------------------------------------
function CheckExistItem(txtItemList, strAllItemList, strItemName)
{

	var vcode =JTrim(txtItemList.value); 
	var j,clist,found1="";
	vcode=vcode.toUpperCase();
		clist=strAllItemList;

		clist=clist.split(",");				

		for(j=0;j<clist.length;j++){
			if(clist[j]==vcode) found1='yes';			
		}		
		if(found1=='yes'){
			alert("Code "+vcode+" of "+strItemName+"  is exist, Please input again!");
			return false;
		}	
		return true;			
}

//-------------------------------------------------------------------------------------
//Desc.  : kiem tra su ton tai cua mot ID
//Inputs : - txtItemList: the textbox that contains the ItemList
//		   - strAllItemList: the string that contains list of all item
//Outputs: No
//Example: CheckExistItemEdit(txtItemList, strAllItemList,strOld,strNew, 'Spa Area')
//-------------------------------------------------------------------------------------

function CheckExistItemEdit(txtItemList, strAllItemList,strOld,strNew, strItemName)
{

	var vcode =JTrim(txtItemList.value); 

	var j,clist,found1="";
		vcode=vcode.toUpperCase();
		clist=strAllItemList;

		clist=clist.split(",");				

		for(j=0;j<clist.length;j++){
			if(clist[j]==JTrim(vcode)) found1='yes';			
		}		
		if((found1=='yes') && (JTrim(strOld)!=JTrim(strNew.toUpperCase()))){
			alert("Code "+vcode+" of "+strItemName+"  is exist, Please input again!");
			return false;
		}	
		return true;			
}

//Ham mo 1 trang 
function fn_Goto(strPage, strParameter)
{
    window.location.href=strPage + strParameter;    
}

function Open_NewWin(Page,PageName,width, height)
{
    if(PageName=='')
        PageName='null';    
    if(width=='')
        width=600;
    if(height=='')
        height=400;
    
        
    window.open(Page,PageName,'toolbar=0, sizable=0, scrollbars=1, top=20, left=100, height='+ height + ',width='+width + '', '');
}
