/* jsilvestris@x-industries.com */

var vers="2.09d1";

var dom=document.getElementById;
var iex=document.all;
var msie6=(navigator.userAgent.indexOf("MSIE 6")>=0)?true:false;
var msie7=(navigator.userAgent.indexOf("MSIE 7")>=0)?true:false;
var msie=(navigator.userAgent.indexOf("MSIE")>=0)?true:false;
var req,req2,req3;
var ff=(navigator.userAgent.indexOf("Firefox")>=0)?true:false;
document.speed=100;

function stripTags(str){
	return str.replace(/<\/?[^>]+>/gi, '');
}
function url_strip_base(obj){
	obj=obj.toString();
	var url_noport=obj.replace(":16080","");
	var my_result=url_noport.replace(/http\:\/\/[\.A-z0-9]+\/(.*?)/,"$1");
	var my_result2=my_result.replace(/\/?([A-z0-9]+)\/.*/,"$1");
	return my_result2;
}
function url_strip_fullbase(obj){
	obj=obj.toString();
	var url_noport=obj.replace(":16080","");
	var my_result=url_noport.replace(/http\:\/\/[\.A-z0-9]+\/(.*?)/,"$1");
	var my_result2=my_result.replace(/\/?([A-z0-9\/]+)\/([0-9]+)\/?.*/,"$1");
	return my_result2;
}
function url_strip_id(obj){
	obj=obj.toString();
	var my_result=obj.replace(":16080","");
	my_result=my_result.replace(/[^0-9]+/,"");
	my_result=my_result.replace(/\/.*/,"");
	return my_result;
}
function url_strip_action(obj){
	obj=obj.toString();
	var url_noport=obj.replace(":16080","");
	var my_result=url_noport.replace(/[^0-9]+/,"");
	return my_result.replace(/[0-9\/]+/,"");
}
function thisPage(){
	var str=window.location.toString();
	if(str.substr(str.length-1,str.length)!="/")str+="/";
	//str=str.replace(":16080","");
	return str;
}
getElement=function(name,nest){
	/* original concept squidfingers.com */
	var nest=nest?'document.'+nest+'.':'';
	var el=dom?document.getElementById(name):iex?document.all[name]:ns4?eval(nest+'document.'+name):false;
	return el;
}
function checkMaxLength(obj){
	var mlength=obj.getAttribute?parseInt(obj.getAttribute("maxlength")):"";
	if(obj.getAttribute&&obj.value.length>mlength)obj.value=obj.value.substring(0,mlength);
}
function newXMLHttpRequest(){
	var errors;
	if(window.XMLHttpRequest){
		try{return new XMLHttpRequest();}
		catch(e){errors=true;}
	}else if(window.ActiveXObject){
		try{return new ActiveXObject("Msxml2.XMLHTTP");}
		catch(e){
			try{return new ActiveXObject("Microsoft.XMLHTTP");}
			catch(e){errors=true;}
		}
	}
	if(errors)return false;
}
handleForms=function(){
	var formsList=document.body.getElementsByTagName('form');
	for(i=0;i<formsList.length;i++){
		formsList[i].onsubmit=function(){return validateForm(this);}
		if(/selectOnly/.test(formsList[i].className)){
			var obj=formsList[i].name.replace("Form","");
			getElement(obj+"Select").onchange=function(){
				document.forms[this.id.replace("Select","Form")].submit();
			}
			try{getElement(obj+"Button").style.display="none";}catch(e){}
		}
	}
}
validateForm=function(theForm){
	var x=theForm.elements;
	var error='';
	if(x){
		for(var i=0;i<x.length;i++){
			if(x[i].className.indexOf('required')!=-1&&!x[i].value){
				var offender=x[i].id;
				while(offender.indexOf("_")>-1){offender=offender.replace("_"," ");}
				error+="\n- "+offender;
				x[i].style.background="#fec";
			}else x[i].style.background="#fff";
		}
	}
	if(error!=""){
		alert("Please fill in the following fields, as they are required for processing this form:\n"+error);
		return false;
	}else{
		try{ theForm.submit(); }catch(e){ }
	}
}
function handleOrderBy(){
	getElement("orderBySelect").onchange=function(){document.forms.orderByForm.submit();}
	try{getElement("orderByButton").style.display="none";}catch(e){}
}
handleContactForm=function(){
	var cform=getElement('contactform');
	getElement('inquire').value="help"+"@"+"gamercreated.com";
	getElement("submitButton").onclick=function(){
		sendEmail();
		return false;
	}
}

/*

	ON LOAD
	addLoadEvent: http://simonwillison.net/2004/May/26/addLoadEvent/

*/
function addLoadEvent(func){
	var oldonload=window.onload;
	if(typeof window.onload!='function'){
		window.onload=func;
	}else{
		window.onload=function(){
			if(oldonload)oldonload();
			func();
		}
	}
}
window.addEvent('domready', function(){
	var navimg1=document.createElement("img");
		navimg1.src="/img/header1/sub_menu.png";
	var navimg2=document.createElement("img");
		navimg2.src="/img/header1/sub_menu_select.png";
	if(getElement("navigation"))handleNavMenu();
	if(getElement("vers"))getElement("vers").innerHTML=" v"+vers;
	handleForms();
	if(getElement("commentForm"))handleCommentForm();
	if(getElement("comments"))handleCommentButtons();
	if(getElement("contactform"))handleContactForm();
	if(getElement("rateForm0"))handleStars();
	if(getElement("orderBySelect"))handleOrderBy();
	if(getElement("forum"))handleForum();
	if(getElement("quickPassword"))handlePass();
	if(getElement("wii_number"))handleRegistrationStuff();
	if(getElement("biggersmaller"))handleBigSmall();
	if(getElement("poll_options"))handlePollOptions();
	if(getElement("poll_form_0"))handlePollForm();
	if(getElement("wiimail_list"))handleWiimailApp();
	if(getElement("index_right_col")||getElement("edit_mii_list_0"))handlePageSaveState();
	if(getElement("badge_list"))handleBadgeList();
	handleMiiLists();
	if(getElement("user_widget_featured_miilist"))handleMiiList($("user_widget_featured_miilist"));
	if(getElement("Add_Game_Selection"))handleGameBox("game_select");
	if(getElement("blastworks")){
		var overimg1=document.createElement("img");
			overimg1.src="/img/blastworks/item-on.png";
		var overimg2=document.createElement("img");
			overimg2.src="/img/blastworks/blast.png";
		var overimg3=document.createElement("img");
			overimg3.src="/img/blastworks/button-over.png";
	}
	if(getElement("addtoqueue"))handleQueue();
	if(getElement("widget_window_0")){
		handleItemWidget();
		handleWidgets();
		if(getElement("widget_id_950"))handleQueueList();
		if(getElement("widget_id_710"))handleCalendar("widget_id_710");
		if(getElement("widget_id_700"))handleCalendar("widget_id_700");
		if(getElement("widget_id_200"))handleAccordian(getElement("widget_id_200").parentNode);
	}
	//if(getElement("game_list"))handleGameAccordian(getElement("game_list"));
	if(getElement("plugHEX1"))handleColorPicker();
	if(getElement("bd_cal"))handleBDcal();
	if(getElement("challenge_cal"))handleCcal();
	if(getElement("post_container"))handlePost($("post_container"),$("post_details"));
	handleBlockLinks();
	handleAddFriendLinks();
	handleMailTo();
	handleRightColumn();
	handleMessageLinks();
	setTimeout("handleRightColumn();",500);
});
addLoadEvent(function(){
	handleRightColumn();
	window.onresize=function(){}
	if(getElement("wiidget"))handleWiidget();
});


/*

	ACCORDIANS

*/
function handleAccordian(acc){
	var accordion=new Accordion('div.user_widget_title','div.user_widget_section', {
		opacity: true,
		onActive: function(toggler, element){
			toggler.setStyle('background','#ffe url("/img/yellow.png") top left repeat-x');
		},
		onBackground: function(toggler, element){
			toggler.setStyle('background','#eee url("/img/frey.png") top left repeat-x');
		},
		onComplete:function(){handleRightColumn();}
	},$(acc.id));
}
function handleGameAccordian(acc){
	var accordion=new Accordion('tr.game_row','tr.game_row_pop', {
		opacity: true,
		onActive: function(toggler, element){
			toggler.className+=" selected";
			element.innerHTML='<td colspan="6"><div>TEST</div></td>';
			var myFx = new Fx.Styles(element.id, {duration:600});
			myFx.start({'height':[0,100]});
		},
		onBackground: function(toggler, element){
			toggler.className.replace(" selected","");
			element.innerHTML='<td colspan="6"></td>';
		},
		onComplete:function(){handleRightColumn();}
	}, $(acc.id));
}

