function sho_votes_window(proxyID,section,title)
{
	var vote_window_id='vote_window_' + proxyID;
	var your_vote_window_id='your_vote_window_' + proxyID;
	var vote_link_id='vote_link_' + proxyID;
	var vote_link = document.getElementById(vote_link_id);
	var newdiv_top = (findPosY(vote_link) + 25);
	var newdiv_left = (findPosX(vote_link) - 150);
	var newdiv_innerHTML = '<div style="width:100%;text-align:center;">';
	var count_knobs = 0;
	var last_knob = 10;
	while(count_knobs <= last_knob)
	{
		if(count_knobs>=1)
		{newdiv_innerHTML = newdiv_innerHTML + ' ';}
		newdiv_innerHTML = newdiv_innerHTML + '<acronym title="vote ' + count_knobs + '"><a onclick="load_your_vote(' + proxyID + ',' + "'" + section + "'" + ',' + count_knobs + ')" style="cursor:pointer;">' + count_knobs + '</a></acronym>';
		count_knobs++;
	}
	var newdiv_innerHTML = newdiv_innerHTML + '</div>';
	var newdiv_innerHTML = newdiv_innerHTML + '<div id="' + your_vote_window_id + '" style="width:100%;text-align:center;"></div>';
	var vote_window = document.getElementById(vote_window_id);
	var votefortitle = 'vote for ' + unescape(title);
	if(vote_window == null)
	{
		pop_div(vote_window_id,"absolute",100,300,newdiv_innerHTML,newdiv_top,newdiv_left,"yes",votefortitle);
		load_your_vote(proxyID,section,"none");
	}
}
function load_your_vote(proxyID,section,newvote)
{
	var urlz = "xmlload_your_vote?proxyID=" + proxyID + "&section=" + section + "&newvote=" + newvote;
	loadXMLDocload_your_vote(urlz);
}
function processReqChangeload_your_vote() 
{
	if (reqload_your_vote.readyState == 4)
	{
		if (reqload_your_vote.status == 200)
		{
			var response = reqload_your_vote.responseXML.documentElement;
			var result = response.getElementsByTagName("result")[0].firstChild.data;
			if(result == 'ok')
			{
				var proxyID = response.getElementsByTagName("proxyID")[0].firstChild.data;
				var hasvoted = response.getElementsByTagName("hasvoted")[0].firstChild.data;
				var notegiven = response.getElementsByTagName("notegiven")[0].firstChild.data;
				var your_vote_window_id='your_vote_window_' + proxyID;
				var your_vote_window = document.getElementById(your_vote_window_id);
				if(your_vote_window != null)
				{
					if(hasvoted == 'no')
					{your_vote_window.innerHTML = 'you have not yet voted for this proxy';}
					else if(hasvoted == 'yes')
					{your_vote_window.innerHTML = 'you have voted ' + notegiven;}
				}
				var votes = response.getElementsByTagName("votes")[0].firstChild.data;
				if(votes >= 1)
				{
					var rating = response.getElementsByTagName("rating")[0].firstChild.data;
					var ratings_span_id = 'rating_' + proxyID;
					var votes_span_id = 'votes_' + proxyID;
					var votesS_span_id = 'votesS_' + proxyID;
					document.getElementById(ratings_span_id).innerHTML = rating;
					document.getElementById(votes_span_id).innerHTML = votes;
					var votesS = '';
					if(votes != 1)
					{votesS = 's';}
					document.getElementById(votesS_span_id).innerHTML = votesS;
				}
			}
		}
	}
}

