function changeInnerHTML(id, text){
	document.getElementById(id).innerHTML = text;
}

function toggleVisibility(elmt){
	$(elmt).toggle();
}

function updateITGscore(song_id){
	var myTable = document.getElementByID('itgtable');
	myTable.insertRow();
	var myRow = myTable.rows[myTable.rows.length];
}

function update_song_selection(td_id){
	if (td_id == "song1td"){
		var current_index = document.challengeladder.song_1.selectedIndex;
		var song = document.challengeladder.song_2.selectedIndex;
		var st = document.challengeladder.song_2[song].text;
		
		if (current_index > song) {
			var ci = current_index - 1;
		} else {
			var ci = current_index;
		}
	} else {
		var current_index = document.challengeladder.song_2.selectedIndex;
		var song = document.challengeladder.song_1.selectedIndex;
		var st = document.challengeladde.song_1[song].text;
		
	}
	
	var params = "td_id="+td_id+"&song_title="+st+"&current_index="+ci;
	
	new Ajax.Updater(td_id,"../itg/updatesonglist.php",
		{
			method: 'post',
			parameters: params,
		}
	);

}

function deletePost(post_id, deleter){
	var params = "post_id="+post_id+"&deleter="+deleter;
	
	var sure = confirm("Are you sure you want to delete this post?")
	
	if(sure){
		new Ajax.Updater("post_id_"+post_id,"../!pbr42boc8/delete.php",
			{
				method: 'post',
				parameters: params,
			}
		);
	}
}

function editPost(post_id,editor){
	var params = "post_id="+post_id+"&editor="+editor;
	new Ajax.Updater("post_id_"+post_id,"editPost.php",
		{
			method: "post",
			parameters: params,
		}
	);
}

function do_ep(post_id,form_elmt){
	var params = $(form_elmt).serialize(true);
	new Ajax.Updater("post_id_"+post_id,"ep.php",
		{
			method: "post",
			parameters: $(form_elmt).serialize(true)
		}
	);
}

function dont_do_ep(post_id,form_elmt){
	var params = $(form_elmt).serialize(true);
	new Ajax.Updater("post_id_"+post_id,"noep.php",
		{
			method: "post",
			parameters: $(form_elmt).serialize(true)
		}
	);
}

function doUpdate(row_elmt,form_elmt){
	var params = $(form_elmt).serialize(true);
	new Ajax.Updater("data_"+row_elmt,"es.php",
		{
			method: "post",
			parameters: $(form_elmt).serialize(true),
			onSuccess: function(){
				toggleVisibility(row_elmt);
						}
		}
	);
}

function doLikeUpdate(post_id,like_action){
	var params = "post_id="+post_id+"&like_action="+like_action;
	new Ajax.Updater("like_count_"+post_id, "like.php",
		{
			method: "post",
			parameters: params,
			onSuccess: function(){
				updateLike(post_id,like_action);
						}
		}
	);
}

function updateLike(post_id,like_action){
	if (like_action == 0){
		var link = "javascript:doLikeUpdate("+post_id+",1)";
		document.getElementById("like_"+post_id).setAttribute("href", link);
		document.getElementById("like_"+post_id).innerHTML = "<img src=\"http://www.stayonsync.com/images/buttons/like.png\" />";
	}
	else if (like_action == 1){
		var link = "javascript:doLikeUpdate("+post_id+",0)";
		document.getElementById("like_"+post_id).setAttribute("href", link);
		document.getElementById("like_"+post_id).innerHTML = "<img src=\"http://www.stayonsync.com/images/buttons/unlike.png\" />";
	}
}

function showResponse(req, elmt){
	$('data_'+elmt).innerHTML= req.responseText;
}

function goToPage(x){
	window.location.href = x; 
}

function quote(postid){
	var msgbox = document.getElementById("msgbox");
	
	var params = 'post=' + postid + '&msg=' + msgbox.value;
	
	new Ajax.Request("../forum/quote.php",
			{
				method: 'post',
				parameters: params,
				onSuccess: function(t){
					msgbox.value += t.responseText;
				}
			}
		);
	
	msgbox.focus();
}

function startScore(score, band){
	var params = 'score=' + score + "&band=" + band;
	
	var scoree = "score" + score;
	
	var update = "update" + score;
	
	toggleVisibility(scoree);
	
	document.getElementById(scoree).innerHTML = '<img src="../images/1gif.gif" alt="loading" />';
	
	new Ajax.Updater(scoree, "bandTab/startNewScore.php",
		{
			method: "post",
			parameters: params
		}
	);
}

function markTopic(topic, user){
	var params = 'topic=' + topic + '&user=' + user + '&always=1';
	
	new Ajax.Updater("always", "../forum/always.php",
		{
			method: 'post',
			parameters: params
		}
	);
}

function unmarkTopic(topic, user){
	var params = 'topic=' + topic + '&user=' + user + '&always=0';
	
	new Ajax.Updater("always", "../forum/always.php",
		{
			method: 'post',
			parameters: params
		}
	);
}

function updatePPP(form_elmt){
	var params = $(form_elmt).serialize();
	
	new Ajax.Request("../forum/updatePPP.php",
		{
			method: 'post',
			parameters: params,
			onSuccess: function(t){
				alert(t.responseText);
			}
		}
	);
}

function test(){
	alert("hello");
}

function showPM(id){		
	var params = 'msgid=' + id;
	
	var msg = "msg" + id;
	
	var subject = "subject" + id;
	
	toggleVisibility(msg);
	
	document.getElementById(msg).innerHTML = '<img src="../images/1gif.gif" alt="loading" />';
	
	new Ajax.Request("user/readCheck.php",
		{
			method: "post",
			parameters: params,
			onSuccess: function(t){
				if(t.responseText != 99999){
					document.getElementById(subject).innerHTML = t.responseText;
				}
			}
		}
	);
	
	new Ajax.Updater(msg, "user/getPost.php",
		{
			method: "post",
			parameters: params
		}
	);
}
