//  ------------------------------------------------------------------------------------------------------------------------------------
// Typing Text Script
//  ------------------------------------------------------------------------------------------------------------------------------------
function reloading()
{
	counter = getCookie('counter');
		
	if (counter < 1 || counter == null){
		counter++;
		document.location.reload();
	} 
	else{
		counter = 0;
	}
	setCookie('counter', counter);
}
	
function getCookie(name)
{
	 var dc = document.cookie;
	 var prefix = name + "=";
	 var begin = dc.indexOf("; " + prefix);
	
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	 } else
		begin += 2;
	
	var end = document.cookie.indexOf(";", begin);
	 if (end == -1)
		end = dc.length;
		
	 return unescape(dc.substring(begin + prefix.length, end));
}
	
function setCookie(name, value, expires, path, domain, secure) 
{
	 var curCookie = name + "=" + escape(value) +
		  ((expires) ? "; expires=" + expires.toGMTString() : "") +
		  ((path) ? "; path=" + path : "") +
		  ((domain) ? "; domain=" + domain : "") +
		  ((secure) ? "; secure" : "");
	 document.cookie = curCookie;
}

//  ------------------------------------------------------------------------------------------------------------------------------------
// Typing Text Script
//  ------------------------------------------------------------------------------------------------------------------------------------

var it=0;
function initialize()
{
	mytext = typing.innerText;
	var myheight = typing.offsetHeight;
	typing.innerText = '';
	document.all.typing.style.height = myheight;
	document.all.typing.style.visibility = "visible";
	typeit();
}

function typeit()
{
	typing.insertAdjacentText("beforeEnd",mytext.charAt(it));
	if (it < mytext.length-1)
	{
		it++;
		setTimeout("typeit()", 100);
	}
	else
		return;
}


// -----------------------------------------------------------------------------------------------------------------------------------
// Date and Clock 
// -----------------------------------------------------------------------------------------------------------------------------------

	function tS(){ x=new Date(); x.setTime(x.getTime()); return x; } 
	function lZ(x){ return (x>9)?x:'0'+x; } 
	function tH(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; } 
	function y2(x){ x=(x<500)?x+1900:x; return String(x).substring(2,4) } 
	function dT(){ if(fr==0){ fr=1; document.write('<font size=2 color= #ffffff face=Verdana><b><span id="tP">'+eval(oT)+'</span></b></font>'); } tP.innerText=eval(oT); setTimeout('dT()',1000); } 
	
	function dT_Portal_StudentUPSR()
	{
		if(fr==0)
		{
			fr=1; 
			document.write('<td valign="middle" background="images/templates/portal/studentUPSR/upsr_current-date-bg_02.jpg"><font size=2 color= #ffffff face=Verdana><span id="tP1">'+eval(oT1)+'</span></font></td>');
			document.write('<td valign="middle" align="right" background="images/templates/portal/studentUPSR/upsr_current-date-bg_02.jpg"><font size=2 color= #ffffff face=Verdana><span id="tP2">'+eval(oT2)+'</span></font></td>');
		}
		tP1.innerText=eval(oT1); 
		tP2.innerText=eval(oT2); 
		setTimeout('dT_Portal_StudentUPSR()',1000); 
	} 
	
	function dT_Banner_StudentUPSR()
	{
		if(fr==0)
		{
			fr=1; 
			document.write('<td width="110" align="right" valign="middle" background="images/templates/banner/studentUPSR/UPSR_system_img02.jpg"><font size=2 color= #ffffff face=Verdana><span id="tP1">'+eval(oT1)+'</span></font></td>');
			document.write('<td width="573"><img border="0" src="images/templates/banner/studentUPSR/UPSR_system_menu.jpg" usemap="#Map"></td>');
			document.write('<td width="112" valign="middle" align="left" background="images/templates/banner/studentUPSR/UPSR_system_img03.jpg"><font size=2 color= #ffffff face=Verdana><span id="tP2">'+eval(oT2)+'</span></font></td>');
		}
		tP1.innerText=eval(oT1); 
		tP2.innerText=eval(oT2); 
		setTimeout('dT_Banner_StudentUPSR()',1000); 
	} 
	
	function aP(x){ return (x>11)?'pm':'am'; } 
	var dN=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
	var mN=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
	var fr=0;
	var oT="dN[tS().getDay()]+' '+tS().getDate()+' '+mN[tS().getMonth()]+' '+y2(tS().getYear())+','+' '+tH(tS().getHours())+':'+lZ(tS().getMinutes())+':'+lZ(tS().getSeconds())+' '+aP(tS().getHours())";
	var oT1="dN[tS().getDay()]";
	var oT2="tS().getDate()+' '+mN[tS().getMonth()]+' '+y2(tS().getYear())";

// -----------------------------------------------------------------------------------------------------------------------------------
// Calendar Date Picker 
// -----------------------------------------------------------------------------------------------------------------------------------

var weekend = [0,6];
var weekendColor = "#e0e0e0";
var fontface = "Verdana";
var fontsize = 8;			// in "pt" units; used with "font-size" style element

var gNow = new Date();
var ggWinContent;
var ggPosX = -1;
var ggPosY = -1;

Calendar.Months = ["January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December"];

Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];// Non-Leap year Month days..
Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];// Leap year Month days..

function Calendar(p_item, p_month, p_year, p_format) 
{
	if ((p_month == null) && (p_year == null))	return;

	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;

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_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;
}

new Calendar(); // This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists.

