/*
Project: Cross-Fury Version 1.0 © Shin, 2005
This code may be used provided that you do not edit or repost this code without my prior permission, and that you do NOT remove this header. This script's coding is my official property, so please do not attempt to claim any of it as your own. This header must always remain intact.
*/

if(location.href.match(/action=modifyprofile/)&&document.modifyForm){

function SaveAllAddOns(){
for(d=0;d<AddOns.length;d++){
if(AddOns[d]!=null&&AddOns[d].enabled=="true"){
AddOns[d].saveValue();
}}}

for(c=0;c<AddOns.length;c++){
if(AddOns[c]!=null&&AddOns[c].enabled=="true"){
AddOns[c].create();
AddOns[c].loadValue();
}}
var checkRemoveString;
var checkRemoveReg;
var removeString;
for(c=0;c<AddOns.length;c++){
if(AddOns[c]!=null){
checkRemoveString=AddOns[c].ID+"=(.+?)&";
checkRemoveReg=new RegExp(checkRemoveString);
if(document.modifyForm.websiteurl.value.match(checkRemoveReg)){
removeString="?"+AddOns[c].ID+"="+RegExp.$1+"&?";
document.modifyForm.websiteurl.value=document.modifyForm.websiteurl.value.replace(removeString,"");
}}}
if(document.modifyForm.websiteurl.value.match(/\?\w+=(.+?)&\?/g)){
document.modifyForm.websiteurl.value=document.modifyForm.websiteurl.value.replace(/\?\w+=(.+?)&\?/g,"");
}

document.modifyForm.onsubmit=SaveAllAddOns;

} else if(location.href.match(/action=headersfooters2&project=(\w+)&/)){

var projectType=new String(RegExp.$1);

function SetElemDetail(){
if(document.createAddOn&&document.createAddOn.elemType&&document.getElementById("elemDetail")){
var Value=document.createAddOn.elemType.options[document.createAddOn.elemType.selectedIndex].value;
if(Value=="input"){
var addInner="<b>Default Value</b> (optional):<br/><font size='1'>This is the default value for this new element.</font><br/><input type='text' name='defaultInput'>";
} else if(Value=="select"){
var addInner="<b>Selections:</b><br/><font size='1'>Place all the selections you wish to add to the select box below.<br/>Separate each selection with an ampersand (&)<br/>Example: choice1&choice2&choice3</font><br/><input type='text' name='selectionInput'>";
}
document.getElementById("elemDetail").innerHTML=addInner;
}}

function returnToAdmin(){
location.href="index.cgi?action=admin";
}

function NextEdit(){
if(document.getElementById("beforeSelect")){
document.getElementById("beforeSelect").style.display="none";
document.getElementById("beforeValid").style.display="";
aoIndex=parseInt(document.createAddOn.selectOption.options[document.createAddOn.selectOption.selectedIndex].value);
document.createAddOn.IDInput.value=AddOns[aoIndex].ID;
document.createAddOn.dispTitle.value=AddOns[aoIndex].displayTitle;
document.createAddOn.descriptionInput.value=AddOns[aoIndex].desc;
for(c=0;c<document.createAddOn.elemType.options.length;c++){
if(document.createAddOn.elemType.options[c].value==AddOns[aoIndex].elementType){
document.createAddOn.elemType.options[c].selected="1";
break;
}}
SetElemDetail();
if(document.createAddOn.defaultInput){
document.createAddOn.defaultInput.value=AddOns[aoIndex].defaultValue;
} else if(document.createAddOn.selectionInput){
for(c=0;c<AddOns[aoIndex].options.length;c++){
document.createAddOn.selectionInput.value+=AddOns[aoIndex].options[c];
if(c!=(AddOns[aoIndex].options.length-1)){
document.createAddOn.selectionInput.value+="&";
}}}
for(c=0;c<document.createAddOn.editByBox.options.length;c++){
if(document.createAddOn.editByBox.options[c].value==AddOns[aoIndex].editBy){
document.createAddOn.editByBox.options[c].selected="1";
break;
}}
for(c=0;c<document.createAddOn.enableBox.options.length;c++){
if(document.createAddOn.enableBox.options[c].value==AddOns[aoIndex].enabled){
document.createAddOn.enableBox.options[c].selected="1";
break;
}}
}}

function NextDelete(){
if(document.getElementById("beforeDelete")){
aoIndex=parseInt(document.createAddOn.selectOption.options[document.createAddOn.selectOption.selectedIndex].value);
document.getElementById("beforeDelete").style.display="none";
document.getElementById("confirmInner").innerHTML="Are you sure you wish to delete the option entitled: \""+AddOns[aoIndex].displayTitle+"\"?";
document.getElementById("deleteConfirm").style.display="";
}}

for(fn=0;fn<document.forms.length;fn++){
if(document.forms[fn].elements[0].type&&document.forms[fn].elements[0].type=="hidden"&&document.forms[fn].elements[0].name=="id"&&document.forms[fn].elements[1].name=="header"){

var Table=document.getElementsByTagName("table");
for(a=0;a<Table.length;a++){
if(Table[a].width=="100%"&&Table[a].getElementsByTagName("form").length>0&&Table[a].getElementsByTagName("form")[0].elements[0].type&&Table[a].getElementsByTagName("form")[0].elements[0].type=="hidden"&&Table[a].getElementsByTagName("form")[0].elements[0].name=="id"&&Table[a].getElementsByTagName("form")[0].elements[1].name=="header"){
Table[a].style.display="none";
Table[a+2].style.display="none";
break;
}}

var AddOnForm="";
var AddOnTitle="";
if(projectType=="create"||projectType=="edit"){

if(projectType=="edit"){
AddOnTitle+="Edit Option";
AddOnForm+="<form name='createAddOn'><font size='2'>This is the admin panel for editing any added profile option.<br/><br/><div id='beforeSelect'>Select the option you wish to edit.<br/><select name='selectOption'>";
for(c=0;c<AddOns.length;c++){
if(AddOns[c]!=null){
AddOnForm+="<option value='"+c+"'>"+AddOns[c].displayTitle+"</option>";
}}
AddOnForm+="</select><br/><br/><input type='button' name='setUpEdit' value='Continue'></div><div id='beforeValid' style='display:none'>";
} else {
AddOnTitle+="Create Option";
AddOnForm+="<form name='createAddOn'><div id='beforeValid'><font size='2'>This is your admin panel for creating new profile options.<br/>Data must be validated by clicking the \"Validate Data\" button before continuing.<br/>All quotation marks are automatically removed from the text fields to prevent errors.<br/><br/>";
}

AddOnForm+="<b>Option ID:</b><br/><font size='1'>This is the name that will be used to identify this profile element.<br/>A simple one word ID is recommended.<br/><b>Only numbers and letters may be used!</b></font><br/><input type='text' name='IDInput'></font><br/><br/>";

AddOnForm+="<b>Displayed Title:</b><br/><font size='1'>This is the title that is displayed for this element.<br/>Something like \"Favorite Game\" would suffice.</font><br/><input type='text' name='dispTitle'><br/><br/>";

AddOnForm+="<b>Option Type:</b><br/><font size='1'>This is the type of element you are creating.<br/>It may be a text field or a select box.<br/>The box below is an example of a select box.</font><br/><select name='elemType'><option value='input'>Text field</option><option value='select'>Select box</option></select><br/><br/>";

AddOnForm+="<div id='elemDetail'><b>Default Value</b> (optional):<br/><font size='1'>This is the default value for this new element.</font><br/><input type='text' name='defaultInput'></div><br/><br/>";

AddOnForm+="<b>Description:</b><br/><font size='1'>This is the description of this new profile option.</font><br/><input type='text' name='descriptionInput'><br/><br/>";

AddOnForm+="<b>Who can edit this option?</b><br/><font size='1'>Choose \"All members\" to allow members to edit this option themselves, in their own profile.<br/>Choose \"Admins only\" to only allow members with administrative powers to edit this option in member profiles.</font><br/><select name='editByBox'><option value='all'>All members</option><option value='admin'>Admins only</option></select><br/><br/>";

AddOnForm+="<b>Enable this option?</b><br/><font size='1'>Selecting \"yes\" will create this element and enable it on the profile.<br/>Selecting \"no\" will still create this element, but leave it inactive until you enable it.</font><br/><select name='enableBox'><option value='true'>Yes</option><option value='false'>No</option></select>";


AddOnForm+="<br/><br/><input type='button' name='validator' value=' Validate Data '></div><div id='afterValid' style='display:none'>Data validation complete. You may choose to "+projectType+" this option, or to cancel.<br/><br/><div id='afterValidInner'></div><input type='button' name='finishButton' value='Create this new option'> <input type='button' name='cancelButton' value=' Cancel '></div></form>";

} else if(projectType=="delete1"){
AddOnTitle+="Delete Option";
AddOnForm+="<form name='createAddOn'><font size='2'>This is the admin panel for deleting any added profile option.<br/><br/><div id='beforeDelete'>Select the option you wish to delete.<br/><select name='selectOption'>";
for(c=0;c<AddOns.length;c++){
if(AddOns[c]!=null){
AddOnForm+="<option value='"+c+"'>"+AddOns[c].displayTitle+"</option>";
}}
AddOnForm+="</select><br/><br/><input type='button' name='continueDelete' value='Continue'></div><div id='deleteConfirm' style='display:none'><div id='confirmInner'></div><br/></br> <input type='button' name='finishButton' value='Create this new option'> <input type='button' name='cancelButton' value=' Cancel '></div></form>";

} else if(projectType=="deleteall"){
AddOnTitle+="Delete All Options";
AddOnForm+="<form name='createAddOn'><font size='2'>Are you sure you wish to delete <b>all</b> of the added profile options?<br/><br/><input type='button' name='finishButton' value='Delete them all'> <input type='button' name='cancelButton' value=' Cancel '></font></form>";
}

if(AddOns.length==0&&projectType.match(/(edit|delete)/)){
var newWord=RegExp.$1;
AddOnForm="<font size='2'>There are no profile add-ons to "+newWord+".<br/><br/>Please create an add-on first by <a href='index.cgi?action=headersfooters2&project=create&id=*'>clicking here</a>, or return to your <a href='index.cgi?action=admin'>admin panel</a>.</font>";
}

document.write("<table border='0' width='92%' cellspacing='0' cellpadding='0' align='center' class='bordercolor'><tr><td><table cellpadding='4' cellspacing='1' border='0' width='100%'><tr><td width='100%' class='titlebg'><font size='2'><b>Project: CrossFury - "+AddOnTitle+"</b></font></td></tr><tr><td width='100%' class='windowbg'><font size='2'>"+AddOnForm+"</font></td></tr></table></td></tr></table>");

if((projectType=="create"||projectType=="edit")&&document.createAddOn){
document.createAddOn.IDInput.onblur=checkForSymbols;
document.createAddOn.elemType.onchange=SetElemDetail;
document.createAddOn.validator.onclick=ValidateData;
if(projectType=="create"){
document.createAddOn.finishButton.onclick=SaveCreatedAddOn;
} else {
var aoIndex;
document.createAddOn.setUpEdit.onclick=NextEdit;
document.createAddOn.finishButton.value="Edit this Option";
document.createAddOn.finishButton.onclick=EditAddOn;
}
document.createAddOn.cancelButton.onclick=returnToAdmin;
} else if(projectType=="delete1"&&document.createAddOn){
var aoIndex;
document.createAddOn.continueDelete.onclick=NextDelete;
document.createAddOn.finishButton.value="Delete this Option";
document.createAddOn.finishButton.onclick=DeleteAddOn;
document.createAddOn.cancelButton.onclick=returnToAdmin;
} else if(projectType=="deleteall"&&document.createAddOn){
document.createAddOn.finishButton.onclick=DeleteAllAddOns;
document.createAddOn.cancelButton.onclick=returnToAdmin;
}
break;
}}
} else if(location.href.match(/action=members/)){
for(c=0;c<AddOns.length;c++){
if(AddOns[c]!=null&&AddOns[c].enabled=="true"){
var startWith=c;
break;
} else if(c==(AddOns.length-1)){
var startWith="none";
}}
var Anchors=document.getElementsByTagName("A");
if(startWith!="none"){
var IDReg=new RegExp(AddOns[startWith].ID);
for(d=0;d<Anchors.length;d++){
if(Anchors[d].href.match(IDReg)){
Anchors[d].href=Anchors[d].href.split(IDReg)[0];
}}}

} else if(location.href.match(/action=(displ|search2|viewpr|pmv|(user)?rece|cal\w+iew)/)){
var Anchors=document.getElementsByTagName("A");
for(c=0;c<AddOns.length;c++){
if(AddOns[c]!=null){
var searchString=AddOns[c].ID+"=(.+?)&";
var searchReg=new RegExp(searchString);
for(d=0;d<Anchors.length;d++){
if(Anchors[d].href.match(searchReg)){
var addOnValue=new String(RegExp.$1);
var addText1=unescape(AddOns[c].displayTitle+": "+addOnValue);
var addText2=document.createTextNode(addText1);
var newBreak=document.createElement("br");
Anchors[d].href=Anchors[d].href.replace(searchReg,"");
if(AddOns[c].enabled=="true"&&addOnValue!="NO_VALUE"&&Anchors[d].parentNode&&Anchors[d].parentNode.parentNode&&Anchors[d].parentNode.parentNode.width&&Anchors[d].parentNode.parentNode.width=="20%"&&Anchors[d].parentNode.parentNode.className&&Anchors[d].parentNode.parentNode.className.match(/windowbg/i)){
Anchors[d].parentNode.parentNode.appendChild(newBreak);
Anchors[d].parentNode.parentNode.appendChild(addText2);
}}}}}
for(e=0;e<Anchors.length;e++){
if(Anchors[e].href.match(/\?\w+=(.+?)&\?/)){
Anchors[e].href=Anchors[e].href.replace(/\?\w+=(.+?)&\?/g,"");
}
if(Anchors[e].href.match(/\?\?/)){
Anchors[e].href=Anchors[e].href.replace(/\?\?/g,"");
}}
} else if(location.href.match(/action=(admin|\w+3)/)){
var TD=document.getElementsByTagName("TD");
for(a=0;a<TD.length;a++){
if(TD[a].width=="34%"&&TD[a].getElementsByTagName("B").length>0&&TD[a].getElementsByTagName("B")[0].innerHTML.match(/customize your forum/i)&&TD[a].innerHTML.match(/headers and footers/i)&&TD[a].getElementsByTagName("div").length>0){
TD[a].getElementsByTagName("div")[0].innerHTML+="<br/><br/><b>CrossFury - Admin Panel</b><br/><i>The Ultimate Profile Hack</i><br/>--<a href='index.cgi?action=headersfooters2&project=create&id=*'>Create New Profile Option</a></br>--<a href='index.cgi?action=headersfooters2&project=edit&id=*'>Edit An Added Option</a><br/>--<a href='index.cgi?action=headersfooters2&project=delete1&id=*'>Delete An Added Option</a><br/>--<a href='index.cgi?action=headersfooters2&project=deleteall&id=*'>Delete All Added Options</a>";
break;
}}

}
