// JavaScript Document

var m_state;
var m_date = '091116';
//'071008';
var m_start = '060501';
var isEval = false;
var isIE, isMozilla;
var m_prev = '-9999';

//var start_date = new Date(2006, 4, 8);
//var end_date = new Date(2007, 9, 9);
var leftDate, rightDate;
var m_xml;
var archType = 0;

function initMain() {
	//read the post string
	
	try {
		//UNCOMMENT THIS TO TURN THE SURVEY BACK ON!!!
		var args = new Object();
		var query = location.search.substring(1);
		var vals = query.split(",");
		if (vals.length > 0) {
			for (var i = 0; i < vals.length; i++) {
				if (i == 0) {
					if (vals[i] == 'EV') {
						isEval = true;
					} else {
						isEval = false;
					}
				}
			}
		} else {
			isEval = false;
		}
				
		setBrowser();
		
		//calculate the date
		/*var today = new Date(2006, 5, 6); //new Date();
		var numdays = DayDiff(today, start_date);
		var numweeks = (numdays-(numdays%=7))/7;
		var biweeks = (numweeks-(numweeks%=2))/2;
		
		//recalc the date of the files to the first tuesday of the biweek
		today = dateAdd(start_date, (biweeks * 14) + 1);
		
		//alert(today);
		var dy = today.getDay();
		switch (dy) {
			case 0:
				offset = -2;
				break;
			case 1:
				offset = -1;
				break;
			case 2:
				offset = 0;
				break;
			case 3:
				offset = 1;
				break;
			case 4:
				offset = 2;
				break;
			case 5:
				offset = 3;
				break;
			case 6:
				offset = 4;
				break;
			default:
				offset = 0;
				break;
		}	
		//set to tuesday?
		today = dateAdd(today, offset);
		
		//alert(today);*/
		
		setState15Map(m_date, 0, 'mapImage');
		setDnld15(m_date, 'mapDownload', 0);

		//and set the descriptive text
		//if (isEval == false) {
			//setTextDesc(m_date, 'desc');
		//}
		var title = "Vegetation Drought Response Index";
		if (isEval) {
			title += ' (Evaluation Site)';
		}
		document.getElementById('title').innerHTML = title;
		
		//add the new comments for the week
		//if (!isIE) {
			//setComments(m_date, 'comments', 'txtComment');
		//}
		
	
	} catch (e) {
		window.location.href = '../error.htm';
	}
}

function initState() {
	try {
		setBrowser();
		
		var args = new Object();
		var query = location.search.substring(1);
		var vals = query.split(",");
		if (vals.length > 0) {
			for (var i = 0; i < vals.length; i++) {
				if (i == 0) {
					m_state = vals[i];
				} else if (i == 1) {
					//UNCOMMENT TO TURN THE SURVEY BACK ON!!
					if (vals[i] == 'EV') {
						isEval = true;
					} else {
						isEval = false;
					}
				}
			}
		} else {
			isEval = false;
		}
		
		setStateMap(0,  m_date, 'mapImage', m_state);
		setDnldSt(m_date, 'mapDownload', m_state, 0);
		
		var url;
		var theHtml = setQuadRef(m_state, isEval);
		if (isEval) {
			//include the ref map
			theHtml += '<br><input name="Survey" type="button" value="Evaluation Form" onClick="loadSurvey();">' + ' <input name="SurveyInst" type="button" value="Evaluation Instructions" onClick="loadSurveyInst();">';
			url = 'VegDRI_Main.htm?EV';
		} else {
			url = 'VegDRI_Main.htm';
		}
		document.getElementById('refMap').innerHTML = theHtml;
		document.getElementById('returnLnk').innerHTML = '<a href="' + url + '">Return to the 48 State map</a>';
		
		var stName = setState(m_state.toUpperCase());
		//document.getElementById('title').innerHTML = 'Vegetation Drought Response Index for ' + stName;
		
		var title = 'Vegetation Drought Response Index for ' + stName;
		if (isEval) {
			title += ' (Evaluation Site)';
		}
		document.getElementById('title').innerHTML = title;
	} catch (e) {
		alert(e);
		window.location.href = '../error.htm';
	}
}

function initQuad() {
	try {
		setBrowser();
		
		var quad;
		var args = new Object();
		var query = location.search.substring(1);
		var vals = query.split(",");
		for (var i = 0; i < vals.length; i++) {
			if (i == 0) {
				m_state = vals[i];
			} else if (i == 1) {
				quad = vals[i];
			} else if (i == 2) {
				//UNCOMMENT TO TURN SURVEY BACK ON
				if (vals[i] == 'EV') {
					isEval = true;
				} else {
					isEval = false;
				}
			}
		}
		
		setQuadMap(0, m_state, quad, 'mapImage', m_date);
		
		setDnldQuad(0, m_state, quad, 'mapDownload', m_date);
		var url;
		var s = setQuadRef(m_state, isEval);
		
		var stName = setState(m_state.toUpperCase());
		var title = 'Vegetation Drought Response Index for ' + stName + ', Quad ' + quad;
		
		if (isEval) {
			s += '<br><input name="Survey" type="Button" value="Evaluation Form" onClick="loadSurvey();"> <input name="SurveyInst" type="button" value="Evaluation Instructions" onClick="loadSurveyInst();">';
			url = 'VegDRI_State.htm?'+m_state.toUpperCase()+',EV';
			title += ' (Evaluation Site)';
		} else {
			url = 'VegDRI_State.htm?'+m_state.toUpperCase();
		}
		document.getElementById('refMap').innerHTML = s;
		document.getElementById('returnLnk').innerHTML = '<a href="' + url + '">Return to the state map</a>';
		
		document.getElementById('title').innerHTML = title;
	} catch (e) {
		window.location.href = '../error.htm';
	}	
}

function initTable() {
	try {
		setBrowser();
		
		var state;
		var args = new Object();
		var query = location.search.substring(1);
		var vals = query.split(",");
		for (var i = 0; i < vals.length; i++) {
			if (i == 0) 
				m_state = vals[i];
		}
		
		state = setState(m_state.toUpperCase());
		
		var xslFile = 'scripts/vdri_tables.xsl';
		var xmlFile = 'xml/vdri_'+ m_state.toUpperCase() +'.xml';
		
		var str
			xml = loadFromUrl(xmlFile);
			xsl = loadFromUrl(xslFile);
			
			var processor = new XSLTProcessor();
			processor.importStylesheet(xsl);
			processor.setParameter("", "aoiSel", "all");
			var outDoc = processor.transformToDocument(xml);  
			var xmlSerializer = new XMLSerializer();  
			var xmlString = xmlSerializer.serializeToString(outDoc);
			str = xmlString ;
		document.getElementById('tab').innerHTML = str;
		document.getElementById('title').innerHTML = 'VegDRI Statistics for ' + state + ' (Percent Area)';
	} catch (e) {
		window.location.href = '../error.htm';
	}
}

