/////////////////////////////////////////////////////////////////////////////////
//
// Vinoteka.com Javascript
//
// (c)2008-2009 by Abacus, info ath abacus doth hr
//
// v1.15 24.3.2009. DSalopek
//
/////////////////////////////////////////////////////////////////////////////////

//-------------------------------------------------------------------------------
//
// globalne varijable
//
//-------------------------------------------------------------------------------

var xURI = 'A=NAS';
var xMENU = 'NAS';
var xWSPCID = 722;
var xNS = (navigator.appName.indexOf("Netscape") != -1);
var xDOC = document;
var xAJAXURI;

//-------------------------------------------------------------------------------
//
// status
//
//-------------------------------------------------------------------------------

window.defaultStatus='Vinoteka';

function S(pMSG) {
  if (pMSG!='') { pMSG='Vinoteka: '+pMSG }
  window.status=pMSG;
  return(true);
}


//-------------------------------------------------------------------------------
//
// AJAX
//
//-------------------------------------------------------------------------------

function ajaxEvaluate (pTXT) {
  var rSCRIPT = new RegExp('(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)', 'img');
  var tSCRIPT = '';
  while (tSCRIPT = rSCRIPT.exec(pTXT)) { eval(tSCRIPT[1]) }
}

function getDataReturnText (pURL,pTAG) { 
  var XMLHttpRequestObject = false; 
  if (window.XMLHttpRequest) { XMLHttpRequestObject = new XMLHttpRequest() } 
  else if (window.ActiveXObject) {
    XMLHttpRequestObject = new 
   ActiveXObject("Microsoft.XMLHTTP");
  }

  if(XMLHttpRequestObject) {
    XMLHttpRequestObject.open('GET', pURL+'&DUMMY='+new Date().getTime()); 
    XMLHttpRequestObject.onreadystatechange = function()  { 
      if (XMLHttpRequestObject.readyState == 4 && 
        XMLHttpRequestObject.status == 200) { 
          ajaxCallback(XMLHttpRequestObject.responseText,pTAG);
          delete XMLHttpRequestObject;
          XMLHttpRequestObject = null;
      } 
    } 

    XMLHttpRequestObject.send(null); 
  }
}


function ajaxCallback (pTXT,pTAG) {
  ajaxEvaluate(pTXT);
  if (pTAG==undefined) { 
    pTAG='BODY';
    if (xAJAXURI) { getDataReturnText('?JSRS=MENU-TOP&'+xAJAXURI,'MENU-TOP') }
  }
  if (xDOC.getElementById('NAVIGATOR')) {
    rNAVIG=/^<NAVIGATOR>(.*)<\/NAVIGATOR>/m;
    var NAVIG=rNAVIG.exec(pTXT);
    if (NAVIG) {
      pTXT=pTXT.replace(rNAVIG,'');
      xDOC.getElementById('NAVIGATOR').innerHTML=NAVIG[1];
    }
  }
  if (xDOC.getElementById(pTAG)) { xDOC.getElementById(pTAG).innerHTML=pTXT; DekodirajURI(); }
  if (myLytebox) { myLytebox.updateLyteboxItems() }
}


function Update(pTAG,pURI) {
  xURI=pURI;
  if (pTAG=='BODY') { 
    getDataReturnText('?JSRS=MENU-TOP&'+pURI,'MENU-TOP');
    xSAL.PassAjaxResponseToFunction('?JSRS='+pTAG+'&'+pURI+'&DUMMY='+new Date().getTime(),'ajaxCallback');
  }
  else { getDataReturnText('?JSRS='+pTAG+'&'+pURI,pTAG) }
} 


