﻿function checkDelete()
{
  var i;
  var checkCount=0;
  for(i=0; i < document.forms[0].elements.length; i++)
  {
    if(document.forms[0].elements[i].type == "checkbox")
    if (document.forms[0].elements[i].checked)
    checkCount++;
  }
  if (checkCount == 0)
  {
    alert('<%=RPM.Common.Utility.GetMessage("005")%>');
    return false;
  }   
  else
  {
    return confirm('<%=RPM.Common.Utility.GetMessage("004")%>');        
  } 
  return true;
}   

function CompareDates(strDateFrom, strDateTo)
{	
    
        
    var d1_str = ReplaceMonth(strDateFrom);
    var d2_str = ReplaceMonth(strDateTo);
    
    var d1 = new Date(d1_str.split('-')[2],d1_str.split('-')[1],d1_str.split('-')[0]);
    var d2 = new Date(d2_str.split('-')[2],d2_str.split('-')[1],d2_str.split('-')[0]);
   
    if (d1.getTime()>=d2.getTime())
      
	    return false;
	 
    else
	    return true;
}


function ReplaceMonth(strDate)
{
	var arrAlphaMonths = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
	var arrMonths = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
	for (var i = 0; i < arrAlphaMonths.length; i++)
		strDate = strDate.replace(arrAlphaMonths[i], arrMonths[i]);				
	return strDate;
}

function checkActive()
{
  var i;
  var checkCount=0;
  for(i=0; i < document.forms[0].elements.length; i++)
  {
    if(document.forms[0].elements[i].type == "checkbox")
    if (document.forms[0].elements[i].checked)
    checkCount++;
  }
  if (checkCount == 0)
  {
    alert('<%=RPM.Common.Utility.GetMessage("003")%>');
    return false;
  }   
  else
  {
    return confirm('<%=RPM.Common.Utility.GetMessage("002")%>');        
  } 
  return true;
}  


function CheckDateFormat(src)
{
	var dateReg = new RegExp("((31(?!-(Feb|Apr|Jun|(Sep|Nov))))|((30|29)(?!-Feb))|(29(?=-Feb-(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\\d|2[0-8])-(Jan|Feb|Ma(r|y)|Apr|Jul|Jun|Aug|Oct|Sep|Nov|Dec)-((1[6-9]|[2-9]\\d)\\d{2})");
	var regex = new RegExp(dateReg);
	if (regex.test(src))
	{
	    var date_array = src.split('-');
      var day = date_array[0];
      
      var month = ReplaceMonth(date_array[1]) - 1;
      var year = date_array[2];

      source_date = new Date(year, month, day);
      
      if(year != source_date.getFullYear())
         return false;

      if(month != source_date.getMonth())
         return false;

      if(day != source_date.getDate())
         return false;
         
      return true;   
	}  
  else 
    return false;
}

function checkInactive()
{
  var i;
  var checkCount=0;
  for(i=0; i < document.forms[0].elements.length; i++)
  {
    if(document.forms[0].elements[i].type == "checkbox")
    if (document.forms[0].elements[i].checked)
    checkCount++;
  }
  if (checkCount == 0)
  {
    alert('<%=RPM.Common.Utility.GetMessage("001")%>');
    return false;
  }   
  else
  {
    return confirm('<%=RPM.Common.Utility.GetMessage("002")%>');        
  } 
  return true;
}  

/* 
  Function to check dates begins 
  strDateFrom: From date
  strDateTo: To date
*/
//Created By: Mohit Malik
//Creation date: 23-Feb-09
function CompareDates(strDateFrom, strDateTo)
{	
    var d1_str = ReplaceMonth(strDateFrom);
    var d2_str = ReplaceMonth(strDateTo);
    
    var d1 = new Date(d1_str.split('-')[2],d1_str.split('-')[1],d1_str.split('-')[0]);
    var d2 = new Date(d2_str.split('-')[2],d2_str.split('-')[1],d2_str.split('-')[0]);

    if (d1.getTime()>=d2.getTime())
	    return false;
    else
	    return true;
}

