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

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 or comments.");
		obj.comments.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 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 = document.getElementById('xcontainer').offsetTop + 290 + 'px';
				document.getElementById('menu' + index).style.left = document.getElementById('xinner').offsetLeft + document.getElementById('nav' + index).offsetLeft + 'px';
			}
			else { // Mozilla, Safari, Opera 9
				document.getElementById('menu' + index).style.top = document.getElementById('nav' + index).offsetTop + 16 + 'px';
				document.getElementById('menu' + index).style.left = document.getElementById('nav' + index).offsetLeft + 'px';
			}
		}
		else { // IE 6, older browsers
				document.getElementById('menu' + index).style.top = document.getElementById('xcontainer').offsetTop + 260 + 'px';
				document.getElementById('menu' + index).style.left = document.getElementById('xinner').offsetLeft + document.getElementById('nav' + index).offsetLeft + '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 imageViewer(height,width,imageID) {
	var newURL = window.open('swatchpage.php?imageID=' + imageID,'image','left=80,top=80,width=' + width + ',height=' + height + ',toolbar=0,resizable=0,location=0,status=0,menubar=0');
}