Calendar.prototype.getMonthlyCalendarCode = function() 
{
	var vCode = "";
	var vHeader_Code = "";
	var vData_Code = "";
	
	vCode += ("<div align=center><TABLE BORDER=1 BGCOLOR=\"" + this.gBGColor + "\" style='font-size:" + fontsize + "pt;'>");
	vHeader_Code = this.cal_header();
	vData_Code = this.cal_data();
	vCode += (vHeader_Code + vData_Code);
	vCode += "</TABLE></div>";
	
	return vCode;
}

Calendar.prototype.show = function() {
	var vCode = "";

	ggWinContent += ("<FONT FACE='" + fontface + "' ><B>");	// build content into global var ggWinContent
	ggWinContent += (this.gMonthName + " " + this.gYear);
	ggWinContent += "</B><BR>";
	
	var prevMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, -1);	// Show navigation buttons
	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];
	
	ggWinContent += ("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0' style='font-size:" + fontsize + "pt;'><TR><TD ALIGN=center>");
	ggWinContent += ("[<A HREF=\"javascript:void(0);\" " +
		"onMouseOver=\"window.status='Go back one year'; return true;\" " +
		"onMouseOut=\"window.status=''; return true;\" " +
		"onClick=\"Build(" + 
		"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "'" +
		");" +
		"\"><<Year<\/A>]</TD><TD ALIGN=center>");
	ggWinContent += ("[<A HREF=\"javascript:void(0);\" " +
		"onMouseOver=\"window.status='Go back one month'; return true;\" " +
		"onMouseOut=\"window.status=''; return true;\" " +
		"onClick=\"Build(" + 
		"'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\"><Mon<\/A>]</TD><TD ALIGN=center>");
	ggWinContent += "       </TD><TD ALIGN=center>";
	ggWinContent += ("[<A HREF=\"javascript:void(0);\" " +
		"onMouseOver=\"window.status='Go forward one month'; return true;\" " +
		"onMouseOut=\"window.status=''; return true;\" " +
		"onClick=\"Build(" + 
		"'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\">Mon><\/A>]</TD><TD ALIGN=center>");
	ggWinContent += ("[<A HREF=\"javascript:void(0);\" " +
		"onMouseOver=\"window.status='Go forward one year'; return true;\" " +
		"onMouseOut=\"window.status=''; return true;\" " +
		"onClick=\"Build(" + 
		"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "'" +
		");" +
		"\">Year>><\/A>]</TD></TR></TABLE><BR>");

	vCode = this.getMonthlyCalendarCode(); // Get the complete calendar code for the month, and add it to the content var
	ggWinContent += vCode;
}

Calendar.prototype.showY = function() {
	var vCode = "";
	var i;

	ggWinContent += "<FONT FACE='" + fontface + "' ><B>"
	ggWinContent += ("Year : " + this.gYear);
	ggWinContent += "</B><BR>";

	var prevYYYY = parseInt(this.gYear) - 1;	// Show navigation buttons
	var nextYYYY = parseInt(this.gYear) + 1;
	
	ggWinContent += ("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0' style='font-size:" + fontsize + "pt;'><TR><TD ALIGN=center>");
	ggWinContent += ("[<A HREF=\"javascript:void(0);\" " +
		"onMouseOver=\"window.status='Go back one year'; return true;\" " +
		"onMouseOut=\"window.status=''; return true;\" " +
		"onClick=\"Build(" + 
		"'" + this.gReturnItem + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\"><<Year<\/A>]</TD><TD ALIGN=center>");
	ggWinContent += "       </TD><TD ALIGN=center>";
	ggWinContent += ("[<A HREF=\"javascript:void(0);\" " +
		"onMouseOver=\"window.status='Go forward one year'; return true;\" " +
		"onMouseOut=\"window.status=''; return true;\" " +
		"onClick=\"Build(" + 
		"'" + this.gReturnItem + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\">Year>><\/A>]</TD></TR></TABLE><BR>");

	// Get the complete calendar code for each month. start a table and first row in the table
	ggWinContent += ("<TABLE WIDTH='100%' BORDER=0 CELLSPACING=0 CELLPADDING=5 style='font-size:" + fontsize + "pt;'><TR>");
	var j;
	for (i=0; i<12; i++) 
	{
		ggWinContent += "<TD ALIGN='center' VALIGN='top'>";
		this.gMonth = i;
		this.gMonthName = Calendar.get_month(this.gMonth);
		vCode = this.getMonthlyCalendarCode();
		ggWinContent += (this.gMonthName + "/" + this.gYear + "<BR>");
		ggWinContent += vCode;
		ggWinContent += "</TD>";
		if (i == 3 || i == 7) {
			ggWinContent += "</TR><TR>";
			}
	}
	ggWinContent += "</TR></TABLE></font><BR>";
}

