var catoverimg0 = new Image; catoverimg0.src = '/images/m01.gif';
var catoverimg1 = new Image; catoverimg1.src = '/images/m11.gif';
var catimg0 = new Image; catimg0.src = '/images/m0.gif';
var catimg1 = new Image; catimg1.src = '/images/m1.gif';

function catover(e) {
	var img, c;
	img = this.getElementsByTagName('img');
	c = this.className;
	img[0].src = eval('catoverimg' + c.substr(1,1) + '.src');
}

function catout(e) {
	var img, c;
	img = this.getElementsByTagName('img');
	c = this.className;
	img[0].src = eval('catimg' + c.substr(1,1) + '.src');
}

function initcat(cat) {
	if (document.getElementById) {
		var c;
		if (c = document.getElementById(cat)) {
			var a, x;
			a = c.getElementsByTagName('a');
			for (x = 0; x < a.length; x ++) {
				a[x].onmouseover=catover;
				a[x].onmouseout=catout;
			}
		}
	}
}

function gallisthi() {
	this.style.backgroundColor="#eeeeee";
	this.style.borderColor="#000066";
}

function gallistlo() {
	this.style.backgroundColor="#ffffff";
	this.style.borderColor="#ffffff";
}

function gallistclick(e) {
	if (document.all) e = window.event;
	var target = e.target?e.target:e.srcElement;
	if ((target.nodeName != 'A') && (target.nodeName != 'IMG')) {
		window.location="gallery.php?op=g&id=" + this.getAttribute("gallery") + '&' + sid;
	}
}

function initgallist() {
	if (document.getElementById) {
		var gals = document.getElementsByTagName("div");
		var x;
		for (x = 0; x < gals.length; x++) {
			if (gals[x].className == 'gallist') {
				gals[x].onmouseover=gallisthi;
				gals[x].onmouseout=gallistlo;
				gals[x].onclick=gallistclick;
				gals[x].style.cursor="pointer";
			}
		}
	}
}

function galimghi() {
	this.style.borderColor="#000066";
}

function galimglo() {
	this.style.borderColor="#aaaaaa";
}

function giv(img, w, h) {
	window.open("gallery.php?" + sid + "&op=d&id=" + img, 'gimg' + img, "width=" + (Number(w) + 60) + ",height=" + (Number(h) + 100) + ",scrollbars=yes");
	return false;
}

function galimgclick(e) {
	if (document.all) e = window.event;
	var target = e.target?e.target:e.srcElement;
	if ((target.nodeName != 'A') && (target.nodeName != 'IMG')) {
		giv(this.getAttribute('i'), this.getAttribute('w'), this.getAttribute('h'));
	}
}

function initgal() {
	if (document.getElementById) {
		var gals = document.getElementsByTagName("table");
		var x;
		for (x = 0; x < gals.length; x++) {
			if (gals[x].className == 'gallery') {
				var tb = gals[x].getElementsByTagName('tbody');
				var trs = tb[0].getElementsByTagName('tr');
				var y;
				for (y = 0; y < trs.length; y++) {
					var tds = trs[y].getElementsByTagName('td');
					var z;
					for (z = 0; z < tds.length; z++) {
						if (tds[z].getAttribute('i')) {
							tds[z].onmouseover=galimghi;
							tds[z].onmouseout=galimglo;
							tds[z].onclick=galimgclick;
							tds[z].style.cursor="pointer";
						}
					}
				}
			}
		}
	}
}

function catalogclick(e) {
	if (document.all) e = window.event;
	var target = e.target?e.target:e.srcElement;
	if ((target.nodeName != 'A') && (target.nodeName != 'IMG')) {
		window.location="details.php?" + sid + '&id=' + this.getAttribute("p");
	}
}

function initcatalog() {
	if (document.getElementById) {
		var c;
		if (c = document.getElementById('catalog')) {
			var p, x;
			p = c.getElementsByTagName('div');
			for (x = 0; x < p.length; x++) {
				if (p[x].getAttribute('p')) {
					p[x].onmouseover=gallisthi;
					p[x].onmouseout=gallistlo;
					p[x].onclick=catalogclick;
					p[x].style.cursor='pointer';
				}
			}
		}
	}
}

function initfpprod() {
	if (document.getElementById) {
		var p, x;
		p = document.getElementsByTagName('div');
		for (x = 0; x < p.length; x++) {
			if (p[x].className == 'fpprod') {
				p[x].onmouseover=gallisthi;
				p[x].onmouseout=gallistlo;
				p[x].onclick=catalogclick;
				p[x].style.cursor='pointer';
			}
		}
	}
}