/*

	CALENDAR

*/
function handleCalendar(el){
	var elid=$(el).parentNode.id;
	var calentries=$(elid).getElements("div[class=cal_entry]");
	for(var i=0;calentries[i];i++){
		var item=calentries[i].getElementsByTagName("a")[0];
		item.setAttribute("old_href",item.href.replace(/http\:\/\/[A-z0-9\.\:]+\/(.*)/,"/$1"));
		item.setAttribute("href","javascript:none();");
		item.id="ci_"+i;
		
		$("ci_"+i).addEvent('click', function(e) {
			e = new Event(e).stop();
			
			closeCalendarPop();
			
			var url = this.getAttribute("old_href");
			var pop=new Element('div', {
				'id':'calendar_info',
				'style':'top:'+(this.getTop()+8)+"px; left:"+(this.getLeft()-12)+"px;"
			});
			var popText=new Element('div', {
				'class':this.className,
				'id':'calendar_info_text'
			}).setHTML('Loading...');
			pop.appendChild(popText);
			
			var popClose=new Element('a', {
				'class':'small_close_button',
				'id':'calendar_close_button',
				'href':'javascript:none();'
			}).setHTML('X');
			popClose.addEvent('click',function(){
				closeCalendarPop();
			});
			
			pop.appendChild(popClose);
			
			document.body.appendChild(pop);
			
			//alert("/calendar/ajax?url="+escape(url));
			
			new Ajax("/calendar/ajax?url="+escape(url), {
				method: 'get',
				update: $('calendar_info_text')
			}).request();
		});
		//item.href="javascript:alert('"+item.getAttribute("old_href")+"');";
	}
}
function closeCalendarPop(){
	if($('calendar_info'))$('calendar_info').parentNode.removeChild($('calendar_info'));
}
/*

	WII DOWNLOAD QUEUE

*/
function handleQueueList(){
	var widget_div_id=getElement("widget_id_950").parentNode.id;
	var queue_list=$(widget_div_id).getElementsByTagName("tbody")[0];
	var queue_buttons=$(widget_div_id).getElements('a[title=Remove]');
	for(var i=0;queue_buttons[i];i++){
		var url_noport=queue_buttons[i].href.replace(":16080","");
		var my_result=url_noport.replace(/[^0-9]+/,"");
		var my_id=my_result.replace(/[^0-9]+/,"");
		var my_game=url_strip_fullbase(url_noport).replace("games/","");
		var my_action=my_result.replace(/[0-9\/]+/,"");
		queue_buttons[i].id="addtoqueue_"+my_id;
		queue_buttons[i].setAttribute("state",my_action);
		queue_buttons[i].setAttribute("obj_id",my_id);
		queue_buttons[i].href="javascript:queue_"+my_action+"("+my_id+",'"+my_game+"');";
	}
	var qlinks=$("content").getElements("a[class^=widgetQueueRemove]");
	for(var i=0;i<qlinks.length;i++){
		handleQueueRemoveButton(qlinks[i]);
	}
}
function handleQueue(){
	var queue_button=getElement("addtoqueue");
	var my_id=getElement("obj").className;
	var my_game=url_strip_fullbase(queue_button.href).replace("games/","");
	var my_action=url_strip_action(queue_button.href);
	queue_button.setAttribute("state",my_action);
	queue_button.setAttribute("obj_id",my_id);
	queue_button.href="javascript:queue_"+my_action+"("+my_id+",'"+my_game+"');";
}
function queue_queue(item_id,game_id){
	var ajax_req=new Ajax("/ajax/queue?game="+game_id+"&queue="+item_id, {
		method: 'get',
		onComplete: function(txt,xml){
			queueResponse(xml,item_id,game_id);
		}
	}).request();
}
function queue_unqueue(item_id,game_id){
	var ajax_req=new Ajax("/ajax/queue?game="+game_id+"&unqueue="+item_id, {
		method: 'get',
		onComplete: function(txt,xml){
			queueResponse(xml,item_id,game_id);
		}
	}).request();
}
function queueResponse(xml,my_item_id,game_id){
	var att=document.createElement("div");
	att.id="attachment";
	var queue_result=xml.getElementsByTagName("queue_result")[0].firstChild.nodeValue;
	if(queue_result==parseInt(queue_result)){
		if(getElement("addtoqueue")){
			var queue_button=getElement("addtoqueue");
		}else if(getElement("addtoqueue_"+my_item_id)){
			var queue_button=getElement("addtoqueue_"+my_item_id);
		}
		/*var queue_state=queue_button.getAttribute("state");*/
		var queue_state=xml.getElementsByTagName("queue_state")[0].firstChild.nodeValue;
		if(getElement("widget_id_950")){
			var widget_div_id=getElement("widget_id_950").parentNode.id;
			var widget_div=$(widget_div_id);
			var queue_list=$(widget_div_id).getElementsByTagName("tbody")[0];
			try{
				var queue_list_items=queue_list.getElementsByTagName("tr");
				var queue_list_length=queue_list_items.length;
				var queue_list_last=queue_list_items[queue_list_items.length-1].className;
			}catch(e){
				var queue_list_length=0;
				var queue_list_last="";
			}
		}
		try{
			var item_name=xml.getElementsByTagName("item_name")[0].firstChild.nodeValue;
			var item_date=xml.getElementsByTagName("item_date")[0].firstChild.nodeValue;
		}catch(e){
			if(!item_name)item_name="Untitled";
			if(!item_date)item_date="Unknown Date";
		}
		var item_id=xml.getElementsByTagName("item_id")[0].firstChild.nodeValue;
		var item_game=xml.getElementsByTagName("item_game")[0].firstChild.nodeValue;
		if(queue_state=="queue"){
			queue_button.href="javascript:queue_unqueue("+queue_button.getAttribute("obj_id")+",'"+item_game+"');";
			queue_button.setAttribute("state","unqueue");
			getElement("addtoqueue_text").innerHTML="Cancel Download";
			
			queue_result=xml.getElementsByTagName("queue_result_text")[0].firstChild.nodeValue;
			queue_result_text_2=xml.getElementsByTagName("queue_result_text_2")[0].firstChild.nodeValue;
			
			if(widget_div){
				
				var newRow=new Element('tr', {
					'class':(queue_list_last.indexOf("alternate")>-1)?'':'alternate',
					'id':'row_'+item_id
				});
				var newCell=new Element('td').setHTML(item_name);
				newRow.appendChild(newCell);
				var newCell=new Element('td').setHTML(item_date);
				newRow.appendChild(newCell);
				/*var newCell=new Element('td').setHTML('<a href="javascript:queue_unqueue('+item_id+')" title="Remove" class="addtoqueue widget_list_link" id="addtoqueue_'+item_id+'" state="unqueue" obj_id="'+item_id+'">X</a>');
				newRow.appendChild(newCell);*/
				if(!queue_list){
					var carea=getElement("user_widget_content_"+widget_div.getAttribute("num"));
					carea.innerHTML='<p>'+queue_result_text_2+'</p>';
				}else{
					queue_list.appendChild(newRow);
					handleItemWidgetRow(newRow,'/html/posts_'+item_game+'/id/'+my_item_id,widget_div.getAttribute("num"),queue_list_length);
				}
			}
		}else if(queue_state=="unqueue"){
			if(queue_button){
				queue_button.href="javascript:queue_queue("+item_id+",'"+item_game+"');";
				queue_button.setAttribute("state","queue");
			}
			if(getElement("addtoqueue_text")){
				if(item_game=="hotandcold"){
					getElement("addtoqueue_text").innerHTML="Download to DS";
				}else getElement("addtoqueue_text").innerHTML="Download to Wii";
			}
			
			queue_result=xml.getElementsByTagName("queue_result_text")[0].firstChild.nodeValue;
			queue_result_text_2=xml.getElementsByTagName("queue_result_text_2")[0].firstChild.nodeValue;
			
			if(widget_div){
				var old_rows=$(widget_div_id).getElements("tr[old_id=row_"+item_id+"]");
				if(queue_list){
					queue_list.removeChild(old_rows[0]);
				}else{
					var carea=getElement("user_widget_content_"+widget_div.getAttribute("num"));
					carea.innerHTML='<p>'+queue_result_text_2+'</p>';
				}
				document.item_list_last=false;
			}
		}
	}else if(xml.getElementsByTagName("error")[0]){
		var b=document.createElement("b");
		b.appendChild(document.createTextNode("Error: "));
		att.appendChild(b);
		queue_result+=" You may need to refresh your browser window.";
	}
	att.appendChild(document.createTextNode(queue_result));
	if(getElement("attachment_holder")){
		getElement("attachment_holder").innerHTML="";
		getElement("attachment_holder").appendChild(att);
	}else{
		alert(queue_result);
	}
}
function handleQueueRemoveButton(b_queue){
	b_queue.old_href=b_queue.href;
	b_queue.href='javascript:none();';
	
	handleWidgetListButton(b_queue);
	
	b_queue.onclick=function(){
		if(getElement("widget_"+this.getAttribute("widget_num")+"_detail")._xml){
			if(document.widget_last==this.getAttribute("widget_num")){
				var my_xml=getElement("widget_"+this.getAttribute("widget_num")+"_detail")._xml;
				var my_post_id=my_xml.getElementsByTagName("id")[0].firstChild.nodeValue;
				var my_post_type=my_xml.getElementsByTagName("type")[0].firstChild.nodeValue.replace("posts_","");
				queue_unqueue(my_post_id,my_post_type);
			}else{
				eval(unescape(b_queue.old_href));
			}
		}
	}
}

/*

	MESSAGING

*/
function handleMailToLinks(){
	//$('myElement').getElements('input[name$=log]');
}
function handleMailTo(){
	if(getElement("sendtofriend")){
		var stf=getElement("sendtofriend");
		stf.setAttribute("obj_type",url_strip_fullbase(stf.href));
		stf.setAttribute("obj_id",url_strip_id(stf.href));
		stf.href='javascript:none()';
		stf.onclick=function(){
			mailTo(false,this.getAttribute("obj_type"),this.getAttribute("obj_id"));
		}
	}
}
function handleWidgetListButton(obj){
	var step=obj.parentNode;
	while(obj.getAttribute("widget_num")==null){
		if(step.getAttribute("num")===0||step.getAttribute("num")){
			obj.setAttribute("widget_num",step.getAttribute("num"));
			//break;
		}else if(step.id=="content"){
			alert("Error identifying the index for a widget! Please report this error as a bug using the contact page.");
			break;
		}else{
			step=step.parentNode;
		}
	}
}
function handleMessageLinks(){
	var mlinks=$("content").getElements("a[class^=send_message]");
	for(var i=0;i<mlinks.length;i++){
		handleSendMessage(mlinks[i]);
	}
	var blinks=$("content").getElements("a[class^=widgetReply]");
	for(var i=0;i<blinks.length;i++){
		handleReplyButton(blinks[i]);
	}
	var overimg1=document.createElement("img");
		overimg1.src="/img/scripts/back.png";
	var overimg2=document.createElement("img");
		overimg2.src="/img/scripts/popup.png";
}
function handleReplyButton(b_reply){
	b_reply.old_href=b_reply.href;
	b_reply.href='javascript:none();';
	
	handleWidgetListButton(b_reply);
	
	b_reply.onclick=function(){
		if(getElement("widget_"+this.getAttribute("widget_num")+"_detail")._xml){
			if(document.widget_last==this.getAttribute("widget_num")){
				var my_xml=getElement("widget_"+this.getAttribute("widget_num")+"_detail")._xml;
				var user=Array();
				if(my_xml.getElementsByTagName("type")[0].firstChild.nodeValue=="user_comments"){
					user["id"]=my_xml.getElementsByTagName("from")[0].getElementsByTagName("id")[0].firstChild.nodeValue;
					user["name"]=my_xml.getElementsByTagName("from")[0].getElementsByTagName("name")[0].firstChild.nodeValue;
					var message_id=my_xml.getElementsByTagName("id")[0].firstChild.nodeValue;
					var att_type="user_comments";
				}else if(my_xml.getElementsByTagName("type")[0].firstChild.nodeValue=="wiis"){
					user["id"]=my_xml.getElementsByTagName("id")[0].firstChild.nodeValue;
					user["name"]=my_xml.getElementsByTagName("name")[0].firstChild.nodeValue;
					var message_id=false;
					var att_type=false;
				}
				mailTo(user,message_id,att_type);
			}else{
				eval(unescape(b_reply.old_href));
			}
		}
	}
}
function handleSendMessage(obj){
	obj.setAttribute("user_id",url_strip_id(obj.href));
	obj.setAttribute("user_name",obj.title.replace("Send Message to ",""));
	obj.href="javascript:none();";
	obj.onclick=function(){
		var user=new Array();
		user["name"]=this.getAttribute("user_name");
		user["id"]=this.getAttribute("user_id");
		mailTo(user,false,false);
	}
}
function mailTo(user,obj_type,obj_id){
	if($('stf')){
		$('stf').parentNode.removeChild($('stf'));
	}
	var form=new Element("form",{
		method:"POST",
		id:"stf",
		name:"stfform"
	});
	appendTextNode(form,"Send To:");
		form_small=document.createElement("small");
		form_small.className="label_add";
	if(!user["name"]){
		appendTextNode(form_small,"Friend's user name or email address.");
	}
	form.appendChild(form_small);
	form.appendChild(document.createElement("br"));
	var form_input_holder=document.createElement("div");
		form_input_holder.style.position="relative";
		form_input_holder.id="form_input_holder";
	var form_input=new Element("input",{
		"name":"friend",
		"type":"text",
		"id":"stfsendto"
	});
	form_input.style.width="100%";		
	if(user["name"]){
		form_input.value=user["name"];
		form_input.setAttribute("readonly","readonly");
		form_input.onfocus=function(){this.blur();}
	}
	var form_input_hidden=new Element("input",{
		"type":"hidden",
		"id":"stffriendid",
		"name":"friend_id"
	});
	if(user["id"]){
		form_input_hidden.value=user["id"];
	}
	form_input_holder.appendChild(form_input_hidden);
	form_input_holder.appendChild(form_input);
	form.appendChild(form_input_holder);
	appendTextNode(form,"Message:");
	form.appendChild(document.createElement("br"));
	var form_textarea=new Element("textarea",{
		"name":"message",
		"class":"widgEditor",
		"id":"stfmessage"
	});
	form_textarea.style.width="100%";
	form_textarea.style.height="130px";
	form.appendChild(form_textarea);
	form.appendChild(document.createElement("br"));
	if(obj_id&&obj_type){
		var form_small=new Element("small",{ "class":"label_att" });
		if(obj_type=="user_comments"){
			appendTextNode(form_small,"Reply to message #"+obj_id);
		}else if(obj_type=="login"&&obj_id=="friends"){
			appendTextNode(form_small,"Friend Request");
		}else{
			appendTextNode(form_small,"Attachment: "+obj_type+"/"+obj_id);
		}
		form.appendChild(form_small);
		var form_input_hidden=new Element("input",{
			"type":"hidden",
			"id":"stfatt",
			"name":"attachment",
			"value":obj_type+"/"+obj_id
		});
		form.appendChild(form_input_hidden);
	}
	var form_input_hidden=new Element("input",{
		"name":"type",
		"type":"hidden",
		"id":"stftype"
	});
	form.appendChild(form_input_hidden);
	var form_submit=new Element("input",{
		"type":"submit",
		"name":"submit_button",
		"id":"stfsubmit",
		"value":"Send"
	});
	form_submit.style.float="right";
	form.appendChild(form_submit);
	form.onsubmit=function(){
		return mailToSubmit();
	}
	form.style.filter='alpha(opacity=0)';
	form.style.opacity="0";
	form.style.display="none";
	lightboxOpenBox(form,function(){
		$('stf').style.display="block";
	});
	widgInit();
	if(!user){
		form_input.disabled=true;
		getAutoFillData("/html/quickfriends/0/",form_input,form_input_holder);
	}
}
function mailToSubmit(){
	var my_form=getElement("stf");
	var send_type=getElement("stftype");
	var send_to=getElement('stfsendto');
	var send_toid=getElement('stffriendid');
	var send_message=getElement('stfmessage');
	var send_att=getElement('stfatt');

	send_type.value="";
	//$('stffriendid').value="";
	for(var j=0;autoCompleteItems[j];j++){
		if(send_to.value==autoCompleteItems[j]){
			send_toid.value=autoCompleteItemIds[j];
			send_type.value="id";
		}
	}
	
	if(send_toid.value<1){
		if(send_to.value.indexOf("@")>0){
			send_type.value="email";
		}else{
			var test=send_to.value;
			while(test.indexOf("-")>0||test.indexOf(" ")>0){
				test=test.replace(/\-/,"");
				test=test.replace(/\ /,"");
			}
			if(test==parseInt(test)){
				send_to.value=test;
				send_type.value="wii";
			}
		}
	}else{
		send_type.value="id";
	}
	
	if(!send_type.value){
		alert("Error recognizing recipient. Please either enter a valid Friend's user name, Wii ID, or email address.");
		return false;
	}else{
		getElement('stfsubmit').disabled=true;
		var query='action=stf&type='+escape(send_type.value)+'&friend='+escape(send_to.value)+'&message='+escape(send_message.value);
		if(send_toid.value>"")query+='&friend_id='+send_toid.value;
		if(send_att)query+='&attachment='+escape(send_att.value);
		setTimeout("mailToInit('"+query+"');",100);
		return false;
	}
}
function mailToInit(query){
	var mail_req=new Ajax("/ajax/insert",{
		method:'post',
		data:query,
		onComplete:function(txt,xml){
			var mresponse=xml.childNodes[0].firstChild.nodeValue;
			if(mresponse){
				var my_form=$("stf");
					my_form.innerHTML=mresponse;
					my_form.id="stf";
					my_form.style.textAlign="center";
					my_form.style.paddingTop="100px";
				setTimeout('lightboxCloseBox();',6000);
			}else{
				getElement('stfsubmit').removeAttribute("disabled");
				alert("There was an error with your submission. If problems persist, you may want to copy the contents of your message to your clipboard, reload the page, and try again.");
			}
			//return false;
		}
	}).request();
}
function getAutoFillData(url_string,autofill_input,autofill_holder){
	var ajax_req=new Ajax(url_string, {
		method: 'get',
		onComplete: function(txt,xml){
			autofill_input.disabled=false;
			autofill_input.removeAttribute("disabled");
			handleAjaxAutoFill(xml,autofill_input,autofill_holder);
		}
	}).request();
}
function handleAjaxAutoFill(xml,autofill_input,autofill_holder){
	autoCompleteItems=new Array();
	autoCompleteItemIds=new Array();
	var children=xml.getElementsByTagName("result_set");
	for(var j=0;children[j];j++){
		autoCompleteItems.push(children[j].getElementsByTagName("name")[0].firstChild.nodeValue);
		autoCompleteItemIds.push(children[j].getElementsByTagName("id")[0].firstChild.nodeValue);
	}
	actb(autofill_input,autoCompleteItems,autofill_holder);
}

