var pSelected = null;

  function isBrowserIE()
{ 
  var bName = navigator.appName;
  var bVer = parseFloat(navigator.appVersion);
  if (bName == "Microsoft Internet Explorer")
  {
    return true;    
  }
  else
  {
    return false;
  }
}

function showNewWindow(sUrl, wX, wY)
{
  x=wX; y=wY;
  myleft=(screen.width)?(screen.width-x)/2:100;
  mytop=(screen.height)?(screen.height-y)/2:100;

  newWindow=window.open(sUrl,'newWin','toolbar=no,scrollbars=yes,resizable=no,width='+ x +',height='+ y +',left='+ myleft +',top='+ mytop);
}

function getSelectedRadioValue(form_name)
{
  nValue = -1;
  for ( var i = 0; i < form_name.length; i++ )
  {
     if (form_name[i].type == 'radio' )
     {
        if (form_name.elements[i].checked == true)
          nValue = form_name.elements[i].value;
     }
  }        
  
  return nValue;
} 


function setCheckBoxItem(sCheckName)
{
  document.getElementById(sCheckName).checked = !document.getElementById(sCheckName).checked;
}
  
function setRadioItem(sCheckName)
{
  document.getElementById(sCheckName).checked = true; 
}


function clearPhone(sFieldName)
{
   // combo
  document.getElementById(sFieldName+'c').value = 0;
  // zone
  document.getElementById(sFieldName+'z').value = '';
  // number
  document.getElementById(sFieldName+'p').value = '';
}
  
function prepareMarksOther(sComboName, sComboHide)
{
  if (document.getElementById(sComboName).selectedIndex > -1)
  {
    var nItemID = document.getElementById(sComboName).value;
    if (nItemID==1)
    { show(sComboHide);}
    else
    { hide(sComboHide);}
  }
}
    
function prepareTaxCombo(sComboName, bShow)
{
  if (bShow == true)
 { show(sComboName);}
  else
  { hide(sComboName);}
}


function hide(objName)
{
  //var obj = document.all(objName);
  var obj = document.getElementById(objName);
  obj.style.visibility = "hidden";
}

function show(objName)
{
//  var obj = document.all(objName);
  var obj = document.getElementById(objName);
  obj.style.visibility = "visible";
}

function formatCurrencySLO(num) 
{
  num = num.toString().replace(/\./g,'');
  num = num.toString().replace(',','.');
  if(isNaN(num))
  num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10)
  cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  num = num.substring(0,num.length-(4*i+3))+'.'+
  num.substring(num.length-(4*i+3));
  return (((sign)?'':'-') +  num + ',' + cents);
}

function formatFloat(num, decSep)
{
  num = num.toString().replace(decSep,'.');
  if(isNaN(num))
    num = "0";
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();

  return num + decSep + cents;
}

function formatInteger(num)
{
   var myMod = num % 1;

   if (myMod != 0) 
    num = "0";

   return (num);
}

function maxIntNumber(num, max)
{
   var myMod = num % 1;

   if (myMod != 0) 
    num = "0";
   else
     if (num > max)
       num = max;

   return (num);
}

function setEnginePower(pObjFrom, pObjTo, sType)
{
  eval("nValue = pObjFrom.value;");
  if (nValue && !isNaN(nValue))
  {
    if (sType == "ps")
      nValue = Math.round(nValue * 1.36);
    else
      nValue = Math.round(nValue / 1.36);
    pObjTo.value = nValue;
   }
   else
   {
      pObjTo.value = '';
   }
}

function checkAccpetedRules(form, sInfo) 
{
  if (form.acceptRules.checked == false)
  {
    alert(sInfo);
    return false;
  }
  else
  {
    return true;
  }
}


function goImgWin(myImage,myWidth,myHeight,origLeft,origTop) 
{
  myHeight += 24;
  myWidth += 24;
  TheImgWin = window.open(myImage,'image','height=' + myHeight + ',width=' + myWidth + ',toolbar=no,directories=no,status=no,' +
                          'menubar=no,scrollbars=no,resizable=no');
  TheImgWin.resizeTo(myWidth+2,myHeight+30);
  TheImgWin.moveTo(origLeft,origTop);
  TheImgWin.focus();
}