function relatedclick(e) {
	if (document.all) e = window.event;
	var target = e.target?e.target:e.srcElement;
	if ((target.nodeName != 'A') && (target.nodeName != 'IMG')) {
		window.location="details.php?id=" + this.getAttribute("p") + '&' + sid;
	}
}

function initrelated() {
	if (document.getElementById) {
		var c;
		if (c = document.getElementById('related')) {
			var p, x;
			p = c.getElementsByTagName('td');
			for (x = 0; x < p.length; x++) {
				if (p[x].getAttribute('p')) {
					p[x].onmouseover=galimghi;
					p[x].onmouseout=galimglo;
					p[x].onclick=relatedclick;
					p[x].style.cursor='pointer';
				}
			}
		}
	}
}

function civ(img, w, h) {
	window.open("details.php?" + sid + "&op=d&id=" + img, 'cimg' + img, "width=" + (Number(w) + 60) + ",height=" + (Number(h) + 60) + ",scrollbars=no");
	return false;
}

function productimgclick(e) {
	if (document.all) e = window.event;
	var target = e.target?e.target:e.srcElement;
	if ((target.nodeName != 'A') && (target.nodeName != 'IMG')) {
		civ(this.getAttribute('p'), this.getAttribute('w'), this.getAttribute('h'));
	}
}

function initproductimg() {
	if (document.getElementById) {
		var d;
		if (d = document.getElementById('productimg')) {
			d.style.cursor="pointer";
			d.onmouseover=galimghi;
			d.onmouseout=galimglo;
			d.onclick=productimgclick;
		}
	}
}

function getQty(frm,str) {
	var qty=frm.qty.value;
	qty = Number(qty);
	if (qty == 0) qty = 1;
	if (qty = window.prompt("Please enter the quantity of '"+str+"' that you would like to add to your cart:", qty)) {
		qty = Number(qty);
		if (qty > 0) {
			frm.qty.value=qty;
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}

function cartrowhi0() {
	this.parentNode.style.backgroundColor="#ffe0dd";
}

function cartrowhi1() {
	this.parentNode.style.backgroundColor="#eeeeee";
}

function cartrowlo() {
	this.parentNode.style.backgroundColor="#ffffff";
}

function cartd(rid) {
	if (window.confirm("Are you sure you want to remove this product from your cart?")) {
		window.location='cart.php?'+sid+'&op=recalculate&qty%5b'+rid+'%5d=0';
	}
	return false;
}

function cartclick0(e) {
	if (document.all) e = window.event;
	var target = e.target?e.target:e.srcElement;
	if ((target.nodeName != 'A') && (target.nodeName != 'IMG') && (target.nodeName != 'NOBR')) {
		cartd(this.parentNode.getAttribute('rid'));
	}
}

function cartclick1(e) {
	if (document.all) e = window.event;
	var target = e.target?e.target:e.srcElement;
	if (target.nodeName != 'A') {
		window.location='details.php?'+sid+'&id='+this.parentNode.getAttribute('pid');
	}
}

function initcart() {
	if (document.getElementById) {
		var d;
		if (d = document.getElementById('bigcart')) {
			var tb;
			if (tb = d.getElementsByTagName('tbody')) {
				var tr;
				if (tr = tb[0].getElementsByTagName('tr')) {
					var y;
					for (y = 0; y < tr.length; y ++) {
						if (tr[y].getAttribute('rid')) {
							var x, td;
							td = tr[y].getElementsByTagName('td');
							tr[y].style.cursor="pointer";
							td[0].onmouseover=cartrowhi0;
							td[1].onmouseover=cartrowhi1;
							td[2].onmouseover=cartrowhi1;
							td[4].onmouseover=cartrowhi1;
							td[0].onmouseout=cartrowlo;
							td[1].onmouseout=cartrowlo;
							td[2].onmouseout=cartrowlo;
							td[4].onmouseout=cartrowlo;
							td[0].onclick=cartclick0;
							td[1].onclick=cartclick1;
							td[2].onclick=cartclick1;
							td[4].onclick=cartclick1;
						}
					}
				}
			}
		}
	}
}

function promohi() {
	this.style.backgroundColor="#eeeeee";
}

function promolo() {
	this.style.backgroundColor="#dddddd";
}

function promoclick(e) {
	if (document.all) e = window.event;
	var target = e.target?e.target:e.srcElement;
	if ((target.nodeName != 'A') && (target.nodeName != 'IMG')) {
		window.location='http://soldier2soldier.com.au/details.php?'+sid+'&id='+this.getAttribute('p');
	}
}

function initpromo(ele) {
	if (document.getElementById) {
		var c;
		if (c = document.getElementById(ele)) {
			c.onmouseover=promohi;
			c.onmouseout=promolo;
			c.onclick=promoclick;
			c.style.cursor="pointer";
		}
	}
}