/*

	NOTLIGHTBOX

*/
var darkness=document.createElement("div");
var litbox=document.createElement("div");
function lightboxOpenBox(html_element,func_on_complete){
	darkness.id="darkness";
	darkness.style.background="url(/img/scripts/back.png)";
	darkness.style.zIndex="100000";
	darkness.style.position="absolute";
	darkness.style.top="0";
	darkness.style.paddingBottom="38px";
	darkness.style.cursor="not-allowed";
	darkness.style.left="0";
	darkness.style.width="100%";
	darkness.style.height=document.body.offsetHeight+"px";
	darkness.onclick=function(){lightboxCloseBox();}
	
	litbox.id="litbox";
	litbox.style.zIndex="100001";
	litbox.style.position="fixed";
	litbox.target_top="100px";
	litbox.style.top="-500px";
	litbox.style.width="490px";
	litbox.style.padding="20px";
	litbox.style.height="310px";
	litbox.style.background="url(/img/scripts/popup.png) center center no-repeat";
	litbox.style.left="20%";
	if(litbox.childNodes[0])litbox.removeChild(litbox.childNodes[0]);
	litbox.appendChild(html_element);
	
	document.body.appendChild(darkness);
	if(iex){
		darkness.style.filter='alpha(opacity=0)';
	}else darkness.style.opacity=0;
	var myFx = new Fx.Styles('darkness', {duration:600});
	myFx.start({'opacity':[0,1]});
	
	document.body.appendChild(litbox);
	if(iex){
		litbox.style.filter='alpha(opacity=0)';
	}else litbox.style.opacity=0;
	
	var myFx = new Fx.Styles('litbox', {
		duration:1000,
		onComplete:function(){
			var myFx = new Fx.Styles('stf', {duration:1000});
			myFx.start({'opacity':[0,1]});
			if(typeof func_on_complete=='function')func_on_complete();
		}
	});
	myFx.start({'opacity':[0,1],'top':[-500,100]});
	
	resizeDarkness();
	window.onresize=function(){resizeDarkness();}
}
function lightboxCloseBox(){
	if($('litbox')){
		var litTween = new Fx.Styles('litbox', {
			duration:800,
			onComplete: function(){
				var me=getElement("litbox");
				if(me){
					me.parentNode.removeChild(me);
				}
			}
		});
		litTween.start({'opacity':[1,0]});
		var darkTween = new Fx.Styles('darkness', {
			duration:1000,
			onComplete:function(){
				var me=getElement("darkness");
				if(me){
					me.parentNode.removeChild(me);
				}
			}
		});
		darkTween.start({'opacity':[1,0]});
	}
}
function windowWidth(){
	var winWidth=0;
	if(document.body&&document.body.clientWidth) {
		winWidth=document.body.clientWidth;
	}else if(typeof(window.innerWidth)=='number'){
		winWidth=window.innerWidth;
	}else if(document.documentElement&&document.documentElement.clientWidth){
		winWidth=document.documentElement.clientWidth;
	}
	return winWidth;
}
function windowHeight(){
	var winHeight=0;
	if(document.body&&document.body.clientHeight){
		winHeight=document.body.clientHeight;
	}else if(typeof(window.innerWidth)=='number'){
		winHeight=window.innerHeight;
	}else if(document.documentElement&&document.documentElement.clientHeight){
		winHeight=document.documentElement.clientHeight;
	}
	return winHeight;
}
function resizeDarkness(){
	darkness.style.width=0;
	darkness.style.height=0;
	if(document.body.offsetHeight>windowHeight()){
		darkness.style.height=document.body.offsetHeight+"px";
	}else darkness.style.height=windowHeight()+"px";
	if(document.body.offsetWidth>windowWidth()){
		darkness.style.width=document.body.offsetWidth+"px";
	}else darkness.style.width=windowWidth()+"px";
	litbox.style.left=(parseInt(darkness.style.width)/2-litbox.offsetWidth/2)+"px";
}

