/// <summary>
///	<p>FieldValidation.js</p>
/// <p>*************************************************************************************</p>
///	<p>Copyright (c) 2005, Sify Ltd. All Rights Reserved.</p>
///	<p>*************************************************************************************</p>
///	<p>This software is the confidential and proprietary information of Sify Ltd. 
/// ("Confidential Information").  You shall not disclose such Confidential Information and
/// shall use it only in accordance with the terms of the license agreement you entered into  
/// with Sify Ltd.</p>
///	<p>Author:							Sathya,Lakshmi,Nikil</p>
///	<p>Date:							Dec 2005</p>
///	<p>Version/Build No.:				1.0</p>
///	<p>Modification Date:				Null</p>	
///	<p>Dependencies:					Null</p>
///	<p>Special Hardware Requirements:	Null</p>
///	<p>*************************************************************************************</p>
///	<p>Purpose of the program:</p>
///	<p>This js file serves as function library for different field validations.</p>
/// </summary>

//---------------------------------------------------------------------------------------//

/// <summary>
/// <p>Author :							Sathya,Lakshmi,Nikil</p>
///	<p>Date:							Dec 2005</p>
///	<p>Version/Build No.:				1.0</p>
///	<p>Modified By:						Null</p>	
///	<p>Modification Date:				Null</p>	
///	<p>Dependencies:					Null</p>
///	<p>Purpose of the program:</p>
/// <p>Trim function for javascript, will return a trim string</p>
/// </summary>
function week_before(s) {
    // parse s for month, day, year
    var dateArray = s.split('/');
    sdate = new Date(dateArray[2],dateArray[1]-1,dateArray[0]);

// figure out day, month, year 7 days ago
    var odate = new Date(sdate.getTime() - (180 * 86400000));

// return value
    return (odate.getMonth()+1) + '/' + odate.getDate() + '/' + odate.getYear();
}




function getKeyCode(e)
{
		if (window.event)
			return window.event.keyCode;
		else if (e)
			return e.which;
		else
			return null;
}

function keyRestrict(e, validchars) 
{	
	
			var key='', keychar='';
			key = getKeyCode(e);
			
			if (key == null) return true;
			keychar = String.fromCharCode(key);
			keychar = keychar.toLowerCase();
			validchars = validchars.toLowerCase() + "'";
			if (validchars.indexOf(keychar) != -1)
			return true;
			if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
			return true;
			return false;
}
	
String.prototype.trim = function() {

 // skip leading and trailing whitespace
 // and return everything in between
  var x=this;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}

function Test1(StartDate,Days)
{

	var dt1   = parseInt(StartDate.substring(0,2),10); 
	var mon1  = parseInt(StartDate.substring(3,5),10); 
	var yr1   = parseInt(StartDate.substring(6,10),10); 
	var date1 = new Date(yr1, mon1, dt1); 
	alert(date1);
	var x =Date.parse(date1);
	alert(x);
	x.setDate(x.getDate()+Days);
	//var y = x.getDate()-180;
	alert(x);
}
// DATE VALIDATION For Two Dates

//---------------------------------------------------------------------------------------//

/// <summary>
/// <p>Author :							Sathya,Lakshmi,Nikil</p>
///	<p>Date:							jan 2006</p>
///	<p>Version/Build No.:				1.0</p>
///	<p>Dependencies:					Null</p>
///	<p>Purpose of the program:</p>
/// <p>Function will compare two dates </p>
/// </summary>

//   Used for comparing DropDownList month and year with hidden full date.
    function CompareMthYear(mon1,year1,mthYear)
    {
            var strMon1 = mon1;
            var strYear1 = year1;
            var strMthYear = mthYear;
            
            var m1 = parseInt(mon1);
            var y1 = parseInt(year1);
            
            var m2 = parseInt(strMthYear.substring(3,5),10);
            var y2 = parseInt(strMthYear.substring(6,10),10);           
            
            if(y1 < y2)
            {
               return false;
            }
            else if((y1 == y2) && (m1 < m2))
            {
              return false;              
            }
            else
            {
               return true;
            }         
	}
	
	function CompareTwoDates(fromDate,toDate) 
	{ 
		var blnResult
		var str1  = fromDate; 
		var str2  = toDate; 
		var dt1   = parseInt(str1.substring(0,2),10); 
		var mon1  = parseInt(str1.substring(3,5),10); 
		var yr1   = parseInt(str1.substring(6,10),10); 
		var dt2   = parseInt(str2.substring(0,2),10); 
		var mon2  = parseInt(str2.substring(3,5),10); 
		var yr2   = parseInt(str2.substring(6,10),10); 
		var date1 = new Date(yr1, mon1, dt1); 
		var date2 = new Date(yr2, mon2, dt2); 
		if(yr2 > yr1) 
			{ 
				//alert('To date must be greater then or equal to from date')
				blnResult=true;
				return blnResult;
			}
			else if(yr2<yr1)
			{
				//alert('To date must be greater then or equal to from date')
				blnResult = false;
				return blnResult;
			} 
			else 
			{
				if(mon2>mon1)
				{
					blnResult=true;
					return blnResult;
				}
				else if(mon2<mon1)
				{
					//alert('To date must be greater then or equal to from date')
					blnResult = false;
					return blnResult;				
				}
				else
				{
					if(dt2>dt1)
					{
						blnResult=true;
						return blnResult;	
					}
					else if(dt2<dt1)
					{
						//alert('To date must be greater then or equal to from date')
						blnResult = false;
						return blnResult;
					}
					else
					{
						blnResult=true;
						return blnResult;
					}
				}
			 }
		/*if(date2 < date1) 
		{ 
			
			blnResult=false;
		}
		else
		{
			blnResult = true;
		} 
		return blnResult*/
	} 		
