// Widget for displaying April 2009 single family home sales figures
// By Timothy C. Barmann 5/26/2009

<!-- hide JavaScript

fieldHeading = new Array("City/Town",
					"Apr 08 sales",
					"Apr 09 sales",
					"Pct Change",
					"Jan-Apr 08 Sales",
					"Jan-Apr 09 sales",
					"Pct Change",
					"Apr 08 median price",
					"Apr 09 median price",
					"Pct change",
					"Jan-Apr 08 median price",
					"Jan-Apr 09 median price",
					"Pct change");



town = new Array();
town[town.length]= new Array("Barrington",15,12,-0.200,41,35,-0.146,440000,317500,-0.278,360000,305000,-0.153);
town[town.length]= new Array("Block Island",0,0,0,2,0,-1.000,0,0,0.000,0,0,0.000);
town[town.length]= new Array("Bristol",10,8,-0.200,41,22,-0.463,359500,234000,-0.349,315000,241000,-0.235);
town[town.length]= new Array("Burrillville",7,8,0.143,36,30,-0.167,225000,230000,0.022,229000,222500,-0.028);
town[town.length]= new Array("Central Falls",2,2,0.000,7,5,-0.286,0,0,0.000,100000,76000,-0.240);
town[town.length]= new Array("Charlestown",10,6,-0.400,26,22,-0.154,388500,251000,-0.354,310000,262500,-0.153);
town[town.length]= new Array("Coventry",23,22,-0.043,83,72,-0.133,230000,156599,-0.319,242000,196750,-0.187);
town[town.length]= new Array("Cranston",51,39,-0.235,183,148,-0.191,240000,181000,-0.246,231000,175000,-0.242);
town[town.length]= new Array("Cumberland",21,13,-0.381,83,45,-0.458,255000,243000,-0.047,294000,243000,-0.173);
town[town.length]= new Array("East Greenwich",10,5,-0.500,34,28,-0.176,515000,485000,-0.058,486000,313300,-0.355);
town[town.length]= new Array("East Providence",24,21,-0.125,99,67,-0.323,206250,200000,-0.030,210000,192000,-0.086);
town[town.length]= new Array("Exeter",5,0,-1.000,16,6,-0.625,392000,0,-1.000,315000,219250,-0.304);
town[town.length]= new Array("Foster",2,1,-0.500,8,10,0.250,0,0,0.000,270000,262500,-0.028);
town[town.length]= new Array("Glocester",8,9,0.125,16,26,0.625,330000,170000,-0.485,271300,197750,-0.271);
town[town.length]= new Array("Hopkinton",5,2,-0.600,19,7,-0.632,175000,0,-1.000,221000,125000,-0.434);
town[town.length]= new Array("Jamestown",5,1,-0.800,21,4,-0.810,574000,0,-1.000,574000,396500,-0.309);
town[town.length]= new Array("Johnston",18,20,0.111,50,68,0.360,229350,166450,-0.274,207500,173500,-0.164);
town[town.length]= new Array("Lincoln",12,10,-0.167,35,29,-0.171,253500,225750,-0.109,289000,217000,-0.249);
town[town.length]= new Array("Little Compton",0,0,0,9,6,-0.333,0,0,0.000,635000,380250,-0.401);
town[town.length]= new Array("Middletown",5,9,0.800,21,17,-0.190,383000,300000,-0.217,383000,280000,-0.269);
town[town.length]= new Array("Narragansett",9,9,0.000,36,37,0.028,315000,290000,-0.079,377500,302000,-0.200);
town[town.length]= new Array("Newport",16,11,-0.313,44,25,-0.432,353750,320000,-0.095,367500,328000,-0.107);
town[town.length]= new Array("North Kingstown",13,13,0.000,50,39,-0.220,525000,242000,-0.539,306250,301000,-0.017);
town[town.length]= new Array("North Providence",16,20,0.250,61,65,0.066,234000,168000,-0.282,212500,175000,-0.176);
town[town.length]= new Array("North Smithfield",3,7,1.333,20,19,-0.050,340000,240000,-0.294,299500,238000,-0.205);
town[town.length]= new Array("Pawtucket",29,28,-0.034,97,105,0.082,187500,155250,-0.172,197500,150000,-0.241);
town[town.length]= new Array("Portsmouth",10,11,0.100,47,30,-0.362,399750,265000,-0.337,360000,259500,-0.279);
town[town.length]= new Array("Providence",35,69,0.971,143,227,0.587,172500,87000,-0.496,170000,85000,-0.500);
town[town.length]= new Array("Richmond",4,2,-0.500,18,6,-0.667,227500,0,-1.000,240000,247950,0.033);
town[town.length]= new Array("Scituate",2,2,0.000,16,19,0.188,0,0,0.000,320000,252500,-0.211);
town[town.length]= new Array("Smithfield",8,12,0.500,34,36,0.059,333250,246500,-0.260,270000,217500,-0.194);
town[town.length]= new Array("South Kingstown",22,15,-0.318,74,45,-0.392,328500,275000,-0.163,327500,245000,-0.252);
town[town.length]= new Array("Tiverton",4,12,2.000,23,30,0.304,197000,194250,-0.014,248000,191000,-0.230);
town[town.length]= new Array("Warren",2,7,2.500,12,16,0.333,0,219000,0.000,274750,220500,-0.197);
town[town.length]= new Array("Warwick",64,76,0.188,239,230,-0.038,222000,160450,-0.277,215000,155700,-0.276);
town[town.length]= new Array("West Greenwich",5,2,-0.600,16,9,-0.438,350000,0,-1.000,330000,260000,-0.212);
town[town.length]= new Array("West Warwick",7,19,1.714,42,55,0.310,180000,140000,-0.222,204500,147500,-0.279);
town[town.length]= new Array("Westerly",15,10,-0.333,41,36,-0.122,305000,272450,-0.107,300000,259950,-0.134);
town[town.length]= new Array("Woonsocket",9,11,0.222,32,41,0.281,200000,130000,-0.350,200000,130000,-0.350);


