function checkEmptyFieldEntry(frmCtlName, strMsg, intTextLength)
{
	var ctlObj = window.document.getElementsByName(frmCtlName)[0];
	ctlObj.value = Trim(ctlObj.value);
	if (ctlObj.value == "")
	{
		alert("Please enter a valid entry for  " + strMsg + " !");
		ctlObj.focus();
		return false;
	}
	if (ctlObj.value.length < intTextLength)
	{
		alert("The entry for " + strMsg + " should be atleast " + intTextLength + " characters long !");
		ctlObj.focus();
		return false;
	}
	return true;
}


function Trim(STRING){
STRING = LTrim(STRING);
return RTrim(STRING);
}

function RTrim(STRING){
while(STRING.charAt((STRING.length -1))==" "){
STRING = STRING.substring(0,STRING.length-1);
}

return STRING;
}


function LTrim(STRING){
while(STRING.charAt(0)==" "){
STRING = STRING.replace(STRING.charAt(0),"");
}
return STRING;
}


function checkDecimals(fieldName, decallowed)
{
	//decallowed = 2;  // how many decimals are allowed?
	if (fieldName.value == "") fieldName.value=0
	if (isNaN(fieldName.value) || fieldName.value == "") 
	{
		alert("Oops!  That does not appear to be a valid number.  Please try again.");
		fieldName.select();
		fieldName.focus();
		return false;
	}
	else 
	{
		//if (fieldName.value.indexOf('.') == -1) fieldName.value += ".";
		var strTemp = fieldName.value;
		if (strTemp.indexOf('.') == -1) strTemp += ".";
		dectext = strTemp.substring(strTemp.indexOf('.')+1, strTemp.length);
		
		if ((dectext.length > decallowed) & (dectext.length > 0) )
		{
			alert ("Oops!  Please enter a number with up to " + decallowed + " decimal places.  Please try again.");
			fieldName.select();
			fieldName.focus();
			return false;
		}
		else 
		{		// Added on 2007-09-08
				var strTemp = fieldName.value;
				var strAmt = 0;
				strAmt =  strTemp.split(".");
				if(parseInt(strAmt) > 999999999)
				{
					alert('Amount can not be greater than  999999999');
					fieldName.select();
					fieldName.focus();
					return false;
				}	
				else
					return true;
		}
 }
}


function checkFieldLength(txtBox, lngAllowed)
{
	var strValue = txtBox.value;
	if (strValue.length > lngAllowed)
	{
		alert("The maximum length of this field could be "+ lngAllowed +" characters only.\nThe length right now is " + strValue.length +""); 
		txtBox.focus(); 
		return false;
	}
	else
		return true;
	
}


function InStr(strSearch, charSearchFor)
/*
InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
                           was found in the string str.  (If the character is not
                           found, -1 is returned.)
                           
Requires use of:
	Mid function
	Len function
*/
{
	for (i=0; i < Len(strSearch); i++)
	{
	    if (charSearchFor == Mid(strSearch, i, 1))
	    {
			return i;
	    }
	}
	return -1;
}

function Mid(str, start, len)
        /***
                IN: str - the string we are LEFTing
                    start - our string's starting position (0 based!!)
                    len - how many characters from start we want to get

                RETVAL: The substring from start to start+len
        ***/
        {
                // Make sure start and len are within proper bounds
                if (start < 0 || len < 0) return "";

                var iEnd, iLen = String(str).length;
                if (start + len > iLen)
                        iEnd = iLen;
                else
                        iEnd = start + len;

                return String(str).substring(start,iEnd);
        }


// Keep in mind that strings in JavaScript are zero-based, so if you ask
// for Mid("Hello",1,1), you will get "e", not "H".  To get "H", you would
// simply type in Mid("Hello",0,1)

// You can alter the above function so that the string is one-based.  Just
// check to make sure start is not <= 0, alter the iEnd = start + len to
// iEnd = (start - 1) + len, and in your final return statement, just
// return ...substring(start-1,iEnd)

