
function in_array(needle, haystack, strict) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
 
    var found = false, key, strict = !!strict;
 
    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }
 
    return found;
}

function clearFormElements(strFormId) {
    var oForm = document.getElementById(strFormId);
    
    if(typeof(oForm) == "undefined" || oForm == null) {
        return;
    }
    
    var elems = oForm.elements;
    var strType = "";
    for(var i = 0;i < elems.length;i++) {
        strType = elems[i].type;
        if(strType == "checkbox") {
            elems[i].checked = false;
        }
        if(strType == "text") {
            elems[i].value = "";
        }
        if(strType = "select") {
            elems[i].selectedIndex = 0;
        }
    }
}

function send(event) {
   event = (event)?event:((window.event)?event:null);
   if (event.keyCode==13) {
    document.forms['form_wyszuk_zb'].submit();
    return false;
   }
}

function events(event,obj) {
   event = (event)?event:((window.event)?event:null);
   if (event.keyCode==13) {
    switch(obj.id) {
        case 'id_zmien_ilosc':
            //submitFormByName('form_koszyk_zm_ilosc');
            obj.form.submit();
            return false;
        break;
    }
   }    
}

function submitFormById(strFormId) {
    if(document.getElementById(strFormId) == null) {
        return false;
    }
    document.getElementById(strFormId).submit();
    return true;
}

function submitFormByName(strFormName) {
    if(typeof(document.forms[strFormName]) == "undefined" || document.forms[strFormName] == null) {
        return false;
    }
    document.forms[strFormName].submit();
    return true;
}


function Logout() {
 window.location="index2.php?option=logout";
}

function LogoutOnTimeout(interval) {
 if(interval > 0) {
  setTimeout("Logout()",interval);
 }
}

jsClock = function(strSep) {
    this.sec = '';
    this.min = '';
    this.hour = '';
    if(strSep != null) {
        this.sep = strSep;
    } else {
        this.sep = ':';
    }
    
    this.timeStr = "";
}

jsClock.prototype.prepareTime = function() {
    var sec, min, hour;
    var time = new Date();
    
    sec = time.getSeconds();
    min = time.getMinutes();
    hour = time.getHours();
    
    if(sec < 10) {
        this.sec = '0' + sec;
    } else {
        this.sec = sec;
    }
    if(min < 10) {
        this.min = '0' + min;
    } else {
        this.min = min;
    }
    if(hour < 10) {
        this.hour = '0' + hour;
    } else {
        this.hour = hour;
    }    
}

jsClock.prototype.prepareTimeString = function() {
    this.timeStr = this.hour + this.sep + this.min + this.sep + this.sec;    
}

jsClock.prototype.getTime = function() {
    this.prepareTime();
    this.prepareTimeString();
    return this.timeStr;
}

function showTime(nId) {
    var time = new jsClock(' : ');
    var oElem = document.getElementById(nId);
    if(oElem == null) {
        return false;
    }
    
    oElem.innerHTML = time.getTime();
}

 function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

function getCursorPosition(e) { 
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}
  


function showSubmenu(nParentId,nOp) {
    var oParent = document.getElementById("id_menu_tdl_" + nParentId);   
    var oSub = document.getElementById("id_submenu_" + nParentId);  
    var x,y;
       
    x = findPosX(oParent); 
    y = findPosY(oParent) + oParent.clientHeight; 
    oSub.style.position='absolute';
    oSub.style.top = y;
    oSub.style.left = x + 1;
    if(nOp == 1 && oSub.className != 'menu-not-active') {
        oSub.style.visibility = 'hidden';  
        oSub.style.display = 'block';
        oSub.style.visibility = 'visible'; 
    } else if(nOp == 0 && oSub.className != 'menu-active') {
        oSub.style.display = 'none';        
    }
}

function setSubmenuPos(nParentId,strClass) {
    var oParent = document.getElementById("id_menu_tdl_" + nParentId);   
    var oSub = document.getElementById("id_submenu_" + nParentId);  
    var x,y;
   
    x = findPosX(oParent); 
    y = findPosY(oParent) + oParent.clientHeight; 
    oSub.style.position='absolute';
    oSub.style.top = y;
    oSub.style.left = x + 1;
}

function changeMenuClassName(nId) {
    oLeft = document.getElementById('id_menu_tdl_' + nId);
    oCenter = document.getElementById('id_menu_tds_' + nId);  
    oRight =  document.getElementById('id_menu_tdr_' + nId);
    
    var strClass = oCenter.className;
    if(strClass.indexOf('pom') != -1) {
        oLeft.className = 'zakladka-l';
        oCenter.className = 'zakladka-s';   
        oRight.className = 'zakladka-p';   
    } else {
        oLeft.className = 'zakladka-l-pom';
        oCenter.className = 'zakladka-s-pom';   
        oRight.className = 'zakladka-p-pom';          
    }
    
}



                            
