PC="pc"
NPC="npc"

mainMenuWrapper=new AGEBox("white", "#ffffff", "#000000")

mainMenu=new AGEElement
mainMenu.putAt(0,0)
mainMenu.setTopWrapper(mainMenuWrapper.topWrapper)
mainMenu.setBottomWrapper(mainMenuWrapper.bottomWrapper)

mainMenuContents="<input type=button value='Roll all initiatives' onclick='javascript:rollInitiatives()'>"
mainMenuContents+="<input type=button value='Save all' onclick='javascript:saveAll()'><br>"
mainMenuContents+="<input type=checkbox id=skipPcs>Automatically roll PC initiatives<br>"
mainMenuContents+="<input type=checkbox id=skipNpcs>Automatically roll NPC initiatives<br>"
mainMenuContents+="Create a new: <input type=button value=PC onclick='javascript:newCharacter(PC)'><input type=button value=NPC onclick='javascript:newCharacter(NPC)'><br>"
mainMenuContents+="<a href='http://www.asmor.com/scripts/CombatTracker/combatTrackerv0.1.zip'>Download Combat Tracker</a> for offline<br>use (reccomended, required for saving)"
mainMenu.setContents(mainMenuContents)

mainMenu.show()

function rollInitiatives() {
	skipPcs=document.getElementById('skipPcs').checked
	skipNpcs=document.getElementById('skipNpcs').checked
	for (i=0; i<characters.length; i++) {
		if (characters[i].type=="pc") {
			initRoll=characters[i].rollInit()
			if (!skipPcs) {
				response=prompt("What does "+characters[i].name+" roll for initiative? (or press OK to use the automatically-rolled initiative)", initRoll)
				if (response==null) {
					response="Unrolled"
				}
				initRoll=response
			}
			characters[i].setInit(initRoll)
		}
	}
	for (i=0; i<characters.length; i++) {
		if (characters[i].type=="npc") {
			initRoll=characters[i].rollInit()
			if (!skipNpcs) {
				response=prompt("What does "+characters[i].name+" roll for initiative? (or press OK to use the automatically-rolled initiative)", initRoll)
				if (response==null) {
					response="Unrolled"
				}
				initRoll=response
			}
			characters[i].setInit(initRoll)
		}
	}
}

savePaneBox=new AGEBox("white", "#FFFFFF", "#000000")

savePane=new AGEElement()
savePane.setStyle("zIndex", "100")
savePane.putAt(100,100)
savePane.setTopWrapper(savePaneBox.topWrapper)
savePane.setBottomWrapper("<hr><input type=button onclick='javascript:savePane.hide()' value=Close>"+savePaneBox.bottomWrapper)

function saveAll() {
	globalSave=""
	for (var i=0; i<characters.length; i++) {
		globalSave+=characters[i].getSaveText()+"<br><br>"
	}
	showSavePrompt("all characters", globalSave)
}

function showSavePrompt(name, toSave) {
	toSave="Copy the code below into defaults.js to save "+name+"<hr>"+toSave
	savePane.setContents(toSave)
	savePane.show()
}