/*
This code was created by the New Hampshire Housing and Finance Authority. 
Use of any part of this code is prohibited without written permission.
http://www.nhhfa.org
Created: 12/2006
By: Sean Vickers
*/
var xmlhttp=null;
function clearGroups() {
   document.getElementById("pwait").innerHTML = "<img src='wait.gif' alt='' width='150' border='0'>";
   document.getElementById("page1").innerHTML = "";
   document.getElementById("page2").innerHTML = "";
   document.getElementById("page3").innerHTML = "";
   document.getElementById("page4").innerHTML = "";
   document.getElementById("page5").innerHTML = "";
   document.getElementById("page6").innerHTML = "";  
   document.getElementById("page7").innerHTML = "";   
   document.getElementById("combo1").innerHTML = "";
   document.getElementById("pwait").innerHTML = "";
   
   if (document.info.report.value == "ccpopulation" || document.info.report.value == "cchousing") {
      document.getElementById("combo0").innerHTML = "";
	  createRpt ("STATE","New Hampshire",document.info.report.value);
	  document.getElementById("page1").focus();
   } else if (document.info.report.value == "rcbycnty") {
      document.getElementById("combo0").innerHTML = "";
	  createRpt ("STATE","New Hampshire",document.info.report.value);
	  document.getElementById("page1").focus();
   } else if (document.info.report.value == "employment" || document.info.report.value == "emphousing") {
      var html1 = "<select name='code1' onchange='javascript:getGroups(this);' style='width:314px;'>" +
				 "<option value=''>---------- Select A Regional Area ----------></option>" +
				 "<option value='STATE'>State Wide Reports</option>" +
				 "<option value='CNTY'>County Reports</option>" +
				 "<option value='TOWN'>Town/City Reports</option>" +
				 "<option value='RPC'>Regional Planning Commission Area Reports</option>" +
				 "</select>";
	  	 
	  document.getElementById("combo0").innerHTML = html1;  
	  document.info.code1.value = "";   
   } else if (document.info.report.value == "labor") {
      var html1 = "<select name='code1' onchange='javascript:getGroups(this);' style='width:314px;'>" +
				 "<option value=''>---------- Select A Regional Area ----------></option>" +
				 "<option value='STATE'>State Wide Reports</option>" +
				 "<option value='CNTY'>County Reports</option>" +
				 "<option value='NECTA'>NECTA/LMA Area Reports</option>" +
				 "<option value='TOWN'>Town/City Reports</option>" +
				 "<option value='RPC'>Regional Planning Commission Area Reports</option>" +
				 "</select>";
	  	 
	  document.getElementById("combo0").innerHTML = html1;  
	  document.info.code1.value = "";      	 
   } else if (document.info.report.value == "permits1" || document.info.report.value == "permits2") {
      var html1 = "<select name='code1' onchange='javascript:getGroups(this);' style='width:314px;'>" +
				 "<option value=''>---------- Select A Regional Area ----------></option>" +
				 "<option value='STATE'>State Wide Reports</option>" +
				 "<option value='CNTY'>County Reports</option>" +
				 "<option value='TOWN'>Town/City Reports</option>" +
				 "<option value='NECTA'>NECTA/LMA Area Reports</option>" +
				 "<option value='RPC'>Regional Planning Commission Area Reports</option>" +
				 "</select>";
	  	 
	  document.getElementById("combo0").innerHTML = html1;  
	  document.info.code1.value = "";  
   } else {
      var html1 = "<select name='code1' onchange='javascript:getGroups(this);' style='width:314px;'>" +
				 "<option value=''>---------- Select A Regional Area ----------></option>" +
				 "<option value='STATE'>State Wide Reports</option>" +
				 "<option value='CNTY'>County Reports</option>" +
				 "<option value='TOWN'>Town/City Reports</option>" +
				 "<option value='HMFA'>HUD Metro Fair Market Rent Area Reports</option>" +
				 "<option value='NECTA'>NECTA/LMA Area Reports</option>" +
				 "<option value='RPC'>Regional Planning Commission Area Reports</option>" +
				 "</select>";
	  	 
	  document.getElementById("combo0").innerHTML = html1;  
	  document.info.code1.value = "";
   }
}