function CheckDateInRange(txtDate,FromDate,ToDate)
{ 	//check from date
			var str1  = txtDate; 
			var str2  = FromDate; 
			var str3 = ToDate;
			var dt1   = parseInt(str1.substring(0,2),10); 
			var mon1  = parseInt(str1.substring(3,5),10); 
			var yr1   = parseInt(str1.substring(6,10),10); 
			var dt2   = parseInt(str2.substring(0,2),10); 
			var mon2  = parseInt(str2.substring(3,5),10); 
			var yr2   = parseInt(str2.substring(6,10),10); 
			var dt3   = parseInt(str3.substring(0,2),10); 
			var mon3  = parseInt(str3.substring(3,5),10); 
			var yr3   = parseInt(str3.substring(6,10),10); 
			var date1 = new Date(yr1, mon1, dt1); 
			var date2 = new Date(yr2, mon2, dt2); 
			var date3 = new Date(yr3, mon3, dt3); 
	if(Date.parse(date1)< Date.parse(date2))
	{	
			return(false);
	}
	//validate to date
	if(Date.parse(date1)>Date.parse(date3))
	{	
		return(false);
	}
	
	return(true);
}
function CheckYear(YearToCheck,YearGreater,YearLesser)
{
	if(YearToCheck<YearGreater || YearToCheck>YearLesser)
	{
		return false;
	}
	return true;
}
function CompareYear(YearFrom,YearToCheck)
{
	if(parseInt(YearFrom)<parseInt(YearToCheck))
	{
		return false;
	}
	return true;
}

				function isInteger(s){
					var i;
					for (i = 0; i < s.length; i++){   
						// Check that current character is number.
						var c = s.charAt(i);
						if (((c < "0") || (c > "9"))) return false;
					}
					// All characters are numbers.
					return true;
				}
				
				function IsFirstCharInteger(s){
					var i;
					var c = s.charAt(0);
					if (((c < "0") || (c > "9"))) return false;
					
					// First character is not number.
					return true;
				}

				function stripCharsInBag(s, bag){
					var i;
					var returnString = "";
					// Search through string's characters one by one.
					// If character is not in bag, append to returnString.
					for (i = 0; i < s.length; i++){   
						var c = s.charAt(i);
						if (bag.indexOf(c) == -1) returnString += c;
					}
					return returnString;
				}

				function daysInFebruary (year){
					// February has 29 days in any year evenly divisible by four,
					// EXCEPT for centurial years which are not also divisible by 400.
					return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
				}
				function DaysArray(n) {
					for (var i = 1; i <= n; i++) {
						this[i] = 31
						if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
						if (i==2) {this[i] = 29}
				} 
				return this
				}

				function isDateNew(dtStr, textValue){
				
				  
					var dtCh= "/";
					var minYear=1900;
					var maxYear=2100;
				
					var daysInMonth = DaysArray(12)
					var pos1=dtStr.indexOf(dtCh)
					var pos2=dtStr.indexOf(dtCh,pos1+1)
					//var strMonth=dtStr.substring(0,pos1)
					//var strDay=dtStr.substring(pos1+1,pos2)
					var strDay=dtStr.substring(0,pos1)
					var strMonth=dtStr.substring(pos1+1,pos2)
					var strYear=dtStr.substring(pos2+1)
					
					
					
					strYr=strYear
					if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
					if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
					for (var i = 1; i <= 3; i++) {
						if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
					}
					month=parseInt(strMonth)
					day=parseInt(strDay)
					year=parseInt(strYr)
					
					
					if (pos1==-1 || pos2==-1){
						alert("The date format should be : dd/mm/yyyy." +" Please enter valid date in "+textValue+".")
						return false
					}
					if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
						alert("Please enter a valid day")
						return false
					}
					if (strMonth.length<1 || month<1 || month>12){
						alert("Please enter a valid month")
						return false
					}
					if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
						alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
						return false
					}
					if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
						alert("Please enter a valid date")
						return false
					}
				return true
				}
				
				function isDate(dtStr){
				
					var dtCh= "/";
					var minYear=1900;
					var maxYear=2100;
				
					var daysInMonth = DaysArray(12)
					var pos1=dtStr.indexOf(dtCh)
					var pos2=dtStr.indexOf(dtCh,pos1+1)
					//var strMonth=dtStr.substring(0,pos1)
					//var strDay=dtStr.substring(pos1+1,pos2)
					var strDay=dtStr.substring(0,pos1)
					var strMonth=dtStr.substring(pos1+1,pos2)
					var strYear=dtStr.substring(pos2+1)
					
					
					
					strYr=strYear
					if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
					if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
					for (var i = 1; i <= 3; i++) {
						if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
					}
					month=parseInt(strMonth)
					day=parseInt(strDay)
					year=parseInt(strYr)
					if (pos1==-1 || pos2==-1){
						alert("The date format should be : dd/mm/yyyy")
						return false
					}
					if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month] || isNaN(day)){
						alert("Please enter a valid day")
						return false
					}
					if (strMonth.length<1 || month<1 || month>12 || isNaN(month)){
						alert("Please enter a valid month")
						return false
					}
					if (strYear.length != 4 || year==0 || year<minYear || year>maxYear || isNaN(year)){
						alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
						return false
					}
					if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
						alert("Please enter a valid date")
						return false
					}
				return true
				}

				//function ValidateDate(){
				//	var dt=document.frmSample.txtDate
				//	if (isDate(dt.value)==false){
				//		dt.focus()
				//		return false
				//	}
				//	return true
				//}

