function validForm(frm) {
	if (frm.author.value.search(/http/ig) >= 0) {alert("link is not a valid name! use another nickname.."); return false;}
	if (frm.author.value.search(/www/ig) >= 0) {alert("link is not a valid name! use another nickname.."); return false;}
	if (frm.emajo.value.search(/http/ig) >= 0) {alert("link is not a valid mail! use another mail.."); return false;}
	if (frm.emajo.value.search(/www/ig) >= 0) {alert("link is not a valid mail! use another mail.."); return false;}
	if (frm.text.value.search(/www./ig) >= 0) {alert("příspěvek obsahuje odkaz ve formátu www.* z důvodu omezení spamu musí být napřed ověřen administrátorem - příspěvek nevkládejte znovu, objeví se na guestbooku po ověření..\n\nthis entry contains a link (www.*) it has to be verified by the webmaster for reasons of spam reduction - do not submit this entry again, it will automatically appear after verification.."); return true;}
	if (frm.text.value.search(/http:/ig) >= 0) {alert("příspěvek obsahuje odkaz ve formátu http:... z důvodu omezení spamu musí být napřed ověřen administrátorem - příspěvek nevkládejte znovu, objeví se na guestbooku po ověření..\n\nthis entry contains a link (http:*) it has to be verified by the webmaster for reasons of spam reduction - do not submit this entry again, it will automatically appear after verification.."); return true;}
	document.getElementById('form').action='/diskuze/send.php';
	return true;
}
var s = 0;
function counter(el, i, counter) {
  if (el.value.length <= i){ 
    s = 0;
  }   
  if (el.value.length <= (i+s)){
	counter.innerHTML = el.value.length + "/" + i;
  }
  else {
  alert("Maximální délka příspěvku je 765 znaků!");
  s = (el.value.length-i);
  }	
}
function subm()
{
		document.getElementById('form').submit();
}
function MejlT(link)
{
  tt = link.title;
  at = tt.indexOf('(at)');
  name = tt.substring(0, at);
  dom = tt.substring(at+4);
	window.open('mailto:'+name+'@'+dom);
	return false;
}
function GenElMejl(text, nastr) {
	mejl = (nastr + "(at)" + "el-gauco");
	document.write("<a class=\"link\" href=\"#\" title=\""+mejl+".cz"+"\" onclick=\"return MejlT(this)\">"+text+"</a>");	
}
function GenMejl(dostr, aclass, text, nastr) {
	mejl = (nastr + "(at)" + dostr);
	document.write("<a class=\""+aclass+"\" href=\"\" title=\""+mejl+"\" onclick=\"return MejlT(this)\">"+text+"</a>");	
}

var exW = window.exW;
    
function OpenExl(link,winName)
{
      var retValue=true;
      if (exW!=null && !exW.closed)
      {
        exW.focus();
        exW.location.href=link.href;
      }
      else
      {
        exW=window.open(link.href,winName);
        if (exW==null || typeof(exW)=="undefined")
          retValue=false;
        else
        {
          link.target=winName;
          exW.focus();
        }
      }
      return retValue;
}

function showImage(seq, latest, video) {
  if (seq!=null)
  {
  if (latest==1) { 
  descs=descsl; hrefs=hrefsl; widths=widthsl; heights=heightsl; count=countl; vids=vidsl;
  } else { descs=descsr; hrefs=hrefsr; widths=widthsr; heights=heightsr; count=countr; vids=vidsr;}
  if (seq < (count-vids-1)) { 
  var nvid = 0;
  } else { 
  var nvid = 1;
  }
  if (seq < (count-vids+1)) { 
  var pvid = 0;
  } else { 
  var pvid = 1;
  }
    clearDiv();
    var detailwrap = document.getElementById("fotoWrap");
    var detail = document.getElementById("foto");
    var photo = document.getElementById("image");
    var arprev = document.getElementById("prev");
    var arnext = document.getElementById("next");
    var description = document.getElementById("desc");
    var wintab = document.getElementById("tab");
  	var tabHeight, detailScroll, yScroll, wh;
    	if (self.innerHeight) {
    		tabHeight = self.innerHeight;
    	} else if (document.documentElement && document.documentElement.clientHeight) {
    		tabHeight = document.documentElement.clientHeight;
    	} else if (document.body) {
  	  	tabHeight = document.body.clientHeight;
    	}
  		if (window.innerHeight && window.scrollMaxY) {	
  			detailScroll = window.innerHeight + window.scrollMaxY;
  		} else if (document.body.scrollHeight > document.body.clientHeight){
  			detailScroll = document.body.scrollHeight;
  		} else {
  			detailScroll = document.body.clientHeight;
  		}
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
			} else if (document.documentElement && document.documentElement.scrollTop){
				yScroll = document.documentElement.scrollTop;
			} else if (document.body) {
				yScroll = document.body.scrollTop;
			}
      detail.style.height = detailScroll + 'px';
      wintab.style.top = yScroll + 'px';
      wintab.style.height = tabHeight + 'px';
      detailwrap.style.visibility = 'visible';
      if (seq != 0) {
        arprev.style.display = 'block';
        arprev.onclick = function() { seq--; return showImage([seq], latest, pvid);};
      } else {
        arprev.style.display = 'none';
        arprev.onclick = function() { return false;};
      }
      if (seq < count-1) {
        arnext.style.display = 'block';
        arnext.onclick = function() { seq++; return showImage([seq], latest, nvid);};
      } else {
        arnext.style.display = 'none';
        arnext.onclick = function() { return false;};
      }
      var text = document.createTextNode(descs[seq]);
      var close = document.createElement("a");
      close.setAttribute('title', 'zavřít');      
      close.setAttribute('id', 'closer'); 
      close.setAttribute('href', '#'); 
      close.onclick = function() { return showIndex();};    
      var img = document.createElement("div");
      img.style.width = widths[seq] + 'px';
      img.style.height = heights[seq] + 'px';
      photo.style.width = widths[seq] + 'px';
      if (video!=1) {
      img.style.background = 'url(' + hrefs[seq] + ') center center no-repeat';
      photo.appendChild(img); 
      }
      if (video==1) {
      img.setAttribute('id', 'nojs');
      photo.appendChild(img);
      link = 'http://youtube.com/v/' + hrefs[seq] + '&autoplay=1';
      var so = new SWFObject(link, 'playvid', widths[seq], heights[seq], '7');
      so.addParam("wmode", "transparent");
      so.write("nojs");
      }
      photo.appendChild(close);
      description.appendChild(text);
      return false;
  }
}

function showIndex() {
    clearDiv();
    var detailwrap = document.getElementById("fotoWrap");
      detailwrap.style.visibility = 'hidden';
      return false;
}
  
function clearDiv() {
  document.getElementById("prev").onclick = null;
  document.getElementById("next").onclick = null;
  var clears = [document.getElementById("image"), document.getElementById("desc")];
  for (var i = 0; i < clears.length; i++) {
    var lng = clears[i].childNodes.length;
    for (var z = lng - 1; z >= 0 ; z--) {
      clears[i].removeChild(clears[i].childNodes[z]);
    }
  }
}

