function IsOblig(name_of_control,oblig_name)
{
var i;

	for(i=0;i<oblig_name.length;i++)
		if(name_of_control==oblig_name[i])
			return true;

return false;
}

/******* priklad volani fce Verify_Form

//$obligatory = 'email,nationality,...'; pole do ktereho se zadaji povinne polozky
$obligatory = 'email';
echo '<form method=post action="app_form.php"  onSubmit="return Verify_Form(this,\''.$obligatory.'\');">';

*/

function Verify_Form(f,obligatory)
{
var empty_fields="" ;
var field_obligatory;
var evalstring = "";
var num_radios;
var radiotrue;
var i,j;

field_obligatory = obligatory.split(/,/);

	for( i = 0 ; i < f.length ; i++ ) 
	{
		var e = f.elements[i];	
		if(e.type == "text" )
		{						 						

			if((e.value == null) || (e.value == ""))
			{
				if(IsOblig(e.name,field_obligatory))
				{
					empty_fields+=e.name+"\n";
					continue;
				}
			}	
		}

		if(e.type == "radio")
		{
		  radiotrue=0;
		  evalstring = "f.elements."+e.name+".length";
			num_radios = eval(evalstring);


			for(j=0;j<num_radios;j++)
			{
				evalstring = "f.elements."+e.name+"["+j+"].checked";
				if(eval(evalstring))
				  radiotrue=1;
			}
			

			if(!radiotrue && (empty_fields.indexOf(e.name) == -1) )
			  empty_fields+=e.name+"\n";
		}
					
	}

	if(empty_fields)
	{
		empty_fields = "missing:\n\n"+empty_fields;
		alert(empty_fields);
		return false;
	}

return true;
}



// stejna fce jako Verify_Form , navic kontroluje i radio, ktere tim padem nemusi byt povinne jako u predchozi fce 

function Verify_Form_R(f,obligatory)
{

var empty_fields="" ;
var field_obligatory;
var evalstring = "";
var num_radios;
var radiotrue;
var i,j;

field_obligatory = obligatory.split(/,/);

	for( i = 0 ; i < f.length ; i++ ) 
	{
		var e = f.elements[i];	
		if(e.type == "text" )
		{						 						

			if((e.value == null) || (e.value == ""))
			{
				if(IsOblig(e.name,field_obligatory))
				{
					empty_fields+=e.name+"\n";
					continue;
				}
			}	
		}

		if(e.type == "radio")
		{
		  radiotrue=0;
		  evalstring = "f.elements."+e.name+".length";
			num_radios = eval(evalstring);


      if(IsOblig(e.name,field_obligatory))
			{
				for(j=0;j<num_radios;j++)
				{
					evalstring = "f.elements."+e.name+"["+j+"].checked";
					if(eval(evalstring))
						radiotrue=1;
				}
				

				if(!radiotrue && (empty_fields.indexOf(e.name) == -1) )
					empty_fields+=e.name+"\n";
			}	
		}
					
	}

	if(empty_fields)
	{
	  // v empty_fields jsou jmena vsech nevyplnenych prvku formulare  
		empty_fields = "Some of obligatory field is empty!! \n\n";
		alert(empty_fields);
		return false;
	}

return true;
}

// stejna fce jako Verify_Form_R , navic kontroluje i select
function Verify_Form_RS(f,obligatory)
{

var empty_fields="" ;
var field_obligatory;
var evalstring = "";
var num_radios;
var radiotrue;
var i,j;

field_obligatory = obligatory.split(/,/);

	for( i = 0 ; i < f.length ; i++ ) 
	{
		var e = f.elements[i];	
		if(e.type == "text" || e.type == "password")
		{						 						

			if((e.value == null) || (e.value == ""))
			{
				if(IsOblig(e.name,field_obligatory))
				{
					empty_fields+=e.name+"\n";
					continue;
				}
			}	
		}

		if(e.type == "select-one" )
		{						 						
			if((e.value == null) || (e.value == ""))
			{
				if(IsOblig(e.name,field_obligatory))
				{
					empty_fields+=e.name+"\n";
					continue;
				}
			}	
		}

		if(e.type == "radio")
		{
		  radiotrue=0;
		  evalstring = "f.elements."+e.name+".length";
			num_radios = eval(evalstring);


      if(IsOblig(e.name,field_obligatory))
			{
				for(j=0;j<num_radios;j++)
				{
					evalstring = "f.elements."+e.name+"["+j+"].checked";
					if(eval(evalstring))
						radiotrue=1;
				}
				

				if(!radiotrue && (empty_fields.indexOf(e.name) == -1) )
					empty_fields+=e.name+"\n";
			}	
		}
					
	}

	if(empty_fields)
	{
	  // v empty_fields jsou jmena vsech nevyplnenych prvku formulare  
		empty_fields = "Some of obligatory field is empty!! \n\n";
		alert(empty_fields);
		return false;
	}

return true;
}


// stejna fce jako Verify_Formi_R , navic kontroluje pritomnost checkboxu agree pokud neni zatrhnut hlasi chybu 

function Verify_Form_R_A(f,obligatory)
{

var empty_fields="" ;
var field_obligatory;
var evalstring = "";
var num_radios;
var radiotrue;
var i,j;

if(!f.elements.agree.checked)
{
	alert("You have to agree with the conditions!! \nSee checkbox on bottom of the form");
	return false;
}

return Verify_Form_R(f,obligatory);

}

// stejna fce jako Verify_Form_RS , navic kontroluje pritomnost checkboxu agree pokud neni zatrhnut hlasi chybu 

function Verify_Form_RS_A(f,obligatory)
{

var empty_fields="" ;
var field_obligatory;
var evalstring = "";
var num_radios;
var radiotrue;
var i,j;

if(!f.elements.agree.checked)
{
	alert("You have to agree with the conditions!! \nSee checkbox on bottom of the form");
	return false;
}

return Verify_Form_RS(f,obligatory);

}

// stejna fce jako Verify_Form_RS_A , navic kontroluje zda jsou password1,password2 stejne 
function Verify_Form_RS_AP(f,obligatory)
{

var empty_fields="" ;
var field_obligatory;
var evalstring = "";
var num_radios;
var radiotrue;
var i,j;

if(f.elements.agree)
{
	if(!f.elements.agree.checked)
	{
		alert("You have to agree with the conditions!! \nSee checkbox on bottom of the form");
		return false;
	}
}

if(f.elements.password1.value != f.elements.password2.value)
{
	alert("Incorrect password");
	return false;
}

return Verify_Form_RS(f,obligatory);

}



