
// Begin Script
var gnumofpart = 1;
var butimage = new Array();

butimage["butonhome"]       = new Image(100,20);
butimage["butonaboutus"]    = new Image(100,20);
butimage["butoncourses"]    = new Image(100,20);
butimage["butonfacilities"] = new Image(100,20);
butimage["butonregister"]   = new Image(100,20);
butimage["butoncontactus"]  = new Image(100,20);

butimage["butofhome"]       = new Image(100,20);
butimage["butofaboutus"]    = new Image(100,20);
butimage["butofcourses"]    = new Image(100,20);
butimage["butoffacilities"] = new Image(100,20);
butimage["butofregister"]   = new Image(100,20);
butimage["butofcontactus"]  = new Image(100,20);

butimage["butonhome"].src       = "./pics/buton_home.gif";
butimage["butonaboutus"].src    = "./pics/buton_aboutus.gif";
butimage["butoncourses"].src    = "./pics/buton_courses.gif";
butimage["butonfacilities"].src = "./pics/buton_facilities.gif";
butimage["butonregister"].src   = "./pics/buton_register.gif";
butimage["butoncontactus"].src  = "./pics/buton_contactus.gif";

butimage["butofhome"].src       = "./pics/butoff_home.gif";
butimage["butofaboutus"].src    = "./pics/butoff_aboutus.gif";
butimage["butofcourses"].src    = "./pics/butoff_courses.gif";
butimage["butoffacilities"].src = "./pics/butoff_facilities.gif";
butimage["butofregister"].src   = "./pics/butoff_register.gif";
butimage["butofcontactus"].src  = "./pics/butoff_contactus.gif";



function userclick(butname) {

    switch (butname) {
    	
    	case 'home'       : location.href="index.html"; break;
    	case 'aboutus'    : location.href="aboutus.php"; break;
    	case 'courses'    : location.href="coursesnext.php"; break;
    	case 'facilities' : location.href="facilities.php"; break;
    	case 'register'   : location.href="register.php"; break;
    	case 'contactus'  : location.href="contactus.php"; break;
    	default           : location.href="index.html"; break;
    }

}

function capson(thisN) {
	
	//alert(window.evt.which);
	//alert(window.event.keyCode);
	//alert(thisN.id);
	
	thisN.value = thisN.value.toUpperCase();
	thisN.value = thisN.value.replace(/\|/g, "-");
	thisN.value = thisN.value.replace(/\+/g, "-");
	thisN.style.backgroundColor = "snow";
	
	var elemid = thisN.id.substr(2,3);
	if (elemid == "dob") {
		//alert("date of birth");
		if (thisN.value.length == 9) {
			var elemval = thisN.value;
			elemval = elemval.substr(0,2) + "-" + elemval.substr(2,3) + "-" + elemval.substr(5,4);
			thisN.value = elemval;
		}
		if (thisN.value.length == 11) {
			var elemval = thisN.value;
			elemval = elemval.substr(0,2) + "-" + elemval.substr(3,3) + "-" + elemval.substr(7,4);
			thisN.value = elemval;			
		}
	}
}

function highlight(thisN) {
	thisN.style.backgroundColor = "yellow";
}


