window.load = initSystem;
/*
 * Initialisiert das System
 */
function initSystem()
{
}

var lxDataTable;
var hotels = [
	"Viva Tropic",
	"Viva Blue",
	"Vanity Golf",
	"Alcudia Garden"
	];
/*
 * Globale Dinge nach Laden des Doc-Roots
 */
$(document).ready(function() {
	// Newsletter-Empfaenger
	if (window.location.pathname == '/newsletter/') {
		lxDataTable = $('.nlReceiverTable').dataTable({
			'bProcessing':		true,
			'bLengthChange': 	false,
			'bFilter':			false,
			'iDisplayLength':	50,
			'oLanguage':		{ 'sUrl': '/inc/german.datatable.txt' },
			'aoColumns':		[ null, null, { 'sClass': 'middle' }, { 'sClass': 'middle' }, { 'sClass': 'right' } ],
			'aaSorting':		[[ 0, 'desc' ]],
			'sAjaxSource':		'/newsletter/ajax.php?get=receiver&display=50'
		});
	}/* else if (window.location.pathname == '/') {
		$('#fruehbucher').dialog({ width: 600 });
	}*/
	$('a[rel^="prettyphoto"]').prettyPhoto({deeplinking:false});
	if (window.location.pathname=="/buchung.php") {
		$('input#hotel').autocomplete({source:hotels});
		var errCont = $('div.error');
		$("#booking").validate();
	}
	// Aktions-Dialog
	var datum = new Date();
	var heute = datum.getDate();
	var monat = datum.getMonth();
	if (monat == 11 && (heute == 15 || heute == 16)){angebot();}
});

// Angebots-Popup 
function angebot() {
	$('#fruehbucher').dialog({
		modal: true,
		width: 620,
		height: 400,
		buttons: {
			Buchen: function(){
				top.location.href='/buchung.php';
			}
		}
	}).dialog('open');
}
// Loesch-Event an IMG binden
$('.deleteReceiver').live('click', function() {
	var obj = this;
	var id = obj.getAttribute('id');
	$.post("/inc/ajax.php", {delReceiver: id}, function(ret) {
		if (ret == 'ok') lxDataTable.fnDeleteRow(obj.parentNode.parentNode); //$(rcid).detach();
	});
});
/*
 * Prueft die Eingaben des Buchungsformulars
 */
function checkBooking()
{
	var f = document.forms[0];
	var error = '';
	if (f.vorname.value == '') { error += 'Vorname '; }
	if (f.name.value == '') { error += 'Nachname '; }
	if (f.email.value == '' || (f.email.value.indexOf("@") < 1) || (f.email.value.substring(f.email.value.indexOf("@"),indexOf(".")) < 2)) { error += 'E-Mail '; }
	if (error != '') {
		var fehler = "Die folgenden Felder wurden leer gelassen:\n";
		fehler += error;
		alert(fehler);
		return false;
	}
	return true;
}
/*
 * Navigations-Hover-Effekt
 */
function navOver(divid)
{
	var navpoint = document.getElementById(divid);
	navpoint.style.backgroundColor = '';
}
/*
 * Loesch-Funktion fuer das Gaestebuch
 */
function gb_loesche(id)
{
	var divid = '#gb-'+id;
	$.post('/inc/ajax.php', {deleteComment: id}, function(ret) {
		$(divid).remove();
	});
}
/*
 * Kommentierungs-Textfeld anzeigen beim Gaestebuch-Eintrag mit der ID
 * id
 */
function gb_comment(id)
{
	var divid = '#comment-'+id;
	$.post('/inc/ajax.php', {comment: id}, function(ret) {
		$(divid).append('<textarea id="setcomment-'+id+'" style="width:100%;height:80px;">'+ret+'</textarea><br/><input type="submit" id="add-'+id+'" onclick="saveComment('+id+')" />')
		$('#commentlk-'+id).removeAttr('onclick');
	});
}
/*
 * Kommentar speichern
 */
function saveComment(id)
{
	var ctid = '#setcomment-'+id;
	$.post("/inc/ajax.php", {addComment: $(ctid).val(), cid: id}, function(ret) {
		$('#setcomment-'+id).detach();
		$('#add-'+id).detach();
		$('#guyctid-'+id).detach();
		$('#comment-'+id).append('<br /><span class="gbcomment" id="guyctid-'+id+'"><span>Guy kommentierte:</span><br />'+ret+'</span>');
	});
}
/*
 * Funktion zum entfernen eines Newsletter
 */
function deleteNewsletter(id)
{
	var nlid = '#nl-'+id;
	$.post("/inc/ajax.php", {delNews: id}, function(ret) {
		$(nlid).detach();
	});
}
/*
 * Funktion zum entfernen eines Empfaengers
 */
function deleteReceiver(id)
{
	var rcid = '#rc-'+id;
	$.post("/inc/ajax.php", {delReceiver: id}, function(ret) {
		$(rcid).detach();
	});
}
