// Subscriber Mail Code

function validEmail(email) {

	invalidChars = " /:,;"

	if (email == "") {
		return false
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) > -1) {
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {
		return false
	}
	if (periodPos+3 > email.length)	{
		return false
	}
	return true
}

// Subscriber Mail Code

function submitIt(subsForm) {
	if (!validEmail(document.subsForm.email.value))
		{
			alert("Invalid email address")
			document.subsForm.email.focus()
			document.subsForm.email.select()
			return false
		}
	
	
	var pref = "";
	var reqfields = new Array();
	
		for(i=0; i < reqfields.length;i++)
			{
				tempfield = "document.subsForm."+pref+reqfields[i]+".value";
				tempid = "document.subsForm."+pref+reqfields[i]+".id";
				tempval = eval(tempfield);
				tempid = eval(tempid);
				
				if(tempval=="")
					{
						alert("Please provide a "+tempid+".");
						return false;
					}
		}

	return true
}

// Tab content switcher on Product pages

function producttabs() {

	var whichtab = arguments[0];
	var tabs = new Array();

	for(var i = 1; i < arguments.length; i++)
		tabs.push(arguments[i]);

	var howmanytab = tabs.length;

	if (document.getElementById(whichtab)) {
		
		for (var i = 0; i < howmanytab; i++) {
			whichone = tabs[i];
			document.getElementById(whichone).className = 'prod_tab_off';
			document.getElementById('prod_tab_' + whichone).style.display='none';
		}
		document.getElementById(whichtab).className = 'prod_tab_on';
		document.getElementById('prod_tab_' + whichtab).style.display='block';
	}
}

// Enables select menus to jump to the URL on selection

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// Product image rollover switcher

function prepareGallery () {
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("imagegallery")) return false;
	var gallery = document.getElementById("imagegallery");
	var links = gallery.getElementsByTagName("a");
	
	for( var i=0; i < links.length; i++ ) {
		links[i].onmouseover = function() {
			return showPic(this);
		}
		links[i].onclick = function() {
			return false;
		}
	}
}

function showPic(whichpic) {
	if (!document.getElementById("placeholder")) return true;
	var source = whichpic.getAttribute("href");
	var placeholder = document.getElementById("placeholder");
	placeholder.setAttribute("src",source);
	return false;
}

window.onload = prepareGallery;

/*
JSTarget function by Roger Johansson, www.456bereastreet.com
*/
var JSTarget = {
	init: function(att,val,warning) {
		if (document.getElementById && document.createElement && document.appendChild) {
			var strAtt = ((typeof att == 'undefined') || (att == null)) ? 'class' : att;
			var strVal = ((typeof val == 'undefined') || (val == null)) ? 'non-html' : val;
			var strWarning = ((typeof warning == 'undefined') || (warning == null)) ? ' (opens in a new window)' : warning;
			var oWarning;
			var arrLinks = document.getElementsByTagName('a');
			var oLink;
			var oRegExp = new RegExp("(^|\\s)" + strVal + "(\\s|$)");
			for (var i = 0; i < arrLinks.length; i++) {
				oLink = arrLinks[i];
				if ((strAtt == 'class') && (oRegExp.test(oLink.className)) || (oRegExp.test(oLink.getAttribute(strAtt)))) {
					oWarning = document.createElement("em");
					oWarning.appendChild(document.createTextNode(strWarning));
					oLink.appendChild(oWarning);
					oLink.onclick = JSTarget.openWin;
				}
			}
			oWarning = null;
		}
	},
	openWin: function(e) {
		var event = (!e) ? window.event : e;
		if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true;
		else {
		    var oWin = window.open(this.getAttribute('href'), '_blank');
			if (oWin) {
				if (oWin.focus) oWin.focus();
				return false;
			}
			oWin = null;
			return true;
		}
	},
	/*
	addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
	*/
	addEvent: function(obj, type, fn) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() {obj["e"+type+fn]( window.event );}
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	}
};
JSTarget.addEvent(window, 'load', function(){JSTarget.init("rel","external","");});