function EffectToggle(id,suff) {
	new Effect.toggle(id,{afterFinish: toggleImage(id,suff)});
}

function myToggle (id,suff) {
	if(myid = $(id)) {
		var visible = (myid.style.display ? '' : 'none');
		myid.style.display = visible;
		toggleImage(id,suff);
	}
}

function toggleImage (id,suff) {
		
	if(document.getElementById('img_'+ id)) {
		h = document.images['img_'+ id].src;
		if (h.substring(h.length-8, h.length) == 'plus.'+ suff) {
			document.images['img_'+ id].src = h.substring(0, h.length-8) + 'minus.'+ suff;
		} else if (h.substring(h.length-9, h.length) == 'minus.'+ suff) {
			document.images['img_'+ id].src = h.substring(0, h.length-9) + 'plus.'+ suff;
		}
	}
}

function ss(id) {

	var sBasePath = "/extlibs/FCKeditor/";
	var oFCKeditor = new FCKeditor(id);
	oFCKeditor.BasePath = sBasePath;
	oFCKeditor.Height = 200;
	oFCKeditor.ToolbarSet  = 'Default';
	oFCKeditor.Config['SkinPath']= sBasePath +"editor/skins/silver/";
	oFCKeditor.Config["AutoDetectLanguage"] = true ;
//	oFCKeditor.Config["DefaultLanguage"]    = "de" ;
	oFCKeditor.ReplaceTextarea();
//	oFCKeditor.Create();

}

function getContents(id) {
	
	var myValues = new Array(8);
	
	//SELECT BOXES
	if(c1 = xajax.$('editor_c1_'+ id))
		myValues[0] = c1.value;
	if(c2 = xajax.$('editor_c2_'+ id))
		myValues[1] = c2.value;
	if(c3 = xajax.$('editor_c3_'+ id))
		myValues[2] = c3.value;
	
	myValues[7] = xajax.$('input_ispoll_'+ id).value;
	
	if(myValues[7] == 1) {
		
		myValues[3] = xajax.$('poll_title_'+ id).value;
		myValues[4] = xajax.$('poll_text_'+ id).value;
		
	} else {
	
		myValues[3] = xajax.$('editor_title_'+ id).value;
		
		var oEditor = FCKeditorAPI.GetInstance('editor_'+ id);
		myValues[4] = oEditor.GetXHTML( true );
		
	}

	myValues[5] = (xajax.$('cb_notification_'+ id).checked) ? 1 : 0;
	
	if(c6 = xajax.$('cb_subscribe_'+ id))
		myValues[6] = c6.checked ? 1 : 0;

	
	return myValues;
	
}

function getVote() {

	for (counter = 0; counter < document.form_vote.vote.length; counter++) {

		if(myElem = document.getElementById('vote_'+ counter)) {
			if(myElem.checked == true) {
				return myElem.value;
			}
		} else {
			//return false;
		}
	}
}

function addOption(elem,txt,val) {
	
	var opt = document.createElement("option");
	xajax.$(elem).options.add(opt);
	opt.text		= txt;
	opt.value 	= val;
	
}

function switchEditMode (elem,id,entryid) {
	
	var e1 = 'editor_'+ id +'_'+ entryid;
	var e2 = 'poll_'+ id +'_'+ entryid;
	
	if(elem == e1) {
		
		xajax.$(e1 +'_div').style.display = '';
		xajax.$(e2 +'_div').style.display = 'none';
		
		xajax.$(e1 +'_tab').className = 'activeTabMenu';
		xajax.$(e2 +'_tab').className = '';
		
	} else {
	
		xajax.$(e1 +'_div').style.display = 'none';
		xajax.$(e2 +'_div').style.display = '';
		
		xajax.$(e1 +'_tab').className = '';
		xajax.$(e2 +'_tab').className = 'activeTabMenu';
	
	}

}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

function str_replace(search, replace, subject) {
	return subject.split(search).join(replace);
}

