var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


function new_window(sfile) {
  popup = window.open (sfile, "cuhk", "scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no,status=yes,menubar=yes,height=600,width=800");
  if (parseInt(navigator.appVersion) >= 4) { popup.window.focus(); }
}
function new_window2(sfile) {
  popup2 = window.open (sfile, "cuhk2", "scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no,status=yes,menubar=yes,height=600,width=800");
  if (parseInt(navigator.appVersion) >= 4) { popup2.window.focus(); }
}
function new_window3(theURL,winName,features) { 
  popup3 = window.open(theURL,winName,features);
}

function goHist(a) {
  history.go(a);      // Go back one.
}

function close_window() {
  window.close();
}

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);

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; }
}

// below functions used for what's news
// change this to where you store the blank.gif image
var blank = "blank.gif";

topedge = 116;  // location of news box from top of page
leftedge = 613;  // location of news box from left edge
boxheight = 165;  // height of news box
boxwidth = 122;  // width of news box
scrollheight = 500; // total height of all data to be scrolled
timeout = 150; // timeout
stp = 1 // increment size
normal_time = 150 // original timeout
normal_stp = 1 // original increment size
scroll_time = 50;   // speed of increment
scroll_stp = 3;    // step increment size


function scrollnews(cliptop) {
if (document.layers) {
newsDiv = document.scroll_news;
newsDiv.clip.top = cliptop;
newsDiv.clip.bottom = cliptop + boxheight;
newsDiv.clip.left = 0;
newsDiv.clip.right = boxwidth + leftedge;
newsDiv.left = leftedge;
newsDiv.top = topedge - cliptop;
}
else {
newsDiv = scroll_news.style;
newsDiv.clip = "rect(" + cliptop + "px " + (boxwidth + leftedge) + "px " + (cliptop + boxheight) + "px 0px)";
newsDiv.pixelLeft = leftedge;
newsDiv.pixelTop = topedge - cliptop;
}
if (cliptop < 0) {
cliptop = scrollheight + boxheight;
}
else {
cliptop = (cliptop + stp) % (scrollheight + boxheight);
}
newsDiv.visibility='visible';
setTimeout("scrollnews(" + cliptop + ")", timeout);
}

function scroll_up() {
timeout = scroll_time;
stp = scroll_stp;
}

function scroll_dn() {
timeout = scroll_time;
stp = - scroll_stp;
}

function restore_scroll() {
timeout = normal_time;
stp = normal_stp;
}

function news_config(xpos,ypos,box_h,box_w,scroll_h,normal_t,normal_s,scroll_t,scroll_s) {
topedge = ypos;  
leftedge = xpos;
boxheight = box_h;
boxwidth = box_w;
scrollheight = scroll_h;
timeout = normal_t;
stp = normal_s;
normal_time = normal_t;
normal_stp = normal_s;
scroll_time = scroll_t;
scroll_stp = scroll_s;
}

//below functions used for banner (max 3 banners)
var mfBanners1 = [];
var mfBanners2 = [];
var mfBanners3 = [];

var mfIe = false;
if( document.all) {
mfIe = true;
}
var mfBannerIndex1 = 0;
var mfBannerIndex2 = 0;
var mfBannerIndex3 = 0;
var BannerWidth1 = 140;
var BannerHeight1 = 50;
var BannerWidth2 = 140;
var BannerHeight2 = 50;
var BannerWidth3 = 140;
var BannerHeight3 = 50;

function RandomStart1() {
mfBannerIndex1 = Math.round((mfBanners1.length - 1) * Math.random());
}

function RandomStart2() {
mfBannerIndex2 = Math.round((mfBanners2.length - 1) * Math.random());
}

function RandomStart3() {
mfBannerIndex3 = Math.round((mfBanners3.length - 1) * Math.random());
}

function mfBannerAdd1(add_url,add_img,add_alt) {
var tmp = new Array();
tmp[0] = add_url;
tmp[1] = add_img;
tmp[2] = add_alt;
mfBanners1[mfBanners1.length] = tmp;
}

function mfBannerAdd2(add_url,add_img,add_alt) {
var tmp = new Array();
tmp[0] = add_url;
tmp[1] = add_img;
tmp[2] = add_alt;
mfBanners2[mfBanners2.length] = tmp;
}

function mfBannerAdd3(add_url,add_img,add_alt) {
var tmp = new Array();
tmp[0] = add_url;
tmp[1] = add_img;
tmp[2] = add_alt;
mfBanners3[mfBanners3.length] = tmp;
}

function mfBannerChange1(banner_name) {
var htmlString = '<a target="_blank" href="'+mfBanners1[mfBannerIndex1][0]+'"> <img border="0" src="'+mfBanners1[mfBannerIndex1][1]+'" alt="'+mfBanners1[mfBannerIndex1][2]+'" width="'+BannerWidth1+'" height="'+BannerHeight1+'"></a>';
if( typeof(document.getElementById(banner_name).innerHTML) != 'undefined') {
//document.all.banner1.innerHTML = htmlString;
document.getElementById(banner_name).innerHTML = htmlString;
}
else {
document.getElementById(banner_name).document.open();
document.getElementById(banner_name).document.write( htmlString);
document.getElementById(banner_name).document.close();
}
if(mfBannerIndex1 < mfBanners1.length - 1)
mfBannerIndex1++;
else
mfBannerIndex1 = 0;
}

function mfBannerChange2(banner_name) {
var htmlString = '<a target="_blank" href="'+mfBanners2[mfBannerIndex2][0]+'"> <img border="0" src="'+mfBanners2[mfBannerIndex2][1]+'" alt="'+mfBanners2[mfBannerIndex2][2]+'" width="'+BannerWidth2+'" height="'+BannerHeight2+'"></a>';
if( typeof(document.getElementById(banner_name).innerHTML) != 'undefined') {
//document.all.banner2.innerHTML = htmlString;
document.getElementById(banner_name).innerHTML = htmlString;
}
else {
document.getElementById(banner_name).document.open();
document.getElementById(banner_name).document.write( htmlString);
document.getElementById(banner_name).document.close();
}
if(mfBannerIndex2 < mfBanners2.length - 1)
mfBannerIndex2++;
else
mfBannerIndex2 = 0;
}

function mfBannerChange3(banner_name) {
var htmlString = '<a target="_blank" href="'+mfBanners3[mfBannerIndex3][0]+'"> <img border="0" src="'+mfBanners3[mfBannerIndex3][1]+'" alt="'+mfBanners3[mfBannerIndex3][2]+'" width="'+BannerWidth3+'" height="'+BannerHeight3+'"></a>';
if( typeof(document.getElementById(banner_name).innerHTML) != 'undefined') {
//document.all.banner3.innerHTML = htmlString;
document.getElementById(banner_name).innerHTML = htmlString;
}
else {
document.getElementById(banner_name).document.open();
document.getElementById(banner_name).document.write( htmlString);
document.getElementById(banner_name).document.close();
}
if(mfBannerIndex3 < mfBanners3.length - 1)
mfBannerIndex3++;
else
mfBannerIndex3 = 0;
}

function BannerConfig1(new_width,new_height) {
BannerWidth1 = new_width;
BannerHeight1 = new_height;
}

function BannerConfig2(new_width,new_height) {
BannerWidth2 = new_width;
BannerHeight2 = new_height;
}

function BannerConfig3(new_width,new_height) {
BannerWidth3 = new_width;
BannerHeight3 = new_height;
}

//below functions used for float 'Top'

function setVariables() {
if (navigator.appName == "Netscape") {
v=".top=";
dS="document.";
sD="";
y="window.pageYOffset+450";
}
else {
v=".pixelTop=";
dS="";
sD=".style";
y="document.body.scrollTop+450";
   }
}

function checkLocation() {
object="object1";
yy=eval(y);
eval(dS+object+sD+v+yy);
setTimeout("checkLocation()",10);
}

//below functions used for checking online enrolment

function check_hkid(id_no) {

// id_no should be XX1234567

c1 = "";
c2 = "";
chk_digit = "";
tmp = "";
tmp_x = "";
tmp_id = "";
digit_start = 0;
digit_end = 0;
chk_no = 0;
id_len = 0;

tmp_id = id_no.toUpperCase();

if (tmp_id == '' || tmp_id.length > 9 || tmp_id.length < 8) {
  return false;
}

c1 = tmp_id.charAt(0);

if (!(c1 >= 'A' && c1 <= 'Z')) {
  return false;
}

c2 = tmp_id.charAt(1);

if (c2 >= 'A' && c2 <= 'Z') {
  digit_start = 2;
  id_len = 9;
}
else {
  c2 = c1;
  c1 = " ";
  id_len = 8;
	
  if (tmp_id.charAt(1) >= '0' && tmp_id.charAt(1) <= '9') {
    digit_start = 1;
  }
  else {
    return false;
  }
}

if (tmp_id.length != id_len) {
  return false;
}


if (c1 == " ") {
  chk_no = 0;
}
else {
  chk_no = (c1.charCodeAt(0) - 64) * 2 + 1;
}

chk_no = chk_no + (c2.charCodeAt(0) - 64) * 3;

digit_end = digit_start + 5;

for (j=digit_start;j<=digit_end;j++) {
  tmp_x = tmp_id.charAt(j);

  if (tmp_x < '0' || tmp_x > '9') {
    return false;
  }
	
  if (digit_start == 1) {
    chk_no = chk_no + (parseInt(tmp_x,10) * (j + 3));
  }
  else {
    chk_no = chk_no + (parseInt(tmp_x,10) * (j + 2));
  }
}

chk_digit = (chk_no % 11).toString();
if (chk_digit == "10") {
  chk_digit = 'A';
}

tmp = tmp_id.charAt(tmp_id.length - 1)

if (tmp != chk_digit) {
  return false;
}

return true;
}

function check_email(email) {
r = /^([\w_\.\-])+\@(([\w\-])+\.)+([\w]{2,4})+$/;
if (r.exec(email)) {
  return true;
}
else {
  return false;
}

}

function check_tel(tel_no) {
  if (tel_no == '') {
    return true;
  }

  if (isNaN(tel_no)) {
    return false;
  }

  return true;
}

function check_cardno(card_no,pay_ty) {
chk_sum = 0;
tmp_x = "";
tmp_num = 0;


if (isNaN(card_no)) {
  return false;
}

if (card_no.length != 16) {
  return false;
}

if (pay_ty == 'WV' && card_no.charAt(0) != '4') {
  return false;
}

if (pay_ty == 'WM' && card_no.charAt(0) != '5') {
  return false;
}

for (j=0;j<=card_no.length-1;j++) {
  tmp_x = card_no.charAt(j);
  if (!(tmp_x >= '0' && tmp_x <= '9')) {
    return false;
  }

  if (j==0 || j== 2 || j==4 || j==6 || j==8 || j==10 || j==12 || j==14) {
    tmp_num = parseInt(tmp_x) * 2;
    if (tmp_num >= 10) {
      tmp_num = ((tmp_num - (tmp_num%10))/10) + (tmp_num%10);
    }
  }
  else {
    tmp_num = parseInt(tmp_x,10);

  }

  chk_sum = chk_sum + tmp_num;
}

if ((chk_sum%10) != 0) {
  return false;
}

return true;
}

function check_enrol_cno(which,disp) {
var pass=true;
messagetext="";

if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];

if ((tempobj.name=="cno")&&tempobj.value=='') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>課 程 編 號 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Course Code</strong></td></tr>";
  }
}
}
}

if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUpperCase();

if (messagetext != '') {
messagetext = "<strong><table class='text01'>" + messagetext + "</table></strong>"
}


if ( typeof(document.getElementById("hints").innerHTML) != 'undefined' ) {
document.getElementById("hints").innerHTML = messagetext;
}
else {
document.getElementById("hints").document.open();
document.getElementById("hints").document.write(messagetext);
document.getElementById("hints").document.close();
}

document.body.scrollTop = 0;

if (disp == 'ch') {
alert("Please see the error message at the right-hand side.")
}
else {
alert("Please see the error message at the right-hand side.")
}

return false;
}
else
return true;

}

function check_enrol(which,disp) {
var pass=true;
messagetext="";
tmp_dd_dob = "";
tmp_mm_dob = "";
tmp_yyyy_dob = "";
dd = 0;
mm = 0;
yyyy = 0;
pay_ref_1 = "";
pay_ref_2 = "";
pay_ref_3 = "";
pay_ref_4 = "";
pay_ty = "";
tmp_mm_expiry = "";
tmp_yy_expiry = "";
title_cd = "";
form_ty = "";
reg_no = "";
is_hkid = "";
surname = "";
forename = "";
file1 = "";
file2 = "";
file3 = "";
file4 = "";
file5 = "";
file6 = "";
file7 = "";
file8 = "";
file9 = "";
file10 = "";
file11 = "";
file12 = "";
dup_file = 0;
id_no = "";
id_country_cd = "";
nation_cd = "";
occup_cd = "";
edu_lvl_cd = "";
card_bank = "";
choice1 = "";
choice2 = "";
choice3 = "";
dup_choice = 0;
submit = "";
invalid_year1 = 0;
invalid_year2 = 0;
invalid_year3 = 0;
invalid_grade1 = 0;
invalid_grade2 = 0;
invalid_grade3 = 0;
invalid_period1 = 0;
invalid_period2 = 0;
empty_grade_year1 = 0;
empty_grade_year2 = 0;
email = "";
email2 = "";
disc_ty = "";
disc_enrol = "";
min_age = 0;
empty_part1 = 1;
empty_part2 = 1;
empty_part3 = 1;
empty_part4 = 1;
empty_part5 = 1;
empty_part6 = 1;
v_app_fee_amt = 0;
skip_chk = 0;
form_show_p1 = "Y";
form_show_p2 = "Y";
form_show_p3 = "Y";
form_show_p4 = "Y";
form_show_p5 = "Y";
form_show_p6 = "Y";

if (document.images) {

for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];

if (tempobj.name=="id_no") {
  if (tempobj.value=='') {
    pass=false;
    if (disp == 'ch') {
      if (is_hkid == 'Y') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>香 港 身 份 證 號 碼 不 能 空 白</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>護 照 號 碼 不 能 空 白</strong></td></tr>";
      }
    }
    else {
      if (is_hkid == 'Y') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in HKID No.</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Passport No.</strong></td></tr>";
      }
    }
  }
  else {
    if (is_hkid == 'Y') {
      if (!(check_hkid(tempobj.value))) {
        pass=false;
        if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>香 港 身 份 證 號 碼 不 正 確</strong></td></tr>";
        }
        else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid HKID No.</strong></td></tr>";
        }
      }
    }
  }
}

//  if (tempobj.name=="is_hkid") {
//  messagetext = messagetext + 'type=[' + tempobj.type + ']<br>'
//  messagetext = messagetext + 'is_hkid=[' + tempobj.value + ']<br>'
//  messagetext = messagetext + 'checked = [' + tempobj.checked + ']<br>'
//  }

if (tempobj.name=="is_hkid" && tempobj.type!="radio") {
   is_hkid = tempobj.value;

   if (is_hkid == 'Y') {
      if (!(check_hkid(id_no))) {
        pass=false;
        if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>香 港 身 份 證 號 碼 不 正 確</strong></td></tr>";
        }
        else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid HKID No.</strong></td></tr>";
        }
      }
   }
}

