/************************************************************************************************************
Ajax poller
Copyright (C) 2006  DTHMLGoodies.com, Alf Magne Kalleland

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

Dhtmlgoodies.com., hereby disclaims all copyright interest in this script
written by Alf Magne Kalleland.

Alf Magne Kalleland, 2006
Owner of DHTMLgoodies.com
	
************************************************************************************************************/	

function gallery(url){
	var parameter="top=50,left=50,toolbar=no,scrollbars=yes,status=no,resizable=yes,width=300,height=300";
	okno=window.open(url,"gallery",parameter);
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}


function eraseCookie(name) {
	createCookie(name,"",-1);
}

function showBanner(pos,ban){
	var seen = readCookie('bp' + pos);
	if(seen) seen = seen + '~' + ban;
	else seen = ban;
	createCookie('bp' + pos,seen,1);
}
function resetBanner(pos){
	eraseCookie('bp' + pos);
}

var ajaxRequest = "/app/vote.php";
var poll;

function vote(node){
	var numId = node.id.replace(/[^0-9]/g, '');
	var parentDiv = node.parentNode.parentNode.parentNode.id;
	var params = "?" + numId + "/";
	poll = new sack();
	poll.requestFile = ajaxRequest + params;
	poll.onCompletion = function() { showVote(numId,parentDiv) };	// Specify function that will be executed after file has been found
	poll.runAJAX();	// Execute AJAX function
}

function showVote(id,parentDiv){
	document.getElementById(parentDiv).innerHTML = poll.response;
}