function formatACList (oResultItem, sQuery) {
	
	var sResult 		= oResultItem[0].trim();
	var sTitle 			= oResultItem[0];
	var iEntryID 		= oResultItem[1];
	
	var aSplitQuery	= sQuery.split(" ");
	
	var i,iStart,sNewQuery;
	
	try {
		var test = aSplitQuery[0];
		
		for(i = 0;i < aSplitQuery.length; i++) {
			
			if(aSplitQuery[i].length > 0) {
			
				iStart = sResult.toLowerCase().indexOf(aSplitQuery[i].toLowerCase());
				if(iStart != -1) {
					sNewQuery = sResult.substr(iStart, aSplitQuery[i].length);
					sResult = str_replace(sNewQuery,"~~~"+ sNewQuery +"###",sResult);
					//alert(aSplitQuery[i] +' -> '+ iStart +' -> '+ sNewQuery +' -> '+ sResult);
				}
			}
		}
	} catch(e) {
		
		iStart = sResult.toLowerCase().indexOf(sQuery.toLowerCase());
		if(iStart != -1) {
			sNewQuery = sResult.substr(iStart, sQuery.length);
			sResult = str_replace(sNewQuery,"~~~"+ sNewQuery +"###",sResult);
			//alert(aSplitQuery[i] +' -> '+ iStart +' -> '+ sNewQuery +' -> '+ sResult);
		}
		
	};  

	sResult = str_replace("~~~","<span class='query'>",sResult);
	sResult = str_replace("###","</span>",sResult);
	
	var aMarkup = ["<div class='result' title='"+ sTitle +"'>",
		sResult,
		"</div>"];
	
	return (aMarkup.join(""));
	
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}


function selectCode(a) {
	
	var e = a.parentNode.nextSibling;

	// Not IE
	if (window.getSelection) {
		var s = window.getSelection();
		// Safari
		if (s.setBaseAndExtent) {
			s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
		}
		// Firefox and Opera
		else {
			var r = document.createRange();
			r.selectNodeContents(e);
			s.removeAllRanges();
			s.addRange(r);
		}
	}
	// Some older browsers
	else if (document.getSelection) {
		var s = document.getSelection();
		var r = document.createRange();
		r.selectNodeContents(e);
		s.removeAllRanges();
		s.addRange(r);
	}
	// IE
	else if (document.selection) {
		var r = document.body.createTextRange();
		r.moveToElementText(e);
		r.select();
	}
}

function searchWithinNode(node, te, len) {

	var count=0,pos, skip, spannode, middlebit, endbit, middleclone;
	skip=0;
	
	if( node.nodeType == 3 ) {
		pos = node.data.toUpperCase().indexOf(te);
		if(pos >= 0) {

			spannode=document.createElement("SPAN");
			spannode.style.backgroundColor="yellow";
			middlebit=node.splitText(pos);
			endbit=middlebit.splitText(len);
			middleclone=middlebit.cloneNode(true);
			spannode.appendChild(middleclone);
			middlebit.parentNode.replaceChild(spannode,middlebit);
			++count;
			skip=1;
		}
	} else if(node.nodeType==1 && node.childNodes && node.tagName.toUpperCase() != "SCRIPT" && node.tagName.toUpperCase != "STYLE"){
		for (var child=0; child < node.childNodes.length; ++child){
			child = child+searchWithinNode(node.childNodes[child], te, len);
		}
	}
	return skip;
}

function doHighlight(bodyText, searchTerm){
	var highlightStartTag = "<span class=\"highlighter\">";
	var highlightEndTag = "</span>";
	var newText = "";
	var i = -1;
	var lcSearchTerm = searchTerm.toLowerCase();
	var lcBodyText = bodyText.toLowerCase();
	while (bodyText.length > 0) {
		i = lcBodyText.indexOf(lcSearchTerm, i+1);
		if (i < 0) {
			newText += bodyText;
			bodyText = "";
		} else {
			if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
				if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
					newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
					bodyText = bodyText.substr(i + searchTerm.length);
					lcBodyText = bodyText.toLowerCase();i = -1;
				}
			}
		}
	}
	return newText;
}
function highlightTerms(searchText){
	var bodyText = document.body.innerHTML;
	bodyText = doHighlight(bodyText, searchText);document.body.innerHTML = bodyText;
	return true;
}
function getHighlightQuery(){
	
	if(window.location.search != ""){
		QUERYSTRING = window.location.search
		QUERYSTRING = QUERYSTRING.replace(/\?/,"");
		QUERYSTRING = unescape(QUERYSTRING);
		var parts = QUERYSTRING.split("=");
		if(parts[0] == "highlight"){
			QUERYSTRING = parts[1];
			QUERYSTRING = QUERYSTRING.replace(/\s/gi,"");
			QUERYSTRING = QUERYSTRING.replace(/\+/gi,"");
			highlightTerms(QUERYSTRING);
		} else {
			return false
		}
	}
}
function preload () {
    document.myPreload = new Array();
    if(document.images) {
        for(var i = 0; i < preload.arguments.length; i++) {
            document.myPreload[i] = new Image();
            document.myPreload[i].src = preload.arguments[i];
        }
    }
}