function SetTab_Active(id,imgpost)
{
   var item = document.getElementById(id);
   item.style.color='#ffffff';
   item.style.backgroundColor='#90979d';
   item.style.backgroundImage='none';
   item.style.backgroundImage='url(images/tab_active_'+imgpost+'.gif)';
}

function SetTab_Inactive(id,imgpost)
{
   var item = document.getElementById(id);
   item.style.color='#dddddd';
   item.style.backgroundColor='#606a74';
   item.style.backgroundImage='none';
   item.style.backgroundImage='url(images/tab_inactive_'+imgpost+'.gif)';
}

function SetTab(to)
{
    if (activetab == to) return;
    if (!document.getElementById) return;
    
    var input = '';
    
    if (activetab != '')
    {
       if (document.getElementById(activetab+'LabelLink'))
       {
         SetTab_Inactive(activetab+'LabelLeft'  , 'left');
         SetTab_Inactive(activetab+'LabelMiddle', 'base');
         SetTab_Inactive(activetab+'LabelRight' , 'right');
         document.getElementById(activetab+'LabelLink').className = 'tabLabel';
         var abox = document.getElementById(activetab.replace('Tab','Box'));
         if (abox) if (abox.value != eval(activetab+'Value')) input = abox.value;
       }
       document.getElementById(activetab).style.display = 'none';
       Change_Class('.mlproduct_'+activetab,'display','none');
    }
    SetTab_Active(to+'LabelLeft'  , 'left');
    SetTab_Active(to+'LabelMiddle', 'base');
    SetTab_Active(to+'LabelRight' , 'right');
    document.getElementById(to+'LabelLink').className = 'activeTabLabel';
    
    var tbox = document.getElementById(to.replace('Tab','Box'));
    if ((input=='') && eval(to+'Value')) input = eval(to+'Value');
    if (tbox) tbox.value = input;
    
    document.getElementById(to).style.display = 'block';
    Change_Class('.mlproduct_'+to,'display','block');
    Change_Class('.errorBox','display','none');
    if (tbox) { tbox.focus(); tbox.select(); }
    activetab = to;
}

function SubmitForm()
{
    var abox = document.getElementById(activetab.replace('Tab','Box'));
    if (abox && (abox.value == ""))
    {
      document.forms[activetab+'Form'].onsubmit = function() { return false; }
      return;
    }

    document.forms[activetab+'Form'].submit()
}

function OnEnterSubmit(textObjId)
{
    if (!document.getElementById) return;
    document.getElementById(textObjId).onkeypress = CheckSubmit;
}

function CheckSubmit(keyObj)
{
    var keyCode = 0;
    if (window.event) keyCode = window.event.keyCode;
    else if (keyObj) keyCode = keyObj.which;

    if (keyCode == 13) SubmitForm();
}

function CheckSpell(tab, input, lang)
{
   SetTab('spellTab');
   document.forms['spellTabForm'].source.value  = tab + ',' + input  + ',' + lang  + ',' + document.getElementById(lang).value;
   document.forms['spellTabForm'].words.value  = document.getElementById(input).value;
   document.forms['spellTabForm'].splang.value = document.getElementById(lang).value.substr(0,2).toLowerCase();
   SubmitForm();
}

function Feedback(product, description)
{
    var fb = feedbackTempl;
    fb = fb.replace('<product>', product);
    fb = fb.replace('<description>', description.replace(/&pc;/g,'%'));
    window.open(fb, "wf_feedback", "menubar=1,toolbar=1,resizable-1,location=1,status=1,scrollbars=1");
}

function GetXPos(obj)
{
    var X = 0;
    do { X += obj.offsetLeft; obj = obj.offsetParent; } while (obj);
    return X;
}

function GetYPos(obj)
{
    var Y = 0;
    do { Y += obj.offsetTop; obj = obj.offsetParent; } while (obj);
    return Y;    
}

var tt;
var tt_div_id;
var so;
function ShowTooltip(obj_under_mouse, div_id, show_under_mouse)
{
    if (!document.getElementById) return;
    
    //Hide active tooltip
    if (tt) tt.style.display = 'none';
    
    
    //Set new tooltip
    tt = document.getElementById(div_id);
    if (!tt) return;
    if (show_under_mouse)
    {
        var objx = GetXPos(obj_under_mouse);
        var objy = GetYPos(obj_under_mouse);
        var screenx = document.body.offsetWidth;
        //var screeny = document.body.offsetHeight;
        
        if (objx < screenx/2)
        {
            tt.style.left   = objx;
            tt.style.right  = 'auto';
        }
        else
        {
            tt.style.left  = 'auto';
            tt.style.right = screenx - objx - obj_under_mouse.offsetWidth;
        }
            
        //if (objy < screeny/2)        
            tt.style.top    = objy + obj_under_mouse.offsetHeight;
        //else
        //    tt.style.bottom =  screeny - objy;
        
        so = tt;
    }
    else
    {
        so = obj_under_mouse;
    }
    tt.style.display = 'block';
    tt_div_id=div_id;
    
    //Check for need
    document.onmousemove=CheckTooltip;
    if(div_id =='EditTooltip')
    {
    	document.onmousemove=null;
    }
}

