
function getURL(){
	return Left(location.href,location.href.lastIndexOf("/")+1);
}

function Left(str, n){
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
		return String(str).substring(0,n);
}
function showhof() {
bajax('hof','pbox','');
}
function iconspeichern() {
        	var author = "author=" + encodeURIComponent(document.getElementById("author").value);
	var title = "title=" + encodeURIComponent(document.getElementById("title").value);
	var hd = "hd=" + encodeURIComponent(document.getElementById("hd").value);
	var param = "action=add&" + author + "&" + title + "&" + hd;
         bajax("hof","pbox",param,'iconspeichern_2()');
}
function iconspeichern_2() {
document.getElementById("title").value = "Wie heißt dein Pictu?";
document.getElementById("formbox").style.visibility = "hidden";
}
function commentspeichern() {
        	var author = "c_author_field=" + encodeURIComponent(document.getElementById("c_author_field").value);
	var text = "c_text_field=" + encodeURIComponent(document.getElementById("c_text_field").value);
	var n = "c_n=" + encodeURIComponent(document.getElementById("c_n").value);
	var c_n = encodeURIComponent(document.getElementById("c_n").value);
	document.getElementById("commentbox").innerHTML = "<img src='grfx/matsupictu/loading20.gif' alt='lädt...'>";
	var param = "action=comment&" + author + "&" + text + "&" + n;
         bajax("comments","commentbox",param,"commentspeichern_2(" + c_n + ")");

}
function commentspeichern_2(c_n) {
showcomments(c_n);
showhof();
}

function showcomments(n) {
var param = "n=" + n;
bajax('comments','commentbox',param,'');
}

function bajax(inner,outer,param,conti) {
	changed = false;
	//erstellen des requests
	var req=null;
	try{
		req=new XMLHttpRequest();
	}
	catch(ms){
		try{
			req=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(nonms){
		try{
			req=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(failed){
			req=null;
			}
		}
	}
	if(req==null) alert("Error creating request object!");


	//anfrage erstellen (GET,urlistlocalhost,
	//request ist asynchron

	req.open("POST", getURL() + inner + ".php", true);
	//Beim abschliessen des request wird diese Funktion ausgeführt

	req.onreadystatechange=function(){
		switch(req.readyState){
			case 4:
				if(req.status!=200){
					alert("Fehler:"+req.status);
				}else{
					document.getElementById(outer).innerHTML = req.responseText;

				}
				break;
			default:
				return false;
				break;
		}
		return false;
	};
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", param.length);
	req.setRequestHeader("Connection", "close");
	// make the server request
	req.send(param);
	eval(conti);
}