Calendar.prototype.cal_header = function() {
	var vCode = "";
	
	vCode = vCode + "<TR>";
	vCode = vCode + "<TD WIDTH='14%'><FONT FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sun</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Mon</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Tue</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Wed</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Thu</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Fri</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='16%'><FONT 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 FACE='" + fontface + "'> </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 FACE='" + fontface + "'>" + 
			"<A HREF='javascript:void(0);' " + 
				"onMouseOver=\"window.status='set date to " + this.format_data(vDay) + "'; return true;\" " +
				"onMouseOut=\"window.status=' '; return true;\" " +
				"onClick=\"document." + this.gReturnItem + ".value='" + 
				this.format_data(vDay) + 
				"';ggPosX=-1;ggPosY=-1;nd();nd();\">" + 
				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 FACE='" + fontface + "'>" + 
				"<A HREF='javascript:void(0);' " +
					"onMouseOver=\"window.status='set date to " + this.format_data(vDay) + "'; return true;\" " +
					"onMouseOut=\"window.status=' '; return true;\" " +
					"onClick=\"document." + this.gReturnItem + ".value='" + 
					this.format_data(vDay) + 
					"';window.scroll(0,ggPosY);ggPosX=-1;ggPosY=-1;nd();nd();\">" + 
				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 FACE='" + fontface + "' COLOR='gray'> </FONT></TD>";
		else
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + 
			"><FONT 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 "YYYY-MM-DD" :
			vData = vY4 + "-" + vMonth + "-" + vDD;
			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) {
	gCal = new Calendar(p_item, p_month, p_year, p_format);

	gCal.gBGColor="white";	// Customize your Calendar here..
	gCal.gLinkColor="black";
	gCal.gTextColor="black";
	gCal.gHeaderColor="darkgreen";

	ggWinContent = "";	// initialize the content string

	// Choose appropriate show function
	if (gCal.gYearly) {
		if (ggPosX == -1) ggPosX = 10;
		if (ggPosY == -1) ggPosY = 10;
		if (fontsize == 8) fontsize = 6;
		gCal.showY();
		}
	else {
		gCal.show();
	}

	// if this is the first calendar popup, use autopositioning with an offset
	if (ggPosX == -1 && ggPosY == -1) {
		overlib(ggWinContent, AUTOSTATUSCAP, STICKY, CLOSECLICK, CSSSTYLE,
			TEXTSIZEUNIT, "pt", TEXTSIZE, 8, CAPTIONSIZEUNIT, "pt", CAPTIONSIZE, 8, CLOSESIZEUNIT, "pt", CLOSESIZE, 8,
			CAPTION, "Select a date", OFFSETX, 20, OFFSETY, -20);
		// save where the 'over' div ended up; we want to stay in the same place if the user clicks on one of the year or month navigation links
		if ( (ns4) || (ie4) ) {
		        ggPosX = parseInt(over.left);
		        ggPosY = parseInt(over.top);
			} else if (ns6) {
			ggPosX = parseInt(over.style.left);
			ggPosY = parseInt(over.style.top);
			}
		}
	else { // we have a saved X & Y position, so use those with the FIXX and FIXY options
		overlib(ggWinContent, AUTOSTATUSCAP, STICKY, CLOSECLICK, CSSSTYLE,
			TEXTSIZEUNIT, "pt", TEXTSIZE, 8, CAPTIONSIZEUNIT, "pt", CAPTIONSIZE, 8, CLOSESIZEUNIT, "pt", CLOSESIZE, 8,
			CAPTION, "Select a date", FIXX, ggPosX, FIXY, ggPosY);
		}
	window.scroll(ggPosX, ggPosY);
}

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 = "YYYY-MM-DD";
	else
		p_format = arguments[3];

	Build(p_item, p_month, p_year, p_format);
}
	
function show_yearly_calendar() {
	p_item = arguments[0];
	if (arguments[1] == "" || arguments[1] == null)
		p_year = new String(gNow.getFullYear().toString());
	else
		p_year = arguments[1];
	if (arguments[2] == null)
		p_format = "YYYY-MM-DD";
	else
		p_format = arguments[2];

	Build(p_item, null, p_year, p_format);
}

// -----------------------------------------------------------------------------------------------------------------------------------
// Timer()
// -----------------------------------------------------------------------------------------------------------------------------------
		
	
	function timer()
	{
		var cookieMins = fnGetCookie("mins");
		var cookieSecs = fnGetCookie("secs");
		
		if (((cookieMins!=null) && (cookieSecs!=null)) || ((cookieMins==0) && (cookieSecs==0)))
		{
			var mins = parseInt(cookieMins);
			var secs = parseInt(cookieSecs);
		}
		else
		{
			var mins = fnSetTimer(); 
			var secs = 1;
		}	
	
		if( --secs == -1 )	
		{		
			secs = 59;
			if (--mins == -1)
			{	
				//fnStopExam();
				setTimeout("fnFinish()", 0); 
			}
		}	
		
		fnSetCookie("mins", mins);
		fnSetCookie("secs", secs);		
		
		if( secs < 10 ) secs = "0" + secs;             	
		if( mins < 10 ) mins = "0" + parseInt( mins );		
		
		document.formTimer.mins.value = mins; 	
		document.formTimer.secs.value = secs;
		window.status = "Time remaining: " + mins + " min " + secs + " sec";		
		
		if( secs == 0 && mins == 0 )
		{
			setTimeout("fnFinish()", 0);
		}
		else 
		{
			window.setTimeout( "timer()", 1000);		
		}
	}

	function fnGetCookie (name) {  
		var arg = name + "=";  
		var alen = arg.length;  
		var clen = document.cookie.length;  
		var i = 0;  
		while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
			i = document.cookie.indexOf(" ", i) + 1;    
			if (i == 0) break;   
		}  
		return null;
	}
	
	function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
		endstr = document.cookie.length;  
		return unescape(document.cookie.substring(offset, endstr));
	}

	function fnSetCookie (name, value) {  
		var argv = fnSetCookie.arguments;  
		var argc = fnSetCookie.arguments.length;  
		var expires = (argc > 2) ? argv[2] : null;  
		var path = (argc > 3) ? argv[3] : null;  
		var domain = (argc > 4) ? argv[4] : null;  
		var secure = (argc > 5) ? argv[5] : false;  
		document.cookie = name + "=" + escape(value) + 
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
		((path == null) ? "" : ("; path=" + path)) +  
		((domain == null) ? "" : ("; domain=" + domain)) +    
		((secure == true) ? "; secure" : "");
	}
	
	function fnDeleteCookie (name) {  
		var expd = new Date();  
		expd.setTime (expd.getTime() - 1);  
		var cval = fnGetCookie (name);  
		document.cookie = name + "=" + cval + "; expires=" + expd.toGMTString();	
	}