function bookmarksite()
{
  if (document.all)
    window.external.AddFavorite(location.href, document.title);
  else 
    if (window.sidebar)
      window.sidebar.addPanel(document.title, location.href, "")
}

function selectCheck(form_name, bChecked)
{
  pForm = document.getElementById(form_name);

  for ( var i = 0; i < pForm.length; i++ )
  {
     if (pForm[i].type == 'checkbox' )
     {
        pForm.elements[i].checked = bChecked;
     }
  }
} 

function selectCheckReverse(form_name, bChecked)
{
  pForm = document.getElementById(form_name);

  for ( var i = 0; i < pForm.length; i++ )
  {
     if (pForm[i].type == 'checkbox' )
     {
        pForm.elements[i].checked = !pForm.elements[i].checked;
     }
  }
} 

function testIfEditValue(form_name)
{
  pForm = document.getElementById(form_name);

  bReturn = false;
  for ( var i = 0; i < pForm.length; i++ )
  {
     if (pForm[i].type == 'file')
     {
        if (pForm[i].value != '')
        {
          bReturn = true;
          break;
        }
     }
  }
  
  return bReturn;
} 

function isEnterPressed(e)
{
  var characterCode
	if(e && e.which)
  {
	 e = e
	 characterCode = e.which
	 }
	 else{
	 e = event
	 characterCode = e.keyCode
	 }	 
	 if(characterCode == 13){
 	 return true
	 }
	 else{
	 return false
	 }
}

function closeWindow() 
{
  window.open('','_parent','');
  window.close();
}


nSpeed = 0.1;
xStart=250;
yStart=100;

function showLargeImage(picName)
{
  x=700; y=600;
  myleft=(screen.width)?(screen.width-x)/2:100;
  mytop=(screen.height)?(screen.height-y)/2:100;

  newWindow=window.open('/adInfo.php','newWin','toolbar=no,width='+ x +',height='+ y +',left='+ myleft +',top='+ mytop);
  newWindow.focus();
}

function getResults(sFormName, sText, nType)
{
  searchParams = Form.serialize(sFormName)+'&qf='+nType;
  url = "/ajaxResultCounter.php";
  
  new Ajax.Request(url, 
  {
     method: "get",
     parameters: searchParams, 
     onSuccess: function(hits) 
     {
        var count = String(hits.responseText);
        sButtonCaption = sText + "&nbsp&nbsp<b>["+count+"]</b>";
        
        switch (nType)
        {
          case 1 :
           document.getElementById("resultButton").innerHTML = sButtonCaption;
          break;
          
          case 2 :
           if (document.getElementById("resultButton1") != null)
             document.getElementById("resultButton1").innerHTML = sButtonCaption;
           if (document.getElementById("resultButton2") != null)
             document.getElementById("resultButton2").innerHTML = sButtonCaption;
           if (document.getElementById("resultButton3") != null)
             document.getElementById("resultButton3").innerHTML = sButtonCaption;
           if (document.getElementById("resultButton4") != null)
             document.getElementById("resultButton4").innerHTML = sButtonCaption;
           if (document.getElementById("resultButton5") != null)
             document.getElementById("resultButton5").innerHTML = sButtonCaption;
           if (document.getElementById("resultButton6") != null)
             document.getElementById("resultButton6").innerHTML = sButtonCaption;
          break;
        }
        
     } 
  });
}

function getItemSubSearch(nType, nLang)
{
  searchParams = 'item_ID='+nType+'&lang='+nLang;
  url = "/ajaxItemsTypeSearch.php";
  
  new Ajax.Request(url, 
  {
     method: "get",
     parameters: searchParams, 
     onSuccess: function(hits) 
     {
        document.getElementById("dropFilterItems").innerHTML = String(hits.responseText);
     } 
  });
}

