// <!-- lib_validation.js -->
DT_NOTYPE		= 0
DT_INTEGER		= 1
DT_FLOAT		= 2
DT_DATE			= 3
DT_EMAIL		= 4
DT_NONSPECIAL	= 5

DT_NUMERIC		= 2

ERR_SUCCESS			= 0
ERR_EMPTY			= 1
ERR_WRONG_NUMBER	= 2
ERR_WRONG_INTEGER	= 3
ERR_WRONG_DATE		= 4
ERR_WRONG_EMAIL		= 5
ERR_WRONG_SPECIAL	= 6
ERR_VALUE_LESS		= 7
ERR_VALUE_GREATER	= 8
ERR_VALUE_BETWEEN	= 9
ERR_DATE_LESS		= 10
ERR_DATE_GREATER	= 11
ERR_DATE_BETWEEN	= 12

var fBrw=(navigator.userAgent.indexOf('MSIE')!= -1 && navigator.userAgent.indexOf('Windows')!= -1);
function openImage(vLink, vHeight, vWidth)
{
	var sLink = (typeof(vLink.href) == 'undefined') ? vLink : vLink.href;

	if (sLink == '')
	{
		return false;
	}

	winDef = 'status=no,resizable=no,scrollbars=0,toolbar=no,location=no,fullscreen=no,titlebar=yes,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	newwin = open('', '_blank', winDef);

	newwin.document.writeln('<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">');
	newwin.document.writeln('<a href="#" onClick="window.close(); return false;"><img src="', sLink, '" alt="', (fBrw) ? '&#272;&#243;ng l&#7841;i' : 'Dong lai', '" border=0></a>');
	newwin.document.writeln('</body>');

	if (typeof(vLink.href) != 'undefined')
	{
		return false;
	}
}
function openWindow(strPath,wName,wWidth,wHeight,wScrollbar,wToolbar,wStatus,wResize)
{
	var top = (screen.height - wHeight)/2;
	var left = (screen.width - wWidth)/2;
	return window.open(strPath,wName, "toolbar=" + wToolbar + ",location=no,directories=no,status=" + wStatus + ",menubar=no,scrollbars=" + wScrollbar + ",resizable=" + wResize + ",copyhistory=no, width=" + wWidth + ", height=" + wHeight + ", top=" + top + ",left=" + left);
}
function openFullscreen(url)
{
	if (this.name!='fullscreen')
			window.open(url,'fullscreen','fullscreen,scrollbars');
	else
		window.close(self);
}
String.prototype.Trim = function()
{
    var intLeft, intRight;
	var str = new String(this);	
	if (str.length==1 && str==" ") return "";	
	
	intLeft = 0;
	while ((str.charAt(intLeft) == " ") && (intLeft<str.length)) intLeft++;	
	intRight = str.length-1;
	while ((str.charAt(intRight) == " ") && (intRight>0)) intRight--;	
	if (intRight>=intLeft)
	{
		return str.substring(intLeft,intRight+1);		
	}
	else
	{
		return "";
	}	
};
String.prototype.Truncate = function(maxlength)
{
    if(this.length > maxlength)
    {
        var str = new String(this);
        str = str.substr(0, maxlength-2);
        var intLastBlank = str.lastIndexOf(" ");
        if(intLastBlank > 0)
        {
            return new String(str.substr(0, intLastBlank) + "...");
        }
        else
        {
            return new String(str + "...");
        }
    }
    else
    {
        return this;
    }
}
function Truncate(inputString, maxlength)
{
	inputString	=	new String(Trim(inputString));
	if(inputString.length > maxlength)
	{
		inputString	=	inputString.substr(0, maxlength-2)
		var intLastBlank	=	inputString.lastIndexOf(" ");
		if(intLastBlank > 0)
		{
			inputString	=	inputString.substr(0, intLastBlank) + "...";
		}
		else
		{
			inputString += "...";
		}
	}
	return Trim(inputString);
}
function getPager(totalItem, pageSize, pageNum)
{
	totalItem	=	eval(totalItem);
	pageSize	=	Math.max(pageSize, 1);
	
	var numPages	=	Math.ceil(totalItem/pageSize);
	pageNum		=	Math.max(pageNum, 1);
	pageNum 	=	Math.min(pageNum, numPages);
	
	var offset	=	(pageNum - 1) * pageSize;
	
	var objPager	=	new Object();
	objPager.offset		=	offset;
	objPager.pagesize	=	pageSize;
	objPager.numpages	=	numPages;
	objPager.page		=	pageNum;
	
	return objPager;
}
function findPosX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)
    {
        while(1) 
        {
            curleft += obj.offsetLeft;
            if(!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
    {
        while(1)
        {
            curtop += obj.offsetTop;
            if(!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}
function ValidateField(objWebControl)
{	
	return ValidateData(objWebControl,false,"");
}
function ValidateField1(objWebControl, strObjectCaption)
{	
	var strError = ""
	var intErrorCode = ERR_SUCCESS
	strError = ValidateData(objWebControl, false, "")	
	if(strError!=""){
		alert(strObjectCaption + ": " + strError)
		try{
			objWebControl.focus()
		}
		catch(err){
		}
		return false
	}
	return true;
}
function ValidateField2(objWebControl)
{	
	return ValidateData(objWebControl,true,"")	
}

function ValidateField3(objWebControl,strCaption)
{	
	return ValidateData(objWebControl,false,strCaption)
}

function ValidateData(objWebControl,getCode,strCaption)
{	
	var strError = ""
	var intErrorCode = ERR_SUCCESS
	var strHead
	if (strCaption!="") strHead = strCaption
	else strHead = ""
	
	if (objWebControl.Required==true) {
		if (objWebControl.value=="") {
			strError += "Value is required \n"			
			intErrorCode = ERR_EMPTY
		}
	}
	if (strError!="") {	
		if (getCode) return intErrorCode
		else return  strHead + strError
	}
	
	if (objWebControl.value=="") {
		if (getCode) return ERR_SUCCESS
		else return  ""
	}
	
	if (objWebControl.DataType!=DT_NOTYPE) {
		switch (objWebControl.DataType) {
			case DT_INTEGER:						
				if (checknumber(objWebControl.value)!=0) {
					strError += "Invalid numeric value\n"
					intErrorCode = ERR_WRONG_NUMBER
				}else{			
					strCheck = objWebControl.value + ""		
					if (strCheck.indexOf('.')!=-1) {
						strError += "Invalid integer value \n"						
						intErrorCode = ERR_WRONG_INTEGER
					}
				}
				break			
			case DT_FLOAT,DT_NUMERIC:
				if (checknumber(objWebControl.value)!=0) {
					strError += "Invalid numeric value \n"
					intErrorCode = ERR_WRONG_NUMBER
				}
				break;
			case DT_DATE:
				objWebControl.value = RefineDate(objWebControl.value)
				if (checkdate(objWebControl.value)!=0) {
					strError += "Invalid date \n"
					intErrorCode = ERR_WRONG_DATE
				}
				break;
			case DT_EMAIL:
				if (checkmailadd(objWebControl.value)!=0) {
					strError += "Invalid email address \n"
					intErrorCode = ERR_WRONG_EMAIL
				}
				break;
			case DT_NONSPECIAL:
				if (ContainSpecialChars(objWebControl.value)) {
					strError += "May not consists entirely of periods and/or spaces, or contain these characters: \n" + SPECIAL_STRING + "\n"
					intErrorCode = ERR_WRONG_SPECIAL
				}
				break;
		}
	}	
	if (strError!="") {	
		if (getCode) return intErrorCode
		else return  strHead + strError
	}
	
	if (objWebControl.DataType==DT_NONSPECIAL || objWebControl.DataType== DT_EMAIL) {
		if (getCode) return intErrorCode
		else return  strHead + strError
	}		
	var hasMinVal, hasMaxVal
	hasMinVal = false
	hasMaxVal = false
	if ( !isNaN(parseFloat(objWebControl.MinVal)) || (objWebControl.MinVal) ) hasMinVal = true
	if ( !isNaN(parseFloat(objWebControl.MaxVal)) || (objWebControl.MaxVal) ) hasMaxVal = true
	if (hasMinVal && hasMaxVal) {
		switch (objWebControl.DataType) {								
			case DT_DATE:			
				try {						
					var minDate = new Date(objWebControl.MinVal)
					var maxDate = new Date(objWebControl.MaxVal)					
					var curDate = new Date(objWebControl.value)
					if (curDate>maxDate || curDate<minDate) {
						strError += "Date value must be between " + objWebControl.MinVal + " and " + objWebControl.MaxVal + " \n"
						intErrorCode = ERR_DATE_BETWEEN
					}
				}
				catch(objException) {					
				}
				break;
			default:				
				if (objWebControl.value>objWebControl.MaxVal || objWebControl.value<objWebControl.MinVal) {
					strError += "Value must be between " + objWebControl.MinVal + " and " + objWebControl.MaxVal + " \n"
					intErrorCode = ERR_VALUE_BETWEEN
				}			
		}		
	} else if (hasMinVal && hasMaxVal==false) {
		switch (objWebControl.DataType) {								
			case DT_DATE:
				try {	
					var minDate = new Date(objWebControl.MinVal)		
					var curDate = new Date(objWebControl.value)
					if (curDate<minDate) {
						strError += "Date value must be greater than " + objWebControl.MinVal + " \n"
						intErrorCode = ERR_DATE_LESS
					}
				}
				catch(objException) {					
				}
				break;
			default:
				if (objWebControl.value<objWebControl.MinVal) {
					strError += "Value must be greater than " + objWebControl.MinVal + " \n"
					intErrorCode = ERR_VALUE_LESS
				}			
		}		
	} else if (hasMinVal==false && hasMaxVal) {
		switch (objWebControl.DataType) {								
			case DT_DATE:
				try {	
					var maxDate = new Date(objWebControl.MaxVal)		
					var curDate = new Date(objWebControl.value)
					if (curDate>maxDate) {
						strError += "Date value must be less than " + objWebControl.MaxVal + " \n"
						intErrorCode = ERR_DATE_GREATER
					}
				}
				catch(objException) {					
				}
				break;
			default:
				if (objWebControl.value>objWebControl.MaxVal) {
					strError += "Value must be less than " + objWebControl.MaxVal + " \n"
					intErrorCode = ERR_VALUE_GREATER
				}
		}
	}	
	if (getCode) return intErrorCode
	else {
		if (strError!="") return  strHead + strError	
		else return ""
	}
}

function isInteger(varInput)
{
	var intErrorCode = 0;
	if (checknumber(varInput)!=0) {		
		intErrorCode = ERR_WRONG_NUMBER
	}else{			
		strCheck = varInput + ""		
		if (strCheck.indexOf('.')!=-1) {			
			intErrorCode = ERR_WRONG_INTEGER
		}
	}
	
	return intErrorCode;
}

function checkdate(checkval) {
     var err=0
     a=RefineDate(checkval)
     if (a.length != 10) err=1 
     b = parseInt(a.substring(0, 2),10)// month
     c = a.substring(2, 3)// '/'
     d = parseInt(a.substring(3, 5),10)// day
     e = a.substring(5, 6)// '/'
     f = parseInt(a.substring(6, 10),10)// year
     if ((b<1 || b>12 || isNaN(a.substring(0, 2)) || a.substring(0, 2).indexOf('.') !=-1) ) err = 1 
     if (c != '/'&&c!='-') err = 1
     if ((d<1 || d>31|| isNaN(a.substring(3, 5)) || a.substring(3, 5).indexOf('.') !=-1) ) err = 1;
     if (e != '/'&&e!='-') err = 1 
     if (f<0000 || f>9999 || isNaN(a.substring(6, 10)) || a.substring(6, 10).indexOf('.') !=-1) err = 1 //whatever years are acceptable to you can be put here
     if (b==4 || b==6 || b==9 || b==11) {
          if (d==31) err=1
          }
     if (b==2){
          var g=parseInt(f/4,10)
          if (isNaN(g)) {
               err=1
          }
          if (d>29) err=1
          if (d==29 && ((f/4)!=parseInt(f/4,10))) err=1
     }
     return err
} 

function RefineDate(strDate)
{	//eliminate spaces
	var strPat = / /g
	strDate = strDate.replace(strPat,"")
	
	//find the seperator
	var strSeperator = "/"
	var intFirstSlash = strDate.indexOf(strSeperator)
	if (intFirstSlash==-1) {
		strSeperator = "-"
		intFirstSlash = strDate.indexOf(strSeperator)
	}	
	var intSecondSlash = strDate.lastIndexOf(strSeperator)	
	
	if (intFirstSlash <= 0 || intSecondSlash<=2 || 
		intSecondSlash-intFirstSlash<2 || strDate.length - intSecondSlash<2)
	{
		return strDate
	}
	
	//add zero numbers
	var strMonth = strDate.substring(0,intFirstSlash)
	var strDay = strDate.substring(intFirstSlash+1,intSecondSlash)
	var strYear = strDate.substring(intSecondSlash+1,strDate.length)
	if (strMonth.length==1) strMonth = '0' + strMonth
	if (strDay.length==1) strDay = '0' + strDay
	strDate = strMonth + strSeperator + strDay + strSeperator + strYear	
	return strDate
}

function checknumber(checkval)
{
	var err=0
	testnum=new Number(parseFloat(checkval))
	if (Trim(checkval)!=""){
		if (isNaN(parseFloat(checkval)) || Trim(testnum.toString())!=Trim(checkval)) {
			err=1
		}
	}
	return err
}

function checkmailadd(strEmail)
{
	var err=0
	var special2 = /\\|\/|\[|\]|\||\<|\>|\?|\*| |\"|\'|\%|\&|{|}/g
	var aintCheckEmail = strEmail.match(special2)
	if (aintCheckEmail!=null) err=1
	var intPosition,intQuantity,strDomain
	intPosition=-1
	intQuantity=0
	for (var intCount=0;intCount<=strEmail.length;intCount++)
	if(strEmail.charAt(intCount)=="@"){
		intQuantity++
		intPosition=intCount
	}
	//alert('quantity:' + intQuantity + ':' + intPosition)
	if((intQuantity>1)||(intPosition<=0)) err=1
	else{
		strDomain=strEmail.substr(intPosition+1,strEmail.length)
		if(strDomain.indexOf('.')<=0) err=1
	}
	return err
}

function Trim(strval)
{
	var intLeft, intRight	
	strvar = new String(strval)	
	if (strvar.length==1 && strvar==" ") return "";	
	
	intLeft = 0;
	while ((strvar.charAt(intLeft) == " ") && (intLeft<strvar.length)) intLeft++;	
	intRight = strvar.length-1;
	while ((strvar.charAt(intRight) == " ") && (intRight>0)) intRight--;	
	if (intRight>=intLeft) {
		return strvar.substring(intLeft,intRight+1)		
	} else {
		return ""
	}	
}

function IsDate(formname,fieldname)
{
	eval("var datefield=document."+formname+"."+fieldname)
	error = checkdate(datefield.value)
	if (Trim(datefield.value)!="") {
		if (error) {		
			datefield.focus()
			alert("Invalid date format")
		}
	}
}

function IsNumberNew(formname,fieldname)
{
	eval("var numfield=document."+formname+"."+fieldname)
	error = checknumber(numfield.value)
	if (Trim(numfield.value)!="") {
		if (error) {		
			alert("Invalid number format")		
			numfield.focus()
		}
	}
}

function IsNumber(formname,fieldname)
{
	eval("var numfield=document."+formname+"."+fieldname)
	testnum=new Number(parseFloat(numfield.value))
	if (Trim(numfield.value)!=""){
		if (isNaN(parseFloat(numfield.value)) || Trim(testnum.toString())!=Trim(numfield.value)) {
			alert("Invalid number format")
			numfield.focus()
		}
	}
}

function DayBetween(startdate,enddate)
{	
	var MinMilli = 1000 * 60;
	var HrMilli = MinMilli * 60;
	var DyMilli = HrMilli * 24;
  
	sdate = new Date(startdate)
	edate = new Date(enddate)		
	DayNumber = (edate.valueOf()-sdate.valueOf())/DyMilli
	return DayNumber+1
}

function DateAdd(datestr,addition)
{
	var MinMilli = 1000 * 60;
	var HrMilli = MinMilli * 60;
	var DyMilli = HrMilli * 24;
	addition--
	if (addition>0) {
		datevar = new Date(datestr)
		retdate = new Date(datevar.valueOf()+addition*DyMilli)

		day = retdate.getDate()<10 ? '0'+retdate.getDate():retdate.getDate();
		month = retdate.getMonth()+1
		month = month<10 ? '0'+month:month
		
		return month+'/'+day+'/'+retdate.getYear()
	} else 	return datestr
}

function ReplaceString(strInput,strFind,strReplace) {	
	eval('var template = /'+strFind+'/g')
	var strTemp = strInput.replace(template,strReplace)
	return strTemp
}

function RefineStr(strInput)
{
	var template = /'/g
	var strTemp = strInput.replace(template,"''")
	return strTemp
}

var SPECIAL_STRING = '\\ \/ \[ \] \: \| \< \> \+ \- \= \; , \? \* \" \' \% \( \) \& { }'
function ContainSpecialChars(strInput)
{
	if (strInput==null) return false;	
	var special = /\\|\/|\[|\]|\:|\||\<|\>|\+|\-|\=|\;|,|\?|\*| |\.|\"|\'|\%|\(|\)|\&|{|}/g
	var aintCheckResult = strInput.match(special)
	if (aintCheckResult!=null) return true;		
	return false;
}

function urlEncode(inStr) {
	outStr=' '; //not '' for a NS bug!
	for (i=0; i < inStr.length; i++) {
	aChar=inStr.substring (i, i+1);
	switch(aChar){
	case '%': outStr += "%25"; break; case ',': outStr += "%2C"; break;
	case '/': outStr += "%2F"; break; case ':': outStr += "%3A"; break;
	case '~': outStr += "%7E"; break; case '!': outStr += "%21"; break;
	case '"': outStr += "%22"; break; case '#': outStr += "%23"; break;
	case '$': outStr += "%24"; break; case "'": outStr += "%27"; break;
	case '`': outStr += "%60"; break; case '^': outStr += "%5E"; break;
	case '&': outStr += "%26"; break; case '(': outStr += "%28"; break;
	case ')': outStr += "%29"; break; case '+': outStr += "%2B"; break;
	case '{': outStr += "%7B"; break; case '|': outStr += "%7C"; break;
	case '}': outStr += "%7D"; break; case ';': outStr += "%3B"; break;
	case '<': outStr += "%3C"; break; case '=': outStr += "%3D"; break;
	case '>': outStr += "%3E"; break; case '?': outStr += "%3F"; break;
	case '[': outStr += "%5B"; break; case '\\': outStr += "%5C"; break;
	case ']': outStr += "%5D"; break; case ' ': outStr += "%20"; break;
	default: outStr += aChar;
	}
	}
	return outStr.substring(1, outStr.length);
}


var weekend = [0,6];
var weekendColor = "#e0e0e0";
var fontface = "Trebuchet MS";
var fontsize = 2;

var gNow = new Date();
var ggWinCal;
isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;

Calendar.Months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];

// Non-Leap year Month days..
Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

function Calendar(p_item, p_WinCal, p_month, p_year, p_format) {
	if ((p_month == null) && (p_year == null))	return;

	if (p_WinCal == null)
		this.gWinCal = ggWinCal;
	else
		this.gWinCal = p_WinCal;
	
	if (p_month == null) {
		this.gMonthName = null;
		this.gMonth = null;
		this.gYearly = true;
	} else {
		this.gMonthName = Calendar.get_month(p_month);
		this.gMonth = new Number(p_month);
		this.gYearly = false;
	}

	this.gYear = p_year;
	this.gFormat = p_format;
	this.gBGColor = "white";
	this.gFGColor = "black";
	this.gTextColor = "black";
	this.gHeaderColor = "black";
	this.gReturnItem = p_item;
}

Calendar.get_month = Calendar_get_month;
Calendar.get_daysofmonth = Calendar_get_daysofmonth;
Calendar.calc_month_year = Calendar_calc_month_year;
Calendar.print = Calendar_print;

function Calendar_get_month(monthNo) {
	return Calendar.Months[monthNo];
}

function Calendar_get_daysofmonth(monthNo, p_year) {
	/* 
	Check for leap year ..
	1.Years evenly divisible by four are normally leap years, except for... 
	2.Years also evenly divisible by 100 are not leap years, except for... 
	3.Years also evenly divisible by 400 are leap years. 
	*/
	if ((p_year % 4) == 0) {
		if ((p_year % 100) == 0 && (p_year % 400) != 0)
			return Calendar.DOMonth[monthNo];
	
		return Calendar.lDOMonth[monthNo];
	} else
		return Calendar.DOMonth[monthNo];
}

function Calendar_calc_month_year(p_Month, p_Year, incr) {
	/* 
	Will return an 1-D array with 1st element being the calculated month 
	and second being the calculated year 
	after applying the month increment/decrement as specified by 'incr' parameter.
	'incr' will normally have 1/-1 to navigate thru the months.
	*/
	var ret_arr = new Array();
	
	if (incr == -1) {
		// B A C K W A R D
		if (p_Month == 0) {
			ret_arr[0] = 11;
			ret_arr[1] = parseInt(p_Year) - 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) - 1;
			ret_arr[1] = parseInt(p_Year);
		}
	} else if (incr == 1) {
		// F O R W A R D
		if (p_Month == 11) {
			ret_arr[0] = 0;
			ret_arr[1] = parseInt(p_Year) + 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) + 1;
			ret_arr[1] = parseInt(p_Year);
		}
	}
	
	return ret_arr;
}

function Calendar_print() {
	ggWinCal.print();
}

function Calendar_calc_month_year(p_Month, p_Year, incr) {
	/* 
	Will return an 1-D array with 1st element being the calculated month 
	and second being the calculated year 
	after applying the month increment/decrement as specified by 'incr' parameter.
	'incr' will normally have 1/-1 to navigate thru the months.
	*/
	var ret_arr = new Array();
	
	if (incr == -1) {
		// B A C K W A R D
		if (p_Month == 0) {
			ret_arr[0] = 11;
			ret_arr[1] = parseInt(p_Year) - 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) - 1;
			ret_arr[1] = parseInt(p_Year);
		}
	} else if (incr == 1) {
		// F O R W A R D
		if (p_Month == 11) {
			ret_arr[0] = 0;
			ret_arr[1] = parseInt(p_Year) + 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) + 1;
			ret_arr[1] = parseInt(p_Year);
		}
	}
	
	return ret_arr;
}

