var innerW;
var innerH;
var d = document;
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
var xmlHttp="";
var chat;
var fields=new Array();
function EU(id){return escape(id);}

 function Music(id)
	{
	 window.open("/Music/"+id+".html",id,"width=431,height=301,noresize");
	}
function PreviewPicture(){var pic=document.getElementById("Picture");window.open(pic.value,"demopic");}
function SubmitProfile()
{
 fields=CF("Character,System");
	if(fields[1]!=""){alert(fields[1]);}
	else
	{
	 param="ACT=NewProfile";
		param+="&Character="+EU(fields[0][0]);
		param+="&System="+EU(fields[0][1]);
		param+="&Picture="+document.getElementById("Picture").value;
		param+="&AIM="+document.getElementById("AIM").value;
		param+="&MSN="+document.getElementById("MSN").value;
		param+="&ICQ="+document.getElementById("ICQ").value;
		param+="&Yahoo="+document.getElementById("Yahoo").value;
		param+="&Description="+EU(document.getElementById("Descript").value);
		param+="&Private="+document.getElementById("Private").value;
  Info("Whos",param,"SubmitProfile1");
	}
}
function SubmitProfile1()
{
 if(info!=""){alert(info);}
	else{alert("Profile Created Successfully.");Page('Whos','M','ACT=');}
}
function DeleteProfile()
{
	var del=confirm("Are you sure you want to delete the profile: "+document.getElementById("Character").value);
	if(del==true)
	{
	 param="ACT=DeleteWhosProfile";
		param+="&ID="+document.getElementById("id").value;
		Info("Whos",param,"DeleteProfile1");
	}
}
function DeleteProfile1()
{
 if(info!=""){alert(info);}
	else{alert("Profile Deleted Successfully.");Page('Whos','M','ACT=');}
}

function EditProfile()
{
 fields=CF("Character,System");
	if(fields[1]!=""){alert(fields[1]);}
	else
	{
	 param="ACT=EditWhoProfile";
		param+="&ID="+document.getElementById("id").value;
		param+="&Character="+EU(fields[0][0]);
		param+="&System="+EU(fields[0][1]);
		param+="&Picture="+document.getElementById("Picture").value;
		param+="&AIM="+document.getElementById("AIM").value;
		param+="&MSN="+document.getElementById("MSN").value;
		param+="&ICQ="+document.getElementById("ICQ").value;
		param+="&Yahoo="+document.getElementById("Yahoo").value;
		param+="&Description="+EU(document.getElementById("Descript").value);
		param+="&Private="+EU(document.getElementById("Private").value);
		Info("Whos",param,"EditProfile1");
	}
}
function EditProfile1()
{
 if(info!=""){alert(info);}
	else{alert("Profile Edited Successfully.");Page('Whos','M','ACT=');}
}
function ChooseWhosSystem()
{
 if(document.getElementById("System").value!="")
	{
  param="ACT=ViewWhosSystem";
	 param+="&System="+document.getElementById("System").value;
	 Page('Whos','M',param);
	}
}
function DeleteWhos(id)
{
 var con=confirm("Are you sure you want to delete this profile?")
 if(con==true)
 {
 param="ACT=DeleteWhos&ID="+id;
 Info("Whos",param,"DeletedWho");
 }
}
function DeletedWho()
{
 if(info!=""){alert(info);}
 else
 {
  Page('Whos','M','ACT=');
 }
}


function ChooseCharacterSystem()
{
 var system=document.getElementById("System").value;
	if(system!="")
	{
	 Page("Characters","Char","ACT=System&System="+system);
	}

	
}

function PageLoad()
{
 PageSize();
 var LastPage=get_cookie("LastPage");
	var LastParam=get_cookie("LastParam");
	var LastTable=get_cookie("LastTable");
	if(LastPage!="" && LastTable!="Char"){Page(LastPage,LastTable,LastParam);}
	else if(LastPage=="" || LastPage=="Home"){Page("News","M","ACT=");}
	else if(LastTable=="Char"){Page("Characters","M","ACT=");}
	setTimeout("CookieLogin()",10);
}





function CF(input)
{
 var msg;
 var inputs=new Array(); 
 input=input.split(",");
	msg="";
	for(x=0;x<input.length;x++)
	{
	 inputs[x]=document.getElementById(input[x]).value;
		if(inputs[x]=="" || inputs[x].charAt(0)==" ")
		{
		 msg+=input[x]+" is a required field. It can not start with a space.\n";
		}
	}
	return [inputs,msg];
}


function ChangeLore(){var obj=document.getElementById("lore").value.split(";-;");var lvl=document.getElementById("lvl");lvl.length=1;for(x=1;x<=obj[0];x++){lvl.options[x]=new Option("Level "+x,x, true, false);}}
function ShowLore()
{
 var lore=document.getElementById("lore").value.split(";-;");
	var lvl=document.getElementById("lvl");

	if(lvl!="")
	{
	 Page("lores/"+lore[1]+"/Level "+lvl.value,"LoreDisplay","");
	}

}

