// JavaScript Document
function ValidateForm() {
   var errors = '';
   		
	myOption = -1;
	for (i=frmRegistration.rdoStatus.length-1; i > -1; i--) {
	if (frmRegistration.rdoStatus[i].checked) {
	myOption = i; i = -1;
	}
	}
	
	   var total=0;
	   for(var i=0; i < document.frmRegistration.ckb.length; i++){
	   if(document.frmRegistration.ckb[i].checked){
	   total =total +1;}
	   }	
	
		if(document.frmRegistration.etxtName.value == "" || document.frmRegistration.etxtName.value == null ) {
		   errors += ' - Name\n';
		}
		if(document.frmRegistration.etxtIC.value == "" || document.frmRegistration.etxtIC.value == null ) {
		   errors += ' - I/C No.\n';
		}
		
		
		if (document.frmRegistration.etxtLogin1.value.length < 6 || document.frmRegistration.etxtLogin1.value.length > 20) {
			errors += ' - Your Login ID (1st Choice) length must have 6 - 20 characters.\n';
		}
		if (ValidateAlphanumeric(frmRegistration.etxtLogin1)==false) {
			errors += ' - Your Login ID (1st Choice) contains invalid character(s).\n';
		}
		
		if (document.frmRegistration.etxtLogin2.value.length < 6 || document.frmRegistration.etxtLogin2.value.length > 20) {
			errors += ' - Your Login ID (2nd Choice) length must have 6 - 20 characters.\n';
		}
		if (ValidateAlphanumeric(frmRegistration.etxtLogin2)==false) {
			errors += ' - Your Login ID (2nd Choice) contains invalid character(s).\n';
		}
		if (document.frmRegistration.etxtLogin3.value.length < 6 || document.frmRegistration.etxtLogin3.value.length > 20) {
			errors += ' - Your Login ID (3rd Choice) length must have 6 - 20 characters.\n';
		}
		if (ValidateAlphanumeric(frmRegistration.etxtLogin3)==false) {
			errors += ' - Your Login ID (3rd Choice) contains invalid character(s).\n';
		}
		
		if (document.frmRegistration.etxtEmail.value =="") {
		
		errors += ' - Email\n';
		} else {
			val = document.frmRegistration.etxtEmail.value
			p=val.search('@');
		
			if (p<1 || p==(val.length-1)){
			 errors+='- Valid email address\n';
			} 
		}
		if(document.frmRegistration.etxtContact.value == "" || document.frmRegistration.etxtContact.value == null ) {
		   errors += ' - Contact no.\n';
		}
		
		if(document.frmRegistration.etxtEducation.value == "" || document.frmRegistration.etxtEducation.value == null ) {
		   errors += ' - Education/Institution\n';
		}
		if (myOption == -1) {
	 	errors += ' - Select your Status \n';
		}
		if(total == 0){
   			errors += ' - Select Job Areas. (maximum 5). \n';
   		}
		if (errors){
			 alert('The following error(s) occurred:\n'+errors);
			 
			 return false;
		} else {
			return true;
		}   
		return false;
}


function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}


function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}


function chkcontrol(j) {
var total=0;
for(var i=0; i < document.frmRegistration.ckb.length; i++){
if(document.frmRegistration.ckb[i].checked){
total =total +1;}



if(total > 5){
alert("Please select only (5) Job Areas.") 
document.frmRegistration.ckb[j].checked = false ;
return false;
}
}
}

function ValidateAlphanumeric(sThisField) {
	var valid="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._"
	var temp
	for (var i=0;i< sThisField.value.length;i++) {
		temp=""+sThisField.value.substring(i, i+1)
		if (valid.indexOf(temp)=="-1") return false
	}
	return true
}

function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}
