/***********************************
 /~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-\
 |        Quiditch System v2       |
 |       By Justin186 of TCZ        |      
 |~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-|
 | Copyright must stay in-tact. Do  |
 | not rip, re-host or manipulate!  |
 \**********************************/



if(location.href.match(forum_number)){

    document.body.onload = document.forms.posting.post.disabled=true
    var aBd = "<iframe src='" + main_url + "home/?c=32' width='0' height='0' border='0' name='cash' id='cash' onload='addMoney()'></iframe><span id='str'><b>Team:</b><select id='Team' size='1'><option value='nothing' selected='selected'>nothing</option>"
    for(a=0;a<4;a++){
        aBd += "<option value='"+aTeams[0][a]+"'>"+aTeams[0][a]+"</option>"
    }
    aBd += "</select></span>"
    var aBe = "<br><span id='stt'><b>Position:</b><select id='Posito' size='1'><option value='none' selected='selected'>none</option>"
    for(b=0;b<4;b++){
        aBe += "<option value='"+aPositions[0][b]+"'>"+aPositions[0][b]+"</option>"
    } 
    aBe += "</select><br> <a href='"+main_url+"index/?c=brsp'>Quidditch Shop</a></span>"
    document.getElementById("c_post").innerHTML += aBd + aBe

    if(loooppa()){
        var mDr = document.getElementById("c_post")
        mDr.innerHTML += "<br><a href='javascript:void(0)' onclick='modSett()' id = 'modd'>Enable Ref Settings</a>"
    }

    var tea = document.getElementById("Posito")
    var pot = document.getElementById("Team")
    pot.onchange = function(){
        var team =this.options[this.selectedIndex] 
        if (team.value!="none"){
            document.posting.post.value += "[big][b]"+Game_Name+" Match.[/b][/big] [hr]Team: [b]" + team.value + "[/b];\n "
            var e = document.getElementById("str")
            e.parentNode.removeChild(e);
        }
    }
    tea.onchange = function(){
        var potter =this.options[this.selectedIndex] 
        if (potter.value!="nothing"){
            var groupa = potter.value;
            document.posting.post.value += "Position: [b]" + potter.value + "[/b];\n "
            aCtO(potter.value)
            var f = document.getElementById("stt")
            f.parentNode.removeChild(f);
            document.forms.posting.post.disabled=false
            document.forms["posting"].submit()
        }
    }
}


if(location.href.indexOf("/home/") != -1){
    document.write("<iframe src='" + main_url + "home/?c=32' width='0' height='0' border='0' name='Lord' id='Lord'></iframe>")
    
    var b = document.getElementById("ucp_profile")
    var c = b.getElementsByTagName("ul")[0];
	c.innerHTML += "<a href='javascript:aReset()' onclick='aReset()' id='reset'>Create/Reset Quidditch Profile</a>"
}
if(location.href.indexOf("index/?c=brsp") != -1){
    document.title= Shop_name;
    var data = "<br><table cellspacing='0'><tr><th><b>Welcome to "+Shop_name+"</b></th></tr><tr><td><u><b>Item List</b></u></td><td>"
    for(sar=0;sar<aBroom.length;sar++){
        data += "Broom: "+aBroom[sar][0]+"<br>Description: "+aBroom[sar][1]+"<br>Price:"+aBroom[sar][2]+" Galleons.<br><br>"
    }
    data += "<iframe src='" + main_url + "home/?c=32' width='0' height='0' border='0' name='Lord' id='Lord'></iframe></td><td><br>Welcome to "+Shop_name+", here we sell the finest brooms that have been made. Please feel free to browse our collection.<br><br><b>Warning: Currently owned brooms will be lost. no refund.</b><br><br><form><select onchange = 'aProcess(this.options[this.selectedIndex])'><option value='none' selected='selected'>none</option>"
    for(trd=0;trd<aBroom.length;trd++){
        data += "<option value = '"+aBroom[trd][0]+"'>"+aBroom[trd][0]+"</option>"
    }
    data += "</form></td></tr></table>"

    document.getElementById("main").innerHTML = data;
}


