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

function leaveANote(userid,linkid) {
	if($('#commmentInput').css("display") == "block") {
		$('#commmentInput').css("display","none");
		return;
	}
	
	if($('#commmentInput').css("display") == "none" && $('#commmentInput').text() != '') {
		$('#commmentInput').css("display","block");
		return;
	} else {
		$('#commmentInput').css("display","block");
		$('#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=\"erating\">Your Rating:</label><select name=\"erating\" id=\"erating\"><option value=\"0\"></option><option value=\"1\">1 star - poor</option><option value=\"2\">2 stars</option><option value=\"3\">3 stars</option><option value=\"4\">4 stars</option><option value=\"5\">5 stars - excellent</option></select><br /><label for=\"econtent\" style=\"color: #466C97\">Your Review:</label><textarea name=\"econtent\" id=\"econtent\"></textarea><br /><button id=\"submitComment\" type=\"button\" onclick=\"submitNote(" + userid + "," + linkid + ")\">submit</button></form>");
	}
}


function showNotes(lid){

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

			$('#commmentDisplay').css("display","block");
			if(lid ==""){

					$('#commmentDisplay').append("<p class=\"missingInfo\">No valid directory id.</p>");

				}
			else if($('#commmentDisplay').text()==''){
					var url = "http://www.otrib.com/directory/notes.php?linkid=" + lid + "&currentuser=0&status=show";
					xmlHttp.open("GET", url, true);
					xmlHttp.onreadystatechange = stateChangedShowNotes;
					xmlHttp.send(null);
				}

		}

function submitNote(user,lid){

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

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

			}
		else{
				//var url = "http://www.otrib.com/directory/notes.php?lc_enteredName=" + ename + "&lc_content=" + econtent + "&lc_rating=" + erating + "&currentuser=" + user + "&linkid=" + lid + "&status=insert";
				var url = "../directory/notes.php?lc_enteredName=" + ename + "&lc_content=" + econtent + "&lc_rating=" + erating + "&currentuser=" + user + "&linkid=" + lid + "&status=insert";
				xmlHttp.open("GET", url, true);
				xmlHttp.onreadystatechange = stateChangedSubmitNote;
				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(lc_id,user_id){
		var url = "../directory/manage/notes.php?noteid=" + lc_id + "&status=online&currentuser=" + user_id;
		xmlHttp.open("GET", url, false);
		xmlHttp.send(null);
		$('#'+lc_id).removeClass("offline2");
		$('#'+lc_id).empty();
		$('#'+lc_id).append("ON");
		$('#'+lc_id).addClass("active2");
		$('#'+lc_id).attr("title","currently on");
		$('#'+lc_id).attr("onclick","setNoteAsOffline("+ lc_id + ","+ user_id +")");
	}

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

function removeNote(lc_id,user_id){

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