$(function(){
	
	
	
	/****************************************************************************
				Hovers for set of 3 order buttons on home page
	****************************************************************************/
	$('.button').each(function(){
		$(this).hover(function(){
			$(this).attr('src', $(this).attr('src').replace(".jpg", "_roll.jpg"));
		},function(){
			$(this).attr('src', $(this).attr('src').replace("_roll.jpg", ".jpg"));
		});
	});
	
	
	
	/****************************************************************************
						Navbar hovers and dropdown menus
	****************************************************************************/
	$('#navbar li').each(function(){
		$(this).hover(function(){
			$(this).css({'background': '#691314 url(images/navroll_bg.jpg) repeat-x'});
		},function(){
			$(this).css({'background': 'none'});
		});
	});
	$('#navbar li.sub').each(function(){
		$(this).hover(function(){
			if (!$(this).children('.subdrop').hasClass('animated')) {
				$(this).children('.subdrop').dequeue().stop().slideDown(200);
			}
		},function(){
			$(this).children('.subdrop').addClass('animated').slideUp(200, function() {
				$(this).removeClass('animated').dequeue();
			});
		}); 
	});
	$('#navbar li.subsub').each(function(){
		$(this).hover(function(){
			if (!$(this).children('.subsubdrop').hasClass('animated')) {
				$(this).children('.subsubdrop').dequeue().stop().slideDown(200);
			}
		},function(){
			$(this).children('.subsubdrop').addClass('animated').slideUp(200, function() {
				$(this).removeClass('animated').dequeue();
			});
		}); 
	});
	
	
	
	/****************************************************************************
						Slide price calculater scripts
	****************************************************************************/
	var prices = new Array();
	var stainprice = new Array();
	var reportprice = new Array();
	var cutoffprice = new Array();
	var clearepoxyprice = new Array();
	var blueepoxyprice = new Array();
	var grindprice = new Array();
	var qty = new Array();
	var sqin = new Array();
	$('.calc_type').live('change', function() {
		var R = $(this).parent().parent().index();
		if($('#calc_type'+R).val() == "Fluid Inclusions"){
			$('#calc_size'+R).parent().html('<input type="text" id="calc_size'+R+'" class="calc_size" name="calc_size'+R+'" size="20" value="">');
			$('#calc_qty'+R).removeAttr('disabled');
			$('#calc_qty'+R).val('1');
			$('#calc_stain'+R).removeAttr('disabled');
			$('#calc_stain'+R).removeAttr('checked');
			$('#calc_report'+R).removeAttr('disabled');
			$('#calc_report'+R).removeAttr('checked');
			$('#calc_cutoff'+R).removeAttr('disabled');
			$('#calc_cutoff'+R).removeAttr('checked');
			$('#calc_clear-epoxy'+R).removeAttr('disabled');
			$('#calc_clear-epoxy'+R).removeAttr('checked');
			$('#calc_blue-epoxy'+R).removeAttr('disabled');
			$('#calc_blue-epoxy'+R).removeAttr('checked');
			$('#calc_grind'+R).removeAttr('disabled');
			$('#calc_grind'+R).removeAttr('checked');
			getPrice(R);
		}else if($('#calc_type'+R).val() == "Rock Cutting and Grinding" || $('#calc_type'+R).val() == "Display Polishing"){
			$('#calc_size'+R).parent().html('<input type="text" id="calc_sqin'+R+'" class="calc_sqin" name="calc_sqin'+R+'" size="20" value=""><input type="hidden" id="calc_size'+R+'" class="calc_size" name="calc_size'+R+'" size="20" value="">'+
			'<span>&nbsp;sq in.</span>');
			$('#calc_qty'+R).removeAttr('disabled');
			$('#calc_qty'+R).val('1');
			$('#calc_stain'+R).attr('disabled', 'disabled');
			$('#calc_stain'+R).removeAttr('checked');
			$('#calc_report'+R).attr('disabled', 'disabled');
			$('#calc_report'+R).removeAttr('checked');
			$('#calc_cutoff'+R).attr('disabled', 'disabled');
			$('#calc_cutoff'+R).removeAttr('checked');
			$('#calc_clear-epoxy'+R).attr('disabled', 'disabled');
			$('#calc_clear-epoxy'+R).removeAttr('checked');
			$('#calc_blue-epoxy'+R).attr('disabled', 'disabled');
			$('#calc_blue-epoxy'+R).removeAttr('checked');
			$('#calc_grind'+R).attr('disabled', 'disabled');
			$('#calc_grind'+R).removeAttr('checked');
			getPrice(R);
		}else if($('#calc_type'+R).val() != ""){
			$('#calc_size'+R).parent().html('<select class="req calc_size" id="calc_size'+R+'" name="calc_size'+R+'" disabled="disabled"><option	value="">Select</option></select>');
			getSizes(R);
			$('#calc_size'+R).removeAttr('disabled');
			$('#calc_qty'+R).attr('disabled', 'disabled');
			$('#calc_qty'+R).val('1');
			$('#calc_stain'+R).attr('disabled', 'disabled');
			$('#calc_stain'+R).removeAttr('checked');
			$('#calc_report'+R).attr('disabled', 'disabled');
			$('#calc_report'+R).removeAttr('checked');
			$('#calc_cutoff'+R).attr('disabled', 'disabled');
			$('#calc_cutoff'+R).removeAttr('checked');
			$('#calc_clear-epoxy'+R).attr('disabled', 'disabled');
			$('#calc_clear-epoxy'+R).removeAttr('checked');
			$('#calc_blue-epoxy'+R).attr('disabled', 'disabled');
			$('#calc_blue-epoxy'+R).removeAttr('checked');
			$('#calc_grind'+R).attr('disabled', 'disabled');
			$('#calc_grind'+R).removeAttr('checked');
			$('#calc_price'+R).html("0.00");
		}else{
			$('#calc_size'+R).parent().html('<select class="req calc_size" id="calc_size'+R+'" name="calc_size'+R+'" disabled="disabled"><option	value="">Select</option></select>');
			$('#calc_qty'+R).attr('disabled', 'disabled');
			$('#calc_qty'+R).val('1');
			$('#calc_stain'+R).attr('disabled', 'disabled');
			$('#calc_stain'+R).removeAttr('checked');
			$('#calc_report'+R).attr('disabled', 'disabled');
			$('#calc_report'+R).removeAttr('checked');
			$('#calc_cutoff'+R).attr('disabled', 'disabled');
			$('#calc_cutoff'+R).removeAttr('checked');
			$('#calc_clear-epoxy'+R).attr('disabled', 'disabled');
			$('#calc_clear-epoxy'+R).removeAttr('checked');
			$('#calc_blue-epoxy'+R).attr('disabled', 'disabled');
			$('#calc_blue-epoxy'+R).removeAttr('checked');
			$('#calc_grind'+R).attr('disabled', 'disabled');
			$('#calc_grind'+R).removeAttr('checked');
			$('#calc_price'+R).html("0.00");
		}
		$('#price_calc_total').html('');
	});
	function getSizes(R){
		xmlhttp=GetXmlHttpObject();
		if (xmlhttp==null){
			alert ("Browser does not support HTTP Request");
			return;
		}
		var slidetype = $('#calc_type'+R).val();
		slidetype = slidetype.replace(/ /g,"__");
		var url="getSize.php";
		url=url+"?slidetype=" + slidetype;
		xmlhttp.onreadystatechange=function(){showSize(R)};
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
	function showSize(R){
		if (xmlhttp.readyState==4){
			$('#calc_size'+R).append(xmlhttp.responseText);
		}
	}
	function GetXmlHttpObject(){
		if (window.XMLHttpRequest){
			// code for IE7+, Firefox, Chrome, Opera, Safari
			return new XMLHttpRequest();
		}
		if (window.ActiveXObject){
			// code for IE6, IE5
			return new ActiveXObject("Microsoft.XMLHTTP");
		}
		return null;
	}
	$('select.calc_size').live('change', function() {
		var R = $(this).parent().parent().index();
		if($('#calc_size'+R).val() != ""){
			$('#calc_qty'+R).removeAttr('disabled');
			$('#calc_qty'+R).val('1');
			$('#calc_stain'+R).removeAttr('disabled');
			$('#calc_stain'+R).removeAttr('checked');
			$('#calc_report'+R).removeAttr('disabled');
			$('#calc_report'+R).removeAttr('checked');
			$('#calc_cutoff'+R).removeAttr('disabled');
			$('#calc_cutoff'+R).removeAttr('checked');
			$('#calc_clear-epoxy'+R).removeAttr('disabled');
			$('#calc_clear-epoxy'+R).removeAttr('checked');
			$('#calc_blue-epoxy'+R).removeAttr('disabled');
			$('#calc_blue-epoxy'+R).removeAttr('checked');
			$('#calc_grind'+R).removeAttr('disabled');
			$('#calc_grind'+R).removeAttr('checked');
			$('#calc_price'+R).html("0.00");
			getPrice(R);
		}else{
			$('#calc_qty'+R).attr('disabled', 'disabled');
			$('#calc_qty'+R).val('1');
			$('#calc_stain'+R).attr('disabled', 'disabled');
			$('#calc_stain'+R).removeAttr('checked');
			$('#calc_report'+R).attr('disabled', 'disabled');
			$('#calc_report'+R).removeAttr('checked');
			$('#calc_cutoff'+R).attr('disabled', 'disabled');
			$('#calc_cutoff'+R).removeAttr('checked');
			$('#calc_clear-epoxy'+R).attr('disabled', 'disabled');
			$('#calc_clear-epoxy'+R).removeAttr('checked');
			$('#calc_blue-epoxy'+R).attr('disabled', 'disabled');
			$('#calc_blue-epoxy'+R).removeAttr('checked');
			$('#calc_grind'+R).attr('disabled', 'disabled');
			$('#calc_grind'+R).removeAttr('checked');
			$('#calc_price'+R).html("0.00");
		}
		$('#price_calc_total').html('');
	});
	function getPrice(R){
		xmlhttp=GetXmlHttpObject();
		if (xmlhttp==null){
			alert ("Browser does not support HTTP Request");
			return;
		}
		var slidetype = $('#calc_type'+R).val();
		slidetype = slidetype.replace(/ /g,"__");
		var size = $('#calc_size'+R).val();
		size = size.replace(/ /g,"__");
		var url="getPrice.php";
		url=url+"?slidetype=" + slidetype + "&size="+size;
		xmlhttp.onreadystatechange=function(){showPrice(R)};
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
	function showPrice(R){
		if (xmlhttp.readyState==4){
			var string = xmlhttp.responseText;
			var split_str = string.split('**');
			prices[R] = split_str[0];
			stainprice[R] = split_str[1];
			if(stainprice[R] == ""){
				stainprice[R] = 0;
			}
			reportprice[R] = split_str[2];
			if(reportprice[R] == ""){
				reportprice[R] = 0;
			}
			cutoffprice[R] = split_str[3];
			if(cutoffprice[R] == ""){
				cutoffprice[R] = 0;
			}
			clearepoxyprice[R] = split_str[4];
			blueepoxyprice[R] = split_str[5];
			grindprice[R] = split_str[6];
			$('#calc_price'+R).html(prices[R]);
		}
	}
	$('.calc_sqin').live('keyup', function() {
		var R = $(this).parent().parent().index();
		sqin[R] = parseInt($('#calc_sqin'+R).val());
		if(sqin[R] == "" || isNaN(sqin[R])){
			sqin[R] = 0;
		}
		qty[R] = parseInt($('#calc_qty'+R).val());
		if(qty[R] == "" || isNaN(qty[R])){
			qty[R] = 0;
		}
		
		var newprice = (parseFloat(prices[R])*qty[R]*sqin[R]);
		newprice = newprice.toFixed(2);
		$('#calc_price'+R).html(newprice);
		$('#price_calc_total').html('');
	});
	$('.calc_qty').live('keyup', function() {
		var R = $(this).parent().parent().index();
		sqin[R] = parseInt($('#calc_sqin'+R).val());
		if($('#calc_size'+R).val() == "" && (sqin[R] == "" || isNaN(sqin[R]))){
			sqin[R] = 0;
		}else if(sqin[R] == "" || isNaN(sqin[R])){ 
			sqin[R] = 1;
		}
		qty[R] = parseInt($('#calc_qty'+R).val());
		if(qty[R] == "" || isNaN(qty[R])){
			qty[R] = 0;
		}
		if($('#calc_stain'+R).is(':checked')){
			var stain = parseFloat(stainprice[R]);
		}else{
			var stain = 0;
		}
		if($('#calc_report'+R).is(':checked')){
			if(qty[R] == 0){
				var report = 0;
			}else{
				var report = parseFloat(reportprice[R]);
			}
		}else{
			var report = 0;
		}
		if($('#calc_cutoff'+R).is(':checked')){
			var cutoff = parseFloat(cutoffprice[R]);
		}else{
			var cutoff = 0;
		}
		if($('#calc_clear-epoxy'+R).is(':checked')){
			var clearepoxy = parseFloat(clearepoxyprice[R]);
		}else{
			var clearepoxy = 0;
		}
		if($('#calc_blue-epoxy'+R).is(':checked')){
			var blueepoxy = parseFloat(blueepoxyprice[R]);
		}else{
			var blueepoxy = 0;
		}
		if($('#calc_grind'+R).is(':checked')){
			var grind = parseFloat(grindprice[R]);
		}else{
			var grind = 0;
		}
		var newprice = (parseFloat(prices[R])*qty[R]*sqin[R])+(stain*qty[R])+(report*qty[R])+(cutoff*qty[R])+(clearepoxy*qty[R])+(blueepoxy*qty[R])+(grind*qty[R]);
		newprice = newprice.toFixed(2);
		$('#calc_price'+R).html(newprice);
		$('#price_calc_total').html('');
	});
	$('.calc_stain').live('change', function() {
		var R = $(this).parent().parent().parent().index();
		qty[R] = parseInt($('#calc_qty'+R).val());
		if(qty[R] == "" || isNaN(qty[R])){
			qty[R] = 0;
		}
		if($('#calc_stain'+R).is(':checked')){
			var stain = parseFloat(stainprice[R]);
		}else{
			var stain = 0;
		}
		if($('#calc_report'+R).is(':checked')){
			if(qty[R] == 0){
				var report = 0;
			}else{
				var report = parseFloat(reportprice[R]);
			}
		}else{
			var report = 0;
		}
		if($('#calc_cutoff'+R).is(':checked')){
			var cutoff = parseFloat(cutoffprice[R]);
		}else{
			var cutoff = 0;
		}
		if($('#calc_clear-epoxy'+R).is(':checked')){
			var clearepoxy = parseFloat(clearepoxyprice[R]);
		}else{
			var clearepoxy = 0;
		}
		if($('#calc_blue-epoxy'+R).is(':checked')){
			var blueepoxy = parseFloat(blueepoxyprice[R]);
		}else{
			var blueepoxy = 0;
		}
		if($('#calc_grind'+R).is(':checked')){
			var grind = parseFloat(grindprice[R]);
		}else{
			var grind = 0;
		}
		var newprice = (parseFloat(prices[R])*qty[R])+(stain*qty[R])+(report*qty[R])+(cutoff*qty[R])+(clearepoxy*qty[R])+(blueepoxy*qty[R])+(grind*qty[R]);
		newprice = newprice.toFixed(2);
		$('#calc_price'+R).html(newprice);
		$('#price_calc_total').html('');
	});
	
	$('.calc_report').live('change', function() {
		var R = $(this).parent().parent().parent().index();
		qty[R] = parseInt($('#calc_qty'+R).val());
		if(qty[R] == "" || isNaN(qty[R])){
			qty[R] = 0;
		}
		if($('#calc_stain'+R).is(':checked')){
			var stain = parseFloat(stainprice[R]);
		}else{
			var stain = 0;
		}
		if($('#calc_report'+R).is(':checked')){
			if(qty[R] == 0){
				var report = 0;
			}else{
				var report = parseFloat(reportprice[R]);
			}
		}else{
			var report = 0;
		}
		if($('#calc_cutoff'+R).is(':checked')){
			var cutoff = parseFloat(cutoffprice[R]);
		}else{
			var cutoff = 0;
		}
		if($('#calc_clear-epoxy'+R).is(':checked')){
			var clearepoxy = parseFloat(clearepoxyprice[R]);
		}else{
			var clearepoxy = 0;
		}
		if($('#calc_blue-epoxy'+R).is(':checked')){
			var blueepoxy = parseFloat(blueepoxyprice[R]);
		}else{
			var blueepoxy = 0;
		}
		if($('#calc_grind'+R).is(':checked')){
			var grind = parseFloat(grindprice[R]);
		}else{
			var grind = 0;
		}
		var newprice = (parseFloat(prices[R])*qty[R])+(stain*qty[R])+(report*qty[R])+(cutoff*qty[R])+(clearepoxy*qty[R])+(blueepoxy*qty[R])+(grind*qty[R]);
		newprice = newprice.toFixed(2);
		$('#calc_price'+R).html(newprice);
		$('#price_calc_total').html('');
	});
	
	$('.calc_cutoff').live('change', function() {
		var R = $(this).parent().parent().parent().index();
		qty[R] = parseInt($('#calc_qty'+R).val());
		if(qty[R] == "" || isNaN(qty[R])){
			qty[R] = 0;
		}
		if($('#calc_stain'+R).is(':checked')){
			var stain = parseFloat(stainprice[R]);
		}else{
			var stain = 0;
		}
		if($('#calc_report'+R).is(':checked')){
			if(qty[R] == 0){
				var report = 0;
			}else{
				var report = parseFloat(reportprice[R]);
			}
		}else{
			var report = 0;
		}
		if($('#calc_cutoff'+R).is(':checked')){
			var cutoff = parseFloat(cutoffprice[R]);
		}else{
			var cutoff = 0;
		}
		if($('#calc_clear-epoxy'+R).is(':checked')){
			var clearepoxy = parseFloat(clearepoxyprice[R]);
		}else{
			var clearepoxy = 0;
		}
		if($('#calc_blue-epoxy'+R).is(':checked')){
			var blueepoxy = parseFloat(blueepoxyprice[R]);
		}else{
			var blueepoxy = 0;
		}
		if($('#calc_grind'+R).is(':checked')){
			var grind = parseFloat(grindprice[R]);
		}else{
			var grind = 0;
		}
		var newprice = (parseFloat(prices[R])*qty[R])+(stain*qty[R])+(report*qty[R])+(cutoff*qty[R])+(clearepoxy*qty[R])+(blueepoxy*qty[R])+(grind*qty[R]);
		newprice = newprice.toFixed(2);
		$('#calc_price'+R).html(newprice);
		$('#price_calc_total').html('');
	});
	
	$('.calc_clear-epoxy').live('change', function() {
		var R = $(this).parent().parent().parent().index();
		qty[R] = parseInt($('#calc_qty'+R).val());
		if(qty[R] == "" || isNaN(qty[R])){
			qty[R] = 0;
		}
		if($('#calc_stain'+R).is(':checked')){
			var stain = parseFloat(stainprice[R]);
		}else{
			var stain = 0;
		}
		if($('#calc_report'+R).is(':checked')){
			if(qty[R] == 0){
				var report = 0;
			}else{
				var report = parseFloat(reportprice[R]);
			}
		}else{
			var report = 0;
		}
		if($('#calc_cutoff'+R).is(':checked')){
			var cutoff = parseFloat(cutoffprice[R]);
		}else{
			var cutoff = 0;
		}
		if($('#calc_clear-epoxy'+R).is(':checked')){
			var clearepoxy = parseFloat(clearepoxyprice[R]);
			$('#calc_blue-epoxy'+R).attr('disabled', 'disabled');
		}else{
			var clearepoxy = 0;
			$('#calc_blue-epoxy'+R).removeAttr('disabled');
		}
		if($('#calc_blue-epoxy'+R).is(':checked')){
			var blueepoxy = parseFloat(blueepoxyprice[R]);
		}else{
			var blueepoxy = 0;
		}
		if($('#calc_grind'+R).is(':checked')){
			var grind = parseFloat(grindprice[R]);
		}else{
			var grind = 0;
		}
		var newprice = (parseFloat(prices[R])*qty[R])+(stain*qty[R])+(report*qty[R])+(cutoff*qty[R])+(clearepoxy*qty[R])+(blueepoxy*qty[R])+(grind*qty[R]);
		newprice = newprice.toFixed(2);
		$('#calc_price'+R).html(newprice);
		$('#price_calc_total').html('');
	});
	
	$('.calc_blue-epoxy').live('change', function() {
		var R = $(this).parent().parent().parent().index();
		qty[R] = parseInt($('#calc_qty'+R).val());
		if(qty[R] == "" || isNaN(qty[R])){
			qty[R] = 0;
		}
		if($('#calc_stain'+R).is(':checked')){
			var stain = parseFloat(stainprice[R]);
		}else{
			var stain = 0;
		}
		if($('#calc_report'+R).is(':checked')){
			if(qty[R] == 0){
				var report = 0;
			}else{
				var report = parseFloat(reportprice[R]);
			}
		}else{
			var report = 0;
		}
		if($('#calc_cutoff'+R).is(':checked')){
			var cutoff = parseFloat(cutoffprice[R]);
		}else{
			var cutoff = 0;
		}
		if($('#calc_clear-epoxy'+R).is(':checked')){
			var clearepoxy = parseFloat(clearepoxyprice[R]);
		}else{
			var clearepoxy = 0;
		}
		if($('#calc_blue-epoxy'+R).is(':checked')){
			var blueepoxy = parseFloat(blueepoxyprice[R]);
			$('#calc_clear-epoxy'+R).attr('disabled', 'disabled');
		}else{
			var blueepoxy = 0;
			$('#calc_clear-epoxy'+R).removeAttr('disabled');
		}
		if($('#calc_grind'+R).is(':checked')){
			var grind = parseFloat(grindprice[R]);
		}else{
			var grind = 0;
		}
		var newprice = (parseFloat(prices[R])*qty[R])+(stain*qty[R])+(report*qty[R])+(cutoff*qty[R])+(clearepoxy*qty[R])+(blueepoxy*qty[R])+(grind*qty[R]);
		newprice = newprice.toFixed(2);
		$('#calc_price'+R).html(newprice);
		$('#price_calc_total').html('');
	});
	
	$('.calc_grind').live('change', function() {
		var R = $(this).parent().parent().parent().index();
		qty[R] = parseInt($('#calc_qty'+R).val());
		if(qty[R] == "" || isNaN(qty[R])){
			qty[R] = 0;
		}
		if($('#calc_stain'+R).is(':checked')){
			var stain = parseFloat(stainprice[R]);
		}else{
			var stain = 0;
		}
		if($('#calc_report'+R).is(':checked')){
			if(qty[R] == 0){
				var report = 0;
			}else{
				var report = parseFloat(reportprice[R]);
			}
		}else{
			var report = 0;
		}
		if($('#calc_cutoff'+R).is(':checked')){
			var cutoff = parseFloat(cutoffprice[R]);
		}else{
			var cutoff = 0;
		}
		if($('#calc_clear-epoxy'+R).is(':checked')){
			var clearepoxy = parseFloat(clearepoxyprice[R]);
		}else{
			var clearepoxy = 0;
		}
		if($('#calc_blue-epoxy'+R).is(':checked')){
			var blueepoxy = parseFloat(blueepoxyprice[R]);
		}else{
			var blueepoxy = 0;
		}
		if($('#calc_grind'+R).is(':checked')){
			var grind = parseFloat(grindprice[R]);
		}else{
			var grind = 0;
		}
		var newprice = (parseFloat(prices[R])*qty[R])+(stain*qty[R])+(report*qty[R])+(cutoff*qty[R])+(clearepoxy*qty[R])+(blueepoxy*qty[R])+(grind*qty[R]);
		newprice = newprice.toFixed(2);
		$('#calc_price'+R).html(newprice);
		$('#price_calc_total').html('');
	});
	
	$('#add_calc_row').click(function(){
		var id = $('#slide_price_calc tr').size(); 
		$('#slide_price_calc').append(
			'<tr>'+
				'<td class="head">'+id+'</td>'+
				'<td><select id="calc_type'+id+'" class="calc_type" name="calc_type'+id+'">'+
					'<option	value="">Select</option>'+
					'<option value="Thin Sections (30 Microns)" title="Transmitted light study only">Thin Sections (30 Microns)</option>'+
					'<option value="Polished Thin Sections (30 Microns)" title="Reflected and transmitted light study">Polished Thin Sections (30 Microns)</option>'+
					'<option value="Kimberlite Thin Sections" title="Covered">Kimberlite Thin Sections</option>'+
					'<option value="Kimberlite Polished Thin Sections">Kimberlite Polished Thin Sections</option>'+
					'<option value="Polished Thick Sections (200 Microns)" title="Reflected light study only - non removable">Polished Thick Sections (200 Microns)</option>'+
					'<option value="Kimberlite Core Slabs" title="Impreg-cut-grind to Mat finish">Kimberlite Core Slabs</option>'+
					'<option value="Fluid Inclusions" title="Removable with Acetone - soak overnight">Fluid Inclusions</option>'+
					'<option value="Sand, Precussion Drill Chips, Mill Concentrates">Sand, Precussion Drill Chips, Mill Concentrates</option>'+
					'<option value="Rock Cutting and Grinding">Rock Cutting and Grinding</option>'+
					'<option value="Display Polishing">Display Polishing</option>'+
				'</select></td>'+
				'<td><select class="calc_size" id="calc_size'+id+'" name="calc_size'+id+'" disabled="disabled">'+
					'<option	value="">Select</option>'+
				'</select></td>'+
				'<td><input type="text" id="calc_qty'+id+'" class="calc_qty" name="calc_qty'+id+'" size="2" value="1" disabled="disabled"></td>'+
				'<td style="text-align:left;">'+
					'<span style="float:left"><input type="checkbox" id="calc_stain'+id+'" class="calc_stain" name="calc_stain'+id+'" value="Yes" disabled="disabled"><label for="calc_stain'+id+'">Stain</label><br>'+
					'<input type="checkbox" id="calc_report'+id+'" class="calc_report" name="calc_report'+id+'" value="Yes" disabled="disabled"><label for="calc_report'+id+'">Report</label><br>'+
					'<input type="checkbox" id="calc_cutoff'+id+'" class="calc_cutoff" name="calc_cutoff'+id+'" value="Yes" disabled="disabled"><label for="calc_cutoff'+id+'">Section Cut-off</label></span>'+
					'<span style="float:left"><input type="checkbox" id="calc_clear-epoxy'+id+'" class="calc_clear-epoxy" name="calc_clear-epoxy'+id+'" value="Yes" disabled="disabled"><label for="calc_clear-epoxy'+id+'">Clear Epoxy</label><br>'+
					'<input type="checkbox" id="calc_blue-epoxy'+id+'" class="calc_blue-epoxy" name="calc_blue-epoxy'+id+'" value="Yes" disabled="disabled"><label for="calc_blue-epoxy'+id+'">Blue Epoxy</label><br>'+
					'<input type="checkbox" id="calc_grind'+id+'" class="calc_grind" name="calc_grind'+id+'" value="Yes" disabled="disabled"><label for="calc_grind'+id+'">Water Sol. Grinding</label></span></td>'+
				'<td style="text-align:right;"><p class="calc_price">$<span id="calc_price'+id+'">0.00</span></p><input type="hidden" id="price'+id+'" name="price'+id+'" value=""></td>'+
				'<td></td>'+
			'</tr>');
		/*if(!($('.subtract').size()==1))
			$('.subtract').fadeIn(100);
		$('.subtract').each(function(){
			$(this).click(function(){
				$(this).parent().parent().remove();
				$('#slide_order tr td:first-child').each(function(){
					if(!($(this).parent().index() == 0))
						$(this).html($(this).parent().index());
				});
				if(($('.subtract').size()==1))
					$('.subtract').fadeOut(100);
			});
		});*/
		$('#price_calc_total').html('');
	});
		
	/****************************************************************************
								Calculate Button
	****************************************************************************/
	$('#calculate').click(function(){
		var rows = $('#slide_price_calc tr').size();
		var subtotal = 0;
		var tax;
		var total = 0;
		for (i=1; i<rows; i++){
			$('#price'+i).val($('#calc_price'+i).html());
			subtotal = subtotal + parseFloat($('#calc_price'+i).html());
		}
		if (subtotal>0){
			tax = subtotal*0.12;
			total = (subtotal + tax).toFixed(2);
			tax = tax.toFixed(2);
			subtotal = subtotal.toFixed(2);
			$('#price_calc_total').html(
			'<div style="float:right">'+
				'<p id="subtotal">' + subtotal + '</p>'+
				'<p id="tax">' + tax + '</p>'+
				'<p id="total2">' + total + '</p>'+
			'</div>'+
			'<div style="float:right">'+
				'<p id="subtotal">Subtotal $</p>'+
				'<p id="tax">HST $</p>'+
				'<p id="total">Estimated Total $</p>'+
			'</div>'+
			'<div class="clear"></div>'+
			'<input type="hidden" id="subtot" name="subtot" value="'+subtotal+'">'+
			'<input type="hidden" id="taxes" name="taxes" value="'+tax+'">'+
			'<input type="hidden" id="tot" name="tot" value="'+total+'">'+
			'<img id="order" class="frm_button" src="images/order.jpg" width="97" height="34" alt="Order Now">');
			$('#error').html('');
		}else{
			$('#error').html('<strong>There is nothing to calculate! Please select a slide type and size.</strong>');
			$('#price_calc_total').html('');
		}
	});
	
	
	
	/****************************************************************************
								Order Now Button
	****************************************************************************/
	$('#order').live('click', function(){
		$('#slide_order_frm').append('<input type="hidden" id="numrows" name="numrows" value="'+$('#slide_price_calc tr').size()+'">');
		$('#slide_order_frm').submit();
	});
	
	
	
	/****************************************************************************
							Final Order Submit Button
	****************************************************************************/	
	$('#addresses_submit').click(function(){
		var valid = true;
		$('#addresses_frm input.req').each(function(){
			if($(this).val() == ''){
				$(this).css({'border':'2px solid red', 'padding': '2px 1px'});
				valid = false;
			}else{
				$(this).removeAttr('style');
			}
		});
		$('#addresses_frm select.req').each(function(){
			if($(this).val() == ''){
				$(this).css({'color':'red'});
				$(this).children('option:not(:first-child)').css({'color':'black'});
				valid = false;
			}else{
				$(this).removeAttr('style');
				$(this).children().removeAttr('style');
			}
		});
		var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if(!filter.test($('#billing #email_bill').val())){
			$('#billing #email_bill').css({'border':'2px solid red', 'padding': '2px 1px'});
			valid = false;
		}else{
			$(this).removeAttr('style');
		}
		if($('#uploaded').val() != ""){
			var file = $('#uploaded').val().split('/').pop();
			if(file.indexOf(".") != -1){
				var ext = file.split('.').pop().toLowerCase();
				var allowed = new Array('xls', 'pdf', 'txt', 'doc', 'docx');
				if(jQuery.inArray(ext, allowed) == -1) {
				   $('#allowed').css({'color':'red', 'font-weight':'bold'});
				   valid = false;
				}else{
					$('#allowed').removeAttr('style');
				}
			}
		}
		if(valid){
			$('#error').html('');
			$('#addresses_frm').submit();
		}else{
			$('#error').html('<strong>There appears to be one or more errors in the highlighted fields.<br>Please check the form and try again.</strong>');
		}
	});
	
	
	

	/****************************************************************************
				Use Billing address as Shipping address checkbox
	****************************************************************************/		
	$('#same_as').click(function(){
		var valid = true;
		$('#billing input.copy').each(function(){
			if($(this).val() == ''){
				$(this).css({'border':'2px solid red', 'padding': '2px 1px'});
				valid = false;
			}else{
				$(this).removeAttr('style');
			}
		});
		$('#billing select.copy').each(function(){
			if($(this).val() == ''){
				$(this).css({'color':'red'});
				$(this).children().css({'color':'black'});
				valid = false;
			}else{
				$(this).removeAttr('style');
				$(this).children().removeAttr('style');
			}
		});
		
		if(valid){
			$('#error').html('');
			$('#shipping input').each(function(){
				bill_id = $(this).attr('id').replace("ship", "bill");
				$(this).attr('value', $('#billing #'+bill_id).val());
			});
			$('#shipping select').each(function(){
				bill_id = $(this).attr('id').replace("ship", "bill");
				$(this).attr('value', $('#'+bill_id).val());
			});
			
			$('#addresses_frm input.req').each(function(){
				if($(this).val() == ''){
					$(this).css({'border':'2px solid red', 'padding': '2px 1px'});
					valid = false;
				}else{
					$(this).removeAttr('style');
				}
			});
			$('#addresses_frm select.req').each(function(){
				if($(this).val() == ''){
					$(this).css({'color':'red'});
					$(this).children().css({'color':'black'});
					valid = false;
				}else{
					$(this).removeAttr('style');
					$(this).children().removeAttr('style');
				}
			});
			var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
			if(!filter.test($('#billing #email_bill').val())){
				$('#billing #email_bill').css({'border':'2px solid red', 'padding': '2px 1px'});
				valid = false;
			}else{
				$(this).removeAttr('style');
			}
			if(valid){
				$('#error').html('');
			}else{
				$('#error').html('<strong>There appears to be one or more errors in the highlighted fields.<br>Please check the form and try again.</strong>');
			}
			
		}
		else{
			$('#error').html('<strong>There appears to be one or more errors in the highlighted fields.<br>Please check the form and try again.</strong>');
			return false;
		}
		
		
	});
	
	/****************************************************************************
							Contact submit button
	****************************************************************************/		
	$('#contact_submit').click(function(){
		var valid = true;
		$('#contact_frm input.req').each(function(){
			if($(this).val() == ''){
				$(this).css({'border':'2px solid red', 'padding': '2px 1px'});
				valid = false;
			}else{
				$(this).removeAttr('style');
			}
		});
		$('#contact_frm textarea.req').each(function(){
			if($(this).val() == ''){
				$(this).css({'border':'2px solid red'});
				valid = false;
			}else{
				$(this).removeAttr('style');
			}
		});
		var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if(!filter.test($('#contact_frm #email').val())){
			$('#contact_frm #email').css({'border':'2px solid red', 'padding': '2px 1px'});
			valid = false;
		}else{
			$(this).removeAttr('style');
		}
		if(valid){
			$('#error').html('');
			$('#contact_frm').submit();
		}else{
			$('#error').html('<strong>There appears to be one or more errors in the highlighted fields.<br>Please check the form and try again.</strong>');
		}
	});

	
	
	
	
	
	
	
	
	
	
	
	
	
	$('.pic img').each(function(){
		$(this).hover(function(){
			$(this).parent().children('.large').css({'display': 'block'});
		},function(){
			$(this).parent().children('.large').css({'display': 'none'});
		});
	});
	
	
	
	$('#print2').click(function(){
		window.print();
	});
	
	
});




