<!--

function clearForm(formObj) {
	if (formObj)
	{
      with(formObj)
      {
         for (i=0;i<formObj.elements.length;i++)
         {
            switch(formObj.elements[i].type)
            {
            	case "hidden"  : formObj.elements[i].value = "";
            			    break;
            	case "text"       : formObj.elements[i].value = "";
            			    break;
            	case "password"       : formObj.elements[i].value = "";
            			    break;
            	case "textarea"       : formObj.elements[i].value = "";
            			    break;
            	case "select-one" : formObj.elements[i].options[0].selected = true;
            			    break;
            	case "checkbox"   : if(formObj.elements[i].checked == true)
            			    {
            			       formObj.elements[i].checked = false
            			    }
            			    break;
            	case "radio"      : if(formObj.elements[i].checked == true)
            			    {
            			       formObj.elements[i].checked = false;
            			    }
            			    break;
            	case "button"		:	break;
            	default           : alert("unknown : " + formObj.elements[i].type);
            }
         }
		}
	}
}


function GetAge(day, month, year) {

	if (day != '' || month != '' || year != '') {
		today = new Date();
		curyear = today.getFullYear();
		curmonth = today.getMonth()+1;
		curdate = today.getDate();
		age = curyear - year;
		if ((month > curmonth) || ((month == curmonth) && (curdate < day)))
			age = age - 1;

		return age;
	};

};
//
// Purpose :	Find out whether the inputted year is a leap year
// Return :	true/false
// Parameter :	The inputted year
//
function fnIsLeapYear (year)
{
	return (year%4 == 0 && (year%100 != 0 || year%400 == 0));
}

//
// Purpose :	Validate the date
// Return :	true/false
// Parameter :	year, month, day
//
function fnIsValidDate (year, month, day)
{
	var iMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	var iMonthLY = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	if (!fnIsMonth(month))
		 return false;
	if (isNaN(day))
		return false;
    	if ( (fnIsLeapYear(year) && (day > iMonthLY[month-1] || day < 1)) ||
             (!fnIsLeapYear(year) && (day > iMonth[month-1] || day < 1)) )
		return false;
	else
		return true;
}

//
// Purpose :	Validate the time
// Return :	true/false
// Parameter :	hr, min, sec
//
function fnIsValidTime (hr, min, sec)
{
	if (!fnIsHour(hr))	{ return "invalid hour !";	}
	if (!fnIsMin(min))	{ return "invalid minute !";}
	if (!fnIsSec(sec))	{	return "invalid second !";}

	if ((hr=="" || min=="" || sec=="") && (hr!="" || min!="" || sec!="")) {
		return "Enter Hour, Minute, Second correspondingly"
	};

	return true;

}

//
// Purpose :	Validate the year
// Return :	true/false
// Parameter :	Inputted year
//
function fnIsYear ( year )
{
	return (year > 1970 && year < 2999);
}

//
// Purpose :	Validate the month
// Return  :    true/false
// Parameter :	Inputted month
//
function fnIsMonth ( month )
{
	return (month >= 1 && month <= 12);
}

//
// Purpose :  	Validate the hour
// Return  :	true/false
// Parameter :	Inputted hour
//
function fnIsHour ( hour )
{
	return (hour >= 0 && hour < 24)
}

//
// Purpose : 	Validate the minute
// Return :	true/false
// Parameter :	Inputted minute
//
function fnIsMin ( minute )
{
	return (minute >= 0 && minute <= 59);
}

//
// Purpose :	Validate the second
// Return :	true/false
// Parameter :	Inputted second
//
function fnIsSec ( second )
{
	return (second >= 0 && second <= 59);
}

//
// Purpose :	Validate the number
// Return :	true/false
// Parameter :	Inputted number
//
function fnIsNumber ( number )
{
	return (!isNaN(number));
}

//
// Purpose :	Validate the integer
// Return :	true/false
// Parameter :	Inputted second
//
function fnIsInteger ( intvalue )
{
	if (intvalue == parseInt(intvalue))
		return true;
	else
		return false;
}

