/* Creation date: 2.10.2009 */

$(document).ready(function()
{

});


function getObjById(id)
{
 var returnVar;
 if(ie)
 	 returnVar = document.all[id];
 else if(dom)
   returnVar = document.getElementById(id);
 else if(nn4)
   returnVar = document.layers[id];
 
 return returnVar;
}

function findPosX(obj)
{
 var curleft = 0;
 if(obj.offsetParent)
 while(1) 
 {
  curleft += obj.offsetLeft;
  if(!obj.offsetParent)
     break;
  obj = obj.offsetParent;
 }
 else if(obj.x)
   curleft += obj.x;
 return curleft;
}

 function findPosY(obj)
{
 var curtop = 0;
 if(obj.offsetParent)
 while(1)
 {
  curtop += obj.offsetTop;
  if(!obj.offsetParent)
    break;
  obj = obj.offsetParent;
 }
 else if(obj.y)
   curtop += obj.y;
 return curtop;
}


function showComments(id,page)
{
 xmlhttp.open("GET", "/includes/updateComments.php?id="+id+"&page="+page,true);
 xmlhttp.onreadystatechange=function() 
 {
  if (xmlhttp.readyState==4) 
  {
   new_data = xmlhttp.responseText
   if(new_data != old_data)
     getObjById("commentList").innerHTML = xmlhttp.responseText;
   old_data = new_data
  }
 }
 xmlhttp.send(null);
}

function addFavourites(id)
{
 xmlhttp.open("GET", "/includes/addFavourites.php?id="+id,true);
 xmlhttp.onreadystatechange=function() 
 {
  if (xmlhttp.readyState==4) 
  {
   getObjById("favourites").innerHTML = xmlhttp.responseText;
  }
 }
 xmlhttp.send(null);
}

function searchSite()
{
 var q;
 q = getObjById("qField").value;
 xmlhttp.open("GET", "/includes/searchSite.php?q="+q,true);
 xmlhttp.onreadystatechange=function() 
 {
  if (xmlhttp.readyState==4) 
   getObjById("searchResults").innerHTML = xmlhttp.responseText;
 }
 xmlhttp.send(null);
}


function clearField(objekt)
{
 getObjById("searchResults").innerHTML = "";
 if(getObjById('qField').value == "Search...")
   getObjById('qField').value = "";
}

function giveVote(id,rate)
{
 xmlhttp.open("GET", "/includes/giveVote.php?id="+id+"&rate="+rate,true);
 xmlhttp.onreadystatechange=function() 
 {
  if (xmlhttp.readyState==4) 
   getObjById("showRate").innerHTML = xmlhttp.responseText;
 }
 xmlhttp.send(null);
}

function showForm(id)
{
 //showNews(id);

 $("#iskanjeForma").load("/includes/drawForm.php?style="+id);

 $('#p1').css("background","#000066");
 $('#p2').css("background","#000066");
 $('#p3').css("background","#000066");
 $('#p4').css("background","#000066");

 $('#p1').css("color","#fff");
 $('#p2').css("color","#fff");
 $('#p3').css("color","#fff");
 $('#p4').css("color","#fff");
 
 if(id == 2)
 {
  $('#p2').css("background","#FFF53B");
  $('#p2').css("color","#000000");
 }
 else if(id == 3)
 {
  $('#p3').css("background","#FFF53B");
  $('#p3').css("color","#000000");
 }
 else if(id == 4)
 {
  $('#p4').css("background","#FFF53B");
  $('#p4').css("color","#000000");
 }
 else
 {
  $('#p1').css("background","#FFF53B");
  $('#p1').css("color","#000000");
 }

 $("#showResults").html("");
}

function clearNews()
{
 $("#showNews").html("");
}

function showNews(id)
{
 $("#showNews").load('/includes/showNews.php?id='+id);
}

function showNovica(id)
{
 $("#showNews").load('/includes/showNovica.php');
}

function odstraniKosarica(id,style)
{
 if(!confirm("Ali ste prepričani, da želite odstraniti artikel iz košarice?"))
   return;
 $("#resultBox").load("/includes/removeArticle.php?style="+style+"&id="+id);
}

function dodajKosarica(id,style)
{
 var kol = $('#kol').val();

 $("#resultBox").load("/includes/addArticle.php?kol="+kol+"&style="+style+"&id="+id,true);
}

var state=0;
function popraviKosarica(id,style)
{
 $("#editBasket").load("/includes/editArticle.php?style="+style+"&id="+id);
 $("#editBasket").show();
}

function kolKosarica(id,style)
{
 kolicina = $('#kol2').val();
 $("#resultBox").load("/includes/updateArticle.php?style="+style+"&id="+id+"&kol="+kolicina);
 $("#editBasket").hide();
}


function HideContent(d) 
{
 if(d.length < 1)
   return;
 document.getElementById(d).style.display = "none";
}

function ShowContent(d) 
{
 if(d.length < 1) 
   return;
 document.getElementById(d).style.display = "block";
}

function ReverseContentDisplay(d) 
{
 if(d.length < 1)
   return;
 if(document.getElementById(d).style.display == "none")
   document.getElementById(d).style.display = "block";
 else
 	 document.getElementById(d).style.display = "none";
}

function changeState()
{
 //var state = $("#agreeBox").val(); 
 //alert(state);
/* 
 var txt = $('agreeBox').value;
 if(txt == 1)
   $('agreeBox').value = 0;
 else
 	 $('agreeBox').value = 1;
*/
}

function checkAgree()
{
 var state = $("#agreeBox").value();
 
 alert(state);
 if(state == 1)
   document.location = "prodano.php";
 else
 	 alert("Če želite opraviti nakup se morate strinjati s pogoji uporabe!");
}