// JavaScript Document
// AJAX support
// by kubix

// blog.js

function xmlhttpPost(strURL,id,star) {
    var xmlHttpReq = false;
    var self = this;
    
    if (window.XMLHttpRequest) { // Mozilla/Safari
        self.xmlHttpReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }

    self.xmlHttpReq.open('POST', "/" + strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText,id,strURL,star);
        }
    }
    
    if (strURL == "write_comment.fcgi") {
      self.xmlHttpReq.send(getquerystring());
    } else if (strURL == "send_link.cgi") {
      self.xmlHttpReq.send(getquerystring2());    
    } else {
      qstr = 'id=' + escape(id) + '&star=' + escape(star);  
      self.xmlHttpReq.send(qstr);
    }
}

function getquerystring() {
    var form = document.comment;
    var name = form.name.value;
    var text = form.text.value;
    var id = form.id.value;
    if (text != "") {
      qstr = 'name=' + escape(name) + '&text=' + escape(text) + '&id=' + id;  // NOTE: no '?' before querystring
      text = "";    
    } else {
      qstr = 'id=' + id;  // NOTE: no '?' before querystring
    }
    return qstr;
}

function getquerystring2() {
    var form = document.forms['send'];
    var name = form.name.value;
    var email = form.email.value;
    var id = form.id.value;
    var email_to = form.email_to.value;
    var mess1 = form.mess1.value;    
    var mess2 = form.mess2.value;    
    if (email_to != "") {
      qstr = 'name=' + escape(name) + '&email=' + escape(email) + '&id=' + id + '&email_to=' + escape(email_to)  + '&mess1=' + escape(mess1)  + '&mess2=' + escape(mess2);  // NOTE: no '?' before querystring
    }
    return qstr;
}


function updatepage(str,id,strURL,star){
  var obj;

  if (strURL == "ajax_action.php?action=vote_action") {
    obj = eval("document.getElementById('rating" + id + "')");
    obj.innerHTML = str;
    doing = 0;
    
    obj_v = eval("document.getElementById('pom_vote" + id + "')");
    
    reRate(obj_v.value,id,1);    
    alert("Thanx for voting ! Rate: " + obj_v.value);
          
  } else if (strURL == "make_star.cgi") {
    updateRate(id,star);
    
  } else if ((strURL == "select_video.cgi") && (!star)) {
    obj = document.getElementById("rss");
    obj.innerHTML = str;
    
  } else if ((strURL == "select_video.cgi") && (star)) {
    obj = document.getElementById("rss_ep");
    obj.innerHTML = "<br><h1>Video TV</h1>";
    obj.innerHTML = obj.innerHTML + str;
    obj.style.display = "block";
    obj.style.top = "1600px";
    obj.style.left = "400px";
    
    //obj = document.getElementById("rekVideo");
    //obj.innerHTML = "TU bude<br>VIDEO reklama<br>TU bude<br>VIDEO reklama<br>TU bude<br>VIDEO reklama<br>TU bude<br>VIDEO reklama<br>"
    
  } else if (strURL == "write_comment.fcgi") {
    document.getElementById("result").innerHTML = str;
    document.getElementById("comment").text.value = "";
    
  } else if (strURL == "send_link.cgi") {
    obj = document.getElementById("send_link");
    obj.innerHTML = str;
    
  } else if (strURL == "select_img.cgi") {
    obj = document.getElementById("img_preview");
    obj.innerHTML = str;

  } else if (strURL == "report_broken.cgi") {
    alert('Broken link sent. Thanx for reporting :)')
  }
  
  
}