// This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists.
new Calendar();

Calendar.prototype.getMonthlyCalendarCode = function() {
	var vCode = "";
	var vHeader_Code = "";
	var vData_Code = "";
	
	// Begin Table Drawing code here..
	vCode = vCode + "<table width='100%' border=0 cellspacing=0 bgcolor=\"" + this.gBGColor + "\">";
	
	vHeader_Code = this.cal_header();
	vData_Code = this.cal_data();
	vCode = vCode + vHeader_Code + vData_Code;
	
	vCode = vCode + "</table>";
	
	return vCode;
}

Calendar.prototype.show = function() {
	var vCode = "";
	
	this.gWinCal.document.open();

	// Setup the page...
	this.wwrite("<html>");
	this.wwrite("<head><title>Calendar</title>");	
	this.wwrite("<style>.a { text-decoration:none } </style>");
	this.wwrite("</head>");

	this.wwrite("<body bgcolor=\"white\" " + 
		"link=\"" + this.gLinkColor + "\" " + 
		"vlink=\"" + this.gLinkColor + "\" " +
		"alink=\"" + this.gLinkColor + "\" " +
		"text=\"" + this.gTextColor + "\">");
	this.wwriteA("<font face='" + fontface + "' size=2><b>");
	this.wwriteA(this.gMonthName + " " + this.gYear);
	this.wwriteA("</b><br />");

	// Show navigation buttons
	var prevMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, -1);
	var prevMM = prevMMYYYY[0];
	var prevYYYY = prevMMYYYY[1];

	var nextMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, 1);
	var nextMM = nextMMYYYY[0];
	var nextYYYY = nextMMYYYY[1];
	
	this.wwrite("<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td align='center'>");
	this.wwrite("[<a href=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "'" +
		");" +
		"\"><<<\/a>]</td><td align='center'>");
	this.wwrite("[<a href=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\"><<\/a>]</td><td align='center'>");
	this.wwrite("[<a href=\"javascript:window.print();\">Print</a>]</td><ta align='center'>");
	this.wwrite("[<a href=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\">><\/a>]</td><td align='center'>");
	this.wwrite("[<a href=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "'" +
		");" +
		"\">>><\/a>]</td></tr></table><br />");

	// Get the complete calendar code for the month..
	vCode = this.getMonthlyCalendarCode();
	this.wwrite(vCode);

	this.wwrite("</font></body></html>");
	this.gWinCal.document.close();
}

