// JavaScript Document
gEffect=true;
//gMsgEventvars="";
//$(function(){ initEvents();});

function showContent(curPage,strEntry){
	//alert("ef="+gEffect);
	if (gEffect==undefined) { gEffect=true; }
	if (strEntry!="gallery"){
		if (gEffect) {
			// set current page hidden
			$("#c"+curPage).css("display","none"); 
			// show new page content
			$("#c"+strEntry).fadeIn("slow");			
		} else {
			// set current page hidden
			$("#c"+curPage).css("display","none"); 
			// show new page content
			$("#c"+strEntry).css("display","block");
		}
	} else {
		document.location.href="?p=gallery";
	}
}

function swtichEffects(){
	if (gEffect){
		gEffect=false;
		$("#effects").html("Effekte: ON");
	}else{
		gEffect=true;
		$("#effects").html("Effekte: OFF");
	}
}

function restContact(){
	$("#drpGender").val("");
	$("#txtCompany").val("");
	$("#txtFirstName").val("");
	$("#txtLastName").val("");
	$("#txtStreet").val("");
	$("#txtZIP").val("");
	$("#txtCity").val("");
	$("#txtPhone").val("");
	$("#txtFax").val("");
	$("#txtMobile").val("");
	$("#txtEmail").val("");
	$("#txtContact").val("");
}

function sendContact(){
	$("#ccontact").css("cursor","wait");
	var bcheck = true;
	// check mandatory-fields
	if ($("#drpGender").val()=="" || $("#txtLastName").val()=="" || $("#txtPhone").val()=="" || $("#txtContact").val()=="" || $("#txtEmail").val()=="") { bcheck=false; }
	// send mail
	if (bcheck) {
		$.post("lib/kloster.php", {FUNC:"sendmail", 
				GENDER:  $("#drpGender").val(),
				COMPANY:	parseSpChars($("#txtCompany").val(),"tohtml"),
				FNAME: 	parseSpChars($("#txtFirstName").val(),"tohtml"),
				LNAME: 	parseSpChars($("#txtLastName").val(),"tohtml"),
				STREET: 	parseSpChars($("#txtStreet").val(),"tohtml"),
				ZIP :	parseSpChars($("#txtZIP").val(),"tohtml"),
				CITY: 	parseSpChars($("#txtCity").val(),"tohtml"),
				PHONE: 	parseSpChars($("#txtPhone").val(),"tohtml"),
				FAX: 	parseSpChars($("#txtFax").val(),"tohtml"),
				MOBILE: 	parseSpChars($("#txtMobile").val(),"tohtml"),
				EMAIL: 	parseSpChars($("#txtEmail").val(),"tohtml"),
				CONTACT: parseSpChars($("#txtContact").val(),"tohtml")}, 
			function(data){
				$("#ccontact").css("cursor","");
				if (data["success"]=="true") {
					alert("Vielen Dank für ihre Anfrage!\nSendeergebnis: "+data["sendres"]);
					restContact();
				} else {
					alert(data["error"]);
				}
			},"json"
		);
	} else {
		$("#ccontact").css("cursor","");
		alert("Bitte füllen Sie alle Felder die mit einem * gekennzeichnet sind aus!");	
	}
}

// sonderzeichen parser (umlaute usw.)
function parseSpChars(vIn,vMode){
	var vOut;
	if (vIn.length>0){
		vOut=vIn;
		if (vMode=="tohtml") {
			vOut=vOut.replace(/ö/g,"&ouml;");
			vOut=vOut.replace(/Ö/g,"&Ouml;");
			vOut=vOut.replace(/ü/g,"&uuml;");
			vOut=vOut.replace(/Ü/g,"&Uuml;");
			vOut=vOut.replace(/ä/g,"&auml;");
			vOut=vOut.replace(/Ä/g,"&Auml;");
			vOut=vOut.replace(/ß/g,"&szlig;");
			vOut=vOut.replace(/©/g,"&copy;");
		}
		if (vMode=="toread") {
			vOut=vOut.replace(/&ouml;/g,"ö");
			vOut=vOut.replace(/&Ouml;/g,"Ö");
			vOut=vOut.replace(/&uuml;/g,"ü");
			vOut=vOut.replace(/&Uuml;/g,"Ü");
			vOut=vOut.replace(/&auml;/g,"ä");
			vOut=vOut.replace(/&Auml;/g,"Ä");
			vOut=vOut.replace(/&szlig;/g,"ß");
			vOut=vOut.replace(/&copy;/g,"©");
		}		
	} else {
		vOut="";	
	}
	return vOut;
}
