// JavaScript Document

//*****************************************************************************************************************************************
// This function checks to make sure that all sections are enabled or disabled correctly
//*****************************************************************************************************************************************
function setFunctionality(){
// check below to make sure that cover cameos are still available

	found_it = getSelectedValue('cover');
	found_it2 = getSelectedValue('coverSize');
	found_it3 = getSelectedValue('coverColor');
	found_it4 = getSelectedValue('proofBookInserts');
	
//	if(found_it4 != "pbiBlack" && found_it4 != "pbiWhite"){
	
//		document.auBuilderForm.qty45.disabled = true;
//		document.auBuilderForm.qty452.disabled = true;
		//		document.auBuilderForm.qty55.disabled = true;
		//		document.auBuilderForm.qty552.disabled = true;
		//		document.auBuilderForm.qty57.disabled = true;
		//		document.auBuilderForm.qty46.disabled = true;
		//		document.auBuilderForm.qty462.disabled = true;
		//		document.auBuilderForm.qty463.disabled = true;
			
//				document.auBuilderForm.qty45.value = "";
		//		document.auBuilderForm.qty452.value = "";
		//		document.auBuilderForm.qty55.value = "";
		//		document.auBuilderForm.qty552.value = "";
		//		document.auBuilderForm.qty57.value = "";
		//		document.auBuilderForm.qty46.value = "";
		//		document.auBuilderForm.qty462.value = "";
		//		document.auBuilderForm.qty463.value = "";
	
//			}
	
	//		if(found_it4 == "pbiBlack" || found_it4 == "pbiWhite"){
	
		//		document.auBuilderForm.qty45.disabled = false;
		//		document.auBuilderForm.qty452.disabled = false;
	//			document.auBuilderForm.qty55.disabled = false;
	//			document.auBuilderForm.qty552.disabled = false;
	//			document.auBuilderForm.qty57.disabled = false;
	//			document.auBuilderForm.qty46.disabled = false;
		//		document.auBuilderForm.qty462.disabled = false;
		//		document.auBuilderForm.qty463.disabled = false;
	
//			}

	if (found_it == 'Dp' || found_it == 'Pb' || found_it == 'Pbcb'){
		enableSection('coverColor',7);
	}
	if ( getSelectedValue('cover') == 'E' || getSelectedValue('cover') == 'Wd'  ){
		disableSection('coverColor',7);
	}
	
	if ( found_it2 == '463wC' ){

		document.auBuilderForm.coverColor[1].disabled = true;
		document.auBuilderForm.coverColor[2].disabled = true;
		document.auBuilderForm.coverColor[3].disabled = true;
		document.auBuilderForm.coverColor[7].disabled = true;
		document.auBuilderForm.coverColor[4].disabled = false;
		document.auBuilderForm.coverColor[5].disabled = false;
		document.auBuilderForm.coverColor[6].disabled = false;

	}else{
	
		document.auBuilderForm.coverColor[1].disabled = false;
		document.auBuilderForm.coverColor[2].disabled = false;
		document.auBuilderForm.coverColor[3].disabled = false;
		document.auBuilderForm.coverColor[7].disabled = false;
		document.auBuilderForm.coverColor[4].disabled = true;
		document.auBuilderForm.coverColor[5].disabled = true;
		document.auBuilderForm.coverColor[6].disabled = true;
	
	}
	
	
	found_it4 = getSelectedValue('cover');

	if ( found_it4 == 'Pb' || found_it4 == 'Pbcb' || found_it4 == 'Dp'){
		enableSection('coverTitle',35);
		enableSection('studioImprint',4);
		enableSection('nameImprint',2);
	}
	if ( found_it4 != 'Pb' &&  found_it4 != 'Pbcb'  &&  found_it4 != 'Dp'  ){
		disableSection('coverTitle',35);
		if (found_it != 'E' && found_it != 'Wd' && found_it != 'Dp'){



			disableSection('studioImprint',4);
		}
		disableSection('nameImprint',2);
	}

	if (  found_it3 == "We" && (found_it2 == '463' || found_it2 == '552' || found_it2 == '452' || found_it2 == '462' || found_it2 == '572') ){
		disableSection('coverTitle',36);
		}
		
	if (  found_it3 == "Wewc" && (found_it2 == '463wC') ){
		disableSection('coverTitle',36);
		}

// check below to make sure that cover title attributes are still available

	found_it = getSelectedValue('coverTitle');

	if ( found_it != 'none' && found_it != 'na' ){
		enableSection('titleColor',5);
	}
	if ( found_it == 'none' || found_it == 'na'  ){
		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' && found_it != 'na'){
		enableSection('studioImprintColor',4);
		disableSection('studioImprintText',3);
	}
	if ( found_it != 'none' && found_it != 'Die'){
		enableSection('studioImprintText',3);
		enableSection('studioImprintColor',4);
	}
	if ( found_it == 'none'|| found_it == 'na'){
		disableSection('studioImprintText',3);
		disableSection('studioImprintColor',4);
	}



// check below to make sure that name and date imprint attributes are still available

	found_it = getSelectedValue('nameImprint');

	if ( found_it != 'none'  && found_it != 'na' ){
		disableSection('nameImprintText',0);
		disableSection('nameImprintText',1);
		disableSection('nameImprintText',2);
		document.auBuilderForm.nameImprintText[3].checked = true;
		enableSection('nameImprintColor',5);
	}
	if ( found_it == 'none' || found_it == 'na' ){
		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 < 13 ){
			document.all.NameImprintColorTD.style.backgroundColor='#E8E5EC';
	}
	if ( val < 12 ){
			document.all.NameImprintTextTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.nameImprintColor[0].checked = true;
			document.all.NameImprintColorTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 11 ){
			document.all.NameImprintTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.nameImprintText[0].checked = true;
			document.all.NameImprintTextTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 10 ){
			document.all.StudioImprintColorTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.nameImprint[0].checked = true;
			document.all.NameImprintTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 9 ){
			document.all.StudioImprintTextTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.studioImprintColor[0].checked = true;
			document.all.StudioImprintColorTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 8 ){
			document.all.StudioImprintTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.studioImprintText[0].checked = true;
			document.all.StudioImprintTextTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 7 ){
			document.all.TitleColorTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.studioImprint[0].checked = true;
			document.all.StudioImprintTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 6 ){
			document.all.CoverTitleTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.titleColor[0].checked = true;
			document.all.TitleColorTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 5 ){
			document.all.proofBookInsertsTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.proofBookInserts[0].checked = true;
			document.all.proofBookInsertsTD.style.backgroundColor='#FFFFFF';		
	}
	if(val < 4){
			document.all.CoverColorTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.coverTitle[0].checked = true;
			document.all.CoverTitleTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 3 ){
			document.all.CoverSizeTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.coverColor[0].checked = true;
			document.all.CoverColorTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 2 ){
			document.all.CoverTD.style.backgroundColor='#E8E5EC';
			document.auBuilderForm.coverSize[0].checked = true;
			document.all.CoverSizeTD.style.backgroundColor='#FFFFFF';
	}
	if ( val < 1 ){ // Nothing has been selected on 
			document.all.CoverTD.style.backgroundColor='#FFFFFF';
	}

	setFunctionality();

}