Calendar.prototype.showY = function() {
	var vCode = "";
	var i;
	var vr, vc, vx, vy;		// Row, Column, X-coord, Y-coord
	var vxf = 285;			// X-Factor
	var vyf = 200;			// Y-Factor
	var vxm = 10;			// X-margin
	var vym;				// Y-margin
	if (isIE)	vym = 75;
	else if (isNav)	vym = 25;
	
	this.gWinCal.document.open();

	this.wwrite("<html>");
	this.wwrite("<head><title>Calendar</title>");
	this.wwrite("<style type='text/css'>\n<!--");
	for (i=0; i<12; i++) {
		vc = i % 3;
		if (i>=0 && i<= 2)	vr = 0;
		if (i>=3 && i<= 5)	vr = 1;
		if (i>=6 && i<= 8)	vr = 2;
		if (i>=9 && i<= 11)	vr = 3;
		
		vx = parseInt(vxf * vc) + vxm;
		vy = parseInt(vyf * vr) + vym;

		this.wwrite(".lclass" + i + " {position:absolute;top:" + vy + ";left:" + vx + ";}");
	}
	this.wwrite("-->\n</style>");
	this.wwrite("</head>");

	this.wwrite("<body " + 
		"link=\"" + this.gLinkColor + "\" " + 
		"vlink=\"" + this.gLinkColor + "\" " +
		"alink=\"" + this.gLinkColor + "\" " +
		"text=\"" + this.gTextColor + "\">");
	this.wwrite("<font face='" + fontface + "' size=2><a>");
	this.wwrite("Year : " + this.gYear);
	this.wwrite("</a><br />");

	// Show navigation buttons
	var prevYYYY = parseInt(this.gYear) - 1;
	var nextYYYY = parseInt(this.gYear) + 1;
	
	this.wwrite("<table width='100%' border=0 cellspacing=0 cellpadding=0 bgcolor='#e0e0e0'><tr><td align=center>");
	this.wwrite("[<a href=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\" alt='Prev Year'><<<\/a>]</td><td align=center>");
	this.wwrite("[<a href=\"javascript:window.print();\">Print</a>]</td><td align=center>");
	this.wwrite("[<a href=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\">>><\/a>]</td></tr></table><br />");

	// Get the complete calendar code for each month..
	var j;
	for (i=11; i>=0; i--) {
		if (isIE)
			this.wwrite("<div id=\"layer" + i + "\" class=\"lclass" + i + "\">");
		else if (isNav)
			this.wwrite("<layer id=\"layer" + i + "\" class=\"lclass" + i + "\">");

		this.gMonth = i;
		this.gMonthName = Calendar.get_month(this.gMonth);
		vCode = this.getMonthlyCalendarCode();
		this.wwrite(this.gMonthName + "/" + this.gYear + "<BR>");
		this.wwrite(vCode);

		if (isIE)
			this.wwrite("</div>");
		else if (isNav)
			this.wwrite("</layer>");
	}

	this.wwrite("</font><br /></body></html>");
	this.gWinCal.document.close();
}