/*

	WIDGET SYSTEM

*/
var widget=Array();
function handleWidgets(){
	for(var i=0;getElement("widget_window_"+i);i++){
		widget[i]=getElement("widget_window_"+i);
		var s=document.createElement("span");
		if(!msie){
			var wshade=document.createElement("a");
				wshade.id="widget_shade_"+i;
				wshade.href='javascript:widgetShade('+i+');';
				wshade.className="shade_button";
				wshade.title="Collapse";
				if(widget[i].className.indexOf("windowshade")>-1){
					wshade.title="Expand";
					widget[i].className=widget[i].className.replace("windowshade","wshade");
				}
				appendTextNode(s,"Expand & Collapse");
				wshade.appendChild(s);
			getElement("controls_"+i).appendChild(wshade);
		}
		var wrb=false;
		wrb=$("widget_window_"+i).getElements("div[class^=resizable]")[0];
		if(wrb){
			if(!wrb.getAttribute("id"))wrb.setAttribute("id","wrb"+i);
			widget[i].setAttribute("drag_id",wrb.getAttribute("id"));
			widget[i].setAttribute("widget_original",widget[i].offsetHeight);
			widget[i].setAttribute("widget_list_current",wrb.collapseHeight);
			widget[i].setAttribute("widget_list_original",wrb.originalHeight);
			var resizeStyle=document.createElement("div");
				resizeStyle.className="resizeStyle";
			var resizeBar=document.createElement("div");
				resizeBar.className="resizeBar";
				resizeBar.id="widget_resize_"+i;
				resizeBar.appendChild(resizeStyle);
			widget[i].appendChild(resizeBar);
			$("widget_window_"+i).makeResizable({
				modifiers: {x: false, y: 'height'},
				limit: {y: [(widget[i].offsetHeight-100), widget[i].offsetHeight+600]},
				handle:"widget_resize_"+i,
				onDrag:function(widget_window){
					var widget_list=getElement(widget_window.getAttribute("drag_id"));
					
					var widget_current=widget_window.offsetHeight;
					var widget_original=widget_window.getAttribute("widget_original")*1;
					var widget_list_current=widget_window.getAttribute("widget_list_current")*1;
					var widget_list_original=widget_window.getAttribute("widget_list_original")*1;
					
					widget_list.style.height= ( widget_list_current +( widget_current -widget_original ) +1 ) +"px";
					widget_list.style.overflow="auto";
					widget_list.originalHeight= widget_list_current +( widget_current -widget_original ) -(widget_list_current -widget_list_original);
					
					handleRightColumn();
				},
				onComplete:function(){handleRightColumn();}
			});
		}
	}
}
function widgetShade(i){
	var el=getElement("widget_window_"+i);
	var wshade=getElement("widget_shade_"+i);
	if(el.className.indexOf("wshade")>-1){
		wshade.title='Collapse';
		el.className=el.className.replace("wshade","");
		el.style.height="auto";
	}else{
		wshade.title='Expand';
		el.shadedHeight=el.offsetHeight;
		el.style.height="auto";
		el.className+=" wshade";
	}
	handleRightColumn();
}
function handleRightColumn(){
	if(getElement("int_right_col")){
		var rc=getElement("int_right_col");
		var mc=getElement("int_main_col");
	}else if(getElement("index_right_col")){
		var rc=getElement("index_right_col");
		var mc=getElement("index_main_col");
	}
	if(rc&&mc){
		rc.style.height="auto";
		mc.style.height="auto";
		var mcw=mc.offsetHeight;
		var rcw=rc.offsetHeight;
		if(rcw<mcw){
			rc.style.height=mcw+"px";
		}else if(rcw>mcw){
			mc.style.height=rcw+"px";
		}
	}
}
function handlePageSaveState(){
	if(getElement("new_buttons")){
		var toolbar=getElement("new_buttons");
		var saveButton=document.createElement("a");
		saveButton.id="saveChanges";
		saveButton.style.display="none";
		saveButton.className="button right";
		saveButton.appendChild(document.createTextNode("Save Changes"));
		var saveButtonDiv=document.createElement("div");
		saveButtonDiv.className="right_side";
		saveButton.appendChild(saveButtonDiv);
		saveButton.href="#";
		saveButton.onclick=function(){
			saveChanges();
		}
		toolbar.appendChild(saveButton);
	}
}
function handleItemWidget(){
	for(var f=0;getElement("widget_window_"+f);f++){
		getElement("widget_window_"+f).setAttribute("num",f);
		if(getElement("widget_"+f+"_detail")&&getElement("widget_table_"+f)){
			var thisTable=getElement("widget_table_"+f);
			/* gets all the items from "item_list" - this would need to be abstracted, but let's focus on one... we get both the table rows and the ahrefs, because we're removing the ahrefs and putting them as onclicks on the table rows... */
			var item_list=thisTable.getElementsByTagName("tr");
			var old_item_list=$("widget_table_"+f).getElements('a[target$=detail]');
			
			/* should replace with .each() soon... */
			for(var i=0;i<item_list.length;i++){
				old_item_list[i].parentNode.appendChild(document.createTextNode(old_item_list[i].innerHTML.replace("&amp;","&")));
				old_item_list[i].innerHTML="";
			}
			
			/* so long, iframe. baby, (don't fear) the iframe */
			var item_iframe;
			var iframeContainer;
			var iframeReplacement;
			
			item_iframe=getElement("widget_"+f+"_detail");
			
			iframeContainer=item_iframe.parentNode;
			iframeContainer.removeChild(item_iframe);
			
			var iframeReplacement=document.createElement("div");
				iframeReplacement.id="widget_"+f+"_detail";
				iframeReplacement.className="widget_detail";
				iframeReplacement.setAttribute("num",f);
				iframeContainer.appendChild(iframeReplacement);
				iframeReplacement.originalHeight=iframeReplacement.offsetHeight;
			var widgetList=getElement("widget_list_"+f);
				widgetList.setAttribute("num",f);
				widgetList.target_height=widgetList.offsetHeight+"px";
				widgetList.originalHeight=widgetList.offsetHeight;
				widgetList.collapseHeight=(widgetList.offsetHeight+iframeReplacement.originalHeight);
				
			var iframeTween = new Fx.Styles(iframeReplacement.id, {
				duration:200,
				onComplete:function(){
					var targetDiv=getElement(this.target_div.id);
						targetDiv.style.borderTopWidth="0px";
						targetDiv.style.height="0px";
				}
			});
			iframeTween.target_div=iframeReplacement;
				
			var listTween = new Fx.Styles(widgetList.id, {
				duration:200,
				onComplete:function(){
					var targetDiv=getElement(this.target_div.id);
						targetDiv.style.height=targetDiv.collapseHeight+"px";
				}
			});
			listTween.target_div=widgetList;
			
			iframeTween.start({'height':"0px"});
			listTween.start({'height':widgetList.collapseHeight+"px"});
			for(var i=0;i<item_list.length;i++){
				handleItemWidgetRow(item_list[i],old_item_list[i].href,f,i);
			}
		}
	}
}
function handleItemWidgetRow(row,row_url,wid_num,row_num){
	row.setAttribute("href",row_url);
	row.style.cursor="pointer";
	row.setAttribute("old_id",row.id);
	row.id="widget_"+wid_num+"_item_"+row_num;
	row.setAttribute("num",wid_num);
	row.setAttribute("originalBG",getStyle(getElement(row.id),'background-color'));
	row.onclick=function(){
		var mytd=this.getElementsByTagName("td")[0];
		mytd.className=mytd.className.replace("unread","read");
		/* check for and return previously selected row to its original state */
		if(document.item_list_last){
			var last_item=getElement(document.item_list_last);
			last_item.style.backgroundColor=last_item.getAttribute("originalBG");
			last_item.className=document.item_list_last_class;
			
			/* return any icons in the row to their previous states */
			var icons=last_item.getElementsByTagName("img");
			for(c=0;icons[c];c++){
				icons[c].src=icons[c].getAttribute("originalsrc");
			}
		}
		
		/* store style and identification for the newly selected row */
		document.item_list_last_class=this.className;
		document.item_list_last=this.id;
		document.widget_last=this.getAttribute("num");
		var new_color=getStyle(getElement("widget_window_"+this.getAttribute("num")),'background-color');
		if(new_color){
			this.style.backgroundColor=new_color;
		}
		
		/* swap any icons in the row to their solid white states */
		var icons=this.getElementsByTagName("img");
		for(c=0;icons[c];c++){
			icons[c].setAttribute("originalsrc",icons[c].src);
			icons[c].src=icons[c].src.replace(".png","_selected.png");
		}
		
		this.className="selected";
		
		// make way for the detail box!
		var target_div=getElement("widget_"+this.getAttribute("num")+"_detail");
		if(target_div.offsetHeight<20){
			
			var topTween = new Fx.Style("widget_list_"+this.getAttribute("num"), 'height', {duration:500});
			//alert($("widget_list_"+this.getAttribute("num")).originalHeight);
			var baseTween = new Fx.Styles("widget_"+this.getAttribute("num")+"_detail", {
				duration:500,
				onComplete:function(){
					var targetDiv=this.target_div;
						targetDiv.innerHTML="Loading...";
					var ajax_req=new Ajax(this.target_link, {
						method: 'get',
						onComplete: function(txt,xml){
							handleAJAXrequest(xml,targetDiv);
						}
					}).request();
				}
			});
			baseTween.target_link=this.getAttribute("href").replace("/ht","/x");
			baseTween.target_div=target_div;
			target_div.style.borderTopWidth="1px";
			var oldBaseHeight=getElement("widget_"+this.getAttribute("num")+"_detail").originalHeight;
			
			topTween.start($("widget_list_"+this.getAttribute("num")).originalHeight);
			baseTween.start({'height':oldBaseHeight});
			
			var qec=getElement("widget_window_"+this.getAttribute("num"));
			qec.setAttribute("widget_list_current",qec.getAttribute("widget_list_current")*1-oldBaseHeight);
		}else{
			target_div.innerHTML="Loading...";
			ajax_req=new Ajax(this.getAttribute("href").replace("/ht","/x"), {
				method: 'get',
				onComplete: function(txt,xml){
					handleAJAXrequest(xml,target_div);
				}
			}).request();
		}
	}
}
function handleAJAXrequest(xml,my_result_div){
	try{
		var dataType=xml.getElementsByTagName("type")[0].firstChild.nodeValue;
	}catch(e){
		//alert(xml.getElementsByTagName("root")[0].attributes);
	}
		
	var r_text=Array();
	var	r_label=Array();
	var	r_text_link=Array();
	var	r_stars=Array();
	var r_html=false
	var result_html='';
	var r_count=0;
	
	// case: what type of data is this?
	if(dataType=="wiis"){
		if(xml.getElementsByTagName("version_recent")[0]){
			var r_img="http://img.gamercreated.com/68/68/scalecrop/"+xml.getElementsByTagName("version_recent")[0].firstChild.nodeValue;
		}else{
			var r_img="http://gamercreated.com/img/anonymoussmall.gif";
		}
		
		if(xml.getElementsByTagName("gamename")[0]){
			r_label[r_count]="Playing:";
			r_text[r_count]=xml.getElementsByTagName("gamename")[0].firstChild.nodeValue;
			r_count++;
		}
		r_label[r_count]="Last Seen:";
		r_text[r_count]=xml.getElementsByTagName("last_seen")[0].firstChild.nodeValue;
		r_count++;
		if(xml.getElementsByTagName("sixteen")[0]){
			r_label[r_count]="Wii CN:";
			r_text[r_count]=xml.getElementsByTagName("sixteen")[0].firstChild.nodeValue;
			r_count++;
		}
		
		result_html=document.createElement("a");
		result_html.href="/user/id/"+xml.getElementsByTagName("id")[0].firstChild.nodeValue;
	}else if(dataType=="posts_images"){
		if(xml.getElementsByTagName("version_recent")[0]){
			var r_img="http://img.gamercreated.com/68/68/scalecrop/"+xml.getElementsByTagName("version_recent")[0].firstChild.nodeValue;
		}else{
			var r_img="http://gamercreated.com/img/anonymoussmall.gif";
		}
		if(xml.getElementsByTagName("postfullname")[0]){
			r_label[r_count]="Name:";
			r_text[r_count]=xml.getElementsByTagName("postfullname")[0].firstChild.nodeValue;
			r_count++;
		}
		r_label[r_count]="Created:";
		r_text[r_count]=xml.getElementsByTagName("created")[0].firstChild.nodeValue;
		r_count++;
		if(xml.getElementsByTagName("updated")[0]){
			r_label[r_count]="Updated:";
			r_text[r_count]=xml.getElementsByTagName("updated")[0].firstChild.nodeValue;
			r_count++;
		}
		if(xml.getElementsByTagName("votes")[0]){
			r_label[r_count]="Rating:";
			if(xml.getElementsByTagName("score")[0].firstChild){
				r_label[r_count]=xml.getElementsByTagName("votes")[0].firstChild.nodeValue+" Votes:";
				r_stars[r_count]=xml.getElementsByTagName("score")[0].firstChild.nodeValue;
			}else{
				r_text[r_count]="Unrated";
			}
			r_count++;
		}
		
		result_html=document.createElement("a");
		result_html.href="/mii/"+xml.getElementsByTagName("id")[0].firstChild.nodeValue;
	}else if(dataType=="posts_blastworks"||dataType=="posts_hotandcold"){
		if(xml.getElementsByTagName("image")[0]){
			var r_img="http://img.gamercreated.com/"+dataType.replace("posts_","")+"/68/68/scalecrop/"+xml.getElementsByTagName("image")[0].firstChild.nodeValue;
		}else{
			var r_img="http://gamercreated.com/img/anonymoussmall.gif";
		}
		if(xml.getElementsByTagName("name")[0].firstChild){
			r_label[r_count]="Name:";
			r_text[r_count]=xml.getElementsByTagName("name")[0].firstChild.nodeValue;
			r_count++;
		}
		if(xml.getElementsByTagName("created")[0].firstChild){
			r_label[r_count]="Created:";
			r_text[r_count]=xml.getElementsByTagName("created")[0].firstChild.nodeValue;
			r_count++;
		}
		if(xml.getElementsByTagName("posted")[0]){
			r_label[r_count]="Posted:";
			r_text[r_count]=xml.getElementsByTagName("posted")[0].firstChild.nodeValue;
			r_count++;
		}

		if(xml.getElementsByTagName("votes")[0]){
			if(xml.getElementsByTagName("score")[0].firstChild){
				r_label[r_count]=xml.getElementsByTagName("votes")[0].firstChild.nodeValue+" Votes:";
				r_stars[r_count]=xml.getElementsByTagName("score")[0].firstChild.nodeValue;
			}else{
				r_label[r_count]="Rating:";
				r_text[r_count]="Unrated";
			}
			r_count++;
		}
		
		result_html=document.createElement("a");
		result_html.href="/games/"+dataType.replace("posts_","")+"/"+xml.getElementsByTagName("id")[0].firstChild.nodeValue;
		
	}else if(dataType=="games"){
		var r_img=xml.getElementsByTagName("art")[0].firstChild.nodeValue;
		if(r_img.indexOf("http")<0){
			r_img="/games/art/68/68/scalecrop/"+r_img;
		}
		
		if(xml.getElementsByTagName("friendcode")[0].firstChild.nodeValue==1){
			r_label[r_count]="Features:";
			r_text[r_count]='Online Play';
			r_count++;
		}
		
		if(xml.getElementsByTagName("ratings")[0]){
			if(xml.getElementsByTagName("score")[0].firstChild){
				r_label[r_count]=xml.getElementsByTagName("ratings")[0].firstChild.nodeValue+" Votes:";
				r_stars[r_count]=xml.getElementsByTagName("score")[0].firstChild.nodeValue;
			}else{
				r_label[r_count]="Rating:";
				r_text[r_count]="Unrated";
			}
			r_count++;
		}
		
		result_html=document.createElement("a");
		result_html.href="/reviews/system/"+xml.getElementsByTagName("system")[0].firstChild.nodeValue+"/"+xml.getElementsByTagName("id")[0].firstChild.nodeValue;
	}else if(dataType=="events"){
		var r_img=xml.getElementsByTagName("art")[0].firstChild.nodeValue;
		if(r_img.indexOf("http")<0){
			r_img="/games/art/68/68/scalecrop/"+r_img;
		}
		r_label[0]="Something:";
		r_text[0]=xml.getElementsByTagName("friendcode")[0].firstChild.nodeValue;
		
		result_html=document.createElement("a");
		result_html.href="/reviews/system/"+xml.getElementsByTagName("system")[0].firstChild.nodeValue+"/"+xml.getElementsByTagName("id")[0].firstChild.nodeValue;
	}else if(dataType=="user_comments"){
		result_html=document.createElement("div");
		r_label[0]="From:";
		r_text[0]=xml.getElementsByTagName("name")[0].firstChild.nodeValue;
		r_text_link[0]="/user/id/"+xml.getElementsByTagName("from_id")[0].firstChild.nodeValue;
		r_label[1]="Date:";
		r_text[1]=xml.getElementsByTagName("created")[0].firstChild.nodeValue;
		if(xml.getElementsByTagName("attachment")[0].firstChild){
			if(xml.getElementsByTagName("attachment")[0].firstChild.nodeValue.indexOf("user_comments")==-1){
				r_label[2]="Attachment:";
				r_text[2]=xml.getElementsByTagName("attachment")[0].firstChild.nodeValue;
				r_text_link[2]="/"+xml.getElementsByTagName("attachment")[0].firstChild.nodeValue;
			}
		}
		r_html=xml.getElementsByTagName("comment")[0].firstChild.nodeValue;
	}
	
	// if there is a href attached, make some pretty hover states
	
	result_html.className=my_result_div.className+" result_box";
	result_html.id=my_result_div.id;
	
	if(result_html.href){
		result_html.target="_blank";
		result_html.onmouseover=function(){
			var new_color=(this.parentNode.parentNode.style.backgroundColor)?this.parentNode.parentNode.style.backgroundColor:'#aaa';
			this.style.backgroundColor=new_color;
			this.style.color="#fff";
		}
		result_html.onmouseout=function(){
			this.style.backgroundColor="#ffe";
			this.style.color="#443";
		}
	}
	
	// clear out the receiving div
	my_result_div.innerHTML="";
	
	// image attachment
	if(r_img){
		var uimg=document.createElement("img");
			uimg.alt="Avatar";
			uimg.src=r_img;
			uimg.className="main_img";
			uimg.style.height="68px";
			uimg.width="68";
			uimg.height="68";
		result_html.appendChild(uimg);
	}
	
	// 'label: value' div assembler
	if(r_text[0]||r_label[0]){
		var description_block=document.createElement("div");
			description_block.className="desc_block";
		for(var t=0;r_label[t];t++){
			if(r_label[t]){
				var b=document.createElement("b");
					b.className="b";
					b.appendChild(document.createTextNode(r_label[t]));
				description_block.appendChild(b);
			}
			if(r_text[t]){
				var text_node=document.createTextNode(r_text[t]);
				if(r_text_link[t]){
					var inner_text_node=text_node;
					text_node=document.createElement("a");
					text_node.href=r_text_link[t];
					text_node.target="_blank";
					text_node.appendChild(inner_text_node);
				}
				var val=document.createElement("div");
					val.className="desc_val";
					val.appendChild(text_node);
				description_block.appendChild(val);
			}else if(r_stars[t]){
				for(var v=0;v<Math.round(r_stars[t]);v++){
					var star=document.createElement("img");
						star.src="/img/icons/small/star-grey.png";
						star.setAttribute("align","abs_middle");
						star.className="star_img";
					description_block.appendChild(star);
				}
				for(var v=Math.round(r_stars[t]);v<5;v++){
					var star=document.createElement("img");
						star.src="/img/icons/small/star-grey-light.png";
						star.setAttribute("align","abs_middle");
						star.className="star_img";
					description_block.appendChild(star);
				}
			}
		}
		result_html.appendChild(description_block);
	}
	
	// raw html
	if(r_html){
		var html_block=document.createElement("div");
			html_block.innerHTML=r_html;
			html_block.className="html_section";
		result_html.appendChild(html_block);
	}
	
	// store the raw xml in the div
	result_html._xml=xml.childNodes[0];

	// try because fades and the like may render the div obsolete before we can append to it
	try{
		my_result_div.parentNode.appendChild(result_html);
		my_result_div.parentNode.removeChild(my_result_div);
	}catch(e){
	
	}
}