function initArchive() {
	
	try {
	
		setBrowser();
		document.getElementById('selState').selectedIndex = 0;
		
		var syr = m_date.substr(0, 2);
		var smo = m_date.substr(2, 2);
		var sdy = m_date.substr(4, 2);
		
		var yr = 2000 + parseInt(syr,10);
		var dy = parseInt(sdy,10);
		var mo = parseInt(smo,10);
		mo -= 1;
		
		var pDate = new Date(yr, mo, dy);
		
		//calc doy
		var doy = calcDOY(yr, mo + 1, dy);
		
		//calc the biweek
		var bw = Math.round(doy / 14);
		
		//set up the images
		var pdf;
		var url = 'jpgs/all.jpg';
		document.getElementById('right-image').innerHTML = '<img src="'+url+'" width="460" height="417" >';
		
		//now get the previous biweek
		var prevDate;
		var oDate;
		if (m_prev == '-9999') {
			prevDate = returnPreviousBiweek(pDate);

			if (prevDate.getDay() != 1) {
				var offset = 0;
				switch (prevDate.getDay()) {
					case 0:
						offset = 1;
						break;
					case 2:
						offset = -1;
						break;
					case 3:
						offset = -2;
						break;
					case 4:
						offset = -3;
						break;
					case 5:
						offset = -4;
						break;
					case 6:
						offset = -5;
						break;
					default:
						alert("Cannot determine previous date.");
						break;
				}
				prevDate = dateAdd(prevDate, offset)
			} 
			
			var oyr = prevDate.getFullYear().toString().substr(2,2);
			var osmo = prevDate.getMonth() + 1;
			var omo;
			if (osmo < 10) {
				omo = '0' + osmo;
			} else {
				omo = osmo;
			}
			var osdy = prevDate.getDate();
			var ody;
			if (osdy < 10) {
				ody = '0' + osdy;
			} else {
				ody = osdy;
			}
			oDate = oyr + omo + ody;
		} else {
			if (m_prev != '-9999') {
				oDate = m_prev;
			} else {
				throw('Unable to identify previous biweek!');
			}
		}
		
		
		//now set up the comboboxes
		var xslFile = 'scripts/vegdri_dropdown.xsl';
		var xmlFile = 'xml/vdri_22State.xml';
		xml = loadFromUrl(xmlFile);
			xsl = loadFromUrl(xslFile);

		m_xml = xml;
		
		rightDate = m_date; 
		try {
			document.getElementById('right-date').innerHTML = createCombo(xml, xsl, m_date, m_date, 'updateRightArchive');
		} catch (e) {
			//alert(e);
		}	
		
		//set up the downloads
		url = 'archive/vegdri/' + m_date + '/pngs/all_' + m_date + '.png';
		pdf = 'archive/vegdri/' + m_date + '/pdfs/all_' + m_date + '.pdf';
		document.getElementById('right-dld').innerHTML = 'Download <a href="' + url + '">image</a> or <a href="' + pdf + '">PDF</a>';
		
		//add the archive text
		if (!isIE) {
			setComments(m_date, 'right-text', 'txtCommentRight');
		}
				
		leftDate = oDate;
		
		if (m_start != m_date) {
		
			url = 'archive/vegdri/' + oDate +'/jpgs/all_' + oDate + '.jpg';
			document.getElementById('left-image').innerHTML = '<img src="'+url+'" width="460" height="417" >';
			
			url = 'archive/vegdri/' + oDate + '/pngs/all_' + oDate + '.png';
			pdf = 'archive/vegdri/' + oDate + '/pdfs/all_' + oDate + '.pdf';
			document.getElementById('left-dld').innerHTML = 'Download <a href="' + url + '">image</a> or <a href="' + pdf + '">PDF</a>';	
		
			try {
				//if (isIE) {
					document.getElementById('left-date').innerHTML = createCombo(xml, xsl, oDate, oDate, 'updateLeftArchive');
					//alert(createCombo(m_xml, xsl, oDate, oDate, 'updateLeftArchive'));
				//} else {
					//document.getElementById('left-date').innerHTML = parseCombo(m_xml, oDate, oDate, 'updateLeftArchive');
				//}
			} catch (ex) {
				alert(ex);
			}
			if (!isIE) {
				setComments(oDate, 'left-text', 'txtCommentLeft');
			}
			
		}

	} catch (e) {
		window.location.href = '../error.htm';
	}
}

function initChange() {
	try {
		setBrowser();
		
		//var syr = m_date.substr(0, 2);
		//var sbw = m_date.substr(3, 2);
		//var bw = parseInt(sbw);
		//var yr = 2000 + parseInt(syr);
		
		var syr = m_date.substr(0, 2);
		var smo = m_date.substr(2, 2);
		var sdy = m_date.substr(4, 2);
		
		var yr = 2000 + parseInt(syr,10);
		var dy = parseInt(sdy,10);
		var mo = parseInt(smo,10);
		
		var pDate = new Date(yr, mo - 1, dy);
		var lDate = dateAdd(pDate, -14);
		
		//calc doy
		var cdoy = calcDOY(pDate.getYear(), pDate.getMonth() + 1, pDate.getDate());
		var pdoy = calcDOY(lDate.getYear(), lDate.getMonth() + 1, lDate.getDate());
		
		//calc the biweek
		var cbw = Math.round(cdoy / 14);
		var pbw = Math.round(pdoy / 14);
		
		var name;
		/*if (bw <= 9) {
			//no previous biweek so no map
			document.getElementById('mapImage').innerHTML = '<p>No previous biweek for this date.</p>';
		} else {*/
			//var pbw  = bw- 1;
			var spbw = pbw.toString();
			if (pbw < 10) {
				spbw = '0' + spbw;
			}
			
			var sbw = cbw;
			if (cbw < 10) {
				sbw = '0' + cbw;
			}
			
			//url = 'pngs/all_vchg_pbw' + spbw + '_cbw' + sbw + '_y' + syr + '_' + m_date + '.png';
			name = 'all_vchg_pbw' + spbw + '_cbw' + sbw + '_y' + syr;
			setState15Chg('mapImage', 'pngs/' + name + '.png');
			setDnldChg(name, 'mapDownload', m_date);
		//}
	} catch (e) {
		window.location.href = '../error.htm';
	}
}

function initChangeState() {
	try {
		setBrowser();
		
		var state;
		var args = new Object();
		var query = location.search.substring(1);
		var vals = query.split(",");
		for (var i = 0; i < vals.length; i++) {
			if (i == 0) 
				m_state = vals[i];
		}
		
		/*var syr = m_date.substr(0, 2);
		var sbw = m_date.substr(3, 2);
		var bw = parseInt(sbw);
		var yr = 2000 + parseInt(syr);*/
		
		var syr = m_date.substr(0, 2);
		var smo = m_date.substr(2, 2);
		var sdy = m_date.substr(4, 2);
		
		var yr = 2000 + parseInt(syr,10);
		var dy = parseInt(sdy,10);
		var mo = parseInt(smo,10);
		mo -= 1;
		
		var pDate = new Date(yr, mo, dy);
		
		//calc doy
		var doy = calcDOY(yr, mo + 1, dy);
		
		//calc the biweek
		var bw = Math.round(doy / 14);
		
		var name;
		if (bw <= 9) {
			//no previous biweek so no map
			document.getElementById('mapImage').innerHTML = '<p>No previous biweek for this date.</p>';
		} else {
			var pbw  = bw - 1;
			var spbw = pbw.toString();
			if (pbw < 10) {
				spbw = '0' + spbw;
			}
			
			var sbw = bw;
			if (bw < 10) {
				sbw = '0' + bw;
			} 
			//url = 'pngs/all_vchg_pbw' + spbw + '_cbw' + sbw + '_y' + syr + '_' + m_date + '.png';
			name = m_state.toLowerCase() + '_vchg_pbw' + spbw + '_cbw' + sbw + '_y' + syr;
			setStateChg('mapImage', 'pngs/' + name + '.png');
			setDnldChg(name, 'mapDownload', m_date);
		}
		document.getElementById('returnLnk').innerHTML = '<a href="VegDRI_change.htm">Return to the 48 State map</a>';
	} catch (e) {
		window.location.href = '../error.htm';
	}
}

function changeAoi(aoi) {
	//check the post param count
	var type;
	var quad;
	var args = new Object();
	var query = location.search.substring(1);
	var vals = query.split(",");
	if (vals.length==0) {
		type = 0;
	} else if (vals.length == 1) {
		if ((vals[0] == "") || (vals[0] == 'EV')) {
			type = 0;
		} else {
			type = 1;
		}
	} else if (vals.length == 2) {
		if (vals[vals.length - 1] == 'EV') {
			type = 1;
		} else { 
			type = 2;
			quad = vals[1];
		}
	} else if (vals.length == 3) {
		type = 2;
		quad = vals[1];
	}
	//alert(vals.length + ' = '+ vals[0]);
	if (type == 0) {
		setState15Map(m_date, aoi, 'mapImage');
		setDnld15(m_date, 'mapDownload', aoi);
	} else if (type == 1) { 
		setStateMap(aoi,  m_date, 'mapImage', m_state);
		setDnldSt(m_date, 'mapDownload', m_state, aoi)
	} else if (type == 2) {
		setQuadMap(aoi, m_state, quad, 'mapImage', m_date);
		setDnldQuad(aoi, m_state, quad, 'mapDownload', m_date)
	}
}

