function setAlert(x){
	//alert(x);
}

function KeepAlive(){
	AJAX({url: '/index.php?ajaxaction=keepalive',
			type: "html",
			timeout: 60000,
			onSuccess: function(){
					window.setTimeout("KeepAlive()", 60000);
				}
		    });
}


function CreateBookmark() {

	 title =  document.title; 
	 url = document.location.href;

		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title); }
		else if(window.opera && window.print) { // Opera Hotlist
			return true; }
 }


function GetLeftOffset(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
	do {
		curleft += obj.offsetLeft;
		} while (obj = obj.offsetParent);
	}
	return curleft+1;
}

function GetTopOffset(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
	do {
		curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return curtop+1;
}

function GetWidth(obj){
	return obj.offsetWidth+1;
}

function ShowLanguageSelector(show){
	var button = document.getElementById('language_button');
	if(button){
		var el = document.getElementById('language_select');
		if(el){
			setAlert(GetLeftOffset(button));
			el.style.marginLeft = GetLeftOffset(button) + 'px';
			el.style.width = GetWidth(button) + 'px';
			el.style.visibility = show ? 'visible' : 'hidden';
		}	
	}
}

function ShowBookmarkSelector(show){
	var button = document.getElementById('bookmark_button');
	if(button){
		var el = document.getElementById('bookmark_select');
		if(el){
			
			el.style.marginLeft = GetLeftOffset(button) + 'px';
			el.style.width = GetWidth(button) + 'px';
			el.style.visibility = show ? 'visible' : 'hidden';
		}
	}
}

function UpdateDateDropDown(id){
	var el_day = document.getElementById(id+'_day');
	var el_month = document.getElementById(id+'_month');
	var el_year = document.getElementById(id+'_year');
	
	var current_day = el_day.value;
	var days = daysInMonth(el_month.value-1, el_year.value);
	
	if (current_day > days) current_day = days;
	
	el_day.options.length = 1;
	
	var dt = '';
	for(d=1;d<=days;d++){
		dt = d;
		if(dt < 10) dt = '0'+dt;
		el_day.options[el_day.options.length] = new Option(dt,d);
	}
	el_day.value = current_day;
}

function daysInMonth(iMonth, iYear){
	return 32 - new Date(iYear, iMonth, 32).getDate();
}

/*
function doIframe(){
	o = document.getElementsByTagName('iframe');
	for(i=0;i<o.length;i++){
		if (/\bautoHeight\b/.test(o[i].className)){
			setHeight(o[i]);
			addEvent(o[i],'load', doIframe);
		}
	}
}

function setHeight(e){
	if(e.contentDocument){
		e.height = e.contentDocument.body.offsetHeight;
	} else {
		e.height = e.contentWindow.document.body.scrollHeight;
	}
}

function addEvent(obj, evType, fn){
	if(obj.addEventListener)
	{
	obj.addEventListener(evType, fn,false);
	return true;
	} else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
	return r;
	} else {
	return false;
	}
}


if (document.getElementById && document.createTextNode){
 addEvent(window,'load', doIframe);	
}

*/


function AlertDialog(title, msg){
	document.getElementById('confirm_dialog_cancel_button').style.visibility = 'hidden';
	document.getElementById('confirm_dialog_ok_button').style.visibility = 'visible';
	document.getElementById('confirm_dialog_ok_button').onclick = CloseConfirmDialog;
	document.getElementById('confirm_dialog').style.visibility = 'visible';
}

function ConfirmDialog(title,msg,callback){
	document.getElementById('confirm_dialog_title').innerHTML = title;
	document.getElementById('confirm_dialog_msg').innerHTML = msg;
	document.getElementById('confirm_dialog_cancel_button').style.visibility = 'visible';
	document.getElementById('confirm_dialog_ok_button').style.visibility = 'visible';
	document.getElementById('confirm_dialog_ok_button').onclick = callback;
	document.getElementById('confirm_dialog').style.visibility = 'visible';
}

function CloseConfirmDialog(){
	document.getElementById('confirm_dialog').style.visibility = 'hidden';
	document.getElementById('confirm_dialog_cancel_button').style.visibility = 'hidden';
	document.getElementById('confirm_dialog_ok_button').style.visibility = 'hidden';
}

function DoAction(action, id, confirmtext){
	var doaction = true;
	if(confirmtext && confirmtext.length && confirmtext.length > 0) doaction = confirm(confirmtext);
	if(doaction){
		var f = '<form action="'+base+'index.php" method="post" id="frmOnTheFly">'+
			'<input type="hidden" name="action" value="'+action+'">'+
			'<input type="hidden" name="id" value="'+id+'">'+
			'</form>';
		document.body.innerHTML=f;
		var el;
		el=document.getElementById('frmOnTheFly')
		if (el) el.submit();
	}
}


var Selection = null;

function BBCode(id, aTag, eTag, defaulttext) {
  var input = document.getElementById(id);
  if(!input) return;
  
   
  input.focus();
  /* Internet Explorer */
  if(typeof document.selection != 'undefined') {
    var range = null;
    if(Selection != null){
    	range = Selection;
    }else{
    	range = document.selection.createRange();
    }
    var insText = range.text;
    if (insText.length == 0 && defaulttext) insText = defaulttext;
    range.text = aTag + insText + eTag;
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);      
    }
    range.select();
  }
  /* Gecko based Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    if (insText.length == 0 && defaulttext) insText = defaulttext;
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* other Browser */
  else
  {
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
  }
  if(textCounter) textCounter();
  HideAllForumSubMenus();
  Selection=null;
}



function HideAllForumSubMenus(){
	ShowForumColors(false);
	ShowForumEmoticons(false);
	ShowForumLink(false);
	ShowForumImage(false);
	ShowForumVideo(false);
}


function SaveCursorData(){
	if(typeof document.selection != 'undefined') {
		var el = document.getElementById('forum_post_text');
		el.focus();
		var range = document.selection.createRange();
		Selection = range.duplicate();
	}
}

function ShowForumColors(show){
	if(show){
		SaveCursorData();
		HideAllForumSubMenus();
	} 
		
	var el = document.getElementById('forum_post_bbcode_dlg_color');
	if(el) el.style.display = (show ? 'block' : 'none');
}

function ShowForumEmoticons(show){
	if(show){
		SaveCursorData();
		HideAllForumSubMenus();
	} 
	var el = document.getElementById('forum_post_bbcode_dlg_emoticon');
	if(el) el.style.display = (show ? 'block' : 'none');
}
function ShowForumLink(show){
	if(show){
		SaveCursorData();
		HideAllForumSubMenus();
	} 
	var el = document.getElementById('forum_post_bbcode_dlg_link');
	if(el) el.style.display = (show ? 'block' : 'none');
}
function ShowForumImage(show){
	if(show){
		SaveCursorData();
		HideAllForumSubMenus();
	} 
	var el = document.getElementById('forum_post_bbcode_dlg_img');
	if(el) el.style.display = (show ? 'block' : 'none');
}

function ShowForumVideo(show){
	if(show){
		SaveCursorData();
		HideAllForumSubMenus();
	} 
	var el = document.getElementById('forum_post_bbcode_dlg_video');
	if(el) el.style.display = (show ? 'block' : 'none');
}

String.prototype.count=function(s1) { 
	return (this.length - this.replace(new RegExp(s1,"g"), '').length) / s1.length;
}
