function validate(obj) {
	if ($.trim($('#email').val())=='') {
		alert("Please enter your email address.");
		$('#email')[0].focus();
		return false;
	}
	else if (!check_email($.trim($('#email').val()))) {
		alert("Please enter your valid email address.");
		$('#email')[0].focus();
		return false;
	}
	if ($.trim($('#email1').val())=='') {
		alert("Please reenter your email address.");
		$('#email1')[0].focus();
		return false;
	}
	if ($.trim($('#email').val())!=$.trim($('#email1').val())) {
		alert("Your email address do not match.");
		$('#email').val('');
		$('#email1').val('');
		$('#email')[0].focus();
		return false;
	}
	if ($('#password').val()=='') {
		alert("Please enter your password.");
		$('#password')[0].focus();
		return false;
	}
	else if ($('#password').val().length<8) {
		alert("Please enter at least 8 characters for your password.");
		$('#password')[0].focus();
		return false;
	}
	if ($('#password1').val()=='') {
		alert("Please reenter your password.");
		$('#password1')[0].focus();
		return false;
	}
	if ($('#password').val()!=$('#password1').val()) {
		alert("Your password do not match.");
		$('#password').val('');
		$('#password1').val('');
		$('#password')[0].focus();
		return false;
	}
	if ($.trim($('#nric').val())=='') {
		alert("Please enter your NRIC / Passport No.");
		$('#nric')[0].focus();
		return false;
	}
	if ($.trim($('#fullname').val())=='') {
		alert("Please enter your fullname.");
		$('#fullname')[0].focus();
		return false;
	}
	if ($('select[name="overseas_school"]').val()== 0) {
		alert("Please select your school.");
		$('select[name="overseas_school"]')[0].focus();
		return false;
	}
	else if($('select[name="overseas_school"]').val() == 454 && $('input[name="overseas_others"]').val()==""){
		alert("Please enter your school in the textbox");
		$('input[name="overseas_others"]').focus();
		return false;
		}
	
	if ($('input[name="referrer[]"]:checked').length==0) {
		alert("Please let us know how you got to know about this portal.");
		$('input[name="referrer[]"]')[0].focus();
		return false;
	}
	else {
		var other=false;
		$('input[name="referrer[]"]:checked').each(function() {
			 if (this.value==31 && $.trim($('#referrer_other').val())=='')
				other=true;
		});
		if (other) {
			 alert("Please elaborate how you got to know about this portal.");
			 $('#referrer_other')[0].focus();
			 return false;
		}
	}
	if ($('#tnc:checked').length<1) {
		alert("You have to acknowledge that you have read and agree to our terms and conditions!");
		$('#tnc')[0].focus();
		return false;
	}
	obj.submit();
	return true;
}

// CHECK EMAIL ADDRESS VALIDITY
function check_email(e) {
	var ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

	for(var i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){
			return (false);
		}
	}
	if (document.images) {
		var re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		var re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return (-1);
		}
	}
}