function numofpart(thisN) {
	//alert(thisN.value);

	if (thisN.value < gnumofpart) {
        var from = eval(thisN.value) + 1;
		var to   = eval(gnumofpart);
		var diff = to - from;
		if (diff <= 0) 
			var cfm = confirm("Are you sure you wish to reduce number of participants?\n\n** PARTICIPANT " + from  + " INFORMATION WILL BE LOST **\n\nClick OK to confirm.\nClick CANCEL to remain.");
		else
			var cfm = confirm("Are you sure you wish to reduce number of participants?\n\n** PARTICIPANTS " + from + " TO " + to + " INFORMATION WILL BE LOST **\n\nClick OK to confirm.\nClick CANCEL to remain.");
		if (cfm == false) {
			thisN.value = gnumofpart;
			return;
		} 
		else {
			gnumofpart = thisN.value;
		}
	}
	else {
		gnumofpart = thisN.value;
	}
	
	switch(thisN.value) {
		case "1":
			if (document.getElementById("participant2") != null) { document.getElementById("participant2").parentNode.removeChild(document.getElementById("participant2")); }
			if (document.getElementById("participant3") != null) { document.getElementById("participant3").parentNode.removeChild(document.getElementById("participant3")); }
			if (document.getElementById("participant4") != null) { document.getElementById("participant4").parentNode.removeChild(document.getElementById("participant4")); }
			if (document.getElementById("participant5") != null) { document.getElementById("participant5").parentNode.removeChild(document.getElementById("participant5")); }
			if (document.getElementById("participant6") != null) { document.getElementById("participant6").parentNode.removeChild(document.getElementById("participant6")); }
			if (document.getElementById("participant7") != null) { document.getElementById("participant7").parentNode.removeChild(document.getElementById("participant7")); }
			if (document.getElementById("participant8") != null) { document.getElementById("participant8").parentNode.removeChild(document.getElementById("participant8")); }
			if (document.getElementById("participant9") != null) { document.getElementById("participant9").parentNode.removeChild(document.getElementById("participant9")); }
			if (document.getElementById("participant10") != null) { document.getElementById("participant10").parentNode.removeChild(document.getElementById("participant10")); }
		   break;
		case "2":
		    addChild("participant2");
			if (document.getElementById("participant3") != null) { document.getElementById("participant3").parentNode.removeChild(document.getElementById("participant3")); }
			if (document.getElementById("participant4") != null) { document.getElementById("participant4").parentNode.removeChild(document.getElementById("participant4")); }
			if (document.getElementById("participant5") != null) { document.getElementById("participant5").parentNode.removeChild(document.getElementById("participant5")); }
			if (document.getElementById("participant6") != null) { document.getElementById("participant6").parentNode.removeChild(document.getElementById("participant6")); }
			if (document.getElementById("participant7") != null) { document.getElementById("participant7").parentNode.removeChild(document.getElementById("participant7")); }
			if (document.getElementById("participant8") != null) { document.getElementById("participant8").parentNode.removeChild(document.getElementById("participant8")); }
			if (document.getElementById("participant9") != null) { document.getElementById("participant9").parentNode.removeChild(document.getElementById("participant9")); }
			if (document.getElementById("participant10") != null) { document.getElementById("participant10").parentNode.removeChild(document.getElementById("participant10")); }
		   break;
		case "3":
		    addChild("participant2");
		    addChild("participant3");
			if (document.getElementById("participant4") != null) { document.getElementById("participant4").parentNode.removeChild(document.getElementById("participant4")); }
			if (document.getElementById("participant5") != null) { document.getElementById("participant5").parentNode.removeChild(document.getElementById("participant5")); }
			if (document.getElementById("participant6") != null) { document.getElementById("participant6").parentNode.removeChild(document.getElementById("participant6")); }
			if (document.getElementById("participant7") != null) { document.getElementById("participant7").parentNode.removeChild(document.getElementById("participant7")); }
			if (document.getElementById("participant8") != null) { document.getElementById("participant8").parentNode.removeChild(document.getElementById("participant8")); }
			if (document.getElementById("participant9") != null) { document.getElementById("participant9").parentNode.removeChild(document.getElementById("participant9")); }
			if (document.getElementById("participant10") != null) { document.getElementById("participant10").parentNode.removeChild(document.getElementById("participant10")); }
		   break;
		case "4":
		    addChild("participant2");
		    addChild("participant3");
		    addChild("participant4");
			if (document.getElementById("participant5") != null) { document.getElementById("participant5").parentNode.removeChild(document.getElementById("participant5")); }
			if (document.getElementById("participant6") != null) { document.getElementById("participant6").parentNode.removeChild(document.getElementById("participant6")); }
			if (document.getElementById("participant7") != null) { document.getElementById("participant7").parentNode.removeChild(document.getElementById("participant7")); }
			if (document.getElementById("participant8") != null) { document.getElementById("participant8").parentNode.removeChild(document.getElementById("participant8")); }
			if (document.getElementById("participant9") != null) { document.getElementById("participant9").parentNode.removeChild(document.getElementById("participant9")); }
			if (document.getElementById("participant10") != null) { document.getElementById("participant10").parentNode.removeChild(document.getElementById("participant10")); }
		   break;
		case "5":
		    addChild("participant2");
		    addChild("participant3");
		    addChild("participant4");
		    addChild("participant5");
			if (document.getElementById("participant6") != null) { document.getElementById("participant6").parentNode.removeChild(document.getElementById("participant6")); }
			if (document.getElementById("participant7") != null) { document.getElementById("participant7").parentNode.removeChild(document.getElementById("participant7")); }
			if (document.getElementById("participant8") != null) { document.getElementById("participant8").parentNode.removeChild(document.getElementById("participant8")); }
			if (document.getElementById("participant9") != null) { document.getElementById("participant9").parentNode.removeChild(document.getElementById("participant9")); }
			if (document.getElementById("participant10") != null) { document.getElementById("participant10").parentNode.removeChild(document.getElementById("participant10")); }
		   break;
		case "6":
		    addChild("participant2");
		    addChild("participant3");
		    addChild("participant4");
		    addChild("participant5");
		    addChild("participant6");
			if (document.getElementById("participant7") != null) { document.getElementById("participant7").parentNode.removeChild(document.getElementById("participant7")); }
			if (document.getElementById("participant8") != null) { document.getElementById("participant8").parentNode.removeChild(document.getElementById("participant8")); }
			if (document.getElementById("participant9") != null) { document.getElementById("participant9").parentNode.removeChild(document.getElementById("participant9")); }
			if (document.getElementById("participant10") != null) { document.getElementById("participant10").parentNode.removeChild(document.getElementById("participant10")); }
		   break;
		case "7":
		    addChild("participant2");
		    addChild("participant3");
		    addChild("participant4");
		    addChild("participant5");
		    addChild("participant6");
		    addChild("participant7");
			if (document.getElementById("participant8") != null) { document.getElementById("participant8").parentNode.removeChild(document.getElementById("participant8")); }
			if (document.getElementById("participant9") != null) { document.getElementById("participant9").parentNode.removeChild(document.getElementById("participant9")); }
			if (document.getElementById("participant10") != null) { document.getElementById("participant10").parentNode.removeChild(document.getElementById("participant10")); }
		   break;
		case "8":
		    addChild("participant2");
		    addChild("participant3");
		    addChild("participant4");
		    addChild("participant5");
		    addChild("participant6");
		    addChild("participant7");
		    addChild("participant8");
			if (document.getElementById("participant9") != null) { document.getElementById("participant9").parentNode.removeChild(document.getElementById("participant9")); }
			if (document.getElementById("participant10") != null) { document.getElementById("participant10").parentNode.removeChild(document.getElementById("participant10")); }
		   break;
		case "9":
		    addChild("participant2");
		    addChild("participant3");
		    addChild("participant4");
		    addChild("participant5");
		    addChild("participant6");
		    addChild("participant7");
		    addChild("participant8");
		    addChild("participant9");
			if (document.getElementById("participant10") != null) { document.getElementById("participant10").parentNode.removeChild(document.getElementById("participant10")); }
		   break;
		case "10":
		    addChild("participant2");
		    addChild("participant3");
		    addChild("participant4");
		    addChild("participant5");
		    addChild("participant6");
		    addChild("participant7");
		    addChild("participant8");
		    addChild("participant9");
		    addChild("participant10");
		   break;
		default:
		   //do nothing
		   
	}

}



