var xmlhttp;
var div;

function init() {
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlhttp;
}

function showPlayer() {
    try{
        var popup = window.open('player/audio.php','Sutekh mp3-player', 'width=450,height=300');
        popup.moveTo(210,0);
    }
    catch(e) {
        showAudio();
    }        
}

function showAudio() {
    post("player/audio.php", "nopopup=true");
}

function dropNews(nid, titel) {
    if (confirm("Are you sure you wish to delete: " + titel + "?")) {
        post("body_admin.php", "f=news&a=edit&drop=true&nid=" + nid);
    }
}

function dropPicture(dir, naam) {
    if (confirm("Are you sure you wish to delete " + naam + " from " + dir + "?")) {
        post("body_admin.php", "f=pictures&a=droppic&dir=" + dir + "&file=" + naam);
    }
}

function dropDir(dir) {
    if (confirm("Are you sure you wish to delete the entire folder " + dir + "?\nThis deletes all pictures inside the folder.")) {
        post("body_admin.php", "f=pictures&a=dropdir&dir=" + dir);
    }
}

function notify(text) {
    document.getElementById("jsenable").innerHTML=text;
}

function increaseCounter(part) {
    control("f=increasecounter&part=" + part);
}

function selectFotographer(file) {
    form = document.forms[file];
    dir  = form["dir"].value;
    fotographer = form["fotographer"].value;
    control("f=setfotographer&dir=" + dir + "&file=" + file + "&fotographer=" + fotographer);
}

function control(values) {
    div = document.getElementById("jsenable");
    xmlhttp.open("POST", "control.php", false);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send(values);
}

function post(file, values) {
	div = document.getElementById("body");
	xmlhttp.onreadystatechange=handler;
	xmlhttp.open("POST", file, false);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send(values);
}

function handler() {
	if (xmlhttp.readyState==4 && xmlhttp.status==200) {
	   if (div != null)
		   div.innerHTML = xmlhttp.responseText;
	}
}