/*

	NAVIGATION MENU

*/
var menuOver=false;
var menuDropTime=400;
var nextZ=0;
var newImage=new Array();
function handleNavMenu(){
	var nav=getElement("navigation");
	var navMenus=nav.getElementsByTagName("ul");
	for(i=0;i<navMenus.length;i++){
		var menu=getElement(navMenus[i].id.replace("menu",""));
		navMenus[i].style.position="absolute";
		navMenus[i].style.top="39px";
		navMenus[i].style.display="block";
		navMenus[i].style.height="0px";
		navMenus[i].style.left="-1000px";
		navMenus[i].style.overflow="hidden";
		menu.onmouseover=function(){showSub(this.id+"menu");}
		menu.onmouseout=function(){hideSub(this.id+"menu");}
		var navMenuItems=navMenus[i].getElementsByTagName("a");
		for(j=0;j<navMenuItems.length;j++){
			navMenuItems[j].id="menu"+i+""+j;
		}
	}
	var dumbIE=nav.getElementsByTagName("li");
	for(i=0;i<dumbIE.length;i++){
		if(dumbIE[i].className.indexOf("menuli")>-1){
			dumbIE[i].style.position="relative";
		}
	}
}
function showSub(menuId){
	var thisMenu=getElement(menuId);
	nextZ++;
	if(!msie){
		if(thisMenu.getLeft()+thisMenu.offsetWidth>window.getWidth()){
			thisMenu.style.left=(window.getWidth()-thisMenu.offsetWidth-thisMenu.parentNode.getLeft())+"px";
		}
	}
	thisMenu.style.zIndex=nextZ;
	getElement("navigation").style.zIndex=nextZ+1;
	if(!menuOver){
		menuOver=menuId;
		thisMenu.onmouseover=function(){showSub(menuId);}
		thisMenu.onmouseout=function(){hideSub(menuId);}
		setTimeout('if(menuOver=="'+menuId+'")showSub("'+menuId+'");',300);
	}else if(menuOver==menuId){
		var theight=thisMenu.getAttribute("real_height");
		if(!theight){
			var menuItems=thisMenu.getElementsByTagName("a");
			menuItems[0].style.marginTop="5px";
			for(i=0;i<menuItems.length;i++){
				menuItems[i].id=menuId+"_item"+i;
			}
			oldTop=thisMenu.style.top;
			thisMenu.style.height="auto";
			thisMenu.setAttribute("real_height",thisMenu.offsetHeight);
			theight=thisMenu.offsetHeight;
			thisMenu.style.padding="0";
			thisMenu.style.left="-"+($(thisMenu.id.replace("menu","")).offsetWidth+(thisMenu.id=="item1menu"?5:7))+"px";
		}
		if(thisMenu.style.height!=theight+"px"){
			var baseTween=new Fx.Styles(menuId,{
				duration:menuDropTime,
				transition:Fx.Transitions.Back.easeOut
			});
			baseTween.start({'height':theight+'px'});
		}
	}
}
function hideSub(menuId){
	if(menuOver==menuId){
		menuOver=false;
		setTimeout('setMenuHide("'+menuId+'");',600);
	}
}
function setMenuHide(menuId){
	if(menuOver!=menuId){
		if($(menuId).style.height==$(menuId).getAttribute("real_height")+"px"){
			var baseTween=new Fx.Styles(menuId,{
				duration:menuDropTime,
				transition:Fx.Transitions.Expo.easeOut
			});
			baseTween.start({'height':"0px"});
		}
	}
}

/*

	REGISTRATION & LOGIN

*/
function handlePass(){
	document.quickPass.qpkey.focus();
}
function handleRegistrationStuff(){
	checkWii=function(){
		var numfield1=getElement("wii_number");
		var moreinfo=getElement("additional_user_info");
		numfield1.value=numfield1.value.replace(/[^0-9\-]/,"");
		if(numfield1.value.length>10){
			if(moreinfo.style.display!="block"){
				moreinfo.style.display="block";
				var baseTween=new Fx.Styles("additional_user_info",{
					duration:200,
					onComplete:function(){
						handleRightColumn();
					}
				});
				baseTween.start({'opacity':[0,1]});
				handleRightColumn();
			}
		}else{
			if(moreinfo.style.display=="block"){
				var baseTween=new Fx.Styles("additional_user_info",{
					duration:200,
					onComplete:function(){
						moreinfo.style.display="none";
						handleRightColumn();
					}
				});
				baseTween.start({'opacity':[1,0]});
			}
		}
	}
	var moreinfo=getElement("additional_user_info");
		moreinfo.style.opacity=0;
		moreinfo.style.display="none";
	var numfield1=getElement("wii_number");
		numfield1.onkeydown=checkWii;
		numfield1.onclick=checkWii;
		numfield1.onblur=checkWii;
		numfield1.onfocus=checkWii;
	getElement("country_select").onchange=function(){
		var state_select=getElement("state_select");
		if(this.selectedIndex==0){
			if(state_select.disabled)state_select.removeAttribute("disabled");
		}else{
			state_select.setAttribute("disabled","disabled");
		}
	}
}

/*

BOX RESIZE: MAY DELETE ENTIRELY

*/
var boxOriginal;
function handleBigSmall(){
	var obj=getElement("biggersmaller");
	boxOriginal=obj.offsetHeight;
	var bigger=document.createElement("a");
	bigger.href="javascript:biggerBox();";
	bigger.appendChild(document.createTextNode("Bigger"));
	var smaller=document.createElement("a");
	smaller.href="javascript:smallerBox();";
	smaller.appendChild(document.createTextNode("Smaller"));
	obj.appendChild(document.createElement("br"));
	obj.appendChild(document.createTextNode("("));
	obj.appendChild(bigger);
	obj.appendChild(document.createTextNode("/"));
	obj.appendChild(smaller);
	obj.appendChild(document.createTextNode(")"));
}
function biggerBox(){
	var obj=getElement("biggersmallerbox");
	obj.style.height=(obj.offsetHeight+20)+"px";
	if(obj.offsetHeight>600)obj.style.height="600px";
}
function smallerBox(){
	var obj=getElement("biggersmallerbox");
	obj.style.height=(obj.offsetHeight-20)+"px";
	if(obj.offsetHeight<boxOriginal)obj.style.height=boxOriginal+"px";
}

