// JavaScript Document
function ukaz(id)
{
document.getElementById(id).style.visibility="visible";
};
function zmiz(id)
{
document.getElementById(id).style.visibility="hidden";
};
function zmiztext()
{
document.getElementById('message').value="";
}



function kontrolaPrazdna(id) {
  if (!jePrazdny(document.getElementById(id).value)) {
      document.getElementById(id).style.background = '#e1ffc1';
      document.getElementById(id).style.border = '1px solid #53a100';
    return true;
  } else {
      document.getElementById(id).style.background = '#ffc1c1';
      document.getElementById(id).style.border = '1px solid #c10000';
    return false;
  }
}

function kontrolaTelefonu(id) {
    value=document.getElementById(id).value;
		reg_vyraz=/^[ 0-9\.\+\/\-]{8,}$/;
		if (reg_vyraz.test(value)) {
        document.getElementById(id).style.background = '#e1ffc1';
        document.getElementById(id).style.border = '1px solid #53a100';
      return true;
    } else {
        document.getElementById(id).style.background = '#ffc1c1';
        document.getElementById(id).style.border = '1px solid #c10000';
      return false;
    }
}

function kontrolaJmena(id) {
    value=document.getElementById(id).value;
		reg_vyraz=/^[a-zA-Z0-9-_ áčďéěíňóřšťúůýžÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]{3,30}$/;
		if (reg_vyraz.test(value)) {
        document.getElementById(id).style.background = '#e1ffc1';
        document.getElementById(id).style.border = '1px solid #53a100';
      return true;
    } else {
        document.getElementById(id).style.background = '#ffc1c1';
        document.getElementById(id).style.border = '1px solid #c10000';
      return false;
    }
}

function kontrolaMailu(id) {
    value=document.getElementById(id).value;
		reg_vyraz=/^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$/;
		if (reg_vyraz.test(value)) {
        document.getElementById(id).style.background = '#e1ffc1';
        document.getElementById(id).style.border = '1px solid #53a100';
      return true;
    } else {
        document.getElementById(id).style.background = '#ffc1c1';
        document.getElementById(id).style.border = '1px solid #c10000';
      return false;
    }
}

function jePrazdny(retezec)
    {
      for(var i = 0; i < retezec.length; i++) {
        var znak = retezec.charAt(i);
        if ((znak != ' ') && (znak != '\n') && (znak != '\t')) return false;
      }
      return true;
    }

function spam() {
	if (document.getElementById('kontrola')) { 
	  document.getElementById('kontrola').value = '123';
		document.getElementById('hidden-timestamp').value = '1';
	}
	
	if (document.getElementById('kontrola-div')) { 
	  document.getElementById('kontrola-div').style.visibility = 'hidden';
	  document.getElementById('kontrola-div').style.display = 'none';
	}
}

// -- KONTROLA CELEHO FORMULARE ------------------------------------------------
function kontrolaCeleho() {
  var kontrola = true;
  if (document.getElementById('kuryr').checked == true) {
    if (!kontrolaPrazdna('adresa')) {kontrola = false;}
    if (!kontrolaPrazdna('telefon')) {kontrola = false;}
    if (!kontrolaPrazdna('odkdy')) {kontrola = false;}
    if (!kontrolaPrazdna('dokdy')) {kontrola = false;}   
  }
  if (!kontrolaJmena('jmeno')) {kontrola = false;}
  if (!kontrolaMailu('mail')) {kontrola = false;}
  
  if (!kontrola) {alert('Špatně vyplněný formulář! \n\nZkontroluje, zdali máte správně vyplněny všechny povinné položky.');}

	// kontrola proti spamu - uprava vychozi hodnoty
	if (kontrola){
		document.getElementById('hidden-timestamp').value = '1';
	}

  return kontrola;
}

