// JavaScript Document

//*****************************************************************************************************************************************
// This function checks to make sure that all sections are enabled or disabled correctly
//*****************************************************************************************************************************************
function setFunctionality(){
// check below to make sure that name and date imprint attributes are still available

	found_it = getSelectedValue('coverSize');

	if ( found_it == '55' ){
		disableSection('cameo',4);
//		disableSection('cameoColor',4);
		document.auBuilderForm.capacity[9].disabled = true;
		document.auBuilderForm.capacity[10].disabled = true;
	}
	else{
		enableSection('cameo',4);
	//	enableSection('cameoColor', 4);
		document.auBuilderForm.capacity[9].disabled = false;
		document.auBuilderForm.capacity[10].disabled = false;
	}
	
	if(found_it == '88'){
		
		disableSection('cameo',4);
		document.auBuilderForm.cameo[3].disabled = true;
	
	}
	
	if(found_it != '55' && found_it != '88'){
		enableSection('cameo', 4);
	}

// check below to make sure that cameo color is still available
/*
	found_it = getSelectedValue('cameo');

	if ( found_it != 'none' && found_it != 'sq' && found_it != 'na'){
		enableSection('cameoColor',4);
	}
	if ( found_it == 'none' || found_it == 'sq' && found_it != 'na'){
		disableSection('cameoColor',4);
	}
*/

// check below to make sure that cover title attributes are still available

	found_it = getSelectedValue('coverTitle');

	if ( found_it != 'none' ){
		enableSection('titleColor',5);
	}
	if ( found_it == 'none' ){
		disableSection('titleColor',5);
	}

// check below to make sure that studio imprint attributes are still available

	found_it = getSelectedValue('studioImprint');

	if ( found_it != 'none' && found_it == 'Die'){
		enableSection('studioImprintColor',5);
		disableSection('studioImprintText',3);
	}
	if ( found_it != 'none' && found_it != 'Die'){
		enableSection('studioImprintText',3);
		enableSection('studioImprintColor',5);
	}
	if ( found_it == 'none'){
		disableSection('studioImprintText',3);
		disableSection('studioImprintColor',5);
	}

// check below to make sure that name and date imprint attributes are still available

	found_it = getSelectedValue('nameImprint');

	if ( found_it != 'none' ){
		enableSection('nameImprintText',3);
		enableSection('nameImprintColor',5);
	}
	if ( found_it == 'none' ){
		disableSection('nameImprintText',3);
		disableSection('nameImprintColor',5);
	}

}

//*****************************************************************************************************************************************
// This function is used ro reset all those sections that follow the most recently selected one
//*****************************************************************************************************************************************
function resetValues(val) { //v3.0

	if ( val < 14 ){
			document.all.NameImprintColorTD.style.backgroundColor='#E8E5EC';
	}
	if ( val < 13 ){
			document.all.NameImprintTextTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.nameImprintColor[0].checked = true;
			document.all.NameImprintColorTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 12 ){
			document.all.NameImprintTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.nameImprintText[0].checked = true;
			document.all.NameImprintTextTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 11 ){
			document.all.StudioImprintColorTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.nameImprint[0].checked = true;
			document.all.NameImprintTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 10 ){
			document.all.StudioImprintTextTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.studioImprintColor[0].checked = true;
			document.all.StudioImprintColorTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 9 ){
			document.all.StudioImprintTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.studioImprintText[0].checked = true;
			document.all.StudioImprintTextTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 8 ){
			document.all.TitleColorTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.studioImprint[0].checked = true;
			document.all.StudioImprintTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 7 ){
			document.all.CoverTitleTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.titleColor[0].checked = true;
			document.all.TitleColorTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 6 ){
			document.all.CameoTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.coverTitle[0].checked = true;
			document.all.CameoTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 5 ){
			document.all.CameoTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.cameo[0].checked = true;
			document.all.CameoTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 4 ){
			document.all.CapacityTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.cameo[0].checked = true;
			document.all.CameoTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 3 ){
			document.all.CoverColorTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.capacity[0].checked = true;
			document.all.CapacityTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 2 ){
			document.all.CoverSizeTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.coverColor[0].checked = true;
			document.all.CoverColorTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 1 ){ // Nothing has been selected on 
			document.all.CoverSizeTD.style.backgroundColor='#FFFFFF';
	}

	setFunctionality();

}

