function tmiAddComment(frm) {
	if (frm.elements["comment_name"].value.length == 0) {
		alert("Please insert Name.");
		frm.elements["comment_name"].focus();
		return false;
	}
	else if (frm.elements["comment_email"].value.length == 0) {
		alert("Please insert Email.");
		frm.elements["comment_email"].focus();
		return false;
	}
	else if (!FrmIsEmail(frm.elements['comment_email'])){
		alert("Please insert valid email address.");
		frm.elements['comment_email'].focus();
		return false;
	}		
	else if (frm.elements["comment_comment"].value.length == 0) {
		alert("Please insert Comment.");
		frm.elements["comment_comment"].focus();
		return false;
	}
	else {
		if (frm.elements["comment_agree"].checked == true) {
			var resp = confirm("Are you sure want to add this comment?");
			if(resp) {		
				frm.submit();
			}
			else {
				return false;
			}
		}
		else {
			alert("Please accept the Terms of Usage.");
			return false;
		}
	}
}

function FrmIsEmail(Ele){
	return IsEmail(Ele.value);
}

function IsEmail(str){
	var PosAlias = str.indexOf("@");
	if (PosAlias < 1 || PosAlias > str.length -1 || PosAlias != str.lastIndexOf("@")) return false;
	
	if (!IsAlpha(str.charAt(0))) return false;
	if (!IsAlpha(str.charAt(str.length-1))) return false;
	
	var PosLastDot = str.lastIndexOf(".");
	if (PosLastDot >= str.length-1 || PosLastDot < PosAlias) return false;
	
	return true;
}

function IsAlpha(str, strCase, WhiteSpace){
	if (IsEmpty(str)) return false;

	for (i=0; i<str.length; i++){
		var c = str.charAt(i);
		
		if (WhiteSpace){
			if (i == 0){
				if (IsWhiteSpace(c)) return false;
			}
			else if (i == str.length-1){
				if (IsWhiteSpace(c)) return false;
			}
			
			if (!strCase){
				if ( !IsLetter(c) ) return false;
			}
			else {
				if ( strCase == 1 && !( IsLetterUpper(c) || IsWhiteSpace(c) ) ) return false;
				if ( strCase == 2 && !( IsLetterLower(c) || IsWhiteSpace(c) ) ) return false;
			}
		}
		else {
			if (!strCase){
				if ( !( IsLetter(c) || IsDigit(c) ) ) return false;
			}
			else {
				if ( strCase == 1 && !IsLetterUpper(c) ) return false;
				if ( strCase == 2 && !IsLetterLower(c) ) return false;
			}
		}
	}
	
	return true;
}

function IsEmpty(s){
	return ((s == null) || (s.length == 0))
}

function IsWhiteSpace(s){
	var WhiteSpace = " \t\n\r";
	
	if (IsEmpty(s)) return true;
	
	for (i = 0; i < s.length; i++){
		var c = s.charAt(i);
		
		if (WhiteSpace.indexOf(c) == -1) return false;
	}

	return true;
}

function IsLetter (c){
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function IsLetterUpper (c){
	return ( (c >= "A") && (c <= "Z") )
}

function IsLetterLower (c){
	return ( (c >= "a") && (c <= "z") )
}

function IsDigit (c){
	return ((c >= "0") && (c <= "9"))
}

function test123() {
	alert("The Malaysian Insider is committed \nto ensuring conversation between readers remain\npolite and on-topic at all times. To protect\nagainst comment spam and other risks,\n we have enabled partial comment moderation.\nComments will be posted to the site\n immediately, however, some comments will be\nheld and manually reviewed by The Malaysian\n Insider before they are made publicly visible.\nWe respect your right to air your point\n of view, whatever it may be. However, we reserve\nthe right to edit, reject or delete\n any post that The Malaysian Insider deems\ninappropriate. Posting repeated messages may\n cause a temporary or permanent suspension of\nyou or your IP address on the The Malaysian\n Insider. If you find a comment offensive, please\nuse the report abuse link found on\n every message so it can be reviewed by a moderator.");
	return false;
}