// END DATE VALIDATION

//---------------------------------------------------------------------------------------//

/// <summary>
/// <p>Author :							Sathya,Lakshmi,Nikil</p>
///	<p>Date:							Dec 2006</p>
///	<p>Version/Build No.:				1.0</p>
///	<p>Modified By:						Abhishek Khare</p>	
///	<p>Modification Date:				Null</p>	
///	<p>Dependencies:					Null</p>
///	<p>Purpose of the program:</p>
/// <p>Trim function for javascript, will return a trim string</p>
/// </summary>	
function IsEmpty(aTextField) 
{
   if ((aTextField.value.length==0) ||
   (aTextField.value==null) || (aTextField.value.trim()=='')) {
      return true;
   }
   else { return false; }
}

//function IsAlphaNumeric(anText)
//{
//  var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_-+={}[]|\:;'<>?,./ ";
//   /* var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_-+={}[]|\:;'>?,./ "; */
//   var IsAlphaNumber=true;
//   var Char;
// 
//   for (i = 0; i < anText.length && IsAlphaNumber == true; i++) 
//      { 
//      Char = anText.charAt(i); 
//      if (ValidChars.indexOf(Char) == -1) 
//         {
//         IsAlphaNumber = false;
//         }
//      }
//   return IsAlphaNumber;
//   
//}
//
function ValidateNumeric(elementid)
{
	var regNum = /^[0-9]*$/;
	if (regNum.test(document.getElementById(elementid).value)==false)
	{
		alert('You Can not Enter Negative Values or any Special Character in Amount');
		document.getElementById(elementid).value = '';
		document.getElementById(elementid).focus();
		return false;
	} 
	return true;
}		

function IsAlphaNumeric(anText)
{
   
   var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_-+={}[]|\:;'?,./ ";
   /* var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_-+={}[]|\:;'>?,./ "; */
   var IsAlphaNumber=true;
   var Char;
 
   for (i = 0; i < anText.length && IsAlphaNumber == true; i++) 
      { 
      Char = anText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsAlphaNumber = false;
         }
      }
   return IsAlphaNumber;
   
}

  function IsAlphaNumericSpecific(anText)
  {
			var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_- ";
			var IsAlphaNumber=true;
			var Char;
						
	     		for (i = 0; i < anText.length && IsAlphaNumber == true; i++) 
				{ 
		        		Char = anText.charAt(i); 
					if (ValidChars.indexOf(Char) == -1) 
					{
						IsAlphaNumber = false;
					}
				}
			return IsAlphaNumber;
					
 }

//
function Alpha(anText)
{
   var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._- ";
   var IsAlphaNumber=true;
   var Char;
 
   for (i = 0; i < anText.length && IsAlphaNumber == true; i++) 
      { 
      Char = anText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsAlphaNumber = false;
         }
      }
   return IsAlphaNumber;
   
}



function IsNumericOld(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}
// Checks whether Integer or not for integer fields...By sasmita Praharaj 12/12/2005
function isInteger(s)
{
	var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9")))
         return false;
    }
    // All characters are numbers.
    return true;
}
//By sasmita Praharaj




//function IsMonetry(sText)
//{
  // var ValidChars = "0123456789.-";
   //var IsMonetry=true;
   //var Char;
 
   //for (i = 0; i < sText.length && IsNumber == true; i++) 
     // { 
      //Char = sText.charAt(i); 
      //if (ValidChars.indexOf(Char) == -1) 
        // {
         //IsMonetry = false;
         //}
     // }
       //return (sText("-"));
  
   
//}



