
var mstar_on = new Image();
mstar_on.src = '/img/rate/star-on.gif';
var mstar_off = new Image();
mstar_off.src = '/img/rate/star-off.gif';

function suche() {
	document.getElementById('suchbox').style.display='inline';
}
function suche_rubrik(e) {
	var f = document.getElementById('form_suche_rubrik');
	f.action = '/suche/'+e.value; f.submit();
}
function suche_change_form(e) {
	document.getElementById('form').value = e.value;
	document.getElementById('form_suche_rubrik').submit();
}

function music_rate(j) { // kann dann weg
	for(var i=1;i<=5;i++) {
		var sta = i<=j ? mstar_on.src : mstar_off.src;
		document.getElementById('mrate'+i).src = sta;
	}
}

var star_on = new Image(); star_on.src = '/img/rate/star-on.gif';
var star_off = new Image(); star_off.src = '/img/rate/star-off.gif';

function rate(id,s) {
	for(var i=1;i<=5;i++) {
		var sta = i<=s ? star_on.src : star_off.src;
		document.getElementById('star_'+id+'_'+i).src = sta;
	}
}

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}
function display_form(f,s) {
	var s1 = s==1 ? 'none' : 'block';
	var s2 = s==1 ? 'block' : 'none';
	document.getElementById('form_msg_'+f).style.display='none';
	document.getElementById('form_new_button_'+f).style.display=s1;
	document.getElementById('form_new_'+f).style.display=s2;
}
function display_element(id) {
	var e = document.getElementById(id);
	var display_on = id == 'tr_d_plz' ? 'table-row' : 'block';
	if (e.style.display == 'none') { e.style.display = display_on; }
	else { e.style.display = 'none'; }
}
function fill_container(elem,str) {
	var e = document.getElementById(elem);
	e.innerHTML = str;

}

function save_and_upload(form) {
	if (form.name == 'form_edit_music') {
		if (document.getElementById('no_rights_harmed').checked == false) { alert('Bitte versichere, dass der Song von Dir stammt!'); return false; }
	}
	window.scrollTo(0,0);
	document.getElementById('wait_upload').style.display = 'block';
	document.getElementById('upload').className = 'transp';
	var eu = document.getElementById(form.name);
	//for(i=0;i<eu.length;i++) { if (eu[i].name != 'act' && eu[i].name != 'img_upload') { eu[i].disabled = true; } }
	if (form.name == 'form_edit_user') {
		if (document.getElementById('img_upload').value != null && document.getElementById('img_upload').value != '') {
			document.getElementById('wait_noimg').style.display = 'none';
			document.getElementById('wait_img').style.display = 'inline';
		}
	}
	return true;
}

function confirm_it(item) {
	return confirm(item);
}

function fill_empty_input(elem,act,soll) {
	if (act == "empty") { if (elem.value == soll) { elem.value = ""; } }
	else { if (elem.value == "") { elem.value = soll; } }
}

var music_sel_id = false;
function music_play(s,w,h,r) {
	if (music_sel_id != s) {
		if (music_sel_id != false) {
			var e = document.getElementById('fp'+music_sel_id);
			e.style.display = 'none';
			e.innerHTML = '';
			document.getElementById('ap'+music_sel_id).style.backgroundColor = '#DAD4CE';
		}
		var e = document.getElementById('fp'+s);
		var q = 'song='+s;
		e.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+w+'" height="'+h+'" id="player"><param name="movie" value="/img/music/player.swf?'+q+'"><param name="FlashVars" value="'+q+'"><param name="wmode" value="opaque"><param name="quality" value="high"><param name="bgcolor" value="#ffffff"><embed src="/img/music/player.swf?'+q+'" quality="high" bgcolor="#ffffff" wmode="opaque" width="'+w+'" height="'+h+'" name="player" flashvars="'+q+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
		if (r!=0) {
			e.innerHTML += '<div id="ratings" style="float:right"></div>';
			ajx('/public/ajax.php?c1=specials&c2=rate&c3='+r+'&c5=mu','ratings');
		}
		e.style.display = 'block';
		music_sel_id = s;
		document.getElementById('ap'+s).style.backgroundColor = '#A4927A';
	}
	return false;
}

function adressbook_goto() {
	document.getElementById('form_msg').action = '/messages/addressbook';
	document.getElementById('form_msg').submit();
}

var to_modi = new Array('to','cc','bcc');
function adressbook_check_sel(n,m) {
	var s=document.getElementById(m+n).checked;
	if (s==true) {
		for(var i=0;i<to_modi.length;i++) {
			if (m != to_modi[i]) {
				var e=document.getElementById(to_modi[i]+n); if (e.checked == true) { e.checked = false; }
			}
		}
	}
}

function peach_user(user) {
	var text_peach = document.getElementById('text_peach').value;
	if (text_peach != '') {
		ajx('/public/ajax.php?c1=peach&c2='+user+'&text_peach='+escape(text_peach),'peach');
	}
	else {
		alert('Bitte gib uns einen kurzen Hinweis!');
	}
	return false;
}

