﻿var checkBrowser = document.appendChild
&& navigator.userAgent.toLowerCase().indexOf("opera") == -1
&& navigator.userAgent.toLowerCase().indexOf("netscape") == -1
&& navigator.userAgent.toLowerCase().indexOf("msie") == -1
&& navigator.userAgent.toLowerCase().indexOf("chrome") == -1
&& navigator.userAgent.toLowerCase().indexOf("firefox") == -1
&& navigator.userAgent.toLowerCase().indexOf("omniweb") == -1
&& navigator.userAgent.toLowerCase().indexOf("apple") == -1
&& navigator.userAgent.toLowerCase().indexOf("msie") == -1
&& navigator.userAgent.toLowerCase().indexOf("icab") == -1
&& navigator.userAgent.toLowerCase().indexOf("kde") == -1
&& navigator.userAgent.toLowerCase().indexOf("camino") == -1
&& navigator.userAgent.toLowerCase().indexOf("gecko") == -1;

function SetElementDisplay(cont_ID, Display, cont_ID2, Display2) {
    if (Display == "true") {
        document.getElementById(cont_ID).style.display = "block";
    }
    else {
        document.getElementById(cont_ID).style.display = "none";
    }
    if (Display2 == "true") {
        document.getElementById(cont_ID2).style.display = "block";
    }
    else {
        document.getElementById(cont_ID2).style.display = "none";
    }
}

function OpenNewWindow(p_url) {
    window.open(p_url, '', config = 'toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no')
    return false;
}

function OpenFullScreenWindow(p_url) {
    window.open(p_url, '', config = 'toolbar=yes, menubar=yes, fullscreen=yes, scrollbars=yes, resizable=yes, location=no, directories=no, status=no')
    return false;
}

function OpenSizeWindow(p_url, Width, Height) {
    window.open(p_url, '', config = 'toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no, width=' + Width + ', height=' + Height)
    return false;
}

function ShowPopUp(p_url) {
    javascript: window.open(p_url);
}

function ValidateAttachment(oSrc, args) {
    args.IsValid = (oSrc.length > 0);
}

function CategoriesCheck(CategoriesSearchCheckBox1, CategoriesSearchCheckBox2, CategoriesSearchTR) {
    document.getElementById(CategoriesSearchCheckBox2).checked = document.getElementById(CategoriesSearchCheckBox1).checked;
    if (document.getElementById(CategoriesSearchCheckBox1).checked == true) {
        document.getElementById(CategoriesSearchTR).className = 'acr_sel';
    }
    else {
        document.getElementById(CategoriesSearchTR).className = 'acr_off';
    }
}

function CompaniesCheck(CompaniesSearchCheckBox1, CompaniesSearchCheckBox2, CompaniesSearchTR) {
    document.getElementById(CompaniesSearchCheckBox2).checked = document.getElementById(CompaniesSearchCheckBox1).checked;
    if (document.getElementById(CompaniesSearchCheckBox1).checked == true) {
        document.getElementById(CompaniesSearchTR).className = 'acr_sel';
    }
    else {
        document.getElementById(CompaniesSearchTR).className = 'acr_off';
    }
}

function CSTRMouseOver(CategoriesSearchTR) {
    if (document.getElementById(CategoriesSearchTR).className != 'acr_sel') {
        document.getElementById(CategoriesSearchTR).className = 'acr_on';
    }
}

function CSTRMouseOut(CategoriesSearchTR) {
    if (document.getElementById(CategoriesSearchTR).className != 'acr_sel') {
        document.getElementById(CategoriesSearchTR).className = 'acr_off';
    }
}

function ShowAdvertPanel(lnkID, classon, classof) {
    if (document.getElementById('paketRL' + lnkID).className == 'knof on') {
        document.getElementById('paketRL' + lnkID).className = 'knof';
        document.getElementById('paketDRL' + lnkID).className = 'podrobnost';
        document.getElementById('paketTRL' + lnkID).className = 'knofl';
    }
    else {
        document.getElementById('paketRL' + lnkID).className = 'knof on';
        document.getElementById('paketDRL' + lnkID).className = 'podrobnost on';
        document.getElementById('paketTRL' + lnkID).className = 'knofb';
    }
}

function ShowAdvertPanelS(lnkID, classon, classof) {
    if (document.getElementById('paketSL' + lnkID).className == 'knof on') {
        document.getElementById('paketSL' + lnkID).className = 'knof';
        document.getElementById('paketDSL' + lnkID).className = 'podrobnost';
        document.getElementById('paketTSL' + lnkID).className = 'knofl';
    }
    else {
        document.getElementById('paketSL' + lnkID).className = 'knof on';
        document.getElementById('paketDSL' + lnkID).className = 'podrobnost on';
        document.getElementById('paketTSL' + lnkID).className = 'knofb';
    }
}

