// JavaScript Document
function highlight(x) {
	document.getElementById(x).style.color = "#d20039";
}

function unhighlight(x) {
	document.getElementById(x).style.color = "";
}

function show(x) {
 	document.getElementById(x).style.visibility = "visible";
}

function hide(x) {
 	document.getElementById(x).style.visibility = "hidden";
}

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

adminIm = new Image();
adminIm.src = "/ratingpictures/sidemenu_col2.gif";

function collapsetable(_12) {
	if(document.getElementById("sidemenu"+_12).style.display=="none"){
		document.getElementById("sidemenu"+_12).style.display = "";
		document.getElementById("sideimage"+_12).src = "/ratingpictures/sidemenu_col2.gif";
		setSideMCookie(_12, 1);
	}
	else{
		document.getElementById("sidemenu"+_12).style.display = "none";
		document.getElementById("sideimage"+_12).src = "/ratingpictures/sidemenu_col1.gif";
		setSideMCookie(_12, 0);
	}
}
function tog_collapse(x) {
	if(document.getElementById(x).style.display == "none"){
		document.getElementById(x).style.display = "";
	}
	else{
		document.getElementById(x).style.display = "none";
	}
}

function collapse_dis(x, y){
	if(document.getElementById(x).style.display == "none"){
		document.getElementById(x).style.display = "";
		document.getElementById(y).style.display = "none";
	}
	else{
		document.getElementById(x).style.display = "none";
		document.getElementById(y).style.display = "";
	}
}

function togStatus(x){
	var cookieString = unescape(getCookie("togState"));
	if(cookieString.length != 0){
		var start = cookieString.indexOf(x+":");
		var state;
		if(start!=-1){
			state = cookieString.substr(start+x.length+1, 1);
		}
		else{
			state = 0;
		}
		return state;
	}
	return false;
}

function addtext(target,text) {
	if(document.getElementById(target).value==""){
		document.getElementById(target).value = text;
	}
	else{
		var content = document.getElementById(target).value;
		document.getElementById(target).value = content + ", " + text;
	}
}


function setSideMCookie(x,y){
	var cookieString=getCookie("togState");
	if(cookieString){
		var anfang=cookieString.indexOf(x+":");
		if(anfang!=-1){
			var _193=cookieString.substring(0,anfang+x.length+1);
			var last=cookieString.substring(anfang+x.length+2,cookieString.length);
		setCookie("togState",_193+y+last);
		}
		else{
			setCookie("togState",cookieString+x+":"+y+",");
		}
	}
	else{
		setCookie("togState",x+":"+y+",");
	}
}
function showsong(x){
	if(document.getElementById(x).style.display=="none"){
		document.getElementById(x).style.display = "";
	}
	else{
		document.getElementById(x).style.display = "none";
	}
}

function clearAlerts(panelId)
{
	var panel = document.getElementById(panelId);
	var notifier = document.createElement("div");
	notifier.className = "ClearConfirm";
	notifier.innerHTML = "<b>resetting alerts...</b>";
	notifier.style.textAlign = "center";
	panel.innerHTML = "";
	panel.appendChild(notifier);
	var myAjax = new Ajax();
	myAjax.method = "GET";
	myAjax.url = "/pages/clearalerts.php";
	myAjax.onSuccess = function(txt)
	{
		clearAlertsDone(txt, notifier);
	}
	myAjax.doRequest();
}

function clearAlertsDone(txt, panel)
{
	if ( txt == 1 )
		panel.innerHTML = "<b>alerts cleared!</b>";
	else
		panel.innerHTML = "error, alerts not cleared";
}

function subscribe(userID)
{
	var notifier = document.getElementById("SubToUser"+userID);
	notifier.innerHTML = "<b>Subscribing...</b>";
	var myAjax = new Ajax();
	myAjax.method = "GET";
	myAjax.url = "/pages/managesubscriptions.php";
	myAjax.params = "action=subscribe&userid="+userID;
	myAjax.onSuccess = function(txt)
	{
		subscribeDone(txt, notifier);
	}
	myAjax.doRequest();
}

function subscribeDone(txt, notifier)
{
	if ( txt == 1 )
		notifier.innerHTML = "<b><font color=\"green\">Subscription Successful!</font></b>";
	else
		if ( txt == 2 )
			notifier.innerHTML = "<font color=\"orange\">Already subscribed!</font>";
		else
			notifier.innerHTML = "<font color=\"red\">Error, subscription not completed.</font>";
}

function unsubscribe(subscriptionID)
{
	var notifier = document.getElementById("Unsubscribe"+subscriptionID);
	notifier.innerHTML = "<b>Cancelling subscription...</b>";
	var myAjax = new Ajax();
	myAjax.method = "GET";
	myAjax.url = "/pages/managesubscriptions.php";
	myAjax.params = "action=unsubscribe&subid="+subscriptionID;
	myAjax.onSuccess = function(txt)
	{
		unsubscribeDone(txt, notifier);
	}
	myAjax.doRequest();
}

function unsubscribeDone(txt, notifier)
{
	if ( txt == 1 )
		notifier.innerHTML = "<b><font color=\"green\">Subscription Removed.</font></b>";
	else
		notifier.innerHTML = "<font color=\"red\">Error, subscription not removed.</font>";
}
