loadedimages = new Array();
myimagelink = "";
myimageborder = "";
mywindow = "";
window.onload = init;
function init(e){
	if($('others')) {
		difference = $('mainContent').offsetHeight - $('others').offsetHeight;
		if(difference > 10) {
			//$('cloud').style.height='100%';
			shortycount = difference / 50;
			new Ajax.Updater('moreshorties','/lib/moreShorties.php?count='+shortycount);
		}
	}
	statlink =	getElementsByStyleClass('statlink')[0];
	if(statlink) {
		statlink.innerHTML = statlink.innerHTML + ' <a style="font-size:100%;color:#003300;" style="font-size:8pt;" href="javascript:PicLensLite.start();">> Start Slide Show!</a>';
	}
}

function getElementsByStyleClass (className) {
	var all = document.getElementsByTagName('td');
	var elements = new Array();
	for (var e = 0; e < all.length; e++){
		if (all[e].className == className){
			elements[elements.length] = all[e];
		}
	}
	return elements;
}
function doSearch(wert) {
	if(wert.length >= 3) {
		$('searchresult').style.display = "block";
		new Ajax.Updater('searchresult','/search_new/search.php?query_string='+wert);
	}
}
function doSearchTopic(wert) {
	if(wert.length >= 3) {
		$('topicResult').style.display = "block";
		new Ajax.Updater('topicResult','/lib/searchTopic.php?topic='+wert);
	}
}
function setTopic(value,name,image,url) {
	$('topicResult').innerHTML = '';
	$('topicResult').style.display='none';
	if(value!='NEW_TOPIC') {
		if(typeof(value)!='undefined') {
			$('topicID').value= value;
			$('search_value').value = "Thema suchen...";
			$('previewName').value = name;
			$('previewImage').src = image;
			$('linkcheck').href = url;
			$('previewLink').value = url;
			$('previewLink').title = url;
			
			// backup the values
			previewName = name;
			previewImage = image;
			previewLink = url;
			topicID = value;
		}
	}
	else {
		$('topicID').value= "";
		$('search_value').value = "Neues Thema";
		$('previewName').value = "Themenbezeichnung eingeben";
		// default image for new topics
		$('previewImage').src = "/pictures/thumbs/tn_flowzone.jpg";
		$('linkcheck').href = "http://www.flowzone.ch/";
		$('previewLink').value = "http://www.flowzone.ch/";
		$('previewLink').title = "http://www.flowzone.ch/";
		$('previewButtons').show();

		// backup the values
		previewName = $('previewName').value;
		previewImage = $('previewImage').src;
		previewLink = $('previewLink').value;
		topicID = $('topicID').value;
	}
	return
}
function createTopic() {
	// create the new topic
	new Ajax.Request('/lib/createTopic.php?id='+$('topicID').value+'&topic='+$('previewName').value+'&link='+$('previewLink').value+'&image='+GetBaseName($('previewImage').src),{
		onComplete: function(id) {
			$('topicID').value=id.responseText;
			$('previewButtons').hide();
			setTopic(id.responseText,$('previewName').value,$('previewImage').src,$('previewLink').value);
		}
	});
}

function resetTopic() {
	setTopic(topicID,previewName,previewImage,previewLink);
	$('previewButtons').hide();
}

function GetBaseName(file)
{
	var Parts = file.split('\\');
	if( Parts.length < 2 )
	Parts = file.split('/');
	return Parts[ Parts.length -1 ];
} 
function closeResult() {
	$('searchresult').innerHTML='';
	$('searchresult').style.display = "none";
}
function get_Actions(turnus,kategorie) {
	new Ajax.Updater('actions','/lib/get_Actions.php?turnus='+turnus+'&c='+kategorie);
}