if (tempobj.name=="is_hkid" && tempobj.type=="radio" && tempobj.checked) {
   is_hkid = tempobj.value;

   if (is_hkid == 'Y') {
      if (!(check_hkid(id_no))) {
        pass=false;
        if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>香 港 身 份 證 號 碼 不 正 確</strong></td></tr>";
        }
        else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid HKID No.</strong></td></tr>";
        }
      }
   }
}

if (tempobj.name=="form_show_p1") {
form_show_p1 = tempobj.value;
}

if (tempobj.name=="form_show_p2") {
form_show_p2 = tempobj.value;
}

if (tempobj.name=="form_show_p3") {
form_show_p3 = tempobj.value;
}

if (tempobj.name=="form_show_p4") {
form_show_p4 = tempobj.value;
}

if (tempobj.name=="form_show_p5") {
form_show_p5 = tempobj.value;
}

if (tempobj.name=="form_show_p6") {
form_show_p6 = tempobj.value;
}


if (tempobj.name=="skip_chk") {
skip_chk = tempobj.value;
}

if (tempobj.name=="v_app_fee_amt") {
v_app_fee_amt = tempobj.value;
}

if (tempobj.name=="min_age") {
min_age = tempobj.value;
}

if (tempobj.name=="form_ty") {
form_ty = tempobj.value;
}

if (tempobj.name=="reg_no") {
reg_no = tempobj.value;
}

if (tempobj.name=="surname") {
surname = tempobj.value;
}

if (tempobj.name=="forename") {
forename = tempobj.value;
}

if (tempobj.name=="id_no") {
id_no = tempobj.value;
}

if (tempobj.name=="id_country_cd") {
id_country_cd = tempobj.value;
}

if (tempobj.name=="nation_cd") {
nation_cd = tempobj.value;
}

if (tempobj.name=="occup_cd") {
occup_cd = tempobj.value;
}

if (tempobj.name=="edu_lvl_cd") {
edu_lvl_cd = tempobj.value;
}

if (tempobj.name=="card_bank") {
card_bank = tempobj.value;
}

if (tempobj.name=="email") {
email = tempobj.value;
}

if (tempobj.name=="email2") {
email2 = tempobj.value;
}

if (tempobj.name=="disc_ty") {
disc_ty = tempobj.value;
}

if (tempobj.name=="file_1") {
file1 = tempobj.value;
}

if (tempobj.name=="file_2") {
file2 = tempobj.value;
}

if (tempobj.name=="file_3") {
file3 = tempobj.value;
}

if (tempobj.name=="file_4") {
file4 = tempobj.value;
}

if (tempobj.name=="file_5") {
file5 = tempobj.value;
}

if (tempobj.name=="file_6") {
file6 = tempobj.value;
}

if (tempobj.name=="file_7") {
file7 = tempobj.value;
}

if (tempobj.name=="file_8") {
file8 = tempobj.value;
}

if (tempobj.name=="file_9") {
file9 = tempobj.value;
}

if (tempobj.name=="file_10") {
file10 = tempobj.value;
}

if (tempobj.name=="file_11") {
file11 = tempobj.value;
}

if (tempobj.name=="file_12") {
file12 = tempobj.value;
}

if (tempobj.name=="choice1") {
choice1 = tempobj.value;
}

if (tempobj.name=="choice2") {
choice2 = tempobj.value;
}

if (tempobj.name=="choice3") {
choice3 = tempobj.value;
}

if ((tempobj.name=="file_10" && form_ty =='2') || (tempobj.name=="file_4" && form_ty =='3') || (tempobj.name=="file_12" && form_ty =='4'))  {

  if (file1 != '' && dup_file == 0) {
    if (file1 == file2 || file1 == file3 || file1 == file4 || file1 == file5 || file1 == file6 || file1 == file7 || file1 == file8 || file1 == file9 || file1 == file10 || file1 == file11 || file1 == file12) {
      dup_file = 1;
    }
  }

  if (file2 != '' && dup_file == 0) {
    if (file2 == file1 || file2 == file3 || file2 == file4 || file2 == file5 || file2 == file6 || file2 == file7 || file2 == file8 || file2 == file9 || file2 == file10 || file2 == file11 || file2 == file12) {
      dup_file = 1;
    }
  }

  if (file3 != '' && dup_file == 0) {
    if (file3 == file1 || file3 == file2 || file3 == file4 || file3 == file5 || file3 == file6 || file3 == file7 || file3 == file8 || file3 == file9 || file3 == file10 || file3 == file11 || file3 == file12) {
      dup_file = 1;
    }
  }

  if (file4 != '' && dup_file == 0) {
    if (file4 == file1 || file4 == file2 || file4 == file3 || file4 == file5 || file4 == file6 || file4 == file7 || file4 == file8 || file4 == file9 || file4 == file10 || file4 == file11 || file4 == file12) {
      dup_file = 1;
    }
  }

  if (file5 != '' && dup_file == 0) {
    if (file5 == file1 || file5 == file2 || file5 == file3 || file5 == file4 || file5 == file6 || file5 == file7 || file5 == file8 || file5 == file9 || file5 == file10 || file5 == file11 || file5 == file12) {
      dup_file = 1;
    }
  }

  if (file6 != '' && dup_file == 0) {
    if (file6 == file1 || file6 == file2 || file6 == file3 || file6 == file4 || file6 == file5 || file6 == file7 || file6 == file8 || file6 == file9 || file6 == file10 || file6 == file11 || file6 == file12) {
      dup_file = 1;
    }
  }

  if (file7 != '' && dup_file == 0) {
    if (file7 == file1 || file7 == file2 || file7 == file3 || file7 == file4 || file7 == file5 || file7 == file6 || file7 == file8 || file7 == file9 || file7 == file10 || file7 == file11 || file7 == file12) {
      dup_file = 1;
    }
  }

  if (file8 != '' && dup_file == 0) {
    if (file8 == file1 || file8 == file2 || file8 == file3 || file8 == file4 || file8 == file5 || file8 == file6 || file8 == file7 || file8 == file9 || file8 == file10 || file8 == file11 || file8 == file12) {
      dup_file = 1;
    }
  }

  if (file9 != '' && dup_file == 0) {
    if (file9 == file1 || file9 == file2 || file9 == file3 || file9 == file4 || file9 == file5 || file9 == file6 || file9 == file7 || file9 == file8 || file9 == file10 || file9 == file11 || file9 == file12) {
      dup_file = 1;
    }
  }

  if (file10 != '' && dup_file == 0) {
    if (file10 == file1 || file10 == file2 || file10 == file3 || file10 == file4 || file10 == file5 || file10 == file6 || file10 == file7 || file10 == file8 || file10 == file9 || file10 == file11 || file10 == file12) {
      dup_file = 1;
    }
  }

  if (file11 != '' && dup_file == 0) {
    if (file11 == file1 || file11 == file2 || file11 == file3 || file11 == file4 || file11 == file5 || file11 == file6 || file11 == file7 || file11 == file8 || file11 == file9 || file11 == file10 || file11 == file12) {
      dup_file = 1;
    }
  }

  if (file12 != '' && dup_file == 0) {
    if (file12 == file1 || file12 == file2 || file12 == file3 || file12 == file4 || file12 == file5 || file12 == file6 || file12 == file7 || file12 == file8 || file12 == file9 || file12 == file10 || file12 == file11) {
      dup_file = 1;
    }
  }


  if (dup_file == 1) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>有 些 上 載 檔 是 重 複 的</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Some attachment are duplicated</strong></td></tr>";
    }
  }
}

if (tempobj.name == "choice3")  {

  if (choice1 != '' && dup_choice == 0) {
    if (choice1 == choice2 || choice1 == choice3) {
      dup_choice = 1;
    }
  }

  if (choice2 != '' && dup_choice == 0) {
    if (choice2 == choice1 || choice2 == choice3) {
      dup_choice = 1;
    }
  }

  if (choice3 != '' && dup_choice == 0) {
    if (choice3 == choice1 || choice3 == choice2) {
      dup_choice = 1;
    }
  }

  if (dup_choice == 1) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>報 讀 課 程 重 複</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Duplicate programme</strong></td></tr>";
    }
  }
}

if (tempobj.name=="id_country_cd") {
  if (is_hkid == 'Y') {
    if (tempobj.value != '' && tempobj.value != 'HK') {
      pass=false;
      if (disp == 'ch') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 留 空 簽 發 國 家 （ 持 香 港 身 份 證 人 士 ）</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please leave 'Issuing Country' blank (for HKID holders)</strong></td></tr>";
      }
    }
  }
  else {
    if (tempobj.value == '') {
      pass=false;
      if (disp == 'ch') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 上 簽 發 國 家 （ 持 護 照 人 士 ）</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 'Issuing Country' (for passport holders)</strong></td></tr>";
      }
    }
  }
}

if (tempobj.name=="id_country_oth_desc") {
  if (id_country_cd != "OTHR" && tempobj.value != '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 留 空 簽 發 國 家 （其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please leave 'Issuing Country (Others)' blank</strong></td></tr>";
    }
  }
  if (id_country_cd == "OTHR" && tempobj.value == '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 簽 發 國 家 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 'Issuing Country (Others)'</strong></td></tr>";
    }
  }
}

if (tempobj.name=="nation_oth_desc") {
  if (nation_cd != "OTHR" && tempobj.value != '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 留 空 國 籍 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please leave 'Nationality (Others)' blank</strong></td></tr>";
    }
  }
  if (nation_cd == "OTHR" && tempobj.value == '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 國 籍 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 'Nationality (Others)'</strong></td></tr>";
    }
  }
}

if (tempobj.name=="occup_oth_desc") {
  if (occup_cd != "OTHR" && tempobj.value != '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 留 空 職 業 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please leave 'Occupation (Others)' blank</strong></td></tr>";
    }
  }
  if (occup_cd == "OTHR" && tempobj.value == '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 職 業 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 'Occupation (Others)'</strong></td></tr>";
    }
  }
}

if (tempobj.name=="edu_oth_desc") {
  if (edu_lvl_cd != "OTHR" && tempobj.value != '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 留 空 最 高 教 育 程 度 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please leave 'Highest Education Level Achieved (Others)' blank</strong></td></tr>";
    }
  }
  if (edu_lvl_cd == "OTHR" && tempobj.value == '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 最 高 教 育 程 度 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 'Highest Education Level Achieved (Others)'</strong></td></tr>";
    }
  }
}

if (tempobj.name=="card_bank_oth_desc") {
  if (card_bank != "OTHR" && tempobj.value != '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 留 空 發 卡 銀 行 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please leave 'Card Issuing Bank (Others)' blank</strong></td></tr>";
    }
  }
  if (card_bank == "OTHR" && tempobj.value == '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 發 卡 銀 行 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 'Card Issuing Bank (Others)'</strong></td></tr>";
    }
  }
}

if ((tempobj.name=="surname")&&tempobj.value=='') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>姓 氏 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Surname</strong></td></tr>";
  }
}

if ((tempobj.name=="forename")&&tempobj.value=='') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>名 字 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in First Name</strong></td></tr>";
  }
}

if ((tempobj.name=="title_cd") && tempobj.type!="radio") {
title_cd = tempobj.value;
}

if ((tempobj.name=="title_cd") && tempobj.type=="radio" && tempobj.checked) {
title_cd = tempobj.value;
}

if ((tempobj.name=="title_cd") && tempobj.type!="radio" && title_cd == '') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>稱 謂 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Title</strong></td></tr>";
  }
}

if ((tempobj.name=="title_cd") && tempobj.type=="radio" && tempobj.value=='MS' && title_cd == '') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>稱 謂 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Title</strong></td></tr>";
  }
}

//if (tempobj.name=="title_cd") {
//pass=false;
//messagetext = messagetext + "title_cd = " + tempobj.value + "<br>";
//messagetext = messagetext + "title_cd = " + tempobj.checked + "<br>";
//}


if (tempobj.name=="dd_dob") {
if (tempobj.value!='' && !isNaN(tempobj.value)) {
tmp_dd_dob = tempobj.value;
  }
else {
tmp_dd_dob = "";
  }
}

if (tempobj.name=="mm_dob") {
if (tempobj.value!='' && !isNaN(tempobj.value)) {
tmp_mm_dob = tempobj.value;
  }
else {
tmp_mm_dob = "";
  }
}

if (tempobj.name=="yyyy_dob") {
  if (tempobj.value!='' && !isNaN(tempobj.value)) {
    tmp_yyyy_dob = tempobj.value;
  }
  else {
    tmp_yyyy_dob = "";
  }

//messagetext = messagetext + "dd = " + tmp_dd_dob + "<br>";
//messagetext = messagetext + "mm = " + tmp_mm_dob + "<br>";
//messagetext = messagetext + "yyyy = " + tmp_yyyy_dob + "<br>";

  if (tmp_dd_dob == '' || isNaN(tmp_dd_dob) || tmp_mm_dob == '' || isNaN(tmp_mm_dob) || tmp_yyyy_dob == '' || isNaN(tmp_yyyy_dob)) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>出 生 日 期 不 是 有 效 的 日 期</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Date of Birth</strong></td></tr>";
    }
  }
  else {
    dd = parseInt(tmp_dd_dob,10);
    mm = parseInt(tmp_mm_dob,10);
    yyyy = parseInt(tmp_yyyy_dob,10);

    monarr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

//messagetext = messagetext + "dd = " + dd.toString() + "<br>";
//messagetext = messagetext + "mm = " + mm.toString() + "<br>";
//messagetext = messagetext + "yyyy = " + yyyy.toString() + "<br>";
//messagetext = messagetext + "step 2...<br>";
//messagetext = messagetext + "monarr[3] = " + monarr[mm - 1].toString() + "<br>";


    // check for leap year
    if (((yyyy % 4 == 0) && (yyyy % 100 != 0)) || (yyyy % 400 == 0)) monarr[1] = "29";

    today = new Date();

    cur_yy = today.getFullYear();
    cur_mm = today.getMonth() + 1;
    cur_dd = today.getDate();

    age = cur_yy - yyyy;
    if ((cur_mm < mm) || (cur_mm == mm && cur_dd < dd)) {
      age = age - 1;
    }

    if ((mm < 1 || mm > 12) || (dd < 1 || dd > monarr[mm - 1]) || (yyyy < 1900) || (yyyy > cur_yy) || (yyyy == cur_yy && mm > cur_mm) || (yyyy == cur_yy && mm == cur_mm && dd > cur_dd) || (age > 110)) {
      pass=false;
      if (disp == 'ch') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>出 生 日 期 不 是 有 效 的 日 期</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Date of Birth</strong></td></tr>";
      }
    }
    else {
      if (age < min_age) {
        pass=false;
        if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>最 小 " + min_age.toString() + " 歲</strong></td></tr>";
        }
        else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>At least " +  min_age.toString() + " years old</strong></td></tr>";
        }
      }
    }
  }
}

//if ((tempobj.name=="home_phone")&&tempobj.value=='' && (form_ty != '2')) {
//pass=false;
//if (disp == 'ch') {
//messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 住 宅 電 話 （ 或 手 提 電 話 ， 如 適 用 ）</strong></td></tr>";
//  }
//else {
//messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 'Home Telephone' (or mobile number, if necessary)</strong></td></tr>";
//  }
//}
if ((tempobj.name=="home_phone")&&tempobj.value!=''&&skip_chk==0) {
  if (!(check_tel(tempobj.value))) {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>住 宅 電 話 不 正 確</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Home Telephone</strong></td></tr>";
    }
  }
}

