
// skrypty do obs³ugi infoTip, pod?wietlania pól menu

function initEvents()
{
    // obs³uga podœwietlania obrazków
    var obj;
    for(var i = 1; i < 15; i++)    // górne menu
    {
        obj = document.getElementById('tm' + i)
        if (obj)
        {
            obj.onmouseover = tMOver;
            obj.onmouseout = tMOut;        
        }
    }
    var dynaLine = document.getElementById('dynaLine');
    if(dynaLine)
    {
        dynaLine.onmouseover = unhide;
        dynaLine.onmouseout = tMOut;   
    }
}

function checkSubmit(waitSec)
{
    if(submitStarted)
    {
        no_submit_block = false;
        return false;
    }
    else
    {
        if(!no_submit_block)
        {
            submitStarted = true;
            window.setTimeout('submitStarted=false', waitSec*1000);
        }
        no_submit_block = false;
        return true;
    }
}

function placeFocus()
{
    if(disable_focus_placing)
        return;
    if(!document.forms || !document.forms[0] || !document.forms[0].elements)
        return;
    var elems = document.forms[0].elements;
    for(var i = 0; i < elems.length; i++)
    {
        if(elems[i].className && elems[i].className == 'errFormField' 
          && elems[i].type != 'hidden' && elems[i].type != 'image'
          && elems[i].name != 'skin' && !elems[i].disabled)
        {
            elems[i].focus();
            return;
        }
    }
    for(i = 0; i < elems.length; i++)
    {
        if(elems[i].type != 'hidden' && elems[i].type != 'image'
          && elems[i].name !='skin' && !elems[i].disabled)
        {
            elems[i].focus();
            break;
        }
    }
}

function eventHelper(event)
{
    var evt = (event) ? event : (window.event) ? window.event : "";
    if (!evt) 
        return false;
    var srcEl = (evt.srcElement) ? evt.srcElement : evt.target;
    return srcEl;    
}

// TOP MENU
function tMOver(event)
{
    try { // for FIREFOX
        var srcEl = eventHelper(event);
        var aTag = srcEl;
        if (aTag && document.getElementById('dynaLine'))
        {
            var leftpos = 0;
            var toppos = 0;
            
            do {
                aTag = aTag.offsetParent;
                leftpos += aTag.offsetLeft;
                toppos += aTag.offsetTop;
            } while(aTag.tagName != "BODY");
            
            var dLineStyle = document.getElementById('dynaLine').style;
            dLineStyle.width= '' + srcEl.offsetWidth - 4 + 'px';
            dLineStyle.top = '' + (toppos + 21) +'px';
            dLineStyle.left = '' + (leftpos + 2) + 'px';
            dLineStyle.visibility = 'visible';
        }
    }
    catch(e) {
    }
    return true;
}

function unhide() 
{
    try { // for FIREFOX
        if(document.getElementById('dynaLine'))
        {
            var dLineStyle = document.getElementById('dynaLine').style;
            dLineStyle.visibility = 'visible';
        }
    }
    catch(e) {
    }
    return true;
}

function tMOut()
{
    try { // for FIREFOX  
        if(document.getElementById('dynaLine'))
        {
            var dLineStyle = document.getElementById('dynaLine').style;
            dLineStyle.visibility = 'hidden';
        }
    }
    catch(e) {
    }
    return true;
}

// menu
function clickMenu(name)
{
    if(document.forms[0].elements['button'])
        document.forms[0].elements['button'].value='';
    document.forms[0].elements['menu'].value=name;
    document.forms[0].submit();
}

// przycisk
function clickButton(name)
{
    if(document.forms[0].elements['menu'])
        document.forms[0].elements['menu'].value='';
    document.forms[0].elements['button'].value=name;
    document.forms[0].submit();
}

//scroll
function scrollSelect(name, waitSec)
{
  var setDelayn = 1000;
  selectChanged = selectChanged + 1 ;
  setTimeout('scrollStoped("'+name+'",'+waitSec+')', setDelayn);
}
function scrollStoped(name, waitSec)
{
  selectChanged=selectChanged-1;

  if (selectChanged<=0)
  {
    if (checkSubmit(waitSec))
    {
      clickButton(name);
    }
  }
}

