/**
 * Maže defaultní text z textboxů.
 * @access public
 * @return void
 **/
function eraseDefaultText(o, defaultText)
{
  if (o.value == defaultText)
    o.value = "";
}

/**
 * Validace zadání emailu pro info o aktualizaci.
 * @access public
 * @return void
 **/
function validateEmailUpdate(text)
{
  var email = e("tbxEmailUpdate").value;

  var reg = new RegExp("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$");
  if (!reg.test(email))
  {
    window.alert(text);
    return false;
  }

  return true;
}

/**
 * Hlasování.
 * @access public
 * @return void
 **/
function voteRating(id, rating)
{
  e("hdnVoteRatingID").value = id;
	e("hdnVoteRatingRating").value = rating; 
	e("frmVoteRating").submit();
}

/**
 * Zobrazí formulář na zadání zprávy.
 * @access public
 * @return void
 **/
function showCommentForm(id)
{
  e("hdnCommentParentID").value = id;
  e("divCommentForm").style.display = "";
  e("btnCommentAdd").disabled = true;
  setFocusOnAddCommentForm();
  nastav_impressum();
}

/**
 * Skryje formulář na zadání zprávy.
 * @access public
 * @return void
 **/
function cancelCommentForm()
{
  e("hdnCommentParentID").value = 0;
  e("divCommentForm").style.display = "none";
  e("btnCommentAdd").disabled = false;
  nastav_impressum();
}

/**
 * Nastaví focus na první prázdné pole ve formuláři na přidávání komentářů.
 * @access public
 * @return void
 **/
function setFocusOnAddCommentForm()
{
  // focus na prvni prazdne pole, nebo na Text
  o = e("tbxCommentName");
  if ((o != null) && (o.value == ""))
    o.focus();
  else
  {
    o = e("tbxCommentTitle");
    if ((o != null) && (o.value == ""))
      o.focus();
    else
    {
      o = e("tbxCommentText");
      if (o != null)
        o.focus();
    }
  }
}

/**
 * Nastaví, že se zobrazí všechny komentáře.
 * @access public
 * @return void
 **/
function submitShowAllComments()
{
  e("hdnCommentsShowAll").value = "1";
  e("frmComments").submit();
}

/**
 * Nastaví, že se zobrazí vybrané komentáře.
 * @access public
 * @return void
 **/
function submitShowSelectedComments()
{
  e("hdnCommentsShowAll").value = "0";
  e("frmComments").submit();
}

/**
 * Zvýrazní hvězdičky při přejetí myší.
 * @access public
 * @return void
 **/
function highlightStars(base_dir, i, lang)
{
  if (lang == null)
    lang = "";
    
  for (j = 1; j <= 5; j++)
  {
    e("imgStar" + j.toString()).src = base_dir + "img/" + lang + "/hvezdicka_" + (j <= i ? "plna" : "prazdna") + ".gif"; 
  }
}

/**
 * Zruší zvýraznění hvězdiček při přejetí myší.
 * @access public
 * @return void
 **/
function resetStars(base_dir, rating, lang)
{
  if (lang == null)
    lang = "";

  for (j = 1; j <= 5; j++)
  {
    e("imgStar" + j.toString()).src = base_dir + "img/" + lang + "/hvezdicka_" + (j <= rating ? "plna" : "prazdna") + ".gif"; 
  }  
}

/**
 * Přidá položku do Můj download.
 * @access public
 * @return void
 **/
function addToMyDownload(base_dir, iduser, idprg, text)
{
  if (iduser == "")
  {
    alert(text);
    return;
  }
  
  var link = base_dir + "svc_mydownload.php?iduser=" + iduser + "&idprg=" + idprg;

  httpRequestMD = createAjax();
  httpRequestMD.open("GET", link, true);
  httpRequestMD.onreadystatechange= function () {getMyDownloadResult(); } ;
  httpRequestMD.send(null);
}

function getMyDownloadResult()
{
  if (httpRequestMD.readyState == 4)
    if (httpRequestMD.status == 200)
    {
      var resp = httpRequestMD.responseText;
    
      if (resp.match("MyDownloadYes"))
      {
	      var s = resp.split("|");
	      e("spanMyDownloadCount").innerHTML = s[1];
	      
	      alert(textMyDownloadSuccess);
      }
      else
        alert(textMyDownloadFailed);
    }
    else
      alert(textMyDownloadFailed);
}

function showAllOldVersions(o)
{
  o.style.display = "none";
  e("allOldVers").style.display = ""; 
}