// -----------------------------------------------------------------------------------------------------------------------------------
// Validation : User Registration - Complete
// -----------------------------------------------------------------------------------------------------------------------------------

function validateFormRegistrationComplete(formName)
{
	var invalid = " "; // Invalid character is a space
	var minLength_1 = 12; // Minimum length for IC No

	if (formName.username.value == "") {
		alert("Please enter your full name !");
		formName.username.focus();
		return false;
	}
	
	if (formName.userIC.value == "") {
		alert("Please enter your IC No !");
		formName.userIC.focus();
		return false;
	}

	if (formName.userIC.value.length > minLength_1)
	{
		alert('Your IC No must be ' + minLength_1 + ' characters long. Enter again.');
		formName.userIC.focus();
		return false;
	}

	if (formName.userIC.value.indexOf(invalid) > -1) 
	{
		alert("Sorry, spaces are not allowed.");
		formName.userIC.focus();
		return false;
	}

	var valueUserIC = "yes";
	valueUserIC = validateInteger(formName, 'userIC');
	if (valueUserIC == "no") 
	{
		alert("Invalid entry for IC No! Only numbers are accepted!");
		formName.userIC.focus();
		return false;
	}	

	if (formName.userBirthDate.value == "" || formName.userBirthDate.value == "None") {
		alert("Please select your birth date !");
		formName.userBirthDate.focus();
		return false;
	}

	var userGenderA;
	for (var i = 0; i < formName.userGender.length; i++) 
	{
		if (formName.userGender[i].checked) {
			userGenderA = formName.userGender[i].value;
			break;
		  }
	}

	if ((userGenderA != "Female") && (userGenderA != "Male" ))
	{
		alert("Please choose your gender !");
		return false;		
	}
	
	if (formName.userAddress.value == "") {
		alert("Please enter your home address !");
		formName.userAddress.focus();
		return false;
	}
	
	if (formName.userAddPostcode.value == "") {
		alert("Please enter postcode !");
		formName.userAddPostcode.focus();
		return false;
	}

		var valueUserAddPostcode = "yes";
		valueUserAddPostcode = validateInteger(formName, 'userAddPostcode');
		if (valueUserAddPostcode == "no") 
		{
			alert("Invalid entry! Only numbers are accepted!");
			formName.userAddPostcode.focus();
			return false;
		}	
	
	if (formName.userAddState.value == "0") 
	{
		alert("Please select your state !");
		formName.userAddState.focus();
		return false;
	}	
	
	if (formName.userAddDistrict.value == "0") 
	{
		alert("Please select your district !");
		formName.userAddDistrict.focus();
		return false;
	}	
	
	if (formName.userEmail.value == "")
	{
		if(formName.detailChecked.checked == true)
		{
			alert("Please insert your email address. ");
			formName.userEmail.focus();
			return false;
		}
	}
	
	if (formName.userEmail.value != "") 
	{
		if((formName.userEmail.value.indexOf("@")==-1) || (formName.userEmail.value.indexOf(".")==-1))
		{
			alert("Invalid E-mail Address! Please re-enter.");
			formName.userEmail.focus();
			return false;
		}
	}
}

// -----------------------------------------------------------------------------------------------------------------------------------
// Validation : User Registration - Password
// -----------------------------------------------------------------------------------------------------------------------------------

function validateFormPasswordRegistration(formName)
{
	var invalid = " "; // Invalid character is a space
	var minLength = 6; // Minimum length
	var pw1 = document.formPasswordRegistration.userPassword.value;
	var pw2 = document.formPasswordRegistration.userTempPassword.value;
	
	if (formName.userName.value == "") {
		alert("Please enter your username !");
		formName.userName.focus();
		return false;
	}
	
	if (document.formPasswordRegistration.userName.value.length < minLength)
	{
		alert('Your username must be at least ' + minLength + ' characters long. Try again.');
		formName.userName.focus();
		return false;
	}

	if (document.formPasswordRegistration.userName.value.indexOf(invalid) > -1) 
	{
		alert("Sorry, spaces are not allowed.");
		formName.userName.focus();
		return false;
	}
	
	if (pw1 == "") {
		alert("Please enter your password !");
		formName.userPassword.focus();
		return false;
	}
	
	if (pw1.length < minLength)
	{
		alert('Your password must be at least ' + minLength + ' characters long. Try again.');
		formName.userPassword.focus();
		return false;
	}
	
	if (pw1.indexOf(invalid) > -1) 
	{
		alert("Sorry, spaces are not allowed.");
		formName.userPassword.focus();
		return false;
	}
	
	if (pw2 == "") {
		alert("Please confirm your password !");
		formName.userTempPassword.focus();
		return false;
	}
	
	if (pw2.length < minLength)

	{
		alert('Your password must be at least ' + minLength + ' characters long. Try again.');
		formName.userTempPassword.focus();
		return false;
	}
	
	if (pw2.indexOf(invalid) > -1) 
	{
		alert("Sorry, spaces are not allowed.");
		formName.userTempPassword.focus();
		return false;
	}
	
	if (pw1 != pw2) 
	{
		alert ("You did not enter the same new password twice. Please re-enter your password.");
		formName.userTempPassword.focus();
		return false;
	}

	return true;
}

// -----------------------------------------------------------------------------------------------------------------------------------
// Validation : User Registration - Level
// -----------------------------------------------------------------------------------------------------------------------------------