function loadlist(p) {
	var pcn = p + "coursename";
	var pcd = p + "coursedate";
	//alert("[" + pcn + "]");
	var cn = document.getElementById(pcn);
	//alert(cn);
	cn.options.length = 0;
	for (x = 0; x < names.length; x++) {
	   cn.options[cn.options.length] = new Option(names[x][0],names[x][0]);
	}
	loaddate(pcn, pcd);
}

function loaddate(pcn, pcd) {
	var ds = document.getElementById(pcd);
	var cn = document.getElementById(pcn);
	//alert(cn.value);
	ds.options.length = 0;
	for(x = 0; x < names.length; x++) {
		if (cn.value == names[x][0]) {
			ds.options.length = 0;
			for (y = 1; y < names[x].length; y++) {
				ds.options[ds.options.length] = new Option(names[x][y], names[x][y]);
			}
		}
	}
}


function loaddate2(thisN) {
	var p = thisN.id.substring(0,2);
	var pcn = p + "coursename";
	var pcd = p + "coursedate";	
	var ds = document.getElementById(pcd);
	var cn = document.getElementById(pcn);
	//alert(cn.value);
	ds.options.length = 0;
	for(x = 0; x < names.length; x++) {
		if (cn.value == names[x][0]) {
			ds.options.length = 0;
			for (y = 1; y < names[x].length; y++) {
				ds.options[ds.options.length] = new Option(names[x][y], names[x][y]);
			}
		}
	}
}



