/*--------------------------------------
	User configured variables
--------------------------------------*/
var inputId = 'search'; 
					// This is the id on the input/textarea that you want to use as the query.
									
var outputId = 'searchresults';
 					// use this to have the results populate your own ID'd tag.
					// leave it blank and a div tag will automatically be added
					// with an id="liveSearchResults"
									
var processURI    = 'live.php';
					// this is the file that you request data from.
									
var emptyString   = '';
					// What to display in the results field when there's nothing
					// Leaving this null will cause the results field to be set to display: none

/*--------------------------------------
	Script Stuff
--------------------------------------*/
var liveReq = false;
var t = null;
var liveReqLast = "";
var isIE = false;

var inputElement;
var outputElement;

// on !IE we only have to initialize it once
if (window.XMLHttpRequest) {
	liveReq = new XMLHttpRequest();
}

function liveReqInit() {
	
	inputElement  = document.getElementById(inputId);
	outputElement = document.getElementById(outputId);
	
	if( inputElement == null || outputElement == null ) 
		return;
	
	
	if (navigator.userAgent.indexOf("Safari") > 0) {
		inputElement.addEventListener("keydown",liveReqStart,false);
		
	} else if (navigator.product == "Gecko") {
		inputElement.addEventListener("keypress",liveReqStart,false);
		
	} else {
		inputElement.attachEvent('onkeydown',liveReqStart);
		isIE = true;
	}
	
	if(emptyString == '') {
		// set the result field to hidden, or to default string
		outputElement.style.display = "none";
	} else {
		outputElement.innerHTML = emptyString;
	}
}

//addLoadEvent(liveReqInit);
//window.onload=liveReqInit;

function liveReqStart() {
	if (t) {
		window.clearTimeout(t);
	}
	t = window.setTimeout("liveReqDoReq()",400);
}



