/*
	----------------------------------------------------------------------------------------------------------------------------
	NOTE:
	DO NOT MODIFY/DELETE ANY PART OF THE CODE BELOW WITHOUT PRIOR PERMISSION FROM THE AUTHOR

	C and P LOGIN INFOTECH PRIVATE LIMITED
	BANGALORE, KARNATAKA, INDIA.

	AUTHOR: C S GURU PRASANNA
	----------------------------------------------------------------------------------------------------------------------------
*/



function isValidEmail(eml)
{
	/*
		This function returns true if the given e-mail id is valid else false.
		NOTE: a valid e-mail id will in "xyz@xyz.com" format.

		INPUT: String containing e-mil id [eml]
	*/

	/*if( isBlank(eml) )
	{
		alert( "E-Mail can't be blank" );
		return false;
	}*/
	//else if( (getCountOf('@', eml) != 1) || (getCountOf('.', eml) < 1) )
	if( (getCountOf('@', eml) != 1) || (getCountOf('.', eml) < 1) )
	{
		alert( "Enter a valid e-mail id." );
		return false;
	}
	else if( !checkInCharSet(eml, "@._0123456789abcdefghijklmnopurstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") )
	{
		alert( "Special Characters are not allwed in e-mail fields" );
		return false;
	}
	else
	{
		return true;
	}
}



function isBlank(txt)
{
	/*
		This fucntion can be used to check if a given text contains only spaces or 0 in length.

		INPUT: Text [txt]

		OUTPUT: returns true if blank else false
	*/

	if( txt.length == getCountOf(' ', txt) || txt.length == 0 )
	{
		return true;
	}
	else
	{
		return false;
	}
}



function getCountOf(vChr, txt)
{
	/*
		This sub-routine can be used for getting the count of occurances of a character in a given string.

		INPUT:	Character to be searched [vChar]
					String in which character has to be searched [txt]

		OUTPUT:	Returns the count.

		USAGE:
					for instance,
						alert( getCountOf('', "Bangalore, Karnataka") );

					the above statement would display 6, number of occurances of character 'a' in string "Bangalore, Karnataka"
	*/

	var i = 0;
	var iCount = 0;

	for( i=0; i < txt.length; i++ )
	{
		if( txt.charAt(i) == vChr )
		{
			iCount++;
		}
	}
	return iCount;
}



function isValidDate(d, m, y)
{
	/*
		This fucntion can be used for date validations.

		INPUT:	Day in numeric format [d]
					Month in numeric format [m]
					4 digit year [y]

		OUTPUT: Returns true if the date is valid else fase.

		USAGE:
					isValidDate( 1, 4, 2001 )		- Returns true

					isValidDate( 1, 13, 2002 )	- Returns false coz month is > 12
	*/

	var vDays = [ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];

	if( m == 2 )
	{
		if( isLeapYear(y) )
		{
			if( d > 29 || d < 1 )
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		else if( d > vDays[m] || d < 1 )
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else if( d > vDays[m] || d < 1 )
	{
		return false;
	}
	else
	{
		return true;
	}
}



function isLeapYear(y)
{
	/*
		This fucntion returns true if the given year is a leap year else false.

		INPUT:	year in numeric format [y]
	*/

	if( y % 4 == 0)
	{
		if( y % 100 == 0 )
		{
			if( y % 400 == 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return true;
		}
	}
	else
	{
		return false;
	}
}



function checkInCharSet(txt, charset)
{
	/*
		This function checks if the characters in a given text are part of a given character set.

		INPUT:	Text ti be verified [txt]
					String of character that forms the reference [charset]

		OUTPUT: Returns true if all of the characters in txt are part of charset, else false.

		USAGE:
					for example:

						checkInCharSet( "guru", "aeiouAEIOU" ) this fucntion returns false as "guru" contains 'g' and 'r'
						whcih are not part of "aeiouAEIOU".

						checkInCharSet( "abC", "abcdefABCDEF" ) this statement returns true as all "abC" contains characters
						that are present in "abcdefABCDEF"
	*/

	var b = true;

	for(i = 0; i < txt.length; i++ )
	{
		if(charset.indexOf(txt.charAt(i)) == -1 )
		{
			b = false;
		}
	}

	return b;
}



function getSelectedIndex(radgroup)
{
	/*
		This function returns the index of a radio button that's being selected.
	*/

	var j = -1;

	for( i=0; i < radgroup.length; i++ )
	{
		if( radgroup[i].checked )
		{
			j = i;
		}
	}

	return j;
}


function chkLength(txt,Length)
{
	var a=true;
	if (txt.length> Length )
		a=false;
	return a;
}

function chkCmbIndex(cmb)
{
	var a=false;
	if (cmb.value = 0 )
		a=true;
	return a;
}

function chkCharData(){
	if (event.keyCode==32)return;
	if (event.keyCode==46)return;
	
	if (event.keyCode<65 || event.keyCode>122){
		event.returnValue=false;
	}
}
function chkNumData(){
	if (event.keyCode==32) return;
	if (event.keyCode==44) return;
	if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;
}
function chNumData(){
	if (event.keyCode==32) return;
	if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;
}			

function chkNumDataWithoutSpace(){
	if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;
}			
			