function isValidEmail(str) 
{
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

//DoEnabledDisabled

function DoEnabledDisabled(chkid, txtid) 
{
   if (chkid.checked)
   {	
	  txtid.disabled = false;
      return true;
   }
   else
   { 
	  txtid.disabled = true;  
	  return true;    
   }
}

/// <summary>
/// <p>Author :							Sathya,Lakshmi,Nikil</p>
///	<p>Date:							Dec 2006</p>
///	<p>Version/Build No.:				1.0</p>
///	<p>Modified By:						Sharif Arif</p>	
///	<p>Modification Date:				Null</p>	
///	<p>Dependencies:					Null</p>
///	<p>Purpose of the program:</p>
/// <p>For restricting against special characters in FA.</p>
/// </summary>
function IsEmail(strEmail) 
{ 
	var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_@.";
	var InvalidFirstChar="0123456789";	
		var IsEmail=true;
		var Char;
		
		for (i = 0; i < strEmail.length && IsEmail == true; i++) 
			{ 
			Char = strEmail.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) 
				{
				IsEmail = false;
				}
			}
				
		
			Char = strEmail.charAt(0); 
			
			if (InvalidFirstChar.indexOf(Char) == 1) 
				{
				IsEmail = false;
				}
			
		if( IsEmail==false)
		{
		    alert("Please enter valid E-mail ID");
		    return false;
		}
		
	if(strEmail.length == 0)
	{
		return true;
	}
    var at="@" ;
    var dot="." ;    
    var lat=strEmail.indexOf(at);
    var lstr=strEmail.length ;
    var ldot=strEmail.indexOf(dot) ;
    
    
    if (strEmail.indexOf(at)==-1)
    {
          alert("Please enter valid E-mail ID") ;
          return false ;
    }

    if (strEmail.indexOf(at)==-1 || strEmail.indexOf(at)==0 || strEmail.indexOf(at)==lstr)
    {
         alert("Please enter valid E-mail ID") ;
	    return false; 
    } 

	if (strEmail.indexOf(dot)==-1 || strEmail.indexOf(dot)==0 || strEmail.indexOf(dot)==lstr)
	{
			alert("Please enter valid E-mail ID") ;
			return false;
	} 

    if (strEmail.indexOf(at,(lat+1))!=-1)
    {
        alert("Please enter valid E-mail ID") ;
            return false;
     }
     if (strEmail.substring(lat-1,lat)==dot || strEmail.substring(lat+1,lat+2)==dot)
     {
			 alert("Please enter valid E-mail ID") ;
			return false ;
     }
     if (strEmail.indexOf(dot,(lat+2))==-1)
     { 
       alert("Please enter valid E-mail ID") ;
      return false ;
	}

	if (strEmail.indexOf(" ")!=-1)
	{
		 alert("Please enter valid E-mail ID") ;
		return false;
	}
	if(ldot>lat)
    {
       if( ldot+1==lstr)
       {
			alert("Please enter valid E-mail ID");
		    return false;
	   }
    }
    else
    {
        if(strEmail.lastIndexOf('.')+1==lstr )
        {
           	alert("Please enter valid E-mail ID");
		    return false;
	   }
    }
	
    return true;
 } 
/// <summary>
/// <p>Author :							Sathya,Lakshmi,Nikil</p>
///	<p>Date:							Dec 2006</p>
///	<p>Version/Build No.:				1.0</p>
///	<p>Modified By:						Null</p>	
///	<p>Modification Date:				Null</p>	
///	<p>Dependencies:					Null</p>
///	<p>Purpose of the program:</p>
/// <p>For restricting against special characters in FA.</p>
/// </summary>
function IsAlphaNumericSpecificFA(anText)
	{
		var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_- ";
		var IsAlphaNumber=true;
		var Char;
			
		for (i = 0; i < anText.length && IsAlphaNumber == true; i++) 
			{ 
			Char = anText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) 
				{
				IsAlphaNumber = false;
				}
			}
		return IsAlphaNumber;
		
	}

/// <summary>
/// <p>Author :							Sathya,Lakshmi,Nikil</p>
///	<p>Date:							Dec 2006</p>
///	<p>Version/Build No.:				1.0</p>
///	<p>Modified By:						Null</p>	
///	<p>Modification Date:				Null</p>	
///	<p>Dependencies:					Null</p>
///	<p>Purpose of the program:</p>
/// <p>For alert aginst atleast one selection for deletion. Without asking for confirmation.
///	As in FA we have done this through .net.</p>
/// </summary>
function checkbox_checker_Delete_WithoutConfirm(aspCheckBoxID)
{

//alert('jnmnk')
// set var checkbox_choices to zero
// + Form1.chkSelect.length)

var checkbox_choices = 0;
re = new RegExp(':' + aspCheckBoxID + '$');

// Loop from zero to the one minus the number of checkbox button selections
//for (counter = 0; counter < Form1.chkSelect.length; counter++)
for (counter = 0; counter < document.Form1.elements.length; counter++)
//document.Form1.elements.length
{
elm = Form1.elements[counter]
//if (elm.type == 'checkbox') {
//if (elm.name == 'chkSelect')
//{
	if (elm.type == 'checkbox')
		{
		if (re.test(elm.name))
			 {
				// If a checkbox has been selected it will return true
				// (If not it will return false)
					if (Form1.elements[counter].checked)
						{ 
						checkbox_choices = checkbox_choices + 1;
						}	
				}
	}
} // close for loop

//alert('total ' + checkbox_choices)



if (checkbox_choices == '0' )
{
// If there were more than three selections made display an alert box 
//msg="You're limited to only one selection.\n"
//msg=msg + "You have made " + checkbox_choices + " selections.\n"
//msg=msg + "No Item Selected for Editing"
//alert('No Item Selected for Deleting')
alert('Please select a record to delete.');
return (false);
}
/*else

// If three were selected then display an alert box stating input was OK
//confirm("Do u want to delete this records");
//return (confirm("Do u want to delete this records"));
return confirm('Are you sure you want to delete this record?');
*/
}