function validateFormLevelRegistration(formName)
{
	if (formName.userLevelID.value == "0") 
	{
		alert("Please select your level !");
		formName.userLevelID.focus();
		return false;
	}
	
	if (formName.userLevelID.value == "1")
	{
		if (formName.educationTypeIDE.value == "0") 
		{
			alert("Please select your education type !");
			formName.educationTypeIDE.focus();
			return false;
		}
		
		if (formName.userAddStateE.value == "0") 
		{
			alert("Please select your state !");
			formName.userAddStateE.focus();
			return false;
		}	
		
		if (formName.userAddDistrictE.value == "0") 
		{
			alert("Please select your district !");
			formName.userAddDistrictE.focus();
			return false;
		}	
	
		if (formName.educationCentreIDE.value == "0") 
		{
			alert("Please select your school name !");
			formName.educationCentreIDE.focus();
			return false;
		}
		
		if (formName.postID.value == "0") 
		{
			alert("Please select your designation !");
			formName.postID.focus();
			return false;
		}	

		if (formName.deptID.value == "0") 
		{
			alert("Please select your department !");
			formName.deptID.focus();
			return false;
		}	
	}
	
	if (formName.userLevelID.value == "2")
	{
		if (formName.educationTypeIDS.value == "0") 
		{
			alert("Please select your education type !");
			formName.educationTypeIDS.focus();
			return false;
		}
		
		if (formName.userAddStateS.value == "0") 
		{
			alert("Please select your state !");
			formName.userAddStateS.focus();
			return false;
		}	
		
		if (formName.userAddDistrictS.value == "0") 
		{
			alert("Please select your district !");
			formName.userAddDistrictS.focus();
			return false;
		}	
	
		if (formName.educationCentreIDS.value == "0") 
		{
			alert("Please select your school name !");
			formName.educationCentreIDS.focus();
			return false;
		}	
	
		if (formName.educationLevelIDS.value == "0") 
		{
			alert("Please select your education Level !");
			formName.educationLevelIDS.focus();
			return false;
		}	
	}

return true;
}

// -----------------------------------------------------------------------------------------------------------------------------------
// Validation : User Registration - Quick
// -----------------------------------------------------------------------------------------------------------------------------------

function validateFormRegistration(formName)
{
	if (formName.username.value == "") {
		alert("Please enter your full name !");
		formName.username.focus();
		return false;
	}
		
	if (formName.userIC.value == "") {
		alert("Please enter your IC No !");
		formName.userIC.focus();
		return false;
	}

	var invalid = " "; // Invalid character is a space
	var minLength = 6; // Minimum length
	var minLength_1 = 12; // Minimum length for IC
	var pw1 = document.formRegistration.userPassword.value;
	var pw2 = document.formRegistration.userTempPassword.value;
	
	if (document.formRegistration.userIC.value.length > minLength_1)
	{
		alert('Your IC No must be ' + minLength_1 + ' characters long. Enter again.');
		formName.userIC.focus();
		return false;
	}

	if (document.formRegistration.userIC.value.indexOf(invalid) > -1) 
	{
		alert("Sorry, spaces are not allowed.");
		formName.userIC.focus();
		return false;
	}

	var valueUserIC = "yes";
	valueUserIC = validateInteger(formName, 'userIC');
	if (valueUserIC == "no") 
	{
		alert("Invalid entry for IC No! Only numbers are accepted!");
		formName.userIC.focus();
		return false;
	}	

	if (formName.userName.value == "") {
		alert("Please enter your username !");
		formName.userName.focus();
		return false;
	}
	
	if (document.formRegistration.userName.value.length < minLength)
	{
		alert('Your username must be at least ' + minLength + ' characters long. Try again.');
		formName.userName.focus();
		return false;
	}

	if (document.formRegistration.userName.value.indexOf(invalid) > -1) 
	{
		alert("Sorry, spaces are not allowed.");
		formName.userName.focus();
		return false;
	}
	
	if (pw1 == "") {
		alert("Please enter your password !");
		formName.userPassword.focus();
		return false;
	}
	
	if (pw1.length < minLength)
	{
		alert('Your password must be at least ' + minLength + ' characters long. Try again.');
		formName.userPassword.focus();
		return false;
	}
	
	if (pw1.indexOf(invalid) > -1) 
	{
		alert("Sorry, spaces are not allowed.");
		formName.userPassword.focus();
		return false;
	}
	
	if (pw2 == "") {
		alert("Please confirm your password !");
		formName.userTempPassword.focus();
		return false;
	}
	
	if (pw2.length < minLength)
	{
		alert('Your password must be at least ' + minLength + ' characters long. Try again.');
		formName.userTempPassword.focus();
		return false;
	}
	
	if (pw2.indexOf(invalid) > -1) 
	{
		alert("Sorry, spaces are not allowed.");
		formName.userTempPassword.focus();
		return false;
	}
	
	if (pw1 != pw2) 
	{
		alert ("You did not enter the same new password twice. Please re-enter your password.");
		formName.userTempPassword.focus();
		return false;
	}
			
	if (formName.userLevelID.value == "0") 
	{
		alert("Please select your level !");
		formName.userLevelID.focus();
		return false;
	}
	
	if (formName.userLevelID.value == "1")
	{
		if (formName.educationTypeIDE.value == "0")
		{
			alert("Please select your education type !");
			formName.educationTypeIDE.focus();
			return false;
		}
		
		if (formName.userAddStateE.value == "0") 
		{
			alert("Please select your state !");
			formName.userAddStateE.focus();
			return false;
		}	
	
		if (formName.userAddDistrictE.value == "0") 
		{
			alert("Please select your district !");
			formName.userAddDistrictE.focus();
			return false;
		}	
	
		if (formName.educationCentreIDE.value == "0") 
		{
			alert("Please select your school name !");
			formName.educationCentreIDE.focus();
			return false;
		}	
	}
	
	if (formName.userLevelID.value == "2")
	{
		if (formName.educationTypeIDS.value == "0")
		{
			alert("Please select your education type !");
			formName.educationTypeIDS.focus();
			return false;
		}
		
		if (formName.userAddStateS.value == "0") 
		{
			alert("Please select your state !");
			formName.userAddStateS.focus();
			return false;
		}	
	
		if (formName.userAddDistrictS.value == "0") 
		{
			alert("Please select your district !");
			formName.userAddDistrictS.focus();
			return false;
		}	
	
		if (formName.educationCentreIDS.value == "0") 
		{
			alert("Please select your school name !");
			formName.educationCentreIDS.focus();
			return false;
		}	
		
		if (formName.educationLevelIDS.value == "0") 
		{
			alert("Please select your level !");
			formName.educationLevelIDS.focus();
			return false;
		}	
	}

return true;
}

