/* ******************************************** */
/*                                              */
/*                    SETTINGS                  */
/*                                              */
/* ******************************************** */

// Tags-Speichern-URL
var violation_submit_url = "../ajax_report_violation";
var violation_success_msg = '';
var firstSelectItem = null;

/* ******************************************** */
/*      Ab hier auf eigene Gefahr:              */
/* ******************************************** */


function report_violation_submit() {
	subject = jQuery('#violation_subject').val();
	text = jQuery('#violation_text').val();
	email = jQuery('#violation_email').val();
	if (text.length >= 0) {
		jQuery.ajax({
			type: "POST",
			url: violation_submit_url,
			data: {
				'violation_subject': subject,
				'violation_text': text,
				'violation_email': email
			},
			success: function(response){
				tb_remove();
				jQuery('#sys_msg').remove();
				jQuery('<div />').attr({id: 'sys_msg'}).prependTo('#left').html('');
				jQuery('<div />').addClass('success').text(violation_success_msg).appendTo('#sys_msg');
				jQuery('#sys_msg').fadeIn();
			}
		});
	} 
	return false;
}
   

function init_report_violation_form() {
	jQuery('#violation_subject').val("");
	jQuery('#violation_text').val("");
	jQuery('#violation_email').val("");
}


jQuery().ready(function() {	
	
	violation_success_msg = jQuery('input#report_violation_success_msg').val();
		
	jQuery('#report_violation_btn').unbind().click(function() {
		if(firstSelectItem) {
			jQuery(firstSelectItem).prependTo('#violation_subject');
		}
		init_report_violation_form();
		tb_show(null, '#TB_inline?inlineId=report_violations_wrapper', false, '_white');
		if(jQuery('#report_violation_head_wrapper').height() > 70) {
			jQuery('#report_violation_head_wrapper').addClass('maxHeightScroll');
		}
    	return false;        
	});
	
	jQuery('#tb_report_submit_btn').click(function() {
		report_violation_submit();
	});
	
	jQuery('#tb_report_cancel_btn').click(function() {
		tb_remove();
	});
	
	jQuery('#violation_subject').change(function() {
		if(!firstSelectItem) firstSelectItem = jQuery('#violation_subject > .chooser');
		firstSelectItem.remove();
	});	
});