/// <summary>
/// <p>Author :							Sathya,Lakshmi,Nikil</p>
///	<p>Date:							Jan 2007</p>
///	<p>Version/Build No.:				1.0</p>
///	<p>Modified By:						Null</p>	
///	<p>Modification Date:				Null</p>	
///	<p>Dependencies:					Null</p>
///	<p>Purpose of the program:</p>
/// </summary>
function checkbox_checker_Delete_FY(aspCheckBoxID)
{

//alert('jnmnk')
// set var checkbox_choices to zero
// + Form1.chkSelect.length)

var checkbox_choices = 0;
re = new RegExp(':' + aspCheckBoxID + '$')  

// Loop from zero to the one minus the number of checkbox button selections
//for (counter = 0; counter < Form1.chkSelect.length; counter++)
for (counter = 0; counter < document.Form1.elements.length; counter++)
//document.Form1.elements.length
{
elm = Form1.elements[counter]
//if (elm.type == 'checkbox') {
//if (elm.name == 'chkSelect')
//{
	if (elm.type == 'checkbox')
		{
		if (re.test(elm.name))
			 {
				// If a checkbox has been selected it will return true
				// (If not it will return false)
					if (Form1.elements[counter].checked)
						{ 
						checkbox_choices = checkbox_choices + 1;
						}
				}
	}
} // close for loop

//alert('total ' + checkbox_choices)



if (checkbox_choices == '0' )
{
// If there were more than three selections made display an alert box 
//msg="You're limited to only one selection.\n"
//msg=msg + "You have made " + checkbox_choices + " selections.\n"
//msg=msg + "No Item Selected for Editing"
//alert('No Item Selected for Deleting')
alert('Please select a record to delete.');
return (false);
}
else
 if(checkbox_choices >1 )
	{
	// If three were selected then display an alert box stating input was OK
	//confirm("Do u want to delete this records");
	//return (confirm("Do u want to delete this records"));
	alert('Please select only one record to delete?');
	return false;
	}
 if (confirm('Are you sure you want to delete this record?'))
  {
     // alert('hgfh')
      return true;
  }
  else
  {
	// alert ('cancel is clicked')   
	// If user clicks on Cancel, then remove the selected check Boxes
				for (counter = 0; counter < document.Form1.elements.length; counter++)
				//document.Form1.elements.length
				{
				elm = Form1.elements[counter]
				//if (elm.type == 'checkbox') {
				//if (elm.name == 'chkSelect')
				//{
					if (elm.type == 'checkbox')
						{
						if (re.test(elm.name))
							{
								// If a checkbox has been selected it will return true
								// (If not it will return false)
									if (Form1.elements[counter].checked)
										{ 
										//checkbox_choices = checkbox_choices + 1;
										Form1.elements[counter].checked=false;
										}	
								}
					}
				} // close for loop
	 return false;	 
  }


}

//By sasmita Praharaj

function checkbox_checker_Delete(aspCheckBoxID)
{

		var checkbox_choices = 0;
		re = new RegExp(':' + aspCheckBoxID + '$')  

		// Loop from zero to the one minus the number of checkbox button selections

		for (counter = 0; counter < document.Form1.elements.length; counter++)
		{
			
			elm = Form1.elements[counter]
			if (elm.type == 'checkbox')
				{				    
				    
					//if (re.test(elm.name))
					//{
						// If a checkbox has been selected it will return true
						// (If not it will return false)
							if (Form1.elements[counter].checked)
							{ 
							   
								checkbox_choices = checkbox_choices + 1;
							}	
						//}
			}
		} // close for loop

		
		if (checkbox_choices == '0' )
		{
			// If there were more than three selections made display an alert box 
			alert('Please select a record to delete.')
			return (false);
		}
		else

		// If three were selected then display an alert box stating input was OK

		if (confirm('Do you want to delete selected record(s)?'))
		{
		    
			return true;      
		}
		else
		{
			
			// If user clicks on Cancel, then remove the selected check Boxes
			for (counter = 0; counter < document.Form1.elements.length; counter++)
			{
						elm = Form1.elements[counter]
						if (elm.type == 'checkbox')
						{
						if (re.test(elm.name))
						{
							// If a checkbox has been selected it will return true
							// (If not it will return false)
								if (Form1.elements[counter].checked)
									{ 
									//checkbox_choices = checkbox_choices + 1;
									Form1.elements[counter].checked=false;
									}	
							}
						}
			} // close for loop
			return false;	 
		}
		
}


// function for checking how many checkbox are selected

function checkbox_checker(aspCheckBoxID)
{
		// set var checkbox_choices to zero
		
		var checkbox_choices = 0;
		re = new RegExp(':' + aspCheckBoxID + '$')  //generated control name starts with a colon


		// Loop from zero to the one minus the number of checkbox button selections
		for (counter = 0; counter < document.Form1.elements.length; counter++)
		{

			elm = Form1.elements[counter]
		
			if (elm.type == 'checkbox')
			{
					if (re.test(elm.name))
					{
						// If a checkbox has been selected it will return true
								if (Form1.elements[counter].checked)
								{ 
								checkbox_choices = checkbox_choices + 1;
								}	
					}
			}
		} // close for loop

		if (checkbox_choices == '0' )
		{
			// If there were more than three selections made display an alert box 
		
			alert('Please select a record to modify.')
			return (false);
		}

		if (checkbox_choices > 1 )
		{
			// If there were more than three selections made display an alert box 
			msg="Please select one record to modify.\n";
			alert(msg);
			return (false);
		}

		// If three were selected then display an alert box stating input was OK
		return (true);
}

// function for checking how many checkbox are selected