function Login1(){if(info!=""){alert(info);}else{exdate=new Date();exdate.setDate(exdate.getDate()+99999);document.cookie = 'SiteUsername='+document.getElementById("Username").value+'; expires='+exdate+'; path=/';UpdateLoginSection();}window.location.reload( true );}
function UpdateLoginSection(){var Username=get_cookie("SiteUsername");var msg="You are logged in as "+Username+". If this is not you <a href='javascript:LogOff()' class='main4'>Logoff</a>.";document.getElementById("login").innerHTML=msg;}
function LogOff(){param="ACT=Logoff";Info("Login",param,"LogOff1");}
function LogOff1(){exdate=new Date();exdate.setDate(exdate.getDate()-100);document.cookie = 'SiteUsername=; expires='+exdate+'; path=/';alert("Successfully logged off.");var msg="Username:\n";msg+="<input class='main2' id='Username' value='' />\n";msg+="Password:\n";msg+="<input type='Password' class='main2' id='Password' value='' />\n";msg+="<a href='javascript:Login()' class='main4'>Login</a>\n";msg+="|\n";msg+="<a href='javascript:Page(\"Register\",\"M\",\"ACT=\");' class='main4'>Register</a>\n";document.getElementById("login").innerHTML=msg;window.location.reload( true );}
function CookieLogin(){if(document.getElementById("loading").value!="true"){var Username=get_cookie("SiteUsername");param="ACT=Cookie";param+="&Username="+EU(Username);Info("Login",param,"CookieLogin1");}else{setTimeout("CookieLogin()",10);}}
function CookieLogin1(){if(info==""){UpdateLoginSection();}}
function Login(){fields=CF("Username,Password");if(fields[1]!=""){alert(fields[1]);}else{param="ACT=Login";param+="&Username="+EU(fields[0][0]);param+="&Password="+EU(fields[0][1]);Info("Login",param,"Login1");}}
function RegisterAccount(){fields=CF("User,Pass,Confirm,Email");if(fields[1]!=""){alert("Marked Fields Are Required.");}else{if(fields[0][1]!=fields[0][2]){alert("Password and Confirm Password do not match.");}else{param="ACT=RegisterAccount";param+="&Username="+EU(fields[0][0]);param+="&Password="+EU(fields[0][1]);param+="&Email="+EU(fields[0][3]);Info("Register",param,"RegisterAccount1");}}}
function RegisterAccount1(){if(info!=""){alert(info);}else{alert("Account Created Successfully.");Page('News','M','ACT=');}}
function RulesPage(dir,page){var page=document.getElementById(page).value;if(dir!=""){Page(dir+"/"+page,"rules","ACT=");}}
function Go(page){window.open(page);}
function SitePages(page,param,table){if(table!="rules"){document.cookie="LastPage="+page;document.cookie="LastParam="+param;document.cookie="LastTable="+table;}}
function HoverIcon(id,status){var img,bg;var obj;obj=document.getElementById(id);if(status=="on"){img="./images/button2_hover.gif";bg="#8c9286";}else if(status=="off"){img="./images/button2.gif";bg="#6A7064";}obj.src=img;obj=document.getElementById(id+"_menu");obj.style.backgroundColor=bg;obj=document.getElementById(id+"_menu2");obj.style.backgroundColor=bg;}
function PageSize(){if (window.opera){innerW = window.innerWidth;innerH = window.innerHeight;}else{if (typeof window.innerWidth != "undefined"){innerW = window.innerWidth ;innerH = window.innerHeight ;}else if (d.documentElement && typeof d.documentElement.offsetWidth != "undefined" && d.documentElement.offsetWidth != 0){innerW = d.documentElement.offsetWidth ; innerH = d.documentElement.offsetHeight ; }	}}
function get_cookie(Name){var search = Name + "=";var returnvalue = "";if (document.cookie.length > 0){offset = document.cookie.indexOf(search);if (offset != -1){offset += search.length;end = document.cookie.indexOf(";", offset);if (end == -1) end = document.cookie.length;returnvalue=unescape(document.cookie.substring(offset, end))}};return returnvalue;}



function ExpandSheet(id)
{
 var display="";
 obj=document.getElementById("info"+id);
	if(obj.style.display!="none"){display="none";}
	obj.style.display=display;
}

function dots(id,start,total,type)
{
 if(type==1 && start==1)
	{
	 if(document.getElementById(id+"_1").src.indexOf("dot.gif")!=-1 && document.getElementById(id+"_2").src.indexOf("dot.gif")==-1){start=0;}
	}
 for(x=1;x<=start;x++){document.getElementById(id+"_"+x).src="./images/dot.gif";}
	for(y=x;y<=total;y++){document.getElementById(id+"_"+y).src="./images/blank.gif";}
	document.getElementById("value_"+id).value=start;
}



function SheetFields()
{

 fields=CF("Name");
	if(fields[1]!=""){alert(fields[1]);}
	else
	{
  var system=document.getElementById("System").value;
	 param="ACT=&System="+system;
	 Info("values",param,"PullSheetValues");
	}
}

