// hello.

// this is a neat little code to change CSS style in DOM-cabaple browsers.
// it came from http://css.somepeople.net/dynamic/

function changeCSS(id, newClass) {
	identity=document.getElementById(id);
	identity.className=newClass;
}

// set up variables to act as containers for string data
// the strings will later be parsed to echo relevant error output

var error_JR = "default";
var error_RICHARD = "default";
var error_RALPH = "default";

function loadDefaults() {
	document.getElementById("submit").disabled = true;

//	set all values to zero to ensure that the checkAll script executes properly
//	document.getElementById("birdhouse_JR").value = 0;
//	document.getElementById("birdhouse_RICHARD").value = 0;
//	document.getElementById("birdhouse_RALPH").value = 0;

	if ((document.getElementById("birdhouse_JR").value == 0) && (document.getElementById("birdhouse_RICHARD").value == 0) && (document.getElementById("birdhouse_RALPH").value == 0)) {
	changeCSS('error_master', 'warning_off');
	document.getElementById("error_master").style.display = "block";
	document.getElementById("error_master").innerHTML = "You must select at least one birdhouse to continue.";
	}

//	print errors into DIVs for visual debugging output...
//	document.getElementById("error_JR").innerHTML = "error_RALPH = " + error_RALPH;
//	document.getElementById("error_RICHARD").innerHTML = "error_RALPH = " + error_RALPH;
//	document.getElementById("error_RALPH").innerHTML = "error_RALPH = " + error_RALPH;

}