// -----------------------------------------------------------------------------------------------------------------------------------
// Validation : User Registration - Quick Notify
// -----------------------------------------------------------------------------------------------------------------------------------

function validateQuickFormRegistrationPayment(formName, formStatus)
{
	if (formName.userPaymentPackage.value == "0") {
		alert("Select the payment package !");
		formName.userPaymentPackage.focus();
		return false;
	}

	if (formName.userPaymentMethod.value == "0") {
		alert("Select the payment method !");
		formName.userPaymentMethod.focus();
		return false;
	}

	if (!formName.userEmailbox.checked && !formName.userAddressbox.checked && !formName.userTelNobox.checked && !formName.userMobileNobox.checked) {
		alert("Please choose the form of notification !");
		return false;
	}
	
	if (formName.userEmailbox.checked && formName.userEmail.value == "") {
		alert("Please enter your email !");
		formName.userEmail.focus();
		return false;
	}
	if (!formName.userEmailbox.checked && formName.userEmail.value != "") {
		alert("Check the checkbox because you have entered the email !");
		formName.userEmail.focus();
		return false;
	}
	if (formName.userEmail.value != "") 
	{
		if((formName.userEmail.value.indexOf("@")==-1) || (formName.userEmail.value.indexOf(".")==-1))
		{
			alert("Invalid E-mail Address! Please re-enter.");
			formName.userEmail.focus();
			return false;
		}
	}

	if (formName.userAddressbox.checked && formName.userAddress.value == "") {
		alert("Please enter your postal address !");
		formName.userAddress.focus();
		return false;
	}
	if (!formName.userAddressbox.checked && formName.userAddress.value != "") {
		alert("Check the checkbox because you have entered the postal address !");
		formName.userAddress.focus();
		return false;
	}
	if (formName.userAddressbox.checked && formName.userAddState.value == "0") {
		alert("Select State !");
		formName.userAddState.focus();
		return false;
	}
	if (formName.userAddressbox.checked && formName.userAddDistrict.value == "0") {
		alert("Select District !");
		formName.userAddDistrict.focus();
		return false;
	}
	if (formName.userAddressbox.checked && formName.userAddPostcode.value == "Enter Postcode") {
		alert("Enter Postcode !");
		formName.userAddPostcode.focus();
		return false;
	}
	var valueUserAddPostcode = "yes";
	valueUserAddPostcode = validateInteger(formName, 'userAddPostcode');
	if (valueUserAddPostcode == "no" && formName.userAddressbox.checked && formName.userAddPostcode.value != "Enter Postcode") 
	{
		alert("Invalid entry! Only numbers are accepted!");
		formName.userAddPostcode.focus();
		return false;
	}	

	if (formName.userTelNobox.checked && formName.userTelNo.value == "") {
		alert("Please enter your Telephone No !");
		formName.userTelNo.focus();
		return false;
	}
	if (!formName.userTelNobox.checked && formName.userTelNo.value != "") {
		alert("Check the checkbox because you have entered your Telephone No !");
		formName.userTelNo.focus();
		return false;
	}
	var valueUserTelNo = "yes";
	valueUserTelNo = validateInteger(formName, 'userTelNo');
	if (valueUserTelNo == "no") 
	{
		alert("Invalid entry for Tel No! Only numbers are accepted!");
		formName.userTelNo.focus();
		return false;
	}	

	if (formName.userMobileNobox.checked && formName.userMobileNo.value == "") {
		alert("Please enter your Mobile No !");
		formName.userMobileNo.focus();
		return false;
	}
	if (!formName.userMobileNobox.checked && formName.userMobileNo.value != "") {
		alert("Check the checkbox because you have entered your Mobile No !");
		formName.userMobileNo.focus();
		return false;
	}
	var valueUserMobileNo = "yes";
	valueUserMobileNo = validateInteger(formName, 'userMobileNo');
	if (valueUserMobileNo == "no") 
	{
		alert("Invalid entry for Mobile No! Only numbers are accepted!");
		formName.userMobileNo.focus();
		return false;
	}	
}

// -----------------------------------------------------------------------------------------------------------------------------------
// Validation : User Registration - Full Notify
// -----------------------------------------------------------------------------------------------------------------------------------