function SheetFields2()
{
 fields=CF("Name");

	if(fields[1]!=""){alert(fields[1]);}
	else
	{
  system=document.getElementById("System").value;
	 param="ACT=&System="+system;
	 Info("values",param,"PullSheetValues2");
	}
}

function PullSheetValues()
{
 info=info.split(",");
	var val="";
	for(a=0;a<info.length-1;a++)
	{
	 i=info[a].split(":");
		if(i.length<2){val+=i[0]+"="+EU(document.getElementById(i[0]).value)+",,";}
		else
		{
		 if(i[1]==1){val+=i[0]+"="+EU(document.getElementById("value_"+i[0]).value)+":"+EU(document.getElementById(i[0]+"_special").value)+",,";}
			else if(i[1]>=2 && i[1]<=4){val+=i[0]+"="+EU(document.getElementById("value_"+i[0]).value)+":"+EU(document.getElementById(i[0]).value)+",,";}
			else if(i[1]==5){val+=i[0]+"="+EU(document.getElementById("value_"+i[0]).value)+",,";}
		}
	}
	val+="Notes="+EU(document.getElementById("Notes").value)+",,";	
	val+="Background="+EU(document.getElementById("Background").value)+",,";
	param="ACT=New Sheet&System="+document.getElementById("System").value+"&Values="+val;
	Info("Characters",param,"NewSheet");
}

function PullSheetValues2()
{

 info=info.split(",");
	var val="";
	for(a=0;a<info.length-1;a++)
	{
	 i=info[a].split(":");
		if(i.length<2){val+=i[0]+"="+EU(document.getElementById(i[0]).value)+",,";}
		else
		{
		 if(i[1]==1){val+=i[0]+"="+EU(document.getElementById("value_"+i[0]).value)+":"+EU(document.getElementById(i[0]+"_special").value)+",,";}
			else if(i[1]>=2 && i[1]<=4){val+=i[0]+"="+EU(document.getElementById("value_"+i[0]).value)+":"+EU(document.getElementById(i[0]).value)+",,";}
			else if(i[1]==5){val+=i[0]+"="+EU(document.getElementById("value_"+i[0]).value)+",,";}
		}
	}
	val+="Notes="+EU(document.getElementById("Notes").value)+",,";	
	val+="Background="+EU(document.getElementById("Background").value)+",,";
	param="ACT=Update Sheet&CID="+document.getElementById("CID").value+"&System="+document.getElementById("System").value+"&Values="+val;	
	Info("Characters",param,"UpdateSheet");
}

function UpdateSheet()
{
 if(info!=""){alert(info);}
	else{alert("Character Updated.");Page("Characters","M","ACT=");}
}

function NewSheet()
{
 if(info!=""){alert(info);}
	else{alert("Character Submitted.");Page('Characters','M','ACT=');}
}

function NewXPSubmission()
{
 fields=CF("Character");
	if(fields[1]!=""){alert(fields[1]);}
	else
	{
	 param="ACT=NewXPSubmission";
		param+="&Name="+EU(fields[0][0]);
		param+="&Cost="+document.getElementById("Cost").value;
		param+="&Request="+EU(document.getElementById("Request").value);
		Info("XP",param,"NewXPSubmission2");
	}
}
function NewXPSubmission2()
{
	if(escape(info)=="%0A%20%0A%09"){alert("XP Request Submitted.");Page('Characters','M','ACT=');}
	else if(info!=""){alert(info);}
}
function ChatLogoff()
{
 param="ACT=ChatLogoff&SID="+document.getElementById("SID").value;
	Info("chatpages",param,"ChatLogoff1");
}
function ChatLogoff1()
{
 //alert(info);
 window.location.reload();
}
function CharacterProfile(id)
{
	//obj=document.getElementById("pageWindow");
	//obj.style.width=600;
	//obj.style.height=innerH-250;
	//obj.style.left=5;
//	obj.style.top=5;
 PageExtras("Whos","pageWindow","ACT=ViewWhosProfile2&ID="+id,"Character Profile","600","300","ProfileWin")	
}


function EditXPRequest(id,sr)
{
 param="ACT=SelectXPEdit&ID="+id;
	PageExtras("Characters","AS",param,"XP Requests","600","300","XPWin");		
}	


	function CancelRequest()
{
 param="ACT=CancelXPRequest&ID="+document.getElementById("ID").value;
	param+="&CID="+document.getElementById("CID").value;
	Info("Characters",param,"CancelRequest2");
}
function CancelRequest2()
{
 if(info!=""){alert(info);}
	else{alert("XP Request was Cancelled by You.");}
	XPWin.close();
}

	function SaveRequest()
{
 param="ACT=SaveXPRequest&ID="+document.getElementById("ID").value;
		param+="&Cost="+document.getElementById("cost").value;
		param+="&Request="+EU(document.getElementById("request").value);
 	Info("Characters",param,"SaveRequest2");
}

function SaveRequest2()
{
	if(info!=""){alert(info);}
	else{alert("XP Request was Updated by You.");}
	XPWin.close();
}
