defectCost = new Array()

defectCost[0] = new Array(1, 2, 3)
defectCost[1] = new Array(0, 0, 0)
defectCost[2] = new Array(0, 0, 0)
defectCost[3] = new Array(1, 2, 3)
defectCost[4] = new Array(1, 2, 3)
defectCost[5] = new Array(1, 2, 3)
defectCost[6] = new Array(0, 0, 0)
defectCost[7] = new Array(1, 2, 3)
defectCost[8] = new Array(1, 2, 3)
defectCost[9] = new Array(1, 2, 3)

defectCost[10] = new Array(1, 2, 3)
defectCost[11] = new Array(2, 4, 6)
defectCost[12] = new Array(1, 2, 3)
defectCost[13] = new Array(2, 4, 6)
defectCost[14] = new Array(1, 2, 3)
defectCost[15] = new Array(3, 6, 9)
defectCost[16] = new Array(2, 4, 6)
defectCost[17] = new Array(1, 2, 3)
defectCost[18] = new Array(1, 2, 3)
defectCost[19] = new Array(0, 0, 0)

defectCost[20] = new Array(1, 2, 3)
defectCost[21] = new Array(1, 2, 3)
defectCost[22] = new Array(1, 2, 3)
defectCost[23] = new Array(0, 0, 0)
defectCost[24] = new Array(1, 2, 3)
defectCost[25] = new Array(1, 2, 3)
defectCost[26] = new Array(1, 2, 3)
defectCost[27] = new Array(1, 2, 3)
defectCost[28] = new Array(1, 2, 3)
defectCost[29] = new Array(1, 2, 3)

defectCost[30] = new Array(1, 2, 3)
defectCost[31] = new Array(1, 2, 3)
defectCost[32] = new Array(1, 2, 3)
defectCost[33] = new Array(1, 2, 3)
defectCost[34] = new Array(1, 2, 3)
defectCost[35] = new Array(1, 2, 3)
defectCost[36] = new Array(1, 2, 3)
defectCost[37] = new Array(1, 2, 3)
defectCost[38] = new Array(1, 2, 3)
defectCost[39] = new Array(1, 2, 3)

defectCost[40] = new Array(1, 2, 3)
defectCost[41] = new Array(1, 2, 3)
defectCost[42] = new Array(1, 2, 3)
defectCost[43] = new Array(1, 2, 3)
defectCost[44] = new Array(1, 2, 3)
defectCost[45] = new Array(1, 2, 3)

var theDefect

function defectAdd(){
	
	numDefect = document.sasCharacter.defects.selectedIndex
	theDefect = document.sasCharacter.defects.options[numDefect].value
	checkDefect()
}

function checkDefect(){
	oppositeAttribute = 0
	if (theDefect=="Not So Tough"){
	
		d = document.sasCharacter.chosenAttributes.length
		if (d>0){
		for (e=0; e<d; e++){
			if (document.sasCharacter.chosenAttributes.options[e].value=="Tough"){
			oppositeAttribute = 1
			}
		}
		}
	}

			if (oppositeAttribute==1){
			alert("You may not select Tough and Not So Tough at the same time. Please remove Tough as an attribute if you wish to choose Not So Tough.")
			}
			else {
			checkDefect2()
			}
}

function checkDefect2(){
	
	//secondDefect = 0
	
	//a = document.sasCharacter.chosenDefects.length
	//if (a>0){
		//for (i=0; i<a; i++){
		//if (document.sasCharacter.chosenDefects.options[i].value==theDefect){
		//secondDefect = 1
		//}
		//}
		//}

	//if (secondDefect==1){
	//alert("You have already chosen this defect.")
	//}
	//else {
	newDefectWindow()
	//}

}


function newDefectWindow(){
	defectWindow = window.open('defectcost.htm', 'defectWin', 'toolbar=no, location=no, scrollbars=no, resizable=no, width=400, height=200')
	defectWindow.open
	return true
}

