if(location.href.match("act=UserCP&CODE")){
	var divs = document.getElementsByTagName("div")
	for(var k=divs.length-1;k>-1;k--){
		if(divs[k].className == 'pformstrip' && divs[k].innerHTML.match("Subscriptions")){
			var div = document.createElement("div")
			div.setAttribute("class", "pformstrip")
			div.innerHTML = "Nation Information"
			divs[k].parentNode.insertBefore(div,divs[k])
			k++ 
			var p = document.createElement("p")
			p.innerHTML = " . <a href='"+location.href.split("?")[0]+"?act=UserCP&CODE=AddProfile'>Manage Nation Information</a><br />"
			divs[k].parentNode.insertBefore(p,divs[k])
		}
	}
}
if(location.href.match("act=UserCP&CODE=AddProfile")!=null){
	a="<br /><br /><span id='check_profile'><div align='center'><br /><b>Loading, please wait...<br /><br /><img src='http://209.85.48.12/11661/52/upload/p2153323.gif'><br /><br /><br /></div></span>";
	document.getElementById("ucpcontent").innerHTML="<div class='maintitle'>Manage Nation Information</div>"+a;
	document.write("<iframe name='Profile' id='Profile' frameborder='0' src='"+location.href.split("?")[0]+"?act=UserCP&CODE=22' height='0' width='0' onload='Check_Profile();'></iframe>");
}
function Check_Profile(){
	var Profile = window.frames['Profile'].document.getElementsByTagName("div");
	for(z=0;z<Profile.length;z++){
		if(Profile[z].className=="signature"){
			if(Profile[z].innerHTML.match(/\[TCZ\](.*),(.*),(.*),(.*)\[\/TCZ\]/i)!=null){
				a = "Your Current Nation Information:<br /><br />";
					if(RegExp.$1 != ""){
						a += "Your Tech Status: <b>"+RegExp.$1+"</b>  <input type='button' value='Reset Tech Info' onclick='Reset_Gender();'><br />";
					}
					if(RegExp.$1 == ""){
						a += "<br />Edit your Tech Status: <form><select onchange='Set_Gender(this.options[this.selectedIndex].value)'><option value=''>Choose your Tech Status";
						a += "<option value='Neither'>Neither<option value='Buying'>Buying<option value='Selling'>Selling";
						a += "</select></form><br />";
					}
					if(RegExp.$2 != ""){
						a += "<br />Your Nation ID: <b>"+RegExp.$2+"</b>  <input type='button' value='Reset Nation ID' onclick='Reset_NID();'><br />";
					}
					if(RegExp.$2 == ""){
						a += "<br />Edit your Nation ID: <input type='text' value='' id='age' maxlength='6' size='8'> <input type='button' value='Edit Nation ID' onclick='Set_NID();'><br />";
					}
					if(RegExp.$3 != ""){
						a += "<br />Your Nation Name: <b>"+RegExp.$3+"</b>  <input type='button' value='Reset Nation Name' onclick='Reset_Name();'><br />";
					}
					if(RegExp.$3 == ""){
						a += "<br />Edit your Nation Name: <input type='text' value='' id='nName' maxlength='16' size='18'> <input type='button' value='Edit Name' onclick='Set_Name();'><br />";
					}
				a += "<br /><br /><input type='button' value='Reset All Profile Info' onclick='Reset_Profile();'>";
			}
			else{
				a = "You don\'t have any Nation Information.<br /><br />"
				a += "Edit your Tech Status: <form><select onchange='Set_Gender(this.options[this.selectedIndex].value)'><option value=''>Choose your Tech Status";
				a += "<option value='Neither'>Neither<option value='Buying'>Buying<option value='Selling'>Selling";
				a += "</select></form><br />";
				a += "<br />Edit your Nation ID: <input type='text' value='' id='age' maxlenght='6' size='36'> <input type='button' value='Edit Nation ID' onclick='Set_NID();'><br />";
				a += "<br />Edit your Nation Name: <input type='text' value='' id='nName' maxlength='16' size='18'> <input type='button' value='Edit Name' onclick='Set_Name();'><br />";
			}
			document.getElementById("check_profile").innerHTML=a
		}
	}
}
function Reset_Profile(){
	var frame = window.frames['Profile'].document.getElementsByTagName("input");
	for(a=0;a<frame.length;a++){
		if(frame[a].value == "Update my Signature"){
			frame[a].click();
			document.getElementById("check_profile").innerHTML="<div align='center'><br /><b>Reseting Profile, please wait...<br /><br /><img src='http://209.85.48.12/11661/52/upload/p2153323.gif'><br /><br /><br /></div>";
			setTimeout("Reload()",3000);
		}
	}
}
function Reload(){
	window.location=location.href.split('?')[0]+"?act=UserCP&CODE=AddProfile";
}
function Set_NID(){
	var get_age = document.getElementById("age").value;
	if(!get_age.match(/^\d+$/i)){
		alert("Input a number.");
	}
	if(get_age.match(/^\d+$/i)){
		var Profile = window.frames['Profile'].document.getElementsByTagName("div");
		for(z=0;z<Profile.length;z++){
			if(Profile[z].className=="signature"){
				if(Profile[z].innerHTML.match(/\[TCZ\](.*),(.*),(.*),(.*)\[\/TCZ\]/i)!=null){
					window.frames['Profile'].document.forms['REPLIER'].Post.value+="[TCZ]"+RegExp.$1+","+get_age+","+RegExp.$3+",[/TCZ]";
				}
				else{
					if(RegExp.$1 == "" && RegExp.$2 != "" || (RegExp.$3 == "" && RegExp.$2 != "") || (RegExp.$4 == "" && RegExp.$2 != "")!=null){
						window.frames['Profile'].document.forms['REPLIER'].Post.value+="[TCZ]"+RegExp.$1+","+get_age+","+RegExp.$3+",[/TCZ]";
					}
				}
			}
		}
		var frame = window.frames['Profile'].document.getElementsByTagName("input");
		for(a=0;a<frame.length;a++){
			if(frame[a].value == "Update my Signature"){
				frame[a].click();
				document.getElementById("check_profile").innerHTML="<div align='center'><br /><b>Editing your Nation Information, please wait...<br /><br /><img src='http://209.85.48.12/11661/52/upload/p2153323.gif'><br /><br /><br /></div>";
			}
		}
	}
}
function Reset_NID(){
	window.frames['Profile'].document.forms['REPLIER'].Post.value+="[TCZ]"+RegExp.$1+",,"+RegExp.$3+",[/TCZ]";
	var frame = window.frames['Profile'].document.getElementsByTagName("input");
	for(a=0;a<frame.length;a++){
		if(frame[a].value == "Update my Signature"){
			frame[a].click();
			document.getElementById("check_profile").innerHTML="<div align='center'><br /><b>Reseting Age, please wait...<br /><br /><img src='http://209.85.48.12/11661/52/upload/p2153323.gif'><br /><br /><br /></div>";
			setTimeout("Reload()",3000);
		}
	}
}
function Set_Gender(type){
	window.frames['Profile'].document.forms['REPLIER'].Post.value+="[TCZ]"+type+","+RegExp.$2+","+RegExp.$3+",[/TCZ]";
	var frame = window.frames['Profile'].document.getElementsByTagName("input");
	for(a=0;a<frame.length;a++){
		if(frame[a].value == "Update my Signature"){
			frame[a].click();
			document.getElementById("check_profile").innerHTML="<div align='center'><br /><b>Editing your Nation Information, please wait...<br /><br /><img src='http://209.85.48.12/11661/52/upload/p2153323.gif'><br /><br /><br /></div>";
		}
	}
}
function Reset_Gender(){
	window.frames['Profile'].document.forms['REPLIER'].Post.value+="[TCZ],"+RegExp.$2+","+RegExp.$3+",[/TCZ]";
	var frame = window.frames['Profile'].document.getElementsByTagName("input");
	for(a=0;a<frame.length;a++){
		if(frame[a].value == "Update my Signature"){
			frame[a].click();
			document.getElementById("check_profile").innerHTML="<div align='center'><br /><b>Reseting Tech Status, please wait...<br /><br /><img src='http://209.85.48.12/11661/52/upload/p2153323.gif'><br /><br /><br /></div>";
			setTimeout("Reload()",3000);
		}
	}
}
function Set_Name(){
	var get_Nationn = document.getElementById("nName").value;
	var Profile = window.frames['Profile'].document.getElementsByTagName("div");
	for(m=0;m<Profile.length;m++){
		if(Profile[m].className=="signature"){
			if(Profile[m].innerHTML.match(/\[TCZ\](.*),(.*),(.*),(.*)\[\/TCZ\]/i)!=null){
				window.frames['Profile'].document.forms['REPLIER'].Post.value+="[TCZ]"+RegExp.$1+","+RegExp.$2+","+get_Nationn+",[/TCZ]";
			}
			else{
				if(RegExp.$1 == "" && RegExp.$2 != "" || (RegExp.$3 == "" && RegExp.$2 != "") || (RegExp.$4 == "" && RegExp.$2 != "")!=null){
					window.frames['Profile'].document.forms['REPLIER'].Post.value+="[TCZ]"+RegExp.$1+","+RegExp.$2+","+get_Nationn+",[/TCZ]";
				}
			}
		}
	}
	var frame = window.frames['Profile'].document.getElementsByTagName("input");
	for(a=0;a<frame.length;a++){
		if(frame[a].value == "Update my Signature"){
			frame[a].click();
			document.getElementById("check_profile").innerHTML="<div align='center'><br /><b>Editing your Nation Information, please wait...<br /><br /><img src='http://209.85.48.12/11661/52/upload/p2153323.gif'><br /><br /><br /></div>";
		}
	}
}
function Reset_Name(){
	window.frames['Profile'].document.forms['REPLIER'].Post.value+="[TCZ]"+RegExp.$1+","+RegExp.$2+",,[/TCZ]";
	var frame = window.frames['Profile'].document.getElementsByTagName("input");
	for(a=0;a<frame.length;a++){
		if(frame[a].value == "Update my Signature"){
			frame[a].click();
			document.getElementById("check_profile").innerHTML="<div align='center'><br /><b>Reseting Nation Name, please wait...<br /><br /><img src='http://209.85.48.12/11661/52/upload/p2153323.gif'><br /><br /><br /></div>";
			setTimeout("Reload()",3000);
		}
	}
}
if(location.href==top.location.href && location.href.match(/act=UserCP/i) && location.href.match(/CODE=22/i)){
	backup=""
	if(document.forms.REPLIER.Post.value.match(/\[TCZ\](.*),(.*),(.*),(.*)\[\/TCZ\]/i)){
		backup="[TCZ]"+RegExp.$1+","+RegExp.$2+","+RegExp.$3+","+RegExp.$4+"[/TCZ]"
		document.forms.REPLIER.Post.value=document.forms.REPLIER.Post.value.split("[TCZ]"+RegExp.$1+","+RegExp.$2+","+RegExp.$3+",[/TCZ]").join("")
	}
		document.forms.REPLIER.onsubmit=function(){
			if(document.forms.REPLIER.Post.value.match(/\[TCZ\](.*),(.*),(.*),(.*)\[\/TCZ\]/i)){
				document.forms.REPLIER.Post.value=document.forms.REPLIER.Post.value.split("[TCZ]"+RegExp.$1+","+RegExp.$2+","+RegExp.$3+",[/TCZ]").join("")
			}
			document.forms.REPLIER.Post.value=backup+document.forms.REPLIER.Post.value
		}
	a=document.getElementsByTagName("div")
	for(i=0;i<a.length;i++){
		if(a[i].innerHTML.match(/\[TCZ\](.*),(.*),(.*),(.*)\[\/TCZ\]/i) && a[i].className=='signature'){
			a[i].innerHTML=a[i].innerHTML.split("[TCZ]"+RegExp.$1+","+RegExp.$2+","+RegExp.$3+",[/TCZ]").join("")
		}
	}
}
if(location.href.match(/act=UserCP&CODE=22/i)){	
	text = document.getElementsByTagName("textarea");
	for(i=0;i<text.length;i++){
		if(text[i].className=="textinput"){
			if(text[i].innerHTML.match(/\[TCZ\](.*),(.*),(.*),(.*)\[\/TCZ\]/i)!=null){
				text[i].innerHTML=text[i].innerHTML.replace(/\[TCZ\](.*),(.*),(.*),(.*)\[\/TCZ\]/i,"");
			}
		}
	}
}
if(location.href.match(/showtopic=/i)){
	a=document.getElementsByTagName("span")
	for(i=0;i<a.length;i++){
		if(a[i].className=="postdetails" && a[i].innerHTML.match(/Joined:/i)){
			b=a[i].parentNode.parentNode.getElementsByTagName("td")[1]
			if(b.getElementsByTagName("div")[b.getElementsByTagName("div").length-1].className=="signature"){
				a[i].innerHTML += "<br /><br /><br />....";
				if(b.getElementsByTagName("div")[b.getElementsByTagName("div").length-1].innerHTML.match(/\[TCZ\](.*),(.*),(.*),(.*)\[\/TCZ\]/i)!=null){
					if(RegExp.$2 != "" && RegExp.$3 != ""){
						a[i].innerHTML += "<br /><br /><b>Nation: </b><i><a href='http://www.cybernations.net/nation_drill_display.asp?Nation_ID="+RegExp.$2+"'>"+RegExp.$3+"</a></i>";
					}
					if(RegExp.$1 != ""){
						a[i].innerHTML += "<br /><b>Tech Status: </b><i>"+RegExp.$1+"</i><br />";
					}
				}
			}
			if(b.getElementsByTagName("div")[b.getElementsByTagName("div").length-1].innerHTML.split(" ").join("")==""){
				b.getElementsByTagName("div")[b.getElementsByTagName("div").length-1].parentNode.innerHTML=b.getElementsByTagName("div")[b.getElementsByTagName("div").length-1].parentNode.innerHTML.split("--------------------").join("")
			}
		}
	}
	var topic = document.getElementsByTagName("div");
	for(hide=0;hide<topic.length;hide++){
		if(topic[hide].className=="signature"){
			if(topic[hide].innerHTML.match(/\[TCZ\](.*),(.*),(.*),(.*)\[\/TCZ\]/i)!=null){
				topic[hide].innerHTML=topic[hide].innerHTML.replace(/\[TCZ\](.*),(.*),(.*),(.*)\[\/TCZ\]/i,"");
			}
		}
	}
}
if(location.href.match(/showuser=/i)){
	var name = document.getElementById("profilename").innerHTML;
	user = document.getElementsByTagName("td");
	for(hide=0;hide<user.length;hide++){
		if(user[hide].className=="maintitle" && user[hide].innerHTML=="Posting Details"){
			if(user[hide].parentNode.parentNode.parentNode.rows[4].cells[1].innerHTML.match(/\[TCZ\](.*),(.*),(.*),(.*)\[\/TCZ\]/i)){
				a=document.getElementsByTagName("TABLE");
				for (i=0;i<a.length;i++){
					if(a[i].align == "center" && a[i].cellPadding == 0 && a[i].cellSpacing == 2 && a[i].width == "100%"){
						b = '<table cellspacing="1" cellpadding="6" width="100%">'
						b += '<tr><td align="center" colspan="2" class="maintitle">'+name+'\'s Nation Information</td></tr>';
						if(RegExp.$2 != "" && RegExp.$3 != ""){
							b += "<tr><td class='row3' width='30%' valign='top'><b>Nation</b></td><td align='left' width='70%' class='row1'><a href='http://www.cybernations.net/nation_drill_display.asp?Nation_ID="+RegExp.$2+"'><i>"+RegExp.$3+'</i></a></td></tr>';
						}
						if(RegExp.$1 != ""){
							b += '<tr><td class="row3" width="30%" valign="top"><b>Tech Status</b></td><td align="left" width="70%" class="row1"><i>'+RegExp.$1+'</i></td></tr>';
						}
						b += '</table>';
							a[i].insertRow(-1);
							a[i].rows[2].insertCell(-1);
							a[i].rows[2].cells[0].innerHTML = b;
							a[i].rows[2].cells[0].vAlign= "top";
							a[i].rows[2].cells[0].className= "plainborder";
					}
				}
				user[hide].parentNode.parentNode.parentNode.rows[4].cells[1].innerHTML=user[hide].parentNode.parentNode.parentNode.rows[4].cells[1].innerHTML.replace(/\[TCZ\](.*),(.*),(.*),(.*)\[\/TCZ\]/i,"");
			}
			else if(!user[hide].parentNode.parentNode.parentNode.rows[4].cells[1].innerHTML.match(/\[TCZ\](.*),(.*),(.*),(.*)\[\/TCZ\]/i)){
				a=document.getElementsByTagName("TABLE");
				for (i=0;i<a.length;i++){
					if(a[i].align == "center" && a[i].cellPadding == 0 && a[i].cellSpacing == 2 && a[i].width == "100%"){
						b = '<table cellspacing="1" cellpadding="6" width="100%">'
						b += '<tr><td align="center" colspan="2" class="maintitle">'+name+'\'s Nation Information</td></tr><tr><td align="center" width="100%" class="row1"><i>None</i></td></tr></table>'
							a[i].insertRow(-1);
							a[i].rows[2].insertCell(-1);
							a[i].rows[2].cells[0].innerHTML = b;
							a[i].rows[2].cells[0].vAlign= "top";
							a[i].rows[2].cells[0].className= "plainborder";
					}
				}
			}
		}
	}
}