function encodeHtml(pTXT) {
  var tRET=escape(pTXT);
  tRET=tRET.replace(/&/g, '%26');
  tRET=tRET.replace(/\//g,'%2F');
  tRET=tRET.replace(/=/g, '%3D');
  tRET=tRET.replace(/\?/g,'%3F');
  tRET=tRET.replace(/@/g, '%40');
  return(tRET);
} 


function getElementFormValues(pE) {
  var tURI='';
  var rTAG=/^(TABLE|TBODY|TR|TD|NOBR|CENTER|DIV|SPAN|A)$/;
  for (var tI=0; tI<pE.childNodes.length; tI++) {
    var tNODE=pE.childNodes[tI];
    if (rTAG.test(tNODE.tagName))  { tURI+=getElementFormValues(tNODE) }
    if (tNODE.name) {
      if (tNODE.tagName=='INPUT') {
        if (tNODE.type=='text')      { tURI+=tNODE.name+'='+encodeHtml(tNODE.value)+'&' }
        if (tNODE.type=='hidden')    { tURI+=tNODE.name+'='+encodeHtml(tNODE.value)+'&' }
        if (tNODE.type=='checkbox')  { if (tNODE.checked) { tURI+=tNODE.name+'='+encodeHtml(tNODE.value)+'&' } }
        if (tNODE.type=='radio')     { if (tNODE.checked) { tURI+=tNODE.name+'='+encodeHtml(tNODE.value)+'&' } }
      }
      if (tNODE.tagName=='TEXTAREA') { tURI+=tNODE.name+'='+encodeHtml(tNODE.value)+'&' }
      if (tNODE.tagName=='SELECT')   { tURI+=tNODE.name+'='+encodeHtml(tNODE.options[tNODE.selectedIndex].value)+'&' }
    }
  }
  return(tURI);
}


function UpdateForm(pTAG,pFORMID) {
  var tFORM=xDOC.getElementById(pFORMID);
  var tURI=getElementFormValues(tFORM);
  Update(pTAG,tURI);
}

//-------------------------------------------------------------------------------
//
// dekodiranja E-mailova
//
//-------------------------------------------------------------------------------

function DekodirajURI() {
  if (!xDOC.getElementsByTagName && !xDOC.createElement && !xDOC.createTextNode) return;
  var cvorovi=xDOC.getElementsByTagName('span');
  for(var i=cvorovi.length-1;i>=0;i--) {
    if (cvorovi[i].className=='DECODE') {
      var na=/ \(na\) /;
      var tocka=/ \(tocka\) /g;
      var cvor=xDOC.createElement('a');
      var URI=cvorovi[i].firstChild.nodeValue;

      URI = URI.replace(na,'@');
      URI = URI.replace(tocka,'.');
      cvor.setAttribute('href','mailto:'+URI);
      cvor.setAttribute('className','LINK');
      cvor.setAttribute('class','LINK');
      cvor.appendChild(xDOC.createTextNode(URI));
      
      var ispis = cvorovi[i].parentNode;
      for(var j=0;j<ispis.childNodes.length;j++)
        if (ispis.childNodes[j] == cvorovi[i]) {
          if (!ispis.replaceChild) return;
          ispis.replaceChild(cvor,ispis.childNodes[j]);
          break;
        }
    }
  }
}

//-------------------------------------------------------------------------------
//
// provjera formi
//
//-------------------------------------------------------------------------------

function CheckForm(form,name) {
  var email=/[\w\-\.]+\@[\-\w\.]+\.[\w\-\.]{2,4}/;
  var ime=/[\w\.]+.*\s+.*[\w\.]+/;
  var prazno=/[\d\w]+/;
  var godina=/^(19|20)\d{2}$/;
  var captcha=/^[\d]{5}$/;
  var broj=/^\d+(,\d+)*$/;

  // salji link
  if (name=='LIN') {
    if (!captcha.test(form.LIN_CODE.value)) {
      alert('Niste upisali kontrolni kod!');
      form.LIN_CODE.focus();
      return(false);
    }
    else if (!ime.test(form.IME.value)) {
      alert('Niste upisali ime i prezime!');
      form.IME.focus();
      return(false);
    }
    else if (!email.test(form.EPO.value)) {
      alert('Niste upisali ispravni E-mail!');
      form.EPO.focus();
      return(false);
    }
    else if (!email.test(form.EPR.value)) {
      alert('Niste upisali ispravni E-mail!');
      form.EPR.focus();
      return(false);
    }
  }


  // vina za online shopping
  else if (name=='UNV') {
    if (!prazno.test(form.NAZ.value)) {
      alert('Niste upisali naziv vina!');
      form.NAZ.focus();
      return(false);
    }
    else if (!prazno.test(form.PRO.value)) {
      alert('Niste upisali proizvođača vina!');
      form.PRO.focus();
      return(false);
    }
    else if (!prazno.test(form.VGO.value)) {
      alert('Niste upisali vinogorje!');
      form.VGO.focus();
      return(false);
    }
    else if (!prazno.test(form.GOD.value)) {
      alert('Niste upisali godinu proizvodnje!');
      form.GOD.focus();
      return(false);
    }
    else if (!prazno.test(form.MJE.value)) {
      alert('Niste upisali mjeru!');
      form.MJE.focus();
      return(false);
    }
    else if (!broj.test(form.CIJ.value)) {
      alert('Niste ispravno upisali cijenu!');
      form.TIP.focus();
      return(false);
    }        
  }
  
  // moj racun
  else if (name=='ACC') {
    if (!prazno.test(form.IME.value)) {
      alert('Niste upisali Vaše ime!');
      form.IME.focus();
      return(false);
    }
    else if (!prazno.test(form.NAD.value)) {
      alert('Niste upisali Vaš nadimak!');
      form.NAD.focus();
      return(false);
    }
    else if (!prazno.test(form.ROD.value)) {
      alert('Niste upisali godinu rođenja!');
      form.ROD.focus();
      return(false);
    }
    else if (!prazno.test(form.INT.value)) {
      alert('Niste upisali Vaše interese!');
      form.INT.focus();
      return(false);
    }
    else if (!prazno.test(form.ADR.value)) {
      alert('Niste upisali Vašu adresu!');
      form.ADR.focus();
      return(false);
    }
    else if (!prazno.test(form.MJE.value)) {
      alert('Niste upisali mjesto stanovanja!');
      form.MJE.focus();
      return(false);
    }
    else if (!prazno.test(form.TEL.value)) {
      alert('Niste upisali Vaš broj telefona!');
      form.TEL.focus();
      return(false);
    }
    else if (!prazno.test(form.GSM.value)) {
      alert('Niste upisali Vaš broj mobitela!');
      form.GSM.focus();
      return(false);
    }
    else if (!prazno.test(form.EMA.value)) {
      alert('Niste upisali Vašu e-mail adresu!');
      form.EMA.focus();
      return(false);
    }
    else if (!prazno.test(form.KON.value)) {
      alert('Niste upisali način na koji želite da Vas kontaktiramo!');
      form.KON.focus();
      return(false);
    }
    else if (!prazno.test(form.KOR.value)) {
      alert('Niste upisali Vaše korisničko ime!');
      form.KON.focus();
      return(false);
    }
    else if (!prazno.test(form.LOZ.value)) {
      alert('Niste upisali Vašu lozinku!');
      form.LOZ.focus();
      return(false);
    }       
  }
  
  // novo vino
  else if (name=='OCJ') {
    if (!prazno.test(form.NAZ.value)) {
      alert('Niste upisali naziv vina!');
      form.NAZ.focus();
      return(false);
    }
    else if (!prazno.test(form.PRO.value)) {
      alert('Niste upisali proizvođača vina!');
      form.PRO.focus();
      return(false);
    }
    else if (!prazno.test(form.VIN.value)) {
      alert('Niste upisali vinogorje!');
      form.VIN.focus();
      return(false);
    }
    else if (!prazno.test(form.GOD.value)) {
      alert('Niste upisali godinu berbe!');
      form.GOD.focus();
      return(false);
    }
    else if (!prazno.test(form.DAT.value)) {
      alert('Niste upisali datum degustacije!');
      form.DAT.focus();
      return(false);
    }
    else if (!prazno.test(form.VID.value)) {
      alert('Niste upisali ocijenjivanje putem vida!');
      form.VID.focus();
      return(false);
    }
    else if (!prazno.test(form.NJU.value)) {
      alert('Niste upisali ocijenjivanje putem njuha!');
      form.NJU.focus();
      return(false);
    }
    else if (!prazno.test(form.OKU.value)) {
      alert('Niste upisali ocijenjivanje putem okusa!');
      form.OKU.focus();
      return(false);
    }
    else if (!prazno.test(form.ZAV.value)) {
      alert('Niste upisali završna razmatranja!');
      form.ZAV.focus();
      return(false);
    }      
  }
  
  // izrada vinske karte
  else if (name=='KAR') {
    if (!captcha.test(form.KAR_CODE.value)) {
      alert('Niste upisali kontrolni kod!');
      form.KAR_CODE.focus();
      return(false);
    }
    else if (!ime.test(form.IME.value)) {
      alert('Niste upisali ime i prezime ili tvrtku!');
      form.IME.focus();
      return(false);
    }
    else if (!prazno.test(form.TEL.value)) {
      alert('Niste upisali broj telefona!');
      form.TEL.focus();
      return(false);
    }
    else if (!prazno.test(form.ADR.value)) {
      alert('Niste upisali adresu!');
      form.ADR.focus();
      return(false);
    }
    else if (!prazno.test(form.MJE.value)) {
      alert('Niste upisali mjesto!');
      form.MJE.focus();
      return(false);
    }
    else if (!email.test(form.EMA.value)) {
      alert('Niste upisali ispravni E-mail!');
      form.EMA.focus();
      return(false);
    }
    else if (!prazno.test(form.BRO.value)) {
      alert('Niste upisali broj vina!');
      form.BRO.focus();
      return(false);
    }
    else if (!checkRadio(form.PRI)) {
      alert('Niste odabrali način primitka!');
      return(false);
    }
    else if (!prazno.test(form.JEL.value)) {
      alert('Niste upisali podatke o jelima!');
      form.JEL.focus();
      return(false);
    }
  }

  // savjetovanje
  else if (name=='SAV') {
    if (!captcha.test(form.SAV_CODE.value)) {
      alert('Niste upisali kontrolni kod!');
      form.SAV_CODE.focus();
      return(false);
    }
    else if (!ime.test(form.IME.value)) {
      alert('Niste upisali ime i prezime!');
      form.IME.focus();
      return(false);
    }
    else if (!prazno.test(form.TVR.value)) {
      alert('Niste upisali tvrtku ili restoran!');
      form.TVR.focus();
      return(false);
    }
    else if (!prazno.test(form.TEL.value)) {
      alert('Niste upisali broj telefona!');
      form.TEL.focus();
      return(false);
    }
    else if (!prazno.test(form.ADR.value)) {
      alert('Niste upisali adresu!');
      form.ADR.focus();
      return(false);
    }
    else if (!prazno.test(form.MJE.value)) {
      alert('Niste upisali mjesto!');
      form.MJE.focus();
      return(false);
    }
    else if (!email.test(form.EMA.value)) {
      alert('Niste upisali ispravni E-mail!');
      form.EMA.focus();
      return(false);
    }
    else if (!checkRadio(form.PRI)) {
      alert('Niste odabrali način primitka!');
      return(false);
    }
  }


  // cjenik
  else if (name=='CJE') {
    if (!captcha.test(form.CJE_CODE.value)) {
      alert('Niste upisali kontrolni kod!');
      form.CJE_CODE.focus();
      return(false);
    }
    else if (!ime.test(form.IME.value)) {
      alert('Niste upisali ime i prezime ili tvrtku!');
      form.IME.focus();
      return(false);
    }
    else if (!prazno.test(form.TEL.value)) {
      alert('Niste upisali broj telefona!');
      form.TEL.focus();
      return(false);
    }
    else if (!prazno.test(form.ADR.value)) {
      alert('Niste upisali adresu!');
      form.ADR.focus();
      return(false);
    }
    else if (!prazno.test(form.MJE.value)) {
      alert('Niste upisali mjesto!');
      form.MJE.focus();
      return(false);
    }
    else if (!email.test(form.EMA.value)) {
      alert('Niste upisali ispravni E-mail!');
      form.EMA.focus();
      return(false);
    }
    else if (!checkRadio(form.INT)) {
      alert('Niste odabrali interes!');
      return(false);
    }
    else if (!checkRadio(form.PRI)) {
      alert('Niste odabrali način primitka!');
      return(false);
    }
  }
  
  // cjenik za izvoz
  else if (name=='ECJ') {
    if (!captcha.test(form.ECJ_CODE.value)) {
      alert('Bad control code!');
      form.ECJ_CODE.focus();
      return(false);
    }
    else if (!ime.test(form.IME.value)) {
      alert('Enter name or company name!');
      form.IME.focus();
      return(false);
    }
    else if (!prazno.test(form.TEL.value)) {
      alert('Enter phone number!');
      form.TEL.focus();
      return(false);
    }
    else if (!prazno.test(form.ADR.value)) {
      alert('Enter address!');
      form.ADR.focus();
      return(false);
    }
    else if (!prazno.test(form.MJE.value)) {
      alert('Enter city!');
      form.MJE.focus();
      return(false);
    }
    else if (!email.test(form.EMA.value)) {
      alert('Enter a valid E-mail!');
      form.EMA.focus();
      return(false);
    }
    else if (!checkRadio(form.INT)) {
      alert('Select type of interest!');
      return(false);
    }
    else if (!checkRadio(form.PRI)) {
      alert('Select delivery type!');
      return(false);
    }
  }

  // registracija za sommelierski kutak
  else if (name=='REG') {
    if (!captcha.test(form.REG_CODE.value)) {
      alert('Niste upisali kontrolni kod!');
      form.REG_CODE.focus();
      return(false);
    }
    else if (!ime.test(form.IME.value)) {
      alert('Niste upisali ime i prezime!');
      form.IME.focus();
      return(false);
    }
    else if (!prazno.test(form.ZAN.value)) {
      alert('Niste upisali zanimanje ili kvalifikaciju!');
      form.ZAN.focus();
      return(false);
    }
    else if (!godina.test(form.GOD.value)) {
      alert('Niste upisali ispravnu godinu rođenja!');
      form.GOD.focus();
      return(false);
    }
    else if (!prazno.test(form.ADR.value)) {
      alert('Niste upisali adresu!');
      form.ADR.focus();
      return(false);
    }
    else if (!prazno.test(form.MJE.value)) {
      alert('Niste upisali mjesto!');
      form.MJE.focus();
      return(false);
    }
    else if (!prazno.test(form.TEL.value)) {
      alert('Niste upisali broj telefona!');
      form.TEL.focus();
      return(false);
    }
    else if (!prazno.test(form.MOB.value)) {
      alert('Niste upisali broj mobitela!');
      form.MOB.focus();
      return(false);
    }
    else if (!checkRadio(form.KON)) {
      alert('Niste odabrali način kontaktiranja!');
      return(false);
    }
    else if (!email.test(form.EMA.value)) {
      alert('Niste upisali ispravni E-mail!');
      form.EMA.focus();
      return(false);
    }
    else if (!prazno.test(form.NAD.value)) {
      alert('Niste upisali način nadimak!');
      form.NAD.focus();
      return(false);
    }
  }

  // login
  else if (name=='PRI') {
    if (!captcha.test(form.PRI_CODE.value)) {
      alert('Niste upisali ispravan kontrolni kod!');
      form.PRI_CODE.focus();
      return(false);
    }
    else if (!prazno.test(form.USER.value)) {
      alert('Niste upisali korisničko ime!');
      form.USER.focus();
      return(false);
    }
    else if (!prazno.test(form.PASS.value)) {
      alert('Niste upisali lozinku!');
      form.PASS.focus();
      return(false);
    }
  }

  // zaboravljena lozinka
  else if (name=='PAS') {
    if (!captcha.test(form.PAS_CODE.value)) {
      alert('Niste upisali ispravan kontrolni kod!');
      form.PAS_CODE.focus();
      return(false);
    }
    else if (!email.test(form.EMA.value)) {
      alert('Niste upisali ispravni E-mail!');
      form.EMA.focus();
      return(false);
    }
    else if (!godina.test(form.GOD.value)) {
      alert('Niste upisali ispravnu godinu rođenja!');
      form.GOD.focus();
      return(false);
    }
  }
  
  // vinski chat
    else if (name=='CHT') {
      if (!captcha.test(form.CHT_CODE.value)) {
        alert('Niste upisali ispravan kontrolni kod!');
        form.CHT_CODE.focus();
        return(false);
    }
    else if (!prazno.test(form.IME.value)) {
        alert('Niste upisali nadimak!');
        form.IME.focus();
        return(false);
    }
    else if (!prazno.test(form.POR.value)) {
        alert('Niste upisali poruku!');
        form.POR.focus();
        return(false);
    }    
  }
  
  // kontakt
  else {
    if (!captcha.test(form.KON_CODE.value)) {
      alert('Niste upisali kontrolni kod!');
      form.KON_CODE.focus();
      return(false);
    }
    else if (!ime.test(form.IME.value)) {
      alert('Niste upisali ime i prezime!');
      form.IME.focus();
      return(false);
    }
    else if (!email.test(form.EMA.value)) {
      alert('Niste upisali ispravni E-mail!');
      form.EMA.focus();
      return(false);
    }
    else if (!prazno.test(form.TEM.value)) {
      alert('Niste upisali temu poruke!');
      form.TEM.focus();
      return(false);
    }
    else if (!prazno.test(form.POR.value)) {
      alert('Niste upisali tekst poruke!');
      form.POR.focus();
      return(false);
    }
  }
  return(true);
}

//------------------
// provjera narudzbe
//------------------

function CheckOrder(pID) {

  var tFORM=xDOC.getElementById(pID);
  var rEMAIL=/[\w\-\.]+\@[\-\w\.]+\.[\w\-\.]{2,4}/;
  var rIME=/[\w\.]+.*\s+.*[\w\.]+/;
  var rPRAZNO=/[\d\w]+/;
  var rCAPTCHA=/^[\d]{5}$/;

  if (!rCAPTCHA.test(tFORM.NAR_CODE.value)) {
    alert('Niste upisali ispravan kontrolni kod!');
    tFORM.NAR_CODE.focus();
    return(false);
  }
  if (!rIME.test(tFORM.IME.value)) {
    alert('Niste upisali ime i prezime!');
    tFORM.IME.focus();
    return(false);
  }
  else if (!rPRAZNO.test(tFORM.ADR.value)) {
    alert('Niste upisali adresu!');
    tFORM.ADR.focus();
    return(false);
  }
  else if (!rPRAZNO.test(tFORM.MJE.value)) {
    alert('Niste upisali mjesto!');
    tFORM.MJE.focus();
    return(false);
  }
  else if (!rPRAZNO.test(tFORM.POS.value)) {
    alert('Niste upisali poštanski broj!');
    tFORM.POS.focus();
    return(false);
  }
  else if (!rPRAZNO.test(tFORM.DRZ.value)) {
    alert('Niste upisali državu!');
    tFORM.POS.focus();
    return(false);
  }
  else if (!rPRAZNO.test(tFORM.TEL.value)) {
    alert('Niste upisali broj telefona!');
    tFORM.TEL.focus();
    return(false);
  }
  else if (!rEMAIL.test(tFORM.EMA.value)) {
    alert('Niste upisali ispravnu E-mail adresu!');
    tFORM.EMA.focus();
    return(false);
  }
  return(true)  
}


//-------------------------------------------------------------------------------
//
//  WSP Capcha zastita formula
//
//-------------------------------------------------------------------------------

function WSPCaptcha(ID) {
  if (!ID) { ID='WSP' }
  var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  var wsp_key_length = 32;
  var wsp_key = '';
  for (var i=0; i<wsp_key_length; i++) {
    var rnum = Math.floor(Math.random() * (chars.length-1));
    wsp_key += chars.substring(rnum, rnum+1);
  }
  xDOC.getElementById(ID+'_CAPTCHA').src = 'http://webspamprotect.com/captcha.php?id=' + xWSPCID + '&key=' + wsp_key;
  xDOC.getElementById(ID+'_KEY').value   = wsp_key;
}

///////////////////////////////////////////////////////////////////////////////////
//
// vraca vrijednost izabrane radio opcije, ako nista nije vraca prazno
//
///////////////////////////////////////////////////////////////////////////////////

function checkRadio(RADIO) {
  var tVALUE='';
  for (var tI=0;tI<RADIO.length;tI++) {
    if (RADIO[tI].checked) { tVALUE=RADIO[tI].value }
  }
  return(tVALUE);
}

//-------------------------------------------------------------------------------
// You may use this code for free on any web page provided that 
// these comment lines and the following credit remain in the code.
// Floating Div from http://www.javascript-fx.com
//-------------------------------------------------------------------------------

function FloatDiv (id, sx, sy) {

  var EL=xDOC.getElementById?xDOC.getElementById(id):xDOC.all?xDOC.all[id]:xDOC.layers[id];
  var PX = xDOC.layers ? "" : "px";
  window[id + "_obj"] = EL;
  if (xDOC.layers) EL.style=EL;
  EL.cx = EL.sx = sx;
  EL.cy = EL.sy = sy;

  EL.sP=function(x,y) { 
    this.style.left=x+PX;this.style.top=y+PX; 
  };

  EL.floatIt=function () {
    var pX, pY;
    pX = (this.sx >= 0) ? 0 : xNS ? innerWidth : 
	xDOC.documentElement && xDOC.documentElement.clientWidth ? 
	xDOC.documentElement.clientWidth : xDOC.body.clientWidth;
    pY = xNS ? pageYOffset : xDOC.documentElement && xDOC.documentElement.scrollTop ? 
	xDOC.documentElement.scrollTop : xDOC.body.scrollTop;
    if (this.sy<0) 
    pY += xNS ? innerHeight : xDOC.documentElement && xDOC.documentElement.clientHeight ? 
	    xDOC.documentElement.clientHeight : xDOC.body.clientHeight;
    this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
    this.sP(this.cx, this.cy);
    setTimeout(this.id + "_obj.floatIt()", 40);
  }
  return EL;
}

//-------------------------------------------------------------------------------
//
// slanje linka
//
//-------------------------------------------------------------------------------

function ShowSendLink () {
  GrayOut(true);
  var X=xDOC.getElementById('DIVSENDLINK').offsetWidth;
  var Y=xDOC.getElementById('DIVSENDLINK').offsetHeight;
  FloatDiv('DIVSENDLINK',parseInt((ClientWidth()-X)/2),parseInt((ClientHeight()-Y)/2)).floatIt();
  xDOC.getElementById('DIVSENDLINK').style.visibility='visible';
}

function SendLink (form) {
  var tURI=xURI.replace(/=/g,'%3D');
  Update('SENDLINK','A=LIN&SEND=LIN&URI='+tURI+'&IME='+form.IME.value+'&EPR='+form.EPR.value+'&EPO='+form.EPO.value+
		'&LIN_KEY='+form.LIN_KEY.value+'&LIN_CODE='+form.LIN_CODE.value);
}

function HideSendLink () {
  xDOC.getElementById('DIVSENDLINK').style.visibility='hidden';
  GrayOut(false);
}  


//-------------------------------------------------------------------------------
//
// prikaz i sakrivanje slike
//
//-------------------------------------------------------------------------------

function ShowPicture (BID,X,Y) {
  var I=xDOC.getElementById('IMGSRC');
  GrayOut(true);
  X+=0;
  Y+=0;
  I.src=BID;
  I.width=X;
  I.height=Y;
  var XD=xDOC.getElementById('DIVIMG').offsetWidth;
  var YD=xDOC.getElementById('DIVIMG').offsetHeight;
  FloatDiv('DIVIMG',parseInt((ClientWidth()-XD)/2),parseInt((ClientHeight()-YD)/2)).floatIt();
  xDOC.getElementById('DIVIMG').style.visibility='visible';
}


function HidePicture () {
  var DIV=xDOC.getElementById('DIVIMG');
  DIV.style.visibility='hidden';
  var I=xDOC.getElementById('IMGSRC');
  I.src='_.gif';
  I.width=100;
  I.height=70;
  GrayOut(false);
}

//-------------------------------------------------------------------------------
//
// print
//
//-------------------------------------------------------------------------------

function PrintBody () {
  window.open('index.cgi?&PRINT=Y&'+xURI,'PRINT','width=750,height=600,screenX=20,screenY=20,left=20,top=20')
}


//-------------------------------------------------------------------------------
//
// zatamnjenje ekrana
//
//-------------------------------------------------------------------------------

function GrayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#699AFA';
  var dark=xDOC.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = xDOC.getElementsByTagName("body")[0];
    var tnode = xDOC.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=xDOC.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( xDOC.body && ( xDOC.body.scrollWidth || xDOC.body.scrollHeight ) ) {
        var pageWidth = xDOC.body.scrollWidth+'px';
        var pageHeight = xDOC.body.scrollHeight+'px';
    } else if( xDOC.body.offsetWidth ) {
      var pageWidth = xDOC.body.offsetWidth+'px';
      var pageHeight = xDOC.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';				 
  } 
  else {
     dark.style.display='none';
  }
}