function toggle(id) {
    if (document.getElementById(id)) {
        var el = document.getElementById(id);
        el.style.display = (el.style.display == 'none') ? 'block' : 'none';
        var lnk_el = document.getElementById('lnk_' + id);
        lnk_el.className = (lnk_el.className == 'toggle_title') ? 'tt_alt' : 'toggle_title';
    }
}

function ShowElement(con_id) {
    if (document.getElementById(con_id)) {
        if (document.getElementById(con_id).style.display == 'block' || document.getElementById(con_id).style.display == '') {
            document.getElementById(con_id).style.display = 'none';
        }
        else {
            document.getElementById(con_id).style.display = 'block';
        }
    }
}

function HideElement(con_id) {
    if (document.getElementById(con_id)) {
        document.getElementById(con_id).style.display = 'none';
    }
}

function RedirectPage(url) {
    document.location.href = url;
}

function PopUpOn(con_id) {
    if (document.getElementById(con_id)) {
        document.getElementById(con_id).style.display = 'block';
        document.getElementById(con_id).style.visibility = 'visible';
    }
}

function PopUpOff(con_id) {
    if (document.getElementById(con_id)) {
        document.getElementById(con_id).style.display = 'none';
        document.getElementById(con_id).style.visibility = 'hidden';
    }
}

function PopUpOnMouseOut(element, event, con_id) {
    var current_mouse_target = null;
    if (event.toElement) {
        current_mouse_target = event.toElement;
    } else if (event.relatedTarget) {
        current_mouse_target = event.relatedTarget;
    }
    if (!Ischild(element, current_mouse_target) && element != current_mouse_target) {
        fadeOut(con_id);
    }
}

function Ischild(parent, child) {
    if (child != null) {
        while (child.parentNode) {
            if ((child = child.parentNode) == parent) {
                return true;
            }
        }
    }
    return false;
}

function fadeOut(con_id) {
    if (document.getElementById(con_id)) {
        oDiv = document.getElementById(con_id);
        oDiv.style.filter = "blendTrans(duration=1)";
        if (oDiv.filters != null) {
            // Make sure the filter is not playing.
            if (oDiv.filters.blendTrans.status != 1) {
                oDiv.filters.blendTrans.apply();
                oDiv.style.visibility = 'hidden';
                oDiv.filters.blendTrans.play();
            }
        }
        else {
            setTimeout("ElementVisibilityHidden('" + con_id + "')", 500);
        }
    }
}

function ElementVisibilityHidden(con_id) {
    if (document.getElementById(con_id)) {
        document.getElementById(con_id).style.visibility = 'hidden';
    }
}

function ChechMaxLength(txtbox, MaxLength) {
    if (txtbox.value.length > MaxLength) {
        txtbox.value = txtbox.value.substring(0, MaxLength);
    }
}

function PosljiPosto(StringWEB) {
    eval(unescape(StringWEB));
}

function resizeMe(obj) {
    if (obj) {
        obj.style.height = (obj.contentWindow.document.body.scrollHeight - 1) + "px";
    }
}

function pageLoad(sender, args) {
    if (args.get_isPartialLoad()) {
        if (typeof (fb) != "undefined") {
            if (fb != null) {
                fb.anchors.length = 0;
                fdiv = document.getElementById('FLOATBOXDIV');
                if (fdiv != null) {
                    fb.tagAnchors(fdiv);
                }
                fdiv2 = document.getElementById('FLOATBOXDIV2');
                if (fdiv2 != null) {
                    fb.tagAnchors(fdiv2);
                }
                fdiv3 = document.getElementById('FLOATBOXDIV3');
                if (fdiv3 != null) {
                    fb.tagAnchors(fdiv3);
                }

            }
        }
    }
}

function RedirectParentURL(ic_href) {
    if (window.parent)
    { window.parent.location.href = ic_href; }
    else
    { window.location.href = ic_href; }
}

function RedirectURL(ic_href) {
    window.location.href = ic_href;
}

function ReloadParentURL() {
    if (window.parent)
    { window.parent.location.reload(); }
    else
    { window.location.reload(); }
}

function ResizeFloatBox(w, h) {
    if (window.parent && window.parent.fb)
    { window.parent.fb.resize(w, h); }
}

function AutoCloseFloatBox() {
    if (window.parent && window.parent.fb)
    { setTimeout('fb.end()', 3000) }
}

function AutoCloseFloatBoxReloadParent() {
    if (window.parent && window.parent.fb)
    { setTimeout('fb.end(); ReloadParentURL();', 3000) }
}