function validateFullFormRegistrationPayment(formName, formStatus)
{
	if (formName.userPaymentPackage.value == "0") {
		alert("Select the payment package !");
		formName.userPaymentPackage.focus();
		return false;
	}

	if (formName.userPaymentMethod.value == "0") {
		alert("Select the payment method !");
		formName.userPaymentMethod.focus();
		return false;
	}

	if (!formName.userEmailbox.checked && !formName.userAddressbox.checked && !formName.userTelNobox.checked && !formName.userMobileNobox.checked) {
		alert("Please choose the form of notification !");
		return false;
	}

	if (formName.userEmailCheck.value == "yes"){
		if (formName.userEmailbox.checked && formName.userEmail.value == "") {
			alert("Please enter your email !");
			formName.userEmail.focus();
			return false;
		}
	
		if (!formName.userEmailbox.checked && formName.userEmail.value != "") {
			alert("Check the checkbox because you have entered the email !");
			formName.userEmail.focus();
			return false;
		}
	}
	if (formName.userEmail.value != "") 
	{
		if((formName.userEmail.value.indexOf("@")==-1) || (formName.userEmail.value.indexOf(".")==-1))
		{
			alert("Invalid E-mail Address! Please re-enter.");
			formName.userEmail.focus();
			return false;
		}
	}

	if (formName.userTelNoCheck.value == "yes" && formName.userTelNobox.checked && formName.userTelNo.value == "") {
		alert("Please enter your Telephone No !");
		formName.userTelNo.focus();
		return false;
	}
	if (formName.userTelNoCheck.value == "yes" && !formName.userTelNobox.checked && formName.userTelNo.value != "") {
		alert("Check the checkbox because you have entered your Telephone No !");
		formName.userTelNo.focus();
		return false;
	}
	var valueUserTelNo = "yes";
	valueUserTelNo = validateInteger(formName, 'userTelNo');
	if (valueUserTelNo == "no") 
	{
		alert("Invalid entry for Tel No! Only numbers are accepted!");
		formName.userTelNo.focus();
		return false;
	}	

	if (formName.userMobileNoCheck.value == "yes" && formName.userMobileNobox.checked && formName.userMobileNo.value == "") {
		alert("Please enter your Mobile No !");
		formName.userMobileNo.focus();
		return false;
	}
	if (formName.userMobileNoCheck.value == "yes" && !formName.userMobileNobox.checked && formName.userMobileNo.value != "") {
		alert("Check the checkbox because you have entered your Mobile No !");
		formName.userMobileNo.focus();
		return false;
	}
	var valueUserMobileNo = "yes";
	valueUserMobileNo = validateInteger(formName, 'userMobileNo');
	if (valueUserMobileNo == "no") 
	{
		alert("Invalid entry for Mobile No! Only numbers are accepted!");
		formName.userMobileNo.focus();
		return false;
	}	
}

// -----------------------------------------------------------------------------------------------------------------------------------
// Edit Profile
// -----------------------------------------------------------------------------------------------------------------------------------

function validateFormEditProfile(formName)
{
	if (formName.username.value == "") {
		alert("Please enter your full name !");
		formName.username.focus();
		return false;
	}
	
	if (formName.userEmail.value == "")
	{
		if(formName.detailChecked.checked == true)
		{
			alert("Please insert your email address. ");
			formName.userEmail.focus();
			return false;
		}
	}
	
	if (formName.userEmail.value != "") 
	{
		if((formName.userEmail.value.indexOf("@")==-1) || (formName.userEmail.value.indexOf(".")==-1))
		{
			alert("Invalid E-mail Address! Please re-enter.");
			formName.userEmail.focus();
			return false;
		}
	}
	return true;
}

// -----------------------------------------------------------------------------------------------------------------------------------
// Change Password
// -----------------------------------------------------------------------------------------------------------------------------------

function validateFormChangePassword(formName)
{
	var invalid = " "; // Invalid character is a space
	var minLength = 6; // Minimum length
	var pw = document.formChangePassword.oldPassword.value;
	var pw1 = document.formChangePassword.userPassword.value;
	var pw2 = document.formChangePassword.userTempPassword.value;
	
	if(pw == ""){
		alert("Please enter your current password");
		formName.oldPassword.focus();
		return false;
	}
	
	if (pw1 == "") {
		alert("Please enter your password !");
		formName.userPassword.focus();
		return false;
	}
	
	if (pw1 == pw) {
		alert("New password cannot be the same as old password");
		formName.userPassword.focus();
		return false;
	}
	
	if (pw1.length < minLength)
	{
		alert('Your password must be at least ' + minLength + ' characters long. Try again.');
		formName.userPassword.focus();
		return false;
	}
	
	if (pw1.indexOf(invalid) > -1) 
	{
		alert("Sorry, spaces are not allowed.");
		formName.userPassword.focus();
		return false;
	}
	
	if (pw2 == "") {
		alert("Please confirm your password !");
		formName.userTempPassword.focus();
		return false;
	}
	
	if (pw2.length < minLength)
	{
		alert('Your password must be at least ' + minLength + ' characters long. Try again.');
		formName.userTempPassword.focus();
		return false;
	}
	
	if (pw2.indexOf(invalid) > -1) 
	{
		alert("Sorry, spaces are not allowed.");
		formName.userTempPassword.focus();
		return false;
	}
	
	if (pw1 != pw2) 
	{
		alert ("You did not enter the same new password twice. Please re-enter your password.");
		formName.userTempPassword.focus();
		return false;
	}

	return true;
}

// -----------------------------------------------------------------------------------------------------------------------------------
// Change Layers
// -----------------------------------------------------------------------------------------------------------------------------------

isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;

function switchDiv(strDivName,bolVisible)
{
//identify the element based on browser type
	if (isNS4) 
	{
	  objElement = document.layers[strDivName];
	} 
	else if (isIE4) 
	{
	  objElement = document.all[strDivName];
	} 
	else if (isIE5 || isNS6) 
	{
	  objElement = document.getElementById(strDivName);
	}

		if(isNS4)
		{
			if(!bolVisible) 
			{
			  objElement.visibility ="hidden"
			} 
			else 
			{
			  objElement.visibility ="visible"
			}     
		}
		else
		{
			if(!bolVisible) 
			{
			  objElement.style.visibility = "hidden";
			} 
			else 
			{
			  objElement.style.visibility = "visible";
			}
		}
}

