// (c) KLIK!  www[dot]klik-info[dot]ch  2007 //

Event.observe(window, 'load', function() { 
	new Draggable("archivdetail", {zindex:1000, handle:'draghandle'});
	$A($$('.ausdtl')).each( function(element) {
			Event.observe(element, 'click', function(el) {
					var myAjax = new Ajax.Request(
    					"/ausgabe_details.php",
    					{   
    						method:"post",
							postBody:"aus_id=" + element.src,
       						onComplete:show_new_data
     					}
    				);			
				["archivdetail"].each(Element.show);
			});
	});
	Event.observe($("schliessen"), 'click', function() {
		["archivdetail"].each(Element.hide);
		$("detailwrapper").innerHTML = '&nbsp;';
	});
	Event.observe($("loginschliessen"), 'click', function() {
		["login_eabo"].each(Element.hide);
		$$(".logmsg").each(Element.hide);
	});
	if ($("loginschliessen2")) {
	Event.observe($("loginschliessen2"), 'click', function() {
		["login_eabo2"].each(Element.hide);
		$$(".logmsg").each(Element.hide);
	});
	}
	Event.observe($("pwfg"), 'click', function(eventObj) {
	  if ($F("eabouser") == "") {
	    alert("Bitte geben Sie beim Benutzernamen Ihre E-Mail Adresse ein!");
	    $("eabouser").focus();
	  } else {
	    send_password(1);
	    alert("Das Passwort wird Ihnen nun per E-Mail zugeschickt."); 
		  ["login_eabo"].each(Element.hide);
		}
		Event.stop(eventObj);
	});
	if ($("pwfg2")) {
	Event.observe($("pwfg2"), 'click', function(eventObj) {
	  if ($F("eabouser2") == "") {
	    alert("Bitte geben Sie beim Benutzernamen Ihre E-Mail Adresse ein!");
	    $("eabouser2").focus();
	  } else {
	    send_password(2);
	    alert("Das Passwort wird Ihnen nun per E-Mail zugeschickt."); 
		  ["login_eabo2"].each(Element.hide);
		}
		Event.stop(eventObj);
	});
	}
	if (location.search.indexOf('aa') > -1) {
		zeige_aktuelle_ausgabe();
	}
});

function zeige_aktuelle_ausgabe() {
	var myAjax = new Ajax.Request(
    					"/ausgabe_details.php",
    					{   
    						method:"post",
							postBody:"aus_id=" + aaus,
       						onComplete:show_new_data
     					}
    				);			
	["archivdetail"].each(Element.show);
	eabo_login('x');
}

function next_item(idstring) {
	var nextAjax = new Ajax.Request(
    					"/ausgabe_details.php",
    					{   
    						method:"post",
							postBody:"aus_id=" + idstring,
       						onComplete:show_new_data
     					}
    				);		
}

function show_new_data(r) {
	$("detailwrapper").innerHTML = r.responseText;
}

function tog() {
	$A($$('.lt')).each(Element.toggle);
	$A($$('.onoff')).each(function(el) {
			el.src = el.src.indexOf("open",0) == -1 ? '/img/arr_open.gif' :' /img/arr_close.gif'; 
	});
}
var target_pdf = "";var logok="n";
function eabo_login(pdfdatei) {
  target_pdf = pdfdatei;
  if (logok == "n") {  $("login_eabo").show();$("eabouser").focus();/*$("eabouser").value="";$("eabopw").value="";*/ }
  else if (target_pdf != "x") { location.href = "/pdf_anzeigen.php?pdf="+target_pdf; }
  return false;
}
function eabo_login2(pdfdatei) {
  target_pdf = pdfdatei;
  if (logok == "n") {  $("login_eabo2").show();$("eabouser2").focus();/*$("eabouser2").value="";$("eabopw2").value="";*/ }
  else if (pdfdatei != "x") { location.href = "/pdf_anzeigen.php?pdf="+target_pdf; }
  return false;
}
function handle_login(r, fk) {
  if (r == "ok") {
    logok="j";
    $("login_eabo"+fk).hide();
    $$("img.pdfi").each(function(ele){ele.src="/img/pdf.gif";});
    if (target_pdf!="x") {
      location.href = "/pdf_anzeigen.php?pdf="+target_pdf;
    } else {
      //$("login_link").hide();
      //$("login_msg").show();
      //window.setTimeout('$("login_msg").hide()', 2500);
    }
    /*if($("login_link")) {
    	$("login_link").hide();
    	$$("img.pdfi").each(function(ele){ele.src="/img/pdf.gif";});
    }*/
  }
  else {
    $("eabouser"+fk).focus();
    $$(".logmsg").each(Element.show);
  }
  return false;
}
function send_login(nr) {
   fk = nr == 2 ? "2" : "";
	 var login_ajax = new Ajax.Request(
    		"/login_eabo.php",
    		{   
    			method:"post",
					postBody:"user=" + $F("eabouser"+fk) + "&pw=" + encodeURIComponent($F("eabopw"+fk)),
       		onComplete:function(r) { handle_login(r.responseText, fk) }
     		}
   );
   $("anmelden"+fk).blur();
  return false;
}
function send_password(nr) {
  fk = nr == 2 ? "2" : "";
	new Ajax.Request(
    		"/send_password.php",
    		{   
    			method:"post",
					postBody:"user=" + $F("eabouser"+fk)
     		}
    	);
}