function get_value(id, def) {
    var elem = document.getElementById(id);
    return (elem != null ? elem.value : def);
}
function hide(id) {
    document.getElementById(id).style.display = "none";
}
function hide_progress(hideObject, showObject) {
    show(hideObject);
    hide(showObject);
}
function popup_window(url) {
    window.open(url);
}
function replaceQueryString(url, param, value) {
    var re = new RegExp("([?|&])" + param + "=.*?(&|$)", "i");
    if (url.match(re))
        return url.replace(re, '$1' + param + "=" + value + '$2');
    else if (url.indexOf("?") == -1)
        return url + '?' + param + "=" + value;
    else
        return url + '&' + param + "=" + value;
}
function set_check(id, state) {
    var elem = document.getElementById(id);
    if (elem) elem.checked = state;
}

function set_selected(id, state) {
    var elem = document.getElementById(id);
    for (var i = 0; i < elem.length; i++) {
        if (elem[i].value == state) {
            elem[i].selected = true;
        }
    }    
}
function show(id) {
    document.getElementById(id).style.display = "";
}
function show_progress(hideObject, showObject) {
    hide(hideObject);
    show(showObject);
}
function yt_alert(title,msg) {
    var win = Ext.MessageBox.alert(title, msg);
    var dlg = win.getDialog();
    dlg.hide();
    win.minWidth = 300;
    win.maxWidth = 600;
    win.setIcon(Ext.MessageBox.ERROR);
    dlg.show();
}
function yt_confirm(title, msg, fn) {
    var win = Ext.Msg.confirm(title, msg, fn);
    var dlg = win.getDialog();
    dlg.hide();
    win.minWidth = 300;
    win.maxWidth = 600;
    win.setIcon(Ext.MessageBox.QUESTION);
    dlg.show();
}

function step_by_step_guide_popup() {
    var win = Ext.getCmp("popup_stepbystep_window");
    if (typeof (win) == "undefined") {
        var popup = document.createElement("DIV");
        document.body.appendChild(popup);
        popup.id = "stepbystep-popup";
        popup.className = "x-hidden";
        popup.innerHTML = "";
        win = new Ext.Window({
            autoHeight: true,
            applyTo: 'stepbystep-popup',
            closeAction: 'hide',
            id: 'popup_stepbystep_window',
            autoLoad: yt_WebRootPath + '/secure/help/stepbystep.rails',            
            plain: false,
            resizable: false,
            y:180,
            width:295
        });
    }
    win.show();
}

function show_step_by_step_step(idToShow, idToHide) {
    show('stepByStep' + idToShow);
    hide('stepByStep' + idToHide);
}