$(function() {
	$("#fieldset_chousing,#chousing_polished_brass,#chousing_polished_chrome").hide();
	
	$(":radio[name='TRIM01'],:radio[name='HOUSING01']").click(function() {
		var skus = "";
		var group = null;
		var bump = null;
		var trim = $(":radio[name='TRIM01'][checked]").val();
		var housing = $(":radio[name='HOUSING01'][checked]").val();

		$("#fieldset_chousing,#chousing_polished_brass,#chousing_polished_chrome").hide();
		
		if(trim == undefined) return;

		for(var i = 0;i < tj.trim.length;i++) {
			if (tj.trim[i][0] == trim) 
				group = tj.trim[i][1];
		}
		if(group == null) {
			for(var i = 0;i < tj.ctrim.length;i++) {
				if (tj.ctrim[i][0] == trim) 
					group = tj.ctrim[i][1];
			}
		}
		
		if(group == 1 && trim == "Polished Chrome")
			$("#fieldset_chousing,#chousing_polished_brass").show();
		else if(group == 1 && trim == "Polished Brass")
			$("#fieldset_chousing,#chousing_polished_chrome").show();

		if (housing == undefined) return;
		
		for(var i = 0;i < tj.housing.length;i++) {
			if (tj.housing[i][0] == housing) 
				bump = tj.housing[i][1];
		}
		if(bump == null) {
			for(var i = 0;i < tj.chousing.length;i++) {
				if (tj.chousing[i][0] == housing) 
					bump = tj.chousing[i][1];
			}
		}

		if (group == null || bump == null) return;
		
		if((housing == "Polished Brass" || housing == "Polished Chrome") && group != 1) {
			$(":radio[name='HOUSING01'][checked]").attr('checked','');
	 		$("#_hideme").hide();
		} else
			$("#_hideme").show();

		if(group == 1 && bump == 2)
			group = "SF";
		else 
			group += parseInt(bump);
			
		
		$("#PRODUCT01").html('');

		for (var i = 1; i < 5; i++) {
			var mag;
			var nomag = '';
			switch(i) {
				case 1:
					mag = "1X";
					break;
				case 2:
					mag = "3X";
					break;
				case 3:
					mag = "5X";
					break;
				case 4:
					mag = "7X";
					break;
			}
			sku = model + group + mag;

			if(prices[sku] == undefined) continue;
			skus += '<option value="' + sku + '"';

			if (mag == "1X")	nomag = 'no ';

			skus += '>' + mag.toLowerCase() + ' ' + nomag + 'Magnification - List Price: $' + prices[sku]['list'] + ' Your Price: $' + prices[sku]['price'] + '</option>';
		}
		//skus = '<option value="">Select Magnification</option>' + skus;
		$("#PRODUCT01").html(skus);		
	});
});

function checkdata() {
	var prod = $('#PRODUCT01').val();
	
	if ($(":radio[name='TRIM01'][checked]").val() == undefined) {
		alert("Please choose trim color.");
		return false;		
	}
	
	if ($(":radio[name='HOUSING01'][checked]").val() == undefined) {
		alert("Please choose housing color.");
		return false;		
	}
	if (prod == '' || prod == null) {
		//alert("Please choose Magification from dropdown list.");
		alert("Please choose Magification.");
		return false;
	}

	if ($('input[name="QUANTITY01"]').val() == '' || $('input[name="QUANTITY01"]').val() < 1) {
		alert('Please enter a quantity greater than 0.');
		return false;
	}
	return true;
}

function moVie(){
	window.open("http://www.seattleluxe.com/tonJon/NTM1_movie.html","p","width=250,height=320");
	}
function thePouch(){
	window.open("http://www.seattleluxe.com/tonJon/NTM1_pouch.html","q","width=250,height=267");
	}

function sendTo(){
	window.open("http://www.seattleluxe.com/tonJon/customSendSample.html","p","width=620,height=410");
}

function whereTo(goTo){
	if (goTo=="cart")top.location="/cart/jcart.php";
	if (goTo=="back")history.back();
	return false;
}