function getMonthLen(theYear, theMonth) 
{
	var oneHour = 1000 * 60 * 60
	var oneDay = oneHour * 24
	var thisMonth = new Date(theYear, theMonth, 1)
	var nextMonth = new Date(theYear, theMonth + 1, 1)
	var len = Math.ceil((nextMonth.getTime() - thisMonth.getTime() - oneHour)/oneDay)
	return len
}
function IsNumeric(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;
	
}
function imposeMaxLength(id, MaxLen)
{
 if (document.getElementById(id).value.length>=MaxLen)
 {
	document.getElementById(id).value = document.getElementById(id).value.substring(0,MaxLen);
	alert("Max length limit ("+MaxLen+" characters) exceeded");
 }
  return (document.getElementById(id).value.length <= MaxLen);
}

function NavigatingDataGrid(oDataGrid,field, divId) 
{ 
  var search_index = 0;
  var str="";
  var obj =  document.getElementById(oDataGrid);
  if(obj != null)
  {
	if(field.value.length > 0)
	{ 
		for(j = 0; j < obj.childNodes.length; j++) 
		{ 
			var tBody = obj.childNodes(j); 
			for(k=1;k < tBody.childNodes.length; k++) 
			{ 
				var tr = tBody.childNodes(k); 
				var val = tr.childNodes[1].innerText.substring(0, field.value.length);
				str = val.toLowerCase();
				searchVal = field.value.toLowerCase();
				if(str.indexOf(searchVal, 0) >= 0)
				{
					if(search_index == 0)
					{
						search_index = k;
					}
					tr.childNodes[1].style.backgroundColor='#D3EBFF';
				}
				else
				{
					tr.childNodes[1].style.backgroundColor='white';
				}	        
			}
			document.getElementById(divId).scrollTop = ((search_index-1)*25);
		}
	}
	else if(field.value.length==0)
	{
		for(j = 0; j < obj.childNodes.length; j++) 
		{ 
			var tBody = obj.childNodes(j); 
			for(k=1;k < tBody.childNodes.length-1; k++) 
			{ 
				var tr = tBody.childNodes(k); 
				var val = tr.childNodes[1].innerText.substring(0, field.value.length);
				str = val.toLowerCase();
				searchVal = field.value.toLowerCase();
				tr.childNodes[1].style.backgroundColor='white';
			} 
		}
		document.getElementById(divId).scrollTop = 0;
	   
	}
	}
   
}

function findIt(sel,field)
{
	selobj = document.getElementById(sel);
	
	var len = selobj.options.length;

	if(field.value.length > 0)
	{               			
		for(var i = 0 ; i < len ; i++)
		{
			var val = selobj.options[i].text.substring(0, field.value.length);
			str = val.toLowerCase();
			searchVal = field.value.toLowerCase();
			if(str.indexOf(searchVal, 0) >= 0)
			{
				selobj.options[i].selected = true;
				break;
			}
		} 
	}
}

function PrintThisPage()
{
	window.print();
	return false;
}
function selectAll(chkval,dgrdId)
{
	//alert(document.getElementById(dgrdId).childNodes[0].childNodes.length);
	var len = document.getElementById(dgrdId).childNodes[0].childNodes.length;
	for(var i=0;i<=len;i++)
	{	
		var elemName = document.getElementById(dgrdId+'__ctl'+i+'_chkSelect'); 
		if(elemName!=null)
		{
			elemName.checked=chkval;
			HighlightRow(elemName);
		}
	}
}
			
		  
function deselectMain(dgrdId)
{
	
	if(document.getElementById(dgrdId+'__ctl1_chkSelectAll')!=null)
	{
		
		document.getElementById(dgrdId+'__ctl1_chkSelectAll').checked=false;
	}
}
function HighlightRow(chkB)
{
  
   var xState=chkB.checked;

   if(xState)
   {
    chkB.parentElement.parentElement.style.backgroundColor='#D3EBFF';
    //chkB.parentElement.parentElement.style.color='white';
   }
   else
  {
    chkB.parentElement.parentElement.style.backgroundColor='white';
    //chkB.parentElement.parentElement.style.color='black';
  }
}
function HighlightRowForEdit(chkB)
{
  
 
 for(var i=1;i<chkB.parentElement.parentElement.parentElement.childNodes.length;i++)
 {
	chkB.parentElement.parentElement.parentElement.childNodes[i].style.backgroundColor='white';
 }
 //chkB.parentElement.parentElement.childNodes);
   chkB.parentElement.parentElement.style.backgroundColor='#D3EBF0';
  
}
function DeleteMappedUsers(GridId)
 {
	var len = document.getElementById(GridId).childNodes[0].childNodes.length;
	for(var i=0;i<=len;i++)
	{
		if(document.getElementById(GridId+"__ctl"+i+"_chkSelect")==null)
		{
			continue;
		}
		else
		{
			if((document.getElementById(GridId+"__ctl"+i+"_chkSelect")).checked==true)
				{
					return(confirm("Are you sure you want to delete the selected mapped user?"));
				}
						
		}
	}
	alert("Select entry to delete");
	return false;
	
 }