function zeropad(string, len)
{
	sbuf = string;

	for (i = string.length; i < parseInt(len); i ++)
	{
		sbuf = "0" + sbuf;
	}
	return sbuf;
}

function fnIsNumString(cardno)
{
	var i;
	for (i=0;i<cardno.length;i++)
		if (isNaN(cardno.charAt(i)) || cardno.charAt(i) == " ")
			return(false);

	return(true);
}


function fnIsAlphanumericWithSpaces(strvalue) {
	return /^[a-zA-Z0-9\s]+$/.test(strvalue);
}

function fnIsAlphanumeric(strvalue) {
	return /^[a-zA-Z0-9]+$/.test(strvalue);
}

function checkHkid(hkid_prefix,hkid_digits,hkid_check) {

			var i, j;
			// check english characters for hkid_prefix
			if (hkid_prefix == "") {
					alert("HKID prefix cannot be blank!");
					return(1);
			}

			for (j=0;j<hkid_prefix.length;j++) {
				prefixChar = hkid_prefix.charAt(j);
				if (prefixChar.charCodeAt(0) < 65	|| hkid_prefix.charCodeAt(0) > 90) {
					alert("HKID prefix can only be capital letter!");
					return(1);
				};
			};

			// check digits for hkid_digits
			if (hkid_digits.length != 6) {
				alert("HKID digits cannot be less than 6 digits!");
				return(2);
			};


			if (!fnIsNumString(hkid_digits)) {
				alert("Please input 6 digits!");
				return(2);
			};


			// check check digit character
			if (hkid_check.length != 1) {
				alert("Please input HKID check digit!");
				return(3);
			};

			/*
			if ((hkid_check != "a" && hkid_check != "A") || !fnIsNumString(hkid_check)) {
				alert("Check digit!");
				return;
			};
			*/

			idpre=hkid_prefix.charCodeAt(0);
			stringA='A';
			acode=stringA.charCodeAt(0);
			indexcode=idpre-acode+1;
			total=indexcode*8;
			for (i=0;i<6;i++){
			 	dcodes=hkid_digits.charAt(i);
				total=total+parseInt(dcodes)*(7-i);
			};

			if (hkid_check=="A" || hkid_check=="a")
				total=total+10;
			else {
				if (!isNaN(hkid_check))
				total=total+parseInt(hkid_check);
			}

			if ((total%11)!=0){
				alert("Invalid value of HKID, please input again!");
				return(2);
			}

	return(0);

}

function trim(str) {

	return str.replace(/^\s*(\S*)\s*$/,"$1")
}

function fnIsDecimal(numValue, beforeDec, afterDec) {
	numValue = stringReplace(numValue,",","");
   	if (isNaN(numValue) == true)
		return false;
        else {
        	maxnumber = Math.pow(10,beforeDec) - Math.pow(10,afterDec * -1);
	        if (numValue > maxnumber)
	        	return false;
	        if (numValue * 1 <= 0)
			return false;
	        if (numValue.indexOf(".") >= 0) // contains "."
	        {
   	                if (eval("/[.]{1}[\\d]{0,"+afterDec+"}$/.test(numValue)")==false)
				return false;
			else
				return true;
		}
		else
			return true;
	}

}

function stringReplace(originalString,findText,replaceText)
{
  var pos=0;
  var len = findText.length;
  pos = originalString.indexOf(findText);
  while(pos != -1)
  {
    preString = originalString.substring(0,pos);
    postString = originalString.substring(pos+len,originalString.length);
    originalString = preString + replaceText + postString;
    pos = originalString.indexOf(findText,pos);
  }
  return originalString;
}

function nochange(thisformObj, thisObj)
{
	if (thisObj.type == "checkbox")
	{
		thisObj.checked = !thisObj.checked;
	}

	else
	{
		thisObjName = thisObj.name;
		for (i=0 ; i<thisformObj.elements[thisObjName].length; i++)
		{
			thisformObj.elements[thisObjName][i].checked = thisformObj.elements[thisObjName][i].defaultChecked;
		}
	}

	return;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

//-->
