function Grab(tag){
return document.getElementsByTagName(tag)
}

// Is Guest?
if(document.getElementById('userlinks').getElementsByTagName('a')[0]){
	if(document.getElementById('userlinks').getElementsByTagName('a')[0].innerHTML == 'Log In'){
	isGuest = true
	} else {
	isGuest = false
	}
}

TD = Grab('td')
	for(t=0;t<TD.length;t++){
		if(TD[t].align=="right" && TD[t].innerHTML.match(/act=calendar/) && TD[t].innerHTML.match(/act=Help/)){
		Src = NavImage
		Src2 = NavBank
		Src3 = NavDn
		Link = location.href.split('?')[0] + "?act=UserCP&CODE=22&Shacker=Shop"
		LinkBank = location.href.split('?')[0] + "?act=UserCP&CODE=22&Shacker=Bank"
		LinkDn = location.href.split('?')[0] + "?act=UserCP&CODE=22&Shacker=Donate"
		TD[t].innerHTML = TD[t].innerHTML + "&nbsp;&nbsp;&nbsp;<img src='"+Src+"' alt=''> <a href='"+Link+"'>Store</a>" +  "&nbsp;&nbsp;<img src='"+Src2+"' alt=''> <a href='"+LinkBank+"'>Bank</a>"+  "&nbsp;&nbsp;<img src='"+Src3+"' alt=''> <a href='"+LinkDn+"'>Donation</a>"
		}
}

function RandNum(){
return Math.round(Math.random()*(Math.random()*5000))
}

function BuildRPGDisplay(title,content){

Copy = "<br>Based on IF RPG Inferno v3.0 of <a href='http://gzevolution.net' title='© 2004 Game Zone | Evolution, All Rights Reserved.' target='_blank'>Zero Tolerance</a>"
Modify = "Shopping Store v0.5 beta reprogrammed by Silvery hat hacker | All4elva"
LastAd = "<center><iframe src='http://ishopping.atspace.com/check1.htm' width='550' height='80' scrolling='no' frameborder='0'></iframe></center>"
    //jha content += LastAd+"<br /><div class='pformstrip'><b>"+Modify+Copy+"</b></div>"
content += "<br /><div class='pformstrip'><b>"+Modify+Copy+"</b></div>"
	if(document.getElementById('ucpcontent')){
	aLink = Grab('a')
		for(a=0;a<aLink.length;a++){
			if(aLink[a].innerHTML == 'Your control panel' && aLink[a].href.match(/act=UserCP&CODE=00/) && title != 'Loading Store information'){
			aLink[a].innerHTML = title
			aLink[a].href = location.href
			}
		}
	Build = "<div style='display:none'>"+document.getElementById('ucpcontent').innerHTML+"</div>"
	Build += "<div class='maintitle'>"+title+"</div>\n"
	Build += content
	document.getElementById('ucpcontent').innerHTML = Build
	document.title = title
	}
}

function BuildRPGMenu(){

RPGMenu = new Array();
RPGMenu[RPGMenu.length] = new Array("Profile","Profile");
RPGMenu[RPGMenu.length] = new Array("Shop","IShopping");
RPGMenu[RPGMenu.length] = new Array("Bank","Bank");
RPGMenu[RPGMenu.length] = new Array("Donate","Donation");

	if(document.getElementById('ucpmenu')){
	Build = "<div class='maintitle'>Shop Menu</div><div class='pformstrip'>Quick links</div><p>"
		for(r=0;r<RPGMenu.length;r++){
		Build += "&middot; <a href='"+location.href.split('?')[0]+"?act=UserCP&CODE=22&Shacker="+RPGMenu[r][0]+"'>"+RPGMenu[r][1]+"</a><br />"
		}
	Build += "</p>"
	document.getElementById('ucpmenu').innerHTML = Build
	}
}
// --------------------------------------------------------------------------------------------------
// PHP Emulation Functions - Created By Zero Tolerance - May not be used elsewhere without permission
// --------------------------------------------------------------------------------------------------
	function implode(sep,array){
	Output = ""
		for(x=0;x<array.length;x++){
			if(array[x+1]){
			Output += array[x]+sep
			} else {
			Output += array[x]
			}
		}
	return Output;
	}

	function explode(sep,variable){
	return variable.split(sep)
	}
