var old_index = 0;
var old_subindex = 0;
var timeout_id;
var timeout_id2;
var imgarr = document.getElementsByTagName('img');

function galleryWin(pID) {
	var win = window.open('gallery.php?photoCategoryID=' + pID + '', 'newwin', 'width=720,height=636');
}

function checkForm(obj)
{
	if(obj.name.value == "") {
		alert("Please enter a name.");
		obj.name.focus();
		return false;
	}
	if(obj.email.value == "" || obj.email.value.indexOf("@") == -1 || obj.email.value.indexOf(".") == -1 || obj.email.value.indexOf(" ") != -1) {
		alert("Please enter a valid email address.");
		obj.email.focus();
		return false;
	}
	if(obj.comments.value == "") {
		alert("Please enter questions, comments or ordering information.");
		obj.message.focus();
		return false;
	}
	return true;
}

function clear_timeouts() {
	if(document.getElementById) {
		if(timeout_id != null)
			self.clearTimeout(timeout_id);
	}
}

function clear_timeouts2() {
	if(document.getElementById) {
		if(timeout_id2 != null)
			self.clearTimeout(timeout_id2);
	}
}

// DOM Image Rollover v3 (hover) by Chris Poole
function domRollover() {
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	
	if (!document.getElementById || operaVersion < 7)
		return;

	var imgPreload = new Array();
	var imgSrc = new Array();
	var imgClass = new Array();
	var imgId = new Array();
	
	for (i = 0; i < imgarr.length; i++) {
		if (imgarr[i].className.indexOf('domroll') != -1) {
			imgSrc[i] = imgarr[i].getAttribute('src');
			imgClass[i] = imgarr[i].className;
			imgPreload[i] = new Image();
			imgId[i] = imgarr[i].getAttribute('id');
			
			if (imgClass[i].match(/domroll (\S+)/)) {
				imgPreload[i].src = imgClass[i].match(/domroll (\S+)/)[1];
			}
			
			imgarr[i].setAttribute('xsrc', imgSrc[i]);
			
			imgarr[i].onmouseover = function() {
				this.setAttribute('src',this.className.match(/domroll (\S+)/)[1]);
			}
			
			imgarr[i].onmouseout = function() {
				this.setAttribute('src',this.getAttribute('xsrc'));
			}
			
			/*
			document.getElementById('menu1').onmouseover = function() {
				document.getElementById('img1').setAttribute('src',document.getElementById('img1').className.match(/domroll (\S+)/)[1]);
			}
			
			document.getElementById('menu1').onmouseout = function() {
				document.getElementById('img1').setAttribute('src',document.getElementById('img1').getAttribute('xsrc'));
			}
			*/
		}
	}
}

function domRolloverSubOn(index) {
	document.getElementById('img' + index).setAttribute('src',document.getElementById('img' + index).className.match(/domroll (\S+)/)[1]); 
}

function domRolloverSubOff(index) {
	document.getElementById('img' + index).setAttribute('src',document.getElementById('img' + index).getAttribute('xsrc'));
}

function getWidth() {
	if(document.all)
		return document.body.scrollWidth;
	else
		return window.innerWidth;
}

function popupon091908(index) {
	if(document.getElementById) {
		if(timeout_id != null)
			self.clearTimeout(timeout_id);
		
		if(old_index != 0) {
			document.getElementById(old_index).style.display = "none";
			document.getElementById(old_index).style.visibility = "hidden";
		}
		
		if (window.XMLHttpRequest) { // IE 7, Mozilla, Safari, Opera 9
			if(document.all) { // IE 7
				document.getElementById('menu' + index).style.top = 58 + 'px';
				document.getElementById('menu' + index).style.left = document.getElementById('xinner').offsetLeft + document.getElementById('mainmenu').offsetLeft + document.getElementById('nav' + index).offsetLeft + 1 + 'px';
			}
			else { // Mozilla, Safari, Opera 9
				document.getElementById('menu' + index).style.top = 58 + 'px';
				document.getElementById('menu' + index).style.left = document.getElementById('nav' + index).offsetLeft + 1 + 'px';
			}
		}
		else { // IE 6, older browsers
				document.getElementById('menu' + index).style.top = 58 + 'px';
				document.getElementById('menu' + index).style.left = document.getElementById('xinner').offsetLeft + document.getElementById('mainmenu').offsetLeft + document.getElementById('nav' + index).offsetLeft + 1 + 'px';
		}
		
		document.getElementById('menu' + index).style.display = "inline";
		document.getElementById('menu' + index).style.visibility = "visible";
		old_index = 'menu' + index;
	}
}