if ((tempobj.name=="mobile_phone")&&tempobj.value=='') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 手 電 / 傳 呼 號 碼 （ 或 住 宅 電 話 ， 如 適 用 ）</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Mobile / Pager (or home telephone number, if necessary)</strong></td></tr>";
  }
}

if ((tempobj.name=="mobile_phone")&&tempobj.value!=''&&skip_chk==0) {
  if (!(check_tel(tempobj.value))) {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>手 電 / 傳 呼 號 碼 不 正 確</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Mobile / Pager</strong></td></tr>";
    }
  }
}

if ((tempobj.name=="emg_phone")&&tempobj.value!=''&&skip_chk==0) {
  if (!(check_tel(tempobj.value))) {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>緊 急 聯 絡 電 話 不 正 確</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Emergency Contact Telephone</strong></td></tr>";
    }
  }
}


if ((tempobj.name=="office_phone")&&tempobj.value!=''&&skip_chk==0) {
  if (!(check_tel(tempobj.value))) {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>辦 事 處 電 話 不 正 確</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Office Telephone</strong></td></tr>";
    }
  }
}

if ((tempobj.name=="fax_no")&&tempobj.value!=''&&skip_chk==0) {
  if (!(check_tel(tempobj.value))) {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>辦 事 處 / 聯 絡 傳 真 不 正 確</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Office / Contact Fax</strong></td></tr>";
    }
  }
}

if ((tempobj.name=="disc_ty") && disc_ty == '' && (form_ty == '1')) {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 選 擇 進 修 積 分 計 劃 學 員 類 別</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please select eligible category of SCS Cash Unit Scheme (CATS)</strong></td></tr>";
  }
}

if ((tempobj.name=="disc_enrol") && tempobj.type=="radio" && tempobj.checked) {
disc_enrol = tempobj.value;
}

//if ((tempobj.name=="disc_enrol") && tempobj.type=="radio" && disc_enrol=='Y' && disc_ty == '' && form_ty == '1') {
//pass=false;
//if (disp == 'ch') {
//messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 選 擇 進 修 積 分 計 劃 學 員 類 別</strong></td></tr>";
//  }
//else {
//messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please select eligible category of SCS Cash Unit Scheme (CATS)</strong></td></tr>";
//  }
//}




if ((tempobj.name=="email2") && form_ty =='1') {
  if (tempobj.value=='') {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>重 新 輸 入 電 郵 地 址 不 能 空 白</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 'Re-enter E-mail Address'</strong></td></tr>";
    }
  }
  else {
    if (email != email2) {
      pass=false;
      if (disp == 'ch') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>重 新 輸 入 電 郵 地 址 與 電 郵 格 式 不 同</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>The format of 'Re-enter Email Address' does not match the one in 'E-mail Address'</strong></td></tr>";
      }
    }
  }
}

if (tempobj.name=="email") {
  if (tempobj.value=='') {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>電 郵 地 址 不 能 空 白</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in E-mail Address</strong></td></tr>";
    }
  }
  else {
    if (!(check_email(tempobj.value))&&skip_chk==0) {
      pass=false;
      if (disp == 'ch') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>電 郵 ?a 址 格 式 不 正 確</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid E-mail Address format</strong></td></tr>";
      }
    }
  }
}


if (tempobj.name=="addr1") {
  if (tempobj.value=='') {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>通 訊 地 址 不 能 空 白</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Correspondence Address</strong></td></tr>";
    }
  }
  else {
    tmp_add = " " + tempobj.value + " "

    if (tmp_add.search('"') > 0) {
      pass=false;
      if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>通 訊 地 址(1) 不 能 有 "+String.fromCharCode(34)+"</strong></td></tr>";
      }
      else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Correspondence Address(1) cannot contains "+String.fromCharCode(34)+"</strong></td></tr>";
      }
    }
  }
}

if ((tempobj.name=="addr2")&&tempobj.value!='') {
    tmp_add = " " + tempobj.value + " "

    if (tmp_add.search('"') > 0) {
      pass=false;
      if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>通 訊 地 址(2) 不 能 有 "+String.fromCharCode(34)+"</strong></td></tr>";
      }
      else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Correspondence Address(2) cannot contains "+String.fromCharCode(34)+"</strong></td></tr>";
      }
    }
}

if ((tempobj.name=="addr3")&&tempobj.value!='') {
    tmp_add = " " + tempobj.value + " "

    if (tmp_add.search('"') > 0) {
      pass=false;
      if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>通 訊 地 址(3) 不 能 有 "+String.fromCharCode(34)+"</strong></td></tr>";
      }
      else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Correspondence Address(3) cannot contains "+String.fromCharCode(34)+"</strong></td></tr>";
      }
    }
}

if ((tempobj.name=="addr4")&&tempobj.value!='') {
    tmp_add = " " + tempobj.value + " "

    if (tmp_add.search('"') > 0) {
      pass=false;
      if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>通 訊 地 址(4) 不 能 有 "+String.fromCharCode(34)+"</strong></td></tr>";
      }
      else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Correspondence Address(4) cannot contains "+String.fromCharCode(34)+"</strong></td></tr>";
      }
    }
}

if ((tempobj.name=="choice1") && tempobj.value=='' && form_ty =='4') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>第 一 選 擇 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 1st choice</strong></td></tr>";
  }
}

if (is_save == 0 && form_ty == '2') {

  today2 = new Date();
  cur_yy = today2.getFullYear();


  if (tempobj.name=="col_3" || tempobj.name=="col_8" || tempobj.name=="col_13" || tempobj.name=="col_18" || tempobj.name=="col_23") {
    if (tempobj.value != '') {
      empty_part1 = 0;
    }
  }
  if (empty_part1 == 1 && tempobj.name=="col_23" && form_show_p1=="Y") {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 最 少 一 項 資 料 於 乙 部 – 學 歷 及 專 業 資 格 。 ( 如 適 用 ， 請 填 上 'NA' 於 頒 授 機 構 。 )</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in at least 1 record for Part B – Academic and Professional Qualifications (If necessary, please input 'NA' in 'Issuing Authority')</strong></td></tr>";
    }
  }

  if (tempobj.name=="col_28" || tempobj.name=="col_33" || tempobj.name=="col_38") {
    if (tempobj.value != '') {
      empty_part2 = 0;
    }
  }
  if (empty_part2 == 1 && tempobj.name=="col_38" && form_show_p2=="Y") {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 最 少 一 項 資 料 於 乙 部 – 工 作 經 驗 。 ( 如 適 用 ， 請 填 上 'NA' 於 公 司 名 稱 及 地 址 。 )</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in at least 1 record for Part B – Work Experience (If necessary, please input 'NA' in 'Company Name & Address')</strong></td></tr>";
    }
  }


  if (tempobj.name=="col_41" || tempobj.name=="col_44" || tempobj.name=="col_47" || tempobj.name=="col_50" || tempobj.name=="col_53" || tempobj.name=="col_56") {
    if (tempobj.value != '') {
      empty_part3 = 0;
    }
  }
  if (empty_part3 == 1 && tempobj.name=="col_56" && form_show_p3=="Y") {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 最 少 一 項 資 料 於 乙 部 – 語 言 能 力 。 ( 如 適 用 ， 請 填 上 'NA' 於 頒 授 機 構 。 )</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in at least 1 record for Part B – Language Skills (If necessary, please input 'NA' in 'Issuing Authority')</strong></td></tr>";
    }
  }

  if (tempobj.name=="col_59") {
    if (tempobj.value != '') {
      empty_part4 = 0;
    }
  }
  if (empty_part4 == 1 && tempobj.name=="col_59" && form_show_p4=="Y") {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 乙 部 – 普 通 話 系 列 / 日 語 / 韓 語 證 書 課 程 的 第 二 選 擇 。 ( 如 適 用 ， 請 填 上 'NA' )</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Second Choice for Part B – Putonghua / Japanese / Korean Certificate Programmes (Please input 'NA' if necessary)</strong></td></tr>";
    }
  }

  if (tempobj.name=="col_66") {
    if (tempobj.value != '') {
      empty_part5 = 0;
    }
  }
  if (empty_part5 == 1 && tempobj.name=="col_66" && form_show_p5=="Y") {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 乙 部 – 藝 術 課 程 。 ( 如 適 用 ， 請 填 上 'NA' )</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Part B - Art Programmes (Please input 'NA' if necessary)</strong></td></tr>";
    }
  }

  if (tempobj.name=="col_69") {
    if (tempobj.value != '') {
      empty_part6 = 0;
    }
  }
  if (empty_part6 == 1 && tempobj.name=="col_69" && form_show_p6=="Y") {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 乙 部 – 電 腦 知 識 及 其 他 技 能 。 ( 如 適 用 ， 請 填 上 'NA' )</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Part B – Computer Knowledge and Other Skills (Please input 'NA' if necessary)</strong></td></tr>";
    }
  }


  if (tempobj.name=="col_1" || tempobj.name=="col_6" || tempobj.name=="col_11" || tempobj.name=="col_16" || tempobj.name=="col_21") {
    temp_fm = tempobj.value;

    if (temp_fm != '') {
      tmp_fm_mm = temp_fm.substr(0,2);
      tmp_fm_sep = temp_fm.substr(2,1);
      tmp_fm_yyyy = temp_fm.substr(3,temp_fm.length - 3);

      if (tmp_fm_mm == '' || tmp_fm_sep != '/' || tmp_fm_yyyy == '') {
        invalid_period1 = 1;
      }

      if (tmp_fm_mm != '') {
        if (tmp_fm_mm.substr(0,1) < '0' || tmp_fm_mm.substr(0,1) > '9') {
          invalid_period1 = 1;
        }
        if (tmp_fm_mm.substr(1,1) < '0' || tmp_fm_mm.substr(1,1) > '9') {
          invalid_period1 = 1;
        }

        if (isNaN(tmp_fm_mm)) {
          invalid_period1 = 1;
        }
        else {
          tmp_fm_mm2 = parseInt(tmp_fm_mm,10);
          if (tmp_fm_mm2 < 1 || tmp_fm_mm2 > 12) {
            invalid_period1 = 1;
          }
        }
      }

      if (tmp_fm_yyyy != '') {
        if (tmp_fm_yyyy.length > 4) {
          invalid_period1 = 1;
        }

        if (tmp_fm_yyyy.substr(0,1) < '0' || tmp_fm_yyyy.substr(0,1) > '9') {
          invalid_period1 = 1;
        }
        if (tmp_fm_yyyy.substr(1,1) < '0' || tmp_fm_yyyy.substr(1,1) > '9') {
          invalid_period1 = 1;
        }
        if (tmp_fm_yyyy.substr(2,1) < '0' || tmp_fm_yyyy.substr(2,1) > '9') {
          invalid_period1 = 1;
        }
        if (tmp_fm_yyyy.substr(3,1) < '0' || tmp_fm_yyyy.substr(3,1) > '9') {
          invalid_period1 = 1;
        }

        if (isNaN(tmp_fm_yyyy)) {
          invalid_period1 = 1;
        }
        else {
          tmp_fm_yyyy2 = parseInt(tmp_fm_yyyy,10);
          if (tmp_fm_yyyy2 < 1950 || tmp_fm_yyyy2 > cur_yy) {
            invalid_period1 = 1;
          }
        }
      }
    }
  }

  if (tempobj.name=="col_2" || tempobj.name=="col_7" || tempobj.name=="col_12" || tempobj.name=="col_17" || tempobj.name=="col_22") {
    temp_to = tempobj.value;

    if ((temp_fm == '' && temp_to != '') || (temp_fm != '' && temp_to == '')) {
      invalid_period1 = 1;
    }

    if (temp_to != '' && temp_to.toUpperCase() != 'NOW') {
      tmp_to_mm = temp_to.substr(0,2);
      tmp_to_sep = temp_to.substr(2,1);
      tmp_to_yyyy = temp_to.substr(3,temp_to.length - 3);

      if (tmp_to_mm == '' || tmp_to_sep != '/' || tmp_to_yyyy == '') {
        invalid_period1 = 1;
      }

      if (tmp_to_mm != '') {
        if (tmp_to_mm.substr(0,1) < '0' || tmp_to_mm.substr(0,1) > '9') {
          invalid_period1 = 1;
        }
        if (tmp_to_mm.substr(1,1) < '0' || tmp_to_mm.substr(1,1) > '9') {
          invalid_period1 = 1;
        }

        if (isNaN(tmp_to_mm)) {
          invalid_period1 = 1;
        }
        else {
          tmp_to_mm2 = parseInt(tmp_to_mm,10);
          if (tmp_to_mm2 < 1 || tmp_to_mm2 > 12) {
            invalid_period1 = 1;
          }
        }
      }

      if (tmp_to_yyyy != '') {
        if (tmp_to_yyyy.length > 4) {
          invalid_period1 = 1;
        }

        if (tmp_to_yyyy.substr(0,1) < '0' || tmp_to_yyyy.substr(0,1) > '9') {
          invalid_period1 = 1;
        }
        if (tmp_to_yyyy.substr(1,1) < '0' || tmp_to_yyyy.substr(1,1) > '9') {
          invalid_period1 = 1;
        }
        if (tmp_to_yyyy.substr(2,1) < '0' || tmp_to_yyyy.substr(2,1) > '9') {
          invalid_period1 = 1;
        }
        if (tmp_to_yyyy.substr(3,1) < '0' || tmp_to_yyyy.substr(3,1) > '9') {
          invalid_period1 = 1;
        }

        if (isNaN(tmp_to_yyyy)) {
          invalid_period1 = 1;
        }
        else {
          tmp_to_yyyy2 = parseInt(tmp_to_yyyy,10);
          if (tmp_to_yyyy2 < 1950 || tmp_to_yyyy2 > cur_yy) {
            invalid_period1 = 1;
          }
        }
      }

      if (temp_fm != '') {
        tmp_fm_mm = temp_fm.substr(0,2);
        tmp_fm_yyyy = temp_fm.substr(3,temp_fm.length - 3);
        if (!isNaN(tmp_fm_mm) && !isNaN(tmp_fm_yyyy) && !isNaN(tmp_to_mm) && !isNaN(tmp_to_yyyy)) {
          tmp_fm_mm2 = parseInt(tmp_fm_mm,10);
          tmp_fm_yyyy2 = parseInt(tmp_fm_yyyy,10);
          tmp_to_mm2 = parseInt(tmp_to_mm,10);
          tmp_to_yyyy2 = parseInt(tmp_to_yyyy,10);
          if ((tmp_fm_yyyy2 > tmp_to_yyyy2) || (tmp_fm_yyyy2 == tmp_to_yyyy2 && tmp_fm_mm2 > tmp_to_mm2)) {
            invalid_period1 = 1;
          }
        }
      }
    }
  }

  if (tempobj.name=="col_22" && invalid_period1 == 1) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>年 份 不 正 確 (專 業 資 格)</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid year (Qualifications)</strong></td></tr>";
    }
  }

  if (tempobj.name=="col_26" || tempobj.name=="col_31" || tempobj.name=="col_36") {
    temp_fm = tempobj.value;

    if (temp_fm != '') {
      tmp_fm_mm = temp_fm.substr(0,2);
      tmp_fm_sep = temp_fm.substr(2,1);
      tmp_fm_yyyy = temp_fm.substr(3,temp_fm.length - 3);

      if (tmp_fm_mm == '' || tmp_fm_sep != '/' || tmp_fm_yyyy == '') {
        invalid_period2 = 1;
      }

      if (tmp_fm_mm != '') {
        if (tmp_fm_mm.substr(0,1) < '0' || tmp_fm_mm.substr(0,1) > '9') {
          invalid_period2 = 1;
        }
        if (tmp_fm_mm.substr(1,1) < '0' || tmp_fm_mm.substr(1,1) > '9') {
          invalid_period2 = 1;
        }

        if (isNaN(tmp_fm_mm)) {
          invalid_period2 = 1;
        }
        else {
          tmp_fm_mm2 = parseInt(tmp_fm_mm,10);
          if (tmp_fm_mm2 < 1 || tmp_fm_mm2 > 12) {
            invalid_period2 = 1;
          }
        }
      }

      if (tmp_fm_yyyy != '') {
        if (tmp_fm_yyyy.length > 4) {
          invalid_period2 = 1;
        }

        if (tmp_fm_yyyy.substr(0,1) < '0' || tmp_fm_yyyy.substr(0,1) > '9') {
          invalid_period2 = 1;
        }
        if (tmp_fm_yyyy.substr(1,1) < '0' || tmp_fm_yyyy.substr(1,1) > '9') {
          invalid_period2 = 1;
        }
        if (tmp_fm_yyyy.substr(2,1) < '0' || tmp_fm_yyyy.substr(2,1) > '9') {
          invalid_period2 = 1;
        }
        if (tmp_fm_yyyy.substr(3,1) < '0' || tmp_fm_yyyy.substr(3,1) > '9') {
          invalid_period2 = 1;
        }

        if (isNaN(tmp_fm_yyyy)) {
          invalid_period2 = 1;
        }
        else {
          tmp_fm_yyyy2 = parseInt(tmp_fm_yyyy,10);
          if (tmp_fm_yyyy2 < 1950 || tmp_fm_yyyy2 > cur_yy) {
            invalid_period2 = 1;
          }
        }
      }
    }
  }

  if (tempobj.name=="col_27" || tempobj.name=="col_32" || tempobj.name=="col_37") {
    temp_to = tempobj.value;

    if ((temp_fm == '' && temp_to != '') || (temp_fm != '' && temp_to == '')) {
      invalid_period2 = 1;
    }

    if (temp_to != '' && temp_to.toUpperCase() != 'NOW') {
      tmp_to_mm = temp_to.substr(0,2);
      tmp_to_sep = temp_to.substr(2,1);
      tmp_to_yyyy = temp_to.substr(3,temp_to.length - 3);

      if (tmp_to_mm == '' || tmp_to_sep != '/' || tmp_to_yyyy == '') {
        invalid_period2 = 1;
      }

      if (tmp_to_mm != '') {
        if (tmp_to_mm.substr(0,1) < '0' || tmp_to_mm.substr(0,1) > '9') {
          invalid_period2 = 1;
        }
        if (tmp_to_mm.substr(1,1) < '0' || tmp_to_mm.substr(1,1) > '9') {
          invalid_period2 = 1;
        }

        if (isNaN(tmp_to_mm)) {
          invalid_period2 = 1;
        }
        else {
          tmp_to_mm2 = parseInt(tmp_to_mm,10);
          if (tmp_to_mm2 < 1 || tmp_to_mm2 > 12) {
            invalid_period2 = 1;
          }
        }
      }

      if (tmp_to_yyyy != '') {
        if (tmp_to_yyyy.length > 4) {
          invalid_period2 = 1;
        }

        if (tmp_to_yyyy.substr(0,1) < '0' || tmp_to_yyyy.substr(0,1) > '9') {
          invalid_period2 = 1;
        }
        if (tmp_to_yyyy.substr(1,1) < '0' || tmp_to_yyyy.substr(1,1) > '9') {
          invalid_period2 = 1;
        }
        if (tmp_to_yyyy.substr(2,1) < '0' || tmp_to_yyyy.substr(2,1) > '9') {
          invalid_period2 = 1;
        }
        if (tmp_to_yyyy.substr(3,1) < '0' || tmp_to_yyyy.substr(3,1) > '9') {
          invalid_period2 = 1;
        }

        if (isNaN(tmp_to_yyyy)) {
          invalid_period2 = 1;
        }
        else {
          tmp_to_yyyy2 = parseInt(tmp_to_yyyy,10);
          if (tmp_to_yyyy2 < 1950 || tmp_to_yyyy2 > cur_yy) {
            invalid_period2 = 1;
          }
        }
      }

      if (temp_fm != '') {
        tmp_fm_mm = temp_fm.substr(0,2);
        tmp_fm_yyyy = temp_fm.substr(3,temp_fm.length - 3);
        if (!isNaN(tmp_fm_mm) && !isNaN(tmp_fm_yyyy) && !isNaN(tmp_to_mm) && !isNaN(tmp_to_yyyy)) {
          tmp_fm_mm2 = parseInt(tmp_fm_mm,10);
          tmp_fm_yyyy2 = parseInt(tmp_fm_yyyy,10);
          tmp_to_mm2 = parseInt(tmp_to_mm,10);
          tmp_to_yyyy2 = parseInt(tmp_to_yyyy,10);
          if ((tmp_fm_yyyy2 > tmp_to_yyyy2) || (tmp_fm_yyyy2 == tmp_to_yyyy2 && tmp_fm_mm2 > tmp_to_mm2)) {
            invalid_period2 = 1;
          }
        }
      }
    }
  }

  if (tempobj.name=="col_37" && invalid_period2 == 1) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>年 份 不 正 確 (工 作 經 驗)</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid year (Work Experience)</strong></td></tr>";
    }
  }
}

