function trim(str) {
	return str.replace(/^\s+|\s+$/g, '');
}

function getCalendar(type,timestamp) {
	if (type=="sidebar")
		update ="sidebar3Calendar";
	else
		update ="cont";
		
	new Ajax.Updater(
		update,
		"scripts/ajax.php",
		{
			parameters: "act=calendar&type="+type+"&timestamp="+timestamp
		}
	);
}

function search(query) {
	$("sidebar3NewssearchButton").hide();
	$("sidebar3NewssearchLoader").style.display ="inline";
	$("sidebar3NewssearchResults").innerHTML ="";
	new Ajax.Updater(
		"sidebar3NewssearchResults",
		"scripts/ajax.php",
		{
			parameters: "act=search&query="+query,
			onComplete: function() {
				$("sidebar3NewssearchLoader").hide();
				$("sidebar3NewssearchButton").style.display ="inline";
			}
		}
	);
}

function commentsWrite(id,page,email,author,cont,table) {
	$("commentAddMail").className ="text";
	$("commentAddName").className ="text";
	$("commentAddText").className ="";
	new Ajax.Request(
		"scripts/ajax.php", {
			method: "post",
			parameters: "act=commentsWrite&id="+id+"&page="+page+"&email="+email+"&author="+author+"&cont="+trim(cont)+"&table="+table,
			onFailure: function(txt) {
				resp =txt.responseXML;
				mail =resp.getElementsByTagName("mail").item(0).firstChild.nodeValue;
				author =resp.getElementsByTagName("author").item(0).firstChild.nodeValue;
				content =resp.getElementsByTagName("content").item(0).firstChild.nodeValue;
				
				if (mail=="1")
					$("commentAddMail").className ="error";
				if (author=="1")
					$("commentAddName").className ="error";
				if (content=="1")
					$("commentAddText").className ="error";
			},
			onSuccess: function(txt) {
				$("comments").innerHTML =txt.responseText;
				$("commentAddMail").value ="";
				$("commentAddName").value ="";
				$("commentAddText").value ="";
			}
		}
	);
}

function photosShow(gallery,pic) {
	$("photo").src ="img/ic_WloaderArrows.gif";
	
	new Ajax.Updater(
		"cont",
		"scripts/ajax.php", {
			method: "post",
			parameters: "act=photosShow&gallery="+gallery+"&pic="+pic
		}
	);
}

function contactSend() {
	$("contact").hide();
	$("indicator").show();
	
	id =$F("contactTo");
	mail =$F("contactMail");
	name =$F("contactName");
	subj =$F("contactSubject");
	text =$F("contactText");
	
	$("contactMail").className ="text";
	$("contactName").className ="text";
	$("contactSubject").className ="text";
	$("contactText").className ="";
	new Ajax.Request(
		"scripts/ajax.php", {
			method: "post",
			parameters: "act=contactSend&id="+id+"&mail="+mail+"&name="+name+"&subject="+subj+"&text="+trim(text),
			onFailure: function(txt) {
				$("contact").show();
				$("indicator").hide();
				resp =txt.responseXML;
				mail =resp.getElementsByTagName("mail").item(0).firstChild.nodeValue;
				name =resp.getElementsByTagName("name").item(0).firstChild.nodeValue;
				subject =resp.getElementsByTagName("subject").item(0).firstChild.nodeValue;
				text =resp.getElementsByTagName("text").item(0).firstChild.nodeValue;
				
				if (mail=="1")
					$("contactMail").className ="error";
				if (name=="1")
					$("contactName").className ="error";
				if (subject=="1")
					$("contactSubject").className ="error";
				if (text=="1")
					$("contactText").className ="error";
			},
			onSuccess: function(txt) {
				$("contact").show();
				$("indicator").hide();
				$("cont").innerHTML ="<h1>Kontakt</h1><br /><img src='img/ic_Waccept.png' alt='' /> Die Nachricht wurde erfolgreich gesendet";
			}
		}
	);
}
