//function to check for valid email
function checkEmail(ctlName){
	var myString = new String(""+ctlName.value);
	var isvalid="yes";
	if ((myString.indexOf("@")<0) || (myString.charAt(0)==".") || (myString.charAt(0)=="@") || (myString.length<6) || (myString.indexOf(".")<0) || (myString.charAt(myString.indexOf("@")+1)==".") || (myString.charAt(myString.indexOf("@")-1)==".") || (myString.charAt(myString.length-1)==".") || (checkNumTimes(ctlName,"@")!=1) || (myString.charAt(myString.indexOf(".")+1)==".")){
		isvalid="no";
	}

	return isvalid;
	
}

//checks the number of occurences of strChar within value of intWhich
//used mainly for checking multiple "@" in email
function checkNumTimes(ctlName,strChar){
	var strValue2 = eval(ctlName.value);
	var noFound=0;
	for (var i=0; i<strValue2.length; i++){
		if(strValue2.charAt(i)==strChar){
			noFound++;
		}
	}
	return noFound;
}

function validate_feedbackform(fsmasform)
{
	if (fsmasform.contact_name.value=="") {
		window.alert("Please enter your name.");
		fsmasform.contact_name.focus();
		return false;
	}
	if (fsmasform.contact_tel.value=="") {
		window.alert("Please enter your telephone no.");
		fsmasform.contact_tel.focus();
		return false;
	}
	if (fsmasform.feedback.value=="") {
		window.alert("Please enter your feedback or enquiries.");
		fsmasform.feedback.focus();
		return false;
	}			
	if (fsmasform.contact_email.value=="") {
		window.alert("Please enter your email address.");
		fsmasform.contact_email.focus();
		return false;
	}
	var sCont = document.fsmasform.contact_email;
	var sContVal = document.fsmasform.contact_email.value;

	var str=new String();
	str=sContVal;
	var span=new RegExp("[ ]","g");
	var rep=str.replace(span,"9");          

	if (sContVal.length != 0)
    {
    	if(sContVal == ''  || isNaN(rep) == false)
        {
		alert("Please enter email with correct format");
        sCont.focus();
        sCont.select();
        return false;
        }                         
                         
        var sAtSym    = sContVal.indexOf('@')
        var sAtSym2       = sContVal.lastIndexOf('@')
        var sPeriod   = sContVal.lastIndexOf('.')
        var sSpace    = sContVal.indexOf(' ')
        var sLength   = sContVal.length - 1   
          
        if ( (sAtSym < 2) || (sAtSym != sAtSym2) || (sPeriod <= sAtSym+2) || (sPeriod == sLength ) || (sSpace  != -1) )                  
    	{
        alert("Please enter email with correct format");
        sCont.focus();
        sCont.select();
        return false;
        }
    }
}
function validate_course_registration(courses_registration)
{
	if (courses_registration.reg_name.value=="") {
		window.alert("Please enter your Name.");
		courses_registration.reg_name.focus();
		return false;
	}
	if (courses_registration.reg_nric.value=="") {
		window.alert("Please enter your NRIC.");
		courses_registration.reg_nric.focus();
		return false;
	}
	if (courses_registration.reg_address.value=="") {
		window.alert("Please enter your Address.");
		courses_registration.reg_address.focus();
		return false;
	}
	if (courses_registration.reg_postal.value=="") {
		window.alert("Please enter your Postal Code.");
		courses_registration.reg_postal.focus();
		return false;
	}
	if (courses_registration.reg_home_tel.value=="") {
		window.alert("Please enter your Home Telephone No..");
		courses_registration.reg_home_tel.focus();
		return false;
	}
	if (courses_registration.reg_qualification.value=="") {
		window.alert("Please enter your highest qualification.");
		courses_registration.reg_qualification.focus();
		return false;
	}	
	if (courses_registration.reg_email.value=="") {
		window.alert("Please enter your Email.");
		courses_registration.reg_email.focus();
		return false;
	}
	var sCont = document.courses_registration.reg_email;
	var sContVal = document.courses_registration.reg_email.value;

	var str=new String();
	str=sContVal;
	var span=new RegExp("[ ]","g");
	var rep=str.replace(span,"9");          

	if (sContVal.length != 0)
    {
    	if(sContVal == ''  || isNaN(rep) == false)
        {
		alert("Please enter email with correct format");
        sCont.focus();
        sCont.select();
        return false;
        }                         
                         
        var sAtSym    = sContVal.indexOf('@')
        var sAtSym2       = sContVal.lastIndexOf('@')
        var sPeriod   = sContVal.lastIndexOf('.')
        var sSpace    = sContVal.indexOf(' ')
        var sLength   = sContVal.length - 1   
          
        if ( (sAtSym < 2) || (sAtSym != sAtSym2) || (sPeriod <= sAtSym+2) || (sPeriod == sLength ) || (sSpace  != -1) )                  
    	{
        alert("Please enter email with correct format");
        sCont.focus();
        sCont.select();
        return false;
        }
    }
}
function validate_join_us(join_us)
{
	if (join_us.member_name.value=="") {
		window.alert("Please enter your Name.");
		join_us.member_name.focus();
		return false;
	}
	if (join_us.member_nric.value=="") {
		window.alert("Please enter your NRIC.");
		join_us.member_nric.focus();
		return false;
	}
	if (join_us.member_dob.value=="") {
		window.alert("Please enter your Date of Birth.");
		join_us.member_dob.focus();
		return false;
	}
	if (join_us.member_birth_place.value=="") {
		window.alert("Please enter your Place of Birth.");
		join_us.member_birth_place.focus();
		return false;
	}
	if (join_us.member_address.value=="") {
		window.alert("Please enter your Address.");
		join_us.member_address.focus();
		return false;
	}
	if (join_us.member_postal.value=="") {
		window.alert("Please enter your Postal Code.");
		join_us.member_postal.focus();
		return false;
	}
	if (join_us.member_home_tel.value=="") {
		window.alert("Please enter your Home Telephone No..");
		join_us.member_home_tel.focus();
		return false;
	}
	if (join_us.member_mobile_tel.value=="") {
		window.alert("Please enter your Mobile No..");
		join_us.member_mobile_tel.focus();
		return false;
	}
	if (join_us.member_pager_tel.value=="") {
		window.alert("Please enter your Pager No..");
		join_us.member_pager_tel.focus();
		return false;
	}
	if (join_us.member_email.value=="") {
		window.alert("Please enter your Email.");
		join_us.member_email.focus();
		return false;
	}
	var sCont = document.join_us.member_email;
	var sContVal = document.join_us.member_email.value;

	var str=new String();
	str=sContVal;
	var span=new RegExp("[ ]","g");
	var rep=str.replace(span,"9");          

	if (sContVal.length != 0)
    {
    	if(sContVal == ''  || isNaN(rep) == false)
        {
		alert("Please enter email with correct format");
        sCont.focus();
        sCont.select();
        return false;
        }                         
                         
        var sAtSym    = sContVal.indexOf('@')
        var sAtSym2       = sContVal.lastIndexOf('@')
        var sPeriod   = sContVal.lastIndexOf('.')
        var sSpace    = sContVal.indexOf(' ')
        var sLength   = sContVal.length - 1   
          
        if ( (sAtSym < 2) || (sAtSym != sAtSym2) || (sPeriod <= sAtSym+2) || (sPeriod == sLength ) || (sSpace  != -1) )                  
    	{
        alert("Please enter email with correct format");
        sCont.focus();
        sCont.select();
        return false;
        }
    }
	if (join_us.batch_no.value=="") {
		window.alert("Please enter your Batch No..");
		join_us.batch_no.focus();
		return false;
	}
	if (join_us.cert_award_date.value=="") {
		window.alert("Please enter your Certificated Awarded On.");
		join_us.cert_award_date.focus();
		return false;
	}
}
