/* Creation date: 1.1.2008 */
var nn4 = (document.layers) ? true : false
var ie = (document.all) ? true : false
var dom = (document.getElementById && !document.all) ? true : false

var xmlhttp=false;
var new_data;
var old_data;
var working = 0;


xmlhttp = getHTTPObject(); // We create the HTTP Object

window.addEvent('domready', function() 
{
 myMenu = new ImageMenu($$('#kwick .kwick'),{openWidth:160, onClick:openThumbs});	
});



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 getHTTPObject() 
{
 var xmlhttp;
 /*@cc_on
 @if (@_jscript_version >= 5)
 try 
 {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) {try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");} catch (E) {xmlhttp = false;}
 }
 @else
  xmlhttp = false;
 @end @*/
 if(!xmlhttp && typeof XMLHttpRequest != 'undefined') 
 {
  try {xmlhttp = new XMLHttpRequest();} catch (e) {xmlhttp = false;}
 }
 return xmlhttp;
}

function put_smiley(smiley,outp)
{
 document.forms['chat_txt'].comment.value += ' ' + smiley + ' ';
 document.forms['chat_txt'].comment.focus();
}

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


/******************************
 **                          **
 **     Chat Functions       **
 **                          **
 ******************************/
function InitChat()
{
 DrawChatText();
 setTimeout("InitChat()", 5000);
}

function DrawChatText()
{
 xmlhttp.open("GET", "/includes/show_chat.php",true);
 xmlhttp.onreadystatechange=function() 
 {
  if (xmlhttp.readyState==4) 
  {
   new_data = xmlhttp.responseText
   if(new_data != old_data)
   {
    document.getElementById("boks").innerHTML = xmlhttp.responseText;
    old_data = new_data;
   }
  }
 }
 xmlhttp.send(null)
}

function setChatChannel(id)
{
 if(!id)
  return;
 xmlhttp.open("GET", "/includes/show_chat.php?channel="+id,true);
 xmlhttp.onreadystatechange=function() 
 {
  if (xmlhttp.readyState==4) 
  {
   document.getElementById("boks").innerHTML = xmlhttp.responseText;
  }
 }
 xmlhttp.send(null)
}