/*
 *  Dokument:       Zakladni spolecne funkce pro js
 *  Posledni zmena: 13.03.2009
 */

String.prototype.trim = function()
{
  a = this.replace(/^\s+/, '');
  return a.replace(/\s+$/, '');
}

/*
 * Zkontroluje platny format emailove adresy
 */
function validEmail(email)
{
  invalidChars = " /:,;"

  if(email == "")
  {
    return false
  }
  for(i=0; i < invalidChars.length; i++)
  {
    badChar = invalidChars.charAt(i)
    if (email.indexOf(badChar,0) > -1)
    {
      return false
    }
  }
  atPos = email.indexOf("@",1)
  if(atPos == -1)
  {
    return false
  }
  if(email.indexOf("@",atPos+1) > -1)
  {
    return false
  }
  periodPos = email.indexOf(".",atPos)
  if(periodPos == -1)
  {
    return false
  }
  if(periodPos+3 > email.length)
  {
    return false
  }
  return true
}


/*
 * Zkontroluje zda zadany text obsahuje diakritiku
 */
function bezdiakString(string)
{
  var sdiak = "áäčďéěíĺžňóôőöŕúůűüýřÁÄČĎÉĚÍĹźŇÓÔŐÖŔÚŮŰÜÝŘ";

  var spravne = 1;  // 1 = bez diakritiky, 2 = s diakritikou

  for(p = 0; p < string.length; p++)
  { // proverim, jestli v nazvu neni znak s diakritikou...

    if(sdiak.indexOf(string.charAt(p)) != -1)
    {
      spravne = 2;
      break;
    }
    else continue;
  } // end for

  if(spravne > 1) return false;
  else return true;
} // end function


/** Zkontroluje platny format data
 * @param string
 */
function validDate(date)
{
  return true;
}
function validPhone(phonenumber)
{
vyraz = /^[+]?[()/0-9. -]{9,}$/
if (vyraz.test(phonenumber)==true)
  return true;
else 
  return false;
}

function showForm(id) {
  
  if (document.getElementById(id).className == "hidden") {
    document.getElementById(id).className="";
    return false
  }
  else if (document.getElementById(id).className == "") {
    document.getElementById(id).className="hidden";
    return false
  }
}
function validateCenaTyp(id) {
  index = id.selectedIndex;
  if (id.options[index].value == 7) {
    document.getElementById("cena").disabled = true;
    document.getElementById("cena").className = "hidden";
  }
  else {
    document.getElementById("cena").disabled = false;
    document.getElementById("cena").className = "";  
  }
}