var http_request = false;
var my_ajax_container = false;
function ajx(myurl,mycontainer) {
	http_request = false;
	if (window.XMLHttpRequest) { http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); } }
	else if (window.ActiveXObject) { try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } }
	if (http_request) { my_ajax_container = mycontainer; http_request.onreadystatechange = ajax_fill_container; http_request.open("GET",myurl,true); http_request.send(null); }
	else {}
}
function ajx_post(myurl,mycontainer) {
	http_request = false;
	if (window.XMLHttpRequest) { http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); } }
	else if (window.ActiveXObject) { try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } }
	if (http_request) { my_ajax_container = mycontainer; http_request.onreadystatechange = ajax_fill_container; http_request.open('POST','/public/ajax.php',true); http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');http_request.setRequestHeader("Content-length", parameters.length);http_request.setRequestHeader("Connection", "close");http_request.send(myurl); }
	else {}
}
function ajax_fill_container() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) { if (http_request.responseText.length > 0) {
			var mycontent = http_request.responseText;
			if (mycontent.substr(0,5) == '/pin/') {
				document.getElementById(my_ajax_container).innerHTML = '';
				window.location.href=mycontent;
			}
			else if (mycontent.substr(0,9) == 'pin-memo/') {
				document.getElementById(my_ajax_container).innerHTML = '';
				memo_post_new(mycontent);
			}
			else if (mycontent.substr(0,10) == 'newsletter') {
				var arr_q = mycontent.split('|');
				document.getElementById(my_ajax_container).innerHTML = arr_q[1];
				if (arr_q[2] != 0) {
					ajx(arr_q[2],'fortschritt');
				}
				else {
					document.getElementById('senden').innerHTML = 'Versand beendet';
				}
			}
			else if (mycontent == 'display=none') {
				document.getElementById(my_ajax_container).style.display = 'none';
			}
			else if (mycontent != 'void') {
				document.getElementById(my_ajax_container).innerHTML = mycontent;
			}
		} }
		else {}
	}
}

var update_online_status_minutes = 1;
var update_online_status_ms = update_online_status_minutes*60*1000;
var http_request_os = false;
function update_online_status() {
	var myurl = '/public/update_online_status.php';
	if (window.XMLHttpRequest) { http_request_os = new XMLHttpRequest(); if (http_request_os.overrideMimeType) { http_request_os.overrideMimeType('text/xml'); } }
	else if (window.ActiveXObject) { try { http_request_os = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request_os = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } }
	if (http_request_os) { http_request_os.onreadystatechange = reload_update_online_status; http_request_os.open("GET", myurl, true); http_request_os.send(null); }
}

function reload_update_online_status() { if (http_request_os.readyState == 4) { if (http_request_os.status == 200) { if (http_request_os.responseText == 1) { timer_online_status = setTimeout("update_online_status()",update_online_status_ms); } else { window.location.href='/'; } } } }

function tranq(f,u) {
	m = new Array("&#105;","&#116;","&#111;","&#109;","&#97;","&#108;");
	document.write("<a href="+m[3]+m[4]+m[0]+m[5]+m[1]+m[2]+"&#58;"+u+"&#64;"+f+">");
	document.write(u+"&#64;"+f+"</a>");
}

function checkall(form) { var e = document.getElementById(form); for (var x=0; x<e.elements.length; x++) { var y=e.elements[x]; if (y.name != 'all') { y.checked=e.all.checked; } } }

var dragobjekt = null; var dragx = 0; var dragy = 0; var posx = 0; var posy = 0;
function draginit() { document.onmousemove = drag; document.onmouseup = dragstop; }
function dragstart(element) { dragobjekt = element; dragx = posx - dragobjekt.offsetLeft; dragy = posy - dragobjekt.offsetTop; }
function dragstop() { dragobjekt=null; }
function drag(ereignis) { posx = document.all ? window.event.clientX : ereignis.pageX; posy = document.all ? window.event.clientY : ereignis.pageY; if(dragobjekt != null) { dragobjekt.style.left = (posx - dragx) + "px"; dragobjekt.style.top = (posy - dragy) + "px"; } }

var z_index = 10;
function z_index_up(e) {
	z_index++;
	e.style.zIndex = z_index;
}

function insert_code(id,tag1,tag2) {
	var input = document.getElementById(id);
	input.focus();
	if (typeof document.selection != 'undefined') {
		var range = document.selection.createRange();
		var insText = range.text;
		range.text = tag1 + insText + tag2;
		range = document.selection.createRange();
		if (insText.length == 0) { range.move('character', -tag2.length); }
		else { range.moveStart('character', tag1.length + insText.length + tag2.length); }
		range.select();
	}
	else if (typeof input.selectionStart != 'undefined') {
		var start = input.selectionStart;
		var end = input.selectionEnd;
		var insText = input.value.substring(start, end);
		input.value = input.value.substr(0, start) + tag1 + insText + tag2 + input.value.substr(end);
		var pos;
		if (insText.length == 0) { pos = start + tag1.length; }
		else { pos = start + tag1.length + insText.length + tag2.length; }
		input.selectionStart = pos;
		input.selectionEnd = pos;
	}
	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) + tag1 + insText + tag2 + input.value.substr(pos);
	}
}
var moving_div_id = false;
var moving_div_x_offset = 0;
var moving_div_y_offset = 0;
function getMousePosition(e) {
	if (moving_div_id != false) {
		var _x; var _y;
		if (document.all) { _x = event.clientX; _y = event.clientY; }
		else { _x = e.pageX; _y = e.pageY; }
		document.getElementById(moving_div_id).style.top  = _y + moving_div_y_offset + 'px';
		document.getElementById(moving_div_id).style.left = _x + moving_div_x_offset + 'px';
	}
	return true;
}

if (window.location.href.indexOf('mumate.com/pin') != -1) {
	draginit();
}
else {
	var timer_online_status = setTimeout("update_online_status()",update_online_status_ms);
}

function navi_new_mumates(page) {
	fill_container('numates_navi','<img src="/img/misc/ladekreis.gif" width="14" height="14" />');
	ajx('/public/ajax.php?c1=numates&c2='+page,'numates');
}
function navi_suche(e) {
	document.getElementById('page').value = e.value;
	document.getElementById('form_suche_rubrik').submit();
}
