var Fade = 0, FadeDirection = true, ButtonB = new Image();
ButtonB.src = './img/button-b.png';

function InsertChar(i)
{
  var input = document.forms['newsadd-form'].elements['text'];

  if(document.selection)
  {
    input.focus();
    range = document.selection.createRange();
    range.text = i;
  }
  else if(input.selectionStart || input.selectionStart == '0')
  {
    var startPos = input.selectionStart;
    var endPos = input.selectionEnd;
    input.value = input.value.substr(0, startPos) + i + input.value.substr(endPos);
    input.focus();
    input.selectionStart = startPos + i.length;
    input.selectionEnd = startPos + i.length;
  } else {
    input.value += i;
    input.focus();
  }
}
function OpenImage(file, description, max_pht)
{
  var following = eval(file.substr(0,1));
  following--;
  if(following < 0) following = max_pht;

  document.getElementById('original_div1').innerHTML = '<a href="#" onclick="OpenImage(\''+following+file.substr(1)+'\',\'GEMA Fotogalerie\','+max_pht+')" style="cursor: pointer; cursor: hand">Další fotografie &raquo;</a>';
  document.getElementById('original').getElementsByTagName('img')[0].src = './img/content/gallery/original/'+file;
  document.getElementById('original_div2').innerHTML = description + ' <i>( Kliknutím zavřete )</i>';
  document.getElementById('original').style.display = 'block';
}
function CloseImage(imgid)
{
  document.getElementById('original').style.display = 'none';
  imgid.src = null;
}
function FadeSubHeader()
{
  if(FadeDirection) Fade += 10; else Fade -= 10;
  if((Fade > 200)||(Fade < 10)) FadeDirection = !FadeDirection;
  document.getElementById('SubHeadText').style.color = 'rgb(0,0,'+Fade+')';
  setTimeout("FadeSubHeader()", 300);
}
function SearchResults(Input)
{
  if((Input.length > 30) || (Input.length < 2))
  {
    document.getElementById('search-results').innerHTML = '<span style="color: #FF0000">Chybně zadaný výraz</span>';
    document.getElementById('search-results').style.display = 'block';
  } else {
    document.getElementById('search-results').style.display = 'block';
    document.getElementById('search-results').innerHTML = '<iframe src="./scripts/search.php?t='+Input+'" />';
  }
  return false;
}
function ValidEmail(email)
{
  var i = 1,switcher = 0;
  for(i;i<email.length;i++)
  {
    switch(switcher)
	{
	 case 0: if(email[i] == '@') switcher++; break;
	 case 1: if(email[i]=='.') switcher++; break;
	 default: return true;
	}
  }
  return false;
}
function EmailValidation()
{
  if(ValidEmail(document.getElementById('ask-mail').value)) document.getElementById('valid-email').src = './img/content-ok.png';
  else document.getElementById('valid-email').src = './img/content-wrong.png';
}
function CheckForm()
{
 if(ValidEmail(document.askform.askmail.value) == false) 
 {
  alert('Zadaný e-mail je chybný');
  return false;
 }
 else if(document.askform.asktext.value.length<=2)
 {
  alert('Zadejte text dotazu');
  return false;
 }
 else if(document.askform.validation.value.length<4)
 {
  alert('Zadejte ověřovací kód z obrázku');
  return false;
 }
 return true;
}
