/*******************************************************************************
  smogwatch.js

  Some useful JavaScript functions for generic smogwatch pages
*******************************************************************************/

function openMap(url, width, height) {
	popMapWindow = window.open(
		url,
		'MapWin',
		"toolbar=no,width=" + (width + 20) +",height=" + (height + 20) + ",status=no,scrollbars=no,resize=no,menubar=no"
		);
}

function openAQIchart() {
	AQIWindow = window.open(
		'AQIchart.html',
		'AQIwin',
		"toolbar=no,width=420,height=540,status=no,scrollbars=no,resize=no,menubar=no"
		);
}

function fillUnits() {

	// shorthand variables
	var ubox = document.frmHist.Unit;
	var selParam = document.frmHist.ParamID.options[document.frmHist.ParamID.selectedIndex].value;

	var ugm3 = "\u00b5g/m\u00b3";
	//var ugm3 = "ug/m3";

	// clear the box
	ubox.options.length = 0;

	// Fill in the options we want
	switch(selParam) {

		case "O3_8hrAvg":
		case "O3_8hrSur":
		case "6":
			ubox.options[ubox.options.length] = new Option("AQI", "AQI", false, false);
		case "1":
		case "O3":
			ubox.options[ubox.options.length] = new Option("ppb", "ppb", true, false);
			break;

		case "PM25_24hrAvgRunning":
		case "7":
			ubox.options[ubox.options.length] = new Option("AQI", "AQI", false, false);
		case "PM25":
		case "2":
			ubox.options[ubox.options.length] = new Option(ugm3, "ug/m3", true, false);
			break;

	}

}

function advanceDay(n) {
	var datebox = document.dateForm.date;
	var date = Date.parse(datebox.value);
	var oneday = 86400000;
	
	// Add the specified number of days
	var d = new Date(date + (n * oneday));

	// Set date box
	datebox.value = (d.getMonth() + 1) + "/" + d.getDate() + "/" + d.getFullYear();

	document.dateForm.submit();
}
