// JavaScript Document
var storage_data = new Object();
  
function menu() {
  var TO = null;
  var aMenu = null;
  if (window.ActiveXObject && (aMenu = document.getElementById("linkKatId"))) {
    /* Znajdujemy w dokumencie wszystkie listy */
    var lists = document.getElementsByTagName("ul");
    
    for (var i = 0; i < lists.length; i++) {
      /* Wybieramy listy z przypisana klasa 'menu' */
      if (lists[i].className == "submenu") {
          var menu = lists[i];
          menu.onmouseover = function() {
            if(TO) {
              clearTimeout(TO);
              TO=null;
            }
         }
         menu.onmouseout = function() {
            if(TO) {
              clearTimeout(TO);
              TO=null;
            }
            TO = setTimeout(function(){menu.style.display='none';},500);
        }
      }
    }
    aMenu.onmouseover = function() {
            menu.style.display="block";
            if(TO) {
              clearTimeout(TO);
              TO=null;
            }
         }
    aMenu.onmouseout = function() {
        if(TO) {
              clearTimeout(TO);
              TO=null;
            }
        TO = setTimeout(function(){menu.style.display='none';},500);
     }

  }

}
if(window.attachEvent) { attachEvent("onload", menu); }
else if(window.addEventListener) { addEventListener("load", menu, false); }

function setAttr(elem_id, attr, val) {
var element;
try {
if (document.getElementById)
      element = eval('document.getElementById(elem_id).' + attr + ' = val;');
else if (document.all)
      element = eval('document.all[elem_id].' + attr + ' = val;');
else if(document.layers)
      element = eval('document.layers[elem_id].' + attr + ' = val;');
} catch (e) {}
}

//setAttr('login','style.backgroundColor','white');
//setAttr('errorLoginIcon','src','_d/lay/ikona_i.gif');
//setAttr('errorLoginText','style.color','#808080');


function checkKat(){

if(document.getElementById('kat1').checked==false && document.getElementById('kat2').checked==false && document.getElementById('kat3').checked==false && document.getElementById('kat4').checked==false
&& document.getElementById('kat5').checked==false && document.getElementById('kat6').checked==false && document.getElementById('kat7').checked==false && document.getElementById('kat8').checked==false
&& document.getElementById('kat9').checked==false && document.getElementById('kat10').checked==false)
setAttr('errKodKat','style.color','red');
else{
   cover(0,'kategorie');
   PopOver('katt',0,590);
}

}

function checkURL(value) {
value = value.toLowerCase();
var urlregex = new RegExp("^(http://){0,1}([0-9A-Za-z\-])*\.{1}([0-9A-Za-z\-\.\/])*$");
if(urlregex.test(value))
{
return(true);
}
return(false);
}

function isUrl(s) {
s = s.toLowerCase();
 var regexp = /((ftp|http|https):\/\/)?(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
 return regexp.test(s);
}

function checkMail()
{
   adres = document.getElementById('eadres').value;
   var re = new RegExp("[^@]{1,}[@]{1}[^@.]{1,}[.]{1}[^@]{1,}","gi");
   var wynik = re.test(adres);
   var zgoda = document.getElementById('regulamin').checked ;
   if(!adres || !wynik )
   {
      setAttr('errKodMail','style.color','red');
      setAttr('email1','style.color','red');
      document.getElementById('errKodMail').innerHTML='<SPAN class=red>Podaj adres email</SPAN>';  
      //alert('Podaj prawidłowy adres email');
   }
   else if(!zgoda)
   {
      setAttr('errKodMail','style.color','red');
      document.getElementById('errKodMail').innerHTML='<SPAN class=red>Aby wzi±ć udział w konkursie musisz zaakceptować regulamin</SPAN>';  
   }
   else
   {
      //cover(0,'kat');
      //rewriteForms();
     cover(0,'katt');
     rewriteForms();
     
   }
}
function checkBlog()
{
   blogAdr = document.getElementById('adres').value;
   blogOpis = document.getElementById('opis').value;
   if(!blogAdr || !isURLBlog(blogAdr))
   {
    setAttr('errKodAdres','style.color','red');
    setAttr('addr','style.color','red');
    setAttr('adres','style.backgroundColor','#FFFFD9');
    document.getElementById('errKodAdres').innerHTML='<SPAN class=red>Podaj prawidłowy adres bloga</SPAN>';
   }
   else if(!blogOpis)
   {
    setAttr('errKodAdres','style.color','red');
    setAttr('opp','style.color','red');
    setAttr('opis','style.backgroundColor','#FFFFD9');
    document.getElementById('errKodAdres').innerHTML='<SPAN class=red>Opisz krótko swojego bloga</SPAN>';
   }
   else if(blogOpis.length>200)
   {
    setAttr('errKodAdres','style.color','red');
    document.getElementById('errKodAdres').innerHTML='<SPAN class=red>Podaj opis do 200 znaków</SPAN>'; 
   }
   else
   {
    cover(0,'b');
    PopOver('kategorie',0,730);
   }

}

function rewriteForms()
{
   cover(0,'zgloszenie');
   //alert(blogOpis);
   storage_data['baUrl']   = document.getElementById('adres').value;
   storage_data['baDesc']  = document.getElementById('opis').value;
   storage_data['catId']   = storage_data['catId'];
   storage_data['email']   = document.getElementById('eadres').value;
   zb();
   
}


function isURLBlog(urlStr) {

  document.getElementById('validateUrlBlog').style.display = "block";
  
  if (urlStr.indexOf(" ") != -1) {
    document.getElementById('validateUrlBlog').innerHTML='<SPAN class=red>W adresie bloga nie mog± znajdować się spacje</SPAN>';
    return false;
  }
  
  if (urlStr == "" || urlStr == null) {
    return true;
  }
  
  urlStr=urlStr.toLowerCase();
  
  var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
  var validChars="\[^\\s" + specialChars + "\]";
  var atom=validChars + '+';
  var urlPat=/^http:\/\/(\www\.)?([\-\+a-z0-9]*)\.(\w*)/;
  //http://zofia-mrzewinska.blog.onet.pl/
  //http://wwwzofia-mrzewinska.blog.onet.pl/
  var matchArray=urlStr.match(urlPat);
  
  if (matchArray==null) {
    document.getElementById('validateUrlBlog').innerHTML='<SPAN class=red>Adres bloga jest błędny !</SPAN>';
  
    return false;
  }
  
  var user=matchArray[2];
  var domain=matchArray[3];
  
  for (i=0; i<user.length; i++) {
    if (user.charCodeAt(i)>127) {  
      document.getElementById('validateUrlBlog').innerHTML='<SPAN class=red>Adres bloga zawiera niedozwolone znaki !</SPAN>';
      return false;
    }
  }
  
  for (i=0; i<domain.length; i++) {
    if (domain.charCodeAt(i) > 127) {
      document.getElementById('validateUrlBlog').innerHTML='<SPAN class=red>Adres bloga zawiera niedozwolone znaki !</SPAN>';
      return false;
    }
  }
  
  var atomPat=new RegExp("^" + atom + "$");
  var domArr=domain.split(".");
  var len=domArr.length;
  
  for (i=0;i<len;i++) {
    if (domArr[i].search(atomPat) == -1) {
      document.getElementById('validateUrlBlog').innerHTML='<SPAN class=red>Adres bloga jest nie popawny !</SPAN>';
      return false;
    }
  }
  document.getElementById('validateUrlBlog').style.display = "none";
  return true;
} 