﻿/* www.eikonsite.it */

function es_GetInt(str, defaultval) {
    try {
        var val = parseInt(str);
        if (isNaN(val)) return defaultval;
        return val;
    }
    catch (ex) {
        alert(ex);
        return defaultval;
    }
}
function getObjAPI(name) {
    if (document.getElementById) { // For Level 1 DOM (Netscape 6, Explorer 5)
        return document.getElementById(name);
    }
    else if (document.all) { // For IE4 DOM
        return document.all[name];
    }
    else if (document.layers) { // For NS4 DOM
        var obj = getObjNN4API(document, name);
        obj.style = obj;
        return obj;
    }
    return null;
}

function getObjNN4API(obj, name) {
    var x = obj.layers;
    var foundLayer;
    for (i = 0; i < x.length; i++) {
        if (x[i].id == name)
            foundLayer = x[i];
        else if (x[i].layers.length)
            var tmp = getObjNN4(x[i], name);
        if (tmp) foundLayer = tmp;
    }
    return foundLayer;
}
function es_GetObj(objid) {
    return getObjAPI(objid);
}

var lastopenmenuid = 0;
var lastopenmenutimeout = -1;

function GetMenu(menuid) {
    return (menuid > 10) ? menuid / 10 : menuid
}

function openM(menuid) {
    if (lastopenmenutimeout >= 0) {
        clearTimeout(lastopenmenutimeout);
        lastopenmenutimeout = -1;
    }

    if (lastopenmenuid != 0) {
        if (lastopenmenuid == menuid) {
            closeM(lastopenmenuid);
            lastopenmenuid = 0;
        }
        else {
            closeM(lastopenmenuid);
            lastopenmenuid = 0;
        }
    }

    var obj = es_GetObj("menuiconedivinner" + GetMenu(menuid));
    if (obj != null) {
        if (obj.style.display == "none") {
            lastopenmenuid = menuid;
            obj.style.display = "";
            var iobj = es_GetObj("menuicoimg" + GetMenu(menuid));
            if (iobj != null)
                iobj.src = "img/menuico" + menuid + "_on.png";
        }
    }
}

function openCloseM(menuid) {
    if (lastopenmenutimeout >= 0) {
        clearTimeout(lastopenmenutimeout);
        lastopenmenutimeout = -1;
    }
    
    if (lastopenmenuid != 0) {
        if (lastopenmenuid == menuid) {
            closeM(lastopenmenuid);
            lastopenmenuid = 0;
            return;
        }
        else {
            closeM(lastopenmenuid);
            lastopenmenuid = 0;
        }
    }

    var obj = es_GetObj("menuiconedivinner" + GetMenu(menuid));
    if (obj != null) {
        if (obj.style.display == "none") {
            lastopenmenuid = menuid;
            obj.style.display = "";
            var iobj = es_GetObj("menuicoimg" + GetMenu(menuid));
            if (iobj != null)
                iobj.src = "img/menuico" + menuid + "_on.png";
        }
        else {
            lastopenmenuid = 0;
            obj.style.display = "none";
            var iobj = es_GetObj("menuicoimg" + GetMenu(menuid));
            if (iobj != null)
                iobj.src = "img/menuico" + menuid + ".png";
        }
    }
}

function closeM(menuid) {
    if (lastopenmenutimeout >= 0) {
        clearTimeout(lastopenmenutimeout);
        lastopenmenutimeout = -1;
    }

    var obj = es_GetObj("menuiconedivinner" + GetMenu(menuid));
    if (obj != null) {
        obj.style.display = "none";
        var iobj = es_GetObj("menuicoimg" + GetMenu(menuid));
        if (iobj != null)
            iobj.src = "img/menuico" + menuid + ".png";
    }
}

function closeEventM(menuid) {
    if (lastopenmenutimeout >= 0) {
        clearTimeout(lastopenmenutimeout);
        lastopenmenutimeout = -1;
    }

    lastopenmenutimeout = setTimeout("closeM(" + menuid + ")", 500);
}

var objSel = null;
function menuSelected(objid) {
    var obj = es_GetObj(objid);
    if (obj != null) {
        objSel = obj;
        menuAdminOver(objSel);
    }
}
function menuAdminOver(obj) {
    obj.className = "menubut_sel";
}

function menuAdminOut(obj) {
    if (objSel != null && objSel.id == obj.id) return;
    obj.className = "menubut";
}

var LngPage = "it";
var LngList = new Array();
function LngRegister(objid) {
    var obj = es_GetObj(objid);
    if (obj != null)
        LngList.push(obj);
}
function LngRefresh(obj) {
    if (obj.id.indexOf(LngPage, 0) == 0) {
        obj.style.display = '';
    }
    else {
        obj.style.display = 'none';
    }
}
function LngSet(keyl) {
    LngElemUnselect(LngPage);
    LngPage = keyl;
    for (var i = 0; i < LngList.length; i++) {
        var obj = LngList[i];
        LngRefresh(obj);
    }
    LngElemSelect(LngPage);
}
function LngElemUnselect(keyl) {
    if (LngList.length == 0) return;
    var oj = es_GetObj('tdlng_' + keyl);
    if (oj != null) {
        oj.style.fontWeight = 'normal';
    }
}
function LngElemSelect(keyl) {
    if (LngList.length == 0) return;
    var oj = es_GetObj('tdlng_' + keyl);
    if (oj != null) {
        oj.style.fontWeight = 'bold';
    }
}
function updatecar(cprod) {
    var obj = es_GetObj('qt_' + cprod);
    if (obj != null) {
        var value = es_GetInt(obj.value);
        if (value > 0)
            window.top.location.href = 'car.aspx?set=' + value + '&cprod=' + cprod;
        else
            window.top.location.href = 'car.aspx?del=1&cprod=' + cprod;
    }
}
var prodshow_obj_item = null;
var prodshow_obj_selected = null;
function prodshow(item, objid) {
    var obj = es_GetObj(objid);

    if (obj != null) {

        if (prodshow_obj_item != null) {
            prodshow_obj_item.className = '';
        }
        if (prodshow_obj_selected != null) {
            prodshow_obj_selected.style.display = 'none';
        }
        prodshow_obj_item = item;
        prodshow_obj_item.className = 'selected';
        prodshow_obj_selected = obj;
        prodshow_obj_selected.style.display = '';
    }
}
var VetCurIndex = -1;
var VetMaxIndex = 0;
function VetrinaClickSx() {
    if (VetCurIndex > 0) {
        VetrinaHide(VetCurIndex);
        VetCurIndex--;
        VetrinaShow(VetCurIndex);
    }
}
function VetrinaClickDx() {
    if (VetCurIndex < VetMaxIndex) {
        VetrinaHide(VetCurIndex);
        VetCurIndex++;
        VetrinaShow(VetCurIndex);
    }
}
function VetrinaHide(index) {
    var obj = es_GetObj("vetrina_page_" + index);
    if (obj != null)
        obj.style.display = "none";
}
function VetrinaShow(index) {
    var obj = es_GetObj("vetrina_page_" + index);
        if (obj != null)
        obj.style.display = "";
}
