﻿
// K I R O W S K  I   2 0 0 6

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 

var globalPage = 'default';
var currentProduct = new String;
var maxFlashVer = 7;
var flashLocation = '/Flash';

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
// CORE ADDONS / MODIFICATIONS
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 

if ( /msie 5\.[56789]/i.test( navigator.userAgent ) ) { //get all fix for ie55
	document._getElementsByTagName = document.getElementsByTagName;
	document.getElementsByTagName = function ( pTagName ) 
	{
		if ( pTagName == '*' ) 
			{ return document.all; }
			else 
			{ return document._getElementsByTagName(pTagName); }
	}
}

String.prototype.has = function ( pSubStr ) {
	if (this.indexOf(pSubStr)!=-1) { return(true); }
	return(false);
}

Array.prototype.has = function ( pItem ) {
	if (this.indexOf(pItem)!=-1) { return(true); }
	return(false);
}

document.getAll = function() {
	return(document.getElementsByTagName('*'));
}

PeriodicalExecuter.prototype.registerCallback = function() {
    this.intervalID = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
}

PeriodicalExecuter.prototype.stop = function() {
    clearInterval(this.intervalID);
}

Array.prototype.has = function( pItem ) {
	for(i=0;i<this.length;i++) { if (this[i]==pItem) return i; }
	return false;
}

Element.opacity = function( obj, opacity ) {
	opacity = (opacity == 100)?99.999:opacity;
	obj.style.filter = "alpha(opacity:"+opacity+")"; //ie
	obj.style.KHTMLOpacity = opacity/100; //khtml and friends
	obj.style.MozOpacity = opacity/100; //older gecko
	obj.style.opacity = opacity/100; //css3
}

Element.cloak = function( obj ) {
	if (obj != null ) obj.style.visibility = 'hidden';
}

Element.reveal = function( obj ) {
	if (obj != null ) obj.style.visibility = 'visible';
}

/*
Object.extend(Element, {
	reveal: function( pTarget ) {
		if ($(pTarget) != null) { $(pTarget).style.visibility = 'visible'; return true;}
		return false;
	}
});
*/

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
// HEARTBEAT / PULSE
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 

function tick( pTarget) {
	executionQueue.each( function(execItem){
		if (execItem.tick()) execItem.tick();
	});
}

var pe = new PeriodicalExecuter(tick, 0.09); //global speed; be careful
var executionQueue = new Array();

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
// CUSTOM OBJECTS (GLOBAL)
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 

