
//********************************
//EMAIL-CHECK Funktion
//********************************
function isValidEmail(email){
	var a = false;
	var res = false;
	if(typeof(RegExp) == 'function'){
		var b = new RegExp('abc');
		if(b.test('abc') == true){a = true;}
	}
	if(a == true){
		reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
			   '(\\@)([a-zA-Z0-9\\-\\.]+)'+
			   '(\\.)([a-zA-Z]{2,3})$');
		res = (reg.test(email));
	} else {
		res = (email.search('@') >= 1 &&
		email.lastIndexOf('.') > email.search('@') &&
		email.lastIndexOf('.') >= email.length-5)
	}
	return(res);
}


$(document).ready(function(){

	//********************************
	//Dialoge initialisieren
	//********************************

	//Formular-Dialog
	$("#lb_dialog").dialog({
		autoOpen:false,
		dialogClass:"aboUI",
		resizable:false,
		draggable:true,
		width:388,
		height:293
	});

	//Dankes-Dialog
	$("#lb_dialog_danke").dialog({
		autoOpen:false,
		dialogClass:"aboUI",
		resizable:false,
		draggable:true,
		width:388,
		height:293
	});
	
	//Dankes-Dialog
	$("#lb_hilfedialog_danke").dialog({
		autoOpen:false,
		dialogClass:"aboUI",
		resizable:false,
		draggable:true,
		width:388,
		height:293
	});


	//********************************
	//FormDaten checken und speichern
	//********************************

	$("#lbsubmit").click(function(){
		var out="";
		$(":input","#leserbewertung").each(function(i){
			if(this.id=='E-Mail' && this.value!=''){
				if(!isValidEmail(this.value)){
					out += this.id+'\n';
				}
			}
			if(this.value=='' && this.id!='undefined'){
				out += this.id+'\n';
			}
		});
		if(out!=''){
			alert("Bitte folgende Felder korrekt ausfüllen:\n\n"+out);
		} else {
			$('#leserbewertung').ajaxSubmit();
			$('#lb_dialog').dialog('close');
			$('#lb_dialog_danke').dialog('open');
			document.getElementById('lb_dialog_danke').style.display="block";
		}
		return false;
	});

});

//***********************************
//Bewertung Hilfreich post-Funktionen
//***********************************
function postUseful(adl_id, useful){
	$.post("tpl/db.insert_lb.php",{ 
		action: "upduseful",
		useful: useful,
		adl_id: adl_id
		});
	$('#help'+adl_id+'').hide();
	$('#lb_hilfedialog_danke').dialog('open');
}