//*****************************************************************************************************************************************
// This function is used to check that the Cover Color selected is valid
//*****************************************************************************************************************************************
function checkCoverColor(val) { //v3.0
	resetValues(2);
	var found_it;
	var change = 1;
   
    found_it = getSelectedValue('coverSize');
	
	if (found_it == "notSelected"){
		alert("You must first select a Cover Size.");
		document.auBuilderForm.coverColor[0].checked = true;
		change = 0;
	}
//	if (val != "Leat"){
//		document.auBuilderForm.leatherColor.value = "";
//	}
//	
//	if ( val == "Leat" ){
//		document.auBuilderForm.leatherColor.disabled = false;
//	}
//	if ( val != "Leat" ){
//		document.auBuilderForm.leatherColor.value = "";
//		document.auBuilderForm.leatherColor.disabled = true;
//	}

setBackgroundColors(change,val,'CoverColorTD');
}

//*****************************************************************************************************************************************
// This function is used to check that the Cover Color selected is valid
//*****************************************************************************************************************************************
function checkCapacity(val) { //v3.0
	resetValues(3);
	var change = 1;

	found_it = getSelectedValue('coverColor');

	if (found_it == "notSelected"){
		alert("You must first select a Cover Color.");
		document.auBuilderForm.capacity[0].checked = true;
		change = 0;
	}
	if (found_it == "Leat" && document.auBuilderForm.leatherColor.value == ""){
		alert("You must enter a leather color before selecting a capacity.");
		document.auBuilderForm.capacity[0].checked = true;
		change = 0;
	}
	setBackgroundColors(change,val,'CapacityTD');
}

//*****************************************************************************************************************************************
// This function is used to check that the Cover Cameo selected is valid
//*****************************************************************************************************************************************
function checkCameo(val) { //v3.0
//	resetValues(4);
	var found_it;
	var change = 1;

	found_it = getSelectedValue('capacity');

	if (found_it == "notSelected"){
		alert("You must first select a Capacity.");
		document.auBuilderForm.cameo[0].checked = true;
		change = 0;
	}
	
	setBackgroundColors(change,val,'CameoTD');
}

//*****************************************************************************************************************************************
// This function is used to check that the Cover Cameo Color selected is valid
//*****************************************************************************************************************************************
function checkCameoColor(val) { //v3.0
	resetValues(5);
	var found_it;
	var change = 1;

	found_it = getSelectedValue('cameo');

	if (found_it == "notSelected"){
		alert("You must first select a Cameo.");
		document.auBuilderForm.cameoColor[0].checked = true;
		change = 0;
	}
	
	setBackgroundColors(change,val,'CameoColorTD');
}

//*****************************************************************************************************************************************
// This function is used to check that the Cover Title selected is valid
//*****************************************************************************************************************************************
function checkCoverTitle(val) { //v3.0
	resetValues(6);
	var found_it;
	var change = 1;

	found_it = getSelectedValue('cameo');
   
   	if (found_it == 'notSelected'){
		alert('You must first select a Cameo Color.');
		document.auBuilderForm.coverTitle[0].checked = true;
		change = 0;
	}
	if ( val == 'Custom' ){
		document.auBuilderForm.customTitle1.disabled = false;
		document.auBuilderForm.customTitle2.disabled = false;
	}
	if ( val != 'Custom'){
		document.auBuilderForm.customTitle1.value = '';
		document.auBuilderForm.customTitle2.value = '';
		document.auBuilderForm.customTitle1.disabled = true;
		document.auBuilderForm.customTitle2.disabled = true;
	}
	if ( val == 'Monogram' ){
		document.auBuilderForm.monogramText1.disabled = false;
		document.auBuilderForm.monogramText2.disabled = false;
		document.auBuilderForm.monogramText3.disabled = false;
	}
	if ( val != 'Monogram' ){
		document.auBuilderForm.monogramText1.value = '';
		document.auBuilderForm.monogramText2.value = '';
		document.auBuilderForm.monogramText3.value = '';
		document.auBuilderForm.monogramText1.disabled = true;
		document.auBuilderForm.monogramText2.disabled = true;
		document.auBuilderForm.monogramText3.disabled = true;
	}
	
	if ( val == 'none') {
		document.auBuilderForm.titleColor[5].disabled = false;
		document.auBuilderForm.titleColor[5].checked = true;
	}

	setBackgroundColors(change,val,'CoverTitleTD');
}