//*****************************************************************************************************************************************
// This function is used to check that the Cover Color selected is valid
//*****************************************************************************************************************************************
function checkCoverSize(val) { //v3.0
	resetValues(2);
	var found_it;
	var change = 1;
   
    found_it = getSelectedValue('cover');

	if ( found_it == "Pb" && (val != '452' && val != '463' && val != '552' && val != '572' && val != '463wC' && val != '462') ){
	
		alert("The size selected is not available for regular Proof Books.");
		document.auBuilderForm.coverSize[0].checked = true;
		change = 0;
	
	}
	if ( found_it == "Pbcb" && (val != '55' && val != '46' && val != '45') ){
		alert("The size selected is not available for regular Comb binded Proof Books.");
		document.auBuilderForm.coverSize[0].checked = true;
		change = 0;
	}
	if ( found_it == "Wd" && (val != '462' ) ){
		alert("White Designer Proof Books are only available in 4x6 (2-up).");
		document.auBuilderForm.coverSize[0].checked = true;
		change = 0;
	}
	if ( found_it == "E" && (val != '355' && val != '452' && val != '462' && val != '552' && val != '572' && val != '57') ){

		alert("The size you selected is not available for Euro Proof Books.");
		document.auBuilderForm.coverSize[0].checked = true;
		change = 0;
	}
	if ( found_it == "Dp" && (val != '8511' && val != '1013' && val != '1310')) {
		alert("The size you selected is not available for Digital Proof Books.");
		document.auBuilderForm.coverSize[0].checked = true;
		change = 0;
	}
	
	setBackgroundColors(change,val,'CoverSizeTD');
}

