﻿function swapBtn(hdnf, ctrlName, path) {
    var ctrl = document.getElementById(ctrlName);
    var hdnfc = document.getElementById(hdnf);
    if (ctrl.src.indexOf('btnIWO.png') > 0) {
        hdnfc.value = hdnfc.value + "|" + ctrlName.substring(ctrlName.indexOf("prdID_") + 7);
        ctrl.src = path + '/btnIWO2.png';
    }
    else {
        hdnfc.value = hdnfc.value.replace("|" + ctrlName.substring(ctrlName.indexOf("prdID_") + 7),"");
        ctrl.src = path + '/btnIWO.png';
    }
}
function swapMnu(m, ctrl, ctrlLink) {
    if (m == 'over') {
        ctrl.className='tmla tmla2';
        document.getElementById(ctrlLink).className = 'tmlb tmlbo';
    } else {
        ctrl.className = 'tmla';
        document.getElementById(ctrlLink).className='tmlb';
    }
}
function setFocus(ctrl, caption) {
    if (ctrl.value == caption)
        ctrl.value = "";
}
function setBlur(ctrl, caption) {
    if (ctrl.value == "")
        ctrl.value = caption;
}

function escapeHTML(str) {
    var div = document.createElement('div');
    var text = document.createTextNode(str);
    div.appendChild(text);
    return div.innerHTML;
}

function syncTextarea() { //tidy up before we go back to the server
    $('.inputEditor').each(function(index) {
        $(this).val(escapeHTML($(this).val()));
    });
}

function ResetScrollPosition() {
    setTimeout("window.scrollTo(0,0)", 0);
}

function badFixSelectBoxDataWidthIE() {
    if ($.browser.msie) {
        $('select').each(function() {
            if ($(this).attr('multiple') == false) {
                $(this).mousedown(function() {
                    if ($(this).css("width") != "auto") {
                        var width = $(this).width();
                        $(this).data("origWidth", $(this).css("width")).css("width", "auto");

                        // If the width is now less than before then undo
                        if ($(this).width() < width) {
                            $(this).unbind('mousedown');
                            $(this).css("width", $(this).data("origWidth"));
                        }
                    }
                })

                // Handle blur if the user does not change the value
                .blur(function() {
                    $(this).css("width", $(this).data("origWidth"));
                })

                // Handle change of the user does change the value
                .change(function() {
                    $(this).css("width", $(this).data("origWidth"));
                });
            }
        });
    }
}

