	var submitted = false;

	function check_form(param,typ,kam) {
	  var error = 0;
	  var error_message = "Nevyplnili ste všetky povinné položky! Prosím : ";
	
	  if(submitted){ 
	    alert( "Tento formulár už bol odoslaný. Stlačte, prosím, ok, a počkajte, kým sa stránka nespracuje."); 
	    return false; 
	  }
	   
	  var r1 = document.of.login.value;
	  var r2 = document.of.password.value;
	  var r3 = document.of.meno.value;
	  var r4 = document.of.ulica.value;
	  var r5 = document.of.mesto.value;
	  var r7 = document.of.tel.value;
	  var r8 = document.of.email.value;
	  if (typ=='1') {
	  	var r9 = document.of.ico.value;
	  }
	  else
	  	var r9 = 0;

	 if (r1.length < 3) {
	    error_message = error_message + " \n Uveďte login. ";
	    error = 1;
         }

	 if (r2.length < 3) {
	    error_message = error_message + " \n Uveďte prihlasovacie heslo. ";
	    error = 1;
         }

	 if (r3.length < 3) {
		if (typ=='1') 
		   error_message = error_message + " \n Uveďte meno firmy. ";
		else
	  	   error_message = error_message + " \n Uveďte Vaše meno. ";
	    error = 1;
         }
	
	if (r4.length < 5) {
		 error_message = error_message + " \n Uveďte adresu. ";
	    error = 1;
         }

	 if (r5.length < 3) {
		 error_message = error_message + " \n Uveďte mesto. ";
	    error = 1;
         }

	 if (r7.length < 5) {
	    error_message = error_message + " \n Uveďte telefónne číslo. ";
	    error = 1;
         }

	if (r9.length < 3 && typ=='1') {
	    error_message = error_message + " \n Uveďte IČO. ";
	    error = 1;
         }

	if (CheckEmail(r8) == 0) {
	    error_message = error_message + " \n Uveďte korektný e-mail. ";
	    error = 1;
         }

	if (error == 1) { 
	  alert(error_message); 
	} else { 
	if(kam == 1)
	{
  	 	 new Ajax.Updater('navigacia', 'ajax/empty.php');
	         new Ajax.Updater('tovar_list', 'ajax/reg.php?'+param);
	}
	else
                 new Ajax.Updater('tovar_list', 'ajax/ucet.php?'+param);
	} 
 	return false; 
}


	function CheckEmail(email) 
	{
		AtPos = email.indexOf("@")
		StopPos = email.lastIndexOf(".")

		if (AtPos == -1 || StopPos == -1) 
			return 0;
		else
			return 1;
	}

function check_login(test_login) 
{
	new Ajax.Request('ajax/is_login.php?table=users&login='+test_login.value,
	{
	    method:'get',
	    onSuccess: function(transport){
	      var response = transport.responseText;
	      if(response == "1")
		{	
			test_login.value='';
			alert('Prihlasovacie meno je už použité, skúste iné');
		}
    	},
	    onFailure: function(){ alert('Something went wrong...') }
  	});
}

function logout()
{
	new Ajax.Updater('login', 'ajax/login.php?logout');
}

function do_login(param)
{
	new Ajax.Updater('login', 'ajax/login.php?'+param);
}
function hladaj(param)
{
	new Ajax.Updater('navigacia', 'ajax/hladaj.php?'+param);
	new Ajax.Updater('tovar_list', 'ajax/empty.php');
}