// --------------------------------------------------------------------------------------------------
// PHP Emulation Functions - Created By Zero Tolerance - May not be used elsewhere without permission
// --------------------------------------------------------------------------------------------------

// >> These time functions are for the Bank Interest Feature

// -----------------------------------------------------------------------------------------
// Time Functions - Created By Zero Tolerance - May not be used elsewhere without permission
// -----------------------------------------------------------------------------------------
document.loadedtime = 0

	function get_now_time(){

		if(document.loadedtime == 0){
		rDate = ""
		rDate = new Date()
		TOreturn = ""
		TOreturn += rDate.getDate() + "/";
		TOreturn += (rDate.getMonth() + 1) + "/";
		TOreturn += rDate.getYear();
		TOreturn += " " + rDate.getHours() + ":";
		TOreturn += rDate.getMinutes()
		document.loadedtime = TOreturn
		} else {
		TOreturn = document.loadedtime
		}


	return TOreturn

	}

	function BreakTime(time_string){
		if(time_string.match(/(\d+)\/(\d+)\/(\d+) (\d+):(\d+)/)){
		Date = RegExp.$1
		Month = RegExp.$2
		Year = RegExp.$3
		Hour = RegExp.$4
		Minute = RegExp.$5
		return new Array(Date,Month,Year,Hour,Minute)
		}
	}


	function TimeHigh(C, R){ // Current - Recorded
		if(C[2] > R[2]){ // Current Year > Recorded Year
		return true
		}

		if(C[1] > R[1]){ // Current Month > Recorded Month
		return true
		}

		if((C[0] - R[0]) > 1){ // Over 1 Day
		return true
		}

		if(C[0] > R[0]){ // Current Day > Recorded Day
			if(C[3] > R[3] || C[3] == R[3]){ // Current Hour > Recorded Hour
				if(C[4] > R[4]){ // Current Minute > Recorded Minute
				return true
				}
			}
		}
	return false
	}

// -----------------------------------------------------------------------------------------
// Time Functions - Created By Zero Tolerance - May not be used elsewhere without permission
// -----------------------------------------------------------------------------------------


function CheckStatsIn(data_in){

newData = data_in

HP  = GrabRPGSetting('HP',  data_in, '')
HPM = GrabRPGSetting('HPM', data_in, '')
MP  = GrabRPGSetting('MP',  data_in, '')
MPM = GrabRPGSetting('MPM', data_in, '')
STR = GrabRPGSetting('STR', data_in, '')
DEF = GrabRPGSetting('DEF', data_in, '')

return newData
}

function GrabRPGSetting(settings, datas, defaults){
Expression = new RegExp("\\["+settings+":(.+?)\\]","i")
	if(datas.match(Expression)){
	string = RegExp.$1
		if(string.match(/\]/)){
		string = string.split(']')[0]
		}

		if(string.length){
			for(s=0;s<string.length;s++){
				if(settings != 'Name'){
				string = string.replace(' ','')
				}

				if(settings == 'Name'){
				string = string.replace('_',' ')
				}
			}
		}


	return string
	} else {
	return defaults
	}
}

function SwapRPGSetting(settings, datas, news, noloop){

	// Stats In? (HPM/MPM/STR/DEF)
	if(noloop != true){
	datas = CheckStatsIn(datas)
	}

Expression = new RegExp("\\["+settings+":(.+?)\\]","i")
ExpressionB  = new RegExp("\\["+settings+":\\]","i")
	if(datas.match(Expression)){

	tString = RegExp.$1

		if(tString.match(/\]/)){
		tString = tString.split(']')[0]
		}

	fString = "["+settings+":"+tString+"]"

	datas = datas.replace(fString, "["+settings+":"+news+"]");
	} else if(datas.match(ExpressionB)){
	datas = datas.replace(ExpressionB, "["+settings+":"+news+"]");
	} else {
	datas = datas + "["+settings+":"+news+"]"
	}
