// check browsers
var op = /opera/i.test(navigator.userAgent);
var ie = !op && /msie/i.test(navigator.userAgent);	     
var mz = !op && /mozilla\/5/i.test(navigator.userAgent); 
// add function getElementById to IE4
if (ie && (document.getElementById == null)) {
  document.getElementById = function( sId ) {
    return document.all[ sId ];
  };
}
activateMenu = function(nav) {
  if (document.all && document.getElementById(nav) && document.getElementById(nav).currentStyle) {
    var navroot = document.getElementById(nav)
    var lis=navroot.getElementsByTagName("LI");
    for (i=0; i<lis.length; i++) {
      if(lis[i].lastChild.tagName=="UL") {
        lis[i].onmouseover=function() { this.lastChild.style.display="block"; }
        lis[i].onmouseout=function() { this.lastChild.style.display="none"; }
      }
    }
  }
}

function externalLinks() {
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++) {
    var anchor = anchors[i];
    if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
      anchor.target = "_blank";
  }
}

function checkMail( form ) {
  if (form.from.value=="") {
    alert( "Musisz podać swój adres e-mail." );
    form.from.focus();
    return false ;
  }

  if (form.from.value!=""&&(form.from.value.indexOf('@',0)==-1||form.from.value.indexOf('.',0)==-1)) {
    alert("Nieprawidlowy adres e-mail.");
    form.from.focus();
    return false;
  }

  if (form.subject.value=="") {
    alert( "Musisz podać temat." );
    form.subject.focus();
    return false ;
  }

  if (form.content.value=="") {
    alert( "Musisz podać treść e-maila." );
    form.content.focus();
    return false ;
  }

  return true ;
}

function checkMailEN( form ) {
  if (form.from.value=="") {
    alert( "You have to enter your e-mail." );
    form.from.focus();
    return false ;
  }

  if (form.from.value!=""&&(form.from.value.indexOf('@',0)==-1||form.from.value.indexOf('.',0)==-1)) {
    alert("E-mail is not valid.");
    form.from.focus();
    return false;
  }

  if (form.subject.value=="") {
    alert( "You have to enter subject." );
    form.subject.focus();
    return false ;
  }

  if (form.content.value=="") {
    alert( "You have to enter content." );
    form.content.focus();
    return false ;
  }

  return true ;
}

function checkMedia( form ) {
  if (form.imie.value=="") {
    alert( "Musisz podać swoje imię." );
    form.imie.focus();
    return false ;
  }

  if (form.nazwisko.value=="") {
    alert( "Musisz podać swoje nazwisko." );
    form.nazwisko.focus();
    return false ;
  }

  if (form.email.value=="") {
    alert( "Musisz podać swój adres e-mail." );
    form.email.focus();
    return false ;
  }

  if (form.email.value!=""&&(form.email.value.indexOf('@',0)==-1||form.email.value.indexOf('.',0)==-1)) {
    alert("Nieprawidlowy adres e-mail.");
    form.email.focus();
    return false;
  }

  if (form.redakcja.value=="") {
    alert( "Musisz podać redakcję." );
    form.redakcja.focus();
    return false ;
  }

  if (form.agree.checked==false) {
    alert( "Musisz wyraźić zgodę na przesyłanie informacji prasowych." );
    form.agree.focus();
    return false ;
  }

  return true ;
}

function checkMediaEN( form ) {
  if (form.imie.value=="") {
    alert( "You have to enter your name." );
    form.imie.focus();
    return false ;
  }

  if (form.nazwisko.value=="") {
    alert( "You have to enter your surname." );
    form.nazwisko.focus();
    return false ;
  }

  if (form.email.value=="") {
    alert( "You have to enter your e-mail." );
    form.email.focus();
    return false ;
  }

  if (form.email.value!=""&&(form.email.value.indexOf('@',0)==-1||form.email.value.indexOf('.',0)==-1)) {
    alert("E-mail address is not valid.");
    form.email.focus();
    return false;
  }

  if (form.redakcja.value=="") {
    alert( "You have to enter publication." );
    form.redakcja.focus();
    return false ;
  }

  if (form.agree.checked==false) {
    alert( "You have to agree to receive press information." );
    form.agree.focus();
    return false ;
  }

  return true ;
}

function checkCard( form ) {
  if (form.imie.value=="") {
    alert( "Musisz podać swoje imię." );
    form.imie.focus();
    return false ;
  }

  if (form.nazwisko.value=="") {
    alert( "Musisz podać swoje nazwisko." );
    form.nazwisko.focus();
    return false ;
  }

  if (form.adres.value=="") {
    alert( "Musisz podać adres." );
    form.adres.focus();
    return false ;
  }

  if (form.miasto.value=="") {
    alert( "Musisz podać miasto." );
    form.miasto.focus();
    return false ;
  }

  if (form.kod.value=="") {
    alert( "Musisz podać kod pocztowy." );
    form.kod.focus();
    return false ;
  }

  if (form.agree.checked==false) {
    alert( "Musisz wyraźić zgodę na przetwarzanie danych osobowych zawartych w formularzu na potrzeby wysyłki pocztówki." );
    form.agree.focus();
    return false ;
  }

  return true ;
}

function insertTAG(tag) {
  if (!document.getElementsByTagName) return;
  document.forms.formularz.content.value+=tag;
}

var bold      = false;
var italic    = false;
var underline = false;
var center    = false;

function insertBOLD( ) {
  if (!document.getElementsByTagName) return;
  if (!bold) {
    document.forms.formularz.content.value+='[b]';
    document.forms.formularz.btnBold.value ='B*';
    bold = true;
  } else {
    document.forms.formularz.content.value+='[/b]';
    document.forms.formularz.btnBold.value ='B';
    bold = false;
  }
}

function insertITALIC( ) {
  if (!document.getElementsByTagName) return;
  if (!italic) {
    document.forms.formularz.content.value+='[i]';
    document.forms.formularz.btnItalic.value ='I*';
    italic = true;
  } else {
    document.forms.formularz.content.value+='[/i]';
    document.forms.formularz.btnItalic.value ='I';
    italic = false;
  }
}

function insertUNDERLINE( ) {
  if (!document.getElementsByTagName) return;
  if (!underline) {
    document.forms.formularz.content.value+='[u]';
    document.forms.formularz.btnUnderline.value ='U*';
    underline = true;
  } else {
    document.forms.formularz.content.value+='[/u]';
    document.forms.formularz.btnUnderline.value ='U';
    underline = false;
  }
}
  
function insertCENTER( ) {
  if (!document.getElementsByTagName) return;
  if (!center) {
    document.forms.formularz.content.value+='[center]';
    document.forms.formularz.btnCenter.value ='CENTER*';
    center = true;
  } else {
    document.forms.formularz.content.value+='[/center]';
    document.forms.formularz.btnCenter.value ='CENTER';
    center = false;
  }
}

function promptTAG(tagOpen, tagInside, tagClose) {
  var tagInside = prompt("Podaj adres: ", tagInside);
  if (tagInside!=null&&tagInside!=undefined) insertTAG(tagOpen+tagInside+tagClose);
}

function showSeason ( sezon ) {
  var sezonDiv = document.getElementById( sezon );
  if (sezonDiv.style.visibility=="hidden") {
    sezonDiv.style.visibility = "visible";
    sezonDiv.style.display = "block";
  } else {
    sezonDiv.style.visibility = "hidden";
    sezonDiv.style.display = "none";
  }
}

window.onload= function(){
    activateMenu('nav');
    externalLinks();
}