function sho_comments_window(proxyID,section,title)
{
	var comments_window_id='comments_window_' + proxyID;
	var comments_div_id='comments_div_' + proxyID;
	var comments_link_id='comments_link_' + proxyID;
	var comments_link = document.getElementById(comments_link_id);
	var screen_width = screen.width;
	var win_width = screen_width - 200;
	var ScrollTop = document.body.scrollTop;
	var newdiv_top = ScrollTop + 60;
	var newdiv_innerHTML = '<div id="' + comments_div_id + '"></div>';
	var commentstitle = 'comments about ' + unescape(title);
	var newdiv_left = 100;
	var comments_window = document.getElementById(comments_window_id);
	if(comments_window == null)
	{
		pop_div(comments_window_id,"absolute",100,win_width,newdiv_innerHTML,newdiv_top,newdiv_left,"no",commentstitle);
		load_comments(proxyID, section, 1);
	}
}
function load_comments(proxyID, section, page)
{
	var urlz = "xmlload_comments?proxyID=" + proxyID + "&section=" + section + "&page=" + page;
	loadXMLDocload_comments(urlz);
}
function processReqChangeload_comments() 
{
	if (reqload_comments.readyState == 4)
	{
		if (reqload_comments.status == 200)
		{
			var response = reqload_comments.responseXML.documentElement;
			var result = response.getElementsByTagName("result")[0].firstChild.data;
			if(result == 'ok')
			{
				var myfinalstring = '';
				var proxyID = response.getElementsByTagName("proxyID")[0].firstChild.data;
				var section = response.getElementsByTagName("section")[0].firstChild.data;
				var thispage = response.getElementsByTagName("thispage")[0].firstChild.data;
				var totalpages = response.getElementsByTagName("totalpages")[0].firstChild.data;
				var totalboxes = response.getElementsByTagName("totalboxes")[0].firstChild.data;
				var nowtime = response.getElementsByTagName("nowtime")[0].firstChild.data;
				var previouspagelink = '';
				var thisabspage = Math.abs(thispage);
				if(thispage > 1)
				{previouspagelink = '<a onclick="load_comments(' + proxyID + ', ' + "'" + section + "'" + ', ' + (thisabspage - 1) + ')" style="cursor:pointer;">previous</a> | ';}
				var nextpagelink = '';
				if(thispage < totalpages)
				{nextpagelink = ' | <a onclick="load_comments(' + proxyID + ', ' + "'" + section + "'" + ', ' + (thisabspage + 1) + ')" style="cursor:pointer;">next</a>';}
				var pagination_string = '<div style="width:100%;text-align:center;">' + previouspagelink + 'page ' + thispage + ' of ' + totalpages + nextpagelink + '</div>';
				if(totalpages > 1)
				{myfinalstring = myfinalstring + pagination_string;}
				var countboxes = 0;
				myfinalstring = myfinalstring + '<table style="width:100%;">';
				while(countboxes < totalboxes)
				{
					countboxes++;
					var this_commentID_name = "commentID_" + countboxes;
					var this_name_name = "name_" + countboxes;
					var this_comment_name = "comment_" + countboxes;
					var this_time_name = "time_" + countboxes;
					var this_encip_name = "encip_" + countboxes;
					var this_commentID = response.getElementsByTagName(this_commentID_name)[0].firstChild.data;
					var this_name = response.getElementsByTagName(this_name_name)[0].firstChild.data;
					var this_comment = response.getElementsByTagName(this_comment_name)[0].firstChild.data;
					var this_time = response.getElementsByTagName(this_time_name)[0].firstChild.data;
					var this_encip = response.getElementsByTagName(this_encip_name)[0].firstChild.data;
					var delete_button = '';
					var oldestacceptabletimeforedit = nowtime - 3600;
					if((this_encip == myencip && this_time > oldestacceptabletimeforedit) || admin==1)
					{
						delete_button = ' <acronym title="erase this comment"><a onclick="erase_comment(' + this_commentID + ', ' + proxyID + ', ' + "'" + section + "'" + ', ' + thispage + ')" style="cursor:pointer;">X</a></acronym>';
					}
					myfinalstring = myfinalstring + '<tr><td><table style="width:100%;" class="bg_color2"><tr><td>' + maketimus(this_time) + ', ' + this_name + ' said:</td></tr><tr><td class="bg_color1">' + this_comment + delete_button + '</td></tr></table></td></tr>';
				}
				myfinalstring = myfinalstring + '</table>';
				if(countboxes==0)
				{myfinalstring = '<div style="width:100%;text-align:center;">empty</div>';}
				var randomnumber=Math.floor(Math.random()*10000000001);
				var name_cookivalu = getCookie("name");
				var add_comment_box = '<div style="width:100%;text-align:center;">' +
					'<h4>Add a Comment:</h4>' +
					'<span id="pointerror_1_' + proxyID + '"></span>' +
					'your name:<br />' +
					'<input type="text" id="my_name_' + proxyID + '" value="' + name_cookivalu + '" /><br />' +
					'<span id="pointerror_2_' + proxyID + '"></span>' +
					'your comment:<br />' +
					'<textarea style="width:300px;height:120px;" id="my_comment_' + proxyID + '"></textarea><br />' +
					'<span id="pointerror_3_' + proxyID + '"></span>' +
					'<input type="hidden" value="' + randomnumber + '" id="my_random_' + proxyID + '" />' +
					'<img src="image_verification?name=cm' + proxyID + '_' + randomnumber + '" style="vertical-align:text-bottom;" /> => retype this number = > <input type="text" id="my_num_' + proxyID + '" /><br />' +
					'<input type="button" value="post comment" onclick="comment(' + proxyID + ', ' + "'" + section + "'" + ')" />' +
					'</div>';
				if(totalpages > 1)
				{myfinalstring = myfinalstring + pagination_string;}
				myfinalstring = myfinalstring + add_comment_box;
				var comments_div_id='comments_div_' + proxyID;
				document.getElementById(comments_div_id).innerHTML = myfinalstring;
			}
		}
	}
}