if (is_save == 0 && form_ty == '4') {

  today2 = new Date();
  cur_yy = today2.getFullYear();

  if (tempobj.name=="col_1" || tempobj.name=="col_5" || tempobj.name=="col_9" || tempobj.name=="col_13" || tempobj.name=="col_17") {
    temp_fm = tempobj.value;

    if (temp_fm != '') {
      tmp_fm_mm = temp_fm.substr(0,2);
      tmp_fm_sep = temp_fm.substr(2,1);
      tmp_fm_yyyy = temp_fm.substr(3,temp_fm.length - 3);

      if (tmp_fm_mm == '' || tmp_fm_sep != '/' || tmp_fm_yyyy == '') {
        invalid_period1 = 1;
      }

      if (tmp_fm_mm != '') {
        if (tmp_fm_mm.substr(0,1) < '0' || tmp_fm_mm.substr(0,1) > '9') {
          invalid_period1 = 1;
        }
        if (tmp_fm_mm.substr(1,1) < '0' || tmp_fm_mm.substr(1,1) > '9') {
          invalid_period1 = 1;
        }

        if (isNaN(tmp_fm_mm)) {
          invalid_period1 = 1;
        }
        else {
          tmp_fm_mm2 = parseInt(tmp_fm_mm,10);
          if (tmp_fm_mm2 < 1 || tmp_fm_mm2 > 12) {
            invalid_period1 = 1;
          }
        }
      }

      if (tmp_fm_yyyy != '') {
        if (tmp_fm_yyyy.length > 4) {
          invalid_period1 = 1;
        }

        if (tmp_fm_yyyy.substr(0,1) < '0' || tmp_fm_yyyy.substr(0,1) > '9') {
          invalid_period1 = 1;
        }
        if (tmp_fm_yyyy.substr(1,1) < '0' || tmp_fm_yyyy.substr(1,1) > '9') {
          invalid_period1 = 1;
        }
        if (tmp_fm_yyyy.substr(2,1) < '0' || tmp_fm_yyyy.substr(2,1) > '9') {
          invalid_period1 = 1;
        }
        if (tmp_fm_yyyy.substr(3,1) < '0' || tmp_fm_yyyy.substr(3,1) > '9') {
          invalid_period1 = 1;
        }

        if (isNaN(tmp_fm_yyyy)) {
          invalid_period1 = 1;
        }
        else {
          tmp_fm_yyyy2 = parseInt(tmp_fm_yyyy,10);
          if (tmp_fm_yyyy2 < 1950 || tmp_fm_yyyy2 > cur_yy) {
            invalid_period1 = 1;
          }
        }
      }
    }
  }

  if (tempobj.name=="col_2" || tempobj.name=="col_6" || tempobj.name=="col_10" || tempobj.name=="col_14" || tempobj.name=="col_18") {
    temp_to = tempobj.value;

    if ((temp_fm == '' && temp_to != '') || (temp_fm != '' && temp_to == '')) {
      invalid_period1 = 1;
    }

    if (temp_to != '') {
      tmp_to_mm = temp_to.substr(0,2);
      tmp_to_sep = temp_to.substr(2,1);
      tmp_to_yyyy = temp_to.substr(3,temp_to.length - 3);

      if (tmp_to_mm == '' || tmp_to_sep != '/' || tmp_to_yyyy == '') {
        invalid_period1 = 1;
      }

      if (tmp_to_mm != '') {
        if (tmp_to_mm.substr(0,1) < '0' || tmp_to_mm.substr(0,1) > '9') {
          invalid_period1 = 1;
        }
        if (tmp_to_mm.substr(1,1) < '0' || tmp_to_mm.substr(1,1) > '9') {
          invalid_period1 = 1;
        }

        if (isNaN(tmp_to_mm)) {
          invalid_period1 = 1;
        }
        else {
          tmp_to_mm2 = parseInt(tmp_to_mm,10);
          if (tmp_to_mm2 < 1 || tmp_to_mm2 > 12) {
            invalid_period1 = 1;
          }
        }
      }

      if (tmp_to_yyyy != '') {
        if (tmp_to_yyyy.length > 4) {
          invalid_period1 = 1;
        }

        if (tmp_to_yyyy.substr(0,1) < '0' || tmp_to_yyyy.substr(0,1) > '9') {
          invalid_period1 = 1;
        }
        if (tmp_to_yyyy.substr(1,1) < '0' || tmp_to_yyyy.substr(1,1) > '9') {
          invalid_period1 = 1;
        }
        if (tmp_to_yyyy.substr(2,1) < '0' || tmp_to_yyyy.substr(2,1) > '9') {
          invalid_period1 = 1;
        }
        if (tmp_to_yyyy.substr(3,1) < '0' || tmp_to_yyyy.substr(3,1) > '9') {
          invalid_period1 = 1;
        }

        if (isNaN(tmp_to_yyyy)) {
          invalid_period1 = 1;
        }
        else {
          tmp_to_yyyy2 = parseInt(tmp_to_yyyy,10);
          if (tmp_to_yyyy2 < 1950 || tmp_to_yyyy2 > cur_yy) {
            invalid_period1 = 1;
          }
        }
      }

      if (temp_fm != '') {
        tmp_fm_mm = temp_fm.substr(0,2);
        tmp_fm_yyyy = temp_fm.substr(3,temp_fm.length - 3);
        if (!isNaN(tmp_fm_mm) && !isNaN(tmp_fm_yyyy) && !isNaN(tmp_to_mm) && !isNaN(tmp_to_yyyy)) {
          tmp_fm_mm2 = parseInt(tmp_fm_mm,10);
          tmp_fm_yyyy2 = parseInt(tmp_fm_yyyy,10);
          tmp_to_mm2 = parseInt(tmp_to_mm,10);
          tmp_to_yyyy2 = parseInt(tmp_to_yyyy,10);
          if ((tmp_fm_yyyy2 > tmp_to_yyyy2) || (tmp_fm_yyyy2 == tmp_to_yyyy2 && tmp_fm_mm2 > tmp_to_mm2)) {
            invalid_period1 = 1;
          }
        }
      }
    }
  }

  if (tempobj.name=="col_18" && invalid_period1 == 1) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>年 份 不 正 確 (教 育 程 度)</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid year (Education Level)</strong></td></tr>";
    }
  }

  if (tempobj.name=="col_214" || tempobj.name=="col_219" || tempobj.name=="col_224") {
    temp_fm = tempobj.value;

    if (temp_fm != '') {
      tmp_fm_mm = temp_fm.substr(0,2);
      tmp_fm_sep = temp_fm.substr(2,1);
      tmp_fm_yyyy = temp_fm.substr(3,temp_fm.length - 3);

      if (tmp_fm_mm == '' || tmp_fm_sep != '/' || tmp_fm_yyyy == '') {
        invalid_period2 = 1;
      }

      if (tmp_fm_mm != '') {
        if (tmp_fm_mm.substr(0,1) < '0' || tmp_fm_mm.substr(0,1) > '9') {
          invalid_period2 = 1;
        }
        if (tmp_fm_mm.substr(1,1) < '0' || tmp_fm_mm.substr(1,1) > '9') {
          invalid_period2 = 1;
        }

        if (isNaN(tmp_fm_mm)) {
          invalid_period2 = 1;
        }
        else {
          tmp_fm_mm2 = parseInt(tmp_fm_mm,10);
          if (tmp_fm_mm2 < 1 || tmp_fm_mm2 > 12) {
            invalid_period2 = 1;
          }
        }
      }

      if (tmp_fm_yyyy != '') {
        if (tmp_fm_yyyy.length > 4) {
          invalid_period2 = 1;
        }

        if (tmp_fm_yyyy.substr(0,1) < '0' || tmp_fm_yyyy.substr(0,1) > '9') {
          invalid_period2 = 1;
        }
        if (tmp_fm_yyyy.substr(1,1) < '0' || tmp_fm_yyyy.substr(1,1) > '9') {
          invalid_period2 = 1;
        }
        if (tmp_fm_yyyy.substr(2,1) < '0' || tmp_fm_yyyy.substr(2,1) > '9') {
          invalid_period2 = 1;
        }
        if (tmp_fm_yyyy.substr(3,1) < '0' || tmp_fm_yyyy.substr(3,1) > '9') {
          invalid_period2 = 1;
        }

        if (isNaN(tmp_fm_yyyy)) {
          invalid_period2 = 1;
        }
        else {
          tmp_fm_yyyy2 = parseInt(tmp_fm_yyyy,10);
          if (tmp_fm_yyyy2 < 1950 || tmp_fm_yyyy2 > cur_yy) {
            invalid_period2 = 1;
          }
        }
      }
    }
  }

  if (tempobj.name=="col_215" || tempobj.name=="col_220" || tempobj.name=="col_225") {
    temp_to = tempobj.value;

    if ((temp_fm == '' && temp_to != '') || (temp_fm != '' && temp_to == '')) {
      invalid_period2 = 1;
    }

    if (temp_to != '') {
      tmp_to_mm = temp_to.substr(0,2);
      tmp_to_sep = temp_to.substr(2,1);
      tmp_to_yyyy = temp_to.substr(3,temp_to.length - 3);

      if (tmp_to_mm == '' || tmp_to_sep != '/' || tmp_to_yyyy == '') {
        invalid_period2 = 1;
      }

      if (tmp_to_mm != '') {
        if (tmp_to_mm.substr(0,1) < '0' || tmp_to_mm.substr(0,1) > '9') {
          invalid_period2 = 1;
        }
        if (tmp_to_mm.substr(1,1) < '0' || tmp_to_mm.substr(1,1) > '9') {
          invalid_period2 = 1;
        }

        if (isNaN(tmp_to_mm)) {
          invalid_period2 = 1;
        }
        else {
          tmp_to_mm2 = parseInt(tmp_to_mm,10);
          if (tmp_to_mm2 < 1 || tmp_to_mm2 > 12) {
            invalid_period2 = 1;
          }
        }
      }

      if (tmp_to_yyyy != '') {
        if (tmp_to_yyyy.length > 4) {
          invalid_period2 = 1;
        }

        if (tmp_to_yyyy.substr(0,1) < '0' || tmp_to_yyyy.substr(0,1) > '9') {
          invalid_period2 = 1;
        }
        if (tmp_to_yyyy.substr(1,1) < '0' || tmp_to_yyyy.substr(1,1) > '9') {
          invalid_period2 = 1;
        }
        if (tmp_to_yyyy.substr(2,1) < '0' || tmp_to_yyyy.substr(2,1) > '9') {
          invalid_period2 = 1;
        }
        if (tmp_to_yyyy.substr(3,1) < '0' || tmp_to_yyyy.substr(3,1) > '9') {
          invalid_period2 = 1;
        }

        if (isNaN(tmp_to_yyyy)) {
          invalid_period2 = 1;
        }
        else {
          tmp_to_yyyy2 = parseInt(tmp_to_yyyy,10);
          if (tmp_to_yyyy2 < 1950 || tmp_to_yyyy2 > cur_yy) {
            invalid_period2 = 1;
          }
        }
      }

      if (temp_fm != '') {
        tmp_fm_mm = temp_fm.substr(0,2);
        tmp_fm_yyyy = temp_fm.substr(3,temp_fm.length - 3);
        if (!isNaN(tmp_fm_mm) && !isNaN(tmp_fm_yyyy) && !isNaN(tmp_to_mm) && !isNaN(tmp_to_yyyy)) {
          tmp_fm_mm2 = parseInt(tmp_fm_mm,10);
          tmp_fm_yyyy2 = parseInt(tmp_fm_yyyy,10);
          tmp_to_mm2 = parseInt(tmp_to_mm,10);
          tmp_to_yyyy2 = parseInt(tmp_to_yyyy,10);
          if ((tmp_fm_yyyy2 > tmp_to_yyyy2) || (tmp_fm_yyyy2 == tmp_to_yyyy2 && tmp_fm_mm2 > tmp_to_mm2)) {
            invalid_period2 = 1;
          }
        }
      }
    }
  }

  if (tempobj.name=="col_225" && invalid_period2 == 1) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>年 份 不 正 確 (工 作 經 驗)</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid year (Work Experience)</strong></td></tr>";
    }
  }


  if (tempobj.name=="col_21" || tempobj.name=="col_23" || tempobj.name=="col_25" || tempobj.name=="col_27" || tempobj.name=="col_29"
  || tempobj.name=="col_31" || tempobj.name=="col_33" || tempobj.name=="col_35" || tempobj.name=="col_37" || tempobj.name=="col_39"
  || tempobj.name=="col_41" || tempobj.name=="col_43" || tempobj.name=="col_45" || tempobj.name=="col_47" || tempobj.name=="col_49"
  || tempobj.name=="col_51" || tempobj.name=="col_53" || tempobj.name=="col_55" || tempobj.name=="col_57" || tempobj.name=="col_59"
  || tempobj.name=="col_61" || tempobj.name=="col_63" || tempobj.name=="col_65" || tempobj.name=="col_67" || tempobj.name=="col_69"
  || tempobj.name=="col_71" || tempobj.name=="col_73" || tempobj.name=="col_75" || tempobj.name=="col_77" || tempobj.name=="col_79"
  || tempobj.name=="col_81" || tempobj.name=="col_83" || tempobj.name=="col_85" || tempobj.name=="col_87" || tempobj.name=="col_89"
  || tempobj.name=="col_91" || tempobj.name=="col_93" || tempobj.name=="col_95" || tempobj.name=="col_97" || tempobj.name=="col_99"
  || tempobj.name=="col_101" || tempobj.name=="col_103" || tempobj.name=="col_105" || tempobj.name=="col_107" || tempobj.name=="col_109"
  || tempobj.name=="col_111" || tempobj.name=="col_113" || tempobj.name=="col_115" || tempobj.name=="col_117" || tempobj.name=="col_119"
  || tempobj.name=="col_122" || tempobj.name=="col_124") {

    tmp_grade = tempobj.value;
    tmp_grade = tmp_grade.toUpperCase();
    if (tmp_grade != '') {
      if (tmp_grade != 'A' && tmp_grade != 'B' && tmp_grade != 'C' && tmp_grade != 'D' && tmp_grade != 'E' && tmp_grade != 'F' && tmp_grade != 'G'
      && tmp_grade != 'H' && tmp_grade != 'U' && tmp_grade != 'X' && tmp_grade != 'Y' && tmp_grade != 'Z' 
      && tmp_grade != '1' && tmp_grade != '2' && tmp_grade != '3' && tmp_grade != '4' && tmp_grade != '5') {
        invalid_grade1 = 1;
      }
    }
  }

  if (tempobj.name=="col_126" || tempobj.name=="col_130" || tempobj.name=="col_134" || tempobj.name=="col_138" || tempobj.name=="col_142"
  || tempobj.name=="col_146" || tempobj.name=="col_150" || tempobj.name=="col_154" || tempobj.name=="col_158" || tempobj.name=="col_162"
  || tempobj.name=="col_166" || tempobj.name=="col_170" || tempobj.name=="col_174" || tempobj.name=="col_178" || tempobj.name=="col_182"
  || tempobj.name=="col_186" || tempobj.name=="col_190" || tempobj.name=="col_195") {

    tmp_grade = tempobj.value;
    tmp_grade = tmp_grade.toUpperCase();
    if (tmp_grade != '') {
      if (tmp_grade != 'A' && tmp_grade != 'B' && tmp_grade != 'C' && tmp_grade != 'D' && tmp_grade != 'E' && tmp_grade != 'F' && tmp_grade != 'G'
      && tmp_grade != 'H' && tmp_grade != 'O' && tmp_grade != 'P' && tmp_grade != 'U' && tmp_grade != 'X' && tmp_grade != 'Y' && tmp_grade != 'Z'
      && tmp_grade != '1' && tmp_grade != '2' && tmp_grade != '3' && tmp_grade != '4' && tmp_grade != '5') {
        invalid_grade2 = 1;
      }
    }
  }

  if (tempobj.name=="col_128" || tempobj.name=="col_132" || tempobj.name=="col_136" || tempobj.name=="col_140" || tempobj.name=="col_144"
  || tempobj.name=="col_148" || tempobj.name=="col_152" || tempobj.name=="col_156" || tempobj.name=="col_160" || tempobj.name=="col_164"
  || tempobj.name=="col_168" || tempobj.name=="col_172" || tempobj.name=="col_176" || tempobj.name=="col_180" || tempobj.name=="col_184"
  || tempobj.name=="col_188" || tempobj.name=="col_192" || tempobj.name=="col_197") {

    tmp_grade = tempobj.value;
    tmp_grade = tmp_grade.toUpperCase();
    if (tmp_grade != '') {
      if (tmp_grade != 'A' && tmp_grade != 'B' && tmp_grade != 'C' && tmp_grade != 'D' && tmp_grade != 'E' && tmp_grade != 'F' && tmp_grade != 'U'
      && tmp_grade != 'X' && tmp_grade != 'Y' && tmp_grade != 'Z'
      && tmp_grade != '1' && tmp_grade != '2' && tmp_grade != '3' && tmp_grade != '4' && tmp_grade != '5') {
        invalid_grade3 = 1;
      }
    }
  }

  if (tempobj.name=="col_124" && invalid_grade1 == 1) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>等 級 不 正 確 (香 港 中 學 會 考)</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid grade (HKCEE)</strong></td></tr>";
    }
  }

  if (tempobj.name=="col_195" && invalid_grade2 == 1) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>等 級 不 正 確 (香 港 高 級 程 度 會 考)</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid grade (HKALE)</strong></td></tr>";
    }
  }

  if (tempobj.name=="col_197" && invalid_grade3 == 1) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>等 級 不 正 確 (香 ?? 高 級 補 充 程 度 會 考)</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid grade (HKASLE)</strong></td></tr>";
    }
  }

  if (tempobj.name=="col_22" || tempobj.name=="col_24" || tempobj.name=="col_26" || tempobj.name=="col_28" || tempobj.name=="col_30"
  || tempobj.name=="col_32" || tempobj.name=="col_34" || tempobj.name=="col_36" || tempobj.name=="col_38" || tempobj.name=="col_40"
  || tempobj.name=="col_42" || tempobj.name=="col_44" || tempobj.name=="col_46" || tempobj.name=="col_48" || tempobj.name=="col_50"
  || tempobj.name=="col_52" || tempobj.name=="col_54" || tempobj.name=="col_56" || tempobj.name=="col_58" || tempobj.name=="col_60"
  || tempobj.name=="col_62" || tempobj.name=="col_64" || tempobj.name=="col_66" || tempobj.name=="col_68" || tempobj.name=="col_70"
  || tempobj.name=="col_72" || tempobj.name=="col_74" || tempobj.name=="col_76" || tempobj.name=="col_78" || tempobj.name=="col_80"
  || tempobj.name=="col_82" || tempobj.name=="col_84" || tempobj.name=="col_86" || tempobj.name=="col_88" || tempobj.name=="col_90"
  || tempobj.name=="col_92" || tempobj.name=="col_94" || tempobj.name=="col_96" || tempobj.name=="col_98" || tempobj.name=="col_100"
  || tempobj.name=="col_102" || tempobj.name=="col_104" || tempobj.name=="col_106" || tempobj.name=="col_108" || tempobj.name=="col_110"
  || tempobj.name=="col_112" || tempobj.name=="col_114" || tempobj.name=="col_116" || tempobj.name=="col_118" || tempobj.name=="col_120"
  || tempobj.name=="col_123" || tempobj.name=="col_125") {

    tmp_yyyy = tempobj.value;
    if (tmp_yyyy != '') {

      if (tmp_yyyy.length > 4) {
        invalid_year1 = 1;
      }

      if (tmp_yyyy.substr(0,1) < '0' || tmp_yyyy.substr(0,1) > '9') {
        invalid_year1 = 1;
      }
      if (tmp_yyyy.substr(1,1) < '0' || tmp_yyyy.substr(1,1) > '9') {
        invalid_year1 = 1;
      }
      if (tmp_yyyy.substr(2,1) < '0' || tmp_yyyy.substr(2,1) > '9') {
        invalid_year1 = 1;
      }
      if (tmp_yyyy.substr(3,1) < '0' || tmp_yyyy.substr(3,1) > '9') {
        invalid_year1 = 1;
      }

      if (isNaN(tmp_yyyy)) {
        invalid_year1 = 1;
      }
      else {
        tmp_yyyy2 = parseInt(tmp_yyyy,10);
        if (tmp_yyyy2 < 1950 || tmp_yyyy2 > cur_yy) {
          invalid_year1 = 1;
        }
      }
    }

    if ((tmp_yyyy == '' && tmp_grade != '') || (tmp_yyyy != '' && tmp_grade == '')) {
      empty_grade_year1 = 1;
    }
  }

  if (tempobj.name=="col_127" || tempobj.name=="col_129" || tempobj.name=="col_131" || tempobj.name=="col_133" || tempobj.name=="col_135"
  || tempobj.name=="col_137" || tempobj.name=="col_139" || tempobj.name=="col_141" || tempobj.name=="col_143" || tempobj.name=="col_145"
  || tempobj.name=="col_147" || tempobj.name=="col_149" || tempobj.name=="col_151" || tempobj.name=="col_153" || tempobj.name=="col_155"
  || tempobj.name=="col_157" || tempobj.name=="col_159" || tempobj.name=="col_161" || tempobj.name=="col_163" || tempobj.name=="col_165"
  || tempobj.name=="col_167" || tempobj.name=="col_169" || tempobj.name=="col_171" || tempobj.name=="col_173" || tempobj.name=="col_175"
  || tempobj.name=="col_177" || tempobj.name=="col_179" || tempobj.name=="col_181" || tempobj.name=="col_183" || tempobj.name=="col_185"
  || tempobj.name=="col_187" || tempobj.name=="col_189" || tempobj.name=="col_191" || tempobj.name=="col_193" || tempobj.name=="col_196"
  || tempobj.name=="col_198") {

    tmp_yyyy = tempobj.value;
    if (tmp_yyyy != '') {

      if (tmp_yyyy.length > 4) {
        invalid_year2 = 1;
      }

      if (tmp_yyyy.substr(0,1) < '0' || tmp_yyyy.substr(0,1) > '9') {
        invalid_year2 = 1;
      }
      if (tmp_yyyy.substr(1,1) < '0' || tmp_yyyy.substr(1,1) > '9') {
        invalid_year2 = 1;
      }
      if (tmp_yyyy.substr(2,1) < '0' || tmp_yyyy.substr(2,1) > '9') {
        invalid_year2 = 1;
      }
      if (tmp_yyyy.substr(3,1) < '0' || tmp_yyyy.substr(3,1) > '9') {
        invalid_year2 = 1;
      }

      if (isNaN(tmp_yyyy)) {
        invalid_year2 = 1;
      }
      else {
        tmp_yyyy2 = parseInt(tmp_yyyy,10);
        if (tmp_yyyy2 < 1950 || tmp_yyyy2 > cur_yy) {
          invalid_year2 = 1;
        }
      }
    }

    if ((tmp_yyyy == '' && tmp_grade != '') || (tmp_yyyy != '' && tmp_grade == '')) {
      empty_grade_year2 = 1;
    }
  }

  if (tempobj.name=="col_199" || tempobj.name=="col_202" || tempobj.name=="col_205" || tempobj.name=="col_208" || tempobj.name=="col_211") {

    tmp_yyyy = tempobj.value;
    if (tmp_yyyy != '') {

      if (tmp_yyyy.length > 4) {
        invalid_year3 = 1;
      }

      if (tmp_yyyy.substr(0,1) < '0' || tmp_yyyy.substr(0,1) > '9') {
        invalid_year3 = 1;
      }
      if (tmp_yyyy.substr(1,1) < '0' || tmp_yyyy.substr(1,1) > '9') {
        invalid_year3 = 1;
      }
      if (tmp_yyyy.substr(2,1) < '0' || tmp_yyyy.substr(2,1) > '9') {
        invalid_year3 = 1;
      }
      if (tmp_yyyy.substr(3,1) < '0' || tmp_yyyy.substr(3,1) > '9') {
        invalid_year3 = 1;
      }

      if (isNaN(tmp_yyyy)) {
        invalid_year3 = 1;
      }
      else {
        tmp_yyyy2 = parseInt(tmp_yyyy,10);
        if (tmp_yyyy2 < 1950 || tmp_yyyy2 > cur_yy) {
          invalid_year3 = 1;
        }
      }
    }
  }

  if (tempobj.name=="col_125" && invalid_year1 == 1) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>年 份 不 正 確 (香 港 中 學 會 考)</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid year (HKCEE)</strong></td></tr>";
    }
  }
  if (tempobj.name=="col_125" && invalid_year1 == 0 && empty_grade_year1 == 1) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>等 級 / 年 份 不 能 空 白 (香 港 中 學 會 考)</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Empty grade / year (HKCEE)</strong></td></tr>";
    }
  }

  if (tempobj.name=="col_198" && invalid_year2 == 1) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>年 份 不 正 確 (香 港 高 級 程 度 會 考)</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid year (HKALE)</strong></td></tr>";
    }
  }
  if (tempobj.name=="col_198" && invalid_year2 == 0 && empty_grade_year2 == 1) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>等 級 / 年 份 不 能 空 白 (香 港 高 級 程 度 會 考)</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Empty grade / year (HKALE)</strong></td></tr>";
    }
  }

  if (tempobj.name=="col_211" && invalid_year3 == 1) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>年 份 不 正 確 (其 他 公 開 考 試)</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid year (Other Public Examination)</strong></td></tr>";
    }
  }
}