function updateRate(id,cis,what) {
  var obj = eval("document.getElementById('fav" + id + "')");
  var obj_2 = eval("document.getElementById('favx" + id + "')");
    
  if (cis == 1) {//
      if ((what != "") && (what == 'update')) { xmlhttpPost('make_star.cgi',id,1) };
      obj.innerHTML = '<a href="javascript:void(0);" onClick="updateRate(' + id + ',0,\'update\');"><img src="/img/check.gif" style="cursor:pointer" title="remove from your favorites"></a>';
      obj_2.value = 1; 
  } else {
      if ((what != "") && (what == 'update')) { xmlhttpPost('make_star.cgi',id,0) };
      obj.innerHTML = '<a href="javascript:void(0);" onClick="updateRate(' + id + ',1,\'update\');"><img src="/img/check_off.gif" style="cursor:pointer" title="add to your favorites"></a>';
      obj_2.value = 0;
  }
}

function updateVotes(id,vote) {
  xmlhttpPost('ajax_action.php?action=vote_action',id,vote);
}

var doing = 0;

function nullClasses(id,cis,objX) {
  var obj;
  //pom = Div(cis,1)+1;
  pom = Math.round(cis)+1;

  //if (pom > 5) { pom = 5; };
  pom = 1;  
  obj = eval("document.getElementById('rat" + id + "_" + pom + "')");
  if (pom == 1 ) {
    obj.className = "one-star";
    obj.style.width = "15px";
  } else if (pom == 2) {
    obj.className = "two-stars";
    obj.style.width = "30px";
  } else if (pom == 3) {
    obj.className = "three-stars";
    obj.style.width = "45px";
  } else if (pom == 4) {
    obj.className = "four-stars";
    obj.style.width = "60px";    
  } else if (pom == 5) {
    obj.className = "five-stars";
    obj.style.width = "75px";    
  }
  doing = 1;
}

function Mod(a, b) {
    return a - Math.floor(a / b) * b;
}

function Div(a, b) {
    return Math.floor(a / b);
}

function reRate(cis,id,ww) {
  var obj;
  pom = Math.round(cis)+1;
  //pom = Div(cis,1);
  //if (pom > 5) { pom = 5; };  
  pom = 1;

  obj = eval("document.getElementById('rat" + id + "_" + pom + "')");
  if (cis > 0 && cis <= 0.5) {
    obj.className = "on";
    obj.style.width = "7px";  
  } else if (cis > 0.5 && cis <= 1) {
    obj.className = "on";
    obj.style.width = "15px";  
  } else if (cis > 1 && cis <= 1.5) {
    obj.className = "on";
    obj.style.width = "23px";  
  } else if (cis > 1.5 && cis <= 2) {
    obj.className = "on";
    obj.style.width = "30px";  
  } else if (cis > 2 && cis <= 2.5) {
    obj.className = "on";
    obj.style.width = "37px";  
  } else if (cis > 2.5 && cis <= 3) {
    obj.className = "on";
    obj.style.width = "45px";  
  } else if (cis > 3 && cis <= 3.5) {
    obj.className = "on";
    obj.style.width = "53px";  
  } else if (cis > 3.5 && cis <= 4) {
    obj.className = "on";
    obj.style.width = "60px";  
  } else if (cis > 4 && cis <= 4.5) {
    obj.className = "on";
    obj.style.width = "67px";  
  } else if (cis > 4.5 && cis <= 5) {
    obj.className = "on";
    obj.style.width = "75px";  
  }
  
  var obj_x = eval("document.getElementById('rate_online" + id + "')");
  if (obj_x !=  null && ww) {
    var obj_v = eval("document.getElementById('pom_vote" + id + "')");
    var obj_vc = eval("document.getElementById('pom_vote_count" + id + "')");
    obj_x.innerHTML = "Rate: " + obj_v.value + " / " + obj_vc.value + " people";
  }
  
  doing = 0;
}

function addBookmark(url,title) {
  if (window.sidebar)
  {
    window.sidebar.addPanel(title, url,"");
  }
  else if( document.all )
  {
    window.external.AddFavorite( url, title);
  }
  else
  {
    return true;
  }
}

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip">&nbsp;as</div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="/img/arrow.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

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

function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
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 nondefaultpos=false
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 winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-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=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
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+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip



// blog_cb.js