function ShowData(ID) {
  GrayOut(true);
  var DIV=xDOC.getElementById('DATA'+ID);
  DIV.style.left=10;
  DIV.style.top=10;
  DIV.style.visibility='visible';
}

function HideData (ID) {
  xDOC.getElementById('DATA'+ID).style.visibility='hidden';
  GrayOut(false);
}

//-------------------------------------------------------------------------------
//
// functions by tigra @ softcomplex
//
// http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
//
//-------------------------------------------------------------------------------

function ClientWidth() {
	return PositionResult (
		window.innerWidth ? window.innerWidth : 0,
		xDOC.documentElement ? xDOC.documentElement.clientWidth : 0,
		xDOC.body ? xDOC.body.clientWidth : 0
	);
}

function ClientHeight() {
	return PositionResult (
		window.innerHeight ? window.innerHeight : 0,
		xDOC.documentElement ? xDOC.documentElement.clientHeight : 0,
		xDOC.body ? xDOC.body.clientHeight : 0
	);
}

function ScrollLeft() {
	return PositionResult (
		window.pageXOffset ? window.pageXOffset : 0,
		xDOC.documentElement ? xDOC.documentElement.scrollLeft : 0,
		xDOC.body ? xDOC.body.scrollLeft : 0
	);
}

function ScrollTop() {
	return PositionResult (
		window.pageYOffset ? window.pageYOffset : 0,
		xDOC.documentElement ? xDOC.documentElement.scrollTop : 0,
		xDOC.body ? xDOC.body.scrollTop : 0
	);
}

