﻿var mouse_x = 0;
var mouse_y = 0;
var akt_sub_menu = 0;

function getByID(id)
{
    if(document.getElementById(id))
    {
        return document.getElementById(id);
    }
    else
    {
        return false;
    }
}

function getInfo(arg)
{
    var obj = null;
    if(typeof arg == 'object')
    {
        obj = arg;
    }
    else
    {
        obj = getByID(arg);
    }

    return {'left'  : parseInt(obj.offsetLeft),
            'top'   : parseInt(obj.offsetTop),
            'width' : parseInt(obj.offsetWidth),
            'height': parseInt(obj.offsetHeight)
            }
}

function showSubMenu(number)
{
    number = parseInt(number);
    var menu = 'menu-'+number;
    var sub = 'sub-'+number;
    var cont = sub+'-contact';
    var sub_obj = null;
    var menu_obj = null;
    var info = null;
    var i=0;
    if(getByID(menu) && getByID(sub) && getByID(cont))
    {
        sub_obj = getByID(sub);
        menu_obj = getByID(menu);
        cont_obj = getByID(cont);
        info = getInfo(menu_obj);
        akt_sub_menu = number;
        for(i=1 ; i<=14 ; i++)
        {
            if(i==number)continue;
            hideSubMenu(i);
        }

        if(number == 7)
        {
            menu_obj.style.color = '#bdd4e8';
        }
        else
        {
             menu_obj.style.backgroundColor = '#9a1225';
        }
        cont_obj.style.width = info.width + 'px';
        sub_obj.style.top = 44 + 'px';
        sub_obj.style.left = info.left + 'px';
        sub_obj.style.display = 'block';
    }
    else
    {
        if(getByID(menu))
        {
            getByID(menu).style.backgroundColor = '#9a1225';
        }
        hideSubMenu(number-1);
        hideSubMenu(number+1);
    }
}

function hideSubMenu(number)
{
    var menu = 'menu-'+number;
    var sub = 'sub-'+number;
    var sub_obj = null;
    var menu_obj = null;
    if(getByID(menu) && getByID(sub))
    {
        sub_obj = getByID(sub);
        menu_obj = getByID(menu);

        menu_obj.style.backgroundColor = '';
        menu_obj.style.color = '';
        sub_obj.style.display = 'none';
    }
}

function checkOnMouseOut(number)
{
    var container = getInfo('container');
    var info = getInfo('sub-'+number);

    var left = info.left;
    var right = left + info.width;
    var top = 0;
    var bottom = info.top + info.height;

    if(mouse_x - container.left < left)
    {
        hideSubMenu(number);
    }

    if(mouse_x - container.left > right)
    {
        hideSubMenu(number);
    }

    if(mouse_y > bottom)
    {
        hideSubMenu(number);
    }
    if(mouse_y < 2)
    {
        hideSubMenu(number);
    }
}

function goTo(url)
{
   	window.location = url;
}

function showAnswer(question, answer)
{
    var div_elements = document.getElementById('faq-question-and-answer').getElementsByTagName('div');
    var id = 'q' + question + '-' + 'a' + answer;
    var i=0;
    
    for(i=0 ; i<div_elements.length ; i++)
    {
        if(!div_elements[i].id) continue;
        
        if(div_elements[i].id == id)
        {
            div_elements[i].style.display = (div_elements[i].style.display == 'none' ? 'block' : 'none');
            div_elements[i].parentNode.style.display = (div_elements[i].parentNode.style.display == 'none' ? 'block' : 'none');
        }
        else
        {
            div_elements[i].style.display = 'none';
            div_elements[i].parentNode.style.display = 'none';
        }
    }
}

function showDownload(subcat, content)
{
    var div_elements = document.getElementById('downloads-subcat-and-content').getElementsByTagName('div');
    var id = 'tlc-' + subcat + '_' + 'suc-' + content;
    var i=0;
    
    for(i=0 ; i<div_elements.length ; i++)
    {
        if(!div_elements[i].id) continue;
        
        if(div_elements[i].id == id)
        {
            div_elements[i].style.display = (div_elements[i].style.display == 'none' ? 'block' : 'none');
        }
        else
        {
            div_elements[i].style.display = 'none';
        }
    }
}

function getPressData(page_name, page_number)
{
    Ajax.call('getPressData', 'fixed/'+page_name+'/ajax/', null, Ajax.OP_SETHTML, {'post':{'PAGENUM': page_number}, 'nodeId': 'press-content'});
}

function getIncubcoData(page_letter, seo)
{
    Ajax.call('getPressData', 'fixed/'+seo+'/ajax/', null, Ajax.OP_SETHTML, {'nodeId': 'incubco-content', 'post': {'PAGENUM': page_letter}});
}

function getInnovationData(page_letter, page_number, seo)
{
    Ajax.call('getPressData', 'fixed/'+seo+'/ajax/', null, Ajax.OP_SETHTML, {'post': {'PAGENUM': page_letter+','+page_number}, 'nodeId': 'innovation-dictionary-content'});
}