function changeChgMap(sel) {
	//check the post data again to see if it's a state
	var state;
	var args = new Object();
	var query = location.search.substring(1);
	var vals = query.split(",");
	for (var i = 0; i < vals.length; i++) {
		if (i == 0) 
			state = vals[i];
	}
	
	if (state == '') {
		state = 'all';
	}
	
	/*var syr = m_date.substr(0, 2);
	var sbw = m_date.substr(3, 2);
	var bw = parseInt(sbw);
	var yr = 2000 + parseInt(syr);*/
	
	var syr = m_date.substr(0, 2);
	var smo = m_date.substr(2, 2);
	var sdy = m_date.substr(4, 2);
	
	var yr = 2000 + parseInt(syr,10);
		var dy = parseInt(sdy,10);
		var mo = parseInt(smo,10);
		mo -= 1;
	
	var pDate = new Date(yr, mo, dy);
	
	//calc doy
	var doy = calcDOY(yr, mo + 1, dy);
	
	//calc the biweek
	var bw = Math.round(doy / 14);
	
	var sbw = bw;
	if (bw < 10) {
		sbw = '0' + bw;
	}
	
	var name;
	if (sel == -2) {
		if (bw <= 9) {
			document.getElementById('mapImage').innerHTML = '<p>No previous biweek for this date.</p>';
		} else {
			var pbw  = bw - 1;
			var spbw = pbw.toString();
			if (pbw < 10) {
				spbw = '0' + spbw;
			}
			//url = 'pngs/all_vchg_pbw' + spbw + '_cbw' + sbw + '_y' + syr + '_' + m_date + '.png';
			name = state.toLowerCase() + '_vchg_pbw' + spbw + '_cbw' + sbw + '_y' + syr;
			if (state == 'all') {
				setState15Chg('mapImage', 'pngs/' + name + '.png');
			} else {  
				setStateChg('mapImage', 'pngs/' + name + '.png');
			}
			
		}
	} else if (sel == -365) {
		//the yr
		var pyr = yr - 1;
		var spyr = pyr.toString().substr(2, 2);
		name = state.toLowerCase() + '_vchg_bw' + sbw + '_p' + spyr + '_c' + syr;
		if (state == 'all') {
			setState15Chg('mapImage', 'pngs/' + name + '.png');
		} else { 
			setStateChg('mapImage', 'pngs/' + name + '.png');
		}
		
		
	}
	
	setDnldChg(name, 'mapDownload', m_date);
}

function setState15Map(pDate, aoi, divid) {
	var tag = '';
	if (isEval) {
		tag = ',EV';
	}
	var url;
	
	if (aoi == 0) {
		//url = 'pngs/all_' + pDate + '.png';
		url = 'pngs/all.png';
	} else if (aoi == 1) {
		//url = 'pngs/range_' + pDate + '.png';
		url = 'pngs/range.png';
	} else if (aoi == 2) {
		//url = 'pngs/crop_' + pDate + '.png';
		url = 'pngs/crop.png';
	}
	
	//var h = '<img src="' + url + '" width="670" height="498" border="0" usemap="#Map">';
	var h = '<img src="' + url + '" width="792" height="612" border="0" usemap="#Map">';

	h += '<map name="Map">';
	h += '<area shape="poly" coords="151,98,140,144,142,151,91,143,85,138,73,140,72,130,63,124,55,121,61,75" href="VegDRI_State.htm?WA'+tag+'" alt="Washington">';
    h += '<area shape="poly" coords="142,152,145,155,131,175,135,178,126,216,37,191,38,178,61,124,71,131,75,141,85,138,95,145" href="VegDRI_State.htm?OR'+tag+'" alt="Oregon">';
    h += '<area shape="poly" coords="89,207,37,193,25,218,50,332,61,360,93,375,132,377,133,361,140,353,134,338,78,258" href="VegDRI_State.htm?CA'+tag+'" alt="California">';
    h += '<area shape="poly" coords="162,100,152,98,141,147,146,154,133,174,135,180,127,216,200,228,206,186,203,182,181,185,174,162,169,165,165,162,173,144,160,124" href="VegDRI_State.htm?ID'+tag+'" alt="Idaho">';
    h += '<area shape="poly" coords="163,223,90,207,80,258,136,339,137,322,142,321,144,324,147,323" href="VegDRI_State.htm?NV'+tag+'" alt="Nevada">';
    h += '<area shape="poly" coords="216,317,150,308,147,323,142,323,140,320,139,322,136,338,141,352,134,363,133,376,128,381,177,412,208,414" href="VegDRI_State.htm?AZ'+tag+'" alt="Arizona">';
    h += '<area shape="poly" coords="200,229,162,223,149,307,216,317,223,249,198,247" href="VegDRI_State.htm?UT'+tag+'" alt="Utah">';
    h += '<area shape="poly" coords="297,323,217,317,208,414,218,414,220,409,244,409,244,404,295,407" href="VegDRI_State.htm?NM'+tag+'" alt="New Mexico">';
    h += '<area shape="poly" coords="294,117,162,100,160,125,173,144,166,161,170,165,174,159,182,184,203,182,206,187,207,179,292,186" href="VegDRI_State.htm?MT'+tag+'" alt="Montana">';
    h += '<area shape="poly" coords="290,186,208,178,199,246,288,254" href="VegDRI_State.htm?WY'+tag+'" alt="Wyoming">';
    h += '<area shape="poly" coords="314,253,224,250,217,317,311,323" href="VegDRI_State.htm?CO'+tag+'" alt="Colorado">';
    h += '<area shape="poly" coords="340,332,298,331,296,407,245,405,245,409,268,446,292,461,305,448,317,453,319,451,350,503,383,515,387,509,383,489,431,449,432,430,435,420,426,404,423,381,407,372,367,375,341,364" href="VegDRI_State.htm?TX'+tag+'" alt="Texas">';
    h += '<area shape="poly" coords="413,320,298,322,298,330,339,332,341,363,371,374,406,372,418,377" href="VegDRI_State.htm?OK'+tag+'" alt="Oklahoma">';
    h += '<area shape="poly" coords="314,271,399,270,408,273,412,284,413,319,313,322" href="VegDRI_State.htm?KS'+tag+'" alt="Kansas">';
    h += '<area shape="poly" coords="290,219,359,221,381,225,396,260,401,271,314,271,315,255,289,252" href="VegDRI_State.htm?NE'+tag+'" alt="Nebraska">';
    h += '<area shape="poly" coords="381,170,293,169,289,220,361,220,376,222,382,227" href="VegDRI_State.htm?SD'+tag+'" alt="South Dakota">';
    h += '<area shape="poly" coords="296,116,371,118,381,169,294,168" href="VegDRI_State.htm?ND'+tag+'" alt="North Dakota">';
    h += '<area shape="poly" coords="374,118,393,117,395,109,403,120,459,127,473,121,432,151,431,167,427,176,427,187,447,199,449,206,383,211" href="VegDRI_State.htm?MN'+tag+'" alt="Minnesota">';
    h += '<area shape="poly" coords="385,211,382,226,397,261,447,255,451,260,457,250,454,243,463,238,464,228,450,215,450,208" href="VegDRI_State.htm?IA'+tag+'" alt="Iowa">';
    h += '<area shape="poly" coords="397,261,447,257,451,260,452,271,465,283,470,283,469,294,482,303,486,314,482,332,470,332,476,325,416,329,413,287,405,273" href="VegDRI_State.htm?MO'+tag+'" alt="Missouri">';
    h += '<area shape="poly" coords="415,331,474,325,471,332,482,333,466,374,467,382,425,388,426,379,419,379" href="VegDRI_State.htm?AR'+tag+'" alt="Arkansas">';
    h += '<area shape="poly" coords="426,388,467,385,472,396,464,419,489,417,495,431,506,444,504,452,467,456,432,444,434,429,436,421,427,404" href="VegDRI_State.htm?LA'+tag+'" alt="Louisiana">';
    h += '<area shape="poly" coords="507,347,478,350,467,372,467,385,473,396,465,419,491,417,496,431,508,444,512,439" href="VegDRI_State.htm?MS'+tag+'" alt="Mississippi">';
    h += '<area shape="poly" coords="527,423,522,413,559,407,562,410,599,406,604,408,603,402,613,401,644,441,648,485,628,509,603,508,627,491,600,455,596,435,578,421,560,431" href="VegDRI_State.htm?FL'+tag+'" alt="Florida">';
    h += '<area shape="poly" coords="542,340,508,346,512,427,525,425,522,413,558,406,555,391,558,384" href="VegDRI_State.htm?AL'+tag+'" alt="Alabama">';
    h += '<area shape="poly" coords="591,303,502,317,504,321,486,323,478,348,558,337,559,334,581,316" href="VegDRI_State.htm?TN'+tag+'" alt="Tennessee">';
    h += '<area shape="poly" coords="543,342,573,335,573,338,582,344,603,362,615,376,613,400,603,401,603,407,564,409,557,392,558,384" href="VegDRI_State.htm?GA'+tag+'" alt="Georgia">';
    h += '<area shape="poly" coords="642,338,623,327,609,330,605,327,592,328,577,332,574,336,619,378,640,354" href="VegDRI_State.htm?SC'+tag+'" alt="South Carolina">';
    h += '<area shape="poly" coords="670,281,590,302,589,309,560,336,574,336,587,327,605,326,610,330,622,328,644,339,661,336,681,301" href="VegDRI_State.htm?NC'+tag+'" alt="North Carolina">';
    h += '<area shape="poly" coords="453,142,434,153,431,167,428,176,427,187,447,199,450,209,451,217,458,222,494,218,491,191,492,178,499,168,494,168,485,182,490,172,485,163,476,160,458,158,452,151" href="VegDRI_State.htm?WI'+tag+'" alt="Wisconsin">';
    h += '<area shape="poly" coords="482,130,454,150,458,158,478,160,486,166,491,171,497,166,499,185,502,213,503,228,555,220,564,200,560,164,536,133" href="VegDRI_State.htm?MI'+tag+'" alt="Michigan">';
    h += '<area shape="poly" coords="494,219,460,222,465,228,464,235,456,243,458,250,451,261,452,269,464,282,470,283,470,293,483,302,487,313,491,309,495,312,497,306,500,306,501,291,506,281,503,272,499,230" href="VegDRI_State.htm?IL'+tag+'" alt="Illinois">';
    h += '<area shape="poly" coords="500,231,532,225,541,274,534,277,529,291,521,295,512,298,502,297,506,284,505,277" href="VegDRI_State.htm?IN'+tag+'" alt="Indiana">';
    h += '<area shape="poly" coords="571,275,566,270,551,273,544,268,541,269,541,275,536,277,529,293,512,298,503,299,501,306,496,308,497,312,490,311,489,314,486,322,503,322,502,317,565,307,582,288" href="VegDRI_State.htm?KY'+tag+'" alt="KY">';
    h += '<area shape="poly" coords="657,226,653,229,660,250,668,248" href="VegDRI_State.htm?DE'+tag+'" alt="Deleware">';
    h += '<area shape="poly" coords="694,175,689,176,693,189,700,186" href="VegDRI_State.htm?RI'+tag+'" alt="Rhode Island">';
    h += '<area shape="poly" coords="669,183,689,177,691,188,673,198" href="VegDRI_State.htm?CT'+tag+'" alt="Connecticut">';
    h += '<area shape="poly" coords="667,171,668,183,692,175,697,178,700,184,718,182,714,165,699,162,696,159,689,164" href="VegDRI_State.htm?MA'+tag+'" alt="Massachusetts">';
    h += '<area shape="poly" coords="654,134,675,126,676,136,674,142,676,168,668,170" href="VegDRI_State.htm?VT'+tag+'" alt="Vermont">';
    h += '<area shape="poly" coords="679,120,674,121,677,137,675,141,677,167,694,159,694,153,691,152" href="VegDRI_State.htm?NH'+tag+'" alt="New Hampshire">';
    h += '<area shape="poly" coords="669,202,657,199,654,213,663,219,658,228,663,236,667,238,676,226" href="VegDRI_State.htm?NJ'+tag+'" alt="New Jersey">';
    h += '<area shape="poly" coords="683,78,680,101,679,117,692,151,697,154,714,129,729,106,713,95,702,73" href="VegDRI_State.htm?ME'+tag+'" alt="Maine">';
    h += '<area shape="poly" coords="606,244,608,252,625,240,641,248,638,258,646,261,656,262,660,275,666,276,669,250,660,251,656,240,653,230" href="VegDRI_State.htm?MD'+tag+'" alt="Maryland">';
    h += '<area shape="poly" coords="557,220,534,224,541,267,545,267,550,272,565,270,573,275,579,263,590,250,589,232,583,208" href="VegDRI_State.htm?OH'+tag+'" alt="Ohio">';
    h += '<area shape="poly" coords="583,288,569,307,667,282,665,277,655,276,656,262,643,262,639,258,639,250,631,244,629,247,621,245,614,264,606,264,604,284,586,291" href="VegDRI_State.htm?VA'+tag+'" alt="Virginia">';
    h += '<area shape="poly" coords="591,241,589,250,574,276,586,291,602,284,606,264,609,263,613,267,622,246,628,248,631,245,626,242,608,252,606,245" href="VegDRI_State.htm?WV'+tag+'" alt="West Virginia">';
    h += '<area shape="poly" coords="590,202,584,207,592,243,655,231,661,221,655,214,656,200,653,196,647,192,593,207" href="VegDRI_State.htm?PA'+tag+'" alt="Pennsylvania">';
    h += '<area shape="poly" coords="653,134,637,139,624,160,626,170,622,175,595,181,600,190,592,201,594,206,647,190,657,199,669,202,674,211,698,193,690,191,670,202,668,184,666,170" href="VegDRI_State.htm?NY'+tag+'" alt="New York">';
	h += '</map></img>';
	document.getElementById(divid).innerHTML = h;
}

