// position of the tooltip relative to the mouse in pixel //
var offsetx = 12;
var offsety =  8;

function newelement(newid)
{ 
    if(document.createElement)
    { 
        var el = document.createElement('div'); 
        el.id = newid;     
        with(el.style)
        { 
            display = 'none';
            position = 'absolute';
        } 
        el.innerHTML = '&nbsp;'; 
        document.body.appendChild(el); 
    } 
} 
var ie5 = (document.getElementById && document.all); 
var ns6 = (document.getElementById && !document.all); 
var ua = navigator.userAgent.toLowerCase();
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);
function getmouseposition(e)
{
    if(document.getElementById)
    {
        var iebody=(document.compatMode && 
            document.compatMode != 'BackCompat') ? 
                document.documentElement : document.body;
        pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
        pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

        var lixlpixel_tooltip = document.getElementById('tooltip');
        lixlpixel_tooltip.style.left = (mousex+pagex+offsetx) + 'px';
        lixlpixel_tooltip.style.top = (mousey+pagey+offsety) + 'px';
    }
}
function tooltip(tip)
{
    if(!document.getElementById('tooltip')) newelement('tooltip');
    var lixlpixel_tooltip = document.getElementById('tooltip');
    lixlpixel_tooltip.innerHTML = tip;
    lixlpixel_tooltip.style.display = 'block';
    document.onmousemove = getmouseposition;
}
function exit()
{
    document.getElementById('tooltip').style.display = 'none';
}


function preveriKraj()
{
    var mess="";
    if(document.nov_kraj.kraj.value=="")
        alert("Kraj?");
    else{
        document.nov_kraj.action="index.php?kaj=nov_kraj"
        document.nov_kraj.submit();    
    }    
}

function najdi1(i)
{

 var f=document.obrazec;
 var mess=""
 switch(i){
    case 1:
        f.action="index.php?kaj=najdi";
        f.submit();        
        break;
    case 2:   
       
        if(f.dat1.value=="")
            mess="Datum igranja?\n";
        if(f.od.value=="")
            mess+="Začetek igranja - ura?\n";                 
       // if(f.do.value=="")
       ///     mess+="Konec igranja - ura?\n";  
        if(mess==""){                       
            f.action="index.php?kaj=najdi&to=shrani";
            f.submit();    
        }    
        else
            alert(mess);    
        break;  
 } 
 
}

function brisi(id)
{
 if(confirm("Ali naj izbrišem zapis"))
    window.location='index.php?kaj=vsi_vpisi&akcija=brisi&id='+id;
}


function preveriVpisEditor()
{
    var mess="";
    var f=document.klubedit;
    
    if(f.ime.value=="")
        mess+="Ime?\n";
    if(f.geslo.value=="")
        mess+="Geslo?\n";    
    if(f.ime_domene.value=="")
        mess+="Ime domene?\n";    
    if(f.naslov_podstrani.value=="")
        mess+="Naslov strani?\n";        
    if(mess=="")    
        f.submit();
    else{
        alert(mess);        
    }
    
}

function preveriVpisEditor1()
{
    var mess="";
    var f=document.klubedit1;
    if(f.id_klub.value=="")
        mess="Najprej vpišite in shranite osnovne podatke, nato dodajte slike ali dokumente\n"
    if(f.opis.value=="")
        mess+="Vpišite opis datoteke ali slike, ki bo viden obiskovalcem vaše strani?\n";
    if(f.priloga.value=="")
        mess+="Izberite datoteko za prenos na strežnik?\n";    
    if(mess=="")    
        f.submit();
    else{
        alert(mess);        
    }
    
}

function preveriVpis()
{
var mess="";
var f=document.registracija;
if(f.datum_vpisa.value=="")
    mess+="Datum?\n";
if(f.ime_vpisa.value=="")
    mess="Ime?\n";


if(f.id_kraj.options[f.id_kraj.selectedIndex].value=="")
    mess+="Kraj?\n";    
if(f.email_vpisa.value=="")
    mess+="Email?\n";    
else{
    var sp=valEmail(f.email_vpisa.value);
    if(sp!=="OK")
        mess+=sp; 
}    
 var id_vpisa=f.id_vpisa;
   
if(mess==""){
   f.action="index.php?kaj=shrani_vpis&id="+id_vpisa;
   f.submit();
}    
else
    alert(mess)    
}

function preveriRegistracijo()
{
var mess="";
var f=document.registracija;
if(f.ime.value=="")
    mess+="Ime?\n";

if(f.id_kraj.options[f.id_kraj.selectedIndex].value=="")
    mess+="Kraj?\n";    
if(f.itn.value=="")
    mess+="ITN številka?\n";    

if(f.email.value=="")
    mess+="Email?\n";    
else{
    var sp=valEmail(f.email.value);
    if(sp!=="OK")
        mess+=sp; 
}    
if(f.user.value=="")
    mess+="Uporabniško ime?\n";

if(f.un=='napaka')
    mess+="Izberite drugo uporabniško ime";   
if(f.pass.value=="")
    mess+="Geslo?\n";
else{
    if(f.pass.value!=f.pass1.value)
        mess+="Ponovljeno geslo ni enako prvemu vpisu?\n";
} 

if(mess==""){
   checkUser();
}    
else
    alert(mess)   
}      


