<!--
//*********************************************************************************************************************
//Created By : Kalyan		Created Date : 05-Dec-02
//Description : Common include file for generic validations.
//----------------------------------------------------------
//Modifications by Kalyan
//Date 31-Dec-02
//1. Added new functions
//**********************************************************************************************************************
//function to validate the presence of mandatory fields
/* conventions: 
vLen is positive if validating a varchar field
vlen is -1 if validating integer field */
function chkReq(item,vLen,dName)
{  //validating the presence of value for the mandatory item
   if (eval(item + ".value.length") == 0)
   {  alert("Please enter the value for " + dName + ".This is mandatory information!" );
      eval(item + ".focus()");
      return(false); }
   else
   {  //validating the presence of initial spaces
      if (!chkSpace(item,dName))
        return(false);
            
      //validating the lengths, depending on the datatype of the field
      /* start of block to validate lengths */
      if (vLen == -1)
      {  if (isNaN(eval(item + '.value'),dName))
         { alert('Enter a numeric value for ' + dName); 
           eval(item + ".focus()");  
		   return; }
	   }	 
	  else	   
      {  if (!chkLen(item,vLen,dName))
           return(false); }}
      /* end of block to validate lengths */      

   return(true); 
}

//function to validate the lengths of the controls
function chkLen(item,vLen,dName)
{  if (eval(item + ".value.length") > vLen)
   {  alert("The length of " + dName + " should not be more than " + vLen);
      eval(item + ".focus()");
      return(false); }
   
   return(true); }

//function to validate the presence of space as the first character
function chkSpace(item,dName)
{  if (eval(item + ".value.indexOf(' ')") == 0)
   {  alert("Remove the initial spaces for " + dName + " details");
      eval(item + ".focus()");
      return(false); }
   
   return(true); }
   
   
//function to validate for the presence of only numeric values with . for money type
function chkAmt(item,dName)
{ var val,i;

  //value to be validated
  val = eval(item + ".value");
  if (isNaN(eval(item+'.value')))
  { alert(dName + " field can contain only numeric values. Please re-enter your data.");
           eval(item + ".focus()");  
		   return (false); }
   //loop thru the length of the value
   for(i=0; i<val.length; i++)
   {  if (!((val.charCodeAt(i) >= 48) && (val.charCodeAt(i) <= 57)))
      {  
      //alert(val.charCodeAt(i))
       if (val.charCodeAt(i)!= 46)
        {
         break;
        } 
      }
   }

   if (i < val.length)
   { alert(dName + " field can contain only numeric values. Please re-enter your data.");
     eval(item + ".focus()"); 
     return (false); }

  return(true);
}   
   
//function to validate for the presence of only numeric values
function chkNum(item,dName)
{ var val,i;

  //value to be validated
  val = eval(item + ".value");

   //loop thru the length of the value
   for(i=0; i<val.length; i++)
   {  if (!((val.charCodeAt(i) >= 48) && (val.charCodeAt(i) <= 57)))
      {  
     
         break;
       
      }
   }

   if (i < val.length)
   { alert(dName + " field can contain only numeric values. Please re-enter your data.");
     eval(item + ".focus()"); 
     return (false); }

  return(true);
}

//function to validate the email address
function chkEmail(item,dName)
{  var email = eval(item + ".value");
   var msg = "Invalid format for " + dName + ".\n\nPlease provide the email address in this format:\nuser@company.com";
   
   //atleast one . and @ should be present
   if ((email.indexOf(".") == -1) || (email.indexOf("@") == -1))
   {  alert(msg);
      eval(item + ".focus()");
      return(false); }

   //only 1 @ is allowed
   if (email.indexOf("@") != email.lastIndexOf("@"))
   {  alert(msg);
      eval(item + ".focus()");
      return(false); }

   //there should be atleast 1 . after @
   if (!(email.lastIndexOf(".") > email.indexOf("@")))
   {  alert(msg);
      eval(item + ".focus()");
      return(false); }
   
   //conescutive .@ or @. are not allowed
   if ((email.charAt(email.indexOf("@") - 1) == ".") || (email.charAt(email.indexOf("@") + 1) == "."))
   {  alert(msg);
      eval(item + ".focus()");
      return(false); }
	
   //no spaces are allowed
   if (email.indexOf(" ") >= 0)
   {  alert(msg);
      eval(item + ".focus()");
      return(false); }   
   
   return(true);
}

//function to submit a form by setting the action to the link
function submitTo(frm,link)
{
 eval("document." + frm + ".action = '" + link + "'");
 eval("document." + frm + ".method='post'");
 eval("document." + frm + ".submit()");
}