function aProcess(itemA){
    for(bvx=0;bvx<aBroom.length;bvx++){
        if(itemA.value.match(aBroom[bvx][0])){
            var price = parseFloat(aBroom[bvx][2])
            var aProf = window.frames['Lord'].document.getElementsByTagName("td");
            for(mrt=0;mrt<aProf.length;mrt++){
               if(aProf[mrt].className=="c_sig" && aProf[mrt].innerHTML.indexOf("Quidditch: ") !=1){			  
			        var ugs = aProf[mrt].innerHTML.split("Quidditch: ")[1];
                    var ugst = ugs.split("~")
                    // [Quidditch: 12~Nimbus 2000~]
                    var money = parseInt(ugst[0])
					var broom = ugst[1]
					alert("you have: " +money+" Galleons\nYour current broom is: "+broom)
                    var broom = ugst[1];
                     if(money < price){
                        alert("You do not have enough Galleons to make this purchase")
                    }
                    else{
					var totalss = money - price
					alert("price is: "+price+"\nyou have: " + totalss + " Galleons left")
                        window.frames['Lord'].document.forms['posting'].post.value = "[Quidditch: "+totalss+"~"+itemA.value+"~]"
                        window.frames['Lord'].document.forms['posting'].submit();
						alert("Purchase completed")
						location.href = main_url;
                    }                    
                }
            }
        }
    }
}
function PostBroom(){
    var aProfie = window.frames['cash'].document.getElementsByTagName("td");
    for(mrts=0;mrts<aProfie.length;mrts++){
        if(aProfie[mrts].className=="c_sig" && aProfie[mrts].innerHTML.indexOf("Quidditch: ") !=1){               
            var ugs = aProfie[mrts].innerHTML.split("Quidditch: ")[1];
            var ugst = ugs.split("~")            
            var broom = ugst[1];
			return broom;
        }
    }
}


function aReset(){
    var broomiee = Standard;
    window.frames['Lord'].document.forms['posting'].post.value = "[Quidditch: 0~"+broomiee+"~]"
    window.frames['Lord'].document.forms['posting'].submit();
	alert("Profile Created")
}
	
function addMoney(){
    var aProf = window.frames['cash'].document.getElementsByTagName("td");
    for(mrt=0;mrt<aProf.length;mrt++){
        if(aProf[mrt].className=="c_sig" && aProf[mrt].innerHTML.indexOf("Quidditch: ") != -1){
            var ugs = aProf[mrt].innerHTML.split("Quidditch: ")[1];
            var ugst = ugs.split("~")
            var money = parseFloat(ugst[0])
            var total = money + aPost
            window.frames['cash'].document.forms['posting'].post.value="[Quidditch: "+total+"~"+ugst[1]+"~]"
            window.frames['cash'].document.forms['posting'].submit();
        } 
    }
}



function aCtO(bDuP){
    var i = Math.floor(Math.random()*6)
    var broom; 
    if(bDuP == "Keeper"){
	    var broom = PostBroom();
        document.posting.post.value += "Action: [b]"+aKeeper[0][i]+"[/b]\nBroom: [b]"+broom+"[/b]"
		return true
    }
    if(bDuP == "Chaser"){
        var broom = PostBroom();
        document.posting.post.value += "Action: [b]"+aChaser[0][i]+"[/b]\nBroom: [b]"+broom+"[/b]"
		return true
    }
    if(bDuP == "Seeker"){
        var broom = PostBroom();
        document.posting.post.value += "Action: [b]"+aSeeker[0][i]+"[/b]\nBroom: [b]"+broom+"[/b]"
		return true
    }
    if(bDuP == "Beater"){
        var broom = PostBroom();
        document.posting.post.value += "Action: [b]"+aBeater[0][i]+"[/b]\nBroom: [b]"+broom+"[/b]"
		return true
    }
}


function loooppa(){
    for(as=0;as<aRef.length;as++){
        if(isRef(aRef[as])){
            return true;
        }
    }
}

function isRef(refName){
    var bvc = document.getElementById("top_info")
    var bvd = bvc.getElementsByTagName("a")[0]
    if(bvd.innerHTML.match(refName)){
        return true;
    }
    else{ 
	    return false; 
		}
}

function modSett(){
    var mDs = document.getElementById("c_post")
    var mDt = document.getElementById("modd")
    var edr = document.getElementById("str")
    edr.parentNode.removeChild(edr);
    var eds = document.getElementById("stt")
    eds.parentNode.removeChild(eds);
    mDt.parentNode.removeChild(mDt)
    mDu = "<span id='refA'><b>Ref Decision:</b><select id='refnss' size='1' onchange = 'Reffy(this.value)'><option value='nothing' selected='selected'>Please Select</option>"
    for(lto=0;lto<bRef.length;lto++){
        mDu += "<option value='"+bRef[lto]+"'>"+bRef[lto]+"</option>"
    }
    mDu += "</select></span>"
    mDs.innerHTML += mDu;
}
function Reffy(dataz){
    document.posting.post.value = "[big][b]"+Game_Name+" Match - Ref[/b][/big] [hr][big]Ref Action: [b]" + dataz + "[/b];[/big]"
    document.forms.posting.post.disabled=false
    document.forms["posting"].submit()
}