function setDnld15(pDate, divid, aoi) {
	var saoi;
	if (aoi == 0) {
		saoi = 'all';
	} else if (aoi == 1) {
		saoi = 'range';
	} else if (aoi == 2) {
		saoi = 'crop';
	}
	
	var url = 'archive/vegdri/'+pDate+'/pngs/'+saoi+'_' + pDate + '.png';
	//var url = 'pngs/'+saoi+ '.png';
	var str = '<p>To download the image, right-click <br>';
	str += '<a href="'+url+'">here</a> and select "Save target as...".<br></p>';
	
	url = 'archive/vegdri/'+pDate+'/pdfs/'+saoi+'_' + pDate + '.pdf';
	//url = 'pdfs/'+saoi+ '.pdf';
	str += '<p>To download the pdf, right-click <br>';
	str += '<a href="'+url+'">here</a> and select "Save target as...".<br></p>';
	
	document.getElementById(divid).innerHTML = str;
}

function setStateMap(aoi, pDate, divid, state) {
	var url;
	
	if (aoi == 0) {
		//url = 'pngs/all_' + state.toUpperCase() + '_' + pDate + '.png';
		url = 'pngs/all_' + state.toUpperCase() + '.png';
	} else if (aoi == 1) {
		//url = 'pngs/range_' + state.toUpperCase() + '_' + pDate + '.png';
		url = 'pngs/range_' + state.toUpperCase() + '.png';
	} else if (aoi == 2) {
		//url = 'pngs/crop_' + state.toUpperCase() + '_' + pDate + '.png';
		url = 'pngs/crop_' + state.toUpperCase() + '.png';
	}
	 
	document.getElementById(divid).innerHTML = '<img src="' + url + '" width="670" height="498" border="0"/>';
}

function setDnldSt(pDate, divid, state, aoi) {
	var saoi;
	if (aoi == 0) {
		saoi = 'all';
	} else if (aoi == 1) {
		saoi = 'range';
	} else if (aoi == 2) {
		saoi = 'crop';
	}
	var url = 'archive/vegdri/'+pDate+'/pngs/'+saoi+'_' + state.toUpperCase() + '_' + pDate + '.png';
	
	var str = '<p>To download the image, right-click <br>';
	str += '<a href="'+url+'">here</a> and select "Save target as...".<br></p>';
	
	url = 'archive/vegdri/'+pDate+'/pdfs/'+saoi+'_' + state.toUpperCase() + '_' + pDate + '.pdf';
	str += '<p>To download the pdf, right-click <br>';
	str += '<a href="'+url+'">here</a> and select "Save target as...".<br></p>';
	
	str += '<p>To view the area statistics for this period,<br>';
	str += 'click <a href="VegDRI_tab.htm?'+ state.toUpperCase() +'">here</a>.</p>';
	
	document.getElementById(divid).innerHTML = str;
}

function setQuadMap(aoi, state, quad, divid, pDate) {
	var url;
	
	if (aoi == 0) {
		//url = 'pngs/all_' + state.toUpperCase() + '_quad' + quad + '_' + pDate + '.png';
		url = 'pngs/all_' + state.toUpperCase() + '_quad' + quad + '.png';
	} else if (aoi == 1) {
		//url = 'pngs/range_' + state.toUpperCase() + '_quad' + quad + '_' + pDate + '.png';
		url = 'pngs/range_' + state.toUpperCase() + '_quad' + quad + '.png';
	} else if (aoi == 2) {
		//url = 'pngs/crop_' + state.toUpperCase() + '_quad' + quad + '_' + pDate + '.png';
		url = 'pngs/crop_' + state.toUpperCase() + '_quad' + quad + '.png';
	}
	document.getElementById(divid).innerHTML = '<img src="' + url + '" width="670" height="498" border="0"/>';
}

