
var myConn = new XHConn();
var flashTimer = null;
var flashState = flashCount = 0;
var __tto_disable_okusearch = false;
$ = function(el){ return document.getElementById(el); }

function collect(a,f){var n=[];for(var i=0;i<a.length;i++){var v=f(a[i]);if(v!=null)n.push(v)}return n}

function serialize(f){
	var g=function(n){
		return f.getElementsByTagName(n)
	};
	var nv=function(e){
		if(e.name) return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value);
		else return ''
	};
	var i=collect(g('input'),function(i){
		if((i.type!='radio'&&i.type!='checkbox')||i.checked)return nv(i)});var s=collect(g('select'),nv);
		var t=collect(g('textarea'),nv);
		return i.concat(s).concat(t).join('&');
}


ce = function(el){ return document.createElement(el); }



function sbku(ttoe)
{
    
	if(__tto_disable_okusearch) return;
	if(ttoe.keyCode == 13)
	{
		if(checkData())
		{
            $("link").submit();
			
                        

		}
	}

    
}

function rateSite(sid, cid)
{
	rating = $("rateSelect_"+sid).value;

	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.\nYou will not be able to vote:(");
	var fnWhenDone = function (oXML) {
		 response = oXML.responseText;

		 if(response == "ok")
		 {
		 	$("rateButton_"+sid).innerHTML = "VOTAT!";
		 	$("rateButton_"+sid).style.fontWeight = "bolder";
		 	$("rateButton_"+sid).href = "javascript:void(0);";
		 }
		else
		{
			$("rateButton_"+sid).innerHTML = "INVALID!";
			$("rateButton_"+sid).style.fontWeight = "bolder";
		 	$("rateButton_"+sid).href = "javascript:void(0);";
		 	alert(response);
		}
		$("rateSelect_"+sid).disabled = true;
	};
	myConn.connect("srv/rate.php", "GET", "sid="+sid+"&cid="+cid+"&rate="+rating, fnWhenDone);
}

function validate(name, value, type) {
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.\nYou will not be able to vote:(");

	var fnWhenDone = function (oXML) {
		 response = oXML.responseText;

		 if(response != "ok") {
			alert(response);
            return false;
		}
        return true;
	};
	myConn.connect("srv/validate.php", "GET", "name="+name+"&value="+value+"&type="+type, fnWhenDone);

}



function showSiteInfo(sid, cid)
{


	if(child2remove = $("rateBox_"+sid+"_"+cid))
	{
		$("showRateBox_"+sid+"_"+cid).src="img/open.gif";
		$("site_"+sid+"_"+cid).removeChild(child2remove);
	}
	else
	{

		$("showRateBox_"+sid+"_"+cid).src="img/close.gif";

	rateBox = ce("div");
	rateBox.className = "rateBox";
	rateBox.id = "rateBox_"+sid+"_"+cid;


		rightCol = ce("div");
		rightCol.className = "rightCol";

			rateButton = ce("a");
			rateButton.className = "rateLink";
			rateButton.id = "rateButton_"+sid;
			rateButton.innerHTML = "VOTEZ";
			rateButton.href = "javascript:rateSite("+sid+","+cid+")";

		rightCol.appendChild(rateButton);

			rateSelect = ce("select");
			rateSelect.className = "rateSelect";
			rateSelect.id = "rateSelect_"+sid;
				rOption0 = ce("option");
				rOption0.value = "5";
				rOption0.innerHTML = "superb";

				rOption1 = ce("option");
				rOption1.value = "4";
				rOption1.innerHTML = "bun";

				rOption2 = ce("option");
				rOption2.value = "3";
				rOption2.innerHTML = "util";

				rOption3 = ce("option");
				rOption3.value = "2";
				rOption3.innerHTML = "slab";

				rOption4 = ce("option");
				rOption4.value = "1";
				rOption4.innerHTML = "prostie";

			rateSelect.appendChild(rOption0);
			rateSelect.appendChild(rOption1);
			rateSelect.appendChild(rOption2);
			rateSelect.appendChild(rOption3);
			rateSelect.appendChild(rOption4);

		rightCol.appendChild(rateSelect);
		tmp = ce("br");
		tmp.style.clear = "both";

		rightCol.appendChild(tmp);


rateBox.appendChild(rightCol);
	tmp = ce("br");
	tmp.style.clear = "both";

	rateBox.appendChild(tmp);
	$("site_"+sid+"_"+cid).appendChild(rateBox);
	}

}


function setUrl(a)
{

	alert($("site").value);
	now = new Date();
	now.setTime(now.getTime() + 30 * 24 * 60 * 60 * 1000);

	setCookie("__ssiteid",$("sel_site_id").value,now,"/","");

	qy = $("suche").value;
	while(qy.indexOf(" ") > -1){ qy = qy.replace(" ","+"); }
	qy = escape(qy);
	if (!$("sel_site_id").value) alert('invalid site');
       
	a.href =  "cauta/"+ $("sel_site_id").value + "/" + qy + ".html";
	
    return false;
}



function checkData()
{
 
	if($("suche").value.length == 0 || $("suche").value == "cauta ...")
	{
		$("suche").value = "";
		flash("suche");
		return false;
	}



	if($("sel_site_id").value == "0")
	{

		flash("sel_site_id");
		return false;
	}

	return true;
}


function flash(el)
{
	if(flashState == 1)
	{
		$(el).style.backgroundColor = "#FFF";
		flashState = 0;
	}
	else
	{
		$(el).style.backgroundColor = "#F00";
		flashState = 1;
	}

	if(flashCount == 5)
	{
		$(el).focus();
		clearTimeout(flashTimer);
		flashCount = flashState = 0;
	}
	else
	{
		flashTimer = setTimeout("flash('"+el+"')",50);
		flashCount++;
	}

}


function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}