/*

	COMMENTING
	v 1.2

*/
handleCommentForm=function(){
	try{
		var commentForm=getElement("commentForm");
		//commentForm.action="/insert:comment/";
		commentForm.onsubmit=function(){
			sendComment(commentForm);
			return false;
		}
	}catch(e){alert("Comment Form Preparation Error 1: "+e);}
}
sendComment=function(form){
	var comment=getElement("Comment").value.toString();
	if(stripTags(comment)<=""){
		alert("You have not entered a comment.");
	}else{
		var querystring="objid="+escape(form.objid.value.toString())+"&objtype="+escape(form.objtype.value.toString())+"&objparent="+escape(form.objparent.value.toString())+"&submit=Submit&comment="+escape(comment)+"";
		getElement("submitComment").disabled="disabled";
		var ajax_req=new Ajax("/insert:comment/", {
			method: 'post',
			data: querystring,
			onComplete: processComment
		}).request();
	}
}
processComment=function(txt,xml){
	getElement("commentForm").innerHTML='<div class="text_block">Comment posted successfully.</div>';
	getElement("newComment").innerHTML=txt;
	if(!txt)commentForm.submit();
}
function handleCommentButtons(){
	$("comments").getElements("a[class^=a_hide]").each(function(el){
		el.setAttribute("cid",commentButtonStripID(el.href));
		el.href="javascript:none();";
		el.id="commentHide"+el.getAttribute("cid");
		el.onclick=function(){
			commentHide(this);
		}
	});
	
	$("comments").getElements("a[class^=a_boost]").each(function(el){
		el.setAttribute("cid",commentButtonStripID(el.href));
		el.href="javascript:none();";
		el.id="commentBoost"+el.getAttribute("cid");
		el.onclick=function(){
			commentBoost(this);
		}
	});
	
	$("comments").getElements("a[class^=a_show]").each(function(el){
		el.setAttribute("cid",commentButtonStripID(el.href));
		el.href="javascript:none();";
		el.id="commentShow"+el.getAttribute("cid");
		el.onclick=function(){
			commentShow(this);
		}
	});
}
function commentShow(button){
	var cid=(button.getAttribute("cid"));
	var baseTween1=new Fx.Styles('commentHidden'+cid,{
		duration:400,
		onComplete:function(){}
	});
	var baseTween=new Fx.Styles('commentEdit'+cid,{
		duration:400,
		onComplete:function(){}
	});
	$('commentEdit'+cid).style.visibility="hidden";
	$('commentEdit'+cid).style.display="block";
	$('commentEdit'+cid).style.height="auto";
	var myHeight=$('commentEdit'+cid).offsetHeight;
	$('commentHidden'+cid).style.position="absolute";
	baseTween1.start({'opacity':[1,0]});
	baseTween.start({'height':["30px",myHeight],'opacity':[0,1]});
	$('commentEdit'+cid).style.visibility="visible";
	
	button.innerHTML="Hide";
	button.onclick=function(){
		commentHide(button);
	}
}
function commentHide(button){
	if(button.innerHTML!="Disapproved"){
		var cid=(button.getAttribute("cid"));
		if(!$('commentHidden'+cid)){
			new Ajax("?ajax=true&comment_hide="+cid, {
				method:'get',
				onComplete:function(txt,xml){
					$('commentHidden'+cid).innerHTML=("This comment is below your viewing threshold.");
				}
			}).request();
			
			var chdiv=new Element('div',{
				'class':'forum_posthidden',
				'id':'commentHidden'+cid
			});
			
			$('commentEdit'+cid).parentNode.insertBefore(chdiv,$('commentEdit'+cid).nextSibling);
		}
		var baseTween=new Fx.Styles('commentHidden'+cid,{
			duration:400,
			onComplete:function(){
				//$('commentHidden'+cid).style.position="relative";
				//$('commentHidden'+cid).style.height="auto";
			}
		});
		baseTween.start({'opacity':[0,1]});
		var baseTween=new Fx.Styles('commentEdit'+cid,{ duration:400 });
		$('commentEdit'+cid).style.display="block";
		var myHeight=$('commentEdit'+cid).offsetHeight-10;
		baseTween.start({'opacity':[1,0],'height':[myHeight,"30px"]});
		
		if(button.innerHTML=="Disapprove"){
			button.innerHTML="Disapproved";
			button.onclick=function(){ none(); }
			
			if($('commentBoost'+cid)){
				$('commentBoost'+cid).innerHTML="Approved";
				$('commentBoost'+cid).onclick=function(){ commentBoost($('commentBoost'+cid)); }
			}
			
			var button=new Element('a',{
				'class':'a_show',
				'id':'commentShow'+cid,
				'cid':cid
			});
			
			$('commentControls'+cid).insertBefore(button,$("commentBoost"+cid));
		}
		
		button.onclick=function(){
			commentShow(this);
		}
		button.innerHTML="Show";
	}
}
function commentBoost(button){
	var cid=button.getAttribute("cid");
	new Ajax("?ajax=true&comment_boost="+cid, {
		method:'get',
		onComplete:function(txt,xml){
			button.innerHTML="Approved";
			commentShow($("commentShow"+cid));
			button.onclick=function(){
				none();
			}
			if($('commentHide'+cid)){
				$('commentHide'+cid).innerHTML="Disapprove";
				$('commentHide'+cid).onclick=function(){ commentHide($('commentHide'+cid)); }
			}
			if($('commentShow'+cid)){
				$('commentShow'+cid).parentNode.removeChild($('commentShow'+cid));
			}
		}
	}).request();
}
function commentButtonStripID(href){
	href=href.replace(/.*\?comment\_[a-z]+\=/,"");
	while(/[^0-9]/.test(href)){ href=href.replace(/[^0-9]+/,""); }
	return href;
}

/*

	VOTING
	v 1.9

*/
function handleStars(){
	var star=new Array();
	document.objType=url_strip_base(window.location); // ?
	for(var s=0;getElement("rateForm"+s);s++){
		var rateForm=$("rateForm"+s);
		rateFormCount++;
		handleRateForm(rateForm,s);
	}
}
function handleStar(star,group){
	star.setProperty("ogsrc",star.src);
	star.setProperty("s",group);
	star.addEvent('mouseenter', function(){
		var s=this.getProperty("s");
		for(var j=1;j<6;j++){
			getElement("star"+s+"-"+j).src="/img/icons/small/star-grey"+(j>this.value?'-light':'')+'.png';
		}
	});
	star.addEvent('mouseleave', function(){
		if(this){
			var s=this.getProperty("s");
			for(var j=1;j<6;j++){
				var star=getElement("star"+s+"-"+j);
				if(star)star.src=star.getProperty("ogsrc");
			}
		}
	});
	star.addEvent("click", function(event){
		var rateForm=getElement("rateForm"+this.getProperty("s"));
		rateForm.rating.value=this.value;
		if(rateForm.getAttribute("action")){
			var s_vote_type=url_strip_base(rateForm.getAttribute("action"));
			var s_vote_id=url_strip_id(rateForm.getAttribute("action"));
		}else{
			var s_vote_type=url_strip_base(window.location);
			var s_vote_id=url_strip_id(window.location);
		}
		var s_vote=rateForm.rating.value;
		placeVote(s_vote_type,s_vote_id,s_vote,rateForm.getAttribute("s"));
		event=new Event(event);
		event.stop();
	});
}
function handleRateForm(form,group){
	form.setAttribute("s",group);
	form.onsubmit=function(){ return false; }
	var star=form.getElements("input");
	for(var i=0;star[i];i++){
		handleStar(star[i],group);
	}
}
var rateFormCount=0;
function createRateForm(pnode,objtype,objid,score){
	rateFormCount++;
	
	var wrap=new Element('div',{
		'class':'mii_index_rating',
		'id':'rating'+rateFormCount
	});
	
	var frm=new Element('form',{
		'method':'GET',
		'action':'/'+objtype+'/'+objid+'/',
		'class':"rating",
		'id':'rateForm'+rateFormCount
	});
	
	for(var i=1;i<6;i++){
		var star=new Element('input', {
			'id':'star'+rateFormCount+"-"+i,
			'type':"image",
			'src':"/img/icons/small/star-grey"+(Math.round(score)<i?'-light':'')+'.png',
			'name':"rate",
			'value':i,
			'class':"rateButton",
			'dynamic':'yes'
		});
		//star.addEvent("click", function(){ this.parentNode.submit(); });
		frm.appendChild(star);
	}
	
	var hid=new Element('input', {
		'type':'hidden',
		'name':'objtype',
		'value':objtype
	});
	frm.appendChild(hid);
	
	var hid=new Element('input', {
		'type':'hidden',
		'name':'num',
		'value':rateFormCount
	});
	frm.appendChild(hid);
	
	var hid=new Element('input', {
		'type':'hidden',
		'name':'id',
		'value':objid
	});
	frm.appendChild(hid);
	
	var hid=new Element('input', {
		'type':'hidden',
		'name':'rating',
		'value':'3'
	});
	frm.appendChild(hid);
	
	wrap.appendChild(frm);
	pnode.appendChild(wrap);
	
	handleRateForm(frm,rateFormCount);
}
var voteReq=new Array();
function placeVote(objtype,objid,vote,num){
	document.vote_default="/"+objtype+"/"+objid+"/vote/"+vote+"/"; // ?
	new Ajax("/vote/"+objtype+"/"+objid+"/"+vote+"/"+num+"/", {
		method:'get',
		update:$("rating"+num),
		onComplete:function(txt,xml){
			var new_pop_text=$("rating"+num).getElementsByTagName("span")[1].innerHTML;
				new_pop_text=new_pop_text.replace('(','');
				new_pop_text=new_pop_text.replace(')','<br /><br />');
			var pop_text=$('pop_text_holder').innerHTML;
			$('pop_text_holder').innerHTML=pop_text.replace(/[0-9\.]+\ Votes\,\ [0-9\.]+\ Average/,new_pop_text);
		}
	}).request();
}

