if (typeof addEvent != 'function') {
	function addEvent(object, event, fn) {
		if (object.addEventListener){
			object.addEventListener(event, fn, false);
			return true;
		} else if (object.attachEvent){
			var r = object.attachEvent("on" + event, fn);
			return r;
		} else {
			return false;
		}
	}
}

// addEvent(window, "load", insertTAd);
addEvent(window, "load", displayMainOffers);
// addEvent(window, "load", fixFlashObjects);

var divMenu = new FSMenu('divMenu', false, 'display', 'block', 'none');
divMenu.showDelay = 250;
divMenu.switchDelay = 60;
divMenu.hideDelay = 10;
divMenu.showOnClick = 1;

FSMenu.prototype.onshow = function(mN) {

	document.getElementById('button_' + mN).className='active';
	document.getElementById('superbanner').style.display='none';
}

FSMenu.prototype.onhide = function(mN) {

	setTimeout("document.getElementById('button_" + mN + "').className=''", 0);
}

function fisherYates ( myArray ) {
  var i = myArray.length;
  if ( i == 0 ) return false;
  while ( --i ) {
     var j = Math.floor( Math.random() * ( i + 1 ) );
     var tempi = myArray[i];
     var tempj = myArray[j];
     myArray[i] = tempj;
     myArray[j] = tempi;
   }
   
   return myArray
}

function fixFlashObjects() {
	var y = document.getElementsByTagName('embed');
	for (var i=0; i<y.length; i++) {
		y[i].setAttribute('wmode', 'transparent');
	}
	var y = document.getElementsByTagName('object');
	for (var i=0; i<y.length; i++) {
/*
		y[i].style.position='absolute';
		y[i].style.zIndex=2;
		y[i].style.left=0;
		alert(y[i].style);
*/
		var param = document.createElement('PARAM');
		param.setAttribute('name', 'wmode');
		param.setAttribute('value', 'transparent');
		y[i].appendChild(param); 
	}
}

function displayMainOffers() {

	var y = document.getElementsByTagName('div');
	var divs = new Array();
	
	for (var i=0; i<y.length; i++) {
		if (y[i].className == 'openpage_offers') {
			divs[divs.length] = y[i];
		}
	}
	
	if (!divs.length) {
		return false;
	}
	
	divs = fisherYates(divs);
	
	for (i = 0; i < 2; i++) {
		divs[i].style.display='block';
	}
}