function checkbox_checker_FY(aspCheckBoxID)
{

//alert('jnmnk')


// set var checkbox_choices to zero

// + Form1.chkSelect.length)

var checkbox_choices = 0;
re = new RegExp(':' + aspCheckBoxID + '$')  //generated control name starts with a colon


// Loop from zero to the one minus the number of checkbox button selections
//for (counter = 0; counter < Form1.chkSelect.length; counter++)
for (counter = 0; counter < document.Form1.elements.length; counter++)
//document.Form1.elements.length
{


elm = Form1.elements[counter]

//if (elm.type == 'checkbox') {
//if (elm.name == 'chkSelect')
//{

	if (elm.type == 'checkbox')
	{
		if (re.test(elm.name))
			 {
				// If a checkbox has been selected it will return true
				// (If not it will return false)
					if (Form1.elements[counter].checked)
						{ 
						checkbox_choices = checkbox_choices + 1;
						}	
				}
	}
} // close for loop

//alert('total ' + checkbox_choices)



if (checkbox_choices == '0' )
{
// If there were more than three selections made display an alert box 
//msg="You're limited to only one selection.\n"
//msg=msg + "You have made " + checkbox_choices + " selections.\n"
//msg=msg + "No Item Selected for Editing"
//Please select a record to be modified
//alert('Please select record to be modified')
alert('Please select a record to modify.')
//alert('No Item Selected for Editing')
return (false);
}

if (checkbox_choices > 1 )
{
// If there were more than three selections made display an alert box 
msg="You're limited to only one selection.\n";
msg=msg + "You have made " + checkbox_choices + " selections.\n";
msg=msg + "Please remove " + (checkbox_choices-1) + " selection(s).";
alert(msg);
return (false);
}

if (checkbox_choices == 1 )
{
	if(confirm('Are you sure for updation against Financial Year.'))
	{
		return true;
	}
	return (false);
}

// If three were selected then display an alert box stating input was OK
////////alert(" *** Valid input of three outfielders was entered. ***");
return (true);
}

/// <summary>
/// <p>Author :							Sathya,Lakshmi,Nikil </p>
///	<p>Date:							Jan 2007</p>
///	<p>Version/Build No.:				1.0</p>
///	<p>Modified By:						Null</p>	
///	<p>Modification Date:				Null</p>	
///	<p>Dependencies:					Null</p>
///	<p>Purpose of the program:</p>
/// <p>For alert aginst atleast one or more selection for process batch/or multi deletion. Without asking for confirmation.
///	As in FA we have done this through .net.</p>
/// </summary>


function checkbox_Multichecker(aspCheckBoxID)
{



var checkbox_choices = 0;
re = new RegExp(':' + aspCheckBoxID + '$')  //generated control name starts with a colon


// Loop from zero to the one minus the number of checkbox button selections
//for (counter = 0; counter < Form1.chkSelect.length; counter++)
for (counter = 0; counter < document.Form1.elements.length; counter++)
//document.Form1.elements.length
{


elm = Form1.elements[counter]



	if (elm.type == 'checkbox')
	{
		if (re.test(elm.name))
			 {
				// If a checkbox has been selected it will return true
				// (If not it will return false)
					if (Form1.elements[counter].checked)
						{ 
						checkbox_choices = checkbox_choices + 1;
						
						}	
				}
	}
} // close for loop

//alert('total ' + checkbox_choices)



if (checkbox_choices == '0' )
{
// If there were more than three selections made display an alert box 
//msg="You're limited to only one selection.\n"
//msg=msg + "You have made " + checkbox_choices + " selections.\n"
//msg=msg + "No Item Selected for Editing"
//Please select a record to be modified
//alert('Please select record to be modified')
alert('Please select a Batch to process.')
//alert('No Item Selected for Editing')
return (false);
}
if (checkbox_choices > '1' )
{

alert('Please select a only one Batch to Process.')

return (false);
}

// If three were selected then display an alert box stating input was OK
////////alert(" *** Valid input of three outfielders was entered. ***");
return (true);
}



//******************************************************
function resetDefaultValues()
{
alert('Hello');
document.Form1.reset();
alert('hi');


for (counter = 0; counter < document.Form1.elements.length; counter++)
//document.Form1.elements.length
{
elm = Form1.elements[counter]

//if (elm.type == 'checkbox') {
//if (elm.name == 'chkSelect')
//{

alert(elm.type)

if (elm.type == 'text')
	{
		Form1.elements[counter].value = "";
	}
if (elm.type == 'select-one')
	{
		Form1.elements[counter].selectedindex = -1;
	}	

	
} // close for loop


///var what = 'Form1';
////    for (var i=0, j=what.elements.length; i<j; i++) 
////    {
////        myName = what.elements[i].name;
////		    if (myName.indexOf('checkbox') > -1 || myName.indexOf('radio') > -1)
////					what.elements[i].checked = what.elements[i].defaultChecked;
////			if (myName.indexOf('hidden') > -1 || myName.indexOf('password') > -1 || myName.indexOf('text') > -1)
///					what.elements[i].value = what.elements[i].defaultValue;
////			if (myName.indexOf('select') > -1)
////				for (var k=0, l=what.elements[i].options.length; k<l; k++)
////					what.elements[i].options[k].selected = what.elements[i].options[k].defaultSelected;
////    }
}





// ** function for RESET