function addChild(anode){
	// anode = appending node
	
	var num = 0;
	
	if (anode.length == 12)
	    num = anode.substring(11,12);
	
	    
	if (anode.length == 13) {
		num = anode.substring(11,13);
	}

	
	var haveElement = document.getElementById(anode)
	var lastnode = document.getElementById("lastpart");
	
	if (haveElement == null) {
		
        var trmain = document.createElement("tr");
		trmain.setAttribute("id",anode);

		var tdmain = document.createElement("td");

		trmain.appendChild(tdmain);

		var tblmain = document.createElement("table");

		if 	(navigator.appName == "Netscape" || navigator.appVersion.indexOf("MSIE 8.0") > -1 ) {
		    tblmain.setAttribute("class","participants")  // Firefox, Safari and IE 8.0
		}
		else if (navigator.appName == "Opera" ) {
			tblmain.className = "participants"; // Opera
			// Opera does not support css for dynamic elements as of version 9.64 and hopefully they will support in next versions
			// However, setting Opera to "Identify as Firefox" works under Tools, Quick Preferences, Edit Site Preferences, Network, Broswser Identification
		}
		else {
		    tblmain.setAttribute("className","participants");  // IE 7.0 and below
		}
		    

		var tblbody    = document.createElement("tbody");
		
		tdmain.appendChild(tblmain);
		tblmain.appendChild(tblbody);     // IE needs TBODY
		

		//********************************
		// BLANK LINE
		//********************************
		
		var tr1     = document.createElement("tr");
		var tr1td1  = document.createElement("td");
		var tr1td2  = document.createElement("td");
		var tr1td3  = document.createElement("td");
		var tr1td4  = document.createElement("td");
        var tr1spc1 = document.createTextNode(String.fromCharCode(160));		
        var tr1spc2 = document.createTextNode(String.fromCharCode(160));		
        var tr1spc3 = document.createTextNode(String.fromCharCode(160));		
        var tr1spc4 = document.createTextNode(String.fromCharCode(160));		
		
		tr1td1.appendChild(tr1spc1);
		tr1td2.appendChild(tr1spc2);
		tr1td3.appendChild(tr1spc3);
		tr1td4.appendChild(tr1spc4);
		
		
		if 	( (navigator.appName == "Netscape") || 
		     (navigator.appVersion.indexOf("MSIE 8.0") > -1) || 
			 (navigator.appName == "Opera") 
			) {
		    tr1td2.setAttribute("class","fieldgap");  // Firefox, Safari and IE 8.0
		}
		else {
		    tr1td2.setAttribute("className","fieldgap");  // IE 7.0 and below
		}
		
		
		tr1.appendChild(tr1td1);
		tr1.appendChild(tr1td2);
		tr1.appendChild(tr1td3);
		tr1.appendChild(tr1td4);
				
		tblbody.appendChild(tr1);
		

		//********************************
		// PARTICIPANT NUMBER
		//********************************
		
		var tr2     = document.createElement("tr");
		var tr2td1  = document.createElement("td");
		var partnum = document.createTextNode("PARTICIPANT # " + num);
		
		if (navigator.appName == "Netscape" || navigator.appVersion.indexOf("MSIE 8.0") > -1) {
		    tr2td1.setAttribute("class","registerhead");  // Firefox, Safari and IE 8.0
		}
		else {
		    tr2td1.setAttribute("className","registerhead");  // IE 7.0 and below
		}

		
		
		//tr2td1.style.cssText = "font-weight:bold;text-align:left;font-size:14px;color:darkgreen;";
		tr2td1.setAttribute("colSpan","4");

	
		tr2.appendChild(tr2td1);
		tr2td1.appendChild(partnum);


		tblbody.appendChild(tr2);


		//********************************
		// BLANK LINE
		//********************************
	
		var tr3     = document.createElement("tr");
		var tr3td1  = document.createElement("td");
		var tr3td2  = document.createElement("td");
		var tr3td3  = document.createElement("td");
		var tr3td4  = document.createElement("td");
        var tr3spc1 = document.createTextNode(String.fromCharCode(160));		
        var tr3spc2 = document.createTextNode(String.fromCharCode(160));		
        var tr3spc3 = document.createTextNode(String.fromCharCode(160));		
        var tr3spc4 = document.createTextNode(String.fromCharCode(160));		


		tr3td1.appendChild(tr3spc1);
		tr3td2.appendChild(tr3spc2);
		tr3td3.appendChild(tr3spc3);
		tr3td4.appendChild(tr3spc4);
		
		tr3.appendChild(tr3td1);
		tr3.appendChild(tr3td2);
		tr3.appendChild(tr3td3);
		tr3.appendChild(tr3td4);
		
		tblbody.appendChild(tr3);


		
		//********************************
		// NAME Field
		//********************************
		
		var tr4     = document.createElement("tr");
		var tr4td1  = document.createElement("td");
		var tr4td2  = document.createElement("td");
		var tr4td3  = document.createElement("td");
		var tr4td4  = document.createElement("td");
		var tr4txt1 = document.createTextNode("Name (as in NRIC/Passport)");
		var tr4spn1 = document.createElement("span");
		var tr4inp1 = document.createElement("input");
		var tr4spc1 = document.createTextNode(String.fromCharCode(160));
		var tr4spc2 = document.createTextNode(String.fromCharCode(160));
		
		tr4spn1.setAttribute("id","sp" + num + "name");
		
		tr4inp1.setAttribute("id","p" + num + "name");
		tr4inp1.setAttribute("size","50");
		tr4inp1.setAttribute("type","text");
		tr4inp1.setAttribute("maxLength","50");
		tr4inp1.onblur = function() { capson(this); }
		tr4inp1.onfocus = function() { highlight(this); }

		if (navigator.appName == "Netscape" || navigator.appVersion.indexOf("MSIE 8.0") > -1) {
		    tr4td1.setAttribute("class","fieldname");  // Firefox, Safari and IE 8.0
		    tr4spn1.setAttribute("class","chkfields");
		    tr4inp1.setAttribute("class","rol");
		}
		else {
		    tr4td1.setAttribute("className","fieldname");  // IE 7.0 and below
		    tr4spn1.setAttribute("className","chkfields");
		    tr4inp1.setAttribute("className","rol");
		}
		
		tr4.appendChild(tr4td1);
		tr4.appendChild(tr4td2);
		tr4.appendChild(tr4td3);
		tr4.appendChild(tr4td4);
		
		tr4td1.appendChild(tr4txt1);
		tr4td2.appendChild(tr4spc1);
		tr4td3.appendChild(tr4inp1);
		tr4td3.appendChild(tr4spn1);
		tr4td4.appendChild(tr4spc2);
		
		tblbody.appendChild(tr4)


		//********************************
		// GENDER Field
		//********************************

		
		var tr5     = document.createElement("tr");
		var tr5td1  = document.createElement("td");
		var tr5td2  = document.createElement("td");
		var tr5td3  = document.createElement("td");
		var tr5td4  = document.createElement("td");
		var tr5txt1 = document.createTextNode("Salutation");
		var tr5spn1 = document.createElement("span");

		var tr5sel1 = document.createElement("select");

		var tr5opt1 = document.createElement("option");
		var tr5otx1 = document.createTextNode("---");

		var tr5opt2 = document.createElement("option");
		var tr5otx2 = document.createTextNode("MR.");

		var tr5opt3 = document.createElement("option");
		var tr5otx3 = document.createTextNode("MS.");

		var tr5spc1 = document.createTextNode(String.fromCharCode(160));
		var tr5spc2 = document.createTextNode(String.fromCharCode(160));

		tr5spn1.setAttribute("id","sp" + num + "gender");
		tr5sel1.setAttribute("id","p" + num + "gender");
		tr5sel1.setAttribute("width","50");

		tr5opt1.setAttribute("value","----");
		tr5opt2.setAttribute("value","MR. ");
		tr5opt3.setAttribute("value","MS. ");
		
		
		if (navigator.appName == "Netscape" || navigator.appVersion.indexOf("MSIE 8.0") > -1) {
		    tr5td1.setAttribute("class","fieldname");  // Firefox, Safari and IE 8.0
		    tr5spn1.setAttribute("class","chkfields");		    
		    tr5sel1.setAttribute("class","rol");
		}
		else {
		    tr5td1.setAttribute("className","fieldname");  // IE 7.0 and below
		    tr5spn1.setAttribute("className","chkfields");		    
		    tr5sel1.setAttribute("className","rol");
		}

		
		tr5.appendChild(tr5td1);
		tr5.appendChild(tr5td2);
		tr5.appendChild(tr5td3);
		tr5.appendChild(tr5td4);
		
		tr5td1.appendChild(tr5txt1);
		tr5td2.appendChild(tr5spc1);
		tr5td3.appendChild(tr5sel1);
		tr5td3.appendChild(tr5spn1);
		tr5td4.appendChild(tr5spc2);
		
		tr5opt1.appendChild(tr5otx1);
		tr5opt2.appendChild(tr5otx2);
		tr5opt3.appendChild(tr5otx3);
		
		tr5sel1.appendChild(tr5opt1);
		tr5sel1.appendChild(tr5opt2);
		tr5sel1.appendChild(tr5opt3);
		
		tr5.setAttribute("id","p" + num + "genderfld");
		
		
		
		tblbody.appendChild(tr5)
		
		
		//********************************
		// DESIGNATION Field
		//********************************

		
		var tr6     = document.createElement("tr");
		var tr6td1  = document.createElement("td");
		var tr6td2  = document.createElement("td");
		var tr6td3  = document.createElement("td");
		var tr6td4  = document.createElement("td");
		var tr6txt1 = document.createTextNode("Designation");
		var tr6spn1 = document.createElement("span");
		var tr6inp1 = document.createElement("input");
		var tr6spc1 = document.createTextNode(String.fromCharCode(160));
		var tr6spc2 = document.createTextNode(String.fromCharCode(160));

		tr6spn1.setAttribute("id","sp" + num + "designation");
		
		tr6inp1.setAttribute("id","p" + num + "designation");
		tr6inp1.setAttribute("size","50");
		tr6inp1.setAttribute("type","text");
		tr6inp1.setAttribute("maxLength",50);
		tr6inp1.onblur = function() { capson(this); }		
		tr6inp1.onfocus = function() { highlight(this); }

		if (navigator.appName == "Netscape" || navigator.appVersion.indexOf("MSIE 8.0") > -1) {
		    tr6td1.setAttribute("class","fieldname");  // Firefox, Safari and IE 8.0
		    tr6spn1.setAttribute("class","chkfields");		    
		    tr6inp1.setAttribute("class","rol");
		}
		else {
		    tr6td1.setAttribute("className","fieldname");  // IE 7.0 and below
		    tr6spn1.setAttribute("className","chkfields");		    
		    tr6inp1.setAttribute("className","rol");
		}

		
		tr6.appendChild(tr6td1);
		tr6.appendChild(tr6td2);
		tr6.appendChild(tr6td3);
		tr6.appendChild(tr6td4);
		
		tr6td1.appendChild(tr6txt1);
		tr6td2.appendChild(tr6spc1);
		tr6td3.appendChild(tr6inp1);
		tr6td3.appendChild(tr6spn1);
		tr6td4.appendChild(tr6spc2);
		
		
		tblbody.appendChild(tr6)
		

		//********************************
		// NATIONALITY Field
		//********************************

		
		var tr7     = document.createElement("tr");
		var tr7td1  = document.createElement("td");
		var tr7td2  = document.createElement("td");
		var tr7td3  = document.createElement("td");
		var tr7td4  = document.createElement("td");
		var tr7txt1 = document.createTextNode("Nationality");
		var tr7spn1 = document.createElement("span");
		var tr7inp1 = document.createElement("input");
		var tr7spc1 = document.createTextNode(String.fromCharCode(160));
		var tr7spc2 = document.createTextNode(String.fromCharCode(160));

		tr7spn1.setAttribute("id","sp" + num + "nationality");
		
		tr7inp1.setAttribute("id","p" + num + "nationality");
		tr7inp1.setAttribute("size","30");
		tr7inp1.setAttribute("type","text");
		tr7inp1.setAttribute("maxLength",30);
		tr7inp1.onblur = function() { capson(this); }		
		tr7inp1.onfocus = function() { highlight(this); }

		if (navigator.appName == "Netscape" || navigator.appVersion.indexOf("MSIE 8.0") > -1) {
		    tr7td1.setAttribute("class","fieldname");  // Firefox, Safari and IE 8.0
		    tr7spn1.setAttribute("class","chkfields");		    
		    tr7inp1.setAttribute("class","rol");
		}
		else {
		    tr7td1.setAttribute("className","fieldname");  // IE 7.0 and below
		    tr7spn1.setAttribute("className","chkfields");		    
		    tr7inp1.setAttribute("className","rol");
		}

		
		tr7.appendChild(tr7td1);
		tr7.appendChild(tr7td2);
		tr7.appendChild(tr7td3);
		tr7.appendChild(tr7td4);
		
		tr7td1.appendChild(tr7txt1);
		tr7td2.appendChild(tr7spc1);
		tr7td3.appendChild(tr7inp1);
		tr7td3.appendChild(tr7spn1);
		tr7td4.appendChild(tr7spc2);
		
		
		tblbody.appendChild(tr7)

		
		
		//********************************
		// NRIC Field
		//********************************
		

		var tr8     = document.createElement("tr");
		var tr8td1  = document.createElement("td");
		var tr8td2  = document.createElement("td");
		var tr8td3  = document.createElement("td");
		var tr8td4  = document.createElement("td");
		var tr8txt1 = document.createTextNode("NRIC / Passport No.");
		var tr8spn1 = document.createElement("span");
		var tr8inp1 = document.createElement("input");
		var tr8spc1 = document.createTextNode(String.fromCharCode(160));
		var tr8spc2 = document.createTextNode(String.fromCharCode(160));
				
		tr8spn1.setAttribute("id","sp" + num + "nric");
		
		tr8inp1.setAttribute("id","p" + num + "nric");
		tr8inp1.setAttribute("size","20");
		tr8inp1.setAttribute("type","text");
		tr8inp1.setAttribute("maxLength",20);
		tr8inp1.onblur = function() { capson(this); }
		tr8inp1.onfocus = function() { highlight(this); }
		
		if (navigator.appName == "Netscape" || navigator.appVersion.indexOf("MSIE 8.0") > -1) {
		    tr8td1.setAttribute("class","fieldname");  // Firefox, Safari and IE 8.0
   		    tr8spn1.setAttribute("class","chkfields");
		    tr8inp1.setAttribute("class","rol");
		}
		else {
		    tr8td1.setAttribute("className","fieldname");  // IE 7.0 and below
		    tr8spn1.setAttribute("className","chkfields");		    
		    tr8inp1.setAttribute("className","rol");
		}

		
		tr8.appendChild(tr8td1);
		tr8.appendChild(tr8td2);
		tr8.appendChild(tr8td3);
		tr8.appendChild(tr8td4);
				
		tr8td1.appendChild(tr8txt1);
		tr8td2.appendChild(tr8spc1);
		tr8td3.appendChild(tr8inp1);
		tr8td3.appendChild(tr8spn1);
		tr8td4.appendChild(tr8spc2);
				
		tblbody.appendChild(tr8)

		
		
		//********************************
		// DOB Field
		//********************************
		

		var tr9     = document.createElement("tr");
		var tr9td1  = document.createElement("td");
		var tr9td2  = document.createElement("td");
		var tr9td3  = document.createElement("td");
		var tr9td4  = document.createElement("td");
		var tr9txt1 = document.createTextNode("Date of Birth");
		var tr9txt2 = document.createTextNode(" (DD-MMM-YYYY)");		
		var tr9spn1 = document.createElement("span");
		var tr9inp1 = document.createElement("input");
		var tr9spc1 = document.createTextNode(String.fromCharCode(160));
		var tr9spc2 = document.createTextNode(String.fromCharCode(160));
				
		tr9spn1.setAttribute("id","sp" + num + "dob");
		
		tr9inp1.setAttribute("id","p" + num + "dob");
		tr9inp1.setAttribute("size","13");
		tr9inp1.setAttribute("type","text");
		tr9inp1.setAttribute("maxLength","11");
		tr9inp1.onblur = function() { capson(this); }
		tr9inp1.onfocus = function() { highlight(this); }
		
		if (navigator.appName == "Netscape" || navigator.appVersion.indexOf("MSIE 8.0") > -1) {
		    tr9td1.setAttribute("class","fieldname");  // Firefox, Safari and IE 8.0
   		    tr9spn1.setAttribute("class","chkfields");
		    tr9inp1.setAttribute("class","rol");
		}
		else {
		    tr9td1.setAttribute("className","fieldname");  // IE 7.0 and below
		    tr9spn1.setAttribute("className","chkfields");		    
		    tr9inp1.setAttribute("className","rol");
		}

		
		tr9.appendChild(tr9td1);
		tr9.appendChild(tr9td2);
		tr9.appendChild(tr9td3);
		tr9.appendChild(tr9td4);
				
		tr9td1.appendChild(tr9txt1);
		tr9td2.appendChild(tr9spc1);
		tr9td3.appendChild(tr9inp1);
		tr9td3.appendChild(tr9spn1);
		tr9td3.appendChild(tr9txt2);
		tr9td4.appendChild(tr9spc2);
				
		tblbody.appendChild(tr9)
		
		
		
		//********************************
		// EDUCATION Field
		//********************************
		

		var tr10     = document.createElement("tr");
		var tr10td1  = document.createElement("td");
		var tr10td2  = document.createElement("td");
		var tr10td3  = document.createElement("td");
		var tr10td4  = document.createElement("td");
		var tr10txt1 = document.createTextNode("Educational Qualification");
		var tr10txt2 = document.createTextNode(" (Highest)");
		var tr10spn1 = document.createElement("span");
		var tr10inp1 = document.createElement("input");
		var tr10spc1 = document.createTextNode(String.fromCharCode(160));
		var tr10spc2 = document.createTextNode(String.fromCharCode(160));
				
		tr10spn1.setAttribute("id","sp" + num + "heq");
		
		tr10inp1.setAttribute("id","p" + num + "heq");
		tr10inp1.setAttribute("size","40");
		tr10inp1.setAttribute("type","text");
		tr10inp1.setAttribute("maxLength",40);
		tr10inp1.onblur = function() { capson(this); }		
		tr10inp1.onfocus = function() { highlight(this); }

		if (navigator.appName == "Netscape" || navigator.appVersion.indexOf("MSIE 8.0") > -1) {
		    tr10td1.setAttribute("class","fieldname");  // Firefox, Safari and IE 8.0
		    tr10spn1.setAttribute("class","chkfields");		    
		    tr10inp1.setAttribute("class","rol");
		}
		else {
		    tr10td1.setAttribute("className","fieldname");  // IE 7.0 and below
		    tr10spn1.setAttribute("className","chkfields");		    
		    tr10inp1.setAttribute("className","rol");
		}

		
		tr10.appendChild(tr10td1);
		tr10.appendChild(tr10td2);
		tr10.appendChild(tr10td3);
		tr10.appendChild(tr10td4);
				
		tr10td1.appendChild(tr10txt1);
		tr10td2.appendChild(tr10spc1);
		tr10td3.appendChild(tr10inp1);
		tr10td3.appendChild(tr10spn1);
		tr10td3.appendChild(tr10txt2);
		tr10td4.appendChild(tr10spc2);
		
		tblbody.appendChild(tr10)


		lastnode.parentNode.insertBefore(trmain,lastnode);

		
	}
	
}

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}