/*

	FORUM

*/
function handleForum(){
	if(getElement("bookmarks"))handleForumButtons(getElement("bookmarks").getElementsByTagName('input'));
	if(getElement("stickies"))handleForumButtons(getElement("stickies").getElementsByTagName('input'));
	handleForumButtons(getElement("forum").getElementsByTagName('input'));
}
function handleForumButtons(buttonArray){
	for(i=0;i<buttonArray.length;i++){
		if(/unflag/.test(buttonArray[i].name)){
			buttonArray[i].onmouseover=function(){this.src='/img/flag-clear.gif';}
			buttonArray[i].onmouseout=function(){this.src='/img/flag-red.gif';}
		}
		if(/addflag/.test(buttonArray[i].name)){
			buttonArray[i].onmouseover=function(){this.src='/img/flag-red.gif';}
			buttonArray[i].onmouseout=function(){this.src='/img/flag-clear.gif';}
		}
		if(/unbookmark/.test(buttonArray[i].name)){
			buttonArray[i].onmouseover=function(){this.src='/img/bookmark-clear.gif';}
			buttonArray[i].onmouseout=function(){this.src='/img/bookmark-blue.gif';}
		}
		if(/addbookmark/.test(buttonArray[i].name)){
			buttonArray[i].onmouseover=function(){this.src='/img/bookmark-blue.gif';}
			buttonArray[i].onmouseout=function(){this.src='/img/bookmark-clear.gif';}
		}
	}
}
function forumQuote(id){
	getElement("Comment").appendChild(document.createTextNode("[quote]"+id+"[/quote]"));
	window.scrollTo(0,getElement("Comment").offsetHeight+getElement("Comment").offsetTop);
}
/* FORUM: EDIT */
var oldtext;
function cEdit(eid){
	var button=getElement("cEditButton"+eid);
	button.innerHTML="";
	button.appendChild(document.createTextNode("Close"));
	button.href="javascript:cHide("+eid+")";
	if(!getElement("commentEditJS"+eid)){
		var block=getElement("commentEdit"+eid);
		var editArea=document.createElement("textarea");
		editArea.id="commentEditJS"+eid;
		//document.eid=eid;
		editArea.style.width=block.offsetWidth+"px";
		damnYouMSIE=block.offsetHeight;
		editArea.style.height=((iex)?damnYouMSIE-58:damnYouMSIE)+"px";
		editArea.style.position="absolute";
		editArea.style.top=0;
		editArea.style.left=0;
		editArea.value="Loading...";
		block.style.position="relative";
		block.appendChild(editArea);
		var ajax_req=new Ajax("/forum/edit/ajax/"+eid, {
			method:'get',
			data:"id="+eid,
			onComplete:function(txt,xml){ createEditForm(txt,xml,eid); }
		}).request();
	}else{
		getElement("commentEditJS"+eid).style.display="block";
	}
	var submitButton=document.createElement("a");
	submitButton.href="javascript:submitEdit("+eid+")";
	submitButton.appendChild(document.createTextNode("Save"));
	getElement("additionalControls"+eid).appendChild(submitButton);
}
function createEditForm(txt,xml,eid){
	if(getElement("commentEditJS"+eid)){
		html_content=txt.toString();
		/*
		while(html_content.test(/\*lt\;/)){html_content=html_content.replace(/\*lt\;/,"<");}
		while(html_content.test(/\*gt\;/)){html_content=html_content.replace(/\*gt\;/,">");}
		while(html_content.test(/\*amp\;/)){html_content=html_content.replace(/\*amp\;/,"&amp;");}
		while(html_content.test(/\*apos\;/)){html_content=html_content.replace(/\*apos\;/,"&apos;");}
		while(html_content.test(/\*quot\;/)){html_content=html_content.replace(/\*quot\;/,"&quot;");}
		*/
		while(html_content.test(/\*lt\;/)){html_content=html_content.replace(/\*lt\;/,"<");}
		while(html_content.test(/\*gt\;/)){html_content=html_content.replace(/\*gt\;/,">");}
		while(html_content.test(/\*amp\;/)){html_content=html_content.replace(/\*amp\;/,"&");}
		while(html_content.test(/\*apos\;/)){html_content=html_content.replace(/\*apos\;/,"'");}
		//while(html_content.test(/\*quot\;/)){html_content=html_content.replace(/\<br\ \/\>/,'"');}
		while(html_content.test(/\*quot\;/)){html_content=html_content.replace(/\*quot\;/,'"');}
		getElement("commentEditJS"+eid).value=html_content;
	}
	//new widgEditor("commentEditJS"+eid);
	if(!txt)location.href="/forum/edit/"+document.eid;
}
function cHide(eid){
	if(getElement("commentEditJS"+eid)){
		getElement("commentEditJS"+eid).style.display="none";
		getElement("commentEdit"+eid).style.paddingBottom="0";
		if($("commentEditJS"+eid+"WidgContainer")){
			getElement("commentEditJS"+eid+"WidgContainer").style.display="none";
			getElement("commentEditJS"+eid+"WidgContainer").parentNode.removeChild(getElement("commentEditJS"+eid+"WidgContainer"));
		}else{
			getElement("commentEditJS"+eid).style.display="none";
			getElement("commentEditJS"+eid).parentNode.removeChild(getElement("commentEditJS"+eid));
		}
		var button=getElement("cEditButton"+eid);
		button.innerHTML="";
		button.appendChild(document.createTextNode("Edit"));
		button.href="javascript:cEdit("+eid+")";
		getElement("additionalControls"+eid).innerHTML="";
	}
}
function submitEdit(eid){
	if($("commentEditJS"+eid+"WidgContainer"))$("commentEditJS"+eid+"WidgContainer").self.updateWidgInput();
	queryString="comment="+escape(getElement("commentEditJS"+eid).value);
	var ajax_req=new Ajax("/forum/edit/ajax/"+eid+"?"+queryString, {
		method:'post',
		data:queryString,
		onComplete: function(txt,xml){ processEdit(txt,xml,eid); }
	}).request();
}
function processEdit(txt,xml,eid){
	getElement("additionalControls"+eid).innerHTML="";
	cHide(eid);
	try{
		var mycomment=xml.getElementsByTagName("comment")[0].firstChild.nodeValue;
		var mydate=xml.getElementsByTagName("updated")[0].firstChild.nodeValue;
	}catch(e){
		try{
			var container=document.createElement('div');
			container.innerHTML=txt;
			var mycomment=getElement('iecomment');
			var mydate=getElement('ieupdated');
		}catch(e){alert(e);}
	}
	if(getElement("commentEdit"+eid)){
		if(mycomment.indexOf("*gt;")>-1){
			while(mycomment.indexOf("*gt;")>-1){
				mycomment=mycomment.replace("*gt;",">");
			}
		}
		if(mycomment.indexOf("*lt;")>-1){
			while(mycomment.indexOf("*lt;")>-1){
				mycomment=mycomment.replace("*lt;","<");
			}
		}
		if(mycomment.indexOf("*amp;")>-1){
			while(mycomment.indexOf("*amp;")>-1){
				mycomment=mycomment.replace("*amp;","&");
			}
		}
		if(mycomment.indexOf("*quot;")>-1){
			while(mycomment.indexOf("*quot;")>-1){
				mycomment=mycomment.replace("*quot;","\"");
			}
		}
		if(mycomment.indexOf("*apos;")>-1){
			while(mycomment.indexOf("*apos;")>-1){
				mycomment=mycomment.replace("*apos;","'");
			}
		}
		getElement("commentEdit"+eid).innerHTML=mycomment;
	}
	if(getElement("editedDate"+eid)){
		getElement("editedDate"+eid).innerHTML="";
		getElement("editedDate"+eid).appendChild(document.createElement("br"))
		getElement("editedDate"+eid).appendChild(document.createTextNode("Edited "+mydate));
	}
}
/* FORUM: POLLS */
var pollOptionCurrent;
function handlePollOptions(){
	var poll_controls=getElement("poll_controls");
	var poll_controls_label=document.createElement("label");
	poll_controls_label.appendChild(document.createTextNode("Poll Options:"));
	poll_controls.appendChild(poll_controls_label);
	var poll_controls_add=document.createElement("a");
	poll_controls_add.href="javascript:pollOptionAdd()";
	poll_controls_add.appendChild(document.createTextNode("Add Option"));
	poll_controls.appendChild(poll_controls_add);
	poll_controls.appendChild(document.createTextNode(" | "));
	var poll_controls_sub=document.createElement("a");
	poll_controls_sub.href="javascript:pollOptionRemove()";
	poll_controls_sub.appendChild(document.createTextNode("Remove Option"));
	poll_controls.appendChild(poll_controls_sub);
	poll_controls.appendChild(document.createElement("br"));
	pollOptionCurrent=5;
	try{
		var lastKnown;
		for(var i=3;getElement("poll_opt_"+i);i++){
			lastKnown=i;
		}
		pollOptionCurrent=lastKnown;
	}catch(e){}
}
function pollOptionRemove(){
	var poll_options=getElement("poll_options");
	if(getElement("poll_opt_"+pollOptionCurrent)){
		poll_options.removeChild(getElement("poll_opt_"+(pollOptionCurrent)));
		pollOptionCurrent--;
	}
}
function pollOptionAdd(){
	if(pollOptionCurrent<12){
		pollOptionCurrent++;
		var poll_options=getElement("poll_options");
		var poll_option=document.createElement("div");
		poll_option.id="poll_opt_"+pollOptionCurrent;
		var poll_option_label=document.createElement("label");
		poll_option_label.appendChild(document.createTextNode("Poll Option "+pollOptionCurrent+":"));
		poll_option.appendChild(poll_option_label);
		var poll_option_input=document.createElement("input");
		poll_option_input.type="text";
		poll_option_input.maxlength="255";
		poll_option_input.name="pollopt"+pollOptionCurrent;
		poll_option_input.id="Poll_Option_"+pollOptionCurrent;
		poll_option.appendChild(poll_option_input);
		poll_option.appendChild(document.createElement("br"));
		poll_options.appendChild(poll_option);
	}
}
function handlePollForm(){
	for(i=0;$("poll_form_"+i);i++){
		var poll_form=$("poll_form_"+i);
		for(var u=0;$("poll_radio_"+i+"_"+u);u++){
			var poll_bar=getElement("poll_bar_"+i+"_"+u);
			poll_bar.setAttribute("number",u);
			poll_bar.setAttribute("poll_number",i);
			poll_bar.onmouseover=function(){
				this.style.color="#000";
				this.style.cursor="pointer";
			}
			poll_bar.onmouseout=function(){
				this.style.color="#444";
			}
			poll_bar.onclick=function(){
				var u=this.getAttribute("number");
				var i=this.getAttribute("poll_number");
				var r=$("poll_radio_"+i+"_"+u)
				$("poll_form_"+i).setAttribute("vote",r.value);
				r.checked="checked";
			}
		}
		poll_form.setAttribute("i",i);
		poll_form.onsubmit=function(){
			var ajax_req=new Ajax("/insert:poll/", {
				method:'post',
				data:"pollVote="+this.pollVote.value+"&vote="+this.getAttribute("vote"),
				update: $('poll_'+this.getAttribute("i"))
			}).request();
			return false;
		}
	}
}

/*
function setColor1(col){
	getElement("color1t").value=col;
	getElement("color1p").style.backgroundColor="#"+col;
}
function setColor2(col){
	getElement("color2t").value=col;
	getElement("color2p").style.backgroundColor="#"+col;
}
*/

/*

	WIIDGET

*/
function handleWiidget(){
	//getElement("color1t").onchange=function(){setColor1(this.value);}
	//getElement("color2t").onchange=function(){setColor2(this.value);}
	getElement("previewWiidget").href="javascript:previewWiidget()";
	getElement("previewWiidget2").href="javascript:previewWiidget()";
}
function handleColorPicker(){
	loadSV(1);
	loadSV(2);
	updateH('307EC5',1);
	updateH('ffffff',2);
}
function previewWiidget(){
	var col1=getElement("plugHEX1").innerHTML;
	var col2=getElement("plugHEX2").innerHTML;
	var cardstyle=getElement("cardstyle").value;
	getElement("previewImage").src="http://gamercreated.com/wiidgetpreview/"+getElement("wiiCode").value+"/"+col1+"/"+col2+"/"+cardstyle;
	if(getElement("wiidgetCode"))getElement("wiidgetCode").innerHTML='&lt;a href="http://gamercreated.com/user/'+getElement("wiiCode").value+'"&gt;&lt;img src="http://gamercreated.com/wiidget/'+getElement("wiiCode").value+'/'+col1+"/"+col2+"/"+cardstyle+'" border="0" /&gt;&lt;/a&gt;';
}

/*

	MISCELLANEOUS

*/
function none(){}

function appendTextNode(obj,str){
	obj.appendChild(document.createTextNode(str));
}
function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue=document.defaultView.getComputedStyle(oElm,"").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

function handleBadgeList(){
	var badge_list=getElement("badge_list").getElementsByTagName("img");
	for(var i=0;badge_list[i];i++){
		badge_list[i].setAttribute("badge_title",badge_list[i].getAttribute("title"));
		badge_list[i].removeAttribute("title");
		badge_list[i].setAttribute("id","badge_"+i);
		badge_list[i].style.cursor="help";
		badge_list[i].onmouseover=function(){
			this.setAttribute("mouse","on");
			setTimeout("popInfo('"+this.id+"');",1000);
		}
		badge_list[i].onmouseout=function(){
			this.setAttribute("mouse","off");
		}
	}
}
function handleMiiLists(){
	if(getElement("miilist"))handleMiiList($("miilist"));
	
	$("content").getElements("ul[class=miilist]").each(function(el){
		handleMiiList(el);
	});
}
var poplist=0;
function handleMiiList(ul){
	var overimg=document.createElement("img");
		overimg.src="/img/info_pop.png";
	var item_list=ul.getElements("img");
	for(var i=0;item_list[i];i++){
		item_list[i].setAttribute("pop_title",item_list[i].getAttribute("title"));
		item_list[i].removeAttribute("title");
		item_list[i].setAttribute("id","popitem_"+i+"_"+poplist);
		poplist++;
		item_list[i].addEvent('mouseenter', function(){
			this.setProperty("my_mouse","on");
			setTimeout("popInfo2('"+this.id+"');",200);
		});
		item_list[i].addEvent('mouseleave', function(){
			this.setProperty("my_mouse","off");
		});
	}
	var item_list=ul.getElementsByTagName("div");
	for(var i=0;item_list[i];i++){
		item_list[i].style.display='none';
	}
}

function removePop(pop,obj){
	try{
		obj=obj.getProperty('my_mouse');
		if(obj=="off"||obj=="force"){
			var baseTween=new Fx.Styles(pop.id,{
				duration:400,
				onComplete:function(){
					if(pop)pop.parentNode.removeChild(pop);
				}
			});
			baseTween.start({'opacity':[1,0]});
		}
	}catch(e){
		if(pop)pop.parentNode.removeChild(pop);
	}
}