function getCountryDistricts(nLang, sFieldName, nSelected, sSubFieldName, nSubSelected)
{
  var nCountryID = document.getElementById('country').value;
  searchParams = 'onlyDistrict=1&countryID='+nCountryID+'&langPrefix='+nLang+'&field='+sFieldName+'&nSelected='+nSelected;
  url = "/ajaxCountrySubDistricts.php";
  
  new Ajax.Request(url, 
  {
     method: "get",
     parameters: searchParams, 
     onSuccess: function(hits) 
     {
       document.getElementById("regionSel").innerHTML = String(hits.responseText);
       getCountryDistrictSub(nLang, sSubFieldName, nSubSelected);
     } 
  });
}

function getCountryDistrictSub(nLang, sFieldName, nSelected)
{
  var nID = document.getElementById('region').value;
  searchParams = 'onlyDistrictSub=1&countryID='+nID+'&langPrefix='+nLang+'&field='+sFieldName+'&nSelected='+nSelected;
  url = "/ajaxCountrySubDistricts.php";
  
  new Ajax.Request(url, 
  {
     method: "get",
     parameters: searchParams, 
     onSuccess: function(hits) 
     {
       document.getElementById("regionSubSel").innerHTML = String(hits.responseText);
     } 
  });
}

function getCountrySubDistricts(nLang, sFieldName, nSelected)
{
  var nCountryID = document.getElementById('country').value;
  searchParams = 'countryID='+nCountryID+'&langPrefix='+nLang+'&field='+sFieldName+'&nSelected='+nSelected;
  url = "/ajaxCountrySubDistricts.php";
  
  new Ajax.Request(url, 
  {
     method: "get",
     parameters: searchParams, 
     onSuccess: function(hits) 
     {
       document.getElementById("region").innerHTML = String(hits.responseText);
       setAddMapMarks();
     } 
  });
}



//Drop Down Tabs Menu- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Created: May 16th, 07'

 var posDef = null;
 var pos = null;
 var posCenter = null;  
 
function pausecomp(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
}   
  
 
                          
var tabdropdown={
  disappeardelay: 200, //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?
  enableiframeshim: 1, //1 or 0, for true or false
  isItem:false,
  currObj:null,
  nLang: 0,
  //No need to edit beyond here////////////////////////
  dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all, previousmenuitem:null,
  currentpageurl: window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, ""), //get current page url (minus hostname, ie: http://www.dynamicdrive.com/)

  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;
  },

  showhide:function(obj, e, obj2){ //obj refers to drop down menu, obj2 refers to tab menu item mouse is currently over
    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 (obj2.parentNode.className.indexOf("default")==-1) //if tab isn't a default selected one
        obj2.parentNode.className="selected";

      if (this.isItem)
      {
        nID = parseInt(obj2.getAttribute('alt'));
        visibility = "hidden";
        if (nID > 0)
        {
          visibility ="visible";
          getItemSubSearch(nID, this.nLang); 
        }
        this.currObj = obj;
        obj.visibility = visibility;
      }
      else
        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.standardbody.scrollLeft+this.standardbody.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.standardbody.scrollTop : window.pageYOffset
      var windowedge=this.ie && !window.opera? this.standardbody.scrollTop+this.standardbody.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
      }
      this.dropmenuobj.firstlink.style.borderTopWidth=(edgeoffset==0)? 0 : "1px" //Add 1px top border to menu if dropping up
    }
    return edgeoffset
  },

  dropit:function(obj, e, dropmenuID){
       if (this.isItem)    {
         document.getElementById('dropFilterItems').innerHTML = '<div style="padding:30;text-align:center"><a href="#"></a><img src="images/roller.gif"></div>';
       }

    if (this.dropmenuobj!=null){ //hide previous menu
      this.dropmenuobj.style.visibility="hidden" //hide menu
      if (this.previousmenuitem!=null && this.previousmenuitem!=obj){
        if (this.previousmenuitem.parentNode.className.indexOf("default")==-1) //If the tab isn't a default selected one
          this.previousmenuitem.parentNode.className=""
      }
    }
    this.clearhidemenu()
    if (this.ie||this.firefox){
      obj.onmouseout=function(){tabdropdown.delayhidemenu(obj);}
      obj.onclick=function(){return !tabdropdown.disablemenuclick} //disable main menu item link onclick?
      this.dropmenuobj=document.getElementById(dropmenuID)
      this.dropmenuobj.onmouseover=function()
      {
        tabdropdown.clearhidemenu();
      }
      this.dropmenuobj.onmouseout=function(e){tabdropdown.dynamichide(e, obj);}
      this.dropmenuobj.onclick=function(){tabdropdown.delayhidemenu(obj)}
      this.showhide(this.dropmenuobj.style, e, obj)
      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.previousmenuitem=obj //remember main menu item mouse moved out from (and into current menu item)
      this.positionshim() //call iframe shim function
    }
  },

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

  dynamichide:function(e, obj2){ //obj2 refers to tab menu item mouse is currently over
    var evtobj=window.event? window.event : e
    if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
      this.delayhidemenu(obj2)
    else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
      this.delayhidemenu(obj2)
  },

  delayhidemenu:function(obj2){
    this.delayhide=setTimeout(function(){tabdropdown.dropmenuobj.style.visibility='hidden'; if (obj2.parentNode.className.indexOf('default')==-1) obj2.parentNode.className=''},this.disappeardelay) //hide menu
  },

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

  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'
  },

