function init() {
	if(document.f && document.f.process) document.f.process.value = "1";
}

activeThumb = 1;
function setThumbBorder(ele,idx) {
	if(idx != activeThumb) {
		ele.style.padding='0';
		ele.style.border='2px solid #4d4d4d';
	}
}

function unsetThumbBorder(ele,idx) {
	if(idx != activeThumb) {
		ele.style.padding='2px';
		ele.style.border='';
	}
}

function enlarge(ele,idx,id) {
	if(idx == 0) {
		document.getElementById('productVidBox').style.display = 'block';
		document.getElementById('productPicBox').style.display = 'none';
		unsetThumbBorder(document.getElementById('productThumb'+activeThumb),-1);
	}
	else {
		document.getElementById('productVidBox').style.display = 'none';
		document.getElementById('productPicBox').style.display = 'block';

		if(tools.xmlRequest()) {
			http_request.onreadystatechange = setMediumPic;
			http_request.open('POST', '/ProductImage.php', true);
			http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			
			var parameters = "size=medium&id="+id;
			http_request.send(parameters);
	
			unsetThumbBorder(document.getElementById('productThumb'+activeThumb),-1);
			activeThumb = idx;
		}
		else
			alert("?");
	}
}

function setMediumPic() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			document.getElementById('productPicBox').innerHTML = http_request.responseText;
		} else {
			alert('There was a problem with the request.');
		}
	}
}

function groupChange(level,group) {
	document.location = "/shop/index.php?l="+level+"&g="+group;
}

function page(page) {
	mixitup(page);
}
function mixitup(page) {
	

/*
	in a nut shell, I need to xmlhttp the next section contents.
	so, grab both group levels, and send them to the server and get the results.  basically a big block of divs...
	need to send a number per page too... - maybe.
*/
	if(tools.xmlRequest()) {
		http_request.onreadystatechange = updateProductList;
		http_request.open('POST', '/Product.php', true);
		http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		
		e = document.getElementById('group');
		var parameters = "page="+page+"&g=" + e.options[e.selectedIndex].value;
		http_request.send(parameters);
	}
	else
		alert("?");
}
function updateProductList() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
/*
			proj = document.f.projectId;
			for(i=0; i<proj.length; i++) proj.options[i] = null;
			proj.length = 0;
*/
			try {
				x = new ActiveXObject("Microsoft.XMLDOM");
				x.async = false;
				x.loadXML(http_request.responseText);
			} catch (e) {
//				alert(http_request.responseText);
//				alert(Base64.decode(http_request.responseText));
				x = http_request.responseXML;
			}

			var productBlock = document.getElementById('productBlock');
//			productBlock.innerHTML = http_request.responseText;

			var products = x.getElementsByTagName("products").item(0).firstChild.data;

			productBlock.innerHTML = Base64.decode(products);



			var pageNav1 = document.getElementById('pageNav1');
			var pageNav2 = document.getElementById('pageNav2');

			var pagenav = Base64.decode(x.getElementsByTagName("pagenav").item(0).firstChild.data);

			pageNav1.innerHTML = pagenav;
			pageNav2.innerHTML = pagenav;

/*
			var opts = x.getElementsByTagName("option");
            
			i = 0;
			while(i<opts.length) {
				opt = opts.item(i);
				//opt.attributes[0].value
				proj.options[i] = new Option(opt.firstChild.data,opt.attributes[0].value,false,false);
				i++;
			}
*/
		} else {
			alert('There was a problem with the request.');
		}
	}
}

function hideEmail(name, domain, display) {
	displayed=(typeof(display)=="undefined") ? name+"@"+domain : display 
	document.write('<a href=mailto:' + name + '@' + domain + '>' + displayed + '</a>');
}

 
colorStats = new Array(9);
for (i = 0; i < colorStats.length; ++ i) colorStats [i] = new Array(3);

colorStats[0][0] = 'Low Risk of Consuming Coral Specimens';
colorStats[0][1] = 'May Consume Coral Specimens';
colorStats[0][2] = 'High Risk of Consuming Coral Specimens';

colorStats[1][0] = 'Low Risk of Consuming Mobile Invertebrates';
colorStats[1][1] = 'May Consume Mobile Invertebrates';
colorStats[1][2] = 'High Risk of Consuming Mobile Invertebrates';

colorStats[2][0] = 'Low Risk of Consuming Small Fish Specimens';
colorStats[2][1] = 'May Consume Small Fish Specimens';
colorStats[2][2] = 'High Risk of Consuming Small Fish Specimens';

colorStats[3][0] = 'Low Care Demand';
colorStats[3][1] = 'Moderate Care Demand';
colorStats[3][2] = 'High Care Demand';

colorStats[4][0] = 'Low Risk of Aggression with Tank mates';
colorStats[4][1] = 'Moderate Risk of Aggression with Tank mates';
colorStats[4][2] = 'High Risk of Aggression with Tank mates';

colorStats[5][0] = 'Normal Feeding Requirements';
colorStats[5][1] = 'Moderately Demanding Feeding Requirements';
colorStats[5][2] = 'Specialized or Frequent Feeding Requirements';

colorStats[6][0] = 'Non-Poisonous and Should Pose No Risk';
colorStats[6][1] = 'Moderately Poisonous and Could Be Dangerous';
colorStats[6][2] = 'Poisonous and Can Be Dangerous';

colorStats[7][0] = 'Low Flow Requirements';
colorStats[7][1] = 'Moderate Flow Requirements';
colorStats[7][2] = 'High Flow Requirements';

colorStats[8][0] = 'Low Light Levels Required';
colorStats[8][1] = 'Moderate Light Levels Required';
colorStats[8][2] = 'High Light Levels Required';

function colorKey(ele,slotId,isOn) {
//alert(obj.id);
	if(isOn) {
		ele.style.backgroundPosition = 'center bottom';

		var wrap = document.getElementById("wrap");
//	alert(wrap);
		var curleft = curtop = 0;
		if (wrap.offsetParent) {
			do {
				curleft += wrap.offsetLeft;
				curtop += wrap.offsetTop;
			} while (wrap = wrap.offsetParent);
		}
		var wrapleft = curleft;		

		curleft = curtop = 0;
		obj = ele;
		if (obj.offsetParent) {
			do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
		curtop = curtop -91;
		curleft = curleft - wrapleft + 10;

		document.getElementById("colorGreen").innerHTML = colorStats[slotId][0];
		document.getElementById("colorYellow").innerHTML = colorStats[slotId][1];
		document.getElementById("colorRed").innerHTML = colorStats[slotId][2];

		document.getElementById("colorKey").style.top = "" + curtop + "px";
		document.getElementById("colorKey").style.left = "" + curleft + "px";
		document.getElementById("colorKey").style.display = "block";
//		alert("t,l: " + curtop + ", " + curleft)
	}
	else {
		ele.style.backgroundPosition = '';
		document.getElementById("colorKey").style.display = "none";
	}
}

function copyBillingInfo() {
	document.forms['f'].card_name.value = document.forms['f'].first_name.value + ' ' + document.forms['f'].last_name.value;
	document.forms['f'].card_address.value = document.forms['f'].address.value;
//	document.forms['f'].card_address2.value = document.forms['f'].address2.value;
	document.forms['f'].card_city.value = document.forms['f'].city.value;

	var cst = document.forms['f'].card_state;
	var st = document.forms['f'].state.value;
	for(i=0; i<cst.options.length; i++) {
		if(cst.options[i].value == st) {
			cst.selectedIndex = i;
			break;
		}
	}
	document.forms['f'].card_zip.value = document.forms['f'].zip.value;
}
