function checkDate(datefield)
{
	
  if(document.getElementById(datefield).value!="")
  {

		// Regular expression used to check if date is in correct format
		var pattern = new RegExp(/^[0-3][0-9]-0|1[0-9]-19|20[0-9]{2}$/);
		if(document.getElementById(datefield).value.match(pattern))
		{
			var date_array = document.getElementById(datefield).value.split('/');
			var day = date_array[0];

			// Attention! Javascript consider months in the range 0 - 11
			var month = date_array[1] - 1;
			var year = date_array[2];

			// This instruction will create a date object
			source_date = new Date(year,month,day);

			if(year != source_date.getFullYear())
			{
				return "invalid";
			}

			if(month != source_date.getMonth())
			{
				return "invalid";
			}

			if(day != source_date.getDate())
			{
				return "invalid";
			}
		}
		else
		{
			return "invalid";
		}

		return "";
	}
	else
	{
	return "";
	}
}


function checkMailId(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return "      " +"Invalid E-mail ID\n\r";
		   
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   
		   return "      " +"Invalid E-mail ID\n\r";
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return "      " +"Invalid E-mail ID\n\r";
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return "      " +"Invalid E-mail ID\n\r";
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return "      " +"Invalid E-mail ID\n\r";
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return "      " +"Invalid E-mail ID\n\r";
		 }
		
		 if (str.indexOf(" ")!=-1){
		   return "      " +"Invalid E-mail ID\n\r";
		 }

 		 return "";				
	}







function getKey(e)
{
	var key;

	if(window.event)
	{
		key = window.event.keyCode;
	}
	else
	{
		key = e.which;
	}
	return key;
}		
function ValidateInvalidCharacters(e)
{
	var key=getKey(e);
	//alert(key);
	if(window.event)
	{

		if((key >=48) && (key <= 57))
		{
		}
		else
		{
			window.event.returnValue = false;
			return false;
		}
	}
	else
	{
		if((key>=48 && key<=57) || (key==8) || (key==0))
		{
		}
		else
		{
			e.returnValue = false;
			e.preventDefault();
		}
	}
}
//Function Name : checkNumber() 
//purpose : To Check Number 0-9
function checkNumber(e) 
{
	
	var key=getKey(e);
	//alert(key);
	if(window.event)
	{

		if((key >=48) && (key <= 57))
		{
		}
		else
		{
			window.event.returnValue = false;
			return false;
		}
	}
	else
	{
		if((key>=48 && key<=57) || (key==8) || (key==0))
		{
		}
		else
		{
			e.returnValue = false;
			e.preventDefault();
		}
	}
	
	
}

//Function Name : checkDecimal() 
//purpose : To Check Number 0-9 and "."
function checkDecimal(e) 
{
	var key=getKey(e);
	//alert(key);
	if(window.event)
	{

		if((key >=48) && (key <= 57) || (key ==46))
		{
		}
		else
		{
			window.event.returnValue = false;
			return false;
		}
	}
	else
	{
		if((key >=48) && (key <= 57) || (key ==46) || (key==8) || (key==0))
		{
		}
		else
		{
			e.returnValue = false;
			e.preventDefault();
		}
	}
	
}

//Function Name : checkName() 
//purpose : To Allow only A-Z,a-z and space and "."
function checkName(e) 
{
	var key=getKey(e);
	//alert(key);
	if(window.event)
	{

		if((key>=97 && key <=122) || (key>=65 && key <=90) || (key==32) || (key==46))
		{
		}
		else
		{
			window.event.returnValue = false;
			return false;
		}
	}
	else
	{
		if((key>=97 && key <=122) || (key>=65 && key <=90) || (key==32) || (key==46) || (key==8) || (key==0))
		{
		}
		else
		{
			e.returnValue = false;
			e.preventDefault();
		}
	}
	
}

//Function Name : checkName() 
//purpose : To Allow only a-z and space and "."
function checkLowerCase(e) 
{
	var key=getKey(e);
	//alert(key);
	if(window.event)
	{

		if((key>=97 && key <=122) ||  (key==32) || (key==46))
		{
		}
		else
		{
			window.event.returnValue = false;
			return false;
		}
	}
	else
	{
		if((key>=97 && key <=122) ||  (key==32) || (key==46) || (key==8) || (key==0))
		{
		}
		else
		{
			e.returnValue = false;
			e.preventDefault();
		}
	}
	
}

//Function Name : checkName() 
//purpose : To Allow only a-z and space and "."
function checkUpperCase(e) 
{
	var key=getKey(e);
	//alert(key);
	if(window.event)
	{

		if((key>=65 && key <=90) || (key==32) || (key==46))
		{
		}
		else
		{
			window.event.returnValue = false;
			return false;
		}
	}
	else
	{
		if((key>=65 && key <=90) || (key==32) || (key==46) || (key==8) || (key==0))
		{
		}
		else
		{
			e.returnValue = false;
			e.preventDefault();
		}
	}
	
}



//Function Name : checkBlank() 
//purpose : To check a control blank or not
function checkBlank(controlName,message) 
{
	//alert(event.keyCode);
	if(document.getElementById(controlName).value=="")
	{
			document.getElementById(controlName).style.backgroundColor = "#fefe8d";
				return "      " + message + "\n\r";
	}
	else
	{
			document.getElementById(controlName).style.backgroundColor = "#d7ddc9";
	
	return "";
	}
	
}

function checkAllBlank() 
{

	var msg="";
	l=checkAllBlank.arguments.length;
	for(i=0;i<l;i++)
	{
	
		if(document.getElementById(checkAllBlank.arguments[i]).value=="")
		{
		
			msg=msg + "      Please Enter " + checkAllBlank.arguments[i].substr(3,checkAllBlank.arguments[i].length) + "\n\r";
			document.getElementById(checkAllBlank.arguments[i]).style.backgroundColor = "#fefe8d";
		}
		else
		{
			document.getElementById(checkAllBlank.arguments[i]).style.backgroundColor = "#d7ddc9";
		
		}
	}
	
	if(msg=="")
	{
	return "";
	
	}
	else
	{
		//alert(msg);
		//return "<table >" + msg + "</table>";
		return  msg ;
		
	}
	
	
}
function checkCheckBoxList(CheckBoxListName,numberOfItems,msgString)
{
var flag="0";
//alert(CheckBoxListName);
//alert(document.getElementById(CheckBoxListName).items[0].value);
	for(i=0;i<numberOfItems;i++)
	{
	var c=document.getElementById(CheckBoxListName + "_" + i);
	
		if(c.checked==true)
		{
		return "";
		}
		else
		{
		flag="1";
		}
		
	}
	if(flag=="1")	
	{
	return "      Please select any one of the " + msgString + "\n\r" ;
	}
	
}

function CheckRadioButtonGroupStatus(groupName,msgString)
		{
		//alert(document.getElementById("project").checked);
		
		    
		 var val = 0;
			
			for( i = 0; i < groupName.length; i++ )
			{
				if(groupName[i].checked == true )
				val = groupName[i].value;
			}
			if(val=="")
			{
			return "      Select the " + msgString + "\n\r";
			}
			else
			{
			return "";
			}
		}