function setDnldQuad(aoi, state, quad, divid, pDate) {
	
	var saoi;
	if (aoi == 0) {
		saoi = 'all';
	} else if (aoi == 1) {
		saoi = 'range';
	} else if (aoi == 2) {
		saoi = 'crop';
	}
	
	var url = 'archive/vegdri/'+pDate+'/pngs/'+saoi+'_' + state.toUpperCase() + '_quad' + quad +'_' + pDate + '.png';
	var str = '<p>To download the image, right-click <br>';
	str += '<a href="'+url+'">here</a> and select "Save target as...".<br></p>';
	
	url = 'archive/vegdri/'+pDate+'/pdfs/'+saoi+'_'+ state.toUpperCase() + '_quad' + quad +'_' + pDate + '.pdf';
	str += '<p>To download the pdf, right-click <br>';
	str += '<a href="'+url+'">here</a> and select "Save target as...".<br></p>';
	
	document.getElementById(divid).innerHTML = str;
}
function setState15Chg(divid, url) {
	var tag = '';
	//var h = '<img src="' + url + '" width="670" height="498" border="0" usemap="#Map">';
	var h = '<img src="' + url + '" width="792" height="612" border="0" usemap="#Map">';
     h += '<map name="Map">';
	h += '<area shape="poly" coords="151,98,140,144,142,151,91,143,85,138,73,140,72,130,63,124,55,121,61,75" href="VegDRI_change_state.htm?WA'+tag+'" alt="Washington">';
    h += '<area shape="poly" coords="142,152,145,155,131,175,135,178,126,216,37,191,38,178,61,124,71,131,75,141,85,138,95,145" href="VegDRI_change_state.htm?OR'+tag+'" alt="Oregon">';
    h += '<area shape="poly" coords="89,207,37,193,25,218,50,332,61,360,93,375,132,377,133,361,140,353,134,338,78,258" href="VegDRI_change_state.htm?CA'+tag+'" alt="California">';
    h += '<area shape="poly" coords="162,100,152,98,141,147,146,154,133,174,135,180,127,216,200,228,206,186,203,182,181,185,174,162,169,165,165,162,173,144,160,124" href="VegDRI_change_state.htm?ID'+tag+'" alt="Idaho">';
    h += '<area shape="poly" coords="163,223,90,207,80,258,136,339,137,322,142,321,144,324,147,323" href="VegDRI_change_state.htm?NV'+tag+'" alt="Nevada">';
    h += '<area shape="poly" coords="216,317,150,308,147,323,142,323,140,320,139,322,136,338,141,352,134,363,133,376,128,381,177,412,208,414" href="VegDRI_change_state.htm?AZ'+tag+'" alt="Arizona">';
    h += '<area shape="poly" coords="200,229,162,223,149,307,216,317,223,249,198,247" href="VegDRI_change_state.htm?UT'+tag+'" alt="Utah">';
    h += '<area shape="poly" coords="297,323,217,317,208,414,218,414,220,409,244,409,244,404,295,407" href="VegDRI_change_state.htm?NM'+tag+'" alt="New Mexico">';
    h += '<area shape="poly" coords="294,117,162,100,160,125,173,144,166,161,170,165,174,159,182,184,203,182,206,187,207,179,292,186" href="VegDRI_change_state.htm?MT'+tag+'" alt="Montana">';
    h += '<area shape="poly" coords="290,186,208,178,199,246,288,254" href="VegDRI_change_state.htm?WY'+tag+'" alt="Wyoming">';
    h += '<area shape="poly" coords="314,253,224,250,217,317,311,323" href="VegDRI_change_state.htm?CO'+tag+'" alt="Colorado">';
    h += '<area shape="poly" coords="340,332,298,331,296,407,245,405,245,409,268,446,292,461,305,448,317,453,319,451,350,503,383,515,387,509,383,489,431,449,432,430,435,420,426,404,423,381,407,372,367,375,341,364" href="VegDRI_change_state.htm?TX'+tag+'" alt="Texas">';
    h += '<area shape="poly" coords="413,320,298,322,298,330,339,332,341,363,371,374,406,372,418,377" href="VegDRI_change_state.htm?OK'+tag+'" alt="Oklahoma">';
    h += '<area shape="poly" coords="314,271,399,270,408,273,412,284,413,319,313,322" href="VegDRI_change_state.htm?KS'+tag+'" alt="Kansas">';
    h += '<area shape="poly" coords="290,219,359,221,381,225,396,260,401,271,314,271,315,255,289,252" href="VegDRI_change_state.htm?NE'+tag+'" alt="Nebraska">';
    h += '<area shape="poly" coords="381,170,293,169,289,220,361,220,376,222,382,227" href="VegDRI_change_state.htm?SD'+tag+'" alt="South Dakota">';
    h += '<area shape="poly" coords="296,116,371,118,381,169,294,168" href="VegDRI_change_state.htm?ND'+tag+'" alt="North Dakota">';
    h += '<area shape="poly" coords="374,118,393,117,395,109,403,120,459,127,473,121,432,151,431,167,427,176,427,187,447,199,449,206,383,211" href="VegDRI_change_state.htm?MN'+tag+'" alt="Minnesota">';
    h += '<area shape="poly" coords="385,211,382,226,397,261,447,255,451,260,457,250,454,243,463,238,464,228,450,215,450,208" href="VegDRI_change_state.htm?IA'+tag+'" alt="Iowa">';
    h += '<area shape="poly" coords="397,261,447,257,451,260,452,271,465,283,470,283,469,294,482,303,486,314,482,332,470,332,476,325,416,329,413,287,405,273" href="VegDRI_change_state.htm?MO'+tag+'" alt="Missouri">';
    h += '<area shape="poly" coords="415,331,474,325,471,332,482,333,466,374,467,382,425,388,426,379,419,379" href="VegDRI_change_state.htm?AR'+tag+'" alt="Arkansas">';
    h += '<area shape="poly" coords="426,388,467,385,472,396,464,419,489,417,495,431,506,444,504,452,467,456,432,444,434,429,436,421,427,404" href="VegDRI_change_state.htm?LA'+tag+'" alt="Louisiana">';
    h += '<area shape="poly" coords="507,347,478,350,467,372,467,385,473,396,465,419,491,417,496,431,508,444,512,439" href="VegDRI_change_state.htm?MS'+tag+'" alt="Mississippi">';
    h += '<area shape="poly" coords="527,423,522,413,559,407,562,410,599,406,604,408,603,402,613,401,644,441,648,485,628,509,603,508,627,491,600,455,596,435,578,421,560,431" href="VegDRI_change_state.htm?FL'+tag+'" alt="Florida">';
    h += '<area shape="poly" coords="542,340,508,346,512,427,525,425,522,413,558,406,555,391,558,384" href="VegDRI_change_state.htm?AL'+tag+'" alt="Alabama">';
    h += '<area shape="poly" coords="591,303,502,317,504,321,486,323,478,348,558,337,559,334,581,316" href="VegDRI_change_state.htm?TN'+tag+'" alt="Tennessee">';
    h += '<area shape="poly" coords="543,342,573,335,573,338,582,344,603,362,615,376,613,400,603,401,603,407,564,409,557,392,558,384" href="VegDRI_change_state.htm?GA'+tag+'" alt="Georgia">';
    h += '<area shape="poly" coords="642,338,623,327,609,330,605,327,592,328,577,332,574,336,619,378,640,354" href="VegDRI_change_state.htm?SC'+tag+'" alt="South Carolina">';
    h += '<area shape="poly" coords="670,281,590,302,589,309,560,336,574,336,587,327,605,326,610,330,622,328,644,339,661,336,681,301" href="VegDRI_change_state.htm?NC'+tag+'" alt="North Carolina">';
    h += '<area shape="poly" coords="453,142,434,153,431,167,428,176,427,187,447,199,450,209,451,217,458,222,494,218,491,191,492,178,499,168,494,168,485,182,490,172,485,163,476,160,458,158,452,151" href="VegDRI_change_state.htm?WI'+tag+'" alt="Wisconsin">';
    h += '<area shape="poly" coords="482,130,454,150,458,158,478,160,486,166,491,171,497,166,499,185,502,213,503,228,555,220,564,200,560,164,536,133" href="VegDRI_change_state.htm?MI'+tag+'" alt="Michigan">';
    h += '<area shape="poly" coords="494,219,460,222,465,228,464,235,456,243,458,250,451,261,452,269,464,282,470,283,470,293,483,302,487,313,491,309,495,312,497,306,500,306,501,291,506,281,503,272,499,230" href="VegDRI_change_state.htm?IL'+tag+'" alt="Illinois">';
    h += '<area shape="poly" coords="500,231,532,225,541,274,534,277,529,291,521,295,512,298,502,297,506,284,505,277" href="VegDRI_change_state.htm?IN'+tag+'" alt="Indiana">';
    h += '<area shape="poly" coords="571,275,566,270,551,273,544,268,541,269,541,275,536,277,529,293,512,298,503,299,501,306,496,308,497,312,490,311,489,314,486,322,503,322,502,317,565,307,582,288" href="VegDRI_change_state.htm?KY'+tag+'" alt="KY">';
    h += '<area shape="poly" coords="657,226,653,229,660,250,668,248" href="VegDRI_change_state.htm?DE'+tag+'" alt="Deleware">';
    h += '<area shape="poly" coords="694,175,689,176,693,189,700,186" href="VegDRI_change_state.htm?RI'+tag+'" alt="Rhode Island">';
    h += '<area shape="poly" coords="669,183,689,177,691,188,673,198" href="VegDRI_change_state.htm?CT'+tag+'" alt="Connecticut">';
    h += '<area shape="poly" coords="667,171,668,183,692,175,697,178,700,184,718,182,714,165,699,162,696,159,689,164" href="VegDRI_change_state.htm?MA'+tag+'" alt="Massachusetts">';
    h += '<area shape="poly" coords="654,134,675,126,676,136,674,142,676,168,668,170" href="VegDRI_change_state.htm?VT'+tag+'" alt="Vermont">';
    h += '<area shape="poly" coords="679,120,674,121,677,137,675,141,677,167,694,159,694,153,691,152" href="VegDRI_change_state.htm?NH'+tag+'" alt="New Hampshire">';
    h += '<area shape="poly" coords="669,202,657,199,654,213,663,219,658,228,663,236,667,238,676,226" href="VegDRI_change_state.htm?NJ'+tag+'" alt="New Jersey">';
    h += '<area shape="poly" coords="683,78,680,101,679,117,692,151,697,154,714,129,729,106,713,95,702,73" href="VegDRI_change_state.htm?ME'+tag+'" alt="Maine">';
    h += '<area shape="poly" coords="606,244,608,252,625,240,641,248,638,258,646,261,656,262,660,275,666,276,669,250,660,251,656,240,653,230" href="VegDRI_change_state.htm?MD'+tag+'" alt="Maryland">';
    h += '<area shape="poly" coords="557,220,534,224,541,267,545,267,550,272,565,270,573,275,579,263,590,250,589,232,583,208" href="VegDRI_change_state.htm?OH'+tag+'" alt="Ohio">';
    h += '<area shape="poly" coords="583,288,569,307,667,282,665,277,655,276,656,262,643,262,639,258,639,250,631,244,629,247,621,245,614,264,606,264,604,284,586,291" href="VegDRI_change_state.htm?VA'+tag+'" alt="Virginia">';
    h += '<area shape="poly" coords="591,241,589,250,574,276,586,291,602,284,606,264,609,263,613,267,622,246,628,248,631,245,626,242,608,252,606,245" href="VegDRI_change_state.htm?WV'+tag+'" alt="West Virginia">';
    h += '<area shape="poly" coords="590,202,584,207,592,243,655,231,661,221,655,214,656,200,653,196,647,192,593,207" href="VegDRI_change_state.htm?PA'+tag+'" alt="Pennsylvania">';
    h += '<area shape="poly" coords="653,134,637,139,624,160,626,170,622,175,595,181,600,190,592,201,594,206,647,190,657,199,669,202,674,211,698,193,690,191,670,202,668,184,666,170" href="VegDRI_change_state.htm?NY'+tag+'" alt="New York">';
	h += '</map></img>';
	document.getElementById(divid).innerHTML = h;
}