function CheckTooltip(e)
{
    if (!so || !tt) return;
    var toler=60;
    var allowx1 = GetXPos(so) - toler;
    var allowx2 = allowx1 + so.offsetWidth + toler*2;
    var allowy1 = GetYPos(so) - toler;
    var allowy2 = allowy1 + so.offsetHeight + toler*2;
    
    var x = GetScreenXPosition(e);
    var y = GetScreenYPosition(e);
    
    if ( (x<allowx1) || (x>allowx2) || (y<allowy1) || (y>allowy2) )
        tt.style.display = 'none';    
}

function HideTooltip(e)
{
    if (tt) tt.style.display = 'none';
    tt_div_id='';
}

var active_icontent = '';
function SwitchIContent(ic)
{
  if (!document.getElementById) return;
  var item=document.getElementById(ic);
  if (item)
  {
    if (item.style.display == 'none')
    {
      if (active_icontent != '') document.getElementById(active_icontent).style.display = 'none';
      item.style.display = 'block';
      active_icontent    = ic;
    }
    else
    {
      item.style.display = 'none';
      active_icontent = '';
    }
  }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function sa_tooltip(obj, hyphen)
{
    if(tt_div_id=='EditTooltip') return;
    sa_ttobj   = obj;
    var tttext = "<"+"table class='tooltiptable' cellpadding='0' cellspacing='2'>";
    
    //Suggestion
    if (sa_tooltip.arguments.length > 2)
    {
      if (hyphen != '') 
        tttext += "<"+"tr><"+"td><"+"hr><"+"/td><"+"/tr>";
      
      if (sa_tooltip.arguments.length < 5)
        tttext += "<"+"tr><"+"td class='spell_suggest'>" + "Nincs ajánlás!" + "<"+"/td><"+"/tr>";
      else for (var i=4; i<sa_tooltip.arguments.length; i++)
        tttext += "<"+"tr><"+"td class='spell_suggest' onclick='sa_replace(this, "+sa_tooltip.arguments[2]+", "+sa_tooltip.arguments[3]+")'>" + sa_tooltip.arguments[i] + "<"+"/td><"+"/tr>";
    }
    
    tttext += "<"+"/table>";
    document.getElementById('spellActionTooltip').innerHTML = tttext;
    ShowTooltip(obj,'spellActionTooltip',true);
}

function sa_replace(source, lid, wid)
{
//  spellActionFrame.sa_input[lid][wid] = source.innerHTML;
//  spellActionFrame.sa_changed = true;
  
  sa_ttobj.style.color = "green";
  sa_ttobj.innerHTML   = source.innerHTML;
  
  HideTooltip('');
}

function edit_tooltip(obj)
{
    sa_ttobj   = obj;
    var tttext = "<"+"table class='tooltiptable' cellpadding='0' cellspacing='2'>";
    
    tttext += "<"+"tr><"+"td class='spell_suggest' ><input id='edit_field'><img src='imports/ok.gif' onclick='edit_replace(this)'><img src='imports/status_x.png' onclick='HideTooltip(this)'></td></tr>";
    tttext += "<a href='#' onclick='document.getElementById(\"edit_field\").focus();VirtualKeyboard.toggle(\"edit_field\",\"edkeyboard\"); return false;'><img src='images/keyboard.png' border='0'></a><div id='edkeyboard' style='position:absolute;'></div>";
//    tttext += "<tr><td> </td></tr></table>";
    document.getElementById('EditTooltip').innerHTML = tttext;
    document.getElementById('edit_field').value=obj.innerHTML;
    ShowTooltip(obj,'EditTooltip',true);
    document.getElementById('edit_field').focus();
}

function edit_replace(source)
{
//  spellActionFrame.sa_input[lid][wid] = source.innerHTML;
//  spellActionFrame.sa_changed = true;
  
  sa_ttobj.style.color = "brown";
  sa_ttobj.innerHTML   = document.getElementById('edit_field').value;
  
  HideTooltip('');
}