function errorfield(field) {
	
	field.style.backgroundColor = "yellow";
	//alert(field.value);
	field.focus();	
}

function formvalidate() {

	//return true;

	// Company Name
	
	var companyName = document.forms[0].company;
	companyName.value = companyName.value.trim();
	
	
	if (lencheck(companyName, 1, "Please Enter Company Name.") == false) {
		return false;
	}
	
	if (lencheck(companyName, 5, "Company Name should be atleast 5 characters.") == false) {
		return false;
	}
	
	// Address Lines 1 
	
	var address1 = document.forms[0].address1;
	address1.value = address1.value.trim();
	
	
	if (lencheck(address1, 1, "Please Enter Address Line 1.") == false) {
		return false;
	}
	
	if (lencheck(address1, 10, "Address should be aleast 10 characters.") == false) {
		return false;
	}
	
	// Address Lines 2 
	
	var address2 = document.forms[0].address2;
	address2.value = address2.value.trim();
	
	
	if (lencheck(address2, 1, "Please Enter Address Line 2 or 'NA' if not applicable.") == false) {
		return false;
	}
	

	if (address2.value.length <= 2 && address2.value.toUpperCase() != "NA") {
		alert("Please Enter Address Line 2 or 'NA' if not applicable.");
		address2.focus();
		return false;
	}
	
	// Postal Code
	

	var pcode = document.forms[0].pcode;
	pcode.value = pcode.value.trim();
	
	
	if (lencheck(pcode, 1, "Please Enter Postal Code.") == false) {
		return false;
	}
	

	if (lencheck(pcode, 3, "Postal Code should be atleast 3 characters.") == false) {
		return false;
	}


	// City
	

	var city = document.forms[0].city;
	city.value = city.value.trim();
	
	
	if (lencheck(city, 2, "Please Enter City Name or 'NA' if not applicable.") == false) {
		return false;
	}
	

	// State
	

	var state = document.forms[0].state;
	state.value = state.value.trim();
	
	
	if (lencheck(state, 2, "Please Enter State Name or 'NA' if not applicable.") == false) {
		return false;
	}
	

	// Country

	var country = document.forms[0].country;
	country.value = country.value.trim();
	
	
	if (lencheck(country, 1, "Please Enter Country Name.") == false) {
		return false;
	}
	

	if (lencheck(country, 3, "Country Name should be atleast 3 characters.") == false) {
		return false;
	}


	// Contact Person


	var contact = document.forms[0].contact;
	contact.value = contact.value.trim();
	
	
	if (lencheck(contact, 1, "Please Enter Contact Person Name.") == false) {
		return false;
	}
	

	if (lencheck(contact, 5, "Contact Person Name should be atleast 5 characters.") == false) {
		return false;
	}

	
	// Salutation


	var salutation = document.forms[0].salutation;
	
	
	if (salutation.value == "----") {
		alert("Kindly select salutation for Contact Person.");
		salutation.focus();
		return false;
	}
	
	

	// Email Address


	var email = document.forms[0].email;
	email.value = email.value.trim();
	
	
	if (lencheck(email, 1, "Please Enter Email Address.") == false) {
		return false;
	}
	
	if (echeck(email.value) == false) {
		email.focus();
		return false;
	}


	// Email Address Check
	
	var emailchk = document.forms[0].emailchk;
	emailchk.value = emailchk.value.trim();
	emailchk.value = emailchk.value.toUpperCase();
	
	if (emailchk.value == "") {
		alert("Kindly Re-Enter Email Address for verification");
		emailchk.focus();
		return false;
	}
	
	if (email.value != emailchk.value) {
		alert("Email Addresses Do Not Match. Kindly check and Correct.");
		email.focus();
		return false;
	}

	// Designation


	var designation = document.forms[0].designation;
	designation.value = designation.value.trim();
	
	
	if (lencheck(designation, 1, "Please Enter your Designation / Position in company.") == false) {
		return false;
	}
	

	if (lencheck(designation, 5, "Designation should be atleast 5 characters.") == false) {
		return false;
	}


	// Telephone


	var telephone = document.forms[0].telephone;
	telephone.value = telephone.value.trim();
	
	
	if (lencheck(telephone, 1, "Please Enter your Telephone number.") == false) {
		return false;
	}
	

	if (lencheck(telephone, 7, "Telephone number should be atleast 7 characters.") == false) {
		return false;
	}


	// Fax


	var fax = document.forms[0].fax;
	fax.value = fax.value.trim();
	
	
	if (lencheck(fax, 1, "Please Enter your Fax number.") == false) {
		return false;
	}
	

	if (lencheck(fax, 7, "Fax number should be atleast 7 characters.") == false) {
		return false;
	}

    // Course Name
    
	var coursename = document.forms[0].p1coursename;

    if (coursename.selectedIndex == 0) {
    	alert("Please select Name of Course you wish to attend.");
    	coursename.focus();
    	return false;
    }
    
    
    // Course Date
    
	var coursedate = document.forms[0].p1coursedate;

    if (coursedate.selectedIndex == 0) {
    	alert("Please select the Course Date.");
    	coursedate.focus();
    	return false;
    }
    

	// Number of Participants
	
	var numofpart = document.forms[0].numofparticipants;
	
	var numop = numofpart.value;
    for (var x = 1; x <= numop; x++) {

    	var pname = document.getElementById("p" + x + "name");
    	var pgender = document.getElementById("p" + x + "gender");
    	var pnationality = document.getElementById("p" + x + "nationality");
    	var pnric = document.getElementById("p" + x + "nric");
    	var pdob = document.getElementById("p" + x + "dob");
    	var pheq = document.getElementById("p" + x + "heq");
    	
    	pname.value = pname.value.toUpperCase().trim();
    	pnationality.value = pnationality.value.toUpperCase().trim();
    	pnric.value = pnric.value.toUpperCase().trim();
    	pdob.value = pdob.value.toUpperCase().trim();
    	pheq.value = pheq.value.toUpperCase().trim();
    	
    	//	alert(pname.value + "-" + pnationality.value + "-" + pnric.value + "-" + pheq.value);
    	
		
		if (lencheck(pname, 5, "Participant " + x + " Name should atleast be 5 characters.") == false) {
			return false;
		}
    	
		if (pgender.value == "----") {
			alert("Kindly select Salutation for Participant " + x + ".");
			pgender.focus();
			return false;
		}


		if (lencheck(pnationality, 5, "Participant " + x + " Nationality should atleast be 5 characters.\n\nExample : THAI CITIZEN") == false) {
			return false;
		}


		if (lencheck(pnric, 5, "Participant " + x + " NRIC should atleast be 5 characters.") == false) {
			return false;
		}

		
		
		if (pdob.value != "NA") {
			if (lencheck(pdob, 11, "Participant " + x + " - Invalid Date Format. Please check!\nFormat should be DD-MMM-YYYY.\nExample : 05-OCT-1955.\nEnter 'NA' otherwise.") == false) {
				return false;
			}
		}
		
		if (lencheck(pheq, 5, "Participant " + x + " Educational Qualification should atleast be 5 characters.\n\nExample : PSLE CERT") == false) {
			return false;
		}
		
		//***********************************************************************************************
		// Special Date Validation - DOB only required for "8) SCDF Transport Drivers Course. Others can enter "NA"
		//***********************************************************************************************
		
		if (pdob.value == "NA" && coursename.value.substr(0,1) == "8") {
			alert("Participant " + x + "\nDate of Birth is *REQUIRED* for [SCDF Transport Drivers Course].\nKindly Provide.");
			errorfield(pdob);
			return false;
		}

		if (pdob.value != "NA") {

			// validate date of birth
			
			var pdobd = pdob.value.substr(0,2);
			var pdobm = pdob.value.substr(3,3);
			var pdoby = pdob.value.substr(7,4);
			
			var pdobd1 = pdob.value.substr(2,1);
			var pdobd2 = pdob.value.substr(6,1);
			
			
			if (pdobd1 != "-" && pdobd1 != "/") {
				alert("Participant " + x + "\nInvalid Date Format. Please check!\nFormat should be DD-MMM-YYYY.\nExample : 05-OCT-1955");
				errorfield(pdob);
				return false;
			}
			
			if (pdobd2 != "-" && pdobd2 != "/") {
				alert("Participant " + x + "\nInvalid Date Format. Please check!\nFormat should be DD-MMM-YYYY.\nExample : 05-OCT-1955");
				errorfield(pdob);
				return false;
			}


			if (pdobd < "01" || pdobd > "31") {
				alert("Particpant " + x + "\nDay of Date should be between 01 to 31\nKindly Check");
				errorfield(pdob);
				return false;
			}
			
			if ( (pdoby % 4) == 0 ) 
				var pdobleap = true;
			else
				var pdobleap = false;
			
			
			if (pdobm == "FEB") {
				if (pdobleap == true && pdobd > 29) {
					alert("Participant " + x + "\nDate of Birth is Leap Year " + pdoby + "\nDay between 01 to 29 only\nKindly Check.");
					errorfield(pdob);
					return false;
				}
				
				if (pdobleap == false && pdobd > 28) {
					alert("Participant " + x + "\nDate of Birth is Non-Leap Year " + pdoby + "\nDay between 01 to 28 only\nKindly Check.");
					errorfield(pdob);
					return false;
				}
			}
			
			var mthtxt = "";
			
			switch (pdobm) {
				case "JAN" : mthtxt = "ok"; break;
				case "FEB" : mthtxt = "ok"; break;
				case "MAR" : mthtxt = "ok"; break;
				case "APR" : mthtxt = "ok"; break;
				case "MAY" : mthtxt = "ok"; break;
				case "JUN" : mthtxt = "ok"; break;
				case "JUL" : mthtxt = "ok"; break;
				case "AUG" : mthtxt = "ok"; break;
				case "SEP" : mthtxt = "ok"; break;
				case "OCT" : mthtxt = "ok"; break;
				case "NOV" : mthtxt = "ok"; break;
				case "DEC" : mthtxt = "ok"; break;
				default :mthtxt = "error";
			}
			
			if (mthtxt == "error") {
				alert("Participant " + x + "\nInvalid Date of Birth Month [" + pdobm + "]\nMonth should be in the range of JAN, FEB, ... DEC.\nKindly Check");
				errorfield(pdob);
				return false;
			}
			
			if (pdobm == "SEP" || pdobm == "APR" || pdobm == "JUN" || pdobm == "NOV") {
				if (pdobd == 31) {
					alert("Participant " + x + "\nDate of Birth Error\nMaximum days for " + pdobm + " is only 30\nKindly Check");
					errorfield(pdob);
					return false;
				}
			}
			
			
			// *************************************************
			// Participant should be atleast 20 years old
			// *************************************************
			
			var tdy = new Date();
			var yer = tdy.getFullYear();
			var tyer = (yer - 18);
			var fyer = (yer - 90);
			
			//alert(pdoby + " --- " + yer);
			
			if (pdoby < fyer || pdoby > tyer) {
				alert("Participant " + x + "\nYear of birth Error.\nYear should be between " + fyer + " and " + tyer + "\nKindly Check");
				errorfield(pdob);
				return false;
			}
		
		}

	}
		
	return true;
	
}

function lencheck(v, l, m) {
	
	if (v.value.length < l) {
		alert(m);
		errorfield(v);
		return false;
	}
	
	return true;

	
	
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		 
		 if (str.substring(str.length,str.length-1) == dot) {
		    alert("Invalid E-mail ID");
		    return false;
		 }

 		 return true					
}

// End of Script