function setStateChg(divid, url) {
	var h = '<img src="' + url + '" width="670" height="498" border="0"></img>';
	document.getElementById(divid).innerHTML = h;
}

function setDnldChg(name, divid, d) {
	var url = 'archive/vegdri/'+d+'/pngs/'+name + '_' + d +'.png';
	var str = '<p>To download the image, right-click <br>';
	str += '<a href="'+url+'">here</a> and select "Save target as...".<br></p>';
	
	url = 'archive/vegdri/'+d+'/pdfs/'+ name + '_' + d +'.pdf';
	str += '<p>To download the pdf, right-click <br>';
	str += '<a href="'+url+'">here</a> and select "Save target as...".<br></p>';
	
	document.getElementById(divid).innerHTML = str;
}

function setTextDesc(pDate, divid) {
	var xslFile = 'scripts/vegdri_desc.xsl';
	var xmlFile = 'xml/vegdri_desc.xml';
	
	try {
		var str;
		/*if (isIE) {
			xml = loadDocIE(xmlFile);
			xsl = loadXslIE(xslFile);
			
			var cache = new ActiveXObject("MSXML2.XSLTemplate.4.0");
			cache.stylesheet = xsl;
	
			var processor = cache.createProcessor();
			processor.input = xml;
			processor.addParameter("selDate", pDate);
			processor.transform();
			str = processor.output;
		} else if (isMozilla) { */
			xml = loadFromUrl(xmlFile);
			xsl = loadFromUrl(xslFile);
			
			var processor = new XSLTProcessor();
			processor.importStylesheet(xsl);
			processor.setParameter("", "selDate", pDate);
			var outDoc = processor.transformToDocument(xml);  
			var xmlSerializer = new XMLSerializer();  
			var xmlString = xmlSerializer.serializeToString(outDoc);
			str = xmlString ;
		/*} else {
			alert('Please switch to Internet Explorer 6x or Mozilla Firefox.');
			return;
		}*/
	
		document.getElementById(divid).innerHTML = str;
	} catch (e) {
		throw('setTextDesc error');
	}
	//<p>Insert the text description here.</p>
  	//<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec sagittis, tellus sit amet laoreet sodales, nibh libero commodo ipsum, quis sagittis justo lectus et pede. Pellentesque dolor quam, pharetra vitae, rutrum vel, dapibus nec, libero. In enim mauris, pharetra a, aliquet congue, euismod sit amet, massa. Vestibulum suscipit nibh quis augue faucibus dictum. Ut neque purus, pellentesque in, viverra id, consectetuer id, mauris. Nam et mi. In mattis ullamcorper tellus. Aenean eget nunc id felis consectetuer semper. Duis cursus dapibus tortor. Ut augue.</p>
 
}

function setComments(pDate, divid, newdivid) {
	var xslFile = 'scripts/vegdri_desc_toggle.xsl';
	var xmlFile = 'xml/vegdri_conditions.xml';
	
	try {
		/*if (isIE) {
			xml = loadDocIE(xmlFile);
			xsl = loadXslIE(xslFile);
				
			var cache = new ActiveXObject("MSXML2.XSLTemplate.4.0");
			cache.stylesheet = xsl;
		
			var processor = cache.createProcessor();
			processor.input = xml;
			processor.addParameter("selDate", pDate);
			processor.addParameter("selDiv", newdivid);
			processor.transform();
			str = processor.output;
		} else if (isMozilla) {*/
			var cxml = loadFromUrl(xmlFile);
			var cxsl = loadFromUrl(xslFile);
				
			var processor = new XSLTProcessor();
			processor.importStylesheet(cxsl);
			processor.setParameter("", "selDate", pDate);
			processor.setParameter("", "selDiv", newdivid);
			var outDoc = processor.transformToDocument(cxml);  
			var xmlSerializer = new XMLSerializer();  
			var xmlString = xmlSerializer.serializeToString(outDoc);
			str = xmlString ;
		/*} else {
			alert('Please switch to Internet Explorer 6x or Mozilla Firefox.');
			return;
		}*/
		
		document.getElementById(divid).innerHTML = str;
	} catch (e) {
		throw('setComments error');
	}
}



function setTable(aoi) {
	try {
	var xslFile = 'scripts/vdri_tables.xsl';
	var xmlFile = 'xml/vdri_'+ m_state.toUpperCase() +'.xml';
	var param;
	if (aoi == 0) {
		param = "all";
	} else if (aoi == 1) {
		param = "range";
	} else if (aoi == 2) {
		param = "crop";
	}
	
	var str
	//if (isMozilla) {
		xml = loadFromUrl(xmlFile);
		xsl = loadFromUrl(xslFile);
		
		var processor = new XSLTProcessor();
		processor.importStylesheet(xsl);
		processor.setParameter("", "aoiSel", param);
		var outDoc = processor.transformToDocument(xml);  
		var xmlSerializer = new XMLSerializer();  
		var xmlString = xmlSerializer.serializeToString(outDoc);
		str = xmlString ;
	/*} else if (isIE) {
		xml = loadDocIE(xmlFile);
		xsl = loadXslIE(xslFile);
		
		var cache = new ActiveXObject("MSXML2.XSLTemplate.4.0");
		cache.stylesheet = xsl;

		var processor = cache.createProcessor();
		processor.input = xml;
		processor.addParameter("aoiSel", param);
		processor.transform();
		str = processor.output;
	} else {
		alert('Please switch to Internet Explorer 6x or Mozilla Firefox.');
		return;
	}*/
	document.getElementById('tab').innerHTML = str;
	} catch (e) {
		throw('setTextDesc error');
	}
}

