// JavaScript Document

//*****************************************************************************************************************************************
// This function checks to make sure that all sections are enabled or disabled correctly
//*****************************************************************************************************************************************
function setFunctionality(){

}

//*****************************************************************************************************************************************
// This function is used ro reset all those sections that follow the most recently selected one
//*****************************************************************************************************************************************
function resetValues(val) { //v3.0

	if ( val < 2 ){
			document.all.ColorTD.style.backgroundColor='#E8E5EC';
	}
	if ( val < 1 ){ // Nothing has been selected on 
			document.all.ColorTD.style.backgroundColor='#FFFFFF';
	}

	setFunctionality();

}
function resetValues2(val) { //v3.0

	if ( val < 2 ){
			document.all.Color2TD.style.backgroundColor='#E8E5EC';
	}
	if ( val < 1 ){ // Nothing has been selected on 
			document.all.Color2TD.style.backgroundColor='#FFFFFF';
	}

	setFunctionality();

}

function validateForm(){

	var reg = /[^0-9]/;
	var submitPage = "true";

	var notNumber = "false";
	var foundInsert = "false";
	var foundMat = "false";
	
	var found_it = getSelectedValue('insertColor');
	var found_it2 = getSelectedValue('matColor');
		
	var ins1010 = document.auBuilderForm.ins1010.value;
			
			if ( ins1010.match(reg) ){
				notNumber = "true";
			}
			if ( ins1010 != "" ){
				foundInsert = "true";
			}
	
	var ins88 = document.auBuilderForm.ins88.value;
			if ( ins88.match(reg) ){
				notNumber = "true";
			}
			if ( ins88 != "" ){
				foundInsert = "true";
			}
	
	var ins55 = document.auBuilderForm.ins55.value;
			if ( ins55.match(reg) ){
				notNumber = "true";
			}
			if ( ins55 != "" ){
				foundInsert = "true";
			}
	
	var pan1010 = document.auBuilderForm.pan1010.value;
			if ( pan1010.match(reg) ){
				notNumber = "true";
			}
			if ( pan1010 != "" ){
				foundInsert = "true";
			}
	
	var pan88 = document.auBuilderForm.pan88.value;
			if ( pan88.match(reg) ){
				notNumber = "true";
			}
			if ( pan88 != "" ){
				foundInsert = "true";
			}
	
	var pan55 = document.auBuilderForm.pan55.value;
			if ( pan55.match(reg) ){
				notNumber = "true";
			}
			if ( pan55 != "" ){
				foundInsert = "true";
			}
	
	var Hpan1010 = document.auBuilderForm.Hpan1010.value;
			if ( Hpan1010.match(reg) ){
				notNumber = "true";
			}
			if ( Hpan1010 != "" ){
				foundInsert = "true";
			}
	
	var Hpan88 = document.auBuilderForm.Hpan88.value;
			if ( Hpan88.match(reg) ){
				notNumber = "true";
			}
			if ( Hpan88 != "" ){
				foundInsert = "true";
			}
	
	var Hpan55 = document.auBuilderForm.Hpan55.value;
			if ( Hpan55.match(reg) ){
				notNumber = "true";
			}
			if ( Hpan55 != "" ){
				foundInsert = "true";
			}
	
	var DHpan1010 = document.auBuilderForm.DHpan1010.value;
			if ( DHpan1010.match(reg) ){
				notNumber = "true";
			}
			if ( DHpan1010 != "" ){
				foundInsert = "true";
			}
	
	var DHpan88 = document.auBuilderForm.DHpan88.value;
			if ( DHpan88.match(reg) ){
				notNumber = "true";
			}
			if ( DHpan88 != "" ){
				foundInsert = "true";
			}
	
	var DHpan55 = document.auBuilderForm.DHpan55.value;
			if ( DHpan55.match(reg) ){
				notNumber = "true";
			}
			if ( DHpan55 != "" ){
				foundInsert = "true";
			}
	
	var dig1010 = document.auBuilderForm.Dig1010.value;
			
			if ( dig1010.match(reg) ){
				notNumber = "true";
			}
			if ( dig1010 != "" ){
				foundInsert = "true";
			}
	
	for (i=1; i<8; i++){
	
		qty = eval('document.auBuilderForm.qty5' +  i + '.value');
			if ( qty.match(reg) ){
				notNumber = "true";
			}
			if ( qty != "" ){
				foundMat = "true";
			}
			
	}
	
	for (i=81; i<92; i++){
	
		qty = eval('document.auBuilderForm.qty' +  i + '.value');
			if ( qty.match(reg) ){
				notNumber = "true";
			}
			if ( qty != "" ){
				foundMat = "true";
			}
			
	}
	
	for (i=101; i<111; i++){
	
		qty = eval('document.auBuilderForm.qty' +  i + '.value');
			if ( qty.match(reg) ){
				notNumber = "true";
			}
			if ( qty != "" ){
				foundMat = "true";
			}
			
	}
	
	for (i=1011; i<1054; i++){
	
		qty = eval('document.auBuilderForm.qty' +  i + '.value');
			if ( qty.match(reg) ){
				notNumber = "true";
			}
			if ( qty != "" ){
				foundMat = "true";
			}
			
	}

	if ( foundInsert == "true" && found_it == "notSelected"){
			alert("You must select an Insert color before submiting Inserts to your basket");
			submitPage = "false";
	}
	if ( foundMat == "true" && found_it2 == "notSelected"){
			alert("You must select a Mat color before submiting Mats to your basket");
			submitPage = "false";
	}
	if ( notNumber == "true"){
			alert("Please enter numbers only into quantity fields");
			submitPage = "false";
	}

	if ( submitPage == "true"){
			document.auBuilderForm.submit();
	}
}
//*****************************************************************************************************************************************
// This function checks to make sure that all selections have been made before submitting
//*****************************************************************************************************************************************
//*****************************************************************************************************************************************
// This function checks to make sure that all selections have been made before submitting
//*****************************************************************************************************************************************
function checkComplete(){
	found_it = getSelectedValue('insertColor');
	
	if ( found_it != "notSelected" ){

		document.auBuilderForm.submit();
		
	}
	else{
		found_it = getSelectedValue('matColor');
		if ( found_it != "notSelected" ){
	
			document.auBuilderForm.submit();
			
		}
		else{
			alert("Please Finish all necessary selections before submitting album to basket.");
		}
	}

}