// JavaScript Document

var tickspeed=6000 //ticker speed in miliseconds (2000=2 seconds)
var enablesubject=0 //enable scroller subject? Set to 0 to hide

if (document.getElementById){
document.write('<style type="text/css">\n')
document.write('.dropcontent{display:none;}\n')
document.write('</style>\n')
}

var selectedDiv=0
var totalDivs=0

function contractall(){
var inc=0
while (document.getElementById("dropmsg"+inc)){
document.getElementById("dropmsg"+inc).style.display="none"
inc++
}
}

function expandone(){
var selectedDivObj=document.getElementById("dropmsg"+selectedDiv)
contractall()
document.getElementById("dropcontentsubject").innerHTML=selectedDivObj.getAttribute("subject")
selectedDivObj.style.display="block"
selectedDiv=(selectedDiv<totalDivs-1)? selectedDiv+1 : 0
setTimeout("expandone()",tickspeed)
}

function startscroller(){
while (document.getElementById("dropmsg"+totalDivs)!=null)
totalDivs++
expandone()
if (!enablesubject)
document.getElementById("dropcontentsubject").style.display="none"
}

if (window.addEventListener)
window.addEventListener("load", startscroller, false)
else if (window.attachEvent)
window.attachEvent("onload", startscroller)

function otevriOkno(url, jmeno, w, h) {  
  popupWin = window.open(url, jmeno, 'resizable=1,top=20,left=20,menubar=0,scrollbars=yes,width=' + w + ',height=' + h);
}

function fitPic() {
if (window.innerWidth){
iWidth = window.innerWidth;
iHeight = window.innerHeight;
}
else{
iWidth = document.body.clientWidth;
iHeight =document.body.clientHeight;
}
iWidth = document.images[0].width - iWidth + 35;
iHeight = document.images[0].height - iHeight + 60;
window.resizeBy(iWidth, iHeight);
};

function emailCheck (emailStr) {
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
	alert("Zadaný e-mail je chybný, opravte jej prosím.")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]
if (user.match(userPat)==null) {
    alert("Zadaný e-mail je chybný, opravte jej prosím.")
    return false
}
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("IP adresa příjemce neexistuje, zadejte prosím správný e-mail.")
		return false
	    }
    }
    return true
}
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("Doména je zadána špatně, opravte ji prosím.")
    return false
}
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   alert("Adresa musí mít koncovku tvořenou dvěma či třemi písmeny.")
   return false
}
if (len<2) {
   var errStr="Adresa příjemce zřejmě neexistuje, pravděpodobně jste v ní udělali chybu."
   alert(errStr)
   return false
}
return true;
}