function popInfo2(obj_id){
	var old_pops=document.getElements('div[class=item_pop]');
	for(var i=0;i<old_pops.length;i++){
		removePop(old_pops[i],"force");
	}
	var obj=getElement(obj_id);
	if(obj.getProperty('my_mouse')=='on'){
		var pop=new Element("div",{
			'class':"item_pop",
			'id':"pop_"+obj_id
		});
		pop.style.left=(obj.parentNode.offsetLeft-8)+"px";
		if(msie)pop.style.left=(obj.parentNode.offsetLeft-30)+"px";
		pop.style.top=(obj.parentNode.offsetTop-25)+"px";
		pop.style.opacity="0";
		pop.style.filter='alpha(opacity=0)';
		pop.style.zindex='2000';
		pop.style.cursor='pointer';
		pop.addEvent('click',function(){
			window.location=obj.parentNode.href;
		});
		
		var hot_spot=new Element('a',{
			'class':'item_pop_hot',
			'pop_id':pop.id,
			'href':obj.parentNode.href
		});
		hot_spot.style.width=(obj.offsetWidth+3)+"px";
		hot_spot.style.height=(obj.offsetHeight+3)+"px";
		hot_spot.style.position="absolute";
		hot_spot.style.cursor="pointer";
		hot_spot.addEvent('mouseenter',function(){
			obj.setProperty('my_mouse','on');
		});
		hot_spot.addEvent('mouseleave',function(){
			obj.setProperty('my_mouse','off');
			setTimeout("removePop($('"+pop.id+"'),$('"+obj.id+"'));",100);
		});
		hot_spot.addEvent('click',function(){
			window.location=obj.parentNode.href;
		});
		pop.appendChild(hot_spot);
		var b=document.createElement("b");
			appendTextNode(b,obj.getAttribute("alt"));
			pop.appendChild(b);
		var pop_icon=document.createElement("img");
			pop_icon.src=obj.src;//.replace(/(.*)\/[0-9]+\/[0-9]+\/(.*)/,"$1/75/75/$2");
			pop.appendChild(pop_icon);
		createRateForm(pop,"mii",url_strip_id(obj.parentNode.href),obj.parentNode.getElementsByTagName("label")[0].className);
		
		pop.getElements("div").each(function(el){
			el.addEvent('mouseenter',function(){obj.setProperty("my_mouse","on");});
			el.addEvent('mouseleave',function(){obj.setProperty("my_mouse","off");});
		});
		pop.getElements("form").each(function(el){
			el.addEvent('mouseenter',function(){obj.setProperty("my_mouse","on");});
			el.addEvent('mouseleave',function(){obj.setProperty("my_mouse","off");});
		});
		pop.getElements("input").each(function(el){
			el.addEvent('mouseenter',function(){obj.setProperty("my_mouse","on");});
			el.addEvent('mouseleave',function(){obj.setProperty("my_mouse","off");});
		});
		
		var pop_text=obj.getAttribute("pop_title");
		var pop_text_holder=document.createElement("div");
			pop_text_holder.id="pop_text_holder";
			appendTextNode(pop_text_holder,pop_text);
		while(pop_text_holder.innerHTML.indexOf(".#.")>0){
			pop_text_holder.innerHTML=pop_text_holder.innerHTML.replace(".#.","<br />");
		}
		pop.appendChild(pop_text_holder);
		
		
		obj.parentNode.parentNode.appendChild(pop);
		
		var baseTween = new Fx.Styles(pop.id, {duration:300});
		baseTween.popid=pop.id;
		baseTween.start({'opacity':[0,1]});
	}
}
function popInfo(obj_id){
	var obj=getElement(obj_id);
	if(obj.getAttribute('mouse')=='on'){
		var pop=document.createElement("div");
			pop.className="badge_pop";
			pop.id="pop_"+obj_id;
			pop.style.left=(obj.offsetLeft-10)+"px";
			pop.style.top=(obj.offsetTop-10)+"px";
		var hot_spot=document.createElement("div");
			hot_spot.style.width=obj.offsetWidth+"px";
			hot_spot.style.height=obj.offsetHeight+"px";
			hot_spot.style.position="absolute";
			hot_spot.setAttribute("pop_id",pop.id);
			hot_spot.addEvent('mouseleave',function(){
				var pop=getElement(this.getAttribute("pop_id"));
				if(pop){
					var baseTween=new Fx.Styles(this.getAttribute("pop_id"), {
						duration:300,onComplete:function(){
							var me=getElement(this.popid);
							me.parentNode.removeChild(me);
						}
					});
					baseTween.popid=this.getAttribute("pop_id");
					baseTween.start({'opacity':[1,0]});
				}
			});
			pop.appendChild(hot_spot);
		var b=document.createElement("b");
			appendTextNode(b,obj.getAttribute("alt"));
			pop.appendChild(b);
		var pop_icon=document.createElement("img");
			pop_icon.src=obj.src.replace("badges/","badges/large/");
			pop.appendChild(pop_icon);
		var pop_text=obj.getAttribute("badge_title")
			appendTextNode(pop,pop_text);
		pop.style.opacity="0";
		pop.style.filter='alpha(opacity=0)';
		pop.target_opacity="1";
		pop.onTweenFinish=function(){
			if(this.target_opacity==0){
				this.parentNode.removeChild(this);
			}
		}
		
		obj.parentNode.appendChild(pop);
		var baseTween=new Fx.Styles(pop.id,{duration:200});
		baseTween.popid=pop.id;
		baseTween.start({'opacity':[0,1]});
	}
}

var autoCompleteItems=new Array();
var autoCompleteItemIds=new Array();
function handleGameBox(box){
	var game_select=getElement(box);
	var game_menu=game_select.getElementsByTagName("select")[0];
	var game_groups=game_menu.getElementsByTagName("optgroup");
	if(game_groups){
		for(var i=0;game_groups[i];i++){
			var prefix=game_groups[i].getAttribute("label").replace("Nintendo ","")+": ";
			var games=game_groups[i].getElementsByTagName("option");
			for(var j=0;games[j];j++){
				autoCompleteItems.push(prefix+games[j].innerHTML);
				autoCompleteItemIds.push(games[j].getAttribute("value"));
			}
		}
	}else{
		var games=game_menu.getElementsByTagName("option");
		for(var j=0;games[j];j++){
			autoCompleteItems.push(prefix+games[j].innerHTML);
			autoCompleteItemIds.push(games[j].getAttribute("value"));
		}
	}
	
	var game_menu_name=game_menu.name;
	game_menu.parentNode.removeChild(game_menu);
	var game_input=document.createElement("input");
	game_input.id="game_input";
	game_input.type="text";
	game_select.appendChild(game_input);
	var game_input_hidden=document.createElement("input");
	game_input_hidden.type="hidden";
	game_input_hidden.id="select_game_id";
	game_input_hidden.name=game_menu_name;
	game_select.appendChild(game_input_hidden);
	
	var game_form=getElement("add_game_form");
	game_form.onsubmit=function(){
		getElement("select_game_id").value="";
		for(var j=0;autoCompleteItems[j];j++){
			if(getElement("game_input").value==autoCompleteItems[j]){
				getElement("select_game_id").value=autoCompleteItemIds[j];
			}
		}
		if(getElement("select_game_id").value<1){
			if(getElement("Null_Game")==undefined){
				alert("The game name you entered is not a game we recognize. If you are having issues, please reload the page. If problems persist, please contact us.");
				return false;
			}
		}
	}
	
	var imgpre1=document.createElement("img");
		imgpre1.src="/img/arrow/up-disabled.png";
	var imgpre2=document.createElement("img");
		imgpre2.src="/img/arrow/down-disabled.png";
	var imgpre3=document.createElement("img");
		imgpre3.src="/img/arrow/up.png";
	var imgpre4=document.createElement("img");
		imgpre4.src="/img/arrow/down.png";
	var imgpre5=document.createElement("img");
		imgpre5.src="/img/scroll.png";
	
	actb(game_input,autoCompleteItems,game_select);
}

/*

	POPCAL

*/

function handleBDcal(){ //birthday
	var sDate=new Date(1985,9,18);
	if($('date').value>0&&$('month').value>0&&$('year').value>0){
		try{
			var sDate=new Date($('year').value,($('month').value-1),$('date').value);
		}catch(e){
			var sDate=new Date(1985,9,18);
		}
	}
	var calendar = new Calendar("bd_cal", "bd_cal_toggler", {
		inputField:{date:'date',month:'month',year:'year'},
		inputType:'select',
		startDate:new Date(1920,0,1),
		endDate:'today',
		offset:{x:0, y:-140},
		selectedDate:sDate,
		allowWeekendSelection:true
	});
}
function handleCcal(){ //challenge
	var sDate=new Date();
	if($('date').value>0&&$('month').value>0&&$('year').value>0){
		try{
			var sDate=new Date($('year').value,($('month').value-1),$('date').value);
		}catch(e){
			var sDate=new Date();
		}
	}
	var new_y=$("challenge_cal").parentNode.getCoordinates();
	var calendar = new Calendar("challenge_cal", "challenge_cal_toggler", {
		inputField:{date:'date',month:'month',year:'year'},
		inputType:'select',
		offset:{x:0, y:-(new_y.y)},
		selectedDate:sDate,
		allowWeekendSelection:true
	});
}

/*

	BLOCK

*/
function handleBlockLinks(){
	document.getElements('a[class=block_user_single]').each(function(el) {
		el.setAttribute("user_id",url_strip_id(el.href));
		el.addEvent('click', function() {
			blockUser(this.getAttribute("user_id"),this);
		});
		el.href="javascript:none()";
	});
	document.getElements('a[class=unblock_user_single]').each(function(el) {
		el.setAttribute("user_id",url_strip_id(el.href));
		el.addEvent('click', function() {
			unblockUser(this.getAttribute("user_id"),this);
		});
		el.href="javascript:none()";
	});
	$("content").getElements('a[class^=widgetBlock]').each(function(el) {
		el.setAttribute("old_href",el.href);
		el.href='javascript:none();';
		
		handleWidgetListButton(el);
		
		el.setAttribute("user_id",url_strip_id(el.href));
		el.addEvent('click', function() {
			if(getElement("widget_"+this.getAttribute("widget_num")+"_detail")._xml){
				if(document.widget_last==this.getAttribute("widget_num")){
					var my_xml=getElement("widget_"+this.getAttribute("widget_num")+"_detail")._xml;
					var user=Array();
					if(my_xml.getElementsByTagName("type")[0].firstChild.nodeValue=="user_comments"){
						user["id"]=my_xml.getElementsByTagName("from")[0].getElementsByTagName("id")[0].firstChild.nodeValue;
						user["name"]=my_xml.getElementsByTagName("from")[0].getElementsByTagName("name")[0].firstChild.nodeValue;
					}else if(my_xml.getElementsByTagName("type")[0].firstChild.nodeValue=="wiis"){
						user["id"]=my_xml.getElementsByTagName("id")[0].firstChild.nodeValue;
						user["name"]=my_xml.getElementsByTagName("name")[0].firstChild.nodeValue;
					}
					if(el.getElements("span")[0].innerHTML=="Unblock"){
						unblockUser(user["id"],el);
					}else{
						blockUser(user["id"],el);
					}
				}else{
					eval(unescape(el.getAttribute("old_href")));
				}
			}
		});
		el.href="javascript:none()";
	});
}
function blockUser(user_id,el){
	var ajax_req=new Ajax("/user/block/"+user_id+"/ajax/", {
		method: 'get',
		onComplete: function(txt,xml){
			el.getElements("span")[0].innerHTML="Unblock";
			el.removeEvent('click');
			el.addEvent('click',function() {
				unblockUser(this.getAttribute("user_id"),this);
			});
		}
	}).request();
}
function unblockUser(user_id,el){
	var ajax_req=new Ajax("/user/unblock/"+user_id+"/ajax/", {
		method: 'get',
		onComplete: function(txt,xml){
			el.getElements("span")[0].innerHTML="Block";
			el.removeEvent('click');
			el.addEvent('click',function() {
				blockUser(this.getAttribute("user_id"),this);
			});
		}
	}).request();
}

/*

	ADD FRIEND LINKS

*/
function handleAddFriendLinks(){
	document.getElements('a[class=friend_request_link]').each(function(el) {
		var user=Array();
		user["id"]=url_strip_id(el.href);
		user["name"]=el.title.replace("Send Friend Request to ","");
		el.addEvent('click',function(){
			mailTo(user,"login","friends");
		});
		el.href="javascript:none()";
	});
}


function handlePost(container,details){
	details.style.marginLeft=container.offsetWidth+"px";
}

function checks(checkem,i){
	$(i).getElements("input[type=checkbox]").each(function(el){
		el.checked=checkem;
	});
}