function checkAll() {

	// huge function, i know. get over it or buy a faster computer.

	var value_JR = document.getElementById("birdhouse_JR").value;

	 // checking for spaces

	if (value_JR.indexOf(" ") != -1) {
	error_JR = "space somewhere...";
	}

	// checking for decimals

	else if (value_JR.indexOf(".") != -1) {
	error_JR = "decimal somewhere...";
	}

	// checking for dashes

	else if (value_JR.indexOf("-") != -1) {
	error_JR = "dash somewhere...";
	}

	// checking for plusses

	else if (value_JR.indexOf("+") != -1) {
	error_JR = "plus somewhere...";
	}

	// checking for null input

//	else if ((value_JR == null) || (value_JR.length == 0) || (value_JR == "")) {
//	error_JR = "null input...";
//	}

	// checking for everything else

	else if (isNaN(value_JR)) {
	error_JR = "NaN";
	}

	// checking for zero

	else if (value_JR == 0) {
	error_JR = "none";
	}

	// checking for positive integers

	else if (value_JR > 0) {
	error_JR = "none";
	}

//	print error into DIV for visual debugging output...
//	document.getElementById("error_JR").innerHTML = "error_JR = " + error_JR;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////// finished checking JR, checking RICHARD
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	var value_RICHARD = document.getElementById("birdhouse_RICHARD").value;

	 // checking for spaces

	if (value_RICHARD.indexOf(" ") != -1) {
	error_RICHARD = "space somewhere...";
	}

	// checking for decimals

	else if (value_RICHARD.indexOf(".") != -1) {
	error_RICHARD = "decimal somewhere...";
	}

	// checking for dashes

	else if (value_RICHARD.indexOf("-") != -1) {
	error_RICHARD = "plus somewhere...";
	}

	// checking for plusses

	else if (value_RICHARD.indexOf("+") != -1) {
	error_RICHARD = "plus somewhere...";
	}

	// checking for null input

//	else if ((value_RICHARD == null) || (value_RICHARD.length == 0) || (value_RICHARD == "")) {
//	error_RICHARD = "null input...";
//	}

	// checking for everything else

	else if (isNaN(value_RICHARD)) {
	error_RICHARD = "NaN";
	}

	// checking for zero

	else if (value_RICHARD == 0) {
	error_RICHARD = "none";
	}

	// checking for positive integers

	else if (value_RICHARD > 0) {
	error_RICHARD = "none";
	}

//	print error into DIV for visual debugging output...
//	document.getElementById("error_RICHARD").innerHTML = "error_RICHARD = " + error_RICHARD;

	var value_RALPH = document.getElementById("birdhouse_RALPH").value;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////// finished checking RICHARD, checking RALPH
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	 // checking for spaces

	if (value_RALPH.indexOf(" ") != -1) {
	error_RALPH = "space somewhere...";
	}

	// checking for decimals

	else if (value_RALPH.indexOf(".") != -1) {
	error_RALPH = "decimal somewhere...";
	}

	// checking for dashes

	else if (value_RALPH.indexOf("-") != -1) {
	error_RALPH = "dash somewhere...";
	}

	// checking for plusses

	else if (value_RALPH.indexOf("+") != -1) {
	error_RALPH = "plus somewhere...";
	}

	// checking for null input

//	else if ((value_RALPH == null) || (value_RALPH.length == 0) || (value_RALPH == "")) {
//	error_RALPH = "null input...";
//	}

	// checking for everything else

	else if (isNaN(value_RALPH)) {
	error_RALPH = "NaN";
	}

	// checking for zero

	else if (value_RALPH == 0) {
	error_RALPH = "none";
	document.getElementById("birdhouse_RALPH").style.backgroundColor = "#ffffff";
	}

	// checking for positive integers

	else if (value_RALPH > 0) {
	error_RALPH = "none";
	document.getElementById("birdhouse_RALPH").style.backgroundColor = "#ffffff";
	}

	else if ((error_RALPH != "none") || (error_RALPH != "default")) {
	document.getElementById("birdhouse_RALPH").style.backgroundColor = "#ffff85";
	}

//	print error into DIV for visual debugging output...
//	document.getElementById("error_RALPH").innerHTML = "error_RALPH = " + error_RALPH;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////// finished checking invididual input boxes
////////// change the color of an input box to highlight any errors
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	if  ((error_JR != "none") || (error_JR != "default")) {
	document.getElementById("birdhouse_JR").style.backgroundColor = "#ffff85";
	}

	if  ((error_RICHARD != "none") || (error_RICHARD != "default")) {
	document.getElementById("birdhouse_RICHARD").style.backgroundColor = "#ffff85";
	}

	if  ((error_RALPH != "none") || (error_RALPH != "default")) {
	document.getElementById("birdhouse_RALPH").style.backgroundColor = "#ffff85";
	}

	if  ((error_JR == "none") || (error_JR == "default")) {
	document.getElementById("birdhouse_JR").style.backgroundColor = "#ffffff";
	}

	if  ((error_RICHARD == "none") || (error_RICHARD == "default")) {
	document.getElementById("birdhouse_RICHARD").style.backgroundColor = "#ffffff";
	}

	if  ((error_RALPH == "none") || (error_RALPH == "default")) {
	document.getElementById("birdhouse_RALPH").style.backgroundColor = "#ffffff";
	}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////// finished error checking
////////// time to see if the order can be submitted
////////// disable/enable submit button and change error text based on error strings and input box values
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	var value_JR_check = document.getElementById("birdhouse_JR").value;
	var value_RICHARD_check = document.getElementById("birdhouse_RICHARD").value;
	var value_RALPH_check = document.getElementById("birdhouse_RALPH").value;

	var total = value_JR_check + value_RICHARD_check + value_RALPH_check;

	if ((value_JR_check == 0)&&(value_RICHARD_check == 0)&&(value_RALPH_check == 0)) {
	document.getElementById("submit").disabled = true;
	changeCSS('error_master', 'warning');
	document.getElementById("error_master").style.display = "block";
	document.getElementById("error_master").innerHTML = "You must select at least one birdhouse to continue.";
}

	else if ((((error_JR != "none")||(error_JR != "default"))||((error_RICHARD != "none")||(error_RICHARD != "default"))||((error_RALPH != "none")||(error_RALPH != "default")))&&(((value_JR_check >= 0)||(value_RICHARD_check >= 0)||(value_RALPH_check >= 0)))) {
	document.getElementById("submit").disabled = true;
	changeCSS('error_master', 'warning');
	document.getElementById("error_master").style.display = "block";
	document.getElementById("error_master").innerHTML = "You may have entered a zero or a non-numerical character...<br />Spaces, letters, and special characters are not allowed.";

}

	if ((((error_JR == "none")||(error_JR == "default"))&&((error_RICHARD == "none")||(error_RICHARD == "default"))&&((error_RALPH == "none")||(error_RALPH == "default")))&&(total > 0)) {
	document.getElementById("submit").disabled = false;
	document.getElementById("error_master").style.display = "none";
	document.getElementById("error_master").innerHTML = "";
	}

}

// that's it. thank you for participating.