function preveriLogin()
{
var mess="";
var f=document.prijava;
if(f.email.value=="")
    mess+="Email?\n";    
   
if(f.pass.value=="")
    mess+="Geslo?\n";
    
if(mess==""){
    f.action="index.php?kaj=login";
    f.submit();
}    
else
    alert(mess)    
}
function valEmail(emailStr)
{
  /* The following variable tells the rest of the function whether or not
  to verify that the address ends in a two-letter country or well-known
  TLD.  1 means check it, 0 means don't. */
  var checkTLD=1;

  /* The following is the list of known TLDs that an e-mail address must end with. */
  var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

  /* The following pattern is used to check if the entered e-mail address
  fits the user@domain format.  It also is used to separate the username
  from the domain. */
  var emailPat=/^(.+)@(.+)$/;

  /* The following string represents the pattern for matching all special
  characters.  We don't want to allow special characters in the address.
  These characters include ( ) < > @ , ; : \ " . [ ] */
  var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

  /* The following string represents the range of characters allowed in a
  username or domainname.  It really states which chars aren't allowed.*/
  var validChars="\[^\\s" + specialChars + "\]";

  /* The following pattern applies if the "user" is a quoted string (in
  which case, there are no rules about which characters are allowed
  and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
  is a legal e-mail address. */
  var quotedUser="(\"[^\"]*\")";

  /* The following pattern applies for domains that are IP addresses,
  rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
  e-mail address. NOTE: The square brackets are required. */
  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

  /* The following string represents an atom (basically a series of non-special characters.) */
  var atom=validChars + '+';

  /* The following string represents one word in the typical username.
  For example, in john.doe@somewhere.com, john and doe are words.
  Basically, a word is either an atom or quoted string. */
  var word="(" + atom + "|" + quotedUser + ")";

  // The following pattern describes the structure of the user
  var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

  /* The following pattern describes the structure of a normal symbolic
  domain, as opposed to ipDomainPat, shown above. */
  var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");


  /* Finally, let's start trying to figure out if the supplied address is valid. */


  /* Begin with the coarse pattern to simply break up user@domain into
  different pieces that are easy to analyze. */
  var matchArray=emailStr.match(emailPat);
  if (matchArray == null)
  {
    /* Too many/few @'s or something; basically, this address doesn't
    even fit the general mould of a valid e-mail address. */
    error = "Nepravilen E-mail (preverite @ in pike)";
    return error;
  }

  var user=matchArray[1];
  var domain=matchArray[2];

  // Start by checking that only basic ASCII characters are in the strings (0-127).
  for (i=0; i < user.length; i++)
  {
    if (user.charCodeAt(i) > 127)
    {
      error = "Nepravilen E-mail (preverite del pred @)";
      return error;
    }
  }
  for (i=0; i < domain.length; i++)
  {
    if (domain.charCodeAt(i)>127)
    {
      error = "Nepravilen E-mail (preverite del za @)";
      return error;
    }
  }

  // See if "user" is valid
  if (user.match(userPat)==null)
  {
    // user is not valid
    error = "Nepravilen E-mail (preverite del pred @)";
    return error;
  }

  /* if the e-mail address is at an IP address (as opposed to a symbolic
  host name) make sure the IP address is valid. */
  var IPArray=domain.match(ipDomainPat);
  if (IPArray != null)
  {
    // this is an IP address
    for (var i=1;i <= 4;i++)
    {
      if (IPArray[i]>255)
      {
        error = "Nepravilen E-mail (ciljni IP je nepravilen)";
        return error;
      }
    }
    return true;
  }

  // Domain is symbolic name.  Check if it's valid.
  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)
    {
      error = "Nepravilen E-mail (preverite del za @)";
      return error;
    }
  }

  /* domain name seems valid, but now make sure that it ends in a
  known top-level domain (like com, edu, gov) or a two-letter word,
  representing country (uk, nl), and that there's a hostname preceding
  the domain or country. */
  if (checkTLD && (domArr[domArr.length-1].length != 2) && (domArr[domArr.length-1].search(knownDomsPat) == -1))
  {
    error = "Nepravilen E-mail (preverite koncnico)";
    return error;
  }

  // Make sure there's a host name preceding the domain.
  if (len < 2)
  {
    error = "Nepravilen E-mail (preverite del za @)";
    return error;
  }

  // If we've gotten this far, everything's valid!
  return "OK";
  }