Calendar.prototype.wwrite = function(wtext) {
	this.gWinCal.document.writeln(wtext);
}

Calendar.prototype.wwriteA = function(wtext) {
	this.gWinCal.document.write(wtext);
}

Calendar.prototype.cal_header = function() {
	var vCode = "";
	
	vCode = vCode + "<tr>";
	vCode = vCode + "<td width='14%'><font size='2' face='" + fontface + "' color='" + this.gHeaderColor + "'><b>Sun</b></font></td>";
	vCode = vCode + "<td width='14%'><font size='2' face='" + fontface + "' color='" + this.gHeaderColor + "'><b>Mon</b></font></td>";
	vCode = vCode + "<td width='14%'><font size='2' face='" + fontface + "' color='" + this.gHeaderColor + "'><b>Tue</b></font></td>";
	vCode = vCode + "<td width='14%'><font size='2' face='" + fontface + "' color='" + this.gHeaderColor + "'><b>Wed</b></font></td>";
	vCode = vCode + "<td width='14%'><font size='2' face='" + fontface + "' color='" + this.gHeaderColor + "'><b>Thu</b></font></td>";
	vCode = vCode + "<td width='14%'><font size='2' face='" + fontface + "' color='" + this.gHeaderColor + "'><b>Fri</b></font></td>";
	vCode = vCode + "<v width='16%'><font size='2' face='" + fontface + "' color='" + this.gHeaderColor + "'><b>Sat</b></font></td>";
	vCode = vCode + "</tr>";
	
	return vCode;
}