function getBlogData(seo, page)
{
    Ajax.call('getPressData', 'fixed/'+seo+'/', null, Ajax.OP_SETHTML, {'post': {'blog_page': page, 'AJAX': true}, 'nodeId': 'blog-content'});
}

function openMailWindow(email)
{
    openPopupPage(_URL_ROOT+'emailpopup/'+email+'/', 'Levélküldés', 500, 400, 'center:yes; fullscreen:0; menubar:0; resizable:0; scrollbars:0; status:0; titlebar:0; toolbar:0;');
}

function getSearchData(word, page)
{
    Ajax.call('getSearchData', 'search/', null, Ajax.OP_SETHTML, {'post': {'page': page, 'AJAX': true, 'search_text': word}, 'nodeId': 'search-content'});
}

function sendSearchForm(form, lang)
{
    var msg = (lang == 'hu' ? 'Túl rövid keresési kritérium, kérem adjon meg legalább 3 karaktert.' : 'Too short text type here.');
    
    if(checkInput(form.search_text, CHK_LENGTH, msg, 3))
    {
        form.submit();
    }
    return false;
}


document.onmousemove = function(e)
{
	if(document.all)
	{
		mouse_x = event.clientX;
     	mouse_y = event.clientY;
    }
	else
	{
    	mouse_x = e.pageX;
    	mouse_y = e.pageY;
    }

    if(akt_sub_menu > 0)
    {
        checkOnMouseOut(akt_sub_menu);
    }
}

function correctPng(id)
{
    var obj = null;
    var src = '';
    var w = 0;
    var h = 0;
    if((obj = document.getElementById(id)) && navigator.appName == 'Microsoft Internet Explorer')
    {
        src = obj.src;
        w = obj.width;
        h = obj.height;
        obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='scale')";
        obj.src = './images/1x1.gif';
        obj.width = w;
        obj.height = h;
    }
}

function expandItem()
{
    var obj = null;
    if( (obj = document.getElementById('expand')) && obj.innerHTML != '')
    {
        eval(obj.innerHTML);
    }
}

window.onload = function()
{
    correctPng('lang-flag');
    expandItem();
}

function writeVideoPlayer(url_video_player,url_video,name_video,stillimgurl,width,height)
{
document.write('<object id="video" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" style="width:'+(width != '' ? width : 400)+'px; height:'+(height != '' ? height : 300)+'px;">');
document.write('<param name="movie" value="'+url_video_player+'#src='+url_video+'&volume=100&autoplay=no&fn='+name_video+'&stillimgurl='+stillimgurl+'">');
document.write('<param name="src" value="'+url_video_player+'#src='+url_video+'&volume=100&autoplay=no&fn='+name_video+'&stillimgurl='+stillimgurl+'">');
document.write('<param name="quality" value="High">');
document.write('<param name="allowScriptAccess" value="sameDomain">');
document.write('<param name="bgcColor" value="FFFFFF">');
document.write('<embed src="'+url_video_player+'#src='+url_video+'&volume=100&autoplay=no&fn='+name_video+'&stillimgurl='+stillimgurl+'" quality="high" bgcolor="#ffffff" name="video" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" style="width:'+(width != '' ? width : 400)+'px; height:'+(height != '' ? height : 300)+'px; text-align:middle;">');
document.write('</object>');
}

function writeKattancs(file,width,height,link)
{
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="player" align="middle" width="'+width+'" height="'+height+'">');
    document.write('<param name="allowScriptAccess" value="sameDomain" />');
    document.write('<param name="movie" value="flash/player.swf?video_src='+file+'&link='+link+'"/>');
    document.write('<param name="wmode" value="transparent"/><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />');
    document.write('<embed wmode="transparent" src="flash/player.swf?video_src='+file+'&link='+link+'" quality="high" bgcolor="#ffffff" name="player" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"  width="'+width+'" height="'+height+'" /></object>');
}

function writeFLVPlayer(stream,width,height)
{
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+width+'" height="'+height+'" id="FLVPlayer1">');
    document.write('<param name="movie" value="flash/FLVPlayer_Progressive.swf">');
    document.write('<param name="salign" value="lt">');
    document.write('<param name="quality" value="high">');
    document.write('<param name="scale" value="noscale">');
    document.write('<param name="FlashVars" value="&skinName=flash/clearSkin_3&streamName='+stream+'&autoPlay=false&autoRewind=true">');
    document.write('<embed src="flash/FLVPlayer_Progressive.swf" flashvars="&skinName=flash/clearSkin_3&streamName='+stream+'&autoPlay=false&autoRewind=true" quality="high" scale="noscale" width="'+width+'" height="'+height+'" name="FLVPlayer1" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">');
    document.write('</object>');
}

function showSubLinks(obj)
{
    var div = nextSibling(obj);
    div.style.display = (div.style.display == 'none' ? 'block' : 'none');
}

function openPopupVideo(width,height,stream)
{
    openPopupPage(_URL_ROOT+'fullvideo/?stream='+stream+"&width="+width+"&height="+height, 'FULLVIDEO', width, height, 'center:yes; fullscreen:0; menubar:0; resizable:0; scrollbars:0; status:0; titlebar:0; toolbar:0;');
}