/** $Id: final.js,v 2.6 2009/08/14 19:01:13 ph Exp $ **/

new Draggable("med_box",{handle:'Leiste',starteffect:null,endeffect:null}); 
new Draggable("detail_box",{handle:'Leiste',starteffect:null,endeffect:null});
new Draggable("pedit_box",{handle:'Leiste',starteffect:null,endeffect:null});
new Draggable("eedit_box",{handle:'Leiste',starteffect:null,endeffect:null});
new Draggable("goverlay",{starteffect:null,endeffect:null}); 

Event.observe($("detail_box"),'mouseout',detail_mouse_out); 

$("detail_box").observe('click', detail_to_front);
$("pedit_box").observe('click', pedit_to_front); 
$("eedit_box").observe('click', eedit_to_front);


function detail_mouse_out(e) {
//	alert("OUT"); 
} 

function to_front(box) {
	var boxen = ["med_box","detail_box","pedit_box", "goverlay"]; 
	var max = 0; 
	for (var i = 0; i < boxen.length; i++) {
		max = Math.max(max, $(boxen[i]).style.zIndex); 
	}
	$(box).style.zIndex = max+1; 
} 

function detail_to_front() { to_front("detail_box") }; 
function pedit_to_front() { to_front("pedit_box") };
function eedit_to_front() { to_front("eedit_box") };


function show_mod(t) {
	$("med_box").style.display = "block"; 
	$("med_title").innerHTML = t; 
//	$("detail_box").style.zIndex = 100; 
//	$("med_box").style.zIndex = 200;
	in_sicht("med_box");
//	to_front("med_box"); 
}

function in_sicht(id) {
	var a = $(id).cumulativeScrollOffset(); 
	var b = $(id).cumulativeOffset(); 
	if(a[1] > b[1]) {
		$(id).style.top = a[1]+"px"; 
	}
	var h = window.innerHeight ; 
	if(typeof(h)  != 'number') {
		var h = document.documentElement.clientHeight;  
	}
	if(a[1]+h < b[1]) {
		var hh = 1*a[1]+h - 1*$(id).getHeight(); 
//		alert($(id).getHeight())
		 $(id).style.top = hh+'px';
	}
}

function show_detail(title,color) {
	if(color) {
		$("detail_Leiste").style.backgroundColor = color; 	
	}
	$("detail_box").style.display = "block";
	$("detail_title").innerHTML = title+"&nbsp;";
	$("detail_box").style.zIndex = 200;
	$("med_box").style.zIndex = 100;
	to_front("detail_box");
	in_sicht("detail_box");
	if($("detail_content_L")) {
		var id = $("detail_content_L").name; 
		if(! getnextpre(id,-1)) {
			$("detail_content_L").style.visibility  = 'hidden'; 
		}
		if(! getnextpre(id,1)) {
			$("detail_content_R").style.display = 'none';
		}
		
	}
}	

function show_pedit(title,color) {
	if(color) {
		$("pedit_Leiste").style.backgroundColor = color;
	}
	$("pedit_box").style.display = "block";
	$("pedit_title").innerHTML = title;
	$("pedit_box").style.zIndex = 200;
	$("med_box").style.zIndex = 100;
	to_front("pedit_box"); 
	in_sicht("pedit_box");
//	$("pedit_box").style.left = "2px"
}	

function show_eedit(title) {
	$("eedit_box").style.display = "block";
	$("eedit_title").innerHTML = title;
	$("eedit_box").style.zIndex = 200;
	$("med_box").style.zIndex = 100;
	to_front("eedit_box"); 
	in_sicht("eedit_box");
}	

function show_xedit(title) {
	$("xedit_box").style.display = "block";
	$("xedit_title").innerHTML = title;
	$("xedit_box").style.zIndex = 200;
	$("med_box").style.zIndex = 100;
	to_front("xedit_box"); 
	in_sicht("xedit_box");
}	

	

function mini_detail() {
	$("detail_inhalt").style.display = "none";
} 

function maxi_detail() {
	$("detail_inhalt").style.display = "block";
}