Calendar.prototype.cal_data = function() {
	var vDate = new Date();
	vDate.setDate(1);
	vDate.setMonth(this.gMonth);
	vDate.setFullYear(this.gYear);

	var vFirstDay=vDate.getDay();
	var vDay=1;
	var vLastDay=Calendar.get_daysofmonth(this.gMonth, this.gYear);
	var vOnLastDay=0;
	var vCode = "";

	/*
	Get day for the 1st of the requested month/year..
	Place as many blank cells before the 1st day of the month as necessary. 
	*/

	vCode = vCode + "<tr>";
	for (i=0; i<vFirstDay; i++) {
		vCode = vCode + "<td width='14%'" + this.write_weekend_string(i) + "><font size='2' face='" + fontface + "'>&nbsp;</font></td>";
	}

	// Write rest of the 1st week
	for (j=vFirstDay; j<7; j++) {
		vCode = vCode + "<td width='14%'" + this.write_weekend_string(j) + "><font size='2' face='" + fontface + "'>" + 
			"<a href='#' " + 
				"onClick=\"self.opener.document." + this.gReturnItem + ".value='" + 
				this.format_data(vDay) + 
				"';window.close();\">" + 
				this.format_day(vDay) + 
			"</a>" + 
			"</font></td>";
		vDay=vDay + 1;
	}
	vCode = vCode + "</tr>";

	// Write the rest of the weeks
	for (k=2; k<7; k++) {
		vCode = vCode + "<tr>";

		for (j=0; j<7; j++) {
			vCode = vCode + "<td width='14%'" + this.write_weekend_string(j) + "><font size='2' face='" + fontface + "'>" + 
				"<a href='#' " + 
					"onClick=\"self.opener.document." + this.gReturnItem + ".value='" + 
					this.format_data(vDay) + 
					"';window.close();\">" + 
				this.format_day(vDay) + 
				"</a>" + 
				"</font></td>";
			vDay=vDay + 1;

			if (vDay > vLastDay) {
				vOnLastDay = 1;
				break;
			}
		}

		if (j == 6)
			vCode = vCode + "</tr>";
		if (vOnLastDay == 1)
			break;
	}
	
	// Fill up the rest of last week with proper blanks, so that we get proper square blocks
	for (m=1; m<(7-j); m++) {
		if (this.gYearly)
			vCode = vCode + "<td width='14%'" + this.write_weekend_string(j+m) + 
			"><font size='2' face='" + fontface + "' color='gray'>&nbsp;</font></td>";
		else
			vCode = vCode + "<td width='14%'" + this.write_weekend_string(j+m) + 
			"><font size='2' face='" + fontface + "' color='gray'>" + m + "</font></td>";
	}
	
	return vCode;
}

