function isblank(s) {
  for(var i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
  }
  return true;
}


function verify(f) {
  var msg;
  var empty_fields = "";
  var errors = "";
  var jmeno = document.getElementById("jmeno").value;
  var email = document.getElementById("email").value;
  var dotaz = document.getElementById("dotaz").value;

  if (jmeno == "Jméno *") {
    var empty_fields = empty_fields+" ";
    var errors = errors+"Jméno nebylo vyplněno.\n";
  }
  if (email == "E-mail *") {
    var empty_fields = empty_fields+" ";
    var errors = errors+"E-mail nebyl vyplněn.\n";
  }
  if (dotaz == "Dotaz *") {
    var empty_fields = empty_fields+" ";
    var errors = errors+"Dotaz nebyl vyplněn.";
  }

  for(var i = 0; i < f.length; i++) {
    var e = f.elements[i];
    if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
      
      if ((e.value == null) || (e.value == "") || isblank(e.value)) {
        empty_fields += "\n            " + e.id;
        continue;
	  }
 
      if (e.numeric || (e.min != null) || (e.max != null)) {
        var v = parseFloat(e.value);
        if (isNaN(v) || ((e.min != null) &&  (v < e.min)) || ((e.max != null) && (v > e.max))) {
          errors += "- V poli " + e.id + " musí být číslo";
		  if (e.min != null) { errors += ", které je větší než " + e.min; }
		  if ((e.max != null) && (e.min != null)) { errors += " a menší než " + e.max;}
		  else {
			  if (e.max != null) { errors += ", které je menší než " + e.max; }
		  }
          errors += ".\n";
	    }
	  } 
    }
  }

  if (!empty_fields && !errors) {
  
		$.blockUI({ css: { 
			border: 'none', 
			padding: '15px', 
			backgroundColor: '#000', 
			'-webkit-border-radius': '10px', 
			'-moz-border-radius': '10px', 
			opacity: '.5', 
			color: '#fff' 
			} 
		});
f.submit();
		setTimeout(jQuery.unblockUI, 2000);

   	
    	$().ajaxStop($.unblockUI);
  }
  else {
  msg = "________________________________________________________\n\n";
  msg += "Formulář nebyl odeslán, obsahuje následující chyby\n";
  msg += "________________________________________________________\n";
  
    if (empty_fields) {
      msg += empty_fields + "";
      if (errors) msg += "\n";
    }

    msg += errors;
  	
    alert(msg);
    return false;
  }
  
}

