/* UTF8 encoding/decoding functions
 * Copyright (c) 2006 by Ali Farhadi.
 * released under the terms of the Gnu Public License.
 * see the GPL for details.
 *
 * Email: ali[at]farhadi[dot]ir
 * Website: http://farhadi.ir/ 
   http://farhadi.ir/works/utf8
  function chr == return String.fromCharCode(code); */

//an alias of String.fromCharCode
function chr(code)
{
	return String.fromCharCode(code);
}

//returns utf8 encoded charachter of a unicode value.
//code must be a number indicating the Unicode value.
//returned value is a string between 1 and 4 charachters.
function code2utf(code)
{
	if (code < 128) return chr(code);
	if (code < 2048) return chr(192+(code>>6)) + chr(128+(code&63));
	if (code < 65536) return chr(224+(code>>12)) + chr(128+((code>>6)&63)) + chr(128+(code&63));
	if (code < 2097152) return chr(240+(code>>18)) + chr(128+((code>>12)&63)) + chr(128+((code>>6)&63)) + chr(128+(code&63));
}

//it is a private function for internal use in utf8Encode function 
function _utf8Encode(str)
{	
	var utf8str = new Array();
	for (var i=0; i<str.length; i++) {
		utf8str[i] = code2utf(str.charCodeAt(i));
	}
	return utf8str.join('');
}

//Encodes a unicode string to UTF8 format.
function utf8Encode(str)
{	
	var utf8str = new Array();
	var pos,j = 0;
	var tmpStr = '';
	
	while ((pos = str.search(/[^\x00-\x7F]/)) != -1) {
		tmpStr = str.match(/([^\x00-\x7F]+[\x00-\x7F]{0,10})+/)[0];
		utf8str[j++] = str.substr(0, pos);
		utf8str[j++] = _utf8Encode(tmpStr);
		str = str.substr(pos + tmpStr.length);
	}
	
	utf8str[j++] = str;
	return utf8str.join('');
}

//it is a private function for internal use in utf8Decode function 
function _utf8Decode(utf8str)
{	
	var str = new Array();
	var code,code2,code3,code4,j = 0;
	for (var i=0; i<utf8str.length; ) {
		code = utf8str.charCodeAt(i++);
		if (code > 127) code2 = utf8str.charCodeAt(i++);
		if (code > 223) code3 = utf8str.charCodeAt(i++);
		if (code > 239) code4 = utf8str.charCodeAt(i++);
		
		if (code < 128) str[j++]= chr(code);
		else if (code < 224) str[j++] = chr(((code-192)<<6) + (code2-128));
		else if (code < 240) str[j++] = chr(((code-224)<<12) + ((code2-128)<<6) + (code3-128));
		else str[j++] = chr(((code-240)<<18) + ((code2-128)<<12) + ((code3-128)<<6) + (code4-128));
	}
	return str.join('');
}

//Decodes a UTF8 formated string
function utf8Decode(utf8str)
{
	var str = new Array();
	var pos = 0;
	var tmpStr = '';
	var j=0;
	while ((pos = utf8str.search(/[^\x00-\x7F]/)) != -1) {
		tmpStr = utf8str.match(/([^\x00-\x7F]+[\x00-\x7F]{0,10})+/)[0];
		str[j++]= utf8str.substr(0, pos) + _utf8Decode(tmpStr);
		utf8str = utf8str.substr(pos + tmpStr.length);
	}
	
	str[j++] = utf8str;
	return str.join('');
}



function iSeType()
{  if (window.external && ("AddSearchProvider" in window.external)) { return 1 ;   // Firefox 2 and IE 7, OpenSearch 
 } else if (window.sidebar && ("addSearchEngine" in window.sidebar)) { return 2;   // Firefox <= 1.5, Sherlock
 } else { return 0;  // 0 No search engine support (IE 6, Opera, etc).
 };};

function instSE() { var xmlURL="http://go.xc.hu/"; var iSE=iSeType();
 if ( iSE==1 ) {  window.external.AddSearchProvider(xmlURL+ "goIE.xml");
 } else if ( iSE==2 ) { window.sidebar.addSearchEngine(xmlURL + "goSE.xml" , xmlURL +"icons/images/kzg/xcSE.GIF",
"xc.hu kereső","")  ; 
 } else {  alert("Keresőmotor nem állítható be");
 }
document.getElementById("goSEinput").focus();
};

function sPatch(his)
{var kerKif="keres&#337; kifejez&eacute;ssel";
var pL=20;var sPhtm="";var goSE=document.getElementById("goSEinput"); if (goSE!=null) {sPhtm=goSE.value;if (sPhtm.length>0){sPhtm+=" "};}; 
sPhtm=sPhtm.replace(/  /g," "); if (sPhtm.length>pL){sPhtm=sPhtm.substr(0,pL)+"... ";}; 
var here=his.getElementsByTagName("SPAN")[0];if(here!=undefined){
var hereB=here.getElementsByTagName("B")[0];if(hereB!=undefined){hereB.innerHTML=sPhtm;};
var hereI=here.getElementsByTagName("I")[0]; 
    if(hereI!=undefined){if(sPhtm.length>0){hereI.innerHTML=kerKif;}else{hereI.innerHTML="";};};
hereI=here.getElementsByTagName("I")[1]; if(hereI!=undefined) {  if ((self.location==top.location) || (document.referrer.indexOf("go.xc.hu")>-1))
    {if(sPhtm.length>0){hereI.innerHTML="";} 
     else { hereI.innerHTML="El&#337;bb azonban &iacute;rja be azt, hogy <b style=\"font-size:1.3em;font-weight:700;color:rgb(1,2,60);\">mit"+"<"+"/"+"b> &nbsp;szeretne megtal&aacute;lni.";};}
		else { hereI.innerHTML="egy &uacute;j ablakban";};};
};};