isSelected:function(menuurl){
  var menuurl=menuurl.replace("http://"+menuurl.hostname, "").replace(/^\//, "")
  return (tabdropdown.currentpageurl==menuurl)
},
      
overItem:function(e){
          var event=typeof e!="undefined"? e : window.event;

          this.x = event.clientX;
          this.y = event.clientY;
          tabdropdown.dropit(this, event, this.getAttribute("rel"));
        },       

  init:function(menuid, dselected){
    this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
    var menuitems=document.getElementById(menuid).getElementsByTagName("a");
    n=0;  
      
    for (var i=0; i<menuitems.length; i++){
      if (menuitems[i].getAttribute("rel")){
        var relvalue=menuitems[i].getAttribute("rel")
        document.getElementById(relvalue).firstlink=document.getElementById(relvalue).getElementsByTagName("a")[0]
        menuitems[i].onmouseover = this.overItem;
      }
      if (dselected=="auto" && typeof setalready=="undefined" && this.isSelected(menuitems[i].href)){
        menuitems[i].parentNode.className+=" selected default"
        var setalready=true
      }
      else if (parseInt(dselected)==i)
        menuitems[i].parentNode.className+=" selected default"
    }
    
  }
}

function setCellStyle(pArray, theAction)
{
  var nCount = pArray.length;
  for (c = 0; c < nCount; c++)
  {
    if (theAction == 'over')
    {
      pArray[c].className  = pArray[c].className + 'Over';
    }
    else
      if (theAction == 'out')
      {
        var str = pArray[c].className;
        var pos = str.indexOf("Over");
        if (pos>=0)
        {
          var nLength = str.length;
          str = str.substr(0, nLength - 4);
          pArray[c].className  = str;
        }
      }
  }
}

function selectRow(theRow, theAction)
{
  var theCells = null;
  var theHead = null;

  if (typeof(document.getElementsByTagName) != 'undefined')
  {
      theCells = theRow.getElementsByTagName('td');
      theHead = theRow.getElementsByTagName('th');
  }
  else
    if (typeof(theRow.cells) != 'undefined')
    {
      theCells = theRow.cells;
    }
    else
    {
      return false;
    }

  setCellStyle(theHead, theAction);
  setCellStyle(theCells, theAction);

  return true;
}


/*
  Potrjevanje brisanja trenutne vrstice
*/
function confirmLink(pLink, sMessage, sParam)
{
  var bConfirmed = confirm(sMessage);
  if (bConfirmed)
  {
    pLink.href += sParam;
  }
  return bConfirmed;
}