function popupon(index) {
	if(document.getElementById) {
		if(timeout_id != null)
			self.clearTimeout(timeout_id);
		
		if(old_index != 0) {
			document.getElementById(old_index).style.display = "none";
			document.getElementById(old_index).style.visibility = "hidden";
		}
		
		if (window.XMLHttpRequest) { // IE 7, Mozilla, Safari, Opera 9
			if(document.all) { // IE 7
				document.getElementById('menu' + index).style.top = 97 + 'px';
				document.getElementById('menu' + index).style.left = document.getElementById('xinner').offsetLeft + document.getElementById('mainmenu').offsetLeft + document.getElementById('nav' + index).offsetLeft + 1 + 'px';
			}
			else { // Mozilla, Safari, Opera 9
				document.getElementById('menu' + index).style.top = 97 + 'px';
				document.getElementById('menu' + index).style.left = document.getElementById('nav' + index).offsetLeft + 1 + 'px';
			}
		}
		else { // IE 6, older browsers
				document.getElementById('menu' + index).style.top = 97 + 'px';
				document.getElementById('menu' + index).style.left = document.getElementById('xinner').offsetLeft + document.getElementById('mainmenu').offsetLeft + document.getElementById('nav' + index).offsetLeft + 1 + 'px';
		}
		
		document.getElementById('menu' + index).style.display = "inline";
		document.getElementById('menu' + index).style.visibility = "visible";
		old_index = 'menu' + index;
	}
}

function popupon2(index, subindex, top, left) {
	if(document.getElementById) {
		if(timeout_id != null)
			self.clearTimeout(timeout_id);
			
		if(timeout_id2 != null)
			self.clearTimeout(timeout_id2);

		if(old_subindex != 0)
			document.getElementById(old_subindex).style.display = "none";
		
		document.getElementById(subindex).style.top = top;
		document.getElementById(subindex).style.left = document.getElementById(index).offsetLeft + document.getElementById(index).offsetWidth - 1;
		document.getElementById(subindex).style.display = "inline";
		old_index = index;
		old_subindex = subindex;
	}
}

function popupoff() {
	if(document.getElementById) {
		if(old_index != 0)
			timeout_id = setTimeout("document.getElementById(old_index).style.display = 'none';", 25);
	}
}

function popupoff2() {
	if(document.getElementById) {
		if(old_subindex != 0)
			timeout_id2 = setTimeout("document.getElementById(old_subindex).style.display = 'none';", 25);
	}
}

function itemAttributeSwitch(objdiv, object) {	
	if(document.getElementById('onecoloropt') && document.getElementById('twocoloropt1') && document.getElementById('twocoloropt2')) {
		document.getElementById('onecoloropt').style.display = 'none';
		document.getElementById('twocoloropt1').style.display = 'none';
		document.getElementById('twocoloropt2').style.display = 'none';
	}
	
	//hide all item attributes for this subcategory, and clear all checkboxes
	for(i = 0; i < objdiv.childNodes.length; i++) {
		if(objdiv.childNodes[i].nodeName == "DIV") {
			for(j = 0; j < objdiv.childNodes[i].childNodes.length; j++) {
				if(objdiv.childNodes[i].childNodes[j].nodeName == "INPUT") {
					objdiv.childNodes[i].childNodes[j].checked = false;
				}
			}

			objdiv.childNodes[i].style.display = 'none';
		}
	}

	itemID = object.options[object.selectedIndex].value;
	
	//show only item attributes for this item
    if(document.getElementById('itemAttributeDiv' + itemID)) {
		document.getElementById('itemAttributeDiv' + itemID).style.display = 'block';
	}
	
	//show two color options
	if(itemID == 84 || itemID == 85 || itemID == 98 || itemID == 99) {
		document.getElementById('twocoloropt1').style.display = 'block';
		document.getElementById('twocoloropt2').style.display = 'block';
	}
	//show one color option
	else if(itemID == 86 || itemID == 87 || itemID == 88 || itemID == 96 || itemID == 97 || itemID == 100) {
		document.getElementById('onecoloropt').style.display = 'block';
	}
	
	//reset color options when user changes item
	resetColorOpts();
}

function checkOrderForm(form) {
	if(form.item.value == "") {
		alert("Please select a size/style.");
		return false;
	}
	
	if(form.color1 && form.color1.value == "") {
		alert("Please select a Top Color.");
		return false;
	}
	
	if(form.color2 && form.color2.value == "") {
		alert("Please select a Base Color.");
		return false;
	}
	
	if(form.color3 && form.color3.value == "") {
		alert("Please select a Drawer Fronts Color.");
		return false;
	}
	
	if(form.color4 && form.color4.value == "" && document.getElementById('onecoloropt').style.display == 'none') {
		alert("Please select a Frame Color.");
		return false;
	}
		
	if(form.color5 && form.color5.value == "" && document.getElementById('onecoloropt').style.display == 'none') {
		alert("Please select a Seat Top Color.");
		return false;
	}
	
	if(form.color6 && form.color6.value == "" && document.getElementById('twocoloropt1').style.display == 'none') {
		alert("Please select a Color.");
		return false;
	}
	
	if(form.color7 && form.color7.value == "") {
		alert("Please select an Outside Color.");
		return false;
	}
	
	if(form.color8 && form.color8.value == "") {
		alert("Please select a Top/Background Color.");
		return false;
	}
	
	if(form.color9 && form.color9.value == "") {
		alert("Please select a Top/Drawer Fronts Color.");
		return false;
	}
}

function resetOpts() {
	if(document.getElementById('item')) {
		document.getElementById('item').options[0].selected = true;

		resetColorOpts();
	}
}

function resetColorOpts() {
	for(i = 0; i < 50; i++) {
		if(document.getElementById('color' + i))
			document.getElementById('color' + i).options[0].selected = true;
	}
}