Calendar.prototype.format_day = function(vday) {
	var vNowDay = gNow.getDate();
	var vNowMonth = gNow.getMonth();
	var vNowYear = gNow.getFullYear();

	if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
		return ("<font color=\"red\"><b>" + vday + "</b></font>");
	else
		return (vday);
}

Calendar.prototype.write_weekend_string = function(vday) {
	var i;

	// Return special formatting for the weekend day.
	for (i=0; i<weekend.length; i++) {
		if (vday == weekend[i])
			return (" bgcolor=\"" + weekendColor + "\"");
	}
	
	return "";
}

Calendar.prototype.format_data = function(p_day) {
	var vData;
	var vMonth = 1 + this.gMonth;
	vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
	var vMon = Calendar.get_month(this.gMonth).substr(0,3).toUpperCase();
	var vFMon = Calendar.get_month(this.gMonth).toUpperCase();
	var vY4 = new String(this.gYear);
	var vY2 = new String(this.gYear.substr(2,2));
	var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day;

	switch (this.gFormat) {
		case "MM\/DD\/YYYY" :
			vData = vMonth + "\/" + vDD + "\/" + vY4;
			break;
		case "MM\/DD\/YY" :
			vData = vMonth + "\/" + vDD + "\/" + vY2;
			break;
		case "MM-DD-YYYY" :
			vData = vMonth + "-" + vDD + "-" + vY4;
			break;
		case "MM-DD-YY" :
			vData = vMonth + "-" + vDD + "-" + vY2;
			break;

		case "DD\/MON\/YYYY" :
			vData = vDD + "\/" + vMon + "\/" + vY4;
			break;
		case "DD\/MON\/YY" :
			vData = vDD + "\/" + vMon + "\/" + vY2;
			break;
		case "DD-MON-YYYY" :
			vData = vDD + "-" + vMon + "-" + vY4;
			break;
		case "DD-MON-YY" :
			vData = vDD + "-" + vMon + "-" + vY2;
			break;

		case "DD\/MONTH\/YYYY" :
			vData = vDD + "\/" + vFMon + "\/" + vY4;
			break;
		case "DD\/MONTH\/YY" :
			vData = vDD + "\/" + vFMon + "\/" + vY2;
			break;
		case "DD-MONTH-YYYY" :
			vData = vDD + "-" + vFMon + "-" + vY4;
			break;
		case "DD-MONTH-YY" :
			vData = vDD + "-" + vFMon + "-" + vY2;
			break;

		case "DD\/MM\/YYYY" :
			vData = vDD + "\/" + vMonth + "\/" + vY4;
			break;
		case "DD\/MM\/YY" :
			vData = vDD + "\/" + vMonth + "\/" + vY2;
			break;
		case "DD-MM-YYYY" :
			vData = vDD + "-" + vMonth + "-" + vY4;
			break;
		case "DD-MM-YY" :
			vData = vDD + "-" + vMonth + "-" + vY2;
			break;

		default :
			vData = vMonth + "\/" + vDD + "\/" + vY4;
	}

	return vData;
}