function erase_comment(commentID, proxyID, section, page)
{
	var conf = confirm('are you sure that you want to erase that comment!?');
	if(conf == true)
	{
		var urlz = "xmlerase_comment?commentID=" + commentID + "&proxyID=" + proxyID + "&section=" + section + "&page=" + page;
		loadXMLDocerase_comment(urlz);
	}
}
function processReqChangeerase_comment() 
{
	if (reqerase_comment.readyState == 4)
	{
		if (reqerase_comment.status == 200)
		{
			var response = reqerase_comment.responseXML.documentElement;
			var result = response.getElementsByTagName("result")[0].firstChild.data;
			if(result == 'ok')
			{
				var proxyID = response.getElementsByTagName("proxyID")[0].firstChild.data;
				var section = response.getElementsByTagName("section")[0].firstChild.data;
				var page = response.getElementsByTagName("page")[0].firstChild.data;
				var totalcomments = response.getElementsByTagName("totalcomments")[0].firstChild.data;
				var comments_amount_id = "comments_amount_" + proxyID;
				document.getElementById(comments_amount_id).innerHTML = totalcomments;
				load_comments(proxyID, section, page);
			}
		}
	}
}


function comment(proxyID, section)
{
	var my_name_id = 'my_name_' + proxyID;
	var my_comment_id = 'my_comment_' + proxyID;
	var my_num_id = 'my_num_' + proxyID;
	var my_random_id = 'my_random_' + proxyID;
	var name = document.getElementById(my_name_id).value;
	var comment = document.getElementById(my_comment_id).value;
	var num = document.getElementById(my_num_id).value;
	var random = document.getElementById(my_random_id).value;
	setCookie("name",name,365);
	//setCookie("url",url,365);
	var urlz = "xmlcomment?proxyID=" + proxyID + "&section=" + section + "&name=" + escape(name) + "&comment=" + escape(comment) + "&num=" + num + "&random=" + random;
	loadXMLDoccomment(urlz);
}
function processReqChangecomment() 
{
	if (reqcomment.readyState == 4)
	{
		if (reqcomment.status == 200)
		{
			var response = reqcomment.responseXML.documentElement;
			var result = response.getElementsByTagName("result")[0].firstChild.data;
			var proxyID = response.getElementsByTagName("proxyID")[0].firstChild.data;
			var pointaterrrorname1='pointerror_1_' + proxyID;
			var pointaterrrorname2='pointerror_2_' + proxyID;
			var pointaterrrorname3='pointerror_3_' + proxyID;
			document.getElementById(pointaterrrorname1).innerHTML = '';
			document.getElementById(pointaterrrorname2).innerHTML = '';
			document.getElementById(pointaterrrorname3).innerHTML = '';
			var showerror_string = '<span style="color:red;">!</span>';
			if(result == 'ok')
			{
				var section = response.getElementsByTagName("section")[0].firstChild.data;
				var totalcomments = response.getElementsByTagName("totalcomments")[0].firstChild.data;
				var comments_amount_id = "comments_amount_" + proxyID;
				document.getElementById(comments_amount_id).innerHTML = totalcomments;
				load_comments(proxyID, section, 1);
			}
			else if(result == 'badcode')
			{
				
				document.getElementById(pointaterrrorname3).innerHTML = showerror_string;
				alert('the number in the box does not match the number in the picture, please try again.');
			}
			else if(result == 'name_tooshort')
			{
				document.getElementById(pointaterrrorname1).innerHTML = showerror_string;
				alert('this name is too short, please try again.');
			}
			else if(result == 'comment_tooshort')
			{
				document.getElementById(pointaterrrorname2).innerHTML = showerror_string;
				alert('this comment is too short, please try again.');
			}
		}
	}
}



var ajax_pipes=new Array();
ajax_pipes[1]='load_your_vote';
ajax_pipes[2]='load_comments';
ajax_pipes[3]='comment';
ajax_pipes[4]='erase_comment';
ajax_pipes[5]='submit_report';
ajax_pipes[6]='make_open_proxy_title';

for (xol in ajax_pipes)
{
	var joystring = 'var req' + ajax_pipes[xol] + '; function loadXMLDoc' + ajax_pipes[xol] + '(url) {if (window.XMLHttpRequest) {req' + ajax_pipes[xol] + ' = new XMLHttpRequest(); req' + ajax_pipes[xol] + '.onreadystatechange = processReqChange' + ajax_pipes[xol] + '; req' + ajax_pipes[xol] + '.open("GET", url, true); req' + ajax_pipes[xol] + '.send(null);} else if (window.ActiveXObject){req' + ajax_pipes[xol] + ' = new ActiveXObject("Microsoft.XMLHTTP"); if (req' + ajax_pipes[xol] + ') {req' + ajax_pipes[xol] + '.onreadystatechange = processReqChange' + ajax_pipes[xol] + ';req' + ajax_pipes[xol] + '.open("GET", url, true);req' + ajax_pipes[xol] + '.send();}}}';
	eval(joystring);
}




