var MoveStep = 10;
//initial values
var ParentAccount0 = 100; 
var GoodKidSS0 = 150;
//current values
var ParentAccount = ParentAccount0; 
var GoodKidSS = GoodKidSS0;

var ToSchoolId = "ToSchool";
var ToChildId="ToChild";
var ParentSSId="ParentSS";
var GoodKidSS0id="GoodKidSS0";
var ParentAccount0id="ParentAccount0";

function initValues(){
	GoodKidSS0 = parseInt(document.getElementById(GoodKidSS0id).value);
	ParentAccount0 = parseInt(document.getElementById(ParentAccount0id).value);
	
	GoodKidSS0 = NaNToZero(GoodKidSS0);
	ParentAccount0 = NaNToZero(ParentAccount0);
	
	var el = document.getElementById(ToChildId);	
	el.value = 0;
	el = document.getElementById(ToSchoolId);
	el.value = 0;
	ParentAccount = ParentAccount0; 
	GoodKidSS = GoodKidSS0;
	initParentSS();
}

function NaNToZero(val){
	if(isNaN(val)){
		return 0;
	}
	return val;
}

function initParentSS(){
	var el = document.getElementById(ParentSSId);	
	el.value = ParentAccount + GoodKidSS;
}
function OnUp(){
	var el = document.getElementById(ToSchoolId);	
	if(ParentAccount >= MoveStep ){
		ParentAccount-=MoveStep;
		el.value =  parseInt(el.value) + MoveStep;
	}else{
		//show warning and beep
	}
	initParentSS();
}


function OnDown(){
	var el = document.getElementById(ToChildId);	
	if(GoodKidSS >= MoveStep ){
		GoodKidSS-=MoveStep;
		el.value =   parseInt(el.value) + MoveStep;
	}else if(ParentAccount >= MoveStep ){
		ParentAccount-=MoveStep;
		el.value =  parseInt(el.value) + MoveStep;
	}else{
		alert("You can't transfer more supershills.");
	}
	initParentSS();
}

function disagebleBenefits(){
	var el = document.getElementById("checkbox3");
	var res = confirm("Are you sure?");
	if(res){
		if(el.checked){		
			document.disableForm.dissable.value = 'dissable';
			document.disableForm.submit();
		}else{
			document.disableForm.dissable.value = 'enable';
			document.disableForm.submit();
		}
	}		
}

function showHelp(pos){
	var text = 'Help popup';
	switch (pos){
		case 1:
			text = 'This is the number of SuperShills you are about to give your child for attendance to SecretBuilders School.';
			break;
		case 2:
			text = 'This is the number of SuperShills you have to distribute. You cannot move the 300 SuperShills per month intended for your child\'s Good Behavior Account - 300 SuperShills per month are automatically added to their SecretBuilders School account.';
			break;
		case 3:
			text = 'This is the number of SuperShills you are about to give your child for good real-world behavior.';
			break;
		case 4:
			text = 'Checking this will disable all parental benefits control. All SuperShills from SecretBuilders School and the Good Behavior Bonus will be given to the player now, and all future monthly allowances will go directly to them for as long as this box is checked.';
			break;
		case 4:
			text = 'This will complete the transaction and gift your child with SuperShills and/or credit their SecretBuilders School account with the amounts you have specified.';
			break;
		case 5:
			text = 'This resets the SecretBuilders School and Good Behavior balances without transferring any SuperShills. Your account balance will be restored. Cannot be used after confirming a transaction.';
			break;
	}
	
	alert(text);
}

function validateReward(userid){
	var schoolSS = parseInt(document.getElementById(ToSchoolId).value);
	var bonusSS = parseInt(document.getElementById(ToChildId).value);
	var parentMoney = parseInt(document.getElementById(ParentSSId).value);
	
	schoolSS = NaNToZero(schoolSS);
	bonusSS = NaNToZero(bonusSS);
	parentMoney = NaNToZero(parentMoney);
	
	if(bonusSS == 0 && schoolSS == 0 && parentMoney > 0){
		alert('You have not added anything to either the SecretBuilders School or the Good Behavior Bonus balances. Use the Up and Down arrow buttons to add SuperShills to each account before clicking \'Update\'');
		return;
	}else if(bonusSS == 0 && schoolSS == 0 && parentMoney == 0){
		alert('You cannot add anything to either the SecretBuilders School or the Good Behavior Bonus balances because you have no SuperShills.');
		return;
	}else if(bonusSS == 0 && schoolSS > 0){
		alert('Successfully transferred SuperShills to SecretBuilders School. Click OK to proceed.');
		
	}else if(bonusSS > 0 && schoolSS == 0){
		alert('Successfully gifted SuperShills to ' + userid + '. Click OK to continue.');		
	}else if(bonusSS > 0 && schoolSS > 0){
		alert('Successfully transferred SuperShills to SecretBuilders School and gifted SuperShills to ' + userid + '. Click OK to proceed.');	
	}	
	document.rewardForm.submit();
}

