WEBAUDIT=function() {
    
  this.WACID=null;
  this.WACIDName="WACID";
  
  
  this.getCookie=function(name)  {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++)
    {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
  }
  
  this.setCookie=function(name,value,topDomain) {
    var date = new Date(2020,12,31,23,59,59);
    var expires = "; expires="+date.toGMTString();
    document.cookie = name+"="+value+expires+"; path=/; domain=" + topDomain;  
  }
  
  this.generateID=function(splitter) {
    var sp=(splitter) ? splitter : 'A';
    var now=new Date();
    return Date.parse(now.toGMTString()) + sp + Math.floor(Math.random()*1000000000);
  }
  
  this.getTopDomain=function(fullDomain) {
    var darabok=fullDomain.split('.');
    return darabok[(darabok.length-2)] + '.' + darabok[(darabok.length-1)];
  }
  
  this.getDomain=function(url) {
    var urlDarabok=url.split('/');
    return urlDarabok[2];
  }
  
  this.WACID=this.getCookie(this.WACIDName);
}

var wa=new WEBAUDIT();
var felbontas = "";
var same =  Math.floor(Math.random()*1000000);

if(wa.WACID==null)
{
  wa.WACID=wa.generateID('A');
  wa.setCookie(wa.WACIDName,wa.WACID,wa.getTopDomain(wa.getDomain(document.URL)));
}

