// To status frame und dann refresh der seite
function tostatus(url, num) {
    myoldurl = location.href;
    location.href = url;
}

// Redirect
function redirect(url, wait, par) {
    if(! wait) {
        wait = 0.1;
    }
    if(par) {
        window.setTimeout(par + '.location.href = "' + url + '"', wait * 1000);
    } else {
        window.setTimeout('location.href = "' + url + '"', wait * 1000);
    }
}

// Program choose
function di(wert, url) {
    location.href = url + wert;
}

// Question bevor delete
function sure(text, url, id) {
    id = (id) ? id : '';
    if(confirm(text)) {
        location.href = url + id;
    }
}

function Delete(question,warn,cmd,form) {
// test on checked Boxes
    ok = new Array;
    txt = new Array;
    x = 0;
    for(var i=0;i<form.length;++i) {
        var id;
        if(form.elements[i].type == 'checkbox' && form.elements[i].checked) {
            id = form.elements[i].value;
            ok.push(id);
            txt.push(form.elements[i].name);
            form.elements[i].checked = 0;
            x += 1;
        }
    }
    if(x > 0) {
        if(confirm(question + '\n' + txt.join("\n"))) {
            tostatus('?cmd=' + cmd + '&data=' + ok.join('_'));
        }
    } else {
        alert(warn);
    }
}

function Toggle(warn,form) {
// test on checked Boxes
    ok = new Array;
    txt = new Array;
    x = 0;
    for(var i=0;i<form.length;++i) {
        var id;
        if(form.elements[i].type == 'checkbox' && form.elements[i].checked) {
            id = form.elements[i].value;
            ok.push(id);
            txt.push(form.elements[i].name);
            form.elements[i].checked = 0;
            x += 1;
        }
    }
    if(x > 0) {
        tostatus('?cmd=ttoggle&data=' + ok.join('_'));
    } else {
        alert(warn);
    }
}

function selAll(form, type) {
// check all Boxes
    for(var i=0;i<form.length;++i) {
        if(form.elements[i].type == 'checkbox') {
            form.elements[i].checked = type;
        }
    }
}

function selSwitch(form, search) {
// switch Boxes with search in name on or off
    for(var i=0;i<form.length;++i) {
        if(form.elements[i].type == 'checkbox' && form.elements[i].name == search) {
            if(form.elements[i].checked) {
                form.elements[i].checked = 0;
            } else {
                form.elements[i].checked = 1;
            }
        }
    }
}

function reverse(form) {
// check all Boxes
    for(var i=0;i<form.length;++i) {
        if(form.elements[i].type == 'checkbox') {
            if(form.elements[i].checked) {
                form.elements[i].checked = 0;
            } else {
                form.elements[i].checked = 1;
            }
        }
    }
}

function Play(warnmsg,form) {
// test on checked Boxes
    ok = new Array;
    x = 0;
    for(var i=0;i<form.length;++i) {
        var id;
        if(form.elements[i].type == 'checkbox' && form.elements[i].checked) {
            id = form.elements[i].value;
            ok.push(id);
            x += 1;
        }
    }
    if(x > 0) {
          location.href = '?cmd=mplaylist&data=' + ok.join('_');
//        F1 = window.open('?cmd=mplay&data=' + ok.join('_'),"Mediaplay","width=250,height=210,left=0,top=0");
    } else {
        alert(warnmsg);
    }
}
