<!--script language="JavaScript"-->
<!-- begin hiding script from old browsers
 
  function warnEmpty(fieldname, fieldesc){
    fieldname.focus();
    alert('Please enter '+fieldesc+'!');
    return false;
  }

  function warnInvalid(fieldname, fieldesc){
    fieldname.focus();
    fieldname.select();
    alert('Invalid input !!! Please re-enter '+fieldesc+'.');
    return false;
  }

  function isEmpty(thefield){
	return ((thefield==null) || (thefield.length==0))
  }

  function isNumber(thefield){
  var checkOK = "0123456789";
  var allValid = true;

    for (var i=0; i< thefield.length;  i++){
      var ch=thefield.charAt(i);
	    for (j = 0;  j < checkOK.length;  j++)
  		    if (ch == checkOK.charAt(j))
  	  			    break;
		    if (j == checkOK.length)
		    {
		      allValid = false;
		      break;
		    }
    }
    return allValid;
  }

   function isDay(thefield){
     var num=0;

     if (!isNumber(thefield)) return false;
     num = parseInt(thefield, 10);
     return ((num >= 1) && (num <= 31));
   }

   function isMonth(thefield){
     var num=0;

     if (!isNumber(thefield)) return false;
     num = parseInt(thefield, 10);
     return ((num >=1) && (num <= 12));
   }

   function isYear(thefield){
     var num=0

     if (!isNumber(thefield)) return false;
     num = parseInt(thefield, 10);
     if (num < 1900)	return 2;
     else if (num >= 2079) return 3; 
	  return (thefield.length==4);
   }

   function daysInFebruary(year){
     return ( ( (year % 4 == 0) &&
       ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
   }

   function daysInMonth(mm){
     if (mm==4 || mm==6 || mm==9 || mm==11) return 30;
     if (mm==1 || mm==3 || mm==5 || mm==7 || mm==8 || mm==10 || mm==12) return 31;
   }

   function isDate(theForm){
     var dd=0;
     var mm=0;
     var yy=0;
     var istatus=0;

     if (isEmpty(theForm.birthday.value)) return warnEmpty(theForm.birthday, "Day of Birth");
     if (isEmpty(theForm.birthmonth.value)) return warnEmpty(theForm.bmonth, "Month of Birth");
     if (isEmpty(theForm.birthyear.value)) return warnEmpty(theForm.birthyear, "Year of Birth");

     if (!(isDay(theForm.birthday.value)))
       return warnInvalid(theForm.birthday, "Day of Birth");
     if (!(isMonth(theForm.birthmonth.value)))
       return warnInvalid(theForm.bmonth, "Month of Birth");
     istatus=isYear(theForm.birthyear.value);
     if (istatus==2) return warnInvalid(theForm.birthyear, "Year of Birth greater than 1900");
     else if (istatus==3) return warnInvalid(theForm.birthyear, "Year of Birth smaller than 2079");
     else if (istatus!=1) return warnInvalid(theForm.birthyear, "Year of Birth");

     dd=parseInt(theForm.birthday.value, 10);
     mm=parseInt(theForm.birthmonth.value, 10);
     yy=parseInt(theForm.birthyear.value, 10);

     if (dd > daysInMonth(mm))
       return warnInvalid(theForm.birthday, "Day of Birth");

     if ((mm==2) && (dd > daysInFebruary(yy)))
       return warnInvalid(theForm.birthday, "Day of Birth");

     return true;
  }

function updateMonthValue(monthObj) {
  document.bmyfren.birthmonth.value = monthObj.selectedIndex + 1;
}



function updateCountryValue(ctryObj) {
  var i
  i = ctryObj.selectedIndex
  if (i == 0)
    document.bmyfren.Country.value = "au";
  else if (i == 1)
    document.bmyfren.Country.value = "be";
  else if (i == 2)
    document.bmyfren.Country.value = "bm";
  else if (i == 3)
    document.bmyfren.Country.value = "bn";
  else if (i == 4)
    document.bmyfren.Country.value = "br";
  else if (i == 5)
    document.bmyfren.Country.value = "ca";
  else if (i == 6)
    document.bmyfren.Country.value = "cn";
  else if (i == 7)
    document.bmyfren.Country.value = "hr";
  else if (i == 8)
    document.bmyfren.Country.value = "cz";
  else if (i == 9)
    document.bmyfren.Country.value = "dk";
  else if (i == 10)
    document.bmyfren.Country.value = "fr";
  else if (i == 11)
    document.bmyfren.Country.value = "de";
  else if (i == 12)
    document.bmyfren.Country.value = "hk";
  else if (i == 13)
    document.bmyfren.Country.value = "is";
  else if (i == 14)
    document.bmyfren.Country.value = "id";
  else if (i == 15)
    document.bmyfren.Country.value = "in";
  else if (i == 16)
    document.bmyfren.Country.value = "it";
  else if (i == 17)
    document.bmyfren.Country.value = "jp";
  else if (i == 18)
    document.bmyfren.Country.value = "kr";
  else if (i == 19)
    document.bmyfren.Country.value = "lb";
  else if (i == 20)
    document.bmyfren.Country.value = "lt";
  else if (i == 21)
    document.bmyfren.Country.value = "my";
  else if (i == 22)
    document.bmyfren.Country.value = "mx";
  else if (i == 23)
    document.bmyfren.Country.value = "nl";
  else if (i == 24)
    document.bmyfren.Country.value = "nz";
  else if (i == 25)
    document.bmyfren.Country.value = "no";
  else if (i == 26)
    document.bmyfren.Country.value = "pg";
  else if (i == 27)
    document.bmyfren.Country.value = "ph";
  else if (i == 28)
    document.bmyfren.Country.value = "ru";
  else if (i == 29)
    document.bmyfren.Country.value = "sa";
  else if (i == 30)
    document.bmyfren.Country.value = "sg";
  else if (i == 31)
    document.bmyfren.Country.value = "za";
  else if (i == 32)
    document.bmyfren.Country.value = "se";
  else if (i == 33)
    document.bmyfren.Country.value = "ch";
  else if (i == 34)
    document.bmyfren.Country.value = "tw";
  else if (i == 35)
    document.bmyfren.Country.value = "th";
  else if (i == 36)
    document.bmyfren.Country.value = "ae";
  else if (i == 37)
    document.bmyfren.Country.value = "uk";
  else if (i == 38)
    document.bmyfren.Country.value = "us";

}

function isEmail(theForm){
     if (isEmpty(theForm.email.value)) return warnEmpty(theForm.email, "Email Address cannot empty");
     if (theForm.email.value.indexOf('@', 0)== -1 ) return warnInvalid (theForm.email, "Email Address")
     if (theForm.email.value.indexOf('.', 0)== -1 ) return warnInvalid (theForm.email, "Email Address")
     var len=parseInt(theForm.email.value.length,10) - 1;
     var ch=theForm.email.value.charAt(len);
     if ((ch=='.') || (ch=='@')) return warnInvalid (theForm.email, "Email Address");
  
     else return true;
}
 
function isUsername(theForm){
     if (isEmpty(theForm.username.value)) return warnEmpty(theForm.username, "Username");
     if (theForm.username.value.length > 20) 
		return warnInvalid(theForm.username, "cannot more than 20 alphanumeric");
     if (theForm.username.value.length < 6) 
		return warnInvalid(theForm.username, "at least 6 alphanumeric for username");
     else return true;
}

function isPassword(theForm){
    if (isEmpty(theForm.password.value)) return warnEmpty(theForm.password, "password"); 
    if (theForm.password.value.length < 6) 
		return warnInvalid(theForm.password, "at least 6 alphabetical");
	 if (theForm.password.value.length > 20)
		return warnInvalid(theForm.password, "cannot more than 20 alphanumeric");
    else return true;
}

//function checkUsernameAndPassword(theForm){
//	if (!(isUsername(theForm))) return false;   
//	if (!(isPassword(theForm))) return false;
//}

function valform(theForm){
	
	if (!(isUsername(theForm))) return false;   
	if (!(isPassword(theForm))) return false;
	if (isEmpty(theForm.name.value)) return warnEmpty(theForm.name, "name");
	if (isEmpty(theForm.ic.value)) return warnEmpty(theForm.ic, "NRIC");
	if (!(isNumber(theForm.ic.value))) 
		return warnInvalid(theForm.ic, "valid NRIC.");	
	if (theForm.ic.value.length < 12)
		return warnInvalid(theForm.ic, "NRIC.");
	
	if (!(isEmail(theForm))) return false;	
	if (!(isNumber(theForm.hp.value))) 
		return warnInvalid(theForm.hp, "valid mobile no.");	
	if (theForm.hp.value.length < 10) 
		return warnInvalid(theForm.hp, "complete mobile no.");
	if (!(isDate(theForm))) return false;
	if (theForm.agree.checked == false) 
	{		
		alert ('Disclaimer must be checked!');		
	return false;		
	}
//	if (isEmpty(theForm.add1.value)) return warnEmpty(theForm.add1, "Address");
//	if (isEmpty(theForm.city.value)) return warnEmpty(theForm.city, "City");
//	if (isEmpty(theForm.postcode.value)) return warnEmpty(theForm.postcode, "Postcode");
	//	if (!(isNumber(theForm.hsetel.value))) 
//		return warnInvalid(theForm.hsetel, "valid house no.");
//	if (!(isEmpty(theForm.hsetel.value)) && (theForm.hsetel.value.length < 9))
//		return warnInvalid(theForm.hsetel, "complete house no.");		
//	if (theForm.hobby1.checked == false && theForm.hobby2.checked == false && theForm.hobby3.checked == false &&
//		theForm.hobby4.checked == false && theForm.hobby5.checked == false && theForm.hobby6.checked == false &&
//		theForm.hobby7.checked == false && theForm.hobby8.checked == false && theForm.hobby9.checked == false &&
//		theForm.hobby10.checked == false && theForm.hobby11.checked == false && theForm.hobby12.checked == false &&
//		theForm.hobby13.checked == false && theForm.hobby14.checked == false && theForm.hobby15.checked == false &&
//		theForm.hobby16.checked == false && theForm.hobby17.checked == false && theForm.hobby18.checked == false &&
//		theForm.hobby19.checked == false && theForm.otherhobby.value == '') 
//	{		
//		alert ('You didn\'t choose any of the checkboxes from Interests!');		
//		return false;		
//	}
//		else
//	{	
//		return true;
//	}
	
//		if (theForm.pre_event1.checked == false && theForm.pre_event2.checked == false && 
//		theForm.pre_event3.checked == false && theForm.pre_event4.checked == false && 
//		theForm.otherpre_event.checked == '') 
//	{		
//		alert ('You didn\'t choose any of the checkboxes from Previous Events!');		
//		return false;		
//	}	
		else
	{	
		return true;
	}
	
	
}
// end hide -->
<!--/script-->