//*****************************************************************************************************************************************
// This function is used to check that the Title Color selected is valid
//*****************************************************************************************************************************************
function checkTitleColor(val) { //v3.0
	resetValues(7);
	var found_it;
	var change = 1;
	
	found_it = getSelectedValue('coverTitle');
   
	if (found_it == "notSelected"){
		alert("You must first select a Cover Title.");
		document.auBuilderForm.titleColor[0].checked = true;
		change = 0;
	}
	
	setBackgroundColors(change,val,'TitleColorTD');
}

//*****************************************************************************************************************************************
// This function is used to check that the Studio Imprint selected is valid
//*****************************************************************************************************************************************
function checkStudioImprint(val) { //v3.0
	resetValues(8);
	var found_it;
	var change = 1;

	found_it = getSelectedValue('titleColor');
   
	if (found_it == 'notSelected' ){
		alert('You must first select a Title Color.');
		document.auBuilderForm.studioImprint[0].checked = true;
		change = 0;
	}
	if ( val == 'Cus' ){
		document.auBuilderForm.customImprint1.disabled = false;
		document.auBuilderForm.customImprint2.disabled = false;
		document.auBuilderForm.customImprint3.disabled = false;
	}
	if ( val == 'Die' ){
		document.auBuilderForm.customImprint1.value = '';
		document.auBuilderForm.customImprint2.value = '';
		document.auBuilderForm.customImprint3.value = '';
		document.auBuilderForm.customImprint1.disabled = true;
		document.auBuilderForm.customImprint2.disabled = true;
		document.auBuilderForm.customImprint3.disabled = true;
	}
	if ( val == 'none' ){
		document.auBuilderForm.customImprint1.value = '';
		document.auBuilderForm.customImprint2.value = '';
		document.auBuilderForm.customImprint3.value = '';
		document.auBuilderForm.customImprint1.disabled = true;
		document.auBuilderForm.customImprint2.disabled = true;
		document.auBuilderForm.customImprint3.disabled = true;
		
		document.auBuilderForm.studioImprintText[3].disabled = false;
		document.auBuilderForm.studioImprintColor[5].disabled = false;		
		document.auBuilderForm.studioImprintText[3].checked = true;
		document.auBuilderForm.studioImprintColor[5].checked = true;
		
	}
	setBackgroundColors(change,val,'StudioImprintTD');
}

//*****************************************************************************************************************************************
// This function is used to check that the Studio Imprint Text selected is valid
//*****************************************************************************************************************************************
function checkStudioImprintText(val) { //v3.0
	resetValues(9);
	var found_it;
	var change = 1;

	found_it = getSelectedValue('studioImprint');

	if (found_it == "notSelected"){
		alert("You must first select a Studio Imprint.");
		document.auBuilderForm.studioImprintText[0].checked = true;
		change = 0;
	}
	
	customImprint1 = document.auBuilderForm.customImprint1.value;
	customImprint2 = document.auBuilderForm.customImprint2.value;
	customImprint3 = document.auBuilderForm.customImprint3.value;
	
	if (found_it == "Cus" && customImprint1 == "" && customImprint2 == "" && customImprint3 == ""){
		alert("Please fill in the Custom Studio Imprint above before selecting a text.");
		document.auBuilderForm.studioImprintText[0].checked = true;
		change = 0;
	}

	if ( val == "none" ){
		document.auBuilderForm.nameImprintText[3].checked = true;
		document.auBuilderForm.nameImprintColor[5].checked = true;
	}
	
	setBackgroundColors(change,val,'StudioImprintTextTD');
}