function PositionResult(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


//-------------------------------------------------------------------------------------
// Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
// This notice MUST stay intact for legal use
// Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
//-------------------------------------------------------------------------------------

var offsetxpoint=-60 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=xDOC.all
var ns6=xDOC.getElementById && !xDOC.all
var enabletip=false

function ietruebody(){
  return (xDOC.compatMode && xDOC.compatMode!="BackCompat")? xDOC.documentElement : xDOC.body
}

function ddrivetip(thetext, thecolor, thewidth){
  if (ns6||ie){
    var tipobj=xDOC.all? xDOC.all["dhtmltooltip"] : xDOC.getElementById? xDOC.getElementById("dhtmltooltip") : ""
    if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
    if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
    tipobj.innerHTML=thetext
    enabletip=true
    return false
  }
}

function positiontip(e){
  if (enabletip){
    var tipobj=xDOC.all? xDOC.all["dhtmltooltip"] : xDOC.getElementById? xDOC.getElementById("dhtmltooltip") : ""
    var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
    var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
    //Find out how close the mouse is to the corner of the window
    var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
    var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

    var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

    //if the horizontal distance isn't enough to accomodate the width of the context menu
    if (rightedge<tipobj.offsetWidth)
      //move the horizontal position of the menu to the left by it's width
      tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
    else if (curX<leftedge)
      tipobj.style.left="5px"
    else
      //position the horizontal position of the menu where the mouse is positioned
      tipobj.style.left=curX+offsetxpoint+"px"

    //same concept with the vertical position
    if (bottomedge<tipobj.offsetHeight)
      tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
    else
      tipobj.style.top=curY+offsetypoint+"px"

    tipobj.style.visibility="visible"
  }
}

function hideddrivetip(){
  var tipobj=xDOC.all? xDOC.all["dhtmltooltip"] : xDOC.getElementById? xDOC.getElementById("dhtmltooltip") : ""
  if (ns6||ie){
    enabletip=false
    tipobj.style.visibility="hidden"
    tipobj.style.left="-1000px"
    tipobj.style.backgroundColor=''
    tipobj.style.width=''
  }
}

xDOC.onmousemove=positiontip 


//-------------------------------------------------------------------------------
//
//Chrome Drop Down Menu v2.01- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated: November 14th 06- added iframe shim technique
//
//-------------------------------------------------------------------------------

var cssdropdown={
disappeardelay: 250, //set delay in miliseconds before menu disappears onmouseout
disablemenuclick: false, //when user clicks on a menu item with a drop down menu, disable menu item's link?
enableswipe: 1, //enable swipe effect? 1 for yes, 0 for no
enableiframeshim: 1, //enable "iframe shim" technique to get drop down menus to correctly appear on top of controls such as form objects in IE5.5/IE6? 1 for yes, 0 for no

//No need to edit beyond here////////////////////////
dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all, swipetimer: undefined, bottomclip:0,

getposOffset:function(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
},

swipeeffect:function(){
if (this.bottomclip<parseInt(this.dropmenuobj.offsetHeight)){
this.bottomclip+=10+(this.bottomclip/10) //unclip drop down menu visibility gradually
this.dropmenuobj.style.clip="rect(0 auto "+this.bottomclip+"px 0)"
}
else
return
this.swipetimer=setTimeout("cssdropdown.swipeeffect()", 10)
},

showhide:function(obj, e){
if (this.ie || this.firefox)
this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px"
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
if (this.enableswipe==1){
if (typeof this.swipetimer!="undefined")
clearTimeout(this.swipetimer)
obj.clip="rect(0 auto 0 0)" //hide menu via clipping
this.bottomclip=0
this.swipeeffect()
}
obj.visibility="visible"
}
else if (e.type=="click")
obj.visibility="hidden"
},

iecompattest:function(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
},

clearbrowseredge:function(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=this.ie && !window.opera? this.iecompattest().scrollLeft+this.iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetWidth
if (windowedge-this.dropmenuobj.x < this.dropmenuobj.contentmeasure)  //move menu to the left?
edgeoffset=this.dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=this.ie && !window.opera? this.iecompattest().scrollTop : window.pageYOffset
var windowedge=this.ie && !window.opera? this.iecompattest().scrollTop+this.iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetHeight
if (windowedge-this.dropmenuobj.y < this.dropmenuobj.contentmeasure){ //move up?
edgeoffset=this.dropmenuobj.contentmeasure+obj.offsetHeight
if ((this.dropmenuobj.y-topedge)<this.dropmenuobj.contentmeasure) //up no good either?
edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
},

dropit:function(obj, e, dropmenuID){
if (this.dropmenuobj!=null) //hide previous menu
this.dropmenuobj.style.visibility="hidden" //hide menu
this.clearhidemenu()
if (this.ie||this.firefox){
obj.onmouseout=function(){cssdropdown.delayhidemenu()}
obj.onclick=function(){return !cssdropdown.disablemenuclick} //disable main menu item link onclick?
this.dropmenuobj=document.getElementById(dropmenuID)
this.dropmenuobj.onmouseover=function(){cssdropdown.clearhidemenu()}
this.dropmenuobj.onmouseout=function(e){cssdropdown.dynamichide(e)}
this.dropmenuobj.onclick=function(){cssdropdown.delayhidemenu()}
this.showhide(this.dropmenuobj.style, e)
this.dropmenuobj.x=this.getposOffset(obj, "left")
this.dropmenuobj.y=this.getposOffset(obj, "top")
this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge")+"px"
this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+1+"px"
//this.positionshim() //call iframe shim function
}
},

positionshim:function(){ 
//display iframe shim function
if (this.enableiframeshim && typeof this.shimobject!="undefined"){
if (this.dropmenuobj.style.visibility=="visible"){
this.shimobject.style.width=this.dropmenuobj.offsetWidth+"px"
this.shimobject.style.height=this.dropmenuobj.offsetHeight+"px"
this.shimobject.style.left=this.dropmenuobj.style.left
this.shimobject.style.top=this.dropmenuobj.style.top
}
this.shimobject.style.display=(this.dropmenuobj.style.visibility=="visible")? "block" : "none"
}
},

hideshim:function(){
if (this.enableiframeshim && typeof this.shimobject!="undefined")
this.shimobject.style.display='none'
},

contains_firefox:function(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
},

dynamichide:function(e){
var evtobj=window.event? window.event : e
if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
this.delayhidemenu()
else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
this.delayhidemenu()
},

delayhidemenu:function(){
this.delayhide=setTimeout("cssdropdown.dropmenuobj.style.visibility='hidden'; cssdropdown.hideshim()",this.disappeardelay) //hide menu
},

clearhidemenu:function(){
if (this.delayhide!="undefined")
clearTimeout(this.delayhide)
},

startchrome:function(){
for (var ids=0; ids<arguments.length; ids++){
var menuitems=document.getElementById(arguments[ids]).getElementsByTagName("a")
for (var i=0; i<menuitems.length; i++){
if (menuitems[i].getAttribute("rel")){
var relvalue=menuitems[i].getAttribute("rel")
menuitems[i].onmouseover=function(e){
var event=typeof e!="undefined"? e : window.event
cssdropdown.dropit(this,event,this.getAttribute("rel"))
}
}
}
}
if (window.createPopup && !window.XmlHttpRequest){ //if IE5.5 to IE6, create iframe for iframe shim technique
//document.write('<IFRAME id="iframeshim"  src="" style="display: none; left: 0; top: 0; z-index: 90; position: absolute; frameBorder="0" scrolling="no"></IFRAME>')
//this.shimobject=document.getElementById("iframeshim") //reference iframe object
}
}
}


//-------------------------------------------------------------------------------
//
// event propagation
//
//-------------------------------------------------------------------------------

function stopEventPropagation(EVENT) {
  if (!EVENT) var EVENT = window.event;
  EVENT.cancelBubble=true;
  if (EVENT.stopPropagation) EVENT.stopPropagation();
}


//-------------------------------------------------------------------------------
//
// vracanje vrijednosti polja ili objekata
//
//-------------------------------------------------------------------------------

function getID (pID) {
  return(xDOC.getElementById(pID));
}

function getSelectValue (pID) {
  var tSEL=xDOC.getElementById(pID);
  if (tSEL && tSEL.selectedIndex>=0) { return(tSEL.options[tSEL.selectedIndex].value) }
  return('')
}

function getTextValue (pID) {
  var tTXT=xDOC.getElementById(pID);
  if (tTXT) { return(tTXT.value) }
  return('')
}

//-------------------------------------------------------------------------------
// flag switch
//-------------------------------------------------------------------------------

function F(pO,pID) {
  pO.src=pO.src.replace(/[0-1]./,pID+'.');
}
