/* 
	Chained Select Menu validator ...
	
	This file should be in your root site directory. The following lines should be part of every page that require
	this script:
	
	<script language="javascript" src="/validate.js"></script>
	
	<body onload="initListGroup('shirts', document.form1.opt0, document.form1.opt1, document.form1.opt2, checkColors);">
	
	<form name="form1" onsubmit="return validate();" action="https://www.superiorsilkscreen.com/cgi-bin/shopper.exe">
	
	Enjoy!
*/

var shirtColor = null, fontColor = null;

function checkColors(list, order, instance, value) {
	if (list.name == "opt0") {
		shirtColor = null;
		fontColor = null;
	} else if (list.name == "opt1") {
		var shirtObj = document.form1.opt1;
		var shirtIndex = shirtObj.selectedIndex;
		shirtColor = shirtObj[shirtIndex].text.toLowerCase();
		fontColor = null;
	}
	else if (list.name == "opt2") {
		var fontObj = document.form1.opt2;
		var fontIndex = fontObj.selectedIndex;
		fontColor = fontObj[fontIndex].text.toLowerCase();
	}
}

function validate() {
	if (shirtColor == null || fontColor == null) {
		
		/* This alert message will appear if shirt color, font color and/or both are not selected.
		   Change the message content to your preference.
		*/
		alert("Please select your style, shirt color and font color.");
		
		return false;
	}
	if (shirtColor == fontColor) {
		
		/* This alert message will appear when the client selects the same color for shirt and font.
		   The variable 'fontColor' is a color that the client currently has selected. Same goes for 'shirtColor'.
		   These variables DO NOT have to be part of the message and can be omitted.
		*/
		alert("You chose " + fontColor + 
			  " font on a " + shirtColor + 
			  " shirt - please change your selection.");
		
		return false;
	}
	return true;
}
