/*This library file contains java validation functions that are used on HTML and ASP.
In the pages, you add following line to use these functions:
<script language="javascript" src="../foldername/JsCommFunctions.js"></script>
*/
//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 Number
//Example :	Onkeypress="javascript:FilterIntegerDigits();"
//-------------------------------------------------------------------------------------
function	FilterIntegerDigits1()
{
    //alert(window.event.keyCode);
	if ((window.event.keyCode >=48 && window.event.keyCode<=57))
	{
	}
	else
		window.event.keyCode =	0;
}

//-------------------------------------------------------------------------------------
//Desc.:	Check if input string is Number
//Example :	Onkeypress="javascript:FilterIntegerDigits();"
//-------------------------------------------------------------------------------------
function	FilterRealIntegerDigits()
{
    //alert(window.event.keyCode);
	if (window.event.keyCode >=48 && window.event.keyCode<=57 )
	{
	}
	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;
}
//--------------------
//
//
//-------------------------
function	GetCurrentHour()
{
	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;
}
//-------- hien thi ngay gio kieu moi ------------

	function GetThuNgay()
	{
		dowArray = new Array("Ch&#7911; nh&#7853;t", "Th&#7913; hai", "Th&#7913; ba", "Th&#7913; t&#432;","Th&#7913; n&#259;m", "Th&#7913; sáu", "Th&#7913; b&#7843;y");
		monthArray = new Array("tháng 1", "tháng 2", "tháng 3","tháng 4","tháng 5", "tháng 6", "tháng 7","tháng 8","tháng 9", "tháng 10", "tháng 11", "tháng 12");
		MyStrDate = new String;
		date = new Date();
		year = new String;
		month = new String;
		day = new String;
		//ngay = new String;
		dayow = new String;
		year = date.getYear();
		month = date.getMonth();
		day = date.getDate();
		//ngay = Left(day,2);
		dayow = date.getDay();
		//MyStrDate = dowArray[dayow]+", "+day+" / "+monthArray[month]+" / "+year;
		MyStrDate = dowArray[dayow]+", ngày "+day+" "+monthArray[month]+" năm "+year;
		MyStrDate = "" + MyStrDate + ""
		document.write(MyStrDate);
	}
	
//-------------------------------------------------------------------------------------
//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;    
}

//Begin "Ranking di pacon oi"
var sUrl = new Array(    
    "Default.aspx"                           //page 1    
    ,"Ticket.aspx"                          //page 2
    ,"Contact.aspx"
    ,"SiteMap.aspx"
    ,"Search.aspx"
    ,"Product.aspx"
    ,"ProDetail.aspx"
    ,"News.aspx"
    ,"Support.aspx"
    ,"FAQ.aspx"
    );    

    function fnRefresh()
    {
        ran = Math.random();
        value = Math.round((ran * (sUrl.length - 1)));
        iframeLoadData.document.location = sUrl[value];        
        //alert(sUrl[value]);    
    }

    //Dat tan suat refresh tinh = minisecond -------
    //setInterval('fnRefresh()', 15000);
    
//End of "Ranking di pacon oi" -------------    
//*********************************************************
//Ham tao chu chay tren statur bar                        *
//Original script by Brent Plugg, adapted by Rob Schluter.*
//*********************************************************
var timerId;
var msg = ""
var newMsg = ""
var counter = 0;
var nWait = 0.1
if (timerId != null) // is the timer already running?
   clearTimeout(timerId);

function pad() {
  var padding = "";
  for (var n=0; n<=(89); n++)
      padding += " ";
  return(padding);
}

function scroll() {
  window.status = newMsg.substring(counter,newMsg.length);
  if (counter == newMsg.length) {
     counter = 0;
  }
  counter ++;
  timerId = setTimeout("scroll()",nWait * 1000);
}

function startScroll(cMsgIn,nWaitIn) {
  msg = cMsgIn
  nWait = nWaitIn
  newMsg = pad() + msg + " ";
  scroll()
}

function displayMenu(SpanID,ImageID, Path)
	{
		if (document.all[SpanID].style.display=="") 
		{
			document.all[SpanID].style.display="none";
			document.images[ImageID].src=Path + "title_maximize.gif";
		}
		else {
			document.all[SpanID].style.display="";
			document.images[ImageID].src=Path + "title_minimize.gif";
		}
		
	}
function swapClass(obj,stylename){
		obj.className = stylename
	}
	
function numeralsOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        alert("Xin nhập số");
        return false;
    }
    return true;
}