/* FORMS */
function show_delete_form(title, id, name, table){
	$('form_delete_id').value = id;
	$('form_delete_table').value = table;
	$('delete_name').innerHTML = name;
	$('form_container').setStyle({borderColor: '#D73233'});
	$('form_title').innerHTML = title;
	
	$('form_container').className = '';
	$('form_container').addClassName('delete_form');
	
	$('form_back').show();
	$('form_delete').show();
	Effect.Appear($('form_container'), { duration:0.4 });
}

function hide_all_forms(){
	$('form_delete').hide();
	$('form_container').hide();
	$('form_back').hide();
	
	$('form_delete_id').value = '';
	$('delete_name').innerHTML = '';
	$('form_title').innerHTML = '';
	$$('.edit_form').each(function(item) {
		item.hide();
	});
}

function show_form(id, table, form_title, form_class){
	$('form_'+table+'_'+id).show();

	$('form_container').className = '';
	$('form_container').addClassName(form_class);
	$('form_container').setStyle({borderColor: '#62BD2D'});
	$('form_title').innerHTML = form_title;
	$('form_id').innerHTML = '';
	if(id != ''){
		$('form_id').innerHTML = 'id: '+id;
	}
	
	$('form_back').show();
	Effect.Appear($('form_container'), { duration:0.4 });
}

function show_form_loader(form_id){
	$(form_id).hide();
	$('form_loader').show();
	
	closeKeepAlive();
	
	$(form_id).submit();
}

/* A pretty little hack to make uploads not hang in Safari. Just call this
 * immediately before the upload is submitted. This does an Ajax call to
 * the server, which returns an empty document with the "Connection: close"
 * header, telling Safari to close the active connection. A hack, but
 * effective. */
function closeKeepAlive() {
  if (/AppleWebKit|MSIE/.test(navigator.userAgent)) {
    new Ajax.Request("/ping/close", { asynchronous:false });
  }
}


/* END FORMS */


/* FULL IMAGE */
/* global variablen*/
var html_buffer;
var container;

/**
* start function
*/
function show_full_img(pic_container, path_pic, path_loader){
	container = pic_container;
	
	html_buffer = $(container).innerHTML;

	var img_image = new_element("img", "js_full_img");
	$(container).innerHTML = '';
	$(container).appendChild(img_image);
	$(container).setStyle({
		textAlign: 'center',	
		paddingTop: '50px'
	});
	set_img(path_pic, path_loader , img_image);
}

/**
* sets the image
*/
function set_img(path, path_logo, img_image){
	img_image.setAttribute("src", path_logo);

	var image = new Image;
	image.onload = function(){
		$(container).setStyle({
			paddingTop: '0px'	
		});
		$('js_full_img').hide();
		img_image.setAttribute("src", path);
		img_image.onclick = close_img;
		$('js_full_img').setStyle({
			cursor: 'pointer'	
		});
		Effect.Appear($('js_full_img'));
	}
	image.src = path;
 
//	scrollTo(0, 0);
}
 
/**
* closes the image
*/
function close_img(){
	$(container).setStyle({
		textAlign: 'left'
	});
	$(container).innerHTML = html_buffer;
}
 
/**
* creates new element
*/
function new_element(tag, id){
	var element = document.createElement(tag);
	element.setAttribute("id", id);
	
	return element;
}