function addDefectCost(){
	nextOption = new Option(theDefect, theDefect)
	numDefects = document.sasCharacter.chosenDefects.length
	document.sasCharacter.chosenDefects.options[numDefects]=nextOption
	document.sasCharacter.chosenDefects.size=numDefects+1
	
	costofDefect = defectWindow.levelCost
	nextOption1 = new Option(costofDefect, costofDefect)
	document.sasCharacter.chosenDefectsCost.options[numDefects]=nextOption1
	document.sasCharacter.chosenDefectsCost.size=numDefects+1
	
	anothernumber = document.sasCharacter.chosenDefectsTotal.length
	basecost = defectWindow.levelCost
	basecost = eval(basecost)*(-1)
	nextOption2 = new Option(basecost, basecost)
	document.sasCharacter.chosenDefectsTotal.options[anothernumber]=nextOption2
	document.sasCharacter.chosenDefectsTotal.size=anothernumber+1
	
	document.sasCharacter.chosenDefects.options[anothernumber].selected="True"
	document.sasCharacter.chosenDefectsCost.options[anothernumber].selected="True"
	document.sasCharacter.chosenDefectsTotal.options[anothernumber].selected="True"
	
	//generate
	nextgenerateOption = new Option(theDefect, theDefect)
	numgenerateDefects = document.sasCharacter.generatechosenDefects.length
	document.sasCharacter.generatechosenDefects.options[numgenerateDefects]=nextgenerateOption
	document.sasCharacter.generatechosenDefects.size=numgenerateDefects+1
	
	costofgenerateDefect = defectWindow.levelCost
	nextgenerateOption1 = new Option(costofDefect, costofDefect)
	document.sasCharacter.generatechosenDefectsCost.options[numgenerateDefects]=nextgenerateOption1
	document.sasCharacter.generatechosenDefectsCost.size=numgenerateDefects+1
	
	anothergeneratenumber = document.sasCharacter.generatechosenDefectsTotal.length
	basecost = defectWindow.levelCost
	basecost = eval(basecost)*(-1)
	nextgenerateOption2 = new Option(basecost, basecost)
	document.sasCharacter.generatechosenDefectsTotal.options[anothergeneratenumber]=nextgenerateOption2
	document.sasCharacter.generatechosenDefectsTotal.size=anothergeneratenumber+1
	
	document.sasCharacter.generatechosenDefects.options[anothergeneratenumber].selected="True"
	document.sasCharacter.generatechosenDefectsCost.options[anothergeneratenumber].selected="True"
	document.sasCharacter.generatechosenDefectsTotal.options[anothergeneratenumber].selected="True"
		
	
	oldtotalpoints = document.sasCharacter.totalpoints.value
	theTotal = document.sasCharacter.chosenDefectsTotal.options[anothernumber].value
	oldtotalpoints = eval(oldtotalpoints)+eval(theTotal)
	document.sasCharacter.totalpoints.value = oldtotalpoints
	
	if (theDefect=="Not So Tough"){
	notSoToughHP = eval(theTotal)*10
	changeHP()
	}
	
	if (theDefect=="Inept Attack"){
	attackCombatMasteryACV = (eval(defectWindow.selectedCost)+1)*-1
	changeACV(attackCombatMasteryACV)
	}
	
	if (theDefect=="Inept Defense"){
	defenseCombatMasteryDCV = (eval(defectWindow.selectedCost)+1)*-1
	changeDCV(defenseCombatMasteryDCV)
	}

}

function DefectsSelect(thingSelected){
	//modifyAttribute=document.sasCharacter.chosenAttributes.selectedIndex 
	
	document.sasCharacter.chosenDefects.options[thingSelected].selected="True"
	document.sasCharacter.chosenDefectsCost.options[thingSelected].selected="True"
	//document.sasCharacter.chosenDefectsLevel.options[thingSelected].selected="True"
	document.sasCharacter.chosenDefectsTotal.options[thingSelected].selected="True"
}

function modifyDefects(){
	modifyWindow = window.open('modifydefects.htm', 'defectWin', 'toolbar=no, location=no, scrollbars=no, resizable=no, width=400, height=200')
	modifyWindow.open
}