﻿// JScript File
function checkEmpty(control, msgText, showMsg) {
	var strTmp = control.value;
	if(strTmp.indexOf("\t") > -1) {
		alert('Invalid character {Tab} found in \'' + msgText + '\'.');
		control.focus();
		control.select();
		return true;
	}
	do {
		strTmp = strTmp.replace('\r\n', '');
	} while (strTmp.indexOf('\r\n') > -1);
	do {
		strTmp = strTmp.replace('  ', ' ');
	} while (strTmp.indexOf('  ') >= 0);
	
	if(strTmp.replace(' ','')  == '') {
		if (showMsg==true) {
			alert('The \'' + msgText + '\' should not be empty.');
		}
		control.focus();
		return true;
	}
	return false;
}
function isEmail(strEmail) {
	var AtTheRate, Dot;
	if (strEmail==null) return false;
	AtTheRate = strEmail.indexOf("@");
	Dot = strEmail.lastIndexOf(".");
	//The occurance of @ sign should be 1 and there should be atleast 1 dot '.' in email address.
	if(CntChar(strEmail, '@') != 1 || CntChar(strEmail, '.') < 1) return false;
	//Check if @ is before .
	if(AtTheRate > Dot) return false;
	//Additional Check: Cannot have coma in E-mail address
	if(strEmail.indexOf(",")!=-1) return false;
	return true;
}
function CntChar(mStr, mChar) {
	   var Dots=0, x=-1;
	   do {
		x = mStr.indexOf(mChar, x+1);
		if (x!=-1) Dots++;
		}while(x!=-1);
		return Dots;
}


