function $(id) { return document.getElementById(id); }
// Swaps out an image based on the values of pull-down menues
// Defaults to Black ink on Gold Foil, Style AP1
function swapStyleFoilColorImage() {
	var sealStyle = ($('style').value != '') ? $('style').value : 'AP1';
	var sealMaterial = ($('material').value != '') ? $('material').value : 'gold';
	var sealInk = ($('ink').value != '') ? $('ink').value : 'black';

	switch (sealStyle) {
		case '1594':
		sealStyle = 'AP1';
		break;
		case '1595':
		sealStyle = 'AP2';
		break;
		case '1596':
		sealStyle = 'AP3';
		break;
		case '1597':
		sealStyle = 'AP4';		
		break;
		case '1598':
		sealStyle = 'AP5';
		break;
		case '1599':
		sealStyle = 'AP6';
		break;
		case '1600':
		sealStyle = 'AP7';
		break;
		case '1601':
		sealStyle = 'AP8';	
		break;
		case '1602':
		sealStyle = 'AP9';
		break;
		case '1603':
		sealStyle = 'AP10';
		break;
		case '1604':
		sealStyle = 'AP11';
		break;
		case '1605':
		sealStyle = 'AP12';		
	}
	
	switch (sealMaterial) {
		case '428':
		sealMaterial = 'gold';
		break;
		case '429':
		sealMaterial = 'silver';		
	}	

	switch (sealInk) {
		case '1':
		sealInk = 'black';
		break;
		case '497':
		sealInk = 'blue';
		break;
		case '529':
		sealInk = 'green';
		break;
		case '490':
		sealInk = 'red';			
	}	
	
	swapImage = $('swap_image');
	swapImage.src = "/images/seal_images/" + sealMaterial + "/" + sealInk +"/" + sealStyle + ".gif";
}

// Swaps out an image based on the values of pull-down menues
// Defaults to Black ink on Gold Foil, Style AP1
function mouseOverSwapStyleFoilColorImage(sealStyle) {
	var sealMaterial = ($('material').value) ? $('material').value : 'gold';
	var sealInk = ($('ink').value) ? $('ink').value : 'black';
	
	switch (sealStyle) {
		case '1594':
		sealStyle = 'AP1';
		break;
		case '1595':
		sealStyle = 'AP2';
		break;
		case '1596':
		sealStyle = 'AP3';
		break;
		case '1597':
		sealStyle = 'AP4';		
		break;
		case '1598':
		sealStyle = 'AP5';
		break;
		case '1599':
		sealStyle = 'AP6';
		break;
		case '1600':
		sealStyle = 'AP7';
		break;
		case '1601':
		sealStyle = 'AP8';	
		break;
		case '1602':
		sealStyle = 'AP9';
		break;
		case '1603':
		sealStyle = 'AP10';
		break;
		case '1604':
		sealStyle = 'AP11';
		break;
		case '1605':
		sealStyle = 'AP12';			
	}
	
	switch (sealMaterial) {
		case '428':
		sealMaterial = 'gold';
		break;
		case '429':
		sealMaterial = 'silver';		
	}	

	switch (sealInk) {
		case '1':
		sealInk = 'black';
		break;
		case '497':
		sealInk = 'blue';
		break;
		case '529':
		sealInk = 'green';
		break;
		case '490':
		sealInk = 'red';			
	}	
	
	swapImage = $('swap_image');
	swapImage.src = "../images/seal_images/" + sealMaterial + "/" + sealInk +"/" + sealStyle + ".gif";
}
		
// Some seal style do not have the option of
//	the addtional text. Hide the input when not applicable
function displayWordingField(styleID) {
	var wordingRowStyle = $("wording_row");
	var wordingText = $("wording");
	switch (styleID) {
		case '1595':
		case '1599':
		case '1600':
		case '1601':
		case '1602':
		case '1603':
		case '1604':
		case '1605':
			$('wording').value = '';
			$('wording').disabled = true;
			$('wording').className = 'disabled';
			$("wording_label").style.color = 'gray';
			//wordingRowStyle.style.visibility = "hidden";
			//wordingText.value = '';
			//wordingText.disabled = true;
			break;
		case '1594':
		case '1596':
		case '1596':
		case '1597':
		case '1598':
			$('wording').disabled = false;
			$('wording').className = 'mx';	
			$("wording_label").style.color = 'black';
			//wordingRowStyle.style.visibility = "visible";
			//wordingText.disabled = false;
			break;
	}
}		
		
// This is for when the user clicks on a seal style, the menu will reflect that clicked choice
// It also runs the function to show or hide the optional wording field. 
function setStyleMenu(apStyle) {
	$('style').value = apStyle;
	displayWordingField(apStyle);
}		

// Checking the required form fields for values
function checkFormFields() {	
	displayWordingField($('style').value)
	// Make sure the error string is empty
	var i = 0;
	var error_string = '';
	
	$("company_name").className = 'mx';
	$("anniversary_number").className = 'mx';
	$("year_from").className = 'mx';
	$("year_to").className = 'mx';
	
	$("quantity_label").style.color = 'black';
	$("company_label").style.color = 'black';
	$("anniversary_label").style.color = 'black';
	$("year_label").style.color = 'black';
	//$("wording_label").style.color = 'black';
		
	// Make sure that the quantity is a number
	if ($('quantity').value == '') {
		i++;
		error_string += i + ") Please select a Quantity\n";
		$("quantity_label").style.color = 'red';
	}	
	
	if ($('company_name').value == '') {
		i++;
		error_string += i + ") Please enter a Company Name.\n";
		$("company_label").style.color = 'red';	
		$("company_name").className = 'notice_o';
	}	

	var anniversary = $('anniversary_number').value.replace(/([^0-9])/g, "");
	if (anniversary.length == 0) {
		i++;
		error_string += i + ") Please enter a numeric Anniversary Number.\n";
		$("anniversary_label").style.color = 'red';	
		$("anniversary_number").className = 'notice_o';
	}
	
	var yearFrom = $('year_from').value.replace(/([^0-9])/g, "");
	var yearTo = $('year_to').value.replace(/([^0-9])/g, "");
	if (yearFrom.length != 4 || yearTo.length != 4) {
		i++;
		error_string += i + ") Please enter a 4 digit year for each \"Year Founded\" fields\n";
		$("year_label").style.color = 'red';	
		$("year_from").className = 'notice_o';
		$("year_to").className = 'notice_o';
	}			

	// If there were any errors, make an alert box and prevent submission
	if (error_string != "") {
		var fieldCount;
		if (i == 1) { fieldCount = "field"; }
		else { fieldCount = i + " fields"; }
		alert(error_string + "\nThe error/missing required " + fieldCount + " will be marked"); 
		return false;
	}
}

function makeCaps(fieldText,fieldID) {
	fieldHandle = $(fieldID);
	fieldHandle.value = fieldText.toUpperCase();
}