if ((tempobj.name=="pay_ty") && tempobj.type!="radio") {
pay_ty = tempobj.value;
}

if ((tempobj.name=="pay_ty") && tempobj.type=="radio" && tempobj.checked) {
pay_ty = tempobj.value;
}

chk_payment = 0;
if (form_ty!='2') {
  chk_payment = 1;
}
if (form_ty=='2' && (v_app_fee_amt > 0 || pay_ty !='')) {
  chk_payment = 1;
}

if ((tempobj.name=="pay_ty") && tempobj.value=='WM' && pay_ty =='' && chk_payment==1) {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>信 用 卡 類 型 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Credit Card Type</strong></td></tr>";
  }
}

if (tempobj.name=="pay_ref_1") {
if (tempobj.value!='' && !isNaN(tempobj.value)) {
pay_ref_1 = tempobj.value;
  }
else {
pay_ref_1 = "";
  }
}

if (tempobj.name=="pay_ref_2") {
if (tempobj.value!='' && !isNaN(tempobj.value)) {
pay_ref_2 = tempobj.value;
  }
else {
pay_ref_2 = "";
  }
}

if (tempobj.name=="pay_ref_3") {
if (tempobj.value!='' && !isNaN(tempobj.value)) {
pay_ref_3 = tempobj.value;
  }
else {
pay_ref_3 = "";
  }
}