function DoReset()
{

// Loop from zero to the one minus the number of checkbox button selections
//for (counter = 0; counter < Form1.chkSelect.length; counter++)
for (counter = 0; counter < document.Form1.elements.length; counter++)
//document.Form1.elements.length
{
elm = Form1.elements[counter]

//if (elm.type == 'checkbox') {
//if (elm.name == 'chkSelect')
//{

if (elm.type == 'TextBox')
	{
		Form1.elements[counter].value = "";
	}

	
} // close for loop


// If three were selected then display an alert box stating input was OK
////////alert(" *** Valid input of three outfielders was entered. ***");
return (true);
}
//************************CheckDateRange****************************
/// <summary>
/// <p>Author :							Sathya,Lakshmi,Nikil</p>
///	<p>Date:							Dec 2006</p>
///	<p>Version/Build No.:				1.0</p>
///	<p>Modified By:						Null</p>	
///	<p>Modification Date:				Null</p>	
///	<p>Dependencies:					Null</p>
///	<p>Purpose of the program:</p>
/// <p>For checking any input date with in two date range.</p>
/// </summary>
function CheckDateRange(txtDate,FromDate,ToDate)
{ 

 
	
	
	//check from date
			var str1  = txtDate; 
			var str2  = FromDate; 
			var str3 = ToDate;
			var dt1   = parseInt(str1.substring(0,2),10); 
			var mon1  = parseInt(str1.substring(3,5),10); 
			var yr1   = parseInt(str1.substring(6,10),10); 
			var dt2   = parseInt(str2.substring(0,2),10); 
			var mon2  = parseInt(str2.substring(3,5),10); 
			var yr2   = parseInt(str2.substring(6,10),10); 
			var dt3   = parseInt(str3.substring(0,2),10); 
			var mon3  = parseInt(str3.substring(3,5),10); 
			var yr3   = parseInt(str3.substring(6,10),10); 
			var date1 = new Date(yr1, mon1-1, dt1); 
			var date2 = new Date(yr2, mon2-1, dt2); 
			var date3 = new Date(yr3, mon3-1, dt3); 
	if(str1.length>10)
	{
	alert("The date format should be : dd/mm/yyyy");
		return(false);
	}
	if(Date.parse(date1)< Date.parse(date2))
	{
		
	
		alert("Date cannot be less than " + FromDate);
		return(false);
	}
	  

	//validate to date
	
	
	if(Date.parse(date1)>Date.parse(date3))
	{
		alert("Date cannot be greater than " + ToDate);
		return(false);
	}
	

	return(true);
}



// ########### Only Float Value is entered ############
				function checkFloatValue(control)
				{
					if (event.keyCode < 46 || event.keyCode > 57) 
					{						
						event.returnValue = false;
					}	
					else if(event.keyCode == 46) // Allows only single (.).
					{
						//if(document.all['txtLowerLimit'].value.indexOf('.') != -1) 
						if(control.value.indexOf('.') != -1) 
						{
							event.returnValue = false;											
						}	
					}
					else if(event.keyCode == 47)  // Do not allow (-).
					{						
						event.returnValue = false;
					}							
				}
				// #################################
				
//-----------Validation of Numeric Data--------


// ########### Only Int Value is entered ############
				function checkIntValue(control)
				{
					if (event.keyCode < 46 || event.keyCode > 57) 
					{						
						event.returnValue = false;
					}	
					else if(event.keyCode == 46) // Allows only single (.).
					{
						//if(document.all['txtLowerLimit'].value.indexOf('.') != -1) 
						
						
							event.returnValue = false;											
							
					}
					else if(event.keyCode == 47)  // Do not allow (-).
					{						
						event.returnValue = false;
					}							
				}
				// #################################
				
//-----------Validation of Numeric Data--------
	function IsNumeric(sText)
	{
		var ValidChars = "0123456789.";
		var IsNumber=true;
		var Char;
		var DotPos = 0;
		if (sText.length == 1 && sText.charAt(0) == '.') 
		{
			IsNumber = false;
			return IsNumber;
		}
		if (sText.charAt(sText.length - 1) == '.') 
		{
			IsNumber = false;
			return IsNumber;
		}
		for (i = 0; i < sText.length && IsNumber == true; i++) 
		{ 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) 
			{
				IsNumber = false;
				return IsNumber;
			}					
			
			if(Char == '.')
			{
				var DotPos = DotPos + 1;					
			}
			if(DotPos >1)
			{
				IsNumber = false;
				return IsNumber;					
			}
		
		}
	return IsNumber;
			
	}
//------------Validation of Numeric Data-------------	

// ############ Added By Abhinav ##############

	// Only Positive Float Value is entered 
	function checkFlaot(control)
	{
		if (event.keyCode < 46 || event.keyCode > 57) 
		{						
			event.returnValue = false;
		}	
		else if(event.keyCode == 46) // Allows only single (.).
		{
			//if(document.all['txtLowerLimit'].value.indexOf('.') != -1) 
			if(control.value.indexOf('.') != -1) 
			{
				event.returnValue = false;											
			}	
		}
		else if(event.keyCode == 47)  // Do not allow (-).
		{						
			event.returnValue = false;
		}							
	}

// ############################################


//------------Validation of Check Time -------------	

// ############ Added By Subramanian ##############


function IsValidTime(timeStr) {
// Checks if time is in HH:MM:SS AM/PM format.
// The seconds and AM/PM are optional.

var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

var matchArray = timeStr.match(timePat);
if (matchArray == null) 
{
	alert("Time is not in a valid format.");
	return (false);
}
hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 23) 
{
	alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
	return (false);
}

if (hour <= 12 && ampm == null)
 {
	if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) 
	{
	alert("You must specify AM or PM.");
	return (false);
	}
}
if  (hour > 12 && ampm != null) 
{
	alert("You can't specify AM or PM for military time.");
	return (false);	
}
if (minute<0 || minute > 59) 
{
	alert ("Minute must be between 0 and 59.");
	return (false);
}
if (second != null && (second < 0 || second > 59))
 {
	alert ("Second must be between 0 and 59.");
	return (false);
}
return (true);
}