//*****************************************************************************************************************************************
// This function is used to check that the Studio Imprint Color selected is valid
//*****************************************************************************************************************************************
function checkStudioImprintColor(val) { //v3.0
	resetValues(10);
	var found_it;
	var change = 1;

	found_it = getSelectedValue('studioImprintText');

	if (found_it == "notSelected"){
		alert("You must first select a Studio Imprint Text.");
		document.auBuilderForm.studioImprintColor[0].checked = true;
		change = 0;
	}
	
	setBackgroundColors(change,val,'StudioImprintColorTD');
}

//*****************************************************************************************************************************************
// This function is used to check that the Name Imprint selected is valid
//*****************************************************************************************************************************************
function checkNameImprint(val) { //v3.0
	resetValues(11);
	var found_it;
	var change = 1;

	found_it = getSelectedValue('studioImprintColor');

	if (found_it == "notSelected"){
		alert("You must first select a Studio Imprint Color.");
		document.auBuilderForm.nameImprint[0].checked = true;
		change = 0;
	}
	if ( val == "Cus" ){
		document.auBuilderForm.nameDate1.disabled = false;
		document.auBuilderForm.nameDate2.disabled = false;
		document.auBuilderForm.nameDate3.disabled = false;
	}
	if ( val == "none" ){
		document.auBuilderForm.nameDate1.value = "";
		document.auBuilderForm.nameDate2.value = "";
		document.auBuilderForm.nameDate3.value = "";
		document.auBuilderForm.nameDate1.disabled = true;
		document.auBuilderForm.nameDate2.disabled = true;
		document.auBuilderForm.nameDate3.disabled = true;
	}
	
	setBackgroundColors(change,val,'NameImprintTD');
}

//*****************************************************************************************************************************************
// This function is used to check that the Name Imprint Text selected is valid
//*****************************************************************************************************************************************
function checkNameImprintText(val) { //v3.0
	resetValues(12);
	var found_it;
	var change = 1;

	found_it = getSelectedValue('nameImprint');

	nameDate1 = document.auBuilderForm.nameDate1.value;
	nameDate2 = document.auBuilderForm.nameDate2.value;
	nameDate3 = document.auBuilderForm.nameDate3.value;

	if (found_it == "notSelected"){
		alert("You must first select a Name & Date Imprint.");
		document.auBuilderForm.nameImprintText[0].checked = true;
		change = 0;
	}
	if (found_it == "Cus" && (nameDate1 == "" && nameDate2 == "" && nameDate3 == "")){
		alert("Please Fill out at least one line for your Name and Date Imprint before selecting a text.");
		document.auBuilderForm.nameImprintText[0].checked = true;
		change = 0;
	}
	setBackgroundColors(change,val,'NameImprintTextTD');
}


//*****************************************************************************************************************************************
// This function is used to check that the Name Imprint Color selected is valid
//*****************************************************************************************************************************************
function checkNameImprintColor(val) { //v3.0
	resetValues(13);
	var found_it;
	var change = 1;

	found_it = getSelectedValue('nameImprintText');

	if (found_it == "notSelected"){
		alert("You must first select a Name & Date Imprint Text.");
		document.auBuilderForm.nameImprintColor[0].checked = true;
		change = 0;
	}
	
	setBackgroundColors(change,val,'NameImprintColorTD');
}

//*****************************************************************************************************************************************
// This function is used to check that the Name Imprint Color selected is valid
//*****************************************************************************************************************************************
function checkMonogram(val) { //v3.0
	resetValues(14);
	var found_it;
	var change = 1;

	found_it = getSelectedValue('nameImprintColor');

	if (found_it == "notSelected"){
		alert("You Must First Select a Name Imprint Color.");
		document.auBuilderForm.monogram[0].checked = true;
		change = 0;
	}
	if ( val == "Cus" ){
		document.auBuilderForm.monogramText.disabled = false;
	}
	if ( val == "none" ){
		document.auBuilderForm.monogramText.value = "";
		document.auBuilderForm.monogramText.disabled = true;
	}

	setBackgroundColors(change,val,'MonogramTD');
}

//*****************************************************************************************************************************************
// This function checks to make sure that all selections have been made before submitting
//*****************************************************************************************************************************************
function checkComplete(){
	found_it = getSelectedValue('nameImprintColor');
	
	if ( found_it != "notSelected" ){
		document.auBuilderForm.submit();
	}
	else{
		alert("Please Finish all necessary selections before submitting album to basket.");
	}

}