function setQuadRef(state, isEV) {
	var s = '<p>Reference Map<br>(Click a quadrant to zoom in further.)</p>';
	var tag = '';
	if (isEV) {
		tag = ',EV';
	}
	if (state.toUpperCase() == 'MT') {
		s += loadMontana(tag);
	} else if (state.toUpperCase() == 'WY') {
		s += loadWyoming(tag);
	} else if (state.toUpperCase() == 'CO') {
		s += loadColorado(tag);
	} else if (state.toUpperCase() == 'NM') {
		s += loadNMexico(tag);
	} else if (state.toUpperCase() == 'ND') {
		s += loadNDakota(tag);
	} else if (state.toUpperCase() == 'SD') {
		s += loadSDakota(tag);
	} else if (state.toUpperCase() == 'NE') {
		s += loadNebraska(tag);
	} else if (state.toUpperCase() == 'KS') {
		s += loadKansas(tag);
	} else if (state.toUpperCase() == 'OK') {
		s += loadOklahoma(tag);
	} else if (state.toUpperCase() == 'TX') {
		s += loadTexas(tag);
	} else if (state.toUpperCase() == 'MN') {
		s += loadMinnesota(tag);
	} else if (state.toUpperCase() == 'IA') {
		s += loadIowa(tag);
	} else if (state.toUpperCase() == 'MO') {
		s += loadMissouri(tag);
	} else if (state.toUpperCase() == 'WI') {
		s += loadWisconsin(tag);
	} else if (state.toUpperCase() == 'IL') {
		s += loadIllinois(tag);
	} else if (state.toUpperCase() == 'AZ') {
		s += loadArizona(tag);
	} else if (state.toUpperCase() == 'CA') {
		s += loadCalifornia(tag);
	} else if (state.toUpperCase() == 'NV') {
		s += loadNevada(tag);
	} else if (state.toUpperCase() == 'UT') {
		s += loadUtah(tag);
	} else if (state.toUpperCase() == 'OR') {
		s += loadOregon(tag);
	} else if (state.toUpperCase() == 'WA') {
		s += loadWashington(tag);
	} else if (state.toUpperCase() == 'ID') {
		s += loadIdaho(tag);

	} else if (state.toUpperCase() == 'SC') {
		s += loadSCarolina(tag);
	} else if (state.toUpperCase() == 'FL') {
		s += loadFlorida(tag);
	} else if (state.toUpperCase() == 'VA') {
		s += loadVirgina(tag);
	} else if (state.toUpperCase() == 'MD') {
		s += loadMaryland(tag);
	} else if (state.toUpperCase() == 'WV') {
		s += loadWVirgina(tag);
	} else if (state.toUpperCase() == 'PA') {
		s += loadWPennsylvania(tag);
	} else if (state.toUpperCase() == 'OH') {
		s += loadWOhio(tag);
	} else if (state.toUpperCase() == 'MI') {
		s += loadWMichigan(tag);
	} else if (state.toUpperCase() == 'AR') {
		s += loadWArkansas(tag);
	} else if (state.toUpperCase() == 'GA') {
		s += loadWGeorgia(tag);
	} else if (state.toUpperCase() == 'LA') {
		s += loadWLouisiana(tag);
	} else if (state.toUpperCase() == 'KY') {
		s += loadWKentucky(tag);
	} else if (state.toUpperCase() == 'ME') {
		s += loadWMaine(tag);
	} else if (state.toUpperCase() == 'MS') {
		s += loadWMississippi(tag);
	} else if (state.toUpperCase() == 'IN') {
		s += loadWIndiana(tag);
	} else if (state.toUpperCase() == 'AL') {
		s += loadWAlabama(tag);
	} else if (state.toUpperCase() == 'CT') {
		s += loadWConnecticut(tag);
	} else if (state.toUpperCase() == 'NH') {
		s += loadWNHampshire(tag);
	} else if (state.toUpperCase() == 'RI') {
		s += loadWRIsland(tag);
	} else if (state.toUpperCase() == 'DC') {
		s += loadWDColumbia(tag);
	} else if (state.toUpperCase() == 'NJ') {
		s += loadWNJersey(tag);
	} else if (state.toUpperCase() == 'DE') {
		s += loadWDeleware(tag);
	} else if (state.toUpperCase() == 'MA') {
		s += loadWMassachusetts(tag);
	} else if (state.toUpperCase() == 'VT') {
		s += loadWVermont(tag);
	}
	return s;
}

function setBrowser() {
	isIE= false;
	isMozilla = false;
	if (navigator.appName.indexOf("Microsoft") != -1) {
		isIE = true;
	} else if (navigator.appName.indexOf("Netscape") != -1) {
		isMozilla = true;
	}
}

/* calc the doy from month (1-12), day (1-31) and year (2006) */
function calcDOY(yr, mo, dy) {
	var lp;
	if (yr % 4 ==0) {
		lp = 1;
	} else {
		lp = 2;
	}
	var doy = Math.floor((275 * mo) / 9) - lp * Math.floor((mo  + 9) / 12) + (dy - 30);
	
	return doy;
}

function returnPreviousBiweek(d) {
	var newDate, numWeeks;
	d = ReturnTuesday(d);
	numWeeks = 14;
		
	//reset the correct number of weeks
	numWeeks *= (1000 * 60 * 60 * 24);
	newDate = new Date(d.valueOf() - numWeeks);

	return newDate;
}

function createCombo(xml, xsl, currDate, selDate, combo) {
	try {
	var str = '<form name="dateForm" method="post" action="">';
	/*if (isIE) {
		var cache = new ActiveXObject("MSXML2.XSLTemplate.4.0");
		cache.stylesheet = xsl;
		var processor = cache.createProcessor();
		processor.input = xml;
		processor.addParameter("selDate", selDate);
		processor.addParameter("comboAction", combo);
		processor.addParameter("currDate", currDate);
		processor.addParameter("selAoi", 'all');
		processor.transform();
		str = processor.output;
		
	} else if (isMozilla) {*/
		//if (comboProcessor == null) {
			processor = new XSLTProcessor();
			processor.importStylesheet(xsl);
		//}
		
		processor.setParameter("", "selDate", selDate);
		processor.setParameter("", "currDate", currDate);
		processor.setParameter("", "comboAction", combo);
		processor.setParameter("", "selAoi", 'all');
		var outDoc = processor.transformToDocument(xml);  
		var xmlSerializer = new XMLSerializer();  
		var xmlString = xmlSerializer.serializeToString(outDoc);
		str = xmlString ;
		
		processor.clearParameters();
		
		//xmlSerializer = null;
		//processor = null;
	/*} else {
		alert('Please switch to Internet Explorer 6x or Mozilla Firefox.');
		return;
	}*/
	return str + '</form>';
	} catch (e) {
		throw('setTextDesc error');
	}
}

function parseCombo(xml, currDate, selDate, combo) {
	try {
	//parse the xml manually to avoid wacky sarissa? load issue
	var theHtml = '<form name="dateForm" method="post" action="">';
	theHtml += '<select id="prevDateList" size="1" onChange="'+ combo +'(this);">';
	var aois = xml.getElementsByTagName('aoi');
	for (var iNode = 0; iNode < aois.length; iNode++) {
		var att = aois[iNode].getAttribute('name')
		if (att == 'all') {
			var node = aois[iNode];
			for (i = 0; i < node.childNodes.length; i++) {
				var child = node.childNodes.item(i);
				if (child.hasAttributes()) {
					var datt = child.getAttributeNode('date');
					var dstr = datt.nodeValue;
					if (dstr <= currDate) {
						//alert(datt.nodeValue);
						var syr = dstr.substr(0, 2);
						var smo = dstr.substr(2, 2);
						var sdy = dstr.substr(4, 2);
						
						var yr = 2000 + parseInt(syr,10);
						var dy = parseInt(sdy,10);
						var mo = parseInt(smo,10);
						mo -= 1;
						
						var pDate = new Date(yr, mo, dy);
						
						theHtml += '<option value="' + dstr + '"' 
						
						if (dstr == selDate) {
							theHtml += ' selected';
						}
						theHtml += '>' + returnMonth(pDate.getMonth()) + ' ' + pDate.getDate() + ', ' + pDate.getFullYear() + '</option> ';
					}
				}
			}
		}
	}
	
	return theHtml + '</select></form>';
	} catch (e) {
		throw('setTextDesc error');
	}
}

