if (window.XMLHttpRequest){
		var xmlHttp = new XMLHttpRequest()
	}
	else if (window.ActiveXObject){
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	

function counterUpdate(opt_countedTextBox, opt_countBody, opt_maxSize) {

        var countedTextBox = opt_countedTextBox ? opt_countedTextBox : "counttxt";
        var countBody = opt_countBody ? opt_countBody : "countBody";
        var maxSize = opt_maxSize ? opt_maxSize : 1024;
alert(countedTextBox);
        var field = document.getElementById(countedTextBox);
        
        //alert(document.getElementById(countedTextBox).value);

        if (field && field.value.length >= maxSize) {
                field.value = field.value.substring(0, maxSize);
        }
        
        var txtField = document.getElementById(countBody);
                if (txtField) {
                txtField.innerHTML = field.value.length;
        }
}

function leaveANote(userid,tributeid) {

	if($('#commmentInput').css("display") == "none" && $('#commmentInput').text() != '') {
		$('#commmentInput').css("display","block");
		return;
	} else if($('#commmentInput').css("display") == "block") {
		$('#commmentInput').css("display","none");
		return;		
	} else {
		$('#commmentInput').append("<form enctype=\"application/x-www-form-urlencoded\"><label for=\"ename\">Your Name:</label><input type=\"text\" name=\"eName\" id=\"ename\" value=\"\" /><br /><label for=\"econtent\">Your Note:</label><textarea name=\"econtent\" id=\"econtent\"></textarea><br /><button id=\"submitComment\" type=\"button\" onclick=\"submitNote(" + userid + "," + tributeid + ")\">submit</button></form>");
		$('#commmentInput').css("display","block");
	}
}


function showNotes(tid) {
	if($('#commmentDisplay').css("display") == "block") {
		$('#commmentDisplay').css("display","none"); return;
	}

	$('#commmentDisplay').css("display","block");
	
	if(tid == "") {
		$('#commmentDisplay').append("<p class=\"missingInfo\">No valid tribute id.</p>");
	} else if($('#commmentDisplay').text() == '') {
		//var url = "http://www.otrib.com/tributes/notes.php?tributeid=" + tid + "&currentuser=0&status=show";
		var randomnumber=Math.floor(Math.random()*10001)
		var url = "../tributes/notes.php?tributeid=" + tid + "&currentuser=0&status=show&random=" + randomnumber;
		xmlHttp.open("GET", url, true);
		xmlHttp.onreadystatechange = stateChangedShowNotes;
		xmlHttp.send(null);
	}
}

function submitNote(user,tid){

		var ename = $('#ename').val();
		var econtent = $('#econtent').val();

		econtent = escape(econtent);
		if($('#ename').val()=="" && $('#econtent').val()==""){

				$('#commmentInput').append("<p class=\"missingInfo\">Please, enter a note.</p>");

			}
		else{
				//var url = "http://www.otrib.com/tributes/notes.php?tc_enteredName=" + ename + "&tc_content=" + econtent + "&currentuser=" + user + "&tributeid=" + tid + "&status=insert";
				var url = "../tributes/notes.php?tc_enteredName=" + ename + "&tc_content=" + econtent + "&currentuser=" + user + "&tributeid=" + tid + "&status=insert";
				xmlHttp.open("GET", url, true);
				xmlHttp.onreadystatechange = stateChangedSubmitNote;
				//xmlHttp.send("tc_enteredName=" + ename + "&tc_content=" + econtent + "&currentuser=" + user + "&tributeid=" + tid + "&status=insert");
				xmlHttp.send(null);
			}
		}

function stateChangedSubmitNote(){

		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{
				$('#commmentInput').find('#loadingPic').remove();
				$('#commmentInput').fadeIn("slow");
				$('#commmentInput').empty().append(xmlHttp.responseText);
			}
			else{
				$('#commmentInput').empty().append('<img src=\"http://www.otrib.com/_images/loading.gif\" id=\"loadingPic\" alt=\"Loading\" border=\"0\" />');
				}

	}

function stateChangedShowNotes(){

		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{
				$('#commmentDisplay').find('#loadingPic').remove();
				$('#commmentDisplay').append(xmlHttp.responseText);
			}
			else{
				$('#commmentDisplay').empty().append('<img src=\"http://www.otrib.com/_images/loading.gif\" id=\"loadingPic\" alt=\"Loading\" border=\"0\" />');
				}

	}

function setNoteAsOnline(tc_id,user_id){
		var url = "../tributes/manage/notes.php?noteid=" + tc_id + "&status=online&currentuser=" + user_id;
		xmlHttp.open("GET", url, false);
		xmlHttp.send(null);
		$('#'+tc_id).removeClass("offline2");
		$('#'+tc_id).empty();
		$('#'+tc_id).append("ON");
		$('#'+tc_id).addClass("active2");
		$('#'+tc_id).attr("title","currently on");
		$('#'+tc_id).attr("onclick","setNoteAsOffline("+ tc_id + ","+ user_id +")");
	}

function setNoteAsOffline(tc_id,user_id){
		var url = "../tributes/manage/notes.php?noteid=" + tc_id + "&status=offline&currentuser=" + user_id;
		xmlHttp.open("GET", url, false);
		xmlHttp.send(null);
		$('#'+tc_id).removeClass("active2");
		$('#'+tc_id).empty();
		$('#'+tc_id).append("OFF");
		$('#'+tc_id).addClass("offline2");
		$('#'+tc_id).attr("title","make it available");
		$('#'+tc_id).attr("onclick","setNoteAsOnline("+ tc_id + ","+ user_id +")");
	}

function removeNote(tc_id,user_id){

		var url = "../tributes/manage/notes.php?noteid=" + tc_id + "&status=remove&currentuser=" + user_id;
		xmlHttp.open("GET", url, false);
		xmlHttp.send(null);
		$('#'+tc_id + '-l').slideUp("slow");
	}