/* 
  Function to check from date 
  strDateFrom: From date
  strDateTo: To date
*/
//Created By: Mohit Malik
//Creation date: 23-Feb-09
function CompareFromDate(strDateFrom, strDateTo)
{	
    var d1_str = ReplaceMonth(strDateFrom);
    var d2_str = ReplaceMonth(strDateTo);
    
    var d1 = new Date(d1_str.split('-')[2],d1_str.split('-')[1],d1_str.split('-')[0]);
    var d2 = new Date(d2_str.split('-')[2],d2_str.split('-')[1],d2_str.split('-')[0]);

    if (d1.getTime()>d2.getTime())
	    return false;
    else
	    return true;
}

/* 

  var strDateFrom = document.getElementById("<%=txtDesiredMoveInDate.ClientID%>").value;                  
            if ((document.getElementById("<%=txtDesiredMoveInDate.ClientID%>").value != "MM/DD/YYYY")) {
                var d1_str = strDateFrom;               
                var x = d1_str.split("/");                 
                var d1 = new Date(x[2], (x[0] - 1), x[1]);               
                var today = new Date();       
                if (d1.getTime() > today.getTime()) {                                 
                    return true;
                }
                else {
                    alert("MoveIn Date should be future Date.");
                    return false;
                }


Function to check from date 
strDateFrom: From date
strDateTo: To date
*/
//Created By: Satish Srivastva
//Creation date: 29 Aug 2009
function CompareFromUKDate(strDateFrom, strDateTo) {

    var d1_str = strDateFrom;
    var x = d1_str.split("/");
    var d1 = new Date(x[2], (x[0] - 1), x[1]);

    var d2_str = strDateTo;
    var y = d2_str.split("/");
    var d2 = new Date(y[2], (y[0] - 1), y[1]);

    if (d1.getTime() > d2.getTime()) {
        return false;
    }
    else {        
        return true;
    } 
    
//    var d1_str = ReplaceMonth(strDateFrom);
//    var d2_str = ReplaceMonth(strDateTo);
//    
//    var d1 = new Date(d1_str.split('/')[2],d1_str.split('/')[1],d1_str.split('/')[0]);
//    var d2 = new Date(d2_str.split('/')[2],d2_str.split('/')[1],d2_str.split('/')[0]);

//    if (d1.getTime()>d2.getTime())
//	    return false;
//    else
//	    return true;
}

/* 
  Checks string for date format 
  src: String to be checked
*/
//Created By: Mohit Malik
//Creation date: 23-Feb-09
function CheckDateFormat(src)
{
	var dateReg = new RegExp("((31(?!-(Feb|Apr|Jun|(Sep|Nov))))|((30|29)(?!-Feb))|(29(?=-Feb-(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\\d|2[0-8])-(Jan|Feb|Ma(r|y)|Apr|Jul|Jun|Aug|Oct|Sep|Nov|Dec)-((1[6-9]|[2-9]\\d)\\d{2})");
	var regex = new RegExp(dateReg);
	if (regex.test(src))
	{
	    var date_array = src.split('-');
      var day = date_array[0];
      
      var month = ReplaceMonth(date_array[1]) - 1;
      var year = date_array[2];

      source_date = new Date(year, month, day);
      
      if(year != source_date.getFullYear())
         return false;

      if(month != source_date.getMonth())
         return false;

      if(day != source_date.getDate())
         return false;
         
      return true;   
	}  
  else 
    return false;
}