function formatPct(number,decPlaces) {
	var pctChange = parseFloat(number) * 100;
    return(pctChange.toFixed(decPlaces)+'&#37;');  // append pct sign


}

function formatCurrency(num) {
	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));
	return (((sign)?'':'-') + '$' + num);
}




function popupTownData(index) {
	
	if ((typeof townWin == 'undefined') || townWin.closed)
		townWin= window.open('about:blank','','height=355,width=250');
//		townWin= window.open('','','height=355,width=250,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
//	townWin.document.open();
	var fields=fieldHeading.length;

	townWin.document.writeln('<html><head>');

	townWin.document.writeln('<style type="text/css">');
	townWin.document.writeln('table, th,td {border:1px #999999 solid; cellpadding:0; cellspacing:10px; border-collapse:collapse; background-color:#CCE6FF;}');
	townWin.document.writeln('.popup_credit { font-family:arial; font-size:9px; }');
	townWin.document.writeln('</style></head>');
	townWin.document.writeln('<body><div>');
	townWin.document.writeln('<table style="font-family:arial; font-size:12px;">');
	townWin.document.write('<tr><th colspan="2" ><h3>' + town[index][0] + '</h3></th></tr>');
	for (x=1;x<fields;x++) {

		townWin.document.write('<tr><td align="right"><b>' + fieldHeading[x] + ':</b></td><td> ');
		
		if ((x==3) || (x==6) || (x==9) || (x==12) )
			townWin.document.write(formatPct(town[index][x],1));
		
		else if ((x==7) || (x==8) || (x==10) || (x==11))
			townWin.document.write(formatCurrency(town[index][x]));
		
		else
			townWin.document.write(town[index][x]);
			
		townWin.document.writeln('</td></tr>');
	}
	townWin.document.writeln('</table>');
	townWin.document.writeln('<div class="popup_credit">Source: The Warren Group</div>');
	townWin.document.writeln('<p><a href="javascript: self.close();">Close</a></p>');
	townWin.document.writeln('</div></body></html>');
	townWin.focus();
	townWin.document.close();
	

}

// end hiding -->
