var dialogStatus = 0;
function enableDialog(){if(dialogStatus==0){
		$("#dialogBox").fadeIn("slow",function(){
			if ($.browser.msie) this.style.removeAttribute("filter");
			$('#focushere').focus();
			});
		dialogStatus = 1;
	}}
function disableDialog(){
	if(dialogStatus==1){
		$("#dialogBox").fadeOut("slow");
		dialogStatus = 0;
		}
	}
function centerDialog(){
	var winW=1024,winH=768,x,y;
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape")
			{winW = window.innerWidth; winH = window.innerHeight;}
		if (navigator.appName.indexOf("Microsoft")!=-1)
			{winW = document.body.offsetWidth; winH = document.body.offsetHeight;}
		}
	x = (winW - $("#dialogBox").width()) / 2; y = (winH - $("#dialogBox").height()) / 2;
	// original
	$("#dialogBox").css({"position": "absolute","top": y,"left": x});
	// 2011-02-18
	$("#dialogBox").css({"position": "absolute","top": 225,"left": x});

	}
function displayDialog() {
	$(document).keypress(function(e){
		if(e.keyCode==27 && dialogStatus==1) disableDialog();
		if(e.keyCode==13 && dialogStatus==1) calculateDiscount();
		});
	centerDialog();	enableDialog();
	}
// our initialization:
$(document).ready(function(){$('#dialogBox').corner("20px")});

// round to nearest cent:
function round(v) {return (Math.round(v*100.0)/100.0);};

// convert something to a number:
function toNumber(v) {
	var p=new String(v),r=new String(''),i,d;
	for (i=0;i<p.length;i++) {
		d=p.charAt(i);
		if (((d=='-')&&(i==0))||(d=='.')||((d>='0')&&(d<='9'))) r+=d;
		}
	if (r=='') r='0';
	return Number(r);
	};

// convert something to a currency value:
function toCurrency(v) {
	var t='',c,p,r;
	c=(round(toNumber(v))).toString();
	p=c.split('.');
	if (p.length<2) p[1]='00';
	if (p[1].length==1) p[1]=p[1]+'0';
	if (p[1].length>2) p[1]=p[1].substring(0,2);
	if (p[0].length==0) p[0]='0';
	for (c=p[0]; c.length>3;) {
		t=','+c.substr(c.length-3)+t;
		c=c.substr(0,(c.length-3));
		}
	r=c+t+'.'+p[1];
	if (r=='0.00') r='';
	return r;
	};

// 2011-10-06 11:40
// calculate the discount copied from fort carson:
//function calculateDiscount() {
//	var baseprice = toNumber($('#focushere').val());
//	var saletype = $('input[name=saletype]:checked').val();
	//var discount = baseprice * (saletype=='resale' ? 0.0075 : 0.01);
//	var discount = baseprice * (saletype=='resale' ? 0.0080 : 0.01);
//	var adjprice = baseprice - discount;
//	$('#focushere').val(toCurrency(baseprice));
//	$('#baseprice').text("$"+toCurrency(baseprice));
//	$('#discount').text("$"+toCurrency(discount));
//	$('#adjprice').text("$"+toCurrency(adjprice));
//}

// 2011-10-08 12:15 new, from Harley Puthuff <harley@yourshowcase.net>
function calculateDiscount() {
	var discounts = {
		newhome:	0.0080,
		resale:	 0.0060
		};
	var baseprice = toNumber($('#focushere').val());
	var saletype = $('input[name=saletype]:checked').val();
	var discount = baseprice * (saletype=='resale' ? discounts.resale : discounts.newhome);
	var adjprice = baseprice - discount;
	$('#focushere').val(toCurrency(baseprice));
	$('#baseprice').text("$"+toCurrency(baseprice));
	$('#discount').text("$"+toCurrency(discount));
	$('#adjprice').text("$"+toCurrency(adjprice));
}


function selectWin(source,h1,w1){
 newWin = window.open(source,'','height=' + h1 + ',width=' + w1 + ',top=10,left=0,status=no');
}