/* Allows only numbers and alphabets */
/* Update by Satish below the commented line on 04 Apr 09*/
function alpanumeric_only(e) 
{
  var iKeyCode = 0;
  if (window.event) 
    iKeyCode = window.event.keyCode 
  else if (e) 
     iKeyCode = e.which; 
     
 //if(((iKeyCode >= 48) && (iKeyCode < 58)  || (iKeyCode >=97) && (iKeyCode <=122) || (iKeyCode == 32) || (iKeyCode == 13)) || ((iKeyCode >=65) && (iKeyCode <=90) || (iKeyCode == 32) || (iKeyCode == 13)))  
if(((iKeyCode >=48) && (iKeyCode <=58) || (iKeyCode >=97) && (iKeyCode <=122) || (iKeyCode == 32) || (iKeyCode == 92) || (iKeyCode == 8) || (iKeyCode == 0)) || ((iKeyCode >=65) && (iKeyCode <=90) || (iKeyCode == 09) || (iKeyCode == 32) || (iKeyCode == 13) || (iKeyCode == 92) || (iKeyCode == 8) || (iKeyCode == 0))) 
  {
   return true;     
  }
  else 
  { 
   if(navigator.appName == "Microsoft Internet Explorer") 
   {
     alert("This field only allows alphanumeric characters. Please do not insert any symbols.");
     window.event.keyCode = null;
     return false;
   }
   else if(navigator.appName == "Netscape")
   {
    
     alert("This field only allows alphanumeric characters. Please do not insert any symbols.");
     return false; 
   } 
  }
  
}  

function alpanuic_only(e) 
{
   var iKeyCode = 0;
  if (window.event) 
    iKeyCode = window.event.keyCode 
  else if (e) 
     iKeyCode = e.which; 
 //if(((iKeyCode >= 48) && (iKeyCode < 58)  || (iKeyCode >=97) && (iKeyCode <=122) || (iKeyCode == 32) || (iKeyCode == 13)) || ((iKeyCode >=65) && (iKeyCode <=90) || (iKeyCode == 32) || (iKeyCode == 13)))  
if(((iKeyCode >=97) && (iKeyCode <=122) || (iKeyCode == 32) || (iKeyCode == 92) || (iKeyCode == 8) || (iKeyCode == 0)) || ((iKeyCode >=65) && (iKeyCode <=90) || (iKeyCode == 09) || (iKeyCode == 32) || (iKeyCode == 13) || (iKeyCode == 92) || (iKeyCode == 8) || (iKeyCode == 0))) 
  {
   return true;     
  }
  else 
  { 
   if(navigator.appName == "Microsoft Internet Explorer") 
   {
     alert("This field only allows alphanumeric characters. Please do not insert any symbols.");
     window.event.keyCode = null;
     return false;
   }
   else if(navigator.appName == "Netscape")
   {
    
     alert("This field only allows alphanumeric characters. Please do not insert any symbols.");
     return false; 
   } 
  }
}   



/* Allows only alphabets */
//Created By: Mohit Malik
//Creation Date: 03-Mar-09
function alphabets_only(e) 
{
  var iKeyCode = 0;
  if (window.event) 
     iKeyCode = window.event.keyCode;
  else if (e) 
      iKeyCode = e.which; 
  if(((iKeyCode >=97) && (iKeyCode <=122) || (iKeyCode == 32) || (iKeyCode == 92) || (iKeyCode == 8) || (iKeyCode == 0)) || ((iKeyCode >=65) && (iKeyCode <=90) || (iKeyCode == 09) || (iKeyCode == 32) || (iKeyCode == 13) || (iKeyCode == 92) || (iKeyCode == 8) || (iKeyCode == 0))) 
  {
    return true;
  }
  else
  { 
    if(navigator.appName == "Microsoft Internet Explorer")
    {
      alert("This field only allows letters. Please do not insert numbers or symbols.");
      window.event.keyCode = null;
      return false;
    }
    else if(navigator.appName == "Netscape")
    {     
      alert("This field only allows letters. Please do not insert numbers or symbols.");
      return false; 
    } 
  }
}
/* Allows only numeric values */
//Created By: Vikash Kr. Gupta
//Creation Date: 25-Aug-09
function numeric_only(e) 
{
  var iKeyCode = 0;
  if (window.event) 
    iKeyCode = window.event.keyCode 
  else if (e) 
     iKeyCode = e.which; 
     
 
if((iKeyCode >=48) && (iKeyCode <=58) ) 
  {
   return true;     
  }
  else 
  { 
   if(navigator.appName == "Microsoft Internet Explorer") 
   {
     alert("Please enter only numeric characters.");
     window.event.keyCode = null;
     return false;
   }
   else if(navigator.appName == "Netscape")
   {
    
     alert("Please enter only numeric characters.");
     return false; 
   } 
  }
  
}  