function Len(str)
        /***
                IN: str - the string whose length we are interested in

                RETVAL: The number of characters in the string
        ***/
        {  return String(str).length;  }



 function Left(str, n)
        /***
                IN: str - the string we are LEFTing
                    n - the number of characters we want to return

                RETVAL: n characters from the left side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                        return "";
                else if (n > String(str).length)   // Invalid bound, return
                        return str;                // entire string
                else // Valid bound, return appropriate substring
                        return String(str).substring(0,n);
        }



function Right(str, n)
        /***
                IN: str - the string we are RIGHTing
                    n - the number of characters we want to return

                RETVAL: n characters from the right side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                   return "";
                else if (n > String(str).length)   // Invalid bound, return
                   return str;                     // entire string
                else { // Valid bound, return appropriate substring
                   var iLen = String(str).length;
                   return String(str).substring(iLen, iLen - n);
                }
        }	


	//function to validate the Email ID
	function IsValidEmail(txtBox) 
	{
		//Added on 20071110
		var strEMail = LCase(txtBox.value);
		txtBox.value = strEMail;
		var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
		var regex = new RegExp(emailReg);
		if (strEMail !="") 
		{
			if (regex.test(strEMail)==false)
			{
				alert ("Please enter a valid email address !!");
				txtBox.focus(); txtBox.select(); return false;
			}
			if (validateEmail(strEMail)==false)
			{
				alert ("Please enter a valid email address !!");
				txtBox.focus(); txtBox.select(); return false;
			}
		}
	}
	
	function validateEmail(addr,man,db) 
	{
		if (addr == '' && man) {
		   if (db) alert('email address is mandatory');
		   return false;
		}
		var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
		for (i=0; i<invalidChars.length; i++) {
		   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		      if (db) alert('email address contains invalid characters');
		      return false;
		   }
		}
		for (i=0; i<addr.length; i++) {
		   if (addr.charCodeAt(i)>127) {
		      if (db) alert("email address contains non ascii characters.");
		      return false;
		   }
		}

		var atPos = addr.indexOf('@',0);
		if (atPos == -1) {
		   if (db) alert('email address must contain an @');
		   return false;
		}
		if (atPos == 0) {
		   if (db) alert('email address must not start with @');
		   return false;
		}
		if (addr.indexOf('@', atPos + 1) > - 1) {
		   if (db) alert('email address must contain only one @');
		   return false;
		}
		if (addr.indexOf('.', atPos) == -1) {
		   if (db) alert('email address must contain a period in the domain name');
		   return false;
		}
		if (addr.indexOf('@.',0) != -1) {
		   if (db) alert('period must not immediately follow @ in email address');
		   return false;
		}
		if (addr.indexOf('.@',0) != -1){
		   if (db) alert('period must not immediately precede @ in email address');
		   return false;
		}
		if (addr.indexOf('..',0) != -1) {
		   if (db) alert('two periods must not be adjacent in email address');
		   return false;
		}
		var suffix = addr.substring(addr.lastIndexOf('.')+1);
		if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
		   if (db) alert('invalid primary domain in email address');
		   return false;
		}
		return true;
	}


// Added on 20071110
function LCase(strValue)
{
		var strEMailAddress = strValue;
		strEMailAddress = strEMailAddress.toLowerCase( );
		return strEMailAddress;
}

 // Added on 20080829
    
function blockNonNumber(obj,e,isAllowDecimal)
 {
   var key,keyChar,isCtrl;
	 key = e.charCode; // Mozill Firefox
	 if(key == 0) return true;
	 if(window.event)
	 {
	  	key = e.keyCode; //Internet Explorer
	  	isCtrl = window.event.ctrlKey;
	 }
	 
	 keyChar= String.fromCharCode(key) 
	 var RegExp = /\d/;
 	
   var allowDecimal = isAllowDecimal? keyChar == '.' && obj.value.indexOf('.') == -1 : false;
	 return allowDecimal || RegExp.test(keyChar);
}


	//Added on 20092801
	function IsValidPhoneNo(vPhoneNumber)
	{
    var regEx;
    var validCard = "^[0-9]{10,15}$";
    var regEx = new RegExp(validCard);
    bcheck = regEx.test(vPhoneNumber);
    if(bcheck == false) alert("Please enter valid phone number.!");
    return bcheck;
  }
  
   function arrHasUnique(A) 
	{
		var i, j, n;
		n=A.length;
		// to ensure the fewest possible comparisons
		for (i=0; i<n; i++) 
		{  // outer loop uses each item i at 0 through n 
			for (j=i+1; j<n; j++) 
			{ // inner loop only compares items j at i+1 to n
				if (A[i].value==A[j].value) 
				{
				  if(A[i].value != 0 || A[j].value != 0 )
					{
					  if(A[i].value != -1 || A[j].value != -1 )
					  {
					    alert(" Sorry! You have already selected this Product! ");
					    A[i].style.background='#FDD9E6';
					    A[j].style.background='#FDD9E6';
					    A[j].value = -1;
					    A[j].focus();
					    return false;
					  }
					}
				}
				A[j].style.background='#FFFFFF';
			}
			A[i].style.background='#FFFFFF';
		}
		return true;
	}
	
//Added on 20090703:Mani	
function ConvertNumber(pValue)
{
    var vTemp = new Number(pValue)
    vResult = (isNaN(vTemp))?0:parseFloat(vTemp)
    return vResult;
}


function showPopUpWindow(URL, h, w) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=" + w + ",height=" + h + ",left = 390,top = 262');");
}