function HideWT(wtdiv, contr) {
    if (document.getElementById(contr + '_WTM')) {
        document.getElementById(contr + '_WTM').style.display = 'none';
    }
    if (document.getElementById(contr + '_WTT')) {
        document.getElementById(contr + '_WTT').style.display = 'none';
    }
    if (document.getElementById(contr + '_WTW')) {
        document.getElementById(contr + '_WTW').style.display = 'none';
    }
    if (document.getElementById(contr + '_WTTH')) {
        document.getElementById(contr + '_WTTH').style.display = 'none';
    }
    if (document.getElementById(contr + '_WTF')) {
        document.getElementById(contr + '_WTF').style.display = 'none';
    }
    if (document.getElementById(contr + '_WTSA')) {
        document.getElementById(contr + '_WTSA').style.display = 'none';
    }
    if (document.getElementById(contr + '_WTSU')) {
        document.getElementById(contr + '_WTSU').style.display = 'none';
    }
    if (document.getElementById(contr + '_' + wtdiv)) {
        document.getElementById(contr + '_' + wtdiv).style.display = 'block';
    }
}

function setHomepage(_url) {
    if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage(_url);
    }
}

function ClearVal(_obj, val) {
    if (_obj) {
        if (_obj.value == val) {
            _obj.value = '';
        }
    }
}
function SetVal(_obj, val) {
    if (_obj) {
        if (_obj.value == '') {
            _obj.value = val;
        }
    }
}

function urlencode(val) {
    return escape(val);
}

function urldecode(val) {
    return unescape(val)
}

function ChangeRatingImage(_img, _val) {
    var image = document.getElementById(_img);
    image.src = GeneralLink + "css/img/ocene/" + _val + ".gif";
};

function ChangeOfferImage(_img, _val) {
    var image = document.getElementById(_img);
    if (_val == '21') {
        image.src = GeneralLink + "css/img/ikone/oddaj_povprasevanje.png";
    }
    else {
        image.src = GeneralLink + "css/img/ikone/oddaj_povprasevanje_zaupno.png";
    }
};

function SetDate(_cmbYears, _cmbMonth, _cmbDates, _txtDate) {
    var txtDate = document.getElementById(_txtDate);
    txtDate.value = document.getElementById(_cmbDates).value + '.' + document.getElementById(_cmbMonth).value + '.' + document.getElementById(_cmbYears).value;
}

function ShowPackage(con_id, con_id2) {
    if (document.getElementById(con_id) && document.getElementById(con_id2)) {
        if (document.getElementById(con_id2).value == "184") {
            document.getElementById(con_id).style.display = 'none';
        }
        else {
            document.getElementById(con_id).style.display = 'block';
        }
    }
}

function CalculatePrice(con_idP, con_idB, con_idN, t) {
    obj_idP = document.getElementById(con_idP);
    obj_idB = document.getElementById(con_idB);
    obj_idN = document.getElementById(con_idN);

    val_idP = obj_idP.value.replace(",", ".");
    val_idB = obj_idB.value.replace(",", ".");
    val_idN = obj_idN.value.replace(",", ".");

    switch (t) {
        case 3:
            if (obj_idB && !isNaN(val_idB) && obj_idN && !isNaN(val_idN) && (parseFloat(val_idB) >= parseFloat(val_idN))) {
                _popust = ((parseFloat(val_idB) - parseFloat(val_idN)) / parseFloat(val_idB) * 100).toFixed(2).replace(".", ",");
                if (parseFloat(_popust) == 100 && (parseFloat(val_idN)) != parseFloat(val_idB)) {
                    obj_idP.value = "99";
                }
                else { obj_idP.value = _popust; }
            }
            else {
                obj_idP.value = "";
            }
            break;
        default:
            if (obj_idP && !isNaN(val_idP) && val_idP.trim() != "" && obj_idB && !isNaN(val_idB) && val_idB.trim() != "") {
                if (parseFloat(val_idP) > 100) { val_idP = 100; obj_idP.value = 100; };
                if (parseFloat(val_idP) < 0) { val_idP = 0; obj_idP.value = 0; };
                obj_idN.value = (parseFloat(val_idB) - parseFloat(val_idB) * parseFloat(val_idP) / 100).toFixed(2).replace(".", ",");
            }
            else {
                obj_idN.value = "";
            }
            break;
    }
}

function ChangeOfferMedij(o, b, p, _val) {
    if (_val == 0) {
        document.getElementById(o).style.display = 'none';
        document.getElementById(b).style.display = 'none';
        document.getElementById(p).style.display = 'none';
    }
    else if (_val == 1) {
        document.getElementById(o).style.display = 'block';
        document.getElementById(b).style.display = 'block';
        document.getElementById(p).style.display = 'none';
    }
    else {
        document.getElementById(o).style.display = 'none';
        document.getElementById(b).style.display = 'none';
        document.getElementById(p).style.display = 'block';
    }
}

function readCookie(name) {
    var cookieValue = "";
    var search = name + "=";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            cookieValue = unescape(document.cookie.substring(offset, end))
        }
    }
    return cookieValue;
}