function getGroups(type) {
   document.getElementById("pwait").innerHTML = "<img src='images/wait.gif' alt='' width='150' border='0'>";
   document.getElementById("page1").innerHTML = "";
   document.getElementById("page2").innerHTML = "";
   document.getElementById("page3").innerHTML = "";
   document.getElementById("page4").innerHTML = "";
   document.getElementById("page5").innerHTML = "";
   document.getElementById("page6").innerHTML = "";  
   document.getElementById("page7").innerHTML = "";  
      
   if (type.value != "STATE" && !(document.info.report.value == "labor" && type.value == "TOWN")) {	  
   
      var url = "http://www.nhhfa.org/oppweb/xml.asp?code1=" + type.value;

      loadXMLDoc(url,type.value);    

   } else if(document.info.report.value == "labor" && type.value == "TOWN") {
   	   document.getElementById("pwait").innerHTML = "";
	   html  = "<select name='TOWN' onchange='createRpt(document.info.code1.value,document.info.TOWN.value,document.info.report.value);' style='width:377px;'>" +
		         "<option value=''>---------- Select Town/City ----------></option>" +
				 "<option value='Concord'>Concord</option>" +
				 "<option value='Derry'>Derry</option>" +
				 "<option value='Dover'>Dover</option>" +
				 "<option value='Hudson'>Hudson</option>" +
				 "<option value='Londonderry'>Londonderry</option>" +
				 "<option value='Manchester'>Manchester</option>" +
				 "<option value='Merrimack'>Merrimack</option>" +
				 "<option value='Nashua'>Nashua</option>" +
				 "<option value='Rochester'>Rochester</option>" +
				 "<option value='Salem'>Salem</option>" +
				 "</select>";			   
			   
	  document.getElementById("combo1").innerHTML = html;  
	  document.info.TOWN.value = "";   
	  	  
   } else {   
      document.getElementById("combo1").innerHTML = "";
      createRpt('STATE','New Hampshire',document.info.report.value);      
   } 
}

function loadXMLDoc(url,type) {
    xmlhttp=null;

    /* Check for running connections */
    if (xmlhttp != null && xmlhttp.readyState != 0 && xmlhttp.readyState != 4){
       xmlhttp.abort();
    }

    // code for Mozilla, etc.
    if (window.XMLHttpRequest) { 
    	try { xmlhttp=new XMLHttpRequest(); }
    	catch(e) { xmlhttp=null; }
    }
 
    // code for IE
    else if (window.ActiveXObject) {
    	try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
    	catch(e) {
    	   try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
    	   catch(e) { xmlhttp=null; }
    	}
    }

    if (xmlhttp) {
        xmlhttp.open("GET",url,true);
        xmlhttp.setRequestHeader('content-type', 'text/xml'); 
        xmlhttp.onreadystatechange=function () {

	    var xml=null;
	    var html=null;
	    var Groups=null;

	    // if xmlhttp shows "loaded"
	    if (xmlhttp.readyState==4) {
  
		// if "OK"
		if (xmlhttp.status==200) {

		    xml  = xmlhttp.responseXML;

			if (type == "TOWN") {
			       Groups = xml.documentElement.getElementsByTagName("TOWN");
				   html  = "<select name='TOWN' onchange='createRpt(document.info.code1.value,document.info.TOWN.value,document.info.report.value);' style='width:377px;'>" +
					       "<option value=''>---------- Select Town/City ----------></option>"; 
			} else if (type == "CNTY") {			
			       Groups = xml.documentElement.getElementsByTagName("CNTY");
				   html  = "<select name='CNTY' onchange='createRpt(document.info.code1.value,document.info.CNTY.value,document.info.report.value);' style='width:377px;'>" +
					       "<option value=''>---------- Select County ----------></option>"; 			
			} else if (type == "HMFA") {
			       Groups = xml.documentElement.getElementsByTagName("HMFA");
				   html  = "<select name='HMFA' onchange='createRpt(document.info.code1.value,document.info.HMFA.value,document.info.report.value);' style='width:377px;'>" +
					       "<option value=''>--------- Select Area ----------></option>"; 					
			} else if (type == "RPC") {
			       Groups = xml.documentElement.getElementsByTagName("RPC");
				   html  = "<select name='RPC' onchange='createRpt(document.info.code1.value,document.info.RPC.value,document.info.report.value);' style='width:377px;'>" +
					       "<option value=''>---------- Select Area ----------></option>"; 						
			} else if (type == "NECTA") {
			       Groups = xml.documentElement.getElementsByTagName("NECTA");
				   html  = "<select name='NECTA' onchange='createRpt(document.info.code1.value,document.info.NECTA.value,document.info.report.value);' style='width:377px;'>" +
					       "<option value=''>---------- Select Area ----------></option>"; 			
			}					

			for (var i = 0; i < Groups.length; i++) {
				html += "<option value='" + Groups[i].getAttribute("id") + "'>" + 
						       Groups[i].getAttribute("id") + "</option>";
			}    

			html += "</select>"; 
			document.getElementById("combo1").innerHTML = html; 
			document.getElementById("pwait").innerHTML = "";    
		    
		} else {
		    alert("Problem retrieving XML data:" + xmlhttp.statusText)
		}    
	    }           
        };
        xmlhttp.send(null);
    } else alert("Your browser does not support XMLHTTP.");
}