var currentLayer = false;
function showLayer(intSelected)
{
	if(intSelected==0)
	{
		switchDiv("section_i",false);
		switchDiv("section_ii",false);
		switchDiv("section_iii",false);
    }
    if(intSelected==1)
	{
		switchDiv("section_i",true);
		switchDiv("section_ii",false);
			switchDiv("section_iii",false);
   	}
	if(intSelected==2)
	{
		switchDiv("section_i",false);
		switchDiv("section_ii",true);
		switchDiv("section_iii",false);
    }
	if(intSelected==3)
	{
		switchDiv("section_i",false);
		switchDiv("section_ii",false);
		switchDiv("section_iii",true);
    }
}
   
// -----------------------------------------------------------------------------------------------------------------------------------
// Integer Validation
// -----------------------------------------------------------------------------------------------------------------------------------
      
function validateInteger(formName, integerInput) 
{
	var validInteger = "0123456789";
	var acceptInteger = "yes";
	var input;
	var total;
		
	for (var i=0; i<formName.elements[integerInput].value.length; i++) 
	{
		input = "" + formName.elements[integerInput].value.substring(i, i+1);
		if (validInteger.indexOf(input) == "-1") 
			acceptInteger = "no";
	}
	return acceptInteger;
}

// -----------------------------------------------------------------------------------------------------------------------------------
// Registration : Set Education Level by Education Centre
// -----------------------------------------------------------------------------------------------------------------------------------

function educationCentreChosen(formName, educationLevelID, educationLevelName)
{   
	var n=1;
	var intCount = 0;
	
	var educationCentreChosen = formName.educationCentreIDS.options[formName.educationCentreIDS.selectedIndex].value;
	
	intCount = educationLevelID.length;
	formName.educationLevelIDS.options.length = 1;
		
		for (var i = 0; i < intCount; i++){
			if (educationLevelID[i].substring(0,3) == educationCentreChosen.substring(0,3)) {
				formName.educationLevelIDS[n++] = new Option(educationLevelName[i], educationLevelID[i]);
			}
		}
}

// -----------------------------------------------------------------------------------------------------------------------------------
// Registration : Set Education Centre by Education Level
// -----------------------------------------------------------------------------------------------------------------------------------

function educationTypeChosen(formName, formInput, educationCentreID, educationCentreName)
{   
	if (formInput == "E")	
	{	
		var n=1;
		var intCount = 0;

		var educationTypeChosen = formName.educationTypeIDE.options[formName.educationTypeIDE.selectedIndex].value;
		intCount = educationCentreID.length;
		formName.educationCentreIDE.options.length = 1;
		    
		for (var i = 0; i < intCount; i++)
		{
			if (educationCentreID[i].substring(0,3) == educationTypeChosen.substring(0,3))
			{
				formName.educationCentreIDE[n++] = new Option(educationCentreName[i], educationCentreID[i]);
			}
		}
	}
	else if (formInput == "S")
	{
		var n=1;
		var intCount = 0;

		var educationTypeChosen = formName.educationTypeIDS.options[formName.educationTypeIDS.selectedIndex].value;
		intCount = educationCentreID.length;
		formName.educationCentreIDS.options.length = 1;
		    
		for (var i = 0; i < intCount; i++)
		{
			if (educationCentreID[i].substring(0,3) == educationTypeChosen.substring(0,3))
			{
				formName.educationCentreIDS[n++] = new Option(educationCentreName[i], educationCentreID[i]);
			}
		}
	}
}

// -----------------------------------------------------------------------------------------------------------------------------------
// Choose Education Level
// -----------------------------------------------------------------------------------------------------------------------------------

function educationLevelChosen(formName, formInput, educationLevelID, educationLevelName)
{   
	if (formInput == "E")	
	{	
		var n=1;
		var intCount = 0;

		var educationLevelChosen = formName.educationTypeIDE.options[formName.educationTypeIDE.selectedIndex].value;
		intCount = educationLevelID.length;
		formName.educationLevelIDE.options.length = 1;
		    
		for (var i = 0; i < intCount; i++)
		{
			if (educationLevelID[i].substring(0,3) == educationLevelChosen.substring(0,3))
			{
				formName.educationLevelIDE[n++] = new Option(educationLevelName[i], educationLevelID[i]);
			}
		}
	}
	else if (formInput == "S")
	{
		var n=1;
		var intCount = 0;

		var educationLevelChosen = formName.educationTypeIDS.options[formName.educationTypeIDS.selectedIndex].value;
		intCount = educationLevelID.length;
		formName.educationLevelIDS.options.length = 1;
		    
		for (var i = 0; i < intCount; i++)
		{
			if (educationLevelID[i].substring(0,3) == educationLevelChosen.substring(0,3))
			{
				formName.educationLevelIDS[n++] = new Option(educationLevelName[i], educationLevelID[i]);
			}
		}
	}
	else if (formInput == "F")
	{
		var n=1;
		var intCount = 0;

		var educationLevelChosen = formName.educationTypeIDS.value;
		intCount = educationLevelID.length;
		formName.educationLevelIDS.options.length = 1;
		    
		for (var i = 0; i < intCount; i++)
		{
			if (educationLevelID[i].substring(0,3) == educationLevelChosen.substring(0,3))
			{
				formName.educationLevelIDS[n++] = new Option(educationLevelName[i], educationLevelID[i]);
			}
		}
	}

}