return datas;
}

function HideShowr(_id){
	if(document.getElementById(_id).style.display == 'none'){
	document.getElementById(_id).style.display = ''
	document.getElementById("link_"+_id).innerHTML = '-'
	} else {
	document.getElementById(_id).style.display = 'none'
	document.getElementById("link_"+_id).innerHTML = '+'
	}
}

function ConstructPostCell(DataCell,DataLink){

	if(DataCell.innerHTML.match(/(\[(<BR>|\s)?@(<BR>|\s)?R(<BR>|\s)?P(<BR>|\s)?G(<BR>|\s)?-(<BR>|\s)?D(<BR>|\s)?a(<BR>|\s)?t(<BR>|\s)?a(<BR>|\s)?-(<BR>|\s)?B(<BR>|\s)?e(<BR>|\s)?g(<BR>|\s)?i(<BR>|\s)?n(<BR>|\s)?\[(<BR>|\s)?(.*)(<BR>|\s)?\](<BR>|\s)?R(<BR>|\s)?P(<BR>|\s)?G(<BR>|\s)?-(<BR>|\s)?(<BR>|\s)?D(<BR>|\s)?a(<BR>|\s)?t(<BR>|\s)?a(<BR>|\s)?-(<BR>|\s)?E(<BR>|\s)?n(<BR>|\s)?d(<BR>|\s)?@(<BR>|\s)?\])/i)){
	Data = RegExp.$1
	} else {
	Data = ""
	}

	for(n=0;n<Data.length;n++){
	Data = Data.replace(/<BR>/i,'')
	Data = Data.replace(' ','')
	Data = Data.replace(/(<BR>|\s)?&amp;(<BR>|\s)?#(<BR>|\s)?1(<BR>|\s)?2(<BR>|\s)?4(<BR>|\s)?;(<BR>|\s)?/, '|')
	}

Number = RandNum()
Number = "tbody_"+Number

Inventory = GrabRPGSetting('Items', Data, '')

InvDisp = ""
	
	// You have items? LIEK OMG! :O!
	if(Inventory != ''){
	Inventory = explode("|",Inventory)
		for(i=0;i<Inventory.length;i++){

		InvDisp += " <img src='"+Items[Inventory[i]][1]+"' alt='"+Items[Inventory[i]][2]+"' />"
		}
	} else {
	InvDisp = "<i>None</i>"
	}

//	DataScan = DataLink.href + "&CODE=Scan"
//	DataScan = "[<a href='"+DataScan+"' target='_blank'>Profile</a>]"

CellDisplay = "<span style='float:right;'><b><a href='javascript:HideShowr(\""+Number+"\");' id='link_"+Number+"'>+</a></b></span>"

RPGTable = "<center><div class='tableborder'><table width='100%' border='0' cellspacing='1' cellpadding='1'>"
RPGTable += "<tr><td colspan='6' class='titlemedium' align='center'>"+CellDisplay+"Shopping Information"+"<!-- RP_PROFILE_IN --></td></tr><tbody style='display:none;' id='"+Number+"'>"
//RPGTable += "<tr>"+"<td class='darkrow1' align='center'><b>Name</b></td>"
RPGTable += "<td class='row2' align='center'><b>"+MoneyName+"</b></td>"
//RPGTable += "<td class='darkrow1' align='center'><b>Type</b></td>"
RPGTable += "<td class='row2' align='center'><b>Element</b></td></tr>"


rClass = GrabRPGSetting('Class', Data, '<i>Not a Store member yet.</i>')
	if(!isNaN(rClass)){
	rClass = Class[rClass]
	}

ElemI = GrabRPGSetting('Element', Data, '<i>Not a Store member yet.</i>')

	if(ElemI != '<i>Not a Store member yet.</i>'){
	ElemI = "<img src='"+Elements[ElemI][0]+"' alt='"+Elements[ElemI][1]+"'>"
	}


//RPGTable += "<tr><td class='row2' align='center'>"+GrabRPGSetting('Name', Data, '<i>None</i>')+"</td>"
RPGTable += "<td class='darkrow1' align='center'>"+GrabRPGSetting('Money', Data, '0')+"</td>"
//RPGTable += "<td class='row2' align='center'>"+rClass+"</td>"
RPGTable += "<td class='darkrow1' align='center'>"+ElemI+"</td></tr>"
RPGTable += "<tr><td colspan='5' class='darkrow1'><table width='100%' border='0' cellspacing='1' cellpadding='1'>"

RPGTable += "<tr><td class='row2' align='center' colspan='2'><b>Inventory</b></td>"
RPGTable += "<tr><td class='darkrow1' align='center' colspan='2'>"+InvDisp+"</td>"

RPGTable += "</table></td></tr>"

RPGTable += ""
RPGTable += ""
RPGTable += "</tbody></table></div></center>"

DataCell.innerHTML += RPGTable
}

function BuildTopicView(){
Table = Grab('table')
	for(t=0;t<Table.length;t++){
	check = Table[t].width == "100%" && Table[t].border == "0" && Table[t].rows[1]
	check2 = Table[t].cellSpacing == "1" && Table[t].cellPadding == "3"
		if(check && check2){
			if(Table[t].rows[1].cells[0] && Table[t].rows[0].cells[0].getElementsByTagName('a')[0]){
				if(Table[t].rows[1].cells[0].className.match(/(post(1|2))/i) && Table[t].rows[1].cells[1] && !Table[t].rows[1].cells[1].innerHTML.match('<!-- RP_PROFILE_IN -->')){
				ConstructPostCell(Table[t].rows[1].cells[1],Table[t].rows[0].cells[0].getElementsByTagName('a')[0])
				}
			}
		}
	}
HideRPGData()
}

function HideRPGData(){
Div = Grab('div')
	for(d=0;d<Div.length;d++){

		if(Div[d].className == "signature" && Div[d].innerHTML.match(/\[(<BR>|\s)?@(<BR>|\s)?R(<BR>|\s)?P(<BR>|\s)?G(<BR>|\s)?-(<BR>|\s)?D(<BR>|\s)?a(<BR>|\s)?t(<BR>|\s)?a(<BR>|\s)?-(<BR>|\s)?B(<BR>|\s)?e(<BR>|\s)?g(<BR>|\s)?i(<BR>|\s)?n(<BR>|\s)?\[(<BR>|\s)?(.*)(<BR>|\s)?\](<BR>|\s)?R(<BR>|\s)?P(<BR>|\s)?G(<BR>|\s)?-(<BR>|\s)?(<BR>|\s)?D(<BR>|\s)?a(<BR>|\s)?t(<BR>|\s)?a(<BR>|\s)?-(<BR>|\s)?E(<BR>|\s)?n(<BR>|\s)?d(<BR>|\s)?@(<BR>|\s)?\]/i)){
		DataIn = RegExp.$1
		Data = new RegExp("\\[(<BR>|\\s)?@(<BR>|\\s)?R(<BR>|\\s)?P(<BR>|\\s)?G(<BR>|\\s)?-(<BR>|\\s)?D(<BR>|\\s)?a(<BR>|\\s)?t(<BR>|\\s)?a(<BR>|\\s)?-(<BR>|\\s)?B(<BR>|\\s)?e(<BR>|\\s)?g(<BR>|\\s)?i(<BR>|\\s)?n(<BR>|\\s)?\\[(<BR>|\\s)?(.*)(<BR>|\\s)?\\](<BR>|\\s)?R(<BR>|\\s)?P(<BR>|\\s)?G(<BR>|\\s)?-(<BR>|\\s)?(<BR>|\\s)?D(<BR>|\\s)?a(<BR>|\\s)?t(<BR>|\\s)?a(<BR>|\\s)?-(<BR>|\\s)?E(<BR>|\\s)?n(<BR>|\\s)?d(<BR>|\\s)?@(<BR>|\\s)?\\]","i")
		Div[d].innerHTML = Div[d].innerHTML.replace(Data,'')
		}
	}
TD = Grab('td')
	for(t=0;t<TD.length;t++){
		if(TD[t].innerHTML.match(/\[@RPG-Data-Begin\[(.*)\]RPG-Data-End@\]/i)){
		DataIn = RegExp.$1
		Data = new RegExp("\\[(<BR>|\\s)?@(<BR>|\\s)?R(<BR>|\\s)?P(<BR>|\\s)?G(<BR>|\\s)?-(<BR>|\\s)?D(<BR>|\\s)?a(<BR>|\\s)?t(<BR>|\\s)?a(<BR>|\\s)?-(<BR>|\\s)?B(<BR>|\\s)?e(<BR>|\\s)?g(<BR>|\\s)?i(<BR>|\\s)?n(<BR>|\\s)?\\[(<BR>|\\s)?(.*)(<BR>|\\s)?\\](<BR>|\\s)?R(<BR>|\\s)?P(<BR>|\\s)?G(<BR>|\\s)?-(<BR>|\\s)?(<BR>|\\s)?D(<BR>|\\s)?a(<BR>|\\s)?t(<BR>|\\s)?a(<BR>|\\s)?-(<BR>|\\s)?E(<BR>|\\s)?n(<BR>|\\s)?d(<BR>|\\s)?@(<BR>|\\s)?\\]","i")
		TD[t].innerHTML = TD[t].innerHTML.replace(Data,'')
		}
	}
}

links = document.links
	for(i=0;i<links.length;i++){
		if(links[i].href.match('act=UserCP&CODE=22') && !links[i].getAttribute('type')){
		links[i].href = links[i].href 
//+ '&Shacker'
		}
	}

if(location.href.match(/UserCP&CODE=22/)){
stripSigValue()
	// Saved?
	if(document.referrer.match(/Shacker=(.*)/) && !location.href.match('NoRedir') && !location.href.match(/&Shacker=(.*)/)){

	BuildRPGMenu()

	RPGData = document.forms['REPLIER'].rpgdata.value

	Page = RegExp.$1

	BuildRPGDisplay("Loading Store information", "Please wait for a moment...");

	location.href = location.href + '&Shacker='+Page
	}
}

if(!location.href.match(/showtopic=(\d+)/i)){
HideRPGData()
} else {
BuildTopicView()
}


function stripSigValue(){
Val = document.forms['REPLIER'].Post.value
	if(Val.match(/\[@RPG-Data-Begin\[(.*)\]RPG-Data-End@\]/i)){
	Data = RegExp.$1
	Val = Val.replace('[@RPG-Data-Begin['+Data+']RPG-Data-End@]','')
	document.forms['REPLIER'].Post.value = Val
	} else {
	Data = ""
	}
	setSigButton(Data)

}

function setSigButton(Data){
NewSigButton = "<input type='button' id='Updatesetsign' value='Update my Signature' onClick='sigSubmit();' class='forminput' />"
NewSigButton += "<input type='hidden' name='rpgdata' value='"+Data+"'>"
Div = Grab('div')
	for(d=0;d<Div.length;d++){
		if(Div[d].getElementsByTagName('input')[0] && Div[d].className == "pformstrip"){
			with(Div[d].getElementsByTagName('input')[0]){
				if(type == "submit" && value == "Update my Signature"){
				Div[d].innerHTML = NewSigButton
				}
			}
		}
	}
}

function sigSubmit(){
document.getElementById('Updatesetsign').disabled = true
document.forms['REPLIER'].style.visibility="hidden"
Data = "[@RPG-Data-Begin["+document.forms['REPLIER'].rpgdata.value+"]RPG-Data-End@]"
document.forms['REPLIER'].Post.value += Data
document.forms['REPLIER'].submit(true)
}