same = same + "@welid=" + wa.WACID;
if(screen) felbontas='@felbontas='+screen.width+'x'+screen.height;
same = same + felbontas;


    function popup(mit) {
      var w = window.open(mit,'','width=700,height=600,toolbar=no,status=no,resizable=no,scrollbars=yes');
      var xc =(screen.width - 700) / 2;
      var yc =(screen.height - 600) / 2;
      w.moveTo(xc, yc);
    }

    function popup2(mit) {
      var w = window.open(mit,'','width=600,height=220,toolbar=no,status=no,resizable=no,scrollbars=no');
      var xc =(screen.width - 600) / 2;
      var yc =(screen.height - 220) / 2-60; //aranymetszes :)
      w.moveTo(xc, yc);
    }

    // getElementById egyszerűsítve
    function $div(id) { return document.getElementById(id); }

    // láthatóvá tesz egy divet
    function showDiv(_id) {
      $div(_id).style.display = 'block';
    }

    // elrejt egy divet
    function hideDiv(_id) {
      $div(_id).style.display = 'none';
    }

    if (navigator.appName.indexOf("Internet Explorer") > -1) { isIE = true; } else { isIE = false; }

    /******************************************************************/

    /** SIDEBAR POSTNÁL ELLENŐRZÉS **/
    function checkSidebarInputs() {

        var f = document.forms.sidebarForm;
        if (!f.cim.value) { alert('Nem adtad meg a link címét!'); f.cim.focus(); return; }
        if (!f.link.value) { alert('Nem adtad meg a linket!'); f.link.focus(); return; }

        f.submit();
        return true;

    }

    /******************************************************************/

    /** SIDEBAR LAPOZÁS ÉS SZÁMLÁLÓ**/
    var row = 0;
    var limit = 10;
    var szoveg = '';

    function sidebarLapozas(merre) {

        if (merre == "elore") {
            row += limit;
        }

        if (merre == "hatra") {
            row -= limit;
            if (row < 0) row = 0;
        }

        oldContent = new fx.Height('sidebarContent', {duration: 200});
        setTimeout("oldContent.toggle();", 0);

        new ajax ('ajax.php', {
            postBody: 'action=sidebarLapozas&row='+row,
            update: $('tempContent'),
            onComplete: sidebarLapozasHandler
        });
        return true;

    }

    function sidebarLapozasHandler() {

        $div('sidebarContent').innerHTML = $div('tempContent').innerHTML;
        $div('tempContent').innerHTML = "";

        oldContent = new fx.Height('sidebarContent', {duration: 200});
        setTimeout("oldContent.toggle();", 200);

    }                       
    
    function sidebarclick(sidebarid) {
        new ajax ('ajax.php', {
            postBody: 'action=sidebarClick&id='+sidebarid
        });
        return true;
    }

    /******************************************************************/

    /** FŐKÉP ÉS AJÁNLÓK CSERÉJE **/
    // bigLoading fade in
    function fadeInBigLoading(nap) {
	if (nap.length != 8) return;
//	alert(document.getElementById("medianimg").src + '\n' + 'http://audit.median.hu/cgi-bin/track.cgi?uc=11607372649944&dc=1&ui='+same);
	document.getElementById("medianimg").src = 'http://audit.median.hu/cgi-bin/track.cgi?uc=11607372649944&dc=1&ui='+same;

        if (!isIE) {

            bigLoading = new fx.Opacity('bigLoading', {opacity: 0, duration: 300});
            bigLoading.setOpacity(0);
            showDiv('bigLoading');
            bigLoading.custom(0, 1);
            bigLoading.toggle();

        } else {

            changeOpac(0, 'bigLoadingIE');
            showDiv('bigLoadingIE');
            showDiv('bigLoadingIEimg');
            setTimeout("opacity('bigLoadingIE', 0, 100, 300);", 0);

        }

        // ha végeztünk az eye-candyvel, akkor jöhet a tényleges AJAX hívás
        setTimeout("loadAjanlok('"+nap+"')", 300);

    }

    // bigLoading fade out
    function fadeOutBigLoading() {
        if (!isIE) {
            bigLoading = new fx.Opacity('bigLoading', {opacity: 0, duration: 300});
            bigLoading.custom(1, 0);
            bigLoading.toggle();
            setTimeout("hideDiv('bigLoading');", 300);

        } else {

            opacity('bigLoadingIE', 100, 0, 300);;
            setTimeout("hideDiv('bigLoadingIE');", 300);

        }
    }
    
    function loadAjanlok(nap) {
      
        new ajax ('ajax.php', {
            postBody: 'action=loadAjanlok&nap='+nap,
            update: $('ajanlokContainerTemp'),
            onComplete: loadAjanlokHandler
        });
        return true;

    }
    
    function loadAjanlokHandler() {

        $div('ajanlokContainer').innerHTML = $div('ajanlokContainerTemp').innerHTML;
        $div('ajanlokContainerTemp').innerHTML = "";
        
        fadeOutBigLoading();

    }
	
    function fadeInError() {
        if (!isIE) {
            bigLoading = new fx.Opacity('bigError', {opacity: 0, duration: 300});
            bigLoading.setOpacity(0);
            showDiv('bigError');
            bigLoading.custom(0, 1);
            bigLoading.toggle();

        } else {
            changeOpac(0, 'bigErrorIE');
            showDiv('bigErrorIE');
            showDiv('bigErrorIEimg');
            setTimeout("opacity('bigErrorIE', 0, 100, 300);", 0);
        }
        setTimeout("showDiv('pswremind')", 300);

    }	
    function fadeOutError() {
        if (!isIE) {
            bigLoading = new fx.Opacity('bigError', {opacity: 0, duration: 300});
            bigLoading.custom(1, 0);
            bigLoading.toggle();
            setTimeout("hideDiv('bigError');", 300);

        } else {
            opacity('bigErrorIE', 100, 0, 300);;
            setTimeout("hideDiv('bigErrorIE');", 300);
        }
        setTimeout("hideDiv('pswremind');", 150);
    }	

    function checkenter(event) { 
	if (event && event.which == 13) dologin();
 	if (window.event && window.event.keyCode == 13) dologin();
    }

    function dologin() {
		var username = document.getElementById("user").value;
		var password = document.getElementById("psw").value;
		if ((username.length == 0) || (username == "felhasználónév")) {
	  		alert("Add meg a felhasználóneved!");
	  		document.getElementById("user").value = "";
	  		document.getElementById("user").focus();
	 		return false;
 		}
		if (password.length == 0) {
	  		alert("Írd be a jelszavad!");
	  		document.getElementById("psw").focus();
	  		return false;
 		}
        new ajax ('ajax.php', {
            postBody: 'action=login&username='+username+'&password='+password,
            update: $('ajanlokContainerTemp'),
            onComplete: loginHandler
        });
        return true;
    }
    
    function loginHandler() {
		result = $div('ajanlokContainerTemp').innerHTML; 
		if (result == "error") {
            fadeInError();
			setTimeout("fadeOutError();", 5000);
		} else { //redirect
	  		window.location.href = result;
    	}
//        $div('ajanlokContainer').innerHTML = $div('ajanlokContainerTemp').innerHTML;
//        $div('ajanlokContainerTemp').innerHTML = "";
        

    }
    /******************************************************************/

    /** CHANGE OPACITY -- IE MIATT KELL KÜLÖN **/
    function opacity(id, opacStart, opacEnd, millisec) {
      	//speed for each frame
      	var speed = Math.round(millisec / 100);
      	var timer = 0;

      	//determine the direction for the blending, if start and end are the same nothing happens
      	if(opacStart > opacEnd) {
      		for(i = opacStart; i >= opacEnd; i--) {
      			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
      			timer++;
      		}
      	} else if(opacStart < opacEnd) {
      		for(i = opacStart; i <= opacEnd; i++)
      			{
      			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
      			timer++;
      		}
      	}
    }

    function changeOpac(opacity, id) {
        $div(id).filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
    }

	
    function checkmaxlength(textareaobj, maxlength) {
     if(textareaobj.value.length>=maxlength) {
          textareaobj.value = textareaobj.value.substring(0, maxlength);
          textareaobj.focus();
     } else {
     }
    }


	function getObject( obj ) {
  		if ( document.getElementById ) {
   	 		obj = document.getElementById( obj );
  		} else if ( document.all ) {
    		obj = document.all.item( obj );
  		} else { 
    		obj = null;
  		}
  		return obj;
  	}
	
	function getPosition(e) {
    	e = e || window.event;
	    var cursor = {x:0, y:0};
	    if (e.pageX || e.pageY) {
    	    cursor.x = e.pageX;
        	cursor.y = e.pageY;
	    } 
    	else {
        	var de = document.documentElement;
	        var b = document.body;
    	    cursor.x = e.clientX + 
        	    (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
	        cursor.y = e.clientY + 
    	        (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
	    }
    	return cursor;
	}

	function getScreenWidth() {
		if (self.innerWidth)
		{
			return self.innerWidth;
		}
		if (document.documentElement && document.documentElement.clientWidth)
		{
			return document.documentElement.clientWidth;
		}
		if (document.body)
		{
			return document.body.clientWidth;
		}
	}
	
	function moveObject( obj, e ) {
  		var tempX = 0;
  		var tempY = 0;
  		var offset = 0;
  		var objHolder = obj;

  		obj = getObject( obj );
  		if (obj==null) return;
/*
  		if (document.all) {
    		tempX = event.clientX + document.body.scrollLeft;
    		tempY = event.clientY + document.body.scrollTop;
  		} else {
    		tempX = e.pageX;
    		tempY = e.pageY;
  		}

  		if (tempX < 0){tempX = 0}
  		if (tempY < 0){tempY = 0}
*/
		cursorpos = getPosition(e);
 /* 		obj.style.top  = (cursorpos.y - 30 + offset) + 'px';
  		obj.style.left = (cursorpos.x - 140 - Math.round((getScreenWidth()-900)/2) + offset)  +'px';*/

		obj.style.left=cursorpos.x+5 +'px';
		obj.style.top  =cursorpos.y-15+'px';

  		displayObject( objHolder, true );
  	}
	
	function displayObject( obj, show ) {
  		obj = getObject( obj );
  		if (obj==null) return;

  		obj.style.display = show ? 'block' : 'none';
  		obj.style.visibility = show ? 'visible' : 'hidden';
  	}
	
	

  