function insertTAd() {

	var mainDiv;
	var append = 0;
	var mtop = '5px';
	var mbottom = '15px';
	var y = document.getElementsByTagName('div');
	
	for (var i=0; i<y.length; i++) {
		if (y[i].className=='main_item_box') {
			mainDiv = y[i];
			break;
		}
	}

	if (mainDiv) {
		var ie = 0;
		if (document.all) {
			var firstTd = mainDiv.childNodes[1].childNodes[0].childNodes[0].childNodes[0];
			var secondTd = mainDiv.childNodes[1].childNodes[0].childNodes[0].childNodes[1];
			var thirdTd = mainDiv.childNodes[1].childNodes[0].childNodes[0].childNodes[2];
			
			if (firstTd.style.width == '175px' && secondTd.style.width == '20px') {
				var prefTd = mainDiv.childNodes[1].childNodes[0].childNodes[0].childNodes[2];
				var bprefTd = prefTd.childNodes[0];
				mtop = '0px';
			}
			else if (firstTd.style.width == '175px') {
				var prefTd = mainDiv.childNodes[1].childNodes[0].childNodes[0].childNodes[0];
				var bprefTd = prefTd.childNodes[0];
				append = 1;
				mbottom = '0px';
			}
			else {
				var prefTd = mainDiv.childNodes[1].childNodes[0].childNodes[0].childNodes[1];
				var bprefTd = prefTd.childNodes[0];
				mtop = '0px';
			}
		}
		else {
			var firstTd = mainDiv.childNodes[3].childNodes[1].childNodes[0].childNodes[1];
			var secondTd = mainDiv.childNodes[3].childNodes[1].childNodes[0].childNodes[3];
			var thirdTd = mainDiv.childNodes[3].childNodes[1].childNodes[0].childNodes[5];
			
			if (firstTd.style.width == '175px' && secondTd.style.width == '20px') {
				var prefTd = mainDiv.childNodes[3].childNodes[1].childNodes[0].childNodes[5];
				var bprefTd = prefTd.childNodes[0];
				mtop = '0px';
			}
			else if (firstTd.style.width == '175px') {
				var prefTd = mainDiv.childNodes[3].childNodes[1].childNodes[0].childNodes[1];
				var bprefTd = prefTd.childNodes[0];
				append = 1;
				mbottom = '0px';
			}
			else {
				var prefTd = mainDiv.childNodes[3].childNodes[1].childNodes[0].childNodes[3];
				var bprefTd = prefTd.childNodes[0];
				mtop = '0px';
			}
		}

		var advert = document.createElement('DIV');
		// advert.innerHTML = '<DIV id="tmobilebanner" style="width: 330px; margin: ' + mtop + ' auto ' + mbottom + ' auto;"><IFRAME SRC="http://ad.hu.doubleclick.net/adi/N1883.fotexnet.hu/B2597624;sz=330x247;ord=[timestamp]?" WIDTH=330 HEIGHT=247 MARGINWIDTH=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 SCROLLING=no BORDERCOLOR="#000000"><SCR' + 'IPT language="JavaScript1.1" SRC="http://ad.hu.doubleclick.net/adj/N1883.fotexnet.hu/B2597624;abr=!ie;sz=330x247;ord=[timestamp]?"></SC'+ 'RIPT><NOSC' + 'RIPT><A HREF="http://ad.hu.doubleclick.net/jump/N1883.fotexnet.hu/B2597624;abr=!ie4;abr=!ie5;sz=330x247;ord=[timestamp]?"><IMG SRC="http://ad.hu.doubleclick.net/ad/N1883.fotexnet.hu/B2597624;abr=!ie4;abr=!ie5;sz=330x247;ord=[timestamp]?" BORDER=0 WIDTH=330 HEIGHT=247 ALT="Kattintson ide!"></A></NOSC' + 'RIPT></IFRAME></DIV>';
		advert.innerHTML = '<DIV id="erstebanner" style="width: 330px; height: 247px; margin: ' + mtop + ' auto ' + mbottom + ' auto;"><IFRAME id="tiframe" WIDTH=330 HEIGHT=247 MARGINWIDTH=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 SCROLLING=no BORDERCOLOR="#000000" src="images/ad.html"></IFRAME></DIV>';
		
		if (prefTd) {
			if (append) {
				prefTd.appendChild(advert); 
			}
			else {
				prefTd.insertBefore(advert, prefTd.childNodes[0]); 
			}
		}

		document.getElementById('tiframe').innerHTML = ize;
	}

}

function change_variant(currentbox) {
	numb = currentbox.id.split("_");
	currentbox = numb[1];

    i=parseInt(currentbox)+1;

// I empty all combo boxes following the current one

    while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) &&
           (document.getElementById("combo_"+i)!=null)) {
         son = document.getElementById("combo_"+i);
	     // I empty all options except the first one (it isn't allowed)
	     for (m=son.options.length-1;m>0;m--) son.options[m]=null;
	     // I reset the first option
	     son.options[0]=new Option(displaywhenempty,valuewhenempty);
	     i=i+1;
    }


// now I create the string with the "base" name ("stringa"), ie. "data_1_0"
// to which I'll add _0,_1,_2,_3 etc to obtain the name of the combo box to fill

    stringa='data';
    i=0
    while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) &&
           (document.getElementById("combo_"+i)!=null)) {
           eval("stringa=stringa+'_'+document.getElementById(\"combo_"+i+"\").selectedIndex");
           if (i==currentbox) break;
           i=i+1;
    }


// filling the "son" combo (if exists)

    following=parseInt(currentbox)+1;

    if ((eval("typeof(document.getElementById(\"combo_"+following+"\"))!='undefined'")) &&
       (document.getElementById("combo_"+following)!=null)) {
       son = document.getElementById("combo_"+following);
       stringa=stringa+"_";
       i=0;
       while ((eval("typeof("+stringa+i+")!='undefined'")) || (i==0)) {

       // if there are no options, I empty the first option of the "son" combo
	   // otherwise I put "-select-" in it

	   	  if ((i==0) && eval("typeof("+stringa+"0)=='undefined'"))
	   	      if (eval("typeof("+stringa+"1)=='undefined'"))
	   	         eval("son.options[0]=new Option(displaywhenempty,valuewhenempty)");
	   	      else
	             eval("son.options[0]=new Option(displaywhennotempty,valuewhennotempty)");
	      else
              eval("son.options["+i+"]=new Option("+stringa+i+".text,"+stringa+i+".value)");
	      i=i+1;
	   }
       //son.focus()
       i=1
       combostatus='';
       cstatus=stringa.split("_");
       while (cstatus[i]!=null) {
          combostatus=combostatus+cstatus[i];
          i=i+1;
          }
       return combostatus;
    }
}