function nw(dom) {window.open(dom.href); return false;}
function zamenjajGumb(dom, hover) {dom.style.backgroundPosition = "0px "+(gumbiID[dom.id]+(hover?-136:0))+"px";}
var gumbiID = new Array();
window.onload = function() {
  var meniAs = document.getElementById('meni').getElementsByTagName('a');
  for(i in meniAs) {
    if(typeof meniAs[i] == "number") {continue;}
    meniAs[i].onmouseover = function() {zamenjajGumb(this,true);}
    meniAs[i].onmouseout = function() {zamenjajGumb(this,false);}
    meniAs[i].innerHTML = "<span>"+meniAs[i].innerHTML+"</span>";
    gumbiID[meniAs[i].id] = parseInt(window.getComputedStyle?window.getComputedStyle(meniAs[i],"").backgroundPosition.split(" ")[1]:meniAs[i].currentStyle.backgroundPositionY);
  }
  delete meniAs;
}

noFriends = 1;
function newFriend() {
  var posTableDOM = document.getElementById('pos-table').getElementsByTagName('tbody')[0];
  var posTableDOMtrs = posTableDOM.getElementsByTagName('tr');
  if(noFriends == 1) {
    posTableDOMtrs[1].getElementsByTagName('th')[0].firstChild.nodeValue = "Ime 1. prijatelja:";
    posTableDOMtrs[2].getElementsByTagName('th')[0].firstChild.nodeValue = "E-mail 1. prijatelja:";
  }
  if(noFriends < 5) {
    var FNdata = new Array("Ime","E-mail");
    var fDOMclones = new Array();
    noFriends++;
    for(i in FNdata) {
      fDOMclones[i] = posTableDOMtrs[(1+Number(i))].cloneNode(true);
      fDOMclones[i].getElementsByTagName('th')[0].firstChild.nodeValue = FNdata[i]+" "+noFriends+". prijatelja:";
      fDOMclones[i].getElementsByTagName('input')[0].value = "";
      posTableDOM.insertBefore(fDOMclones[i], document.getElementById('f-add'));
    }
  }
  if(noFriends >= 5) {
    document.getElementById('f-add').style.visibility = "hidden";
  }
  return false;
}

function doRatingStarsDivs(dom) {
  for(var i = 1; i <= 5; i++) {
    dom.appendChild(document.createElement("div"));
    if(i == 5) {dom.lastChild.style.marginRight = "-1px";}
    dom.lastChild.onmouseover = function() {doRatingStars(this, true);}
    dom.lastChild.onmouseout = function() {doRatingStars(this, false);}
    dom.lastChild.onclick = function() {doRating(this);}
    dom.lastChild.title = i;
  }
  dom.onmouseover = null;
}

function doRatingStars(star, rate) {
  star.parentNode.className = "ocena o"+(rate?star.title:star.parentNode.title.replace(",","")).concat("00").substr(0,2);
}

function doRating(star) {
  document.getElementById('rating-value').value = parseInt(star.title);
  document.getElementById('rating-value').parentNode.submit();
}