function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }


function remove_element_by_id(element_id)
{
	var oldelem = document.getElementById(element_id);
	oldelem.innerHTML = '';
	document.body.removeChild(oldelem);
}



function pop_div(newdiv_id,newdiv_position,newdiv_zIndex,newdiv_width,newdiv_innerHTML,newdiv_top,newdiv_left,makedraggable,title)
{
	var newdiv = document.createElement("div");
	newdiv.setAttribute("id",newdiv_id);
	document.body.appendChild(newdiv);
	newdiv.style.position = newdiv_position;
	newdiv.style.zIndex = newdiv_zIndex;
	if(newdiv_width!='none')
	{newdiv.style.width = newdiv_width + "px";}

	if(title.indexOf('open|') >= 0)
	{
		var spanid = 'title_' + newdiv_id;
		make_open_proxy_title(spanid,title);
		title = '<span id="' + spanid + '">loading title...</span>';
	}
	
	var header_div = '<table style="width:100%;font-size:75%;" class="bg_color2"><tr>' +
		'<td style="width:5%;">&#160;</td>' +
		'<td style="width:90%;text-align:center;vertical-align:middle;height:18px;">' + title + '</td>' +
		'<td style="width:5%;text-align:right;vertical-align:top;">[<acronym title="close this window"><a onclick="remove_element_by_id(' + "'" + newdiv_id + "'" + ')" style="cursor:pointer;">x</a></acronym>]</td>' +
		'</tr></table>';
	var windowed_HTML = '<div style="padding:1px;" class="bg_color1"><div style="padding:6px;" class="bg_color2"><div class="bg_color1">' + header_div + newdiv_innerHTML + '</div></div></div>';


	newdiv.innerHTML = windowed_HTML;
	newdiv.style.top = newdiv_top + "px";
	newdiv.style.left = newdiv_left + "px";
	if(makedraggable=='yes')
	{makeDraggable(newdiv);}
}



function make_open_proxy_title(spanid,title)
{
	var urlz = "xmlmake_open_proxy_title?spanid=" + spanid + "&title=" + title;
	loadXMLDocmake_open_proxy_title(urlz);
}
function processReqChangemake_open_proxy_title() 
{
	if (reqmake_open_proxy_title.readyState == 4)
	{
		if (reqmake_open_proxy_title.status == 200)
		{
			var response = reqmake_open_proxy_title.responseXML.documentElement;
			var result = response.getElementsByTagName("result")[0].firstChild.data;
			var spanid = response.getElementsByTagName("spanid")[0].firstChild.data;
			var showit = response.getElementsByTagName("showit")[0].firstChild.data;
			if(result == 'ok')
			{document.getElementById(spanid).innerHTML = showit;}
		}
	}
}


//from http://www.webreference.com/programming/javascript/mk/column2/
document.onmousemove = mouseMove;
function mouseMove(ev){
	ev           = ev || window.event;
	var mousePos = mouseCoords(ev);
}
function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:ev.clientY + document.body.scrollTop  - document.body.clientTop
	};
}
document.onmousemove = mouseMove;
document.onmouseup   = mouseUp;
var dragObject  = null;
var mouseOffset = null;
function getMouseOffset(target, ev){
	ev = ev || window.event;

	var docPos    = getPosition(target);
	var mousePos  = mouseCoords(ev);
	return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
}
function getPosition(e){
	var left = 0;
	var top  = 0;

	while (e.offsetParent){
		left += e.offsetLeft;
		top  += e.offsetTop;
		e     = e.offsetParent;
	}

	left += e.offsetLeft;
	top  += e.offsetTop;

	return {x:left, y:top};
}
function mouseMove(ev){
	ev           = ev || window.event;
	var mousePos = mouseCoords(ev);

	if(dragObject){
		dragObject.style.position = 'absolute';
		dragObject.style.top      = mousePos.y - mouseOffset.y;
		dragObject.style.left     = mousePos.x - mouseOffset.x;

		return false;
	}
}
function mouseUp(){
	dragObject = null;
}

function makeDraggable(item){
	if(!item) return;
	item.onmousedown = function(ev){
		dragObject  = this;
		mouseOffset = getMouseOffset(this, ev);
		return false;
	}
}
//end of - from http://www.webreference.com/programming/javascript/mk/column2/