function createRpt (code1,code2,code3) {

   document.getElementById("page1").innerHTML = "";
   document.getElementById("page2").innerHTML = "";
   document.getElementById("page3").innerHTML = "";
   document.getElementById("page4").innerHTML = "";
   document.getElementById("page5").innerHTML = "";
   document.getElementById("page6").innerHTML = "";  
   document.getElementById("page7").innerHTML = "";   


    switch (code3) {		  
       case "population":          
          population(code1,code2);
          break;    
       case "birth":          
          birth(code1,code2);
          break;
       case "school":          
          school(code1,code2);
          break;   
	   case "disability": 		  
          disability(code1,code2);
          break;   	
	   case "housing": 		  
          housing(code1,code2);
          break; 		  
	   case "rentalcost": 		  
          rentalcost(code1,code2);
          break; 	
	   case "ownercost": 		  
          ownercost(code1,code2);
          break; 
	   case "permits1": 		  
          permits(code1,code2,1);
          break; 	
	   case "permits2": 		  
          permits(code1,code2,2);
          break; 			  	  
	   case "inc2000": 		  
          inc2000(code1,code2);
          break; 	
	   case "incTenure": 		  
          incTenure(code1,code2);
          break; 		  
	   case "inc1990and2000": 		  
          inc1990and2000(code1,code2);
          break; 	
	   case "poverty": 		  
          poverty(code1,code2);
          break; 			  
	   case "ccpopulation": 		  
          ccpopulation(code1,code2);
          break; 			  
	   case "cchousing": 		  
          cchousing(code1,code2);
          break; 
	   case "commuting1":
          commuting1(code1,code2);
          break; 	
	   case "commuting2":
          commuting2(code1,code2);
          break; 		  
	   case "employment":
          employment(code1,code2);
          break; 			
	   case "labor":
          labor(code1,code2);
          break; 		    
	   case "emphousing":
          emphousing(code1,code2);
          break; 			  
       case "pptrends":          
          ppTrends(code1,code2,"Jan-Aug 2011");
          break;
       case "rctrends":          
          rcTrends(code1,code2,"2011");
          break;		  	  
       case "rcbycnty":          
          rcByCnty(code1,code2);
          break;	     	  		  	  		  		  	  
    }	
    document.getElementById("page1").focus();
}
