//	Name			=>	Java Script Validation
//	By 				=> 	P. Rashmi
//	Date and Time	=>	18/02/2006 & 12:15 p.m.


//		Does not Allow Null value and spaces only
function Fn_TextOnly(m_value,lbl)
{
	if(m_value.match(/[^A-Z a-z , & ( ) ! @ # $ % ]/))
	{
		alert(lbl+" Should be Text Only");
		return true;
	}
	return false;	
}
function Fn_SpecialCharacters(m_value,lbl)
{
	var illegalChars= /[\<\>\;\:\\\[\]]/
//	var illegalChars= /[\\]/
		if (m_value.match(illegalChars)) 
		{
			alert(lbl + "does not allow these special character" );
			return true;
		}
}
function Fn_IsEmpty(m_value,lbl)
{
	if(m_value=="")
	{
		alert(lbl+" Cannot be Empty");
		return true;	
	}
	if(m_value.charAt(0)==" ")
	{
		alert("Enter the " + lbl);
		return true;	
	}
	return false;	
}
//		Must select a value from the combo box
function Fn_ComboValid(m_value,lbl)
{
	if(m_value=="Select")
	{
		alert("Select the "+lbl);
		return true;
	}
	return false;
}
//		If text box is displayed then only check if value is null
function Fn_Disp(m_value)
{
	if(m_value=='')
	{
		return true;
	}
	return false;
}
//		Check if the value is number with a hyphen (Phone Number)
function Fn_PhoneNumberOnly(m_value,lbl)
{
	if(m_value.match(/[^0-9 -]/))
	
	{
		alert(lbl+" Should be a number");
		return true;
	}
	return false;
}
function Fn_NumberOnly(m_value,lbl)
{
	if(m_value.match(/[^0-9]/))
	
	{
		alert(lbl+" Should be a number");
		return true;
	}
	return false;
}

//		Check if the value is number with a decimal
function Fn_NumDesiOnly(m_value,lbl)
{
	if (isNaN(m_value))
	{
		alert(lbl+" Should be a number");
		return true;
	}
	return false;
}
//		Compare Two Dates, From Date should not be more than To Date, From and To date should not be more than System Date, Null values not allowed
function Fn_CompareTwoDates(m_FromDate,m_ToDate,lblf,lblt)
{
	
	var mfmonth			=	0;
	var mtmonth			=	0;
	sysdate1			=	new Date();
	sysdate2			=	sysdate1.getDate();	
	sysdate3			=	sysdate1.getMonth();
	sysmonth			=	sysdate3 + 1;
	sysyear				=	sysdate1.getYear();
	FromDate			=	m_FromDate;
		if(FromDate=="")
		{
			alert("Enter your From Date");
			return true;
		}
	ToDate				=	m_ToDate; 
		if(ToDate=="")
		{
			alert("Enter your To Date");
			return true;
		}
	
	FromGivenDate		=	m_FromDate;

	m_datefrom				=	new Number(FromGivenDate.substring(0,2));
	m_monfrom				=	FromGivenDate.substring(3,5);
	m_yearfrom				=	new Number(FromGivenDate.substring(6,10));

/*	if(FromGivenDate.length==10)
	{
		m_datefrom			=	new Number(FromGivenDate.substring(0,1));
		m_monfrom			=	FromGivenDate.substring(2,5);
		m_yearfrom			=	new Number(FromGivenDate.substring(6,10));
	}
	
	if(FromGivenDate.length==11)
	{
	m_datefrom			=	new Number(FromGivenDate.substring(0,2));
	m_monfrom			=	FromGivenDate.substring(3,6);
	m_yearfrom			=	new Number(FromGivenDate.substring(7,11));
	}
*/
	
	if (m_monfrom		==	"01")
		m_monthfrom		=	1;
	else if (m_monfrom	==	"02")	
		m_monthfrom		=	2;
	else if (m_monfrom	==	"03")	
		m_monthfrom		=	3;
	else if (m_monfrom	==	"04")	
		m_monthfrom		=	4;
	else if (m_monfrom	==	"05")	
		m_monthfrom		=	5;
	else if (m_monfrom	==	"06")	
		m_monthfrom		=	6;
	else if (m_monfrom	==	"07")	
		m_monthfrom		=	7;
	else if (m_monfrom	==	"08")	
		m_monthfrom		=	8;
	else if (m_monfrom	==	"09")	
		m_monthfrom		=	9;
	else if (m_monfrom	==	"10")	
		m_monthfrom		=	10;
	else if (m_monfrom	==	"11")	
		m_monthfrom		=	11;
	else if (m_monfrom	==	"12")
		m_monthfrom		=	12;
	else
		m_monthfrom		=	0;

	if (m_yearfrom > sysyear)
	{
		alert(lblf  + " is Greater than System Date. Re-Pick the" + lblf + "Date");
		return true;
	}
	if(m_yearfrom == sysyear && m_monthfrom > sysmonth)
	{
		alert(lblf  +" is Greater than System Date. Re-Pick the" + lblf + "Date");
		return true;
	}
	if(m_yearfrom == sysyear && m_monthfrom == sysmonth && m_datefrom > sysdate2) 
	{
		alert(lblf  +" is Greater than System Date. Re-Pick the" + lblf + "Date");
		return true;
	}

	ToGivenDate			=	m_ToDate;
	
	m_dateto				=	new Number(ToGivenDate.substring(0,2));
	m_monto					=	ToGivenDate.substring(3,5);
	m_yearto				=	new Number(ToGivenDate.substring(6,10));
	
/*	if(ToGivenDate.length == 10)
	{
	m_dateto			=	new Number(ToGivenDate.substring(0,1));
 	m_monto				=	ToGivenDate.substring(2,5);
	m_yearto			=	new Number(ToGivenDate.substring(6,10));
	}
	
	if(ToGivenDate.length==11)
	{
	m_dateto			=	new Number(ToGivenDate.substring(0,2));
	m_monto				=	ToGivenDate.substring(3,6);
	m_yearto			=	new Number(ToGivenDate.substring(7,11));
	}
*/	

	if (m_monto			==	"01")
		m_monthto		=	1;
	else if (m_monto	==	"02")	
		m_monthto		=	2;
	else if (m_monto	==	"03")	
		m_monthto		=	3;
	else if (m_monto	==	"04")	
		m_monthto		=	4;
	else if (m_monto	==	"05")	
		m_monthto		=	5;
	else if (m_monto	==	"06")	
		m_monthto		=	6;
	else if (m_monto	==	"07")	
		m_monthto		=	7;
	else if (m_monto	==	"08")	
		m_monthto		=	8;
	else if (m_monto	==	"09")	
		m_monthto		=	9;
	else if (m_monto	==	"10")	
		m_monthto		=	10;
	else if (m_monto	==	"11")	
		m_monthto		=	11;
	else if (m_monto	==	"12")
		m_monthto		=	12;
	else
		m_monthto		=	0;

	if(m_yearto > sysyear)
	{
		alert(lblt  + " is Greater than System Date. Re-Pick the" + lblt + "Date");
		return true;
	}
	if(m_yearto == sysyear && m_monthto > sysmonth)
	{
		alert(lblt  +" is Greater than System Date. Re-Pick the" + lblt + "Date");
		return true;
	}
	if(m_yearto == sysyear && m_monthto == sysmonth && m_dateto > sysdate2) 
	{
		alert(lblt  +" is Greater than System Date. Re-Pick the" + lblt + "Date");
		return true;
	}
	if(m_yearfrom > m_yearto)
	{
		alert(lblt  + " should be more than " + lblf  );
		return true;
	}
	if(m_yearto <= m_yearfrom && m_monthfrom > m_monthto)
	{
		alert(lblt  + " should be more than " + lblf  );
		return true;
	}
	if(m_yearto <= m_yearfrom  && m_monthto <= m_monthfrom && m_datefrom > m_dateto) 
	{
		alert(lblt  + " should be more than " + lblf  );
		return true;
	}
	return false;
}

function Fn_CheckSystemDate(m_value,m_cmdText)
	{
		var mmonthfrom				=	0;
		var mmonthto				=	0;
		sdate1						=	new Date();
		sdate						=	sdate1.getDate();
		sdate3						=	sdate1.getMonth();
		smonth						=	sdate3	+	1;
		syear						=	sdate1.getYear();
		FromDate					=	m_value;

		entereddatefrom				=	m_value;
		if(FromDate=="")
		{
			alert("Enter " + m_cmdText);
			return true;
		}
			mdatefrom				=	new Number(entereddatefrom.substring(0,2));
			monfrom					=	entereddatefrom.substring(3,5);
			myearfrom				=	new Number(entereddatefrom.substring(6,10));
			
/*		if(entereddatefrom.length	==	10)
		{
			mdatefrom				=	new Number(entereddatefrom.substring(0,1));
			monfrom					=	entereddatefrom.substring(2,5);
			myearfrom				=	new Number(entereddatefrom.substring(6,10));
		}
	
		if(entereddatefrom.length	==	11)
		{
			mdatefrom				=	new Number(entereddatefrom.substring(0,2));
			monfrom					=	entereddatefrom.substring(3,6);
			myearfrom				=	new Number(entereddatefrom.substring(7,11));
		}
*/	

		if (monfrom					==	"01")
			mmonthfrom				=	1;
		else if (monfrom			==	"02")	
			mmonthfrom				=	2;
		else if (monfrom			==	"03")	
			mmonthfrom				=	3;
		else if (monfrom			==	"04")	
			mmonthfrom				=	4;
		else if (monfrom			==	"05")	
			mmonthfrom				=	5;
		else if (monfrom			==	"06")	
			mmonthfrom				=	6;
		else if (monfrom			==	"07")	
			mmonthfrom				=	7;
		else if (monfrom			==	"08")	
			mmonthfrom				=	8;
		else if (monfrom			==	"09")	
			mmonthfrom				=	9;
		else if (monfrom			==	"10")	
			mmonthfrom				=	10;
		else if (monfrom			==	"11")	
			mmonthfrom				=	11;
		else if (monfrom			==	"12")
			mmonthfrom				=	12;
		else
			mmonthfrom				=	0;
	
		if(myearfrom > syear)
		{
			alert(m_cmdText + " is Greater than System Date. Re-Pick the Date");
			return true;
		}
		if(myearfrom == syear && mmonthfrom > smonth)
		{
			alert(m_cmdText +  " is Greater than System Date. Re-Pick the Date");
			return true;
		}
		if(myearfrom == syear && mmonthfrom == smonth && mdatefrom > sdate)
		{
			alert(m_cmdText +  " is Greater than System Date. Re-Pick the Date");
			return true;
		}
		return false;
	}


// Event Date should not be less than the System date

function Fn_CheckLessSystemDate(m_value,m_cmdText)
	{
		var mmonthfrom				=	0;
		var mmonthto				=	0;
		sdate1						=	new Date();
		sdate						=	sdate1.getDate();
		sdate3						=	sdate1.getMonth();
		smonth						=	sdate3	+	1;
		syear						=	sdate1.getYear();
		FromDate					=	m_value;

		entereddatefrom				=	m_value;
		if(FromDate=="")
		{
			alert("Enter " + m_cmdText);
			return true;
		}
			mdatefrom				=	new Number(entereddatefrom.substring(0,2));
			monfrom					=	entereddatefrom.substring(3,5);
			myearfrom				=	new Number(entereddatefrom.substring(6,10));
			
		if (monfrom					==	"01")
			mmonthfrom				=	1;
		else if (monfrom			==	"02")	
			mmonthfrom				=	2;
		else if (monfrom			==	"03")	
			mmonthfrom				=	3;
		else if (monfrom			==	"04")	
			mmonthfrom				=	4;
		else if (monfrom			==	"05")	
			mmonthfrom				=	5;
		else if (monfrom			==	"06")	
			mmonthfrom				=	6;
		else if (monfrom			==	"07")	
			mmonthfrom				=	7;
		else if (monfrom			==	"08")	
			mmonthfrom				=	8;
		else if (monfrom			==	"09")	
			mmonthfrom				=	9;
		else if (monfrom			==	"10")	
			mmonthfrom				=	10;
		else if (monfrom			==	"11")	
			mmonthfrom				=	11;
		else if (monfrom			==	"12")
			mmonthfrom				=	12;
		else
			mmonthfrom				=	0;
	
		if(myearfrom < syear)
		{
			alert(m_cmdText + " is Lesser than System Date. Re-Pick the Date");
			return true;
		}
		if(myearfrom == syear && mmonthfrom < smonth)
		{
			alert(m_cmdText +  " is Lesser than System Date. Re-Pick the Date");
			return true;
		}
		if(myearfrom == syear && mmonthfrom == smonth && mdatefrom < sdate)
		{
			alert(m_cmdText +  " is Lesser than System Date. Re-Pick the Date");
			return true;
		}
		return false;
	}



//For Next action date // Staff_Child_MedicalJournal_Details.asp *********************************************************************


function Fn_CompareTwoDatesOnly(m_FromDate,m_ToDate,lblf,lblt)
{
	var mfmonth			=	0;
	var mtmonth			=	0;
	sysdate1			=	new Date();
	sysdate2			=	sysdate1.getDate();	
	sysdate3			=	sysdate1.getMonth();
	sysmonth			=	sysdate3 + 1;
	sysyear				=	sysdate1.getYear();
	FromDate			=	m_FromDate;
		if(FromDate=="")
		{
			alert("Enter "+lblf);
			return true;
		}
	ToDate				=	m_ToDate; 
		if(ToDate=="")
		{
			alert("Enter "+lblt);
			return true;
		}
	
	FromGivenDate		=	m_FromDate;

	if(FromGivenDate.length==10)
	{
		m_datefrom			=	new Number(FromGivenDate.substring(0,1));
		m_monfrom			=	FromGivenDate.substring(2,5);
		m_yearfrom			=	new Number(FromGivenDate.substring(6,10));
	}
	
	if(FromGivenDate.length==11)
	{
	m_datefrom			=	new Number(FromGivenDate.substring(0,2));
	m_monfrom			=	FromGivenDate.substring(3,6);
	m_yearfrom			=	new Number(FromGivenDate.substring(7,11));

	}
	
	if (m_monfrom		==	"Jan")
		m_monthfrom		=	1;
	else if (m_monfrom	==	"Feb")	
		m_monthfrom		=	2;
	else if (m_monfrom	==	"Mar")	
		m_monthfrom		=	3;
	else if (m_monfrom	==	"Apr")	
		m_monthfrom		=	4;
	else if (m_monfrom	==	"May")	
		m_monthfrom		=	5;
	else if (m_monfrom	==	"Jun")	
		m_monthfrom		=	6;
	else if (m_monfrom	==	"Jul")	
		m_monthfrom		=	7;
	else if (m_monfrom	==	"Aug")	
		m_monthfrom		=	8;
	else if (m_monfrom	==	"Sep")	
		m_monthfrom		=	9;
	else if (m_monfrom	==	"Oct")	
		m_monthfrom		=	10;
	else if (m_monfrom	==	"Nov")	
		m_monthfrom		=	11;
	else if (m_monfrom	==	"Dec")
		m_monthfrom		=	12;
	else
		m_monthfrom		=	0;


//	entereddateto		=	m_date2;
	ToGivenDate			=	m_ToDate;
	if(ToGivenDate.length == 10)
	{
	m_dateto			=	new Number(ToGivenDate.substring(0,1));
 	m_monto				=	ToGivenDate.substring(2,5);
	m_yearto			=	new Number(ToGivenDate.substring(6,10));
	}
	
	if(ToGivenDate.length==11)
	{
	m_dateto			=	new Number(ToGivenDate.substring(0,2));
	m_monto				=	ToGivenDate.substring(3,6);
	m_yearto			=	new Number(ToGivenDate.substring(7,11));
	}
	
	if (m_monto			==	"Jan")
		m_monthto		=	1;
	else if (m_monto	==	"Feb")	
		m_monthto		=	2;
	else if (m_monto	==	"Mar")	
		m_monthto		=	3;
	else if (m_monto	==	"Apr")	
		m_monthto		=	4;
	else if (m_monto	==	"May")	
		m_monthto		=	5;
	else if (m_monto	==	"Jun")	
		m_monthto		=	6;
	else if (m_monto	==	"Jul")	
		m_monthto		=	7;
	else if (m_monto	==	"Aug")	
		m_monthto		=	8;
	else if (m_monto	==	"Sep")	
		m_monthto		=	9;
	else if (m_monto	==	"Oct")	
		m_monthto		=	10;
	else if (m_monto	==	"Nov")	
		m_monthto		=	11;
	else if (m_monto	==	"Dec")
		m_monthto		=	12;
	else
		m_monthto		=	0;
	if(m_yearfrom > m_yearto)
	{
		alert(lblt  + " should be more than " + lblf  );
		return true;
	}
	if(m_yearto <= m_yearfrom && m_monthfrom > m_monthto)
	{
		alert(lblt  + " should be more than " + lblf  );
		return true;
	}
	if(m_yearto <= m_yearfrom  && m_monthto <= m_monthfrom && m_datefrom > m_dateto) 
	{
		alert(lblt  + " should be more than " + lblf  );
		return true;
	}
	return false;
}

//-------------------------------------Check If Date given is equal to the System Date--------------------------------------------------

function Fn_CheckSystemDateEq(m_value,m_cmdText)
	{
		var mmonthfrom				=	0;
		var mmonthto				=	0;
		sdate1						=	new Date();
		sdate						=	sdate1.getDate();
		sdate3						=	sdate1.getMonth();
		smonth						=	sdate3	+	1;
		syear						=	sdate1.getYear();
		FromDate					=	m_value;

		entereddatefrom				=	m_value;

		if(FromDate=="")
		{
			alert("Enter " + m_cmdText);
			return true;
		}


		if(entereddatefrom.length	==	10)
		{
			mdatefrom				=	new Number(entereddatefrom.substring(0,1));
			monfrom					=	entereddatefrom.substring(2,5);
			myearfrom				=	new Number(entereddatefrom.substring(6,10));
		}
	
		if(entereddatefrom.length	==	11)
		{
			mdatefrom				=	new Number(entereddatefrom.substring(0,2));
			monfrom					=	entereddatefrom.substring(3,6);
			myearfrom				=	new Number(entereddatefrom.substring(7,11));
		}
	
		if (monfrom					==	"Jan")
			mmonthfrom				=	1;
		else if (monfrom			==	"Feb")	
			mmonthfrom				=	2;
		else if (monfrom			==	"Mar")	
			mmonthfrom				=	3;
		else if (monfrom			==	"Apr")	
			mmonthfrom				=	4;
		else if (monfrom			==	"May")	
			mmonthfrom				=	5;
		else if (monfrom			==	"Jun")	
			mmonthfrom				=	6;
		else if (monfrom			==	"Jul")	
			mmonthfrom				=	7;
		else if (monfrom			==	"Aug")	
			mmonthfrom				=	8;
		else if (monfrom			==	"Sep")	
			mmonthfrom				=	9;
		else if (monfrom			==	"Oct")	
			mmonthfrom				=	10;
		else if (monfrom			==	"Nov")	
			mmonthfrom				=	11;
		else if (monfrom			==	"Dec")
			mmonthfrom				=	12;
		else
			mmonthfrom				=	0;
	
		if(myearfrom > syear)
		{
			alert(m_cmdText + " should be less than System Date. Re-Pick the Date");
			return true;
		}
		if(myearfrom == syear && mmonthfrom > smonth)
		{
			alert(m_cmdText +  " should be less than System Date. Re-Pick the Date");
			return true;
		}
		if(myearfrom == syear && mmonthfrom == smonth && mdatefrom > sdate)
		{
			alert(m_cmdText +  " should be less than System Date. Re-Pick the Date");
			return true;
		}
		return false;
	}



//--------------------------------------------------------------------------------------------------------------------------------------