//*****************************************************************************************************************************************
// This function is used to check that the Cover Color selected is valid
//*****************************************************************************************************************************************
function checkCoverColor(val) { //v3.0
	resetValues(3);
	var found_it;
	var found_it2;
	var change = 1;
    
	found_it = getSelectedValue('cover');
    found_it2 = getSelectedValue('coverSize');

	if (found_it2 == "notSelected"){
		alert("You must first select a Cover Size.");
		document.auBuilderForm.coverColor[0].checked = true;
		change = 0;
	}
	if ((found_it == "Pb" ) && (found_it2 != '463' && found_it2 != '463wC') && (val == 'Bbc' || val == 'Wwc') ){
		alert("Black/black cameo or White/white cameo are only available for 4x6(3-up) Proof Books.");
		document.auBuilderForm.coverColor[0].checked = true;
		change = 0;
	}
	if ((found_it == "Pbcb" ) && (val != 'B' && val != 'M') ){
		alert("Comb Binding Proof Books are only available in Black and Medallion.");
		document.auBuilderForm.coverColor[0].checked = true;
		change = 0;
	}
	if ((found_it == "E" ) && (val != 'W') ){
		alert("Euro Proof Books are only available in white.");
		document.auBuilderForm.coverColor[0].checked = true;
		change = 0;
	}
	if ((found_it == "Dp" ) && (val != 'M') ){
		alert("Digital Proof Albums are only available in Medallion.");
		document.auBuilderForm.coverColor[0].checked = true;
		change = 0;
	}	
	setBackgroundColors(change,val,'CoverColorTD');
}
//*****************************************************************************************************************************************
// This function is used to check that the Cover Title selected is valid
//*****************************************************************************************************************************************

function checkProofBookInserts(val){
    // had to take out resetValues(4); right here... Was making the code function abnormal...
	var found_it;
	var change = 1;
	setFunctionality();
	
	found_it = getSelectedValue('coverColor');
	
	if(found_it == "notSelected"){
		document.all.proofBookInsertsTD.style.backgroundColor='#E8E5EC';
		alert("You must first select a Cover Color.");
		document.auBuilderForm.proofBookInserts[0].checked = true;
		document.all.proofBookInsertsTD.style.backgroundColor='#FFFFFF';
	}
	if(found_it != "notSelected"){
		if(val == "pbiBlack" || val == "pbiWhite"){
			document.all.proofBookInsertsTD.style.backgroundColor='#E8E5EC';
			document.all.CoverTitleTD.style.backgroundColor='#FFFFFF';
			document.auBuilderForm.coverTitle[0].checked = true;
		}
		if(val == "none"){
			document.all.proofBookInsertsTD.style.backgroundColor='#E8E5EC';
			document.all.CoverTitleTD.style.backgroundColor='#FFFFFF';
			document.auBuilderForm.coverTitle[0].checked = true;
		}
	}

}

//*****************************************************************************************************************************************
// This function is used to check that the Cover Title selected is valid
//*****************************************************************************************************************************************
function checkCoverTitle(val) { //v3.0
	resetValues(5);
	var found_it;
	var change = 1;

	found_it = getSelectedValue('coverColor');
   
   	if (found_it == "notSelected"){
		alert("You must first select a Cover Color.");
		document.auBuilderForm.coverTitle[0].checked = true;
		change = 0;
	}
	if(found_it != "notSelected"){
		document.all.proofBookInsertsTD.style.backgroundColor='#E8E5EC';
	}

	setBackgroundColors(change,val,'CoverTitleTD');
}

//*****************************************************************************************************************************************
// This function is used to check that the Title Color selected is valid
//*****************************************************************************************************************************************
function checkTitleColor(val) { //v3.0
	resetValues(6);
	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(7);
	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;
	}
	setBackgroundColors(change,val,'StudioImprintTD');
}

//*****************************************************************************************************************************************
// This function is used to check that the Studio Imprint Text selected is valid
//*****************************************************************************************************************************************
function checkStudioImprintText(val) { //v3.0
	resetValues(8);
	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;
	}
	
	setBackgroundColors(change,val,'StudioImprintTextTD');
}

//*****************************************************************************************************************************************
// This function is used to check that the Studio Imprint Color selected is valid
//*****************************************************************************************************************************************
function checkStudioImprintColor(val) { //v3.0
	resetValues(9);
	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(10);
	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(11);
	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(12);
	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(13);
	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');

	//qty45 = document.auBuilderForm.qty45.value;
	//qty55 = document.auBuilderForm.qty55.value;
	//qty46 = document.auBuilderForm.qty46.value;
	//qty100 = document.auBuilderForm.qty100.value;
	
	//if ( found_it != "notSelected" || qty45 > 0 || qty55 > 0 || qty46 > 0 || qty100 > 0){
	if ( found_it == "notSelected"){
		alert("Please Finish all necessary selections before submitting album to basket.");
	}
	else{
		document.auBuilderForm.submit();
	}

}