if (tempobj.name=="pay_ref_4") {
  if (tempobj.value!='' && !isNaN(tempobj.value)) {
    pay_ref_4 = tempobj.value;
  }
  else {
    pay_ref_4 = "";
  }

  tmp_pay_ref = pay_ref_1 + pay_ref_2 + pay_ref_3 + pay_ref_4;

//pass=false;
//messagetext = messagetext + "card_no =" + tmp_pay_ref + "<br>";

  if (chk_payment==1) {
   if (tmp_pay_ref == '') {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>信 用 卡 號 碼 不 正 確 (或 信 用 卡 類 型 不 正 確)</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Card No. (or Invalid Credit Card Type)</strong></td></tr>";
    }
   }
   else {
    // checking check digital
    if (!check_cardno(tmp_pay_ref,pay_ty)) {
      pass=false;
      if (disp == 'ch') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>信 用 卡 號 碼 不 正 確 (或 信 用 卡 類 型 不 正 確)</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Card No. (or Invalid Credit Card Type)</strong></td></tr>";
      }
    }
   }
  }
}

if ((tempobj.name=="card_bank") && tempobj.value=='' && chk_payment==1) {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>發 卡 銀 行 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Card Issuing Bank</strong></td></tr>";
  }
}

if (tempobj.name=="card_holder" && chk_payment==1) {

//messagetext = messagetext + "student name = " + surname + ' ' + forename + "<br>";

  if (tempobj.value=='') {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>持 卡 人 姓 名 不 能 空 白</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Card Holder's Name</strong></td></tr>";
    }
  }
  else {
    temp2 = tempobj.value;
    temp3 = surname + forename;
    temp4 = forename + surname;

    temp2 = temp2.toUpperCase();
    temp3 = temp3.toUpperCase();
    temp4 = temp4.toUpperCase();

    temp5 = "";
    temp6 = "";
    temp7 = "";

    index1=0;
    while (index1 <= temp2.length) {
      tmp_ch = temp2.charCodeAt(index1);
      if (tmp_ch != 32) {
        temp5 = temp5 + temp2.charAt(index1);
      }
      index1++;
    }

    index1=0;
    while (index1 <= temp3.length) {
      tmp_ch = temp3.charCodeAt(index1);
      if (tmp_ch != 32) {
        temp6 = temp6 + temp3.charAt(index1);
      }
      index1++;
    }

    index1=0;
    while (index1 <= temp4.length) {
      tmp_ch = temp4.charCodeAt(index1);
      if (tmp_ch != 32) {
        temp7 = temp7 + temp4.charAt(index1);
      }
      index1++;
    }

//    messagetext = messagetext + "temp4=" + temp4 + "<br>";
//    messagetext = messagetext + "temp5=" + temp5 + "<br>";


    //if (temp5 != temp6 && temp5 != temp7) {
    //  pass=false;
    //  if (disp == 'ch') {
    //    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>持 卡 人 姓 名 與 學 生 姓 名 ( 英 文 ) 不 符</strong></td></tr>";
    //  }
    //  else {
    //    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Card Holder's Name does not match Student Name ( English )</strong></td></tr>";
    //  }
    //}
  }
}


if (tempobj.name=="mm_card_expiry") {
if (tempobj.value!='' && !isNaN(tempobj.value)) {
tmp_mm_expiry = tempobj.value;
  }
else {
tmp_mm_expiry = "";
  }
}

if (tempobj.name=="yy_card_expiry" && chk_payment==1) {
  if (tempobj.value!='' && !isNaN(tempobj.value)) {
    tmp_yy_expiry = tempobj.value;
  }
  else {
    tmp_yy_expiry = "";
  }

  if (tmp_mm_expiry == '' || isNaN(tmp_mm_expiry) || tmp_yy_expiry == '' || isNaN(tmp_yy_expiry)) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>有 效 日 期 不 正 確</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Expiry Date</strong></td></tr>";
    }
  }
  else {
    mm = parseInt(tmp_mm_expiry,10);
    yyyy = 2000 + parseInt(tmp_yy_expiry,10);

    if ((mm < 1 || mm > 12)) {
      pass=false;
      if (disp == 'ch') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>有 效 日 期 不 正 確</strong></td><tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Expiry Date</strong></td></tr>";
      }
    }
    else {
      today = new Date();

//      messagetext = messagetext + "today = " + today + "<br>";
//      messagetext = messagetext + "year = " + today.getFullYear() + "<br>";
//      messagetext = messagetext + "mm = " + today.getMonth() + "<br>";

      if ((yyyy < today.getFullYear()) || (yyyy == today.getFullYear() && (mm - 1) < today.getMonth()) ) {
        pass=false;
        if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>有 效 日 期 不 正 確</strong></td></tr>";
        }
        else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Expiry Date</strong></td></tr>";
        }
      }
    }
  } 
}

if ((tempobj.name=="col_1") && (!tempobj.checked) && form_ty =='1') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 丁 部 以 示 同 意 網 上 申 請 之 聲 明</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please click the checkbox in Part D for consent of declaration</strong></td></tr>";
  }
}

if ((tempobj.name=="col_36") && (!tempobj.checked) && form_ty =='3') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 戊 部 以 示 同 意 網 上 申 請 之 聲 明</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please click the checkbox in Part E for consent of declaration</strong></td></tr>";
  }
}



//  if (tempobj.name=="col_63") {
//  messagetext = messagetext + 'form_ty=[' + form_ty + ']<br>'
//  messagetext = messagetext + 'col_63=[' + tempobj.value + ']<br>'
//  messagetext = messagetext + 'checked = [' + tempobj.checked + ']<br>'
//  }


if ((tempobj.name=="col_73") && (!tempobj.checked) && form_ty =='2') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 己 部 以 示 同 意 網 上 申 請 之 聲 明</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please click the checkbox in Part F for consent of declaration</strong></td></tr>";
  }
}

if ((tempobj.name=="col_233") && (!tempobj.checked) && form_ty =='4') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 X 部 以 示 同 意 網 上 申 請 之 聲 明</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please click the checkbox in Part X for consent of declaration</strong></td></tr>";
  }
}


   }
}
if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUpperCase();

if (messagetext != '') {
messagetext = "<strong><table class='text01a'>" + messagetext + "</table></strong>"
}


if ( typeof(document.getElementById("hints").innerHTML) != 'undefined' ) {
document.getElementById("hints").innerHTML = messagetext;
}
else {
document.getElementById("hints").document.open();
document.getElementById("hints").document.write(messagetext);
document.getElementById("hints").document.close();
}

document.body.scrollTop = 0;

if (disp == 'ch') {
alert("Please see the error message at the right-hand side.")
}
else {
alert("Please see the error message at the right-hand side.")
}

return false;
}
else
return true;
}

function reset_enrol(which,cno,disp) {

messagetext="";

if ( typeof(document.getElementById("hints").innerHTML) != 'undefined' ) {
document.getElementById("hints").innerHTML = messagetext;
}
else {
document.getElementById("hints").document.open();
document.getElementById("hints").document.write(messagetext);
document.getElementById("hints").document.close();
}

document.body.scrollTop = 0;

}

function check_upload(which,disp) {
var pass=true;
messagetext="";
is_hkid = "";
surname = "";
forename = "";
file1 = "";
file2 = "";
file3 = "";
file4 = "";
file5 = "";
file6 = "";
file7 = "";
file8 = "";
file9 = "";
file10 = "";
file11 = "";
file12 = "";
dup_file = 0;
id_no = "";
id_country_cd = "";


if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];

if (tempobj.name=="id_no") {
  if (tempobj.value=='') {
    pass=false;
    if (disp == 'ch') {
      if (is_hkid == 'Y') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>香 港 身 份 證 號 碼 不 能 空 白</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>護 照 號 碼 不 能 空 白</strong></td></tr>";
      }
    }
    else {
      if (is_hkid == 'Y') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in HKID No.</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Passport No.</strong></td></tr>";
      }
    }
  }
  else {
    if (is_hkid == 'Y') {
      if (!(check_hkid(tempobj.value))) {
        pass=false;
        if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>香 港 身 份 證 號 碼 不 正 確</strong></td></tr>";
        }
        else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid HKID No.</strong></td></tr>";
        }
      }
    }
  }
}

if (tempobj.name=="is_hkid" && tempobj.checked) {
   is_hkid = tempobj.value;

   if (is_hkid == 'Y') {
      if (!(check_hkid(id_no))) {
        pass=false;
        if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>香 港 身 份 證 號 碼 不 正 確</strong></td></tr>";
        }
        else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid HKID No.</strong></td></tr>";
        }
      }
    }
}

if (tempobj.name=="surname") {
surname = tempobj.value;
}

if (tempobj.name=="forename") {
forename = tempobj.value;
}

if (tempobj.name=="id_no") {
id_no = tempobj.value;
}

if (tempobj.name=="id_country_cd") {
id_country_cd = tempobj.value;
}

if (tempobj.name=="file_1") {
file1 = tempobj.value;
}

if (tempobj.name=="file_2") {
file2 = tempobj.value;
}

if (tempobj.name=="file_3") {
file3 = tempobj.value;
}

if (tempobj.name=="file_4") {
file4 = tempobj.value;
}

if (tempobj.name=="file_5") {
file5 = tempobj.value;
}

if (tempobj.name=="file_6") {
file6 = tempobj.value;
}

if (tempobj.name=="file_7") {
file7 = tempobj.value;
}

if (tempobj.name=="file_8") {
file8 = tempobj.value;
}

if (tempobj.name=="file_9") {
file9 = tempobj.value;
}

if (tempobj.name=="file_10") {
file10 = tempobj.value;
}

if (tempobj.name=="file_11") {
file11 = tempobj.value;
}

if (tempobj.name=="file_12") {
file12 = tempobj.value;
}

if (tempobj.name=="file_10")  {

  if (file1 != '' && dup_file == 0) {
    if (file1 == file2 || file1 == file3 || file1 == file4 || file1 == file5 || file1 == file6 || file1 == file7 || file1 == file8 || file1 == file9 || file1 == file10 || file1 == file11 || file1 == file12) {
      dup_file = 1;
    }
  }

  if (file2 != '' && dup_file == 0) {
    if (file2 == file1 || file2 == file3 || file2 == file4 || file2 == file5 || file2 == file6 || file2 == file7 || file2 == file8 || file2 == file9 || file2 == file10 || file2 == file11 || file2 == file12) {
      dup_file = 1;
    }
  }

  if (file3 != '' && dup_file == 0) {
    if (file3 == file1 || file3 == file2 || file3 == file4 || file3 == file5 || file3 == file6 || file3 == file7 || file3 == file8 || file3 == file9 || file3 == file10 || file3 == file11 || file3 == file12) {
      dup_file = 1;
    }
  }

  if (file4 != '' && dup_file == 0) {
    if (file4 == file1 || file4 == file2 || file4 == file3 || file4 == file5 || file4 == file6 || file4 == file7 || file4 == file8 || file4 == file9 || file4 == file10 || file4 == file11 || file4 == file12) {
      dup_file = 1;
    }
  }

  if (file5 != '' && dup_file == 0) {
    if (file5 == file1 || file5 == file2 || file5 == file3 || file5 == file4 || file5 == file6 || file5 == file7 || file5 == file8 || file5 == file9 || file5 == file10 || file5 == file11 || file5 == file12) {
      dup_file = 1;
    }
  }

  if (file6 != '' && dup_file == 0) {
    if (file6 == file1 || file6 == file2 || file6 == file3 || file6 == file4 || file6 == file5 || file6 == file7 || file6 == file8 || file6 == file9 || file6 == file10 || file6 == file11 || file6 == file12) {
      dup_file = 1;
    }
  }

  if (file7 != '' && dup_file == 0) {
    if (file7 == file1 || file7 == file2 || file7 == file3 || file7 == file4 || file7 == file5 || file7 == file6 || file7 == file8 || file7 == file9 || file7 == file10 || file7 == file11 || file7 == file12) {
      dup_file = 1;
    }
  }

  if (file8 != '' && dup_file == 0) {
    if (file8 == file1 || file8 == file2 || file8 == file3 || file8 == file4 || file8 == file5 || file8 == file6 || file8 == file7 || file8 == file9 || file8 == file10 || file8 == file11 || file8 == file12) {
      dup_file = 1;
    }
  }

  if (file9 != '' && dup_file == 0) {
    if (file9 == file1 || file9 == file2 || file9 == file3 || file9 == file4 || file9 == file5 || file9 == file6 || file9 == file7 || file9 == file8 || file9 == file10 || file9 == file11 || file9 == file12) {
      dup_file = 1;
    }
  }

  if (file10 != '' && dup_file == 0) {
    if (file10 == file1 || file10 == file2 || file10 == file3 || file10 == file4 || file10 == file5 || file10 == file6 || file10 == file7 || file10 == file8 || file10 == file9 || file10 == file11 || file10 == file12) {
      dup_file = 1;
    }
  }

  if (file11 != '' && dup_file == 0) {
    if (file11 == file1 || file11 == file2 || file11 == file3 || file11 == file4 || file11 == file5 || file11 == file6 || file11 == file7 || file11 == file8 || file11 == file9 || file11 == file10 || file11 == file12) {
      dup_file = 1;
    }
  }

  if (file12 != '' && dup_file == 0) {
    if (file12 == file1 || file12 == file2 || file12 == file3 || file12 == file4 || file12 == file5 || file12 == file6 || file12 == file7 || file12 == file8 || file12 == file9 || file12 == file10 || file12 == file11) {
      dup_file = 1;
    }
  }

  if (dup_file == 1) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>有 些 上 載 檔 是 重 複 的</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Some attachment are duplicated</strong></td></tr>";
    }
  }
}