// ############################################

// ############################################
// -- Session Time Out Alert Message after 30 mins 
// ############################################
	function checkSessionTimeOut()
	{
		setTimeout("showMessage()",1800000);	
		//setTimeout("openPoPUp()",10000);
		//setTimeout("showMessage()",18000);	
	}
	function openPoPUp()
	{
		var opn;
		opn = window.open('../SessionTimeOutTimer.htm','','width=320,height=100,resizable=no,scrollbars=no,toolbars=no');
		opn.focus();
		return false;
		
	}
	function showMessage()
	{
		alert("Your Session will expire in 10 minutes, Please save your work.");
	}
// ############################################

function checkbox_checker_Select(aspCheckBoxID)
{
	var checkbox_choices = 0;
	re = new RegExp(':' + aspCheckBoxID + '$')  

	for (counter = 0; counter < document.Form1.elements.length; counter++)
	{
	elm = Form1.elements[counter]
		if (elm.type == 'checkbox')
			{
			if (re.test(elm.name))
				{
						if (Form1.elements[counter].checked)
							{ 
							checkbox_choices = checkbox_choices + 1;
							}	
					}
		}
	} 
	if (checkbox_choices == '0' )
	{
	alert('Please select atleast one Record.')
	return (false);
	}
	else
	{
	return true;
	}
	
}
function DateConversionMMM_MM(gdate)
{
	
	var SDate=gdate.split("-");
	var arr=new Array();
	arr[1]="Jan";
	arr[2]="Feb";
	arr[3]="Mar";
	arr[4]="Apr";
	arr[5]="May";
	arr[6]="Jun";
	arr[7]="Jul";
	arr[8]="Aug";
	arr[9]="Sep";
	arr[10]="Oct";
	arr[11]="Nov";
	arr[12]="Dec";
	var mon;
	for(i=1;i<=12;i++)
	{
	//alert(SDate[1]);
		if(arr[i]==SDate[1])
		{
			mm=i;
			if(mm<9)
			{
				mon="0"+mm;
			}
			else
			{
				mon=mm;
			}
		}
	}
	return (mon+"/"+SDate[0]+"/"+SDate[2]);
}
//To get todays Date in 01/01/2006(mm/dd/yy) format
function ToDayDate()
{
		var  TodayDate=new Date();
		 var TodayDay=TodayDate.getDate();
		 var TodayMonth=TodayDate.getMonth();
		 var TodayYear=TodayDate.getYear();
		 TodayMonth=parseInt(TodayMonth)+parseInt(1);
		 if(TodayMonth<9)
		 {
			TodayMonth="0"+TodayMonth;
		 }
		 if(TodayDay<9)
		 {
			TodayDay="0"+TodayDay;
		 }
		 var Tdate=TodayMonth+"/"+TodayDay+"/"+TodayYear;
		 return Tdate;
}
function ConvertDateMDY(DateValue)
{
		var dt1   = DateValue.substring(0,2); 
		var mon1  = DateValue.substring(3,5); 
		var yr1   = DateValue.substring(6,10); 
		var newDateValue = mon1 + '/' + dt1 + '/' + yr1;
		
		return newDateValue;
}

function ConvertDateDMY(DateValue1)
{
		var mon1   = DateValue1.substring(0,2); 
		var dt1  = DateValue1.substring(3,5); 
		var yr1   = DateValue1.substring(6,10); 
		var newDateValue1 = dt1 + '/' + mon1 + '/' + yr1;
		
		return newDateValue1;
}

//Validating  Date and format (dd/MM/yyyy)
function validateDate(fld)
{
	
	if(fld.value != "")
	{
		var RegExPattern = /^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((1[6-9]|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/;	
		var errorMessage = 'Please enter valid date as DAY, Month, and Four Digit Year.\nYou may use a slash to separate the values.\n Valid Date Format is (dd/mm/yyyy)';
		if (((fld.value).match(RegExPattern)) && (fld.value!=''))
		{
			return true;
		}
		else 
		{
			alert(errorMessage);
			fld.value ="";
			fld.focus();
			return false;
		}
	}
	else
	{return true;}	
}

// Date format should be dd/MM/yyyy
function CheckDateInRangeDMY(txtDate,FromDate,ToDate)
{ 	//check from date
			var str1  = txtDate.split("/"); 
			var str2  = FromDate.split("/"); 
			var str3 = ToDate.split("/");
			
			var dt1   = parseInt(str1[0],10); 
			var mon1  = parseInt(str1[1],10); 
			var yr1   = parseInt(str1[2],10); 
			var dt2   = parseInt(str2[0],10); 
			var mon2  = parseInt(str2[1],10); 
			var yr2   = parseInt(str2[2],10); 
			var dt3   = parseInt(str3[0],10); 
			var mon3  = parseInt(str3[1],10); 
			var yr3   = parseInt(str3[2],10); 
			
			var date1 = new Date(yr1, mon1-1, dt1); 
			var date2 = new Date(yr2, mon2-1, dt2); 
			var date3 = new Date(yr3, mon3-1, dt3); 
	
	if(Date.parse(date1)< Date.parse(date2))
	{	
			return(false);
	}
	//validate to date
	if(Date.parse(date1)>Date.parse(date3))
	{	
		return(false);
	}
	
	return(true);
}
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}