function addEvent(o,e,f){
	if (o.addEventListener){ o.addEventListener(e,f,true); return true; }
	else if (o.attachEvent){ return o.attachEvent("on"+e,f); }
	else { return false; }
}

var timer = null;
var IMG = null;
var NewWindow = null;
function ViewImage(Isrc,title) {
	IMG = new Image;
	IMG.src = Isrc;
	if (typeof(title)=="undefined" || title=="") title="Gallery";
	if (NewWindow) { NewWindow.close(); }
	if (NewWindow==null || NewWindow.closed) {
		settings=
		 "left="+50+","
		 +"top="+50+","
		 +"width="+640+","
		 +"height="+480+","
		 +"toolbar=no,"
		 +"location=no,"
		 +"directories=no,"
		 +"status=no,"
		 +"menubar=no,"
		 +"scrollbars=yes,"
		 +"resizable=yes"
		 NewWindow = window.open("",'Gallery',settings);
	}
	NewWindow.document.open();
	//NewWindow.document.clear();
	NewWindow.document.write(
         "<html><head><title>"+ title +"</title>"
        +"</head>\n"
        +"<body onclick=\"window.close();\" style=\"text-align:left;margin:15px;\">\n"
        +"<img src=\"" + IMG.src + "\" border=\"0\" alt=\""+title+"\" />\n"
        +"</body>\n"
        +"</html>"
	);
	NewWindow.document.close();
	NewWindow.focus();
	timer = setInterval("resize()",250);
}

function resize() {
    if(!IMG.complete){ return; }
    clearInterval(timer);
    var w = IMG.width+60;
    var h = IMG.height+80;
    if (w > 800) w = 800;
    if (h > 600) h = 600;
	resizeWindowTo(NewWindow,w,h);
	IMG = null;
}

function resizeWindowTo(WindowObject,w,h) {
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			WindowObject.outerWidth=w;
			WindowObject.outerHeight=h;
		}
		else WindowObject.resizeTo(w,h);
	}
}

var PopupWin = null;
function OpenPopup(url,w,h) {
	if (PopupWin) { PopupWin.close(); }
	if (PopupWin==null || PopupWin.closed) {
		settings=
		 "left="+(screen.width-w)/2+","
		 +"top="+(screen.width-h)/2+","
		 +"width="+w+","
		 +"height="+h+","
		 +"toolbar=no,"
		 +"location=no,"
		 +"directories=no,"
		 +"status=no,"
		 +"menubar=no,"
		 +"scrollbars=no,"
		 +"resizable=yes"
		 PopupWin = window.open(url,'PopupWin',settings);
	}
	PopupWin.focus();
}

function Hlasuj(anketa,id)
{
    AjaxRequest.post(
        {
             'url':'./hlasuj.php'
            ,'parameters':{ 'anketaid':anketa, 'odpoved':id }
            ,'onSuccess':function(req) { updateAnketa(req.responseText); }
            ,'onError':function() { alert('Chyba!'); }
            ,'onLoading':function() { anketaLoading(); }
        }
    );
    return false;
}

function anketaLoading()
{
    var anketa = document.getElementById('anketa');
    var div = document.createElement('DIV');
    div.className = 'message';
    div.appendChild(document.createTextNode('nahrávam...'));
    anketa.appendChild(div);
}

function updateAnketa(html)
{
    var anketa = document.getElementById('anketa');
    anketa.innerHTML = html
    var div = document.createElement('DIV');
    div.className = 'message';
    div.appendChild(document.createTextNode('Váš hlas bol zaznamenaný'));
    anketa.appendChild(div);
}