if (tempobj.name=="id_country_cd") {
  if (is_hkid == 'Y') {
    if (tempobj.value != '' && tempobj.value != 'HK') {
      pass=false;
      if (disp == 'ch') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 留 空 簽 發 國 家 （ 持 香 港 身 份 證 人 士 ）</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please leave 'Issuing Country' blank (for HKID holders)</strong></td></tr>";
      }
    }
  }
  else {
    if (tempobj.value == '') {
      pass=false;
      if (disp == 'ch') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 上 簽 發 國 家 （ 持 護 照 人 士 ）</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 'Issuing Country' (for passport holders)</strong></td></tr>";
      }
    }
  }
}

if ((tempobj.name=="enrol_id") && tempobj.value=='') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>網 上 報 名 編 號 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Enrolment Reference Number</strong></td></tr>";
  }
}

if ((tempobj.name=="course_no") && tempobj.value=='') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>課 程 編 號 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Programme Code</strong></td></tr>";
  }
}

if ((tempobj.name=="surname") && tempobj.value=='') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>姓 氏 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Surname</strong></td></tr>";
  }
}

if ((tempobj.name=="forename") && tempobj.value=='') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>名 字 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in First Name</strong></td></tr>";
  }
}

   }
}
if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUpperCase();

if (messagetext != '') {
messagetext = "<strong><table class='text01'>" + messagetext + "</table></strong>"
}

if ( typeof(document.getElementById("hints").innerHTML) != 'undefined' ) {
document.getElementById("hints").innerHTML = messagetext;
}
else {
document.getElementById("hints").document.open();
document.getElementById("hints").document.write(messagetext);
document.getElementById("hints").document.close();
}

document.body.scrollTop = 0;

if (disp == 'ch') {
alert("Please see the error message at the right-hand side.")
}
else {
alert("Please see the error message at the right-hand side.")
}

return false;
}
else
return true;
}

function reset_upload(which,disp) {

messagetext="";

if ( typeof(document.getElementById("hints").innerHTML) != 'undefined' ) {
document.getElementById("hints").innerHTML = messagetext;
}
else {
document.getElementById("hints").document.open();
document.getElementById("hints").document.write(messagetext);
document.getElementById("hints").document.close();
}

document.body.scrollTop = 0;

}

function wait(msg,disp) {

messagetext=msg;

if (document.all) {
document.getElementById("wait_section").innerHTML = messagetext;
}
else {
document.layers["wait_section"].document.open();
document.layers["wait_section"].document.write(messagetext);
document.layers["wait_section"].document.close();
}

}

function check_status_enquiry(which,disp) {
var pass=true;
messagetext="";
enrol_id = "";
course_no = "";
dd = 0;
mm = 0;
tmp_dd_dob = "";
tmp_mm_dob = "";
term = "";
course_cd = "";
class_cd = "";

if (document.images) {

for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];


if ((tempobj.name=="enrol_id") && tempobj.value=='') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>網 上 報 名 編 號 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Enrolment Reference Number</strong></td></tr>";
  }
}

if (tempobj.name=="term") {
  term = tempobj.value;
}

if (tempobj.name=="course_cd") {
  course_cd = tempobj.value;
}

if (tempobj.name=="class_cd") {
  class_cd = tempobj.value;

  if (term == '' || course_cd == '' || class_cd == '') {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>課 程 編 號 不 能 空 白</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Programme / Course Code</strong></td></tr>";
    }
  }
}


if ((tempobj.name=="id_no") && tempobj.value=='') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>護 照 / 香 港 身 份 證 號 碼 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Passport / HKID No.</strong></td></tr>";
  }
}

if (tempobj.name=="dd_dob") {
if (tempobj.value!='' && !isNaN(tempobj.value)) {
tmp_dd_dob = tempobj.value;
  }
else {
tmp_dd_dob = "";
  }
}

if (tempobj.name=="mm_dob") {
  if (tempobj.value!='' && !isNaN(tempobj.value)) {
    tmp_mm_dob = tempobj.value;
  }
  else {
    tmp_mm_dob = "";
  }

  if (tmp_dd_dob == '' || isNaN(tmp_dd_dob) || tmp_mm_dob == '' || isNaN(tmp_mm_dob)) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>出 生 日 期 不 是 有 效 的 日 期</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Date of Birth</strong></td></tr>";
    }
  }
  else {
    dd = parseInt(tmp_dd_dob,10);
    mm = parseInt(tmp_mm_dob,10);

    monarr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

    // unknown year
    monarr[1] = "29";

    if ((mm < 1 || mm > 12) || (dd < 1 || dd > monarr[mm - 1]) ) {
      pass=false;
      if (disp == 'ch') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>出 生 日 期 不 是 有 效 的 日 期</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Date of Birth</strong></td></tr>";
      }
    }
  }
}


   }
}


if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUpperCase();

if (messagetext != '') {
messagetext = "<strong><table width='100%' class='text01'>" + messagetext + "</table></strong>"
}

if ( typeof(document.getElementById("hints").innerHTML) != 'undefined' ) {
document.getElementById("hints").innerHTML = messagetext;
}
else {
document.getElementById("hints").document.open();
document.getElementById("hints").document.write(messagetext);
document.getElementById("hints").document.close();
}

document.body.scrollTop = 0;

if (disp == 'ch') {
alert("Please see the error message at the right-hand side.")
}
else {
alert("Please see the error message at the right-hand side.")
}

return false;
}
else
return true;
}

function check_status_enquiry2(which,disp) {
var pass=true;
messagetext="";
enrol_id = "";
course_no = "";
dd = 0;
mm = 0;
tmp_dd_dob = "";
tmp_mm_dob = "";
term = "";
course_cd = "";
class_cd = "";

if (document.images) {

for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];

//if ((tempobj.name=="reg_no") && tempobj.value=='') {
//pass=false;
//if (disp == 'ch') {
//messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>報 名 編 號 不 能 空 白</strong></td></tr>";
//  }
//else {
//messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Registration Number</strong></td></tr>";
//  }
//}

if (tempobj.name=="term") {
  term = tempobj.value;
}

if (tempobj.name=="course_cd") {
  course_cd = tempobj.value;
}

if (tempobj.name=="class_cd") {
  class_cd = tempobj.value;

  if (term == '' || course_cd == '' || class_cd == '') {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>課 程 編 號 不 能 空 白</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Programme / Course Code</strong></td></tr>";
    }
  }
}


if ((tempobj.name=="id_no") && tempobj.value=='') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>護 照 / 香 港 身 份 證 號 碼 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Passport / HKID No.</strong></td></tr>";
  }
}

if (tempobj.name=="dd_dob") {
if (tempobj.value!='' && !isNaN(tempobj.value)) {
tmp_dd_dob = tempobj.value;
  }
else {
tmp_dd_dob = "";
  }
}

if (tempobj.name=="mm_dob") {
  if (tempobj.value!='' && !isNaN(tempobj.value)) {
    tmp_mm_dob = tempobj.value;
  }
  else {
    tmp_mm_dob = "";
  }

  if (tmp_dd_dob == '' || isNaN(tmp_dd_dob) || tmp_mm_dob == '' || isNaN(tmp_mm_dob)) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>出 生 日 期 不 是 有 效 的 日 期</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Date of Birth</strong></td></tr>";
    }
  }
  else {
    dd = parseInt(tmp_dd_dob,10);
    mm = parseInt(tmp_mm_dob,10);

    monarr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

    // unknown year
    monarr[1] = "29";

    if ((mm < 1 || mm > 12) || (dd < 1 || dd > monarr[mm - 1]) ) {
      pass=false;
      if (disp == 'ch') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>出 生 日 期 不 是 有 效 的 日 期</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Date of Birth</strong></td></tr>";
      }
    }
  }
}


   }
}


if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUpperCase();

if (messagetext != '') {
messagetext = "<strong><table width='100%' class='text01'>" + messagetext + "</table></strong>"
}

if ( typeof(document.getElementById("hints").innerHTML) != 'undefined' ) {
document.getElementById("hints").innerHTML = messagetext;
}
else {
document.getElementById("hints").document.open();
document.getElementById("hints").document.write(messagetext);
document.getElementById("hints").document.close();
}

document.body.scrollTop = 0;

if (disp == 'ch') {
alert("Please see the error message at the right-hand side.")
}
else {
alert("Please see the error message at the right-hand side.")
}

return false;
}
else
return true;
}

function check_status_enquiry3(which,disp) {
var pass=true;
messagetext="";
enrol_id = "";
course_no = "";
dd = 0;
mm = 0;
tmp_dd_dob = "";
tmp_mm_dob = "";
term = "";
course_cd = "";
class_cd = "";

if (document.images) {

for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];


if ((tempobj.name=="enrol_id") && tempobj.value=='') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>網 上 報 名 編 號 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Enrolment Reference Number</strong></td></tr>";
  }
}

if ((tempobj.name=="auth_no") && tempobj.value=='') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>認 證 號 碼 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Authorisation No.</strong></td></tr>";
  }
}

if (tempobj.name=="dd_dob") {
if (tempobj.value!='' && !isNaN(tempobj.value)) {
tmp_dd_dob = tempobj.value;
  }
else {
tmp_dd_dob = "";
  }
}

if (tempobj.name=="mm_dob") {
  if (tempobj.value!='' && !isNaN(tempobj.value)) {
    tmp_mm_dob = tempobj.value;
  }
  else {
    tmp_mm_dob = "";
  }

  if (tmp_dd_dob == '' || isNaN(tmp_dd_dob) || tmp_mm_dob == '' || isNaN(tmp_mm_dob)) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>出 生 日 期 不 是 有 效 的 日 期</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Date of Birth</strong></td></tr>";
    }
  }
  else {
    dd = parseInt(tmp_dd_dob,10);
    mm = parseInt(tmp_mm_dob,10);

    monarr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

    // unknown year
    monarr[1] = "29";

    if ((mm < 1 || mm > 12) || (dd < 1 || dd > monarr[mm - 1]) ) {
      pass=false;
      if (disp == 'ch') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>出 生 日 期 不 是 有 效 的 日 期</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Date of Birth</strong></td></tr>";
      }
    }
  }
}


   }
}


if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUpperCase();

if (messagetext != '') {
messagetext = "<strong><table width='100%' class='text01'>" + messagetext + "</table></strong>"
}

if ( typeof(document.getElementById("hints").innerHTML) != 'undefined' ) {
document.getElementById("hints").innerHTML = messagetext;
}
else {
document.getElementById("hints").document.open();
document.getElementById("hints").document.write(messagetext);
document.getElementById("hints").document.close();
}

document.body.scrollTop = 0;

if (disp == 'ch') {
alert("Please see the error message at the right-hand side.")
}
else {
alert("Please see the error message at the right-hand side.")
}

return false;
}
else
return true;
}

function chk_form1(which,disp,skip_chk) {
var pass=true;
messagetext="";
tmp_dd_dob = "";
tmp_mm_dob = "";
tmp_yyyy_dob = "";
dd = 0;
mm = 0;
yyyy = 0;
title_cd = "";
form_ty = "";
reg_no = "";
is_hkid = "";
surname = "";
forename = "";
id_no = "";
id_country_cd = "";
nation_cd = "";
occup_cd = "";
edu_lvl_cd = "";
submit = "";
disc_ty = "";
disc_enrol = "";
email = "";
email2 = "";

if (document.images) {

for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];

if (tempobj.name=="id_no") {
  if (tempobj.value=='') {
    pass=false;
    if (disp == 'ch') {
      if (is_hkid == 'Y') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>香 港 身 份 證 號 碼 不 能 空 白</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>護 照 號 碼 不 能 空 白</strong></td></tr>";
      }
    }
    else {
      if (is_hkid == 'Y') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in HKID No.</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Passport No.</strong></td></tr>";
      }
    }
  }
  else {
    if (is_hkid == 'Y') {
      if (!(check_hkid(tempobj.value))) {
        pass=false;
        if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>香 港 身 份 證 號 碼 不 正 確</strong></td></tr>";
        }
        else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid HKID No.</strong></td></tr>";
        }
      }
    }
  }
}

if (tempobj.name=="is_hkid") {
   is_hkid = tempobj.value;

   if (is_hkid == 'Y') {
      if (!(check_hkid(id_no))) {
        pass=false;
        if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>香 港 身 份 證 號 碼 不 正 確</strong></td></tr>";
        }
        else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid HKID No.</strong></td></tr>";
        }
      }
    }
}

if (tempobj.name=="form_ty") {
form_ty = tempobj.value;
}

if (tempobj.name=="disc_ty") {
disc_ty = tempobj.value;
}

if (tempobj.name=="email") {
email = tempobj.value;
}

if (tempobj.name=="email2") {
email2 = tempobj.value;
}

if (tempobj.name=="reg_no") {
reg_no = tempobj.value;
}

if (tempobj.name=="surname") {
surname = tempobj.value;
}

if (tempobj.name=="forename") {
forename = tempobj.value;
}

if (tempobj.name=="id_no") {
id_no = tempobj.value;
}

if (tempobj.name=="id_country_cd") {
id_country_cd = tempobj.value;
}

if (tempobj.name=="nation_cd") {
nation_cd = tempobj.value;
}

if (tempobj.name=="occup_cd") {
occup_cd = tempobj.value;
}

if (tempobj.name=="edu_lvl_cd") {
edu_lvl_cd = tempobj.value;
}

if ((tempobj.name=="disc_enrol") && tempobj.checked) {
disc_enrol = tempobj.value;
}

if ((tempobj.name=="disc_enrol") && tempobj.type=="hidden") {
disc_enrol = tempobj.value;
}

if ((tempobj.name=="disc_enrol") && (tempobj.value=='N' || tempobj.type=='hidden') && disc_enrol == '') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 選 擇 使 用 / 不 使 用 積 分</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please select use / not use CATS</strong></td></tr>";
  }
}


if ((tempobj.name=="disc_ty") && disc_ty == '') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 選 擇 進 修 積 分 計 劃 學 員 類 別</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please select eligible category of SCS Cash Unit Scheme (CATS)</strong></td></tr>";
  }
}

if (tempobj.name=="id_country_cd") {
  if (is_hkid == 'Y') {
    if (tempobj.value != '' && tempobj.value != 'HK') {
      pass=false;
      if (disp == 'ch') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 留 空 簽 發 國 家 （ 持 香 港 身 份 證 人 士 ）</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please leave 'Issuing Country' blank (for HKID holders)</strong></td></tr>";
      }
    }
  }
  else {
    if (tempobj.value == '') {
      pass=false;
      if (disp == 'ch') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 上 簽 發 國 家 （ 持 護 照 人 士 ）</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 'Issuing Country' (for passport holders)</strong></td></tr>";
      }
    }
  }
}

if (tempobj.name=="id_country_oth_desc") {
  if (id_country_cd != "OTHR" && tempobj.value != '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 留 空 簽 發 國 家 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please leave 'Issuing Country (Others)' blank</strong></td></tr>";
    }
  }
  if (id_country_cd == "OTHR" && tempobj.value == '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 簽 發 國 家 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 'Issuing Country (Others)'</strong></td></tr>";
    }
  }
}