function updateLeftArchive(combo) {
	try {
	var newDate = combo.value;
	var aoi = document.getElementById('selState').value;
	
	var tag;
	if (archType == 0) {
		tag = 'all';
	} else if (archType == 1) {
		tag = 'range';
	} else if (archType == 2) {
		tag = 'crop';
	}
	
	var url, png, pdf;
	if (aoi == 'all') {
		url = 'archive/vegdri/' + newDate + '/jpgs/'+tag+'_' + newDate + '.jpg';
		png = 'archive/vegdri/' + newDate + '/pngs/'+tag+'_' + newDate + '.png';
		pdf = 'archive/vegdri/' + newDate + '/pdfs/'+tag+'_' + newDate + '.pdf';
	} else {
		url = 'archive/vegdri/' + newDate + '/jpgs/'+tag+'_' + aoi.toUpperCase() + '_' + newDate + '.jpg';
		png = 'archive/vegdri/' + newDate + '/pngs/'+tag+'_' + aoi.toUpperCase() + '_' + newDate + '.png';
		pdf = 'archive/vegdri/' + newDate + '/pdfs/'+tag+'_' + aoi.toUpperCase() + '_' + newDate + '.pdf';
	}
	
	document.getElementById('left-image').innerHTML = '<img src="'+url+'" width="460" height="417" >';
	
	//set up the downloads
	document.getElementById('left-dld').innerHTML = 'Download <a href="' + png + '">image</a> or <a href="' + pdf + '">PDF</a>';
	
	if (!isIE) {
		setComments(newDate, 'left-text', 'txtCommentLeft');
	}
	
	
	//reset the leftDate var
	leftDate = newDate;
	} catch (e) {
		throw('setTextDesc error');
	}
}

function updateRightArchive(combo) {
	try {
	var newDate = combo.value;
	var aoi = document.getElementById('selState').value;
	
	var tag;
	if (archType == 0) {
		tag = 'all';
	} else if (archType == 1) {
		tag = 'range';
	} else if (archType == 2) {
		tag = 'crop';
	}
	
	var url, png, pdf;
	if (aoi == 'all') {
		url = 'archive/vegdri/' + newDate + '/jpgs/'+tag+'_' + newDate + '.jpg';
		png = 'archive/vegdri/' + newDate + '/pngs/'+tag+'_' + newDate + '.png';
		pdf = 'archive/vegdri/' + newDate + '/pdfs/'+tag+'_' + newDate + '.pdf';
	} else {
		url = 'archive/vegdri/' + newDate + '/jpgs/'+tag+'_' + aoi.toUpperCase() + '_' + newDate + '.jpg';
		png = 'archive/vegdri/' + newDate + '/pngs/'+tag+'_' + aoi.toUpperCase() + '_' + newDate + '.png';
		pdf = 'archive/vegdri/' + newDate + '/pdfs/'+tag+'_' + aoi.toUpperCase() + '_' + newDate + '.pdf';
	}
	
	document.getElementById('right-image').innerHTML = '<img src="'+url+'" width="460" height="417" >';
	document.getElementById('right-dld').innerHTML = 'Download <a href="' + png + '">image</a> or <a href="' + pdf + '">PDF</a>';
	
	if (!isIE) {
		setComments(newDate, 'right-text', 'txtCommentRight');
	}
	
	
	//reset the rightDate var
	rightDate = newDate;
	} catch (e) {
		throw('setTextDesc error');
	}
}

function setCompare() {
	try {
	var aoi = document.getElementById('selState').value;	
	var url, pdf;
	
	var tag;
	if (archType == 0) {
		tag = 'all';
	} else if (archType == 1) {
		tag = 'range';
	} else if (archType == 2) {
		tag = 'crop';
	}
	
	if (aoi == 'all') {
		//reset the left
		if (m_date != m_start) {
			url = 'archive/vegdri/' + leftDate +'/jpgs/'+tag+'_' + leftDate + '.jpg';
			document.getElementById('left-image').innerHTML = '<img src="'+url+'" width="460" height="417" >';
			
			//set up the downloads
			url = 'archive/vegdri/' + leftDate + '/pngs/'+tag+'_' + leftDate + '.png';
			pdf = 'archive/vegdri/' + leftDate + '/pdfs/'+tag+'_' + leftDate + '.pdf';
			document.getElementById('left-dld').innerHTML = 'Download <a href="' + url + '">image</a> or <a href="' + pdf + '">PDF</a>';
		}
		
		//and the right
		url = 'archive/vegdri/' + rightDate +'/jpgs/'+tag+'_' + rightDate + '.jpg';
		document.getElementById('right-image').innerHTML = '<img src="'+url+'" width="460" height="417" >';

		url = 'archive/vegdri/' + rightDate + '/pngs/'+tag+'_' + rightDate + '.png';
		pdf = 'archive/vegdri/' + rightDate + '/pdfs/'+tag+'_' + rightDate + '.pdf';
		document.getElementById('right-dld').innerHTML = 'Download <a href="' + url + '">image</a> or <a href="' + pdf + '">PDF</a>';
	} else {
		
		if (m_date != m_start) {
			url = 'archive/vegdri/' + leftDate + '/jpgs/'+tag+'_' + aoi.toUpperCase() + '_' + leftDate + '.jpg';
			document.getElementById('left-image').innerHTML = '<img src="'+url+'" width="460" height="417" >';
			
			//set up the downloads
			url = 'archive/vegdri/' + leftDate + '/pngs/'+tag+'_' + aoi.toUpperCase() + '_' + leftDate + '.png';
			pdf = 'archive/vegdri/' + leftDate + '/pdfs/'+tag+'_' + aoi.toUpperCase() + '_' + leftDate + '.pdf';
			document.getElementById('left-dld').innerHTML = 'Download <a href="' + url + '">image</a> or <a href="' + pdf + '">PDF</a>';
		}
	
		url = 'archive/vegdri/' + rightDate + '/jpgs/'+tag+'_' + aoi.toUpperCase() + '_' + rightDate + '.jpg';
		document.getElementById('right-image').innerHTML = '<img src="'+url+'" width="460" height="417" >';

		url = 'archive/vegdri/' + rightDate + '/pngs/'+tag+'_' + aoi.toUpperCase() + '_' + rightDate + '.png';
		pdf = 'archive/vegdri/' + rightDate + '/pdfs/'+tag+'_' + aoi.toUpperCase() + '_' + rightDate + '.pdf';
		document.getElementById('right-dld').innerHTML = 'Download <a href="' + url + '">image</a> or <a href="' + pdf + '">PDF</a>';
	}
	} catch (e) {
		throw('setTextDesc error');
	}
}

function setArchiveType(rad) {
	if (rad.id == 'completeRad') {
		archType = 0;
	} else if (rad.id == 'rangeRad') {
		archType = 1;
	} else if (rad.id == 'cropRad') {
		archType = 2;
	} else {
		alert('Invalid landcover selection');
	}
}

function loadSurvey() {
	window.open("http://snr.unl.edu/ndmcsurvey/loginndmc.asp", "surveyWin", "width=700,height=600,status=yes,resizable=yes,scrollbars=yes")
}

function loadSurveyInst() {
	window.open("VegDRI_EvalInst.htm", "surveyWin", "width=700,height=600,status=yes,resizable=yes,scrollbars=yes")
}

function loadUsgs() {
	window.open("http://gisdata.usgs.gov/website/Drought_Monitoring/viewer.php", "usgsViewer", "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes");
}

function DayDiff(d1, d2) {
	return Math.round((d1 - d2) / 86400000);
}

function dateAdd(d, ndys) {
	//convert to seconds
	ndys *= (1000 * 60 * 60 * 24);
	return new Date(d.valueOf() + ndys);
}

function loadDom(url) {
	//var oDomDoc = Sarissa.getDomDocument();
	//oDomDoc.async = false;
	//oDomDoc.load(url);
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.open("GET", url, false);
	xmlhttp.send(null);
	var oDomDoc = xmlhttp.responseXML;
	return oDomDoc;
}

function toggleDiv(divid) {
	if (document.getElementById(divid).style.display == 'none') {
		document.getElementById(divid).style.display = 'block';
		document.images[divid+'img'].src = 'pics/minus.gif';
	} else {
		document.getElementById(divid).style.display = 'none';
		document.images[divid+'img'].src = 'pics/plus.gif';
	}
}

