// Topmenu
function change_img(img1,img2) {
  if (document.images) {
    active = new Image ();
    normal = new Image ();
    active.src = '../_images/' + img2 + '.gif';
    normal.src = '../_images/' + img1 + '.gif';
    if (img1 != img2) {
      document.images[img1].src = active.src;
    } else {
      document.images[img1].src = normal.src;
    }
  }
}

// Kalender
function fileupload() {
    document.editform.fileflag.value = 1;
    document.editform.submit();
}
function delbilaga(fil, id, table) {
    if (window.confirm("Radera bilagan?"))
        window.location='../_transaction/delbilaga.php?delkey=' + fil + '&id=' + id + '&table=' + table;
}
function delkalender(id) {
    if (window.confirm("Radera kalendernoteringen?"))
        window.location='../_transaction/delkalender.php?id=' + id;
}
function autofyll(dat, rad) {
	document.editform.elements[rad].value = document.editform.elements[dat].value;
}
function delbokning(id, time_from) {
    if (window.confirm("Radera bokningen?"))
        window.location='../_transaction/delbokning.php?id=' + id + '&time_from=' + time_from;
}
// Aktuellt
function delaktuellt(id) {
    if (window.confirm("Radera dokumentet?"))
        window.location='../_transaction/delaktuellt.php?id=' + id;
}


// edituser
function check_uname(unames) {
    this_uname = document.edituser.uname.value;
    if (unames.search(this_uname) != -1) {
        alert("Användarnamnet '" + this_uname + "' finns redan!");
    } else {
        document.edituser.submit();
    }
}
function generate_passwd() {
    var generated = "";
    for (var i = 0; i < 3; i++) {
		randchar = String.fromCharCode(Math.ceil(25*Math.random())+97);
        randnum = Math.ceil(9*Math.random());
		generated = generated + randchar + randnum;
	}
    document.edituser.passwd.value = generated;
}

function foresla_uname(lchars, fchars, unames) {
    if (document.edituser.fname.value.length > 1 && document.edituser.lname.value.length > 1) {
        suggestuname = document.edituser.fname.value.substr(0,fchars) + document.edituser.lname.value.substr(0,lchars);
        suggestuname = suggestuname.replace(/å/gi, "a");
        suggestuname = suggestuname.replace(/ä/gi, "a");
        suggestuname = suggestuname.replace(/ö/gi, "o");
		suggestuname = suggestuname.replace(/ü/gi, "u");
		suggestuname = suggestuname.replace(/é/gi, "e");
        suggestuname = suggestuname.toLowerCase();
        if (unames.search(suggestuname) != -1) {
            lchars--;
            fchars++;
            foresla_uname(lchars, fchars, unames);
        } else {
            document.edituser.uname.value = suggestuname.toLowerCase();
        }

    } else {
        window.alert("Användarnamnet genereras av förnamnet och efternamnet.\n Fyll i dessa först.");
    }

}

// Skickamail
function select_all() {
    document.skickamail.elements["sty"].checked = 'true';
    document.skickamail.elements["raati"].checked = 'true';
    document.skickamail.elements["t1"].checked = 'true';
    document.skickamail.elements["t2"].checked = 'true';
    document.skickamail.elements["b1"].checked = 'true';
    document.skickamail.elements["b2"].checked = 'true';
}

// Links
function dellink(id) {
    if (window.confirm("Radera länken?"))
        window.location='../_transaction/dellink.php?id=' + id;
}

// Uppdrag
function deluppdrag(id) {
    if (window.confirm("Radera uppdraget?"))
        window.location='../_transaction/deluppdrag.php?id=' + id;
}
// Anslag
function delanslag(id) {
    if (window.confirm("Radera anslaget?"))
        window.location='../_transaction/delanslag.php?id=' + id;
}

// Uppdragstyp
function deluppdragstyp(id) {
    if (window.confirm("Radera typen?"))
        window.location='../_transaction/deluppdragstyp.php?id=' + id;
}

// Bilder
function delbild(id, cur_album) {
    if (window.confirm("Radera bild?"))
        window.location='../_transaction/uploadpic_action.php?del=' + id + '&cur_album=' + cur_album;
}
function delalbum(id, cur_album) {
    if (window.confirm("Radera albumet och alla bilderna i det?"))
        window.location='../_transaction/delalbum.php?del=' + id;
}
// Audio
function delskiva(id) {
    if (window.confirm("Radera skivan och alla låtarna?"))
        window.location='../_transaction/delskiva.php?del=' + id;
}
function deltrack(id, nummer, skiva) {
    if (window.confirm("Radera spår " + nummer + "?"))
        window.location='../_transaction/deltrack.php?del=' + id + '&nummer=' +nummer + '&skiva=' +skiva;
}
// Skriv ut
function skrivut(var1, var2, value1, value2) {
	window.open("../_templates/printbase.php?" + var1 + "=" + value1 + "&" + var2 + "=" + value2);
}