var fontsize = 13;
var savedFontSize = 13;
//	alert(savedFontSize);

function setFontSize() {
	if (savedFontSize)
	{
		savedFontSize = Get_Cookie("FontSize");
		if (parseInt(savedFontSize)) fontsize = savedFontSize;
		el = document.getElementsByTagName("body");
		if (el)
		{
			try
			{
				el[0].style.fontSize = fontsize + "px";	
			}
			catch (ex)
			{
				;
			}
			
		}
	}
}

function changeFontSize(direction) {
	el = document.getElementsByTagName("body");
	if (direction == 0)
	{
		el[0].style.fontSize = "13px";
		fontsize = 13;
	} else {
		if (fontsize >= 19 && direction > 0) return true;
		if (fontsize <= 11 && direction < 0) return true;
		fontsize = parseInt(fontsize) + parseInt(direction); 
		el[0].style.fontSize = fontsize + "px";
	}
	direction = 1 - direction;
	Set_Cookie("FontSize", fontsize, 1);
}


var models = [];
var curmodel = -1;
function loadPlan(modelid) {
	curmodel = modelid;
	model = models[modelid];
	disclaimer = "";
	if (model.id == 10)
	{
		disclaimer = "<div class='inner-disclaimer'>This lot has a corner condition. Actual house is a variation of rendering.</div>"
	}
	txt = "";
txt +=' <table cellpadding="0" cellspacing="0" border="0" class="model-popup">';
txt +=' 	<tr>';
txt +=' 		<td height="25" width="486" align="left" valign="top"><a href="#" onclick="prevModel();">PREVIOUS</a> | <a href="#" onclick="nextModel();">NEXT</a></td>';
txt +=' 		<td width="422" align="right" valign="top"><a href="#" onclick="closeWait();">CLOSE</a></td>';
txt +=' 	</tr>';
txt +=' 	<tr>';
txt +=' 		<td colspan="2" style="border: 1px solid #ccc;">';
txt +=' 			<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr>';
txt +=' 				<td width="386">';
txt +=' 						<table cellpadding="0" cellspacing="0" border="0" style="margin-left: 35px;">';
txt +=' 							<tr><td height="176" colspan="2" align="left" valign="bottom"><img style="margin-bottom: 22px;" src="'+model.logo+'"></td></tr>';
txt +=' 							<tr><td height="50" colspan="2" align="left" valign="top"><span class="model-title">'+model.name+'</span> <span class="elevation-title">(ELEVATION '+model.elevation+')</span></td></tr>';
txt +=' 							<tr><td height="25" width="143" align="left" valign="top"><b>HOME TYPE</b></td><td valign="top" height="25">'+model.model+'</td></tr>';
txt +=' 							<tr><td height="25" width="143" align="left" valign="top"><b>BEDROOMS</b></td><td valign="top" height="25">'+model.bedrooms+'</td></tr>';
txt +=' 							<tr><td height="25" width="143" align="left" valign="top"><b>SQ. FT.</b></td><td valign="top" height="25">'+model.sqft+'</td></tr>';
txt +=' 							<tr><td height="25" width="143" align="left" valign="top"><b>LOT SIZE</b></td><td valign="top" height="25">'+model.lot+'\'</td></tr>';
txt +=' 							<tr><td height="25" width="143" align="left" valign="top"><b>PRICE</b></td><td valign="top" height="25">'+formatCurrency(model.price)+'</td></tr>';
txt +=' 							<tr><td height="75" colspan="2" valign="bottom" align="left"><a href="'+model.pdf+'"><img src="images/icon-print-2.png" style="margin-right: 30px;"></a><a href="'+model.pdf+'"><img src="images/icon-download-2.png"></a></td></tr>';
txt +=' 							<tr><td height="35" colspan="2"></td></tr>';
txt +=' 						</table>';
txt +=' 				</td>';
txt +=' 				<td align="right" valign="top"><div style="position: relative;"><a href="'+model.image.replace(".", "_l.")+'" target="_blank"><img style="margin-top: 39px; margin-right: 40px; height: 380px;" src="'+model.image+'"></a><div style="color :#000; position: absolute; right: 50px; bottom: 10px; background-color: #fff; background-image: url(../images/plus-black.png); background-repeat: no-repeat; opacity: 0.7; filter: alpha(opacity=70); padding:5px 0px 5px 0px; cursor: pointer; width: 80px; font-size: 13px; text-align: center; font-weight: bold; ">ENLARGE</div></div>'+disclaimer+'</td>';
txt +=' 			</tr>';
txt +=' 			</table>';
txt +=' 		</td>';
txt +=' ';
txt +=' 	</tr>';
txt +=' 	<tr>';
txt +=' 		<td><div class="disclaimer-plans">Prices are subject to change. Premiums and options are in addition to listed price.</div></td>';
txt +=' 		<td align="left" height="42" valign="bottom"></td>';
txt +=' 	</tr>	';
txt +=' 	</table>';

showOverlay();
box(txt);

}

function showModelHomes() {
	txt = "<img src='images/model-homes.jpg' onclick='closeWait();' style='cursor: pointer;'>";
	showOverlay();
	box(txt);

}

function nextModel() {
	curmodel++;
	if (curmodel >= models.length) curmodel = 0;
	loadPlan(curmodel);
}

function prevModel() {
	curmodel --;
	if (curmodel >= models.length) curmodel = models.length - 1;
	loadPlan(curmodel);
}

function number_format(amt, decs) {
	if (!decs) decs = 0;
	return Math.round(amt * Math.pow(10,decs)) / Math.pow(10,decs);
}

function formatCurrency(num, decs) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
if (decs) return (((sign)?'':'-') + '$' + num + '.' + cents); else return (((sign)?'':'-') + '$' + num); 
}

function downloadDocument(doc) {
	window.open(doc, "download");
}