var tCookie = Class.create();
Object.extend(tCookie.prototype, {

	initialize: function() {
	},
	

	set: function(name,value,days)
	{
		if (days)
		{
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	},

	get: function(name)
	{
		var nameEQ = name + "=";
		var retVal = null;
		var cookies = document.cookie.split(';');
		cookies.each(function(cookieItem){
			while (cookieItem.charAt(0)==' ') cookieItem = cookieItem.substring(1,cookieItem.length);
			if (cookieItem.indexOf(nameEQ) == 0) retVal = cookieItem.substring(nameEQ.length,cookieItem.length);
		});
		return retVal;
	},

	erase: function(name)
	{
		this.set(name,"",-1);
	}

});
var cookie = new tCookie();



// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
// DEBUG MODE
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 

function evalBooleanCookie( pInput) {
	if (pInput==null) return('nincs adat')
		else if (pInput==1) return('igen')
			else if (pInput==1) return('nem');
}

if ((location.hash.has('_noflash')) || (cookie.get('noflash')==1)) 
		{ maxFlashVer = 999; cookie.set('noflash',1,3); }
if (location.hash.has('_flash')) cookie.erase('noflash');


// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
// PER-MODULE/PAGE ADDONS, LOCAL OBJECTS
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 

//input field on left miniboxes should be cleared on first click
function inputSkinClickBoxLeft ( pTarget ) {
	inputs = $(pTarget).getElementsByTagName('INPUT');

	inputs[0].onclick = function() {
		if (this.clicked != 1) { this.value = ''; this.clicked = 1; }
	}

	inputs[1].onclick = function() {
		if (this.clicked != 1) { this.value = ''; this.clicked = 1; }
	}
}


//"our products" box in left sidebar
var tMenuWatcher = Class.create();
tMenuWatcher.prototype = {

	initialize: function( pSubCont , pmaxInTicks, pmaxOutTicks ) {
		this.pSubCont = pSubCont;
		this.pCont = $(pSubCont).parentNode;
		this.htmlElements = $A($(this.pCont).getElementsByTagName('*'));
		this.isVisible = false;
		
		//effectors
		this.fadeOutCount = -1;
		this.fadeInCount = -1;
		this.maxFadeTick = 4;
		
		//main object props
		this.maxOutTick = pmaxOutTicks;
		this.timeOut = -1;
		this.maxInTick = pmaxInTicks;
		this.timeIn = -1;
		
		for(i=0;i<this.htmlElements.length;i++) //no loops
		{ 
			var htmlElement = this.htmlElements[i];
			htmlElement.onmouseover = this.mouseOver.bindAsEventListener(this);
			htmlElement.onmouseout  = this.mouseOut.bindAsEventListener(this);
		}
		
		executionQueue.push(this); //push this to the heartbeat queue
	},
   
	//on timeout stop the clock and start the effect timer
	onTimeOut: function() {
		this.fadeOutCount = this.maxFadeTick;
		this.timeOut = -1;
	},
	
	//on timein allow opening
	onTimeIn: function() {
		//this.fadeInCount = 3;
		this.isVisible = true;
		this.timeIn = -1;
		this.mouseOver();
	},
   
	fadesOut: function() {
		if (this.fadeOutCount>0)
		{
			this.fadeOutCount--;
			Element.opacity($(this.pSubCont),this.fadeOutCount*20);
		}
		if  ( (this.fadeOutCount==0) && ( Element.visible($(this.pSubCont))) ) //if totally faded and still rendered, stop fader and hide html
		{
			this.fadeOutCount=-1;
			this.fadeInCount=-1;
			this.isVisible = false;
			Element.hide(this.pSubCont);
		}
	},
   
	fadesIn: function() {
	},
   
	//event loopback
	mouseOver: function(evt) {
		if (this.isVisible) 
		{
			Element.show(this.pSubCont);
			Element.opacity($(this.pSubCont),100);
			this.timeOut = -1; //don't start /halt timeout
			this.fadeOutCount = -1; //don't start / halt fadestep
		} else {
			this.timeIn = this.maxInTick;
		}
	},

	//event loopback
	mouseOut: function(evt) {
		//if we are in a timein cycle, cancel it now
		if (this.timeIn > 0) { this.timeIn = -1; } 
			//otherwise just start a timeout cycle
			else { this.timeOut = this.maxOutTick; }
	},

	//per-object  ticker
	tick: function(pSelf) {
		this.fadesOut();
		this.fadesIn();

		if (this.timeOut > 0) this.timeOut--;
		if (this.timeOut == 0) this.onTimeOut();
		
		if (this.timeIn > 0) this.timeIn--;
		if (this.timeIn == 0) this.onTimeIn();
	}
};

//extra addons for the prodbox "dropdown"
function enhanceLinks() {
	htmlElements = $('subMenuBlock').getElementsByTagName('A');
	for (var i = 0; i < htmlElements.length; i++ )
	{
		htmlElement = htmlElements[i];
		htmlElement.onmouseover = function() {
			$('subMenuMainLink').innerHTML = '<span>' + this.innerHTML + '</span>';
		}
	}

}

//popup page
function popupPage(pImgName, pMonth, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=0';
	win = window.open('', pMonth, winprops);
	win.document.write('<html><head><title>Nestlé hírlevél - '+ pMonth +'</title><meta http-equiv="imagetoolbar" content="no" /><meta name="author" content="kirowski"><meta name="reply-to" content="info@kirowski.com"><meta name="copyright" content="copyright 2006. kirowski"></head>');	
	win.document.write('<img src="' + pImgName + '" border="0" width="555" alt="Nestlé hírlevél - '+ pMonth +'" />');
	win.document.write('</body></html>');
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function popup( page, width, height ) {
	window.open( page, '', "width=" + width + ",height=" + height + ",menubar=no,location=no,resizable=no,scrollbars=no,status=no" )
}

//dropdown divs
function dropDown(menu) {
	var selected = document.getElementById(menu);
	var maxNum = 19;
	if (selected.className=='question'){
		//var actMenuNum = menu.substring(1,menu.length)
		for ( var i = 1; i <= 19; i++ ) {
			var actMenuId = 'm' + i + 'sub';
			document.getElementById(actMenuId).style.display = 'none';
		}
		document.getElementById(menu + 'sub').style.display = 'block';
		document.getElementById(menu).className ='answerView';
	}
	else {
		document.getElementById(menu + 'sub').style.display = 'none';
		document.getElementById(menu).className ='question';
	}
	
}

function Digitonly(event) {
	var unicode = event.charCode ? event.charCode : event.keyCode;
	if ((unicode >= 48 && unicode <= 57) || (unicode >= 96 && unicode <= 105) || (unicode >= 35 && unicode <= 40) ||
       unicode == 9 || unicode == 8 || unicode == 46
    ) {
        return true;
	} else {
        return false;
	}
}



function c_opacity(o,p){
  o.style.filter='alpha(opacity='+p+')';
  o.style.opacity=p/100;
}


function fade(x,n,p){
    var opp=p;
    if (opp>=0 && opp<=100) {
        x.style.display='block';
        opp+=n;
        if (opp > 100) {
            opp = 100;
            x.className='showLogin';
            return true;
        }
        else if (opp < 0) {
            opp = 0;
            x.style.display='none';
            x.className='';
            return true;
        }
        c_opacity(x,opp);
        setTimeout(function(){
          fade(x,n,opp)
        },30);
    }
}

document.getElementsByClassName = function(cl) {
    var retnode = [];
    var myclass = new RegExp('\\b'+cl+'\\b');
    var elem = this.getElementsByTagName('*');
    for (var i = 0; i < elem.length; i++) {
        var classes = elem[i].className;
        if (myclass.test(classes)) retnode.push(elem[i]);
    }
    return retnode;
}; 


function frameResize(){
    var df=document.getElementsByClassName('dynamicFrame');
    if (df.length) {
            
        var RegFrame = df[0];
        var rfb = RegFrame.contentWindow.document.body || RegFrame.window.document.body;
        var newHeight=Element.getHeight(rfb);
        {
            RegFrame.style.height = newHeight + 'px';            
        }
    }    
}

Event.observe(window,'load',function(){
    if ($('exitLogin')) {
        
        var fb = document.getElementById('floatBox');
        
        if (document.getElementsByClassName('smallError')[0]) {
            fb.style.display='block';
            c_opacity(fb,100);
        }
        
        $('exitLogin').onclick=function(){
            fade(this.parentNode, -10, 100);
        }
        
        
        
        Event.observe(document.getElementsByClassName('enterLink')[0],'click', function(){
            if (fb.className.indexOf('showLogin')==-1) {
                fade(fb, 10, 0);
            }
            return false;
        })
    }
    
    frameResize();
    
})