var iDe2="A keres&#337;szolg&aacute;ltat&aacute;s hozz&aacute;ad&aacute;sa p&aacute;rbesz&eacute;dpanelen "+
  "jel&ouml;lje be a &bdquo;Haszn&aacute;lat mostant&oacute;l&rdquo; n&eacute;gyzetet, &eacute;s kattintson a &bdquo;Hozz&aacute;ad&aacute;s&rdquo;-ra.";
var iDe1="A keres&eacute;si szolg&aacute;ltat&oacute; hozz&aacute;ad&aacute;sa p&aacute;rbesz&eacute;dpanelen jel&uuml;lje be:<br>"+
"Ez legyen az alap&eacute;rtelmezett keres&eacute;si szolg&aacute;ltat&oacute;";



var hova="_blank";
function instGO() { var ideGO;  var iSE=iSeType(); 
 var cellaD=""; 
 if ((self.location==top.location) || (document.referrer.indexOf("xc.hu")<0)) { hova="_top"; cellaD="none";}; if (iSE==0){cellaD="none";};
     if (document.referrer.indexOf("go.xc.hu")>-1){ hova="_top";};
ideGO=document.getElementById("xcGO"); if (ideGO!=null) { ideGO.style.display=cellaD;};
ideGO=document.getElementById("kBE"); if (ideGO!=null) { ideGO.style.display=cellaD;};
ideGO=document.getElementById("kKE"); if (ideGO!=null) { if(cellaD.length==0){ ideGO.style.display="none";}  else { ideGO.style.display="";  };};

ideGO=document.getElementById("idePDFse");if (ideGO!=null) {if ((cellaD=="none")&&(top.location==self.location))
{ideGO.innerHTML=
'<iframe name="xcSearch" WIDTH="178" HEIGHT="58" FRAMEBORDER=0 MARGINWIDTH="0" MARGINHEIGHT="0" '+
'SCROLLING="NO" style="margin:0px;padding:0px;border:solid 1px darkblue;overflow:hidden;" '+
'src="http://pdf.xc.hu/php/xcSearch.html">'+'<'+'/'+'iframe'+'>'; ideGO.style.display="block";};};

ideGO=document.getElementById("iSEdesc"); if (ideGO!=null) { if (iSE==1){ideGO.innerHTML=iDe1}; 
if ((iSE==2)||(window.sidebar)){ideGO.innerHTML=iDe2};  };

ideGO=null;
if (document.forms[0]!=undefined) {ideGO=document.getElementById("ideGO"); if (ideGO!=null)  { 
   ideGO=ideGO.getElementsByTagName("FORM")[0]; ideGO.target=hova;  };}

var goSEinput=document.getElementById("goSEinput"); if (goSEinput!=null)  { 
   var qSize="320px";qSize="316px"; goSEinput.style.width=qSize;goSEinput.style.minWidth=qSize;goSEinput.style.maxWidth=qSize;
   var qHeight="21px";goSEinput.style.height=qHeight;goSEinput.style.minHeight=qHeight; 

goSEterm="";var k=document.location.search; var j=k.indexOf("q="); 
if (j>-1){ var q=k.substr(j+2);
goSEterm=utf8Decode(unescape(q)).replace(/\+/g," ");}; goSEinput.value=goSEterm; if (j>-1){ XCreDir(); }
   };

};

function goSearch() { goSEterm=document.getElementById("goSEinput").value;
var goURL="http://go.xc.hu/";if (goSEterm.length>0){goURL+="?q="+escape(utf8Encode(goSEterm.replace(/ /g,"+")));};
 // alert(goURL)

 if ((self.location==top.location) && (goSEterm.length>0)) {rss.iniFrame ();XCreDir();} else {
 if  ((self.location==top.location)||(document.referrer.indexOf("go.xc.hu")>-1)) {window.top.location=goURL;}
 else {window.open(goURL); }; };
}


var goSEterm=""; var qGoogle="";
var ieC=20;
var XCtimer;
function XCreDir()
{ var goF=document.getElementById("cse").getElementsByTagName("FORM");
  if (goF.length==0){ieC--;if(ieC>0){XCtimer=setTimeout("XCreDir()",300);};}
else { qGoogle = goF[0].elements[0].value; if ((qGoogle.length==0)||(qGoogle!=goSEterm)){
 // if (confirm( goF[0].elements[0].name + ":"+goSEterm)){
goF[0].elements[0].value=goSEterm;
goF[0].elements[1].onclick();
// }; //confirm
} else {goSEterm=qGoogle; document.getElementById("goSEinput").value=qGoogle;};};
}

//document.getElementById("goSEinput").focus();