function liveReqDoReq() {
	if (liveReqLast != inputElement.value && inputElement.value != "") {
		if (liveReq && liveReq.readyState < 4) {
			liveReq.abort();
		}
		if (window.XMLHttpRequest) {
		// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			liveReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
		liveReq.onreadystatechange = liveReqProcessReqChange;
//		liveReq.open("GET", processURI + "?s=" + encodeURI(inputElement.value));
//		liveReq.open("GET", processURI + "?s=" + encode(inputElement.value));
//		liveReq.open("GET", processURI + "?s=" + encode64(inputElement.value));	
//alert(base64enc(escape(inputElement.value)));
	
		liveReq.open("GET", processURI + "?s=" + base64enc(escape(inputElement.value)));
		liveReqLast = inputElement.value;
		liveReq.send(null);
	} else if(inputElement.value == "") {
		if(emptyString == '') {
			outputElement.style.display = "none";
			outputElement.innerHTML = '';			
		} else {
			outputElement.innerHTML = emptyString;
		}
	}
}

function liveReqProcessReqChange() {
	if (liveReq.readyState == 4) {
		outputElement.innerHTML = liveReq.responseText;
		if((emptyString == '') && outputElement.style.display!="block") {
 			outputElement.style.display = "block";
		}
	}
	
}



var b64str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+"abcdefghijklmnopqrstuvwxyz"+"0123456789+/=";
var b64str_m = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+"abcdefghijklmnopqrstuvwxyz"+"0123456789-_=";
// -lett a + helyett és _ a / helyett

function base64enc(inp,m)
{

 if (inp=="") return("");

 var b64ch=(m==1)?b64str:b64str_m;

 for (i=0;i<inp.length;i++)
 {
   //if (inp.charCodeAt(i)>255) alert("i:"+i+" code:"+inp.charCodeAt(i)+" ch:"+inp.charAt(i));
   if (inp.charCodeAt(i)>255) alert("i:"+i+" code:"+inp.charCodeAt(i)+" code:"+inp.charCodeAt(i+1));
   //alert(inp.charCodeAt(i)+inp.charAt(i));
 }

 if (typeof(btoa)=="function")
  {
    alap=btoa(inp);
    if (m!=1)
    {
     alap=alap.replace(/\x2B/g,"-");
     alap=alap.replace(/\x2F/g,"_");
    }
    return alap;
  }

    var out = ""; //This is the output
    var chr1, chr2, chr3 = ""; //These are the 3 bytes to be encoded
    var enc1, enc2, enc3, enc4 = ""; //These are the 4 encoded bytes
    var i = 0; //Position counter

    do
    { //Set up the loop here
        chr1 = inp.charCodeAt(i++); //Grab the first byte
        chr2 = inp.charCodeAt(i++); //Grab the second byte
        chr3 = inp.charCodeAt(i++); //Grab the third byte

        //Here is the actual base64 encode part.
        //There really is only one way to do it.
        enc1 = chr1 >> 2;
        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
        enc4 = chr3 & 63;

        if (isNaN(chr2))
        {
          enc3 = enc4 = 64;
        }
         else if (isNaN(chr3))
         {
            enc4 = 64;
         }

        //Lets spit out the 4 encoded bytes
        out = out + b64ch.charAt(enc1) + b64ch.charAt(enc2) + b64ch.charAt(enc3) + b64ch.charAt(enc4);

        // OK, now clean out the variables used.
        chr1 = chr2 = chr3 = "";
        enc1 = enc2 = enc3 = enc4 = "";

    } while (i < inp.length); //And finish off the loop

    //Now return the encoded values.
    return out;
}









///////////////////////////////////////////


//Disable hyperlinks in 1st level tab images?
var disabletablinks=0 //0 for no (default), 1 for yes


////////Stop editting////////////////

var previoustab=""

if (turntosingle==1)
document.write('<style type="text/css">\n#tabcontentcontainer{display: none;}\n</style>')

var delay   = 300
var timeout_id = ""
var aobject=""
function disp_on(cid, aobject1){
  aobject=aobject1
  clearTimeout( timeout_id )
  timeout_id = setTimeout( 'expandcontent(\''+cid+'\')', delay+1 )
}
function disp_off(){
  clearTimeout( timeout_id )
}

function expandcontent(cid){
if (disabletablinks==1)
aobject.onclick=new Function("return false")
if (document.getElementById){
highlighttab(aobject)
if (turntosingle==0){
if (previoustab!="")
document.getElementById(previoustab).style.display="none"
document.getElementById(cid).style.display="block"
previoustab=cid
}
}
}

function highlighttab(aobject){
if (typeof tabobjlinks=="undefined")
collecttablinks()
for (i=0; i<tabobjlinks.length; i++)
tabobjlinks[i].className=""
aobject.className="current"
}

function collecttablinks(){
var tabobj=document.getElementById("tablist")
tabobjlinks=tabobj.getElementsByTagName("A")
}

function do_onload(){
collecttablinks()
aobject = tabobjlinks[initialtab[0]-1]
expandcontent(initialtab[1])
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

//---------------------------------

    activateMenu = function(nav) {

    /* currentStyle restricts the Javascript to IE only */
if (document.all && document.getElementById(nav).currentStyle) { 
        var navroot = document.getElementById(nav);
       
        /* Get all the list items within the menu */
        var lis=navroot.getElementsByTagName("LI"); 
        for (i=0; i<lis.length; i++) {
       
           /* If the LI has another menu level */
            if(lis[i].lastChild.tagName=="UL"){
           
                /* assign the function to the LI */
              lis[i].onmouseover=function() {
               
                   /* display the inner menu */
                   this.lastChild.style.display="block";
                }
                lis[i].onmouseout=function() {                       
                   this.lastChild.style.display="none";
                }
            }
        }
    }
}

window.onload= function(){

    activateMenu('nav1');
    activateMenu('nav2');
    activateMenu('nav3');
    activateMenu('nav4');
    activateMenu('nav5');
    activateMenu('nav6');
    activateMenu('nav7');
    liveReqInit();
    createExternalLinks();
}


function spam()
 {
   var z;
 for(i = 0; i < document.links.length; i++)
  {
    if (document.links[i].nodeName=="A") {
    
document.links[i].href=document.links[i].href.replace('[-]','@');
document.links[i].href=document.links[i].href.replace(/\[dot\]/gi,'.');
document.links[i].innerHTML = document.links[i].innerHTML.replace('[-]','@');
document.links[i].innerHTML = document.links[i].innerHTML.replace(/\[dot\]/gi,'.');
}
}
 }



function spam1(){
for(i=0;i<document.links.length;i++) {
		document.links[i].href=document.links[i].href.replace('[-]','@');
		document.links[i].href=document.links[i].href.replace(/\[dot\]/gi,'.');
		document.links[i].innerHTML=document.links[i].innerHTML.replace(/\[dot\]/gi,'.');
		document.links[i].innerHTML=document.links[i].innerHTML.replace('[-]','@');		
	}
}
	
function selectlink(where){
var temp = new Array();
temp = where.split('|');
linktype = temp[0];
linktarget = temp[1];
switch (linktype)
{
case 'internal': document.location = linktarget; break;
case 'external': window.open(linktarget); break;
}
  return false;
}

function createExternalLinks()
    {
    linksArray = document.getElementsByTagName('a');
    for(var i = 0; i < linksArray.length; i++)
        {
        if(linksArray[i].getAttribute('rel') == 'external')
             {
         linksArray[i].onclick = new Function("window.open('/redirect.php?link=" + escape(linksArray[i].href) + "'); return false;");
//             linksArray[i].className = "external";
             linksArray[i].id = "autoId" + i;
             linksArray[i].href = "#autoId" + i;
             }
        }
    }



function movie() {
  _winName = "movie";
  szel=screen.width;
  mag=screen.height;
  fent=(mag-404)/2;
  bal=(szel-720)/2;

  _info  = "toolbar=no";      // yes|no 
  _info += ",location=no";    // yes|no 
  _info += ",directories=no"; // yes|no 
  _info += ",status=no";     // yes|no 
  _info += ",menubar=no";     // yes|no 
  _info += ",scrollbars=no"; // yes|no 
  _info += ",margins=no";  // yes|no 
  _info += ",resizable=no";  // yes|no 
  _info += ",dependent";      // close the parent, close the popup, omit if you want otherwise 
  _info += ",height="+404;
  _info += ",width="+702;
  _info += ",left="+bal;
  _info += ",top="+fent;
  DispWin=window.open("/mplayer.php",_winName,_info);
//  self.focus();
}
function popup(what) {
  _winName = "pic";
  szel=screen.width;
  mag=screen.height;
  fent=(mag)/2;
  bal=(szel)/2;

  _info  = "toolbar=no";      // yes|no 
  _info += ",location=no";    // yes|no 
  _info += ",directories=no"; // yes|no 
  _info += ",status=no";     // yes|no 
  _info += ",menubar=no";     // yes|no 
  _info += ",scrollbars=no"; // yes|no 
  _info += ",margins=no";  // yes|no 
  _info += ",resizable=no";  // yes|no 
  _info += ",dependent";      // close the parent, close the popup, omit if you want otherwise 
  _info += ",height="+404;
  _info += ",width="+702;
  _info += ",left="+bal;
  _info += ",top="+fent;
  DispWin=window.open(what,_winName,_info);
//  self.focus();
}

var prevlength = 0;
function checkZip() {
if(($F('sales').length == 5) && !(prevlength==5)) {

var url = '/findzip.php';
var params = 'sales=' + $F('sales');
var ajax = new Ajax.Updater(
{success: 'zipResult'},
url,
{method: 'get', parameters: params, onFailure: reportError});
}
prevlength = $F('sales').length;
}
function reportError(request) {
$F('zipResult') = "Error";
}