var ajaxMod = "lib/site/wrapper.php";

function subscribe() {
	switch (lang) {
		case "fr":
			l_inv_mail = "adresse email invalide";
			l_conf_mail = "un email de confirmation a &eacute;t&eacute; envoy&eacute; &agrave; votre adresse indiqu&eacute;e";
		break;
		case "de":
			l_inv_mail = "ung&uuml;ltige Emailadresse";
			l_conf_mail = "Eine Best&auml;tigungsmail wurde an die angebene Email geschickt";
		break;
	}
	email = $('#i_email').val();
	if (!checkEmail(email)) {
		report(l_inv_mail);
		return;
	}
	$.post(ajaxMod,{ action: "email.send", e: email },function(xml){
		if ($('status',xml).text() == 1) {
			report(l_conf_mail);
			$('#i_email').val('');
		}
		else { report($('status',xml).text()); }
	});
}

function sendCandi() {
	switch (lang) {
		case "fr":
			l_cand_succ = "Votre candidature a &eacute;t&eacute; envoy&eacute;e avec succ&egrave;s et sera trait&eacute;e par notre service du personnel dans les meilleurs d&eacute;lais."
			l_inv_mail = "email invalide";
			l_inv_name = "veuillez entrer votre nom";
			l_inv_adr = "veuillez entrer votre adresse";
			l_inv_text = "veuillez entrer votre texte de candidature";
		break;
		case "de":
			l_cand_succ = "Ihre Bewerbung wurde erfolgreich gesendet und wird in k&uuml;rzester Zeit von unserer Personalabteilung bearbeitet.";
			l_inv_mail = "ung&uuml;ltige email";
			l_inv_name = "Bitte Namen eintragen";
			l_inv_adr = "Bitte Adresse eintragen";
			l_inv_text = "Bitte Bewerbungstext eintragen";
		break;
	}
	check = true;
	if ($('#cand_name').val() == "") { report(l_inv_name); check = false; }
	email = $('#cand_email').val();
	if (!checkEmail(email)) {
		report(l_inv_mail);
		check = false
	}
	if ($('#cand_adr1').val() == "" || $('#cand_adr2').val() == "") { report(l_inv_adr); check = false; }
	if ($('#cand_text').val() == "") { report(l_inv_text); check = false; }
	if (!check) return;
	$.post(ajaxMod,{
		action:"candi.send",
		n: $('#cand_name').val(),
		e: email,
		a1: $('#cand_adr1').val(),
		a2: $('#cand_adr2').val(),
		t: $('#cand_text').val()
		},function(xml){
		if ($('status',xml).text() == 1) {
			report(l_cand_succ);
			nyroModalClose();
		}
		else {
			report($('status',xml).text());
		}
	})
}

function loadTipp(id) {
	$.post(ajaxMod,{ action:"tipp.load", i: id },function(xml){
		if ($('status',xml).text() == 1) {
			html = "";
			html += '<div><img src="files/tipps/'+$('thumb',xml).text()+'" /></div>';
			html += '<a href="files/tipps/'+$('pdf',xml).text()+'" target="_blank">Online ansehen</a>';
			html += '<a href="pages/download/download.php?t=tipps&f='+$('pdf',xml).text()+'" class="tipps_download"><img src="images/Download_Button.png" title="Download" /></a>';
			$('#tipps_detail').html(html);
			$('#tipps_detail').fadeIn(anispeed);
		}
		else {
			report($('status',xml).text());
		}
	})
}

function searchTipp() {
	$('#tipps_detail').css("display","none");
	if ($('#tipp_search').val() == "") {
		report("Bitte geben Sie einen Begriff ein");
		return;
	}
	$.post(ajaxMod,{ action:"tipp.search", str: $('#tipp_search').val() },function(xml){
		if ($('status',xml).text() == 1) {
			html = "";
			if ($('tipp',xml).length == 0) { html += "Keinen Ratgeber gefunden"; }
			$('tipp',xml).each(function(i){
				tipp = $('tipp',xml).get(i);
				html += '<a href="#" onclick="loadTipp('+$('id',tipp).text()+')" class="tipps_tipp">';
					html += '<img src="files/tipps/'+$('thumb',tipp).text()+'" width="75" />';
					html += '<img src="images/Loupe.png" class="tipps_loupe_small" width="20" />';
				html += '</a>';
			});
			$('#tipps_right_cont').html(html);
			$('#tipps_right_cont').fadeIn(anispeed);
		}
		else {
			report($('status',xml).text());
		}
	})
}