//function to open a new window with url mentioned with height,width
function openWin(url,ele,height,width)
{  if (ele != ''){
     url = url + 'sval='  + eval('document.' + ele + '.value') + '&formtxt=' + ele ;
    
     eval('document.' + ele + '.focus()')
  }
   window.open(url,'Popup','height=' + height + ',width=' + width + ',status=yes,toolbar=no,scrollbars,resizable,left=650,top=165');
}

function openWins(url,ele,height,width,top,left)
{  if (ele != ''){
     url = url + 'sval='  + eval('document.' + ele + '.value') + '&formtxt=' + ele ;
    
     eval('document.' + ele + '.focus()')
  }
  window.open(url,'Popup','height=' + height + ',width=' + width + ',status=no,toolbar=no,scrollbars,resizable,left=' + left + ',top=' + top);
}

//function to populate value into the field against magnifying glass
function popFld(ele,val)
{   //regular expression to replace single quotes in values
	//the function requires that the VAL has single quotes converted to *# combination before calling the function
	rExp = /\*\#/gi;
	val = String.fromCharCode(34) + val.replace(rExp,String.fromCharCode(39)) + String.fromCharCode(34);
    eval('window.opener.document.' + ele + '.value=' + val);

    window.close();
}

//function to confirm delete operation
function delConfirm(frm,link)
{ if (confirm("Do you want to delete the record? Click 'OK', to confirm"))
    submitTo(frm,link);  
}

//function to open attachments after replacing spaces in filenames
function openAttachment(ofile)
{  var awin;

   while(ofile.indexOf("^") > 0)
   {  ofile = ofile.replace("^"," ");
   }

   awin = window.open(ofile,"Attached");
}

//function to open export window
function exportWin(url,options)
{  window.open(url,'Export',options);
}

//-----------------------------------------Added by surya--may 6th 2003
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   
   return retValue; // Return the trimmed string back to the user
} 
// Ends the "trim" function
//-----------------------------------------------------------------
//-----------------------------------------Added by Ajay on July 17 2003
//Function for checking whether passed string value is alphanumeric or not
function chkAlphaNumeric(item,dName)
{
	var FieldValue=eval(item+ ".value" );
	//alert(FieldValue);
	if (FieldValue != "")
		{   //var Flag
			for(i=0; i< FieldValue.length; i++)
				{
					//alert(FieldValue.charCodeAt(i));
					
					if(!((FieldValue.charCodeAt(i)>=48 && FieldValue.charCodeAt(i)<=57 ) || ( FieldValue.charCodeAt(i)>=65 && FieldValue.charCodeAt(i)<= 90 ) || (FieldValue.charCodeAt(i)>=97 && FieldValue.charCodeAt(i)<=127 )||(FieldValue.charCodeAt(i) == 32) || (FieldValue.charCodeAt(i)== 39)))
					{
						break;
						
					}
				}
				 if (i < FieldValue.length)
					{	
						alert(dName + " field can contain only alphanumeric values. Please re-enter your data.");
						eval(item + ".focus()"); 
						return (false); 
					} 		
		}	
		
		return (true); 	
	}	
		
//-----------------------------------------------------------------
//function to switch modules
function switchModule(value)
{
	document.FrmDigiPad.method="post"	
	document.FrmDigiPad.action="/html/ValidateAccessRight.asp?module="+value
	document.FrmDigiPad.submit()
}

//function to open the help file in new window with url mentioned with height,width,left,top
function openHelp(url,height,width,left,top)
{    
   window.open(url,'Help','height=' + height + ',width=' + width + ',left=' + left + ',top=' + top + ',status=yes,toolbar=no,scrollbars,resizable');
}

//function not to allow the single quote or double quote wherever it is not required to enter.
// Added by Ramesh on 26/06/2003
function singlequote() {
	if (window.event.keyCode==39)   { 
		window.event.returnValue=false;
	}
}
function doublequote() {
	if (window.event.keyCode==34){ 
		window.event.returnValue=false;
	}
}
//-->  

//function to open the help file in new window with url mentioned with height,width,left,top
function openHelp(url,height,width,left,top)
{    
   window.open(url,'Help','height=' + height + ',width=' + width + ',left=' + left + ',top=' + top + ',status=yes,toolbar=no,scrollbars,resizable');
}

//function not to allow the single quote or double quote wherever it is not required to enter.
// Added by Ramesh on 26/06/2003
function singlequote() {
	if (window.event.keyCode==39)   { 
		window.event.returnValue=false;
	}
}
function doublequote() {
	if (window.event.keyCode==34){ 
		window.event.returnValue=false;
	}
}
//-->  