function ControlVal( element, ealert, etype, evalue )
{
  	var etest = false;
	
	// type of num //
	if( etype == "numeric" )
	{
		if( element.value > evalue ) etest = true;
	}
	else if( etype == "text" )
	{
		if( element.value.length > evalue ) etest = true;
	}
	else if( etype == "email" )
	{
		re = new RegExp("^([a-zA-Z0-9]{1})+[a-zA-Z0-9_\.\-]+[@]{1}([^.][a-zA-Z0-9_\.\-]+[.])+[a-z]{2,3}$");
		etest = re.test( element.value );
	}
	else if( etype == "phone" )
	{
		if( element.value > 10000000 ) 
		{
			if( element.value.length > 8 ) etest = true;
		}
	}
	else if( etype == "date" )
	{
		if( ( ealert = IsDate( element ) ) == true ) etest = true;
	}
	else
	{
		etest = true;
	}
	
	
	if( etest == false )
	{
		if( ealert != "" )
		{
			alert( ealert );
		}

		element.focus();
	}
	
	return etest;
}



function IsDate( vstup ) 
{
	var text ;
	var index ;
	var tecka ;
	var den ;
	var mesic ;
	var rok ;
	var ch ;
	
	text = "" ;
	den = "" ;
	mesic = "" ;
	rok = "" ;
	tecka = 0 ;
	
	for( index = 0; index < vstup.value.length; index++ ) 
	{ 
		ch = vstup.value.charAt(index); 
		if( ch != "0" && ch != "1" && ch != "2" && ch != "3" && ch != "4" && ch != "5" && ch != "6" && ch != "7" && ch != "8" && ch != "9" && ch != ".") 
		{
			text="Datum if form DD.MM.YYYY (DD=day, MM=month, YYYY=year).\r"
		} 
		
		if( ( ch == "0" || ch == "1" || ch == "2" || ch == "3" || ch == "4" || ch == "5" || ch == "6" || ch == "7" || ch == "8" || ch == "9" ) && ( text == "" ) ) 
		{ 
			if (tecka == 0) 
			{ 
				den = den + ch;
			} 
			
			if( tecka == 1 ) 
			{
				mesic=mesic + ch;
			} 
			
			if( tecka == 2 )
			{
				rok=rok + ch;
			} 
		} 
		
		if( ch == "." && text == "" ) 
		{ 
			if (tecka == 1) tecka=2;
			if (tecka == 0) tecka=1;
		} 
	} 
	
	if( ( den<1 || den >31 ) && ( text == "" ) ) text = text + "Number of days in this month can't be less then 1 and more then 31.\r";
	
	if( ( mesic<1 || mesic>12 ) && (text == "" ) ) text = text + "Number of months can't be less then 1 and more then 12.\r";
	
	if(rok < 1990 && tecka == 2 && text == "" && rok != "") text = text + "Year can't be less then 1990.\r";
	
	if( ( tecka == 2 && rok == "" ) || ( tecka > 2 ) ) text = text+ "Datum in form DD.MM.YYYY (DD=day, MM=month, YYYY=year)\r";
	
	// unor //
	if( mesic == 2 )
	{ 
		if( rok != "" ) 
		{ 
			if (rok % 4 == 0)
			{ 
				if( den > 29 ) text=text + "In February " + rok + " is maximum 29 days.\r"; 
			} 
			else 
			{ 
				if( den > 28 ) text=text + "In February " + rok + " is maximum 28 days.\r";
			} 
		} 
		else 
		{ 
			if( den > 29 ) text = text + "In February is maximum 29 days.\r";
		} 
	} 
	
	if( ( mesic == 4 || mesic == 6 || mesic == 9 || mesic == 11 ) && ( den > 30 ) ) 
	{
		text = text + "Number of days in this month can't be less then 1 and more then 30.\r"	} 
	
	if( text != "" ) 
	{ 
		alert(text); 
		return false;
	} 
	else 
	{ 
		return true;
	} 
}
