// Action Dialog		
var action_dialog;	

// --- Session Warning
function session_timer() {
	 setTimeout ( "session_warning()", 2400000 ); // = 40 Minuten
}
function session_warning() {
	 allg_dialog('/rekruter_2/login/session_warning.lasso', {title: 'Ihre Session l&auml;uft bald ab', modal: true});
	 setTimeout ( "session_timeout()", 600000 ); // = 10 Minuten
}	
function session_timeout() {
	 allg_dialog('/rekruter_2/login/session_timeout.lasso', {title: 'Ihre Session ist abgelaufen', modal: true});
}	

// allgemeine Funktion für voreingestellte Textfelder
function preset_field(el, wert) {
	if(el.val() == wert) {
		el.val('');
	}
}		

// --- Allgemeiner-Dialog
function allg_dialog(source, opt) {
	var action_dialog = $('#dialog').dialog({autoOpen: false});	
	opt.draggable = false;
	action_dialog.dialog("option", opt);
	if(action_dialog.dialog("isOpen")) {
		action_dialog.load(source);
	} else {
		action_dialog.load(source, function(){
			action_dialog.dialog('open');
		});
	}
	return false;
}

// --- Anmeldung-Dialog
function anmelden() {
	var source = '/rekruter_2/unternehmen/anmeldung.lasso';
	action_dialog.dialog("option", {
		autoOpen: false, title: 'Anmeldung f&uuml;r Unternehmen',
		modal: true, width: 700,
		resizable: false, draggable: false,
		buttons: {}
	});
	if(action_dialog.dialog("isOpen")) {
		action_dialog.load(source);
	} else {
		action_dialog.load(source, function(){
			action_dialog.dialog('open');
		});
	}
	return false;
}

// --- Login-Dialog
function login(goto) {
	var action_dialog = $('#dialog').dialog({autoOpen: false});	
	var source = '/rekruter_2/login/login_form.lasso?goto='+ goto;	
	action_dialog.dialog("option", {
		autoOpen: false, width: 200,
		modal: true, resizable: false,
		draggable: false,
		title: "Login",
		buttons: {
			"Login": function() { $('#modal_login_data').submit(); }, 
			"Abbrechen": function() { $(this).dialog("close"); }
		}			
	});
	
	if(action_dialog.dialog("isOpen")) {
		action_dialog.load(source);
	} else {
		action_dialog.load(source, function(){
			action_dialog.dialog('open');
		});
	}
	return false;
}

// --- Initialisiere Form-Tooltip
function init_form_tooltip(info_text) {
	var info_el = $('<div />');
	
	$('input, textarea, select').focus(function(){
		var inf_text = info_text[$(this).attr('name')];			
		if(inf_text != '') {
			var el_left_posi = $(this).offset().left + $(this).outerWidth() + 6;
			var el_top_posi = $(this).offset().top;
			info_el.css({'position':'absolute', 'width': 240, 'left': el_left_posi, 'top': el_top_posi});
			info_el.html(inf_text);
			$(this).after(info_el);
		}
	});		
	$('input, textarea, select').blur(function(){
		info_el.html('');
	});
}

// --- Ajax-Felder Validierung
function validate_fields(fields, form_id) { 

	var errors 	= 0;
	var valid 	= {'border-color':'#c0ccda', 'background-color':'#ffffff'};
	var invalid = {'border-color':'#86a816', 'background-color':'#cee66a'};
	
	for(var i=0; i<fields.length; i++) {
		var el = $(form_id +' input[name='+ fields[i] +']');
		if(el.fieldValue() == '') { el.css(invalid); errors++; } 
		else {						el.css(valid); }
	}
							
	if(errors != 0) { return false; }
	else { return true; }				
};		

// --- FEHLER MELDEN
function send_error(message) {				
	var data = {
		"action": "error", "url": url, "browser": browser, "header": header, 
		"message": message, "html": $('html').html()};
		
	$.ajax({
	  url: "/rekruter_2/static/kontakt_send.lasso",
	  data: data, type: "POST", cache: false,
	  success: function(){
		$('#err_form').html("<div class='no_error'>Vielen Dank f&uuml;r Ihre Hilfe.<br /> Ihr Rekruter Team</div>");
	  }
	});				
}


// --------------------------------
//	Init wenn Seite geladen
// --------------------------------	
$(document).ready(function() { 
	
	var action_dialog = $('#dialog').dialog({autoOpen: false});	
	
	// Email entmaskieren
	$('.email').each(function(){
		var email=$(this).html();
		email = email.replace(/\/.dot.\//g,".")
		email = email.replace(/\/.at.\//g,"@")
		$(this).html(email);
	})	
	
	//login
	$('#login_link').click(function(){
		login('') ;
		return false;
	});

	// --- Tooltips
	$('.tooltip').tooltip({ 
		delay: 0, 
		left: 90,
		showURL: false, 
		bodyHandler: function() { 
			return $('#tip_'+ $(this).attr("name")).html(); 
		} 
	});			
	$('.info').tooltip({ 
		delay: 0, 
		showURL: false 
	});				
	
	// --- TABS
	$('#tab_container').tabs();		
	
	// --- Minimize / Maximize
	$('.min_max').click(function(){			
		var target = $('#'+ $(this).attr('id').substring(4));
		var x = $(this).css('background-position').split(' ')[0];
		if(target.is(':visible')) {
			target.slideUp("slow");
			$(this).css('background-position', x +' 100%');
			$(this).attr('title', 'Detail Informationen einblenden');
		} else {
			target.slideDown("slow");
			$(this).css('background-position', x +' 0');
			$(this).attr('title', 'Detail Informationen ausblenden');
		}
		return false;
	});
	

	// --- Message / Error - Kurzeinblendung
	if($('.temp_msg').html() != null) {
		$('.temp_msg').animate({
			opacity: 0.8
		}, 500, function() {			
			setTimeout("$('.temp_msg').fadeOut()",6000);
		});
	}	
	
	// --- Preset Field
	$('.preset').focus(function(){
		if ($(this).attr('rel') == $(this).val()) 
			$(this).val('');})
	$('.preset').blur(function(){
		if ($(this).val() == '') 
			$(this).val($(this).attr('rel'));})			
});	
		