function FlashMovie(src, movie, width, height)
{
	document.write("<object codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' type='application/x-shockwave-flash' data='" +src+ "' width='" +width+ "' height='" +height+ "' id='" +movie+ "'>");
	document.write("<param name='movie' value='" +src+ "' />");
	document.write("<param name='wmode' value='transparent' />");
	document.write("<param name='scale' value='noborder' />");
	document.write("<param name='quality' value='high' />");
	document.write("<param name='allowScriptAccess' value='always' />");
	document.write("<embed src='http://www.flowzone.ch/pictures/layout/Dock.swf' quality='high' wmode='transparent' width='"+width+"' height='"+height+"' name='mainmenu' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
	document.write("</object>");
}

function showFlashPreview(movie) {
	olddiv_id = "view"+movie;
	div_id = "flashpreview"+movie;
	$(olddiv_id).style.visibility = "hidden";
	$(olddiv_id).style.display = "none";
	$(div_id).style.visibility = "visible";
	$(div_id).style.display = "block";
}

function preview_window(href) {
	var myprev = "";
	var mynext = "";
	var previouslink = "";
	var nextlink = "";
	mywindow = $('preview_window');
	if(mywindow) {
		// Popup sichtbar machen
		mywindow.style.visibility = "visible";
		// Automatische Gr�sse
		mywindow.style.display = "block"; 
		mypicture = new Image();
		mypicture.onload = function() {ImageOnLoaded(href);};
		mypicture.onerror = function() {ImageNotLoaded();};
		if(typeof(jsImages) != "undefined" && jsImages.length > 1) {
			for(i=0; i<jsImages.length; i++) {
				if(jsImages[i] == href) {
					break;
				}
			}
			if (i != jsImages.length-1) {
				mynext = jsImages[i+1];
			}
			else {
				mynext = jsImages[0];
			}
			if (i != 0) {
				myprev = jsImages[i-1];
			}
			else {
				myprev = jsImages[jsImages.length-1];
			}
			if(typeof(mynext) == "undefined") {
				mynext = jsImages[0];
			}

		}
	
		if(typeof(myprev) != "undefined" && myprev != "") {
			// sites = "<font class=\"textgrey\">"+(i+1)+"/"+jsImages.length+"</font>";
			previouslink = '<div onclick="preview_window(\''+myprev+'\');" style="float: left; left: 0px; text-align: left;" id="left" onmouseout="$(\'prev\').style.display = \'none\';" onmousemove="$(\'prev\').style.display = \'block\';" class="navi"><div style="display: none;" id="prev"><img border="0" alt="previous image" src="/pictures/layout/arrow-left.png"/></div></div>';
			nextlink = '<div onclick="preview_window(\''+mynext+'\');" style="float: right; right: 0px; text-align: right;" id="right" onmouseout="$(\'next\').style.display = \'none\';" onmousemove="$(\'next\').style.display = \'block\';" class="navi"><div style="display: none;" id="next"><img border="0" alt="next image" src="/pictures/layout/arrow-right.png"/></div></div>';
			mywindow.innerHTML = previouslink+nextlink;
			
		}

		// Scrollhöhe herausfinden
		if (self.pageYOffset) // all except Explorer
		{
			//y = self.pageYOffset;
			h = self.innerHeight;
			w = self.innerWidth;
		}
		else if (document.documentElement)
			// Explorer 6 Strict
		{
			//y = document.documentElement.scrollTop;
			h = document.documentElement.clientHeight;
			w = document.documentElement.clientWidth;
		}
		else if (document.body) // all other Explorers
		{
			//y = document.body.scrollTop;
			h = document.body.clientHeight;
			w = document.body.clientWidth;
		}
		
		if (w < 0){w = 0;}  
		if (h < 0){h = 0;} 

		mywindow.style.width = w+"px";
		mywindow.style.height = h+'px';
		mywindow.style.position = "fixed";
	
		mypicture.src = href;
		return false;
	}
	else {
		return true;
	}
}
function ImageOnLoaded(href) {
	mywindow.innerHTML = mywindow.innerHTML+"<a onclick='preview_window_close();'><img id=\"preview_div\" class=\"preview_window\" src='"+href+"' alt='Close'></a><br>Click image to close";

}
function ImageNotLoaded() {

	// Fehlermeldung anzeigen
	mywindow.innerHTML = "<a onclick='preview_window_close();'><img id=\"preview_div\" class=\"preview_window\" src='/pictures/layout/flowzone_bling.png' alt='Hide Picture'><p>Das Bild konnte leider nicht gefunden werden. Sorry!</p></a>";
}

function preview_window_close() {
	document.onmousemove = "";
	if(myimageborder) {myimageborder.innerHTML = "";}
	if(mywindow) {
		mywindow.style.visibility = "hidden";
		mywindow.style.display = "none"; 
		mywindow.style.width = "0px";
		mywindow.style.height = "0px";
		mywindow.style.position = "";
		mywindow.innerHTML = "";
		return false;
	}
	else {
		return true;
	}
}

function Speichern(id,value,days) {
		var a = new Date();
		a = new Date(a.getTime() +1000*60*60*24*365);
		document.cookie = id + '=' + value + "; expires="+a.toGMTString()+"; path=/;"; 
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function event_validation() {
	var mycalendarform = $('form_kalender'); 
	var errors = "";
	if (mycalendarform) {
		if(mycalendarform.elements('name').value.length == 0) {
			errors= errors + "\nDer Titel f�r diesen Event fehlt.";
		}
		if(mycalendarform.elements('datum').value.length == 0) {
			errors = errors + "\nEs muss nat�rlich auch ein Datum eingegeben werden (dd.mm.yyyy).";
		}
		myurl = mycalendarform.elements('link_url').value;
		if(!isUrl(myurl)) {
			errors = errors + "\nDie eingegebene URL ist nicht korrekt.";
		 }
		if(mycalendarform.elements('verification').value != "flowzone") {
			errors = errors + "\nDie Eingaben wurden nicht verifiziert.";
		}
		if(mycalendarform.elements('Description').value == "Schreibe hier eine Kurzbeschreibung des Events" || mycalendarform.elements('Description').value.length == 0) {
			errors = errors + "\nSo geht das also nicht... Bitte erfasse eine kurze Beschreibung dieses Events";
		}
	}
	if(errors.length != 0) {
	 	alert(errors);
		return false;
	}
	else {
		return true;
	}
}

function emoticon_post(text) {
	// ZUERST DEN TEST "HIER KANNST DU DEINE MEINUNG..." ENTFERNEN
	if(document.kommentar3.comment.value=='Hier kannst Du Deine Meinung zu diesem News-Eintrag abgeben') {
		document.kommentar3.comment.value = '';
	}
	text = ' ' + text + ' ';
	// HERAUSFINDEN, OB DER TEXT AM ENDE HINZUGEF�GT WIRD ODER ZWISCHEN DEM TEXT
	if (document.kommentar3.comment.createTextRange && document.kommentar3.comment.caretPos) {
		// SMILEY ZWISCHEN DEN TEXT SETZEN
		var caretPos = document.kommentar3.comment.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		document.kommentar3.comment.focus();
	} 
	else {
		// SMILEY AM ENDE HINZUF�GEN
		document.kommentar3.comment.value += text;
		document.kommentar3.comment.focus();
	}
}