// INFO TIP
function closeInfoTip()
{
  if(infoTipWindow && infoTipWindow.close) 
    infoTipWindow.close();
}

function infoTip(elem, tipContent) 
{
    if (typeof infoTipDiv == 'function') {
      infoTipDiv(elem, tipContent);
    }
    
    tipContent = tipContent.replace(/&gt;/g, '>');
    tipContent = tipContent.replace(/&lt;/g, '<');
    var maxSmallTipSize = 240;
    if(tipContent.length > maxSmallTipSize) 
    {
        var tipHeight = 278;
        var tipWidth = 216;
        var tipLeft = eval(screen.availWidth-250);
        var tipTop = eval(screen.availHeight-360);
        var tipScrollbars = "yes";
    }
    else 
    {
        tipHeight = 148;
        tipWidth = 200;
        tipLeft = eval(screen.availWidth-250);
        tipTop = eval(screen.availHeight-230);
        tipScrollbars = "no";
    }  	
   closeInfoTip();
    window.tipContent = tipContent;
    
    var params = "width=" + tipWidth+ ",height=" + tipHeight 
        + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" 
        + tipScrollbars + ",resizable=no,left=" + tipLeft + ",top=" + tipTop;
    if(tipContent.length > maxSmallTipSize)
        infoTipWindow = window.open(htmlUrl + 'infoTip2.html', 'infoTipWindow', params);
    else 
        infoTipWindow = window.open(htmlUrl + 'infoTip.html', 'infoTipWindow', params);
}

function rawWindow(url, title, width, height)
{
    var params = "width=" + width + ", height=" + height
      + ",toolbar=no,location=no,directories=no,status=no"
      + ",menubar=no,scrollbars=no,resizable=no, left=100, top=100";
    window.open(url, title, params);
    return false;
}

function infoWindow(url, width, height)
{
    //window.moveTo(0,0);
    tipLeft = eval(screen.availWidth-250);
    tipTop = eval(screen.availHeight-230);
    var params = "width=" + width + ", height=" + height
      + ",toolbar=no,location=no,directories=no,status=no"
      + ",menubar=no,scrollbars=yes,resizable=no,left=100, top=100";
    infoLinkWindow = window.open(url, 'infoLinkWindow', params);
}

function infoTipLink(url)
{
    var tipHeight = 216;
    var tipWidth = 216;
    var tipLeft = eval(screen.availWidth-360);
    var tipTop = eval(screen.availHeight-360);
    
    closeInfoTip();
    
    var params = "width=" + tipWidth+ ",height=" + tipHeight 
        + ",scrollbars,left=" + tipLeft + ",top=" + tipTop;
    infoTipWindow = window.open(url, 'infoTipWindow', params);
}

function amountHelper(evt, fieldToFocus)
{
    var charCode = evt.charCode ? evt.charCode : evt.which == 0 ? 0 : evt.keyCode;
    if(charCode == 44 || charCode == 46)
    {
        if(document.forms[0].elements[fieldToFocus])
        {
            document.forms[0].elements[fieldToFocus].focus();
            document.forms[0].elements[fieldToFocus].select();
            if(!(evt.which || evt.which == 0)) // IE
                evt.keyCode = 0;
            return false;
        }
    }
    return true;
}

function preventBackRefresh(event)
{
    var evt = (event) ? event : (window.event) ? window.event : "";
    if (!evt) 
        return false;
    var srcEl = (evt.srcElement) ? evt.srcElement : evt.target;

    var retValue = true;
    
    if (evt.keyCode == 116 // next for Firefox
        && (evt.type == "keydown" || (evt.type == "keypress" && evt.charCode == 0)))
    {
        /* F5 */
        retValue = false;
    } 
    else if (evt.keyCode == 8) 
    {
        /* backspace */
        if (!srcEl || !srcEl.type || 
           !(srcEl.type == "text" || srcEl.type == "textarea" || srcEl.type == "password"))
        {
            retValue = false;
        }
    }
    
    if(!retValue)
    {
        if(!(evt.which || evt.which == 0)) // IE
            evt.keyCode = 0;
    }
    
    return retValue;
}

function unblock_js() {
    var obj = document.getElementById('no_js');
    if (obj) {
       obj.value=0;
    }
}









