function sendRequest(req) {
    var httpReq = null;

        try {
                httpReq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
                try {
                    httpReq = new ActiveXObject("Microsoft.XMLHTTP");
                } catch(sc) {
                    httpReq = null;
                }
        }

        if (!httpReq && typeof XMLHttpRequest!="undefined") {
                httpReq = new XMLHttpRequest();
        }

    httpReq.open("GET", req);
        httpReq.onreadystatechange=function() {
            if(httpReq.readyState==4&&httpReq.responseText) {
		window.location.reload();
            }
        };
    httpReq.send(null);
}

function convert(s) {
        if(encodeURIComponent) return encodeURIComponent(s);
        if(escape) return escape(s);
}

var sess = null;

function sendSearchReqPoll() {
    var httpReq = null;

        try {
                httpReq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
                try {
                    httpReq = new ActiveXObject("Microsoft.XMLHTTP");
                } catch(sc) {
                    httpReq = null;
                }
        }

        if (!httpReq && typeof XMLHttpRequest!="undefined") {
                httpReq = new XMLHttpRequest();
        }

    var req = "search_results.php?session_id="+sess+"&ts="+(new Date().getTime().toString());
//    alert(req);
    httpReq.open("GET", req);
        httpReq.onreadystatechange=function() {
            if(httpReq.readyState==4&&httpReq.responseText) {
//		alert(httpReq.responseText);
		if (httpReq.responseText == "-1") setTimeout("sendSearchReqPoll()", "1000");
		else {
		    document.getElementById("searchResults").className = 'searchResults';
		    document.getElementById("searchResults").innerHTML = httpReq.responseText;
		}
            }
        };
    httpReq.send(null);

}

/*
function sendVideoSearchReqPoll() {
    var httpReq = null;

        try {
                httpReq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
                try {
                    httpReq = new ActiveXObject("Microsoft.XMLHTTP");
                } catch(sc) {
                    httpReq = null;
                }
        }

        if (!httpReq && typeof XMLHttpRequest!="undefined") {
                httpReq = new XMLHttpRequest();
        }

    var req = "search_results.php?session_id="+sess+"&ts="+(new Date().getTime().toString());
    httpReq.open("GET", req);
        httpReq.onreadystatechange=function() 
		{
            if(httpReq.readyState==4&&httpReq.responseText) 
			{
				if (httpReq.responseText == "-1") 
					setTimeout("sendVideoSearchReqPoll()", "1000");
				else 
				{
					document.getElementById("searchResults").className = 'searchResults';
					document.getElementById("searchResults").innerHTML = httpReq.responseText;
				}
            }
        };
    httpReq.send(null);
}
*/
function sendSearchReq(session, expression, cats) {
    var httpReq = null;

        try {
                httpReq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
                try {
                    httpReq = new ActiveXObject("Microsoft.XMLHTTP");
                } catch(sc) {
                    httpReq = null;
                }
        }

        if (!httpReq && typeof XMLHttpRequest!="undefined") {
                httpReq = new XMLHttpRequest();
        }

    var req = "search.php?session_id="+session+"&expression="+convert(expression)+"&categories="+cats+"&ts="+(new Date().getTime().toString());
    httpReq.open("GET", req);
    httpReq.send(null);
}
/*
function sendVideoSearchReq(session, expression, cats) {
    var httpReq = null;

        try {
                httpReq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
                try {
                    httpReq = new ActiveXObject("Microsoft.XMLHTTP");
                } catch(sc) {
                    httpReq = null;
                }
        }

        if (!httpReq && typeof XMLHttpRequest!="undefined") {
                httpReq = new XMLHttpRequest();
        }

    var req = "search.php?session_id="+session+"&expression="+convert(expression)+"&categories="+cats+"&ts="+(new Date().getTime().toString());
    httpReq.open("GET", req);
    httpReq.send(null);
}
*/
function startSearch(session, expr, cats) {
    sess = session;
    sendSearchReq(session, expr, cats);
    setTimeout("sendSearchReqPoll()", 1000);
}

/*
function startVideoSearch(session, player_nick, games, types, bets, rooms, player_per_tables, rooms) {
    sess = session;
    sendVideoSearchReq(session, player_nick, games, types, bets, rooms, player_per_tables, rooms);
    setTimeout("sendVideoSearchReqPoll()", 1000);
}
*/

function showDropDown(parent, id, evt) {
    var menu = document.getElementById(id);

    if (menu.style.display == 'none') {
	var pos = getPosition(parent);
	menu.style.left = pos['x']+1; menu.style.top = pos['y']+26;
	menu.style.display = 'block';
    } else {
	menu.style.display = 'none';
    }
}

function SetCookie (name,value,expires,path,domain,secure) {
    var expdate = new Date ();
    var cdomain = "www.pokerdebata.com";
    var cpath = "/";

    expdate.setTime (expdate.getTime() + (365 * 24 * 60 * 60 * 1000)); // expires in a year
    var lt = expdate.toGMTString();
    document.cookie = name + "=" + escape (value) + "; expires=" + lt + "; path=" + cpath + "; domain=" + cdomain;
}

function autoIframe(frameId){
    try{
	frame = document.getElementById(frameId);
	innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
	objToResize = (frame.style) ? frame.style : frame;
	if (objToResize.height != innerDoc.body.scrollHeight + 20) objToResize.height = innerDoc.body.scrollHeight + 20;
    }
    catch(err){
	window.status = err.message;
    }
}

var defaultRate = null;
function showRate(rate) {
    if (rate == -1 && defaultRate != null) rate = defaultRate;
    for(var i = 1; i<= 5; i++) {
	if (i <= rate) document.getElementById('rate'+i).src = 'images/design/small_star.gif';
	else document.getElementById('rate'+i).src = 'images/design/empty_star.gif';
    }
}

function setRate(article, player, rate, mode) {
    if (!window.confirm('Článok hodnotím na '+rate+'?')) return;
    var httpReq = null;

        try {
                httpReq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
                try {
                    httpReq = new ActiveXObject("Microsoft.XMLHTTP");
                } catch(sc) {
                    httpReq = null;
                }
        }

        if (!httpReq && typeof XMLHttpRequest!="undefined") {
                httpReq = new XMLHttpRequest();
        }

    var req = "rate_article.php?article="+article+"&player="+player+"&rate="+rate+"&mode="+mode+"&ts="+(new Date().getTime().toString());
    httpReq.open("GET", req);
    httpReq.send(null);
    defaultRate = rate;
}