/*
addEvent function found at http://www.scottandrew.com/weblog/articles/cbs-events
*/
function addEvent(obj, evType, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

/*
createElement function found at http://simon.incutio.com/archive/2003/06/15/javascriptWithXML
*/
function createElement(element) {
	if (typeof document.createElementNS != 'undefined') {
		return document.createElementNS('http://www.w3.org/1999/xhtml', element);
	}
	if (typeof document.createElement != 'undefined') {
		return document.createElement(element);
	}
	return false;
}

function insertTop(obj) {
	// Create the two div elements needed for the top of the box
	d=createElement("div");
	d.className="bt"; // The outer div needs a class name
    d2=createElement("div");
    d.appendChild(d2);
	obj.insertBefore(d,obj.firstChild);
}

function insertBottom(obj) {
	// Create the two div elements needed for the bottom of the box
	d=createElement("div");
	d.className="bb"; // The outer div needs a class name
    d2=createElement("div");
    d.appendChild(d2);
	obj.appendChild(d);
}

function initCB()
{
	// Find all div elements
	var divs = document.getElementsByTagName('div');
	var cbDivs = [];
	for (var i = 0; i < divs.length; i++) {
	// Find all div elements with cbb in their class attribute while allowing for multiple class names
		if (/\bcbb\b/.test(divs[i].className))
			cbDivs[cbDivs.length] = divs[i];
	}
	// Loop through the found div elements
	var thediv, outer, i1, i2;
	for (var i = 0; i < cbDivs.length; i++) {
	// Save the original outer div for later
		thediv = cbDivs[i];
	// 	Create a new div, give it the original div's class attribute, and replace 'cbb' with 'cb'
		outer = createElement('div');
		outer.className = thediv.className;
		outer.className = thediv.className.replace('cbb', 'cb');
	// Change the original div's class name and replace it with the new div
		thediv.className = 'i3';
		thediv.parentNode.replaceChild(outer, thediv);
	// Create two new div elements and insert them into the outermost div
		i1 = createElement('div');
		i1.className = 'i1';
		outer.appendChild(i1);
		i2 = createElement('div');
		i2.className = 'i2';
		i1.appendChild(i2);
	// Insert the original div
		i2.appendChild(thediv);
	// Insert the top and bottom divs
		insertTop(outer);
		insertBottom(outer);
	}
}


  if(document.getElementById && document.createTextNode) {
	   //addEvent(window, 'load', initCB);
  }

// lightbox.js


/*
Created By: Chris Campbell
Website: http://particletree.com
Date: 2/1/2006

Adapted By: Simon de Haan
Website: http://blog.eight.nl
Date: 21/2/2006

Inspired by the lightbox implementation found at http://www.huddletogether.com/projects/lightbox/
And the lightbox gone wild by ParticleTree at http://particletree.com/features/lightbox-gone-wild/

*/

/*-------------------------------GLOBAL VARIABLES------------------------------------*/

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

/*-----------------------------------------------------------------------------------------------*/

//Browser detect script origionally created by Peter Paul Koch at http://www.quirksmode.org/

function getBrowserInfo() {
	if (checkIt('konqueror')) {
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari')) browser 	= "Safari"
	else if (checkIt('omniweb')) browser 	= "OmniWeb"
	else if (checkIt('opera')) browser 		= "Opera"
	else if (checkIt('webtv')) browser 		= "WebTV";
	else if (checkIt('icab')) browser 		= "iCab"
	else if (checkIt('msie')) browser 		= "Internet Explorer"
	else if (!checkIt('compatible')) {
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";

	if (!version) version = detect.charAt(place + thestring.length);

	if (!OS) {
		if (checkIt('linux')) OS 		= "Linux";
		else if (checkIt('x11')) OS 	= "Unix";
		else if (checkIt('mac')) OS 	= "Mac"
		else if (checkIt('win')) OS 	= "Windows"
		else OS 								= "an unknown operating system";
	}
}

function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

