//top.opener.window.location.reload()	//--> to refresh page
var fldData 
var kx
var notPwd="~`!@#$%^&*()_+=-\|<>?,./:;'\""

function onoffmenu(subNavItem,submenuEx) {
	theID=document.getElementById(subNavItem)
	theID.style.backgroundColor = (theID.style.backgroundColor=="" ? "#C1A26F" : "");
	theID.className = (theID.className=="offMenu" ? "onMenu" : "offMenu");
}

function showhidesub(subNavItem){	
	if(document.getElementById(subNavItem)){
		theIDsub=eval(subNavItem + "sub")	
		theIDsub.style.display=(theIDsub.style.display=="block" ? "none" : "block")
	}
}

function trim(strText){ 
	while (strText.substr(0,1) == ' ') 
		strText = strText.substr(1, strText.length);
	while (strText.substr(strText.length-1,1) == ' ')
		strText = strText.substr(0, strText.length-1);
   	return strText;
}
	
function validString(strText){
	strText=trim(strText)
	for(n=0;n < strText.length;n++){
	   	chr = strText.charAt(n)
	   	if (notPwd.indexOf(chr) != -1) //if found character in notPwd
			return false
	}
 	return true
}

function fldDataArr(formFld,tajukTxt,str2comp){ //assigned input to array
	if(formFld)
		fldData[kx++]=new Array(trim(formFld.value),tajukTxt,str2comp) 
}

function defiErrMsg(iStart,iEnd){ //list down error msg in order
	for(i=iStart;i<=iEnd;i++){
		if(fldData[i][0]==fldData[i][2]){
			eval("errMsgDo"+ limitW +"='"+ limitW +". "+ fldData[i][1] +"'")
			limitW++	}
	}
	return limitW
}

function showMsgErr(limitW,txtMsg){	//display error msg in order list
	errMsgDo=txtMsg + "\n\n"
	for(w=1;w<limitW;w++){
		eval("errMsgDo += errMsgDo"+w)
		errMsgDo=errMsgDo+"\n"	}
	alert(errMsgDo)
}

function checkAdd(){
	kx=0
	fldData = new Array
	theForm=document.all
	fldDataArr(theForm.theName,"Nama","")
	fldDataArr(theForm.ic,"No. KP","")
	fldDataArr(theForm.loginpwd2,"Kata Laluan (Baru)","")
	
	for(j=0;j<1;j++){
		limitW=1
		switch(j){
		case 0: limitW=defiErrMsg(0,fldData.length-1)
				txtMsg="Sila masukkan maklumat berikut :"
				break
		default:
		} 
	 
		if(limitW > 1){ 
			showMsgErr(limitW,txtMsg)
			return false	}
	}
}

function printInfo(studID){
	win_printInfo=window.open("printInfo.asp?studID="+studID,"PrintInfo","menubar=1,scrollbars=1,resizable=1,width=700,height=400")	
	win_printInfo.focus()
}

function updList(nomX,theID){
	theForm=document.all
	namabox=eval("document.all.namabox"+nomX)
	if(namabox.length > 1){	//kursus & subject
		theForm.theCode.value=trim(namabox(0).innerText)
		theForm.theName.value=trim(namabox(1).innerText)
	}else
		theForm.theName.value=trim(namabox.innerText)
	
	theForm.theID.value=theID
	theForm.submitBtn(1).disabled=false
}

function LTrim(value) 
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

function RTrim(value)
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

function trim(value) 
{
	return LTrim(RTrim(value));
}

function validate()
{
	studIC = trim(document.theForm.txtIC.value)
	studYear = trim(document.theForm.txtYear.value)
	lenStudIC = studIC.length
	lenStudYear = studYear.length

	
	if((studIC=="") || (studYear==""))
	{
		alert ("Sila masukkan No KP dan Tahun pendaftaran!");
		return false;
	}
	else if((lenStudIC!=12) || (lenStudYear!=4))
	{
		alert ("Sila masukkan data yang betul bagi No KP dan Tahun pendaftaran!");
		return false;
	}
	else
		return true;
}

function validateResit()
{
	noResit = trim(document.theForm.txtResit.value)
		
	if(noResit == "")
	{
		alert("Sila masukkan No Resit!")
		return false;
	}
	else
		return true;
}