if (tempobj.name=="nation_oth_desc") {
  if (nation_cd != "OTHR" && tempobj.value != '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 留 空 國 籍 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please leave 'Nationality (Others)' blank</strong></td></tr>";
    }
  }
  if (nation_cd == "OTHR" && tempobj.value == '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 國 籍 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 'Nationality (Others)'</strong></td></tr>";
    }
  }
}

if (tempobj.name=="occup_oth_desc") {
  if (occup_cd != "OTHR" && tempobj.value != '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 留 空 職 業 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please leave 'Occupation (Others)' blank</strong></td></tr>";
    }
  }
  if (occup_cd == "OTHR" && tempobj.value == '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 職 業（ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 'Occupation (Others)'</strong></td></tr>";
    }
  }
}

if (tempobj.name=="edu_oth_desc") {
  if (edu_lvl_cd != "OTHR" && tempobj.value != '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 留 空 最 高 教 育 程 度 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please leave 'Highest Education Level Achieved (Others)' blank</strong></td></tr>";
    }
  }
  if (edu_lvl_cd == "OTHR" && tempobj.value == '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 最 高 教 育 程 度 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 'Highest Education Level Achieved (Others)'</strong></td></tr>";
    }
  }
}

if (tempobj.name=="card_bank_oth_desc") {
  if (card_bank != "OTHR" && tempobj.value != '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 留 空 發 卡 銀 行 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please leave 'Card Issuing Bank (Others)' blank</strong></td></tr>";
    }
  }
  if (card_bank == "OTHR" && tempobj.value == '') {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 發 卡 銀 行 （ 其 他 ） 欄</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 'Card Issuing Bank (Others)'</strong></td></tr>";
    }
  }
}

if ((tempobj.name=="surname")&&tempobj.value=='') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>姓 氏 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Surname</strong></td></tr>";
  }
}

if ((tempobj.name=="forename")&&tempobj.value=='') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>名 字 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in First Name</strong></td></tr>";
  }
}

if ((tempobj.name=="title_cd") && tempobj.checked) {
title_cd = tempobj.value;
}

if ((tempobj.name=="title_cd") && tempobj.type=="hidden") {
title_cd = tempobj.value;
}

if ((tempobj.name=="title_cd") && (tempobj.value=='MS' || tempobj.type=='hidden') && title_cd == '') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>稱 謂 不 能 空 白</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Title</strong></td></tr>";
  }
}

//if (tempobj.name=="title_cd") {
//pass=false;
//messagetext = messagetext + "title_cd = " + tempobj.value + "<br>";
//messagetext = messagetext + "title_cd = " + tempobj.checked + "<br>";
//}


if (tempobj.name=="dd_dob") {
if (tempobj.value!='' && !isNaN(tempobj.value)) {
tmp_dd_dob = tempobj.value;
  }
else {
tmp_dd_dob = "";
  }
}


if (tempobj.name=="mm_dob") {
if (tempobj.value!='' && !isNaN(tempobj.value)) {
tmp_mm_dob = tempobj.value;
  }
else {
tmp_mm_dob = "";
  }
}


if (tempobj.name=="yyyy_dob") {
  if (tempobj.value!='' && !isNaN(tempobj.value)) {
    tmp_yyyy_dob = tempobj.value;
  }
  else {
    tmp_yyyy_dob = "";
  }


//messagetext = messagetext + "dd = " + tmp_dd_dob + "<br>";
//messagetext = messagetext + "mm = " + tmp_mm_dob + "<br>";
//messagetext = messagetext + "yyyy = " + tmp_yyyy_dob + "<br>";

  if (tmp_dd_dob == '' || isNaN(tmp_dd_dob) || tmp_mm_dob == '' || isNaN(tmp_mm_dob) || tmp_yyyy_dob == '' || isNaN(tmp_yyyy_dob)) {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>出 生 日 期 不 是 有 效 的 日 期</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Date of Birth</strong></td></tr>";
    }
  }
  else {
    dd = parseInt(tmp_dd_dob,10);
    mm = parseInt(tmp_mm_dob,10);
    yyyy = parseInt(tmp_yyyy_dob,10);


    monarr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

//messagetext = messagetext + "dd = " + dd.toString() + "<br>";
//messagetext = messagetext + "mm = " + mm.toString() + "<br>";
//messagetext = messagetext + "yyyy = " + yyyy.toString() + "<br>";
//messagetext = messagetext + "step 2...<br>";
//messagetext = messagetext + "monarr[3] = " + monarr[mm - 1].toString() + "<br>";


    // check for leap year
    if (((yyyy % 4 == 0) && (yyyy % 100 != 0)) || (yyyy % 400 == 0)) monarr[1] = "29";

    today = new Date();


    cur_yy = today.getFullYear();
    cur_mm = today.getMonth() + 1;
    cur_dd = today.getDate();


    age = cur_yy - yyyy;
    if ((cur_mm < mm) || (cur_mm == mm && cur_dd < dd)) {
      age = age - 1;
    }



    if ((mm < 1 || mm > 12) || (dd < 1 || dd > monarr[mm - 1]) || (yyyy < 1900) || (yyyy > cur_yy) || (yyyy == cur_yy && mm > cur_mm) || (yyyy == cur_yy && mm == cur_mm && dd > cur_dd) || (age > 110)) {
      pass=false;
      if (disp == 'ch') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>出 生 日 期 不 是 有 效 的 日 期</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Date of Birth</strong></td></tr>";
      }
    }
    else {
      if (age < 16) {
        pass=false;
        if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>最 小 十 六 歲</strong></td></tr>";
        }
        else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>At least 16 years old</strong></td></tr>";
        }
      }
    }
  }
}


// if ((tempobj.name=="home_phone")&&tempobj.value=='') {
// pass=false;
// if (disp == 'ch') {
// messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 住 宅 電 話 （ 或 手 提 電 話 ， 如 適 用 ）</strong></td></tr>";
//   }
// else {
// messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 'Home Telephone' (or mobile number, if necessary)</strong></td></tr>";
//   }
// }

if ((tempobj.name=="home_phone")&&tempobj.value!=''&&skip_chk==0) {
  if (!(check_tel(tempobj.value))) {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>住 宅 電 話 不 正 確</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Home Telephone</strong></td></tr>";
    }
  }
}

if ((tempobj.name=="mobile_phone")&&tempobj.value=='') {
pass=false;
if (disp == 'ch') {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>請 填 寫 手 電 / 傳 呼 號 碼 （ 或 住 宅 電 話 ， 如 適 用 ）</strong></td></tr>";
  }
else {
messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Mobile / Pager (or home telephone number, if necessary)</strong></td></tr>";
  }
}
if ((tempobj.name=="mobile_phone")&&tempobj.value!=''&&skip_chk==0) {
  if (!(check_tel(tempobj.value))) {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>手 電 / 傳 呼 號 碼 不 正 確</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Mobile / Pager</strong></td></tr>";
    }
  }
}

if ((tempobj.name=="emg_phone")&&tempobj.value!=''&&skip_chk==0) {
  if (!(check_tel(tempobj.value))) {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>緊 急 聯 絡 電 話 不 正 確</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Emergency Contact Telephone</strong></td></tr>";
    }
  }
}

if ((tempobj.name=="office_phone")&&tempobj.value!=''&&skip_chk==0) {
  if (!(check_tel(tempobj.value))) {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>辦 事 處 電 話 不 正 確</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Office Telephone</strong></td></tr>";
    }
  }
}

if ((tempobj.name=="fax_no")&&tempobj.value!=''&&skip_chk==0) {
  if (!(check_tel(tempobj.value))) {
    pass=false;
    if (disp == 'ch') {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>辦 事 處 / 聯 絡 傳 真 不 正 確</strong></td></tr>";
    }
    else {
    messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid Office / Contact Fax</strong></td></tr>";
    }
  }
}

if (tempobj.name=="email2") {
  if (tempobj.value=='') {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>重 新 輸 入 電 郵 地 址 不 能 空 白</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in 'Re-enter E-mail Address'</strong></td></tr>";
    }
  }
  else {
    if (email != email2) {
      pass=false;
      if (disp == 'ch') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>重 新 輸 入 電 郵 地 址 與 電 郵 格 式 不 同</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>The format of 'Re-enter Email Address' does not match the one in 'E-mail Address'</strong></td></tr>";
      }
    }
  }
}

if (tempobj.name=="email") {
  if (tempobj.value=='') {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>電 郵 地 址 不 能 空 白</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in E-mail Address</strong></td></tr>";
    }
  }
  else {
    if (!(check_email(tempobj.value))&&skip_chk==0) {
      pass=false;
      if (disp == 'ch') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>電 郵 地 址 格 式 不 正 確</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid E-mail Address format</strong></td></tr>";
      }
    }
  }
}


if (tempobj.name=="addr1") {
  if (tempobj.value=='') {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>通 訊 地 址 不 能 空 白</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Correspondence Address</strong></td></tr>";
    }
  }
  else {
    tmp_add = " " + tempobj.value + " "

    if (tmp_add.search('"') > 0) {
      pass=false;
      if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>通 訊 地 址(1) 不 能 有 "+String.fromCharCode(34)+"</strong></td></tr>";
      }
      else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Correspondence Address(1) cannot contains "+String.fromCharCode(34)+"</strong></td></tr>";
      }
    }
  }
}

if ((tempobj.name=="addr2")&&tempobj.value!='') {
    tmp_add = " " + tempobj.value + " "

    if (tmp_add.search('"') > 0) {
      pass=false;
      if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>通 訊 地 址(2) 不 能 有 "+String.fromCharCode(34)+"</strong></td></tr>";
      }
      else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Correspondence Address(2) cannot contains "+String.fromCharCode(34)+"</strong></td></tr>";
      }
    }
}

if ((tempobj.name=="addr3")&&tempobj.value!='') {
    tmp_add = " " + tempobj.value + " "

    if (tmp_add.search('"') > 0) {
      pass=false;
      if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>通 訊 地 址(3) 不 能 有 "+String.fromCharCode(34)+"</strong></td></tr>";
      }
      else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Correspondence Address(3) cannot contains "+String.fromCharCode(34)+"</strong></td></tr>";
      }
    }
}

if ((tempobj.name=="addr4")&&tempobj.value!='') {
    tmp_add = " " + tempobj.value + " "

    if (tmp_add.search('"') > 0) {
      pass=false;
      if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>通 訊 地 址(4) 不 能 有 "+String.fromCharCode(34)+"</strong></td></tr>";
      }
      else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Correspondence Address(4) cannot contains "+String.fromCharCode(34)+"</strong></td></tr>";
      }
    }
}




   }
}
if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUpperCase();

if (messagetext != '') {
messagetext = "<strong><table class='text01a'>" + messagetext + "</table></strong>"
}


if ( typeof(document.getElementById("hints").innerHTML) != 'undefined' ) {
document.getElementById("hints").innerHTML = messagetext;
}
else {
document.getElementById("hints").document.open();
document.getElementById("hints").document.write(messagetext);
document.getElementById("hints").document.close();
}

document.body.scrollTop = 0;

if (disp == 'ch') {
alert("Please see the error message at the right-hand side.")
}
else {
alert("Please see the error message at the right-hand side.")
}

return false;
}
else
return true;
}

function chk_pre_form1(which,disp) {
var pass=true;
messagetext="";
is_hkid = "";
id_no = "";
submit = "";

if (document.images) {

for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];

if (tempobj.name=="id_no") {
  if (tempobj.value=='') {
    pass=false;
    if (disp == 'ch') {
      if (is_hkid == 'Y') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>香 港 身 份 證 號 碼 不 能 空 白</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>護 照 號 碼 不 能 空 白</strong></td></tr>";
      }
    }
    else {
      if (is_hkid == 'Y') {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in HKID No.</strong></td></tr>";
      }
      else {
        messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Passport No.</strong></td></tr>";
      }
    }
  }
  else {
    if (is_hkid == 'Y') {
      if (!(check_hkid(tempobj.value))) {
        pass=false;
        if (disp == 'ch') {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>香 港 身 份 證 號 碼 不 正 確</strong></td></tr>";
        }
        else {
          messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Invalid HKID No.</strong></td></tr>";
        }
      }
    }
  }
}

if (tempobj.name=="is_hkid" && tempobj.type=="radio" && tempobj.checked) {
is_hkid = tempobj.value;
}


if (tempobj.name=="form_ty") {
form_ty = tempobj.value;
}

if (tempobj.name=="id_no") {
id_no = tempobj.value;
}

  }
}

if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUpperCase();

if (messagetext != '') {
messagetext = "<strong><table class='text01a'>" + messagetext + "</table></strong>"
}


if ( typeof(document.getElementById("hints").innerHTML) != 'undefined' ) {
document.getElementById("hints").innerHTML = messagetext;
}
else {
document.getElementById("hints").document.open();
document.getElementById("hints").document.write(messagetext);
document.getElementById("hints").document.close();
}

document.body.scrollTop = 0;

if (disp == 'ch') {
alert("Please see the error message at the right-hand side.")
}
else {
alert("Please see the error message at the right-hand side.")
}

return false;
}
else
return true;
}

function chk_pre_form2(which,disp) {
var pass=true;
messagetext="";
dept_cd = "";
cno = "";
submit = "";

if (document.images) {

for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];

if (tempobj.name=="dept_cd") {
  if (tempobj.value=='') {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>部 門 不 能 空 白</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Department</strong></td></tr>";
    }
  }
}

if (tempobj.name=="cno") {
  if (tempobj.value=='') {
    pass=false;
    if (disp == 'ch') {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>課 程 編 號 不 能 空 白</strong></td></tr>";
    }
    else {
      messagetext = messagetext + "<tr><td valign='top'><li></li></td><td><strong>Please fill in Programme / Course Code</strong></td></tr>";
    }
  }
}
  }
}

if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUpperCase();

if (messagetext != '') {
messagetext = "<strong><table class='text01a'>" + messagetext + "</table></strong>"
}


if ( typeof(document.getElementById("hints").innerHTML) != 'undefined' ) {
document.getElementById("hints").innerHTML = messagetext;
}
else {
document.getElementById("hints").document.open();
document.getElementById("hints").document.write(messagetext);
document.getElementById("hints").document.close();
}

document.body.scrollTop = 0;

if (disp == 'ch') {
alert("Please see the error message at the right-hand side.")
}
else {
alert("Please see the error message at the right-hand side.")
}

return false;
}
else
return true;
}

function longpics(imglink) {
   longWin=window.open("","newWindow","width=350,height=520,scrollbars=no");
   longWin.document.write("<html><head><title>SCS Express 學院快訊</title></head><body bgcolor=#FFFFFF>");
   longWin.document.write("<img src =" + imglink + " onClick=self.close()>");
   longWin.document.write("</body></html>");
}
   
function widepics(imglink) {
   wideWin=window.open("","window","toolbar=no,location=no,status=no,titlebar=no,width=520,height=350");
   wideWin.document.write("<html><head><title>SCS Express 學院快訊</title></head><body bgcolor=#FFFFFF>");
   wideWin.document.write("<img src= " + imglink + " onClick=self.close()>");
   wideWin.document.write("</body></html>");
}