function IsSomeCheckBoxChecked(GridId)
 {
	//for(i=0;i<document.forms[0].elements.length;i++)
	var len = document.getElementById(GridId).childNodes[0].childNodes.length;
	for(var i=0;i<=len;i++)
	{
		if(document.getElementById(GridId+"__ctl"+i+"_chkSelect")==null)
		{
			continue;
		}
		else
		{
			if((document.getElementById(GridId+"__ctl"+i+"_chkSelect")).checked==true)
				{
					return(confirm("Are you sure you want to delete the selected user(s)?"));
				}
						
		}
	}
	alert("Select a user to delete");
	return false;
	
 }
  function IsSomeCheckBoxChecked_Keycontrol(GridId)
 {
	//for(i=0;i<document.forms[0].elements.length;i++)
	var len = document.getElementById(GridId).childNodes[0].childNodes.length;
	for(var i=0;i<=len;i++)
	{
		if(document.getElementById(GridId+"__ctl"+i+"_chkSelect")==null)
		{
			continue;
		}
		else
		{
			if((document.getElementById(GridId+"__ctl"+i+"_chkSelect")).checked==true)
				{
					return(confirm("Are you sure you want to delete the selected compliance area(s)?"));
				}
						
		}
	}
	alert("Select a compliance area to delete");
	return false;
	
 }
 function IsSomeCheckBoxChecked_Transfer(GridId)
 {
	var len = document.getElementById(GridId).childNodes[0].childNodes.length;
	for(var i=0;i<=len;i++)
	{
		if(document.getElementById(GridId+"__ctl"+i+"_chkSelect")==null)
		{
			continue;
		}
		else
		{
			if((document.getElementById(GridId+"__ctl"+i+"_chkSelect")).checked==true)
				{
					return(confirm("Are you sure you want to transfer this record?"));
				}
						
		}
	}
	alert("Select entry to transfer");
	return false;
	
 }
 function IsSomeCheckBoxChecked_Locked(GridId)
 {
	var len = document.getElementById(GridId).childNodes[0].childNodes.length;
	for(var i=0;i<=len;i++)
	{
		if(document.getElementById(GridId+"__ctl"+i+"_chkSelect")==null)
		{
			continue;
		}
		else
		{
			if((document.getElementById(GridId+"__ctl"+i+"_chkSelect")).checked==true)
				{
					return(confirm("Are you sure you want to unlock this user?"));
				}
						
		}
	}
	alert("Please select a user to unlock");
	return false;
	
 }
 function IsSomeCheckBoxChecked_ADD(GridId)
 {
	var len = document.getElementById(GridId).childNodes[0].childNodes.length;
	for(var i=0;i<=len;i++)
	{
		if(document.getElementById(GridId+"__ctl"+i+"_chkSelect")==null)
		{
			continue;
		}
		else
		{
			if((document.getElementById(GridId+"__ctl"+i+"_chkSelect")).checked==true)
				{
					return(confirm("Are you sure you want to add user(s)?"));
				}
						
		}
	}
	alert("Please select a user");
	return false;
	
 }
  function IsSomeCheckBoxChecked_ADDCompliance(GridId)
 {
	var len = document.getElementById(GridId).childNodes[0].childNodes.length;
	for(var i=0;i<=len;i++)
	{
		if(document.getElementById(GridId+"__ctl"+i+"_chkSelect")==null)
		{
			continue;
		}
		else
		{
			if((document.getElementById(GridId+"__ctl"+i+"_chkSelect")).checked==true)
				{
					return(confirm("Are you sure you want to map selected compliance(s)?"));
				}
						
		}
	}
	alert("Please select a user");
	return false;
	
 }
 function IsChecked(GridId,Msg1,Msg2)
 {
 var len = document.getElementById(GridId).childNodes[0].childNodes.length;
	for(var i=0;i<=len;i++)
	{
		if(document.getElementById(GridId+"__ctl"+i+"_chkSelect")==null)
		{
			continue;
		}
		else
		{
			if((document.getElementById(GridId+"__ctl"+i+"_chkSelect")).checked==true)
				{
					return(confirm(Msg1));
				}
						
		}
	}
	alert(Msg2);
	return false;
 }
 
 
 
