var preloadedImages = new Array();
function preload() {
	var args = preload.arguments;
		
	for(var i = 0; i < args.length; i++) {
		var image = new Image();
		image.src = args[i];
		preloadedImages.push(image);		
	}
}

function enterExitValue(which, what) {
	if(what && which.value == '0') {
		which.value = '';
	} else if(!what && which.value == '') {
		which.value = '0';
	}
}

function checkValue(e) {
	var keyCode;
	if(window.event) {
		keyCode = e.keyCode;
	} else if(e.which) {
		keyCode = e.which;
	}
	
	return !(/[a-zA-Z\.]/.test(String.fromCharCode(keyCode)));
}

function toggleAddress(which) {
	if(which.checked) {
		document.orderForm.shipping_name.disabled = true;
		document.orderForm.shipping_address.disabled = true;
		document.orderForm.shipping_city.disabled = true;
		document.orderForm.shipping_state.disabled = true;
		document.orderForm.shipping_zip.disabled = true;
		document.orderForm.shipping_country.disabled = true;
		document.orderForm.shipping_phone.disabled = true;
		document.orderForm.shipping_fax.disabled = true;
		
		document.orderForm.shipping_name.value = '';
		document.orderForm.shipping_address.value = '';
		document.orderForm.shipping_city.value = '';
		document.orderForm.shipping_state.value = '';
		document.orderForm.shipping_zip.value = '';
		document.orderForm.shipping_country.value = '';
		document.orderForm.shipping_phone.value = '';
		document.orderForm.shipping_fax.value = '';
		
		document.getElementById('label_name').style.color = 'black';
		document.getElementById('label_address').style.color = 'black';
		document.getElementById('label_city').style.color = 'black';
		document.getElementById('label_state').style.color = 'black';
		document.getElementById('label_zip').style.color = 'black';
		document.getElementById('label_country').style.color = 'black';
		document.getElementById('label_phone').style.color = 'black';
	} else {
		document.orderForm.shipping_name.disabled = false;
		document.orderForm.shipping_address.disabled = false;
		document.orderForm.shipping_city.disabled = false;
		document.orderForm.shipping_state.disabled = false;
		document.orderForm.shipping_zip.disabled = false;
		document.orderForm.shipping_country.disabled = false;
		document.orderForm.shipping_phone.disabled = false;
		document.orderForm.shipping_fax.disabled = false;
	}
}

function toggleCat(cat) {
	var cats = ['Finished_Rifles', 'Pistols', 'Barrels', 'Stocks', 'Trigger_Assemblies', 'Trigger_Jobs', 'Parts', 'Optics', 'Receivers', 'Photographic_Prints'];
	
	var matches = location.hash.match(/(\d)-\d+/);
	if(matches) {
		cat = cats[matches[1]];
	}
	
	for(var i = 0; i < cats.length; i++) {
		var curCat = document.getElementById('cat_'+cats[i]);
		var curCatH = document.getElementById('cat_h_'+cats[i]);
		if(curCat && curCatH) {
			if(cat == cats[i]) {
				curCat.style.display = 'block';
				curCatH.className = 'categoryOpen';
			} else {
				curCat.style.display = 'none';
				curCatH.className = 'categoryClosed';
			}
		}
	}
}

function toggleJTechComments() {
	var jtechComments = document.getElementById('jtechCommentsContainer');
	
	if(jtechComments) {	
		jtechComments.style.display = jtechComments.style.display == 'block' ? 'none' : 'block';
	}
}
