function trim(string)
{
   return string.replace(/^\s*|\s*$/g,"");
}

function checkIntroMagazine( postForm )
{
  if( trim(postForm.articleContent.value) == "" )
  {
    var errorMessage = "Není možné mít prázdné políčko!";
    
    window.alert(errorMessage);
    return false; //chyba, nepusti se dale    
  }
  else //OK
  {
    return true;
  }
}

function checkNewArticle( postForm )
{
  var fTitle = 0, fIntroText = 0, fFileName = 0, fArticleContent = 0;
  
  if( trim(postForm.nTitle.value) == "" )
    fTitle = 1;
    
  if( trim(postForm.nIntroText.value) == "" )
    fIntroText = 1; 
  
  file = trim(postForm.nFileName.value);
  if( file == "" )
    fFileName = 1; 
  else
  {
    pripona = file.substring( file.lastIndexOf('.') + 1 ).toLowerCase();
    if( pripona != "jpg" && pripona != "jpeg" && pripona != "gif" && pripona != "png" )
      fFileName = 2;
  }
      
  if( trim(postForm.articleContent.value) == "" )
    fArticleContent = 1;       

  var errorMessage = "Není možné mít prázdná políčka! -- ";

  if( fTitle )
  {
    errorMessage = errorMessage + "'Nadpis' ";
  }
  
  if( fIntroText )
  {
    errorMessage = errorMessage + "'Popisek' ";
  }  
  
  if( fFileName )
  {
    if( fFileName == 1 )
      errorMessage = errorMessage + "'Náhledový obrázek' ";
    else if( fFileName == 2 )
      errorMessage = errorMessage + "'Formát obrázku' ";
  } 
  
  if( fArticleContent )
  {
    errorMessage = errorMessage + "'Obsah článku' ";
  }      
   

  if( fTitle || fIntroText || fFileName || fArticleContent )
  {
    window.alert(errorMessage);
    return false; //chyba, nepusti se dale
  }
  else
  { 
    return true;
  }  
}


function checkEditArticle( postForm )
{
  var fTitle = 0, fIntroText = 0, fArticleContent = 0;
  
  if( trim(postForm.nTitle.value) == "" )
    fTitle = 1;
    
  if( trim(postForm.nIntroText.value) == "" )
    fIntroText = 1; 

  if( trim(postForm.articleContent.value) == "" )
    fArticleContent = 1;       
  
  if( postForm.eFileWhat[1].checked )
  {
    file = trim(postForm.nFileName.value);
    if( file == "" )
      fFileName = 1;
    
    else
    {
      pripona = file.substring( file.lastIndexOf('.') + 1 ).toLowerCase();
      if( pripona != "jpg" && pripona != "jpeg" && pripona != "gif" && pripona != "png" )
        fFileName = 2;
    }
  }
  
  var errorMessage = "Není možné mít prázdná políčka! -- ";

  if( fTitle )
  {
    errorMessage = errorMessage + "'Nadpis' ";
  }
  
  if( fIntroText )
  {
    errorMessage = errorMessage + "'Popisek' ";
  }  
  
  if( fArticleContent )
  {
    errorMessage = errorMessage + "'Obsah článku' ";
  }      
   
  if( fFileName )
  {
    if( fFileName == 1 )
      errorMessage = errorMessage + "'Náhledový obrázek' ";
    else if( fFileName == 2 )
      errorMessage = errorMessage + "'Formát obrázku' ";
  } 

  if( fTitle || fIntroText || fArticleContent || fFileName )
  {
    window.alert(errorMessage);
    return false; //chyba, nepusti se dale
  }
  else
  { 
    return true;
  }  
}


/**
 * Mazani clanecku. Dotaz, zda chce admin skutecne mazat clanek.
 */ 
function deleteArticle()
{
  var ifDelete = confirm("Chcete skutečně smazat tento článek?");
  return ifDelete;  
}