function Build(p_item, p_month, p_year, p_format) {
	var p_WinCal = ggWinCal;
	gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format);

	// Customize your Calendar here..
	gCal.gBGColor="white";
	gCal.gLinkColor="black";
	gCal.gTextColor="black";
	gCal.gHeaderColor="darkgreen";

	// Choose appropriate show function
	if (gCal.gYearly)	gCal.showY();
	else	gCal.show();
}

function show_calendar() {
	/* 
		p_month : 0-11 for Jan-Dec; 12 for All Months.
		p_year	: 4-digit year
		p_format: Date format (mm/dd/yyyy, dd/mm/yy, ...)
		p_item	: Return Item.
	*/

	p_item = arguments[0];
	if (arguments[1] == null)
		p_month = new String(gNow.getMonth());
	else
		p_month = arguments[1];
	if (arguments[2] == "" || arguments[2] == null)
		p_year = new String(gNow.getFullYear().toString());
	else
		p_year = arguments[2];
	if (arguments[3] == null)
		p_format = "MM/DD/YYYY";
	else
		p_format = arguments[3];

	vWinCal = window.open("", "Calendar", 
		"width=250,height=220,status=no,resizable=no,top=200,left=200");
	vWinCal.opener = self;
	ggWinCal = vWinCal;

	Build(p_item, p_month, p_year, p_format);
}
/*
Yearly Calendar Code Starts here
*/
function show_yearly_calendar(p_item, p_year, p_format) {
	// Load the defaults..
	if (p_year == null || p_year == "")
		p_year = new String(gNow.getFullYear().toString());
	if (p_format == null || p_format == "")
		p_format = "MM/DD/YYYY";

	var vWinCal = window.open("", "Calendar", "scrollbars=yes");
	vWinCal.opener = self;
	ggWinCal = vWinCal;

	Build(p_item, null, p_year, p_format);
}


//check numeric of Duc Duong
function isNumeric(str){
	str+=""
	if (isNaN(str)) return false
	for (var i=0;i<str.length;i++)
	if (str.charAt(i)==".") return false
	return true
}

//check numeric of Hoa Nguyen
function isFloatGreaterThan0(str)
{
	if(checknumber(str) == 0)
		if(eval(str) > 0)	return true;
		
	return false;
}

//check numeric of Hoa Nguyen
function isFloatGreaterThanOrEqualTo0(str)
{
	if(checknumber(str) == 0)
		if(eval(str) >= 0)	return true;
	return false;
}

//check numeric of Hoa Nguyen
function isNumericGreaterThanOrEqualTo0(str)
{
	var ch;
	str += "";
	if (isNaN(str)) return false;
	for (var i=0;i<str.length;i++)
		if (str.charAt(i)==".") return false;
	
	ch = str.charAt(0);
	if(ch <'0' || ch > '9') return false;
	return true;
}

//check numeric of Hoa Nguyen
function isNumericGreaterThan0(str)
{
	var ch;
	str += "";
	if (isNaN(str)) return false;
	for (var i=0;i<str.length;i++)
		if (str.charAt(i)==".") return false;
	
	ch = str.charAt(0);
	if(ch <'0' || ch > '9') return false;
	if(eval(str) == 0) return false;
	return true;
}

//Check and refine date
//Added by Duc Duong Feb-20-2002
function isDateOfDucDuong(str){
	if ((str.length>10)||(str.length<8)) return null
	intDash = str.search("/")
	if (intDash == -1) return null
	else
	{
		strTemp = str.substr(0,intDash)
		if ((strTemp.charAt(0) == "0")&&(strTemp.length>1)) strTemp = strTemp.substr(1)
		if (isNumeric(strTemp)==false) return null
		else{	
			intMonth = parseInt(strTemp)
			if ((intMonth<1)||(intMonth>12))	return null
			intDayN = 30
			if ((intMonth<8)&&(intMonth % 2 == 1)) intDayN = 31
			if ((intMonth>7)&&(intMonth % 2 == 0)) intDayN = 31
		}	
		str = str.substr(intDash+1)
	}
	intDash = str.search("/")
	if (intDash == -1) return null
	else
	{
		strTemp = str.substr(0,intDash)
		if ((strTemp.charAt(0) == "0")&&(strTemp.length>1)) strTemp = strTemp.substr(1)
		if (isNumeric(strTemp)==false) return null
		else
		{
			intDay = parseInt(strTemp)
			if ((intDay<1)||(intDay>intDayN))return null
		}	
		str = str.substr(intDash+1)
	}	
	if (isNumeric(str)==false) return null
	else
	{	
		intYear = parseInt(str)
		if ((intYear<1900)||(intYear>2100))	return null
	}	
	if (intMonth==2)
	{
		if (intYear % 4 == 0) intDayN = 29
		else intDayN = 28
		if (intDay > intDayN) return null
	}
	strTemp = ""
	if (intMonth<10) strTemp = strTemp + "0" + intMonth + "/"
	else strTemp = strTemp + intMonth + "/"
	if (intDay<10) strTemp = strTemp + "0" + intDay + "/"
	else strTemp = strTemp + intDay + "/"
	strTemp = strTemp + intYear
	return strTemp
}

function setCookie(name, value, expire) {
	document.cookie = name + "=" + escape(value)
	+ ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

function getCookie(Name) {
	var search = Name + "="
	if (document.cookie.length > 0) { 
		offset = document.cookie.indexOf(search)
		if (offset != -1) {
			offset += search.length
			end = document.cookie.indexOf(";", offset)
			if (end == -1)
				end = document.cookie.length
			return unescape(document.cookie.substring(offset, end))
		}
	}
	return "";
}

function DeleteArrayElement(arrInput,intIndex)
{	
	if (arrInput==null) return null
	//if (arrInput.length==1) return null
	//if array has more than one element, copy it to a new array
	var arrResult = new Array()
	var intCount,intInc
	intInc = 0
	for (intCount=0;intCount<arrInput.length;intCount++) {
		if (intCount!=intIndex) {			
			arrResult[intInc] = arrInput[intCount]
			intInc++
		}
	}
	//Return the new array
	return arrResult
}

function ZeroAdd(strInput,intLen)
{
	strTemp = strInput + ''
	var intAdded = intLen - strTemp.length;
	if (intAdded>0 ) {
		for (var i=0; i<intAdded; i++) {
			strTemp = '0'+ strTemp
		}
	}
	return strTemp;
}

function ValidatePhoneNumber(strInput)
{
	var patRefine = /  /g
	while (strInput.match(patRefine)) strInput = strInput.replace(patRefine," ")
	var patPhonePattern = /\(\d{3}\) \d{3}-\d{4}/
	return strInput.match(patPhonePattern)!=null
}

function HTMLEncode(t) {  
  var t = t.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
  return(t.replace(/</g, "&lt;").replace(/>/g, "&gt;"));
}

function SortList(oList,blnASC)
{
	var i, blnSwap;
	for (i=0; i<oList.length-1; i++) 
	{
		for (j=i+1; j<oList.length; j++) {
			blnSwap = blnASC==true ? parseInt(oList.item(i).value) > parseInt(oList.item(j).value) : parseInt(oList.item(i).value) < parseInt(oList.item(j).value);
			if (blnSwap==true) oList.children(i).swapNode(oList.children(j));
		}
	}
}

function KillSpace(strInput)
{
	return strInput.replace(/ /g,"");
}

function ChangeCase(strInput,blnUpCase)
{
	strInput = strInput.replace(/ /g,"");
	arrCase = new Array(
				new Array("�?","á"), 
				new Array("À","à"), 
				new Array("?","?"), 
				new Array("Ã","ã"), 
				new Array("?","?"), 
				new Array("A","a"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("Â","â"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("Ó","ó"), 
				new Array("Ò","ò"), 
				new Array("?","?"), 
				new Array("Õ","õ"), 
				new Array("?","?"), 
				new Array("Ô","ô"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("O","o"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("Ú","ú"), 
				new Array("Ù","ù"), 
				new Array("?","?"), 
				new Array("U","u"), 
				new Array("?","?"), 
				new Array("U","u"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("É","é"), 
				new Array("È","è"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("Ê","ê"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("�?","í"), 
				new Array("Ì","ì"), 
				new Array("?","?"), 
				new Array("I","i"), 
				new Array("?","?"), 
				new Array("�?","ý"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("?","?"), 
				new Array("�?","d")
			)
	var patAZ = blnUpCase==true ? /[a-z]/g : /[A-Z]/g
	var arrMatch = strInput.match(patAZ);	
	var i;
	if (arrMatch!=null) {	
		for (i=0; i<arrMatch.length; i++) {
			strInput = strInput.replace(arrMatch[i],(arrMatch[i]+"").toUpperCase())		
		}
	}
	for (i=0; i<arrCase.length; i++) {
		if (blnUpCase) {
			strInput = strInput.replace(arrCase[i][1],arrCase[i][0])
		} else {
			strInput = strInput.replace(arrCase[i][0],arrCase[i][1])
		}
	}
	
	return strInput;
}