//regular expression defining a 5 digit number 
var re5digit =/^[a-zA-Z]{5,20}$/ 
// local variable for Regulare expression check.
var re5digitAZ =/(?=.*[A-Z]).{1,}$/ //regular expression 
var re5digitaz =/(?=.*[A-Z]).{1,}$/ //regular expression 
var re5digit09 =/(?=.*\d).{1,}$/ //regular expression 
var re5digitLen =/(?=.*).{5,10}$/ //regular expression 
// URL regular expression
var regexpURL =/(http:\/\/|https:\/\/|)\S+\.\S+/i;
// Email regular expression
var rexpEmail = /\w+(@|\.\w+@)\w+\.\w+/i;

// Class Constructor for String Validation
function trim_string() 
{
	var iChar, iCount;
	var sValue = this;
	
	iChar = sValue.length - 1;
	iCount = -1;
	while (sValue.charAt(iChar)==' ' && iChar > iCount)
	    --iChar;
	if (iChar!=(sValue.length-1))
	    sValue = sValue.slice(0, iChar+1);
	iChar = 0;
	iCount = sValue.length - 1;
	while (sValue.charAt(iChar)==' ' && iChar < iCount)
	    ++iChar;
	if (iChar!=0)
	    sValue = sValue.slice(iChar, sValue.length);
	return sValue;
}

// Extend the string object to include a trim function
String.prototype.Trim = trim_string;

// Is Blank Data Input
function IsBlank(ctl,ctlMsg)
{
	if(ctl != null)
	{
		if(ctl.value.Trim() == "")
		{
			if(ctlMsg != "")
			{
				alert('Please Provide ' + ctlMsg );
				ctl.focus();
				return true;
			}
			else
				return true;
		}
			return false;
	}
	else
	{
		alert('Control Missing');
		return false;
	}

}

// Is Valid Email ID
function IsEmail_old(ctl)
{
	if(ctl.value.Trim() != "")
	{
		if(! rexpEmail.test(ctl.value.Trim()))
			return false;
		else
			return true;
	}
}

// Integer Check
function IsInteger(ctl, errMsg)
{
	var i;
	var s;
	s = ctl.value;
	for (i = 0; i < s.length; i++)
	{   
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) 
		{
			alert(errMsg + ' Should be Numeric.');
			ctl.focus();
			return false;
		}
		else
		{
			return true;
		}
	}
	
	// All characters are numbers.
}

// Check Valid URL
function IsURL(ctl)
{
	if (! regexpURL.test(ctl.value))
		return false;
	else
		return true;
}

// Is password a Valid one
// alert("Password must be at least 6 characters, no more than 10 characters, and \nMust include at least one upper case letter, one lower case letter, and one numeric digit.")
function IsValidPassword(ctl)
{
	if (ctl.value.search(re5digitAZ)==-1 || ctl.value.search(re5digitaz)==-1 || ctl.value.search(re5digit09)==-1 || ctl.value.search(re5digitLen)==-1 )//if match failed
		return false;
	else
		return true;	
}

// Only Characters are allowed
function IsCharOnly(ctl,ctlMsg)
{
	/*if (ctl.value.search(re5digit)==-1 )//if match failed
		return false;
	else
		return true;
	*/	
		
	if (ctl.value.search(re5digit)==-1 )//if match failed
	{
		if(ctlMsg != "")
		{
			alert('Only characters \(A-Z a-z \) are allowed for ' + ctlMsg + ' and Should be more than 5 characters.');
			ctl.focus();
		}
		return false;
	}
	else
		return true;
}


	function checkFileExtention(ctlName)
	{
		var objFileUpload = document.getElementById(ctlName);		
		var strFileName = objFileUpload.value;
		var bolStatus = true;
		
		if(strFileName.Trim() != "")
		{
			var strFileExtention = strFileName.substr(strFileName.length - 4);
			strFileExtention = strFileExtention.toUpperCase();
			if(strFileExtention != ".XLS" && strFileExtention != ".DOC" && strFileExtention != ".PDF" )
			{
				alert('File with extention `' + strFileExtention + '` is not allowed to upload.');
				bolStatus = false;
			}
		}
		return bolStatus;	
	}
	
	function limitChecked(SkillLimit,ctlName,ctlCounter) 
	{
		ckd	= 0;
		for (i=0;i<ctlCounter;i++)	
		{
			checkbox = document.getElementById(ctlName + i).checked;
			if (eval(checkbox))
				ckd = ckd + 1; 
		}

		if (ckd > SkillLimit) 
		{
			alert('You have selected '+ckd+' Category Skills. Please limit your selection to '+SkillLimit+ ".");
			return false;
		}
		else if(ckd == 0)
		{
			alert("You have not selected any Category Skills. You can select maximum " + SkillLimit + " skills");
			return false;
		}
		else
			return true;	
	}	
	
	function CheckMaxChar(ctlName,maxLength,msg)
	{
		var bolStatus = true;
		var  objtxtComments = document.getElementById(ctlName);
		if(objtxtComments)
		{	if(objtxtComments.value.length > parseInt(maxLength))
			{	alert(msg + ' text should not be more than ' + maxLength + ' Characters.');
				objtxtComments.focus();	
				bolStatus = false;
			} 
		}
		
		return bolStatus;
	}
	
	
	function IsEmail(field)
	{
	with (field)
	{
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2) 
	  	{
			return false;
		}
		else 
		{
			return true;
		}
	}
	}