function hide_mod() {
	$("med_box").style.display = "none";
	$("med_title").innerHTML = "";
	$("med_box").style.zIndex = 100;
	$("med_content").innerHTML = "";
} 

function hide_detail() {
	$("detail_box").style.display = "none";
}

function hide_pedit() {
        $("pedit_box").style.display = "none";
}
function hide_eedit() {
        $("eedit_box").style.display = "none";
}


function hide_it(a) {
	if($(a)) {
		$(a).style.display = "none";
	} 
}

function late_hide(a) {
	windows.setTimeout("hide_it('"+a+"');", 500);
}

var pos_updates = new Array(); 

function pos_update(t) {
	if (document.getElementById(t.myname)) {
		pos_updates.push(Sortable.serialize(t.myname)) ; 
		getBiggestSortable();

//		alert(document.getElementById(t.myname).className);
//		noden = document.getElementById(t.myname).parentNode;
//		var a = document.getElementById(t.myname).childNodes.length;
//		var b;
//		var c;
//		var x;

		/*if(noden.className == "listbox2sp") {
			for(x=1;x<a;x++) {
				b = document.getElementById(t.myname).childNodes[x];
					if (navigator.appName=="Microsoft Internet Explorer") {
						c = b.childNodes[0]; 
					}else{ c = b.childNodes[1]; }
				if(c.className == "Spalte") {
					c.className = "SpalteZ";
				}
			}
		}else if(noden.className == "listbox layout2" ) {
			for(x=0;x<a;x++) {
				b = document.getElementById(t.myname).childNodes[x];
					if (navigator.appName=="Microsoft Internet Explorer") {
						c = b.childNodes[0]; 
					}else{ c = b.childNodes[1]; }
				if(c.className == "SpalteZ") {
                c.className = "Spalte";
             }
			}
		}*/
//		alert(document.getElementById(t.myname).parentNode.className);
	}
} 

function flipflop(w) {
	if($(w)) {
		 
		if($(w).style.display == 'none') {
			$(w).style.display = 'block'; 
			$(w+'_edit').style.display = 'none'; 
		} else {
			$(w).style.display = 'none';
			$(w+'_edit').style.display = 'block';
		}
	}
}

var flipdisplaybacktext=''; 

function flipdisplay(p,mode) {
	if($(p)) {
	var a = document.getElementById(p);
	 if(mode != 1) {
		a.style.display = 'none';
	 } else {
		a.innerHTML = flipdisplaybacktext;
	 }
	}
}


function flipdisplayback(p) {
	if($(p)) {
		var a = document.getElementById(p);
		a.style.display = 'block';
	}
}

function abo_ok(p,text) {
		flipdisplaybacktext = text;  
		flipdisplayback('editdiv_'+p);
		setTimeout("flipdisplay('editabodiv_" + p + "',1)",1500)
}

function Autocompleter(name,was,f) {
	var a =  new Ajax.Autocompleter(name, name + "s", "/ajax/av/view/"+was, {
	    paramName: "word",
	    minChars: 2
          });  
}

function aj_updater() {
   	var pos_updates_tmp = pos_updates; 
	p = ''; 
	pos_updates = new Array();
	if(pos_updates_tmp.length > 0) {
		for(var i = 0; i < (pos_updates_tmp).length; i++ ) {
			p = pos_updates_tmp[i] + '&'; 		
		} 
//		alert(p); 
		ajax_call("/ajax/user_liste/save_pos?"+p); 
// 		IREDS_URL("ajax/user_liste/save_pos/"+p,{method:'GET'}).call();
	} 

} 

var sortable_boxes=3;

function getBiggestSortable() {
	var height=0;
	var height_diff=0; 
/*	var google_karte = $('GoogleKarte'); 
	if(! google_karte ) google_karte =  $('GoogleKarteGross');
	if(! google_karte ) google_karte =  $('GoogleKarteMittel');
	if($('teaser_box')) var teaser_height=$('teaser_box').getDimensions().height;
	else var teaser_height=0;	

	if(google_karte) {
		height_diff=google_karte.getDimensions().height-
			teaser_height;
	} else { teaser_height=0; }*/

	var tmp_height = 0; 
	for(i=1;i<=sortable_boxes;i++) {
		//dim=$('liste_'+i).getDimensions();
		tmp_height=0;
		if(document.getElementById('liste_'+i)) {
		  tmpChildren=document.getElementById('liste_'+i).childNodes;
		  for(c=0;c<tmpChildren.length;c++) {
			if($(tmpChildren[c].id)) {
				dim=$(tmpChildren[c].id).getDimensions();
				tmp_height+=dim.height;
			}
		  }
		  if(tmp_height> height) {
			height=tmp_height;
		  }
		}
	}


	for(i=1;i<=sortable_boxes;i++) {
		set_height=height;
		if(i>=4) {
			//hack fuer die 2 rechten listen
			set_height=height-height_diff;
		}
		if($('liste_'+i)) {
			$('liste_'+i).style.height=set_height+"px";
		}
	}
	
}

function makeSortable() {
	var anz=0;  
	var containments = new Array(); 

	for(var i = 1; i <= sortable_boxes; i++ ) {
		if(document.getElementById("liste_"+i)) {
			anz = i; 
			containments.push("liste_"+i); 
		} 	
	}
	for(var ixd = 1; ixd <= anz; ixd++ ) {
	    if(document.getElementById("liste_"+ixd)) {
			Sortable.create("liste_"+ixd,
			{	
				dropOnEmpty:true,
				containment:containments, 
				constraint:false,
				handle:"handle", 
				hoverclass:"boxhover",
				myname:"liste_"+ixd,
				scroll:window,
				starteffect:null,
				endeffect:null,
				onChange:function() { pos_update(this); } 
			}); 
	    }
	}
	
//	getBiggestSortable();
} 

function show_news(nid) {
	ajax_call('/ajax/detail/view/'+nid); 
	if($('detail_banner')) {
		$('detail_banner').src="/ajax/googlebanner.php?ID="+nid;
	}
	return false;
}

function add_userlist(id) {
	var e = $("listitem_"+id); 
	var enew = $("listitem_0_A1");
	var ep = e.parentNode; 
	ep.insertBefore(enew,e); 
	enew.style.display = 'block'; 
	ajax_call('/ajax/user_liste/addliste/A'+id)
}

function open_sitemap_channel(id) {
	var e = $("channelchid_"+id); 
	var enew = $("channelchid_hidden_"+id);
	var ep = e.parentNode; 
	ep.insertBefore(enew,e); 
	enew.style.display = 'block'; 
	
	e.style.display = 'none'; 
//	ajax_call('/ajax/user_liste/addliste/A'+id)
}

function close_sitemap_channel(id) {
	var enew = $("channelchid_"+id);
   var e = $("channelchid_hidden_"+id);
   var ep = e.parentNode;
   ep.insertBefore(enew,e);
   enew.style.display = 'block';

   e.style.display = 'none';
}

function close_userlist() {
	var enew = $("listitem_0_A1");
	enew.style.display = 'none';
}


function openwarnbox(box) {
	if(box == '') { box = 'A'; }
	var openbox = $("warnbox_"+box);
   openbox.style.display = 'block';
	window.setTimeout("closewarnbox('"+box+"')",2500);
}
function closewarnbox(box) {
//   Effect.SlideUp('warnbox_'+box, { duration: 1.0 });
	if($('warnbox_'+box)) {
		$('warnbox_'+box).style.display="none";
	}
}

function delete_userlist(id) {
	var e = $("listitem_"+id);
	var ep = e.parentNode;
	ep.removeChild(e);
}

function show_loader(id,t) {
	if($(id+'_box')) {
		$(id+'_content').innerHTML = '<div align="center"><img src="/bilder/ajax-loader.gif" alt="" vspace=50 hspace=50></div>'; 	
		$(id+'_box').style.display = "block"; 
		$(id+'_title').innerHTML = t
	} 
}

function getgooglemap() {
	return document.getElementById('googleframe').contentWindow
}

function show_pin(lat,long,acc) {	
	dm = $('detail_banner');

	if(dm.src.match(/google[.]php/)) {
		dm.contentWindow.show_pin(lat, long,acc);
	} else {
		dm.src = '/ajax/google.php?wo=inlayer&LAT='+lat+'&LONG='+long+'&ACC='+acc;
	}
}

function run_suche(e,color) {
	if(color) {
		$("pedit_Leiste").style.backgroundColor = color;
	}
	myga.seg="channels"; 
	myga.settrack(); 	
	show_loader('pedit','Es wird gesucht ...');
	$("pedit_oben").style.display = 'none'; 
	ajax_call('/ajax/search/'+e);
	
	return false; 
}

window.onLoad = makeSortable(); 

window.setInterval("aj_updater()",500); 


function ulist_loader() {
  if(uliste.items.length > 0) {

//	ajax_call("/ajax/liste/offset/"+uliste.items[uliste.last]); 	
	new IREDS_URL('/ajax/liste/offset/'+uliste.items[uliste.last],{method:'get'}).call();
	uliste.last++; 
	if(uliste.items.length <= uliste.last) {uliste.last = 0}
  }	
  
}




//function onloader() {
	window.setInterval("ulist_loader()",1000*10); 
//}

//document.onload = onloader; 

function box_resize() {
}

function check_mail(str,divid) {
	var elem = document.getElementById(divid);
	elem.style.display = "none";
	if (!validEmail(str)) {
		elem.style.display = "block";
	}
}
function validEmail(email) {
//		var strReg = "^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$";
      var strReg = new RegExp('^([a-zA-Z0-9äüöÄÜÖ\\-\\.\\_]+)'+
							         '(\\@)([a-zA-Z0-9äüöÄÜÖ\\-\\.]+)'+
									   '(\\.)([a-zA-Z]{2,4})$');
		var regex = new RegExp(strReg);
		return(regex.test(email));
}

function empfehlung_out() {
		var elem = document.getElementById('med_content');
		elem.innerHTML = '<span style="font-size:12px"> <br />&nbsp;Ihre Empfehlung wurde erfolgreich versendet!<br /><br /></span>';
//		elem.style.display='none';

 		window.setTimeout("empfehlung_weg()",1000*5);
}

function empfehlung_weg() {
		$('med_box').style.display='none'; 
} 

//////////// EDIT PUBLISCHER ///// 

function addpubl(id,o) {
	var v = encodeURI(o.innerHTML); 
	ajax_call('/ajax/user_liste/addpub/'+id+'/'+v); 
	return false; 
}

function delpubl(id) {
	ajax_call('/ajax/user_liste/delpub/'+id);
} 


//////////// /////
// Tickertape - Start 
////////////////////


/*TICKER_CONTENT = document.getElementById("TICKER").innerHTML;
 
TICKER_RIGHTTOLEFT = false;
TICKER_SPEED = 2;
TICKER_STYLE = "font-family:Arial; font-size:12px; color:#fff";
TICKER_PAUSED = false;


ticker_start();
*/

function flash_save_kat() {
	$('kat_save_status').innerHTML = 'Gespeichert!';
	$('kat_save_status').show();

	window.setTimeout("hide_flash_kat()", 2000);
}

function hide_flash_kat() {
	$('kat_save_status').hide();
}

function add_myspace(T, C, U, L) {
	T = encodeURIComponent(T);
	C = encodeURIComponent(C);
	U = encodeURIComponent(U);
	targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&t=' + T + '&c=' + C + '&u=' + U + '&l=' + L;
	window.open(targetUrl);
}


  function getmyselected(o) {
 	var s = ''; 
        for (i = 0; i < o.length; i++) {
	 if(o.options[i].selected) {
		s = s + o.options[i].value+","; 
	  }
	} 
	return s; 

  }

// wnn-168
var microsoft_banner = ""; 

var nox = document.createElement("div"); 
nox.id = "ajaxLoaderTop"; 
nox.setAttribute("style","position:fixed;top:2px;left:2px;display:none;");
nox.innerHTML = "<img src='/bilder/miniloader2.gif' alt=''>"; 
document.body.appendChild(nox);

