 function escHTMLnl2br(wert) {
  var lines = new Array();
  wert.split("\n").each( function(item) {
   lines.push(item.escapeHTML());
  });
  return lines.join("<br>");
 }

 function page_offset() {
  var x,y;
  // all except Explorer
  if (self.pageYOffset) {
   x = self.pageXOffset;
   y = self.pageYOffset;
  // Explorer 6 Strict
  } else if (document.documentElement && document.documentElement.scrollTop) {
   x = document.documentElement.scrollLeft;
   y = document.documentElement.scrollTop;
  // all other Explorers
  } else if (document.body) {
   x = document.body.scrollLeft;
   y = document.body.scrollTop;
  }
  return x+','+y;
 }

 function do_command(com) {
  var f = document.forms[0];
  f.com.value=com;
  if (arguments.length>1) f.com_arg.value=arguments[1];
  if (f.PageOffset)
   f.PageOffset.value=page_offset();
  f.submit();
 }

 function do_sub_command(com) {
  var f = document.forms[0];
  f.sub_com.value=com;
  if (f.PageOffset)
   f.PageOffset.value=page_offset();
  if (arguments.length>1) f.sub_com_arg.value=arguments[1];
  f.submit();
 }

 function do_command_arg(com,arg) {
  var f = document.forms[0];
  f.com.value=com;
  f.com_arg.value=arg;
  if (f.PageOffset)
   f.PageOffset.value=page_offset();
  f.submit();
 }

 function do_sub_command_arg(com,arg) {
  var f = document.forms[0];
  f.sub_com.value=com;
  f.sub_com_arg.value=arg;
  if (f.PageOffset)
   f.PageOffset.value=page_offset();
  f.submit();
 }

 function del_email(id) {
	 do_sub_command_arg('del_email',id);
 }

function goto_page(nr) {
//  var f = document.forms[0];
//  f.page_id.value = nr;
//  do_command('set_context');
  location.href="index.php?page_id="+nr;
 }

 function save_it() {do_command("save");}
 function save_() {do_sub_command("save");}
 function neu(nr) {do_command("neu_"+nr);}
 function neu_(nr) {do_sub_command_arg("neu",nr);}
 function edit_it(nr) {do_command("edit_"+nr);}
 function edit_(nr) {do_sub_command_arg("edit",nr);}
 function send_email() {do_command("send_email");}
 function search() {
  document.forms[0].action="Foren.Suchergebnisse.php";
  do_command("search");
 }

 function delete_it(nr) {
  if (confirm("Sind Sie sicher?"))
   do_command("del_"+nr);
 }

 function delete_(nr) {
  if (confirm("Sind Sie sicher?"))
   do_sub_command_arg("del",nr);
 }

 function do_confirmed_sub_command(value) {
  if (confirm("Sind Sie sicher?"))
   do_sub_command(value);
 }

 function do_confirmed_sub_command_arg(com,value) {
  if (confirm("Sind Sie sicher?"))
   do_sub_command_arg(com,value);
 }

 function cancel_it() {
  if (confirm("Sind Sie sicher?"))
   do_command("cancel");
 }

 function move_up(nr) {do_sub_command_arg("up",nr);}
 function move_down(nr) {do_sub_command_arg("down",nr);}

 function login_me() {do_command("login");}
 function view_protokoll_archiv() {do_command("protokoll_archiv");}
 function goto_forum(nr) {location.href="Forum.php?id="+nr;}
 function goto_thema(nr) {location.href="Forum.Thema.php?id="+nr;}
 function goto_beitrag(thema,nr) {location.href="Forum.Thema.php?id="+thema+"#"+nr;}

 function top_navi_mouse_over(nr) {
  $("top_navi_img_"+nr).src = top_navi_mouse_over_img_array[nr].src;
 }

 function top_navi_mouse_out(nr) {
  $("top_navi_img_"+nr).src = top_navi_mouse_out_img_array[nr].src;
 }

 function main_navi_mouse_over(nr) {
  $("main_navi_img_"+nr).src = main_navi_mouse_over_img_array[nr].src;
 }

 function main_navi_mouse_out(nr) {
  $("main_navi_img_"+nr).src = main_navi_mouse_out_img_array[nr].src;
 }

 function main_sub_navi_mouse_over(nr) {
  $("main_sub_navi_img_"+nr).src = main_sub_navi_mouse_over_img_array[nr].src;
 }

 function main_sub_navi_mouse_out(nr) {
  $("main_sub_navi_img_"+nr).src = main_sub_navi_mouse_out_img_array[nr].src;
 }

 function change_layout_type() {
  var f = document.forms[0];
  do_command_arg("change_layout_type",f.layout_type.value);
 }

 function content_edit() {
  do_command('content_edit');
 }

 function let_appear_big_image_of(tn_img) {
  var img = $("big_image_layer_img");
  img.src = big_image_array[tn_img.getAttribute('id')].src;
  var layer = $("big_image_layer");
  var tn = $(tn_img.getAttribute('id'));
  var tn_pos = Position.cumulativeOffset(tn);
  var tn_w = tn.getWidth();
  var w = big_image_array[tn_img.getAttribute('id')].width;
  var h = big_image_array[tn_img.getAttribute('id')].height;
  layer.setStyle({left: (tn_pos[0]+tn_w-w-10)+"px", top: (tn_pos[1]-10)+"px", height: (h+0)+"px", width: (w+10)+"px"});
  new Effect.Appear(layer);
 }

 function leave_big_image_layer() {
  $("big_image_layer").hide();
 }

// function hide_div(id) {$(id).hide();}
 function hide_div(id) {$(id).setStyle({visibility:'hidden'});}

function papierfinder_oeffnen () {
  papierfinder_window = window.open("http://www.papier-news.de/paperdb/", "papierfinder_", "width=795,height=686,left=0,top=0,scrollbars=yes");
  papierfinder_window.focus();
}

 /* hold mouse position */

 var mouse_pos_x = 0;
 var mouse_pos_y = 0;

 Event.observe(window, "load", function() {
  Event.observe($("body"),"mousemove", function(event) {
   mouse_pos_x = Event.pointerX(event);
   mouse_pos_y = Event.pointerY(event);
  });
  /*** CATCHING DOCUMENT WIDE KEY EVENTS ***/
	if( document.attachEvent ) {
	 $("body").attachEvent('onkeyup',window_keycode_trigger); // IE
	} else if( document.addEventListener ) {
	 window.addEventListener( 'keyup', window_keycode_trigger, false ) // none IE
	} 
 });


/*** ON WINDOW KEY EVENTS ***/
function window_keycode_trigger(event) {
 /* on CTRL Y event */
 if (event.ctrlKey && event.keyCode == 89) login_to_current_page();
}

function login_to_current_page() {
 if (document.forms[0].page_id) {
  location.href="index.php?Login=1&page_id="+document.forms[0].page_id.value;
 } else {
  location.href="index.php?Login=1";
 }
}
