function addNewQuoteRow() {
	var last = $(".quoteItem:last").attr("id");
	$.ajax({
		type: "POST",
		url: "../cf-scripts/getQuoteForm.php",
		data: "last="+last,
		success: function(html) {
			$("#sealtype").append(html);		
		}
	});
	
	return false;
}

function selectQuoteType(quote, cat) {
	$.ajax({
		type: "POST",
		url: "../cf-scripts/getQuoteType.php",
		data: "category="+cat+"&id="+quote,
		success: function(html) {
			if(html!="NONE") {
				$("#quoteType-"+quote).html(html).slideDown();	
			}
			else {
				$("#quoteType-"+quote).html("").slideUp();
			}
		}
	});
}

function selectSealType(cat) {
	$("#subForm").slideUp("normal", function() {
		$.ajax({
			type: "POST",
			url: "../cf-scripts/getSearchForm.php",
			data: "category="+cat,
			success: function(html) {
				$("#subForm").html(html).slideDown();
			}
		});
	});
}

function selectSealTypeHorz(cat) {
	$("#subForm").slideUp("normal", function() {
		$.ajax({
			type: "POST",
			url: "../cf-scripts/getSearchFormHorz.php",
			data: "category="+cat,
			success: function(html) {
				$("#subForm").html(html).slideDown();
			}
		});
	});
}

function savedAddress(id) {
	$("#shippingInfo").slideUp("normal", function() {
		$.ajax({
			type: "POST",
			url: "../cf-scripts/getSavedAddress.php",
			data: "id="+id,
			success: function(html) {
				$("#shippingInfo").html(html);
				$("#shippingInfo").slideDown();
			}
		});
	});
}

function paymentMethod(meth) {
	if(meth=="Collect Account" || meth=="3rd Party") {
		$(".otherInfo").slideUp("normal", function() {
			$.ajax({
				type: "POST",
				url: "../cf-scripts/getPaymentMethod.php",
				data: "meth="+meth,
				success: function(html) {
					$(".otherInfo").html(html);
					$(".otherInfo").slideDown();
				}
			});
		});
	}
	else {
		$(".otherInfo").slideUp();
		$(".otherInfo").html("");
	}
}

var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
var time = true;

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}
}

function cartPreview() {
	if(time) {
		var xOff = tempX-400;
		var yOff = tempY;
		$("#cartPreview").css("top", yOff);
		$("#cartPreview").css("left", xOff);
		$("#cartPreview").slideDown();
		
		time = false;
		setTimeout("previewTimer()", 100);
	}
}

function hideCart() {
	if(time) {
		$("#cartPreview").slideUp();
		
		time = false;
		setTimeout("previewTimer()", 100);
	}
}

function previewTimer() {
	time = true;
}

function closeCartPreview() {
	$("#cartPreview").slideUp();
	return false;
}

function calcC(degF) {
	if(degF!="") {
		degF = parseFloat(degF);
		var c = (degF*1.8)+32;
		$("#degC").val(c);
	}
}

function calcF(degC) {
	if(degC!="") {
		degC = parseFloat(degC);
		var c = (degC-32)*(5/9);
		c = roundNumber(c, 2);
		$("#degF").val(c);
	}
}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function calcMM(mm) {
	if(mm!="") {
		var m = mm*0.03937;
		m = roundNumber(m, 3);
		$("#inch").val(m);
	}
}

function calcInch(inch) {
	if(inch!="") {
		var m = inch/0.03937;
		m = roundNumber(m, 3);
		$("#mm").val(m);
	}
}

function onMap(map) {
	if(map=='denver') {
		$("#denverTitle").css("font-size", "16px");
		$("#denverAddress").css("font-weight", "bold");
	}
	if(map=='barre') {
		$("#barreTitle").css("font-size", "16px");
		$("#barreAddress").css("font-weight", "bold");
	}
}
function outMap() {
	$("#denverTitle").css("font-size", "12px");
	$("#denverAddress").css("font-weight", "normal");
	$("#barreTitle").css("font-size", "12px");
	$("#barreAddress").css("font-weight", "normal");
}

function reloadCaptcha() {
	$("#captchaImg").fadeOut("normal", function() {
		$("#captchaImg").attr("src", "http://harwal.com/cf-scripts/getCaptcha.php?"+Math.random());
		$("#captchaImg").fadeIn();
	});
	return false;
}

function sameShipp() {
	if($("#sameShipping").attr("checked")) {
		$("#shipping_business").val($("#billing_business").val());
		$("#shipping_address").val($("#billing_address").val());
		$("#shipping_city").val($("#billing_city").val());
		$("#shipping_st").val($("#billing_st").val());
		$("#shipping_zip").val($("#billing_zip").val());
		$("#shipping_phone").val($("#billing_phone").val());
		$("#shipping_fax").val($("#billing_fax").val());
	}
	else {
		$("#shipping_business").val("");
		$("#shipping_address").val("");
		$("#shipping_city").val("");
		$("#shipping_st").val("");
		$("#shipping_zip").val("");
		$("#shipping_phone").val("");
		$("#shipping_fax").val("");
	}
}