//////////////////////////////////////////////////////////////////
// basic/basic.js v1.0
// 
// Company: New West Technologies, LLC
//          3451 Garden City Drive
//          Suite 600
//          Landover MD, 20785
//          301.429.1180
//
// Author: Kevin King
//
// NOTES:
//	DEBUG is set in common\wind.js
//////////////////////////////////////////////////////////////////
///////////////DO NOT EDIT BELOW THIS LINE////////////////////////
//////////////////////////////////////////////////////////////////

var v=0;

var street = "";
var city = "";
var st = "";
var zip = "";
var address = street;

function initialize() {

	//fill out the forms, if possible
	if(GET["street"])
		fill_form_GET("user_address");

	if(GET["lat"] && GET["lon"] && GET["speed050"]) { //see if we have data to show
		rough = GET["rough"];
		speed = GET["speed030"];		
		units = "meters";
		document.getElementById("latitude").innerHTML = GET["lat"];
		document.getElementById("longitude").innerHTML = GET["lon"];	
		document.getElementById("t050").innerHTML = GET["speed050"];
		document.getElementById("wpd050").innerHTML = GET["wpd050"];
		document.getElementById("wbk050").innerHTML = GET["wbk050"];
		document.getElementById("accuracy").innerHTML = how_accurate(GET["acc"]) + " (" + GET["acc"] + ")";
		document.getElementById("user_address").my_go.value = "Restart";
		document.getElementById("t030").value = GET["speed030"];
		document.getElementById("tro").value = GET["rough"];
		for(i=0;i<document.getElementById("units").length;i++) {
			if(document.getElementById("units").options[i].value == GET["units"]) 
				document.getElementById("units").selectedIndex = i;
		}
		s = "visible";
		turbines_list();
		setUnits(GET["units"]);
		fill_form_GET("cost_inputs");
		wind_class();
	} else {	//no data to show
		s = "hidden";
	}
	document.getElementById("s2").style.visibility = s;

	try {	//buttons has no buttons - just disclaimer and google icon
		document.getElementById("buttons").style.visibility = s;
	} catch(e) {
	}
	
}


function get_gps() {
	if(DEBUG)
		alert("get_gps()");
	
	var pass = true;

	//pull address elements (used in other places, too)
	add_form = document.getElementById("user_address");
	street = add_form.elements[0].value;
	city = add_form.elements[1].value;
	st = add_form.elements[2].value;
	zip = add_form.elements[3].value;

	//check if all the fields have data
	for(j=0;j<4;j++) {
		if(DEBUG && LEVEL == 1)
			alert("pass=" + pass + ", j=" + j + ", color=" + document.getElementById("el" + j).style.color + ", value=" + document.getElementById("user_address").elements[j].value);
		document.getElementById("el" + j).style.color = "";

		if(document.getElementById("user_address").elements[j].value == "") {
			if(DEBUG && LEVEL ==1)
				alert("failure at j=" + j);
			document.getElementById("el" + j).style.color="red";
			document.getElementById("error").innerHTML="You must fill out the form completely.";
			document.getElementById("error").style.visibility="visible";
			pass = false;
		} else if(j == 3 && (zip > 21930 || zip < 20601 || !IsNumeric(zip) || zip.length < 5 || zip.length > 5 || zip.indexOf(".") >= 0) ) {	//check zipcode
			document.getElementById("el3").style.color="red";
			if(document.getElementById("error").innerHTML != "")
				document.getElementById("error").innerHTML = document.getElementById("error").innerHTML + "<br />";
			
			document.getElementById("error").innerHTML=document.getElementById("error").innerHTML + "You have entered and invalid postal code.";
			document.getElementById("error").style.visibility="visible";
			pass = false;
		}
	}

	if(pass) {
		//build address for geocoder
		address = street;
		address = address.concat(", ",city,", ",st);

		//call geocoder API
		var geocoder = new GClientGeocoder();
		geocoder.getLocations(address, ripPoints);
	}
}

function ripPoints(r) {
	if(DEBUG)
		alert("ripPoints()");
	
	var lat;
	var lon;
	var url;
	if (r.Status.code != 200 || r.Placemark[0].Point.coordinates[1] < 37.836 || r.Placemark[0].Point.coordinates[1] > 39.727 || r.Placemark[0].Point.coordinates[0] < -79.488 || r.Placemark[0].Point.coordinates[0] > -74.961) { //something went wrong
		if(DEBUG && LEVEL >= 2)
			alert(v);
		geocoder = new GClientGeocoder();
		switch(v) { 
			case 0: //remove the city (most likely thing to be 'wrong')
				address = street;
				address = address.concat(", ",st);
				break;
			case 1: //lookup by zip
				address = st + ", " + zip;
				break;
			case 2: //look up by city and state
				address = city;
				address = address.concat(", ",st);
				break;
			case 3: //apparently the user doesn't know where they live
				answer = confirm("Your address could not be located.\n Did you want to try again?");
				if(!answer) {
					address = st + ", USA";
					break;
				}
			default:
				url = location.href;
				if(url.indexOf("street=") > 0) { //check if we have already passed our HTTP GET arguments, if so then remove the old arguments	
					url = url.substr(0,url.indexOf("street=")); 
				} else if(url.indexOf("?") < 0) { //check if HTTP GET arguments exist yet
					url = url.concat("?");
				}
				url = url.concat("street=",street.replace(/ /g,"+"),"&city=",city.replace(/ /g,"+"),"&zip=",zip);
				window.location = url; 
		}	
		if(DEBUG && LEVEL >= 2)
			alert(r.Status.code + " " + v + " " + address + "<br />");
		
		geocoder.getLocations(address, ripPoints);
		v++;
	} else {
		if(v < 4)
			answer = confirm("Is This Address Correct:\n" + r.Placemark[0].address + "\n(" + v + ")");
		else
			answer = true;
		
		if(answer) {
			url = location.href.substr(0,location.href.lastIndexOf("/") + 1) + "common/get_resources.asp";
			
			if(url.indexOf("lat=") > 0) { //check if we have already passed our HTTP GET arguments, if so then remove the old arguments	
				url = url.substr(0,url.indexOf("lat=")); 
			} else if(url.indexOf("?") < 0) { //check if HTTP GET arguments exist yet
				url = url.concat("?");
			}
			
			//shorten the latitude and longitude for use with database
			//precise_round lives in evo_math_toolkit.js
			lat = precise_round(r.Placemark[0].Point.coordinates[1],3);
			lon = precise_round(r.Placemark[0].Point.coordinates[0],3);

			
			//js = JSON.stringify(r); //use this for debugging the JSON returned by google
			/* A JSON returned by Google
			{"name":"2401 battersea pl, milford mill, MD",
					"Status": {"code":200,"request":"geocode"},
					"Placemark":[{"id":"p1",
								  "address":"2401 Battersea Pl, Milford Mill, MD 21244, USA",
								  "AddressDetails":{"Country":{"CountryNameCode":"US",
															   "AdministrativeArea":{"AdministrativeAreaName":"MD",
																					 "SubAdministrativeArea":{"SubAdministrativeAreaName":"Baltimore County",
																											  "Locality":{"LocalityName":"Milford Mill",
																														  "Thoroughfare":{"ThoroughfareName":"2401 Battersea Pl"},
																																		  "PostalCode":{"PostalCodeNumber":"21244"}}}}},
													"Accuracy":8},
								  "Point":{"coordinates":[-76.760032,39.32417,0]}}]}
			*/
			try {
				if(r.Placemark[0].AddressDetails.Accuracy - 0 == 8) { //'Clean up' user entered address, if we can
					street = r.Placemark[0].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName;
					city = r.Placemark[0].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName;
				//	zip = r.Placemark[0].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.PostalCode.PostalCodeNumber;
				}
			} catch (e) {
			
			}
			
			//add our HTTP GET arguments
			theGet = "street=" + street.replace(/ /g,"+") + "&city=" + city.replace(/ /g,"+") + "&st=" + st + "&zip=" + zip + "&acc=" + r.Placemark[0].AddressDetails.Accuracy + "&lat=" + lat + "&lon=" + lon; // + "&js=" + js.replace(/ /g,"+"); 
	
			url = url.concat(theGet);
		} else {
			url = location.href;
			if(url.indexOf("street=") > 0) { //check if we have already passed our HTTP GET arguments, if so then remove the old arguments	
				url = url.substr(0,url.indexOf("street=")); 
			} else if(url.indexOf("?") < 0) { //check if HTTP GET arguments exist yet
				url = url.concat("?");
			}
			 url = url.concat("street=",street.replace(/ /g,"+"),"&city=",city.replace(/ /g,"+"),"&zip=",zip);
		}
	
		//redirect to the new URL
		window.location = url; 
	}    
}


function turbines_list() {
	if(DEBUG)
		alert("turbines_list()");
	
	for (i=0;i<turbines.length;i++) {	//create turbine option elements
		y = document.createElement('option');
		y.text = turbines[i].name;
		y.value = turbines[i].options_list;
		z = document.createElement('option');
		z.text = turbines[i].name;
		z.value = turbines[i].options_list;
		
		try{	//IE
			document.getElementById("turbine1").add(y,null);
			document.getElementById("turbine2").add(z,null);
		} catch(err) {	//Mozilla
			document.getElementById("turbine1").add(y);
			document.getElementById("turbine2").add(z);
		}
	}

	//initialize the selected index
	document.getElementById("turbine1").selectedIndex = 0;
	document.getElementById("turbine2").selectedIndex = 0;
		
	//initialize the towers
	towers_list(document.getElementById("turbine1").options[0].value,"1");
	towers_list(document.getElementById("turbine2").options[0].value,"2");
}

function towers_list(id,tt) {
	if(DEBUG) 
		alert("towers_list(" + id + ", " + tt + ")");
	
	while(0<document.getElementById("tower" + tt).length) {	//clear the existing tower height list
		document.getElementById("tower" + tt).remove(document.getElementById("tower" + tt).length - 1);
	}

	for(r=1;r<6;r++) {
		if(DEBUG && LEVEL >= 1)
			alert("towers_list " + r);

		if(towers[cross_reference[id - 1]["t" + r]].height != null) {

			y = document.createElement('option');
			tHeight = towers[cross_reference[id - 1]["t" + r]].height;	//height of this tower
			tId = towers[cross_reference[id - 1]["t" + r]].id;			//id number of tower
			//alert(units);
			if(units == "feet") {	//see if we are displaying in English Units
				tHeightEng = tHeight * 3.28;
				y.text = precise_round(tHeightEng,1);
			} else { 
				y.text = tHeight;
			}

			y.value = tId;

			try{	//write the tower height option - IE
				document.getElementById("tower" + tt).add(y,null);
			} catch(err) { // others
				document.getElementById("tower" + tt).add(y);
			}
		}
	}
	document.getElementById("tower" + tt).selectedIndex = 0;

	calculations(tt);
}

function calculations(s) {

	t = document.getElementById("turbine" + s).selectedIndex; //turbine number
	o = document.getElementById("tower" + s).value; //tower number
	lifetime = turbines[t].lifetime; //turbine lifetime

	//Annual Energy Output of Turbine (AEOT) Calculation
	// EWS = windspeed at 30m * ln( tower_height / surface_roughness ) / ln( 30m / surface_roughness) - http://www.windpower.org/en/tour/wres/shear.htm 
	// AEOT = 1.64 * (turbine_diameter)^2 * (EWS)^3 - http://www.omafra.gov.on.ca/english/engineer/facts/03-047.htm 
	
	d = Math.pow(turbines[t].diameter,2);
	tr = Math.log((towers[o].height *100) / (GET["rough"] * 100));
	r3 = Math.log(30 / GET["rough"]);

	EWS = GET["speed030"] * tr / r3; //Effective windspeed
	document.getElementById("eews" + s).innerHTML = precise_round(EWS,2);
	if(units == "feet")	//if using metric units
		document.getElementById("eews" + s).innerHTML = precise_round(EWS * 2.24,2);
	
	s30 = Math.pow(EWS,3);

		
	AEOT = (1.64 * d * s30);
	AEOT = Math.round(AEOT); //Annual Energy Output of Turbine

	document.getElementById("aeot" + s).innerHTML = AEOT;
	

	//Effective Energy Offset (EEO) Calculation
	// You can only offset up to 100% of your usage; any more power generated is forefitted to the electric company
	
	if(AEOT > document.getElementById("kwu" + s).value) { // see if we generate more than we need
		EEO = document.getElementById("kwu" + s).value;
	} else { // we need more than we generate!
		EEO = AEOT;
	}

	document.getElementById("aeo" + s).innerHTML = EEO;
	

	//Percentage Energy Offset (PEO) Calculation
	// we want to see how well we have sized the turbine
	// PEO = EEO / actual usage * 100
	
	PEO = EEO / document.getElementById("kwu" + s).value * 100;
	PEO = precise_round(PEO,2);

	document.getElementById("peo" + s).innerHTML = PEO + "%";
	

	//Annual Value of Energy Offset (AVEO) Calculation
	// How much is the electricity I generated worth to me?

	AVEO = EEO * document.getElementById("cpkwh" + s).value / 100;
	AVEO = Math.round(AVEO);

	document.getElementById("ayv" + s).innerHTML = "$" + AVEO;


	//Installed Cost of Turbine (ICT) Calculation
	// Total costs associated with building a specific turbine configuration

	ICT = (turbines[t].cost - 0) + (towers[o].cost - 0);
	
	document.getElementById("ict" + s).innerHTML = "$" + ICT;
	

	if(document.getElementById("fsi" + s).value == "yes") {
		//Federal Tax Credit (FTC)
		// The tax credit is 30% of the Installed System Cost, up to max_tax_credit	
		// currently, there are no tax credits
		
		FTC = 0.3 * ICT;
	
		if(FTC > max_tax_credit) {
			FTC = max_tax_credit;
		}
		
	
		//State Tax Credit (STC)
		// STC = $.0085 * AEO * 5yrs
		
		STC = 0.0085 * EEO * 5;
		
	
		//State Grants (SG) calculation
		// turbine must have power rating greater than 1kW to qualify
		// grant is $1,500 * kW rating to a maximum of $3,000
		
		if((turbines[t].power - 0) >= 1) {
			SG = (turbines[t].power - 0) * 1500;
		
			if(SG > 3000) {
				SG = 3000;
			}
		} else {
			SG = 0;
		}
		
		TTC = FTC + STC + SG;
		TTC = Math.round(TTC);

	} else {
		TTC = 0;
	}	
	document.getElementById("incentives" + s).innerHTML = "$" + TTC;
	

	//Net System Cost (NSC) Calculation
	// System cost less credits and rebates
	// NSC = ICT - TTC	
	
	NSC = ICT - TTC;
	

	//Monthly Interest Payment (MIP) and Final Net System Cost (FNSC) Calculations
	// this calculates the cost of interest for the loan - simple monthly compounding
	// see calc_pmt function for algorithm
	
	if((document.getElementById("ft" + s).value - 0) > 0 && (document.getElementById("apr" + s).value - 0) > 0) {
		MIP = calc_pmt(document.getElementById("apr" + s).value/12,document.getElementById("ft" + s).value,NSC);
		
		document.getElementById("mpa" + s).innerHTML = "$" + Math.round(MIP);
		
		FNSC = MIP * document.getElementById("ft" + s).value;
		FNSC = Math.round(FNSC);
		
		NSC = FNSC;
	} else {
		document.getElementById("mpa" + s).innerHTML = "N/A";
	}

	document.getElementById("nsc" + s).innerHTML = "$" + NSC;


	//Net Yearly Savings (NYS) Calculation
	// NYS = AVEO - Maintenance Costs
	
	NYS = AVEO - (ICT * turbines[t].o_and_m);
	NYS = Math.round(NYS);
	
	if(NYS < 0) {
		q = NYS.toString();
		document.getElementById("nss" + s).innerHTML = q.substr(0,1) + "$" + q.substr(1);
		document.getElementById("nss" + s).style.color = "red";
	} else if(NYS == 0) {
		document.getElementById("nss" + s).innerHTML = "$" + NYS;
		document.getElementById("nss" + s).style.color = "red";
	} else {
		document.getElementById("nss" + s).innerHTML = "$" + NYS;
		document.getElementById("nss" + s).style.color = "";
	}
		

	//Simple Playback Period (SPP) Calculation
	// SPP = NSC/NYS
	// there is no payback if NYS is negative or if both NYS and NSC are negative and end up 
	//       costing more over time than the install was worth
		
	if(NYS > 0 || (NSC < 0 && NYS < 0) ) {
		SPP = NSC/NYS;
		
		if(SPP > lifetime || (SPP < lifetime && NYS < 0) ) {
			SPP = null;
		} else if(SPP < 0) {
			SPP = 0;
		}
	} else {
		SPP = null;
	}
	
	if(SPP == null) {
		document.getElementById("sp" + s).style.color = "red";
		if(NSC/NYS > 0)	
			document.getElementById("sp" + s).innerHTML = "No Payback (" + Math.round(NSC/NYS) + ")";
		else
			document.getElementById("sp" + s).innerHTML = "No Payback (Infinity)";
	} else {
		SPP = Math.round(SPP);
		document.getElementById("sp" + s).innerHTML = SPP;
		document.getElementById("sp" + s).style.color = "";	
	}
	

	//Lifetime Savings (LS) Calculation
	// Calculate how much the lifetime savings of the system is (if any)
	
	if(SPP != null) {
		LS = (lifetime - SPP) * NYS;
		document.getElementById("sl" + s).style.color = "";	
	} else {
		LS = 0;
		document.getElementById("sl" + s).style.color = "red";	
	}

	document.getElementById("sl" + s).innerHTML = "$" + LS;	
	
	//Emissions Offset Calculation
	// COEO - CO2 emissoin offsets
	// SOEO - SO2 emission offsets
	// NOEO - NOx emission offsets
	// COEOT - Effective number of trees planted; Link: http://www.treelink.org/docs/29_reasons.phtml
	// COEOC - Effective number of cars removed from road; Link: http://www.bnl.gov/rideshare/benefits.asp
	//         363.2 g/mi, 24 mi/gal, 12,000 mi/yr, 1000000 g/metric ton 
	
	COEO = EEO * lifetime * 623/1000/1000;
	SOEO = EEO * lifetime * 4.58/1000/1000;
	NOEO = EEO * lifetime * 1.58/1000/1000;
	
	COEOT = EEO * 623/1000/1000/(13/2.2/1000);
	COEOC = EEO * 623/1000/1000/4.354;
	
	document.getElementById("co2" + s).innerHTML = precise_round(COEO,2);
	document.getElementById("so2" + s).innerHTML = precise_round(SOEO,2);
	document.getElementById("nox" + s).innerHTML = precise_round(NOEO,2);
	document.getElementById("co2t" + s).innerHTML = precise_round(COEOT,2);
	document.getElementById("co2c" + s).innerHTML = precise_round(COEOC,2);
}

function setUnits(u) {
	if(DEBUG)
		alert("setUnits(" + u + ")");

	if(u != units) {	//are we changing units
		if(u == "feet") {	//changing to English
			t = document.getElementsByTagName("table");
			for(i=0;i<t.length;i++) {
				for(j=0;j<t[i].rows.length && (t[i].className == "basic_data_table" || t[i].className == "wind_table");j++) {
					for(k=0;k<t[i].rows[j].cells.length;k++) {
						// had problem with function when the t[i].className not restricted
						// function caused select tags to reset selectedIndex attribute to -1
													
						if(DEBUG && LEVEL >= 3)
							alert(t[i].rows[j].cells[k].innerHTML);
	
						if(t[i].rows[j].cells[k].innerHTML.indexOf("(meters)") > 0)
							t[i].rows[j].cells[k].innerHTML = t[i].rows[j].cells[k].innerHTML.replace("(meters)","(feet)");
						if(t[i].rows[j].cells[k].innerHTML.indexOf("(m/s)") > 0)
							t[i].rows[j].cells[k].innerHTML = t[i].rows[j].cells[k].innerHTML.replace("(m/s)","(mph)");
						if(t[i].rows[j].cells[k].innerHTML.indexOf("30m") > 0)
							t[i].rows[j].cells[k].innerHTML = t[i].rows[j].cells[k].innerHTML.replace("30m","100ft");
						if(t[i].rows[j].cells[k].innerHTML.indexOf("50m") > 0)
							t[i].rows[j].cells[k].innerHTML = t[i].rows[j].cells[k].innerHTML.replace("50m","165ft");
						if(t[i].rows[j].cells[k].innerHTML.indexOf("W/m") > 0)
							t[i].rows[j].cells[k].innerHTML = t[i].rows[j].cells[k].innerHTML.replace("W/m","W/ft");
					}
				}
			}
			
			document.getElementById("t030").value = precise_round(GET["speed030"] * 2.24 ,2);		
			document.getElementById("tro").value = precise_round(GET["rough"] * 3.28 ,2);		
			document.getElementById("t050").innerHTML = precise_round(GET["speed050"] * 2.24 ,2);
			document.getElementById("wpd050").innerHTML = precise_round(GET["wpd050"] / 10.76 ,2);
		} else {	//changing to SI
			t = document.getElementsByTagName("table");
			for(i=0;i<t.length;i++) {
				for(j=0;j<t[i].rows.length && (t[i].className == "basic_data_table" || t[i].className == "wind_table");j++) {
					for(k=0;k<t[i].rows[j].cells.length;k++) {			
						if(DEBUG && LEVEL == 3)
							alert(t[i].rows[j].cells[k].innerHTML);
	
						if(t[i].rows[j].cells[k].innerHTML.indexOf("(feet)") > 0)
							t[i].rows[j].cells[k].innerHTML = t[i].rows[j].cells[k].innerHTML.replace("(feet)","(meters)");
						if(t[i].rows[j].cells[k].innerHTML.indexOf("(mph)") > 0)
							t[i].rows[j].cells[k].innerHTML = t[i].rows[j].cells[k].innerHTML.replace("(mph)","(m/s)");
						if(t[i].rows[j].cells[k].innerHTML.indexOf("100ft") > 0)
							t[i].rows[j].cells[k].innerHTML = t[i].rows[j].cells[k].innerHTML.replace("100ft","30m");
						if(t[i].rows[j].cells[k].innerHTML.indexOf("165ft") > 0)
							t[i].rows[j].cells[k].innerHTML = t[i].rows[j].cells[k].innerHTML.replace("165ft","50m");
						if(t[i].rows[j].cells[k].innerHTML.indexOf("W/ft") > 0)
							t[i].rows[j].cells[k].innerHTML = t[i].rows[j].cells[k].innerHTML.replace("W/ft","W/m");
					}
				}
			}

			document.getElementById("t030").value = GET["speed030"];		
			document.getElementById("tro").value = GET["rough"];		
			document.getElementById("t050").innerHTML = GET["speed050"];
			document.getElementById("wpd050").innerHTML = GET["wpd050"];
		}
	units = u;
	} else {	//not changing units
		if(u == "feet") {	//display English Units
			if(document.getElementById("t030").value == GET["speed030"])
				GET["speed030"] = precise_round(GET["speed030"] / 2.24,2);
			if(document.getElementById("t050").value == GET["speed030"])
				GET["speed050"] = precise_round(GET["speed050"] / 2.24,2);
			if(document.getElementById("tro").value == GET["rough"])
				GET["rough"] = precise_round(GET["rough"] / 3.28,2);
		}
	}
	
	towers_list(document.getElementById("turbine1").options[document.getElementById("turbine1").selectedIndex].value,"1");
	towers_list(document.getElementById("turbine2").options[document.getElementById("turbine2").selectedIndex].value,"2");
	
}

function is_valid(s) {
	if(DEBUG)
		alert("is_valid(" + s + ")");

	if(document.getElementById(s).value == "" || !IsNumeric(document.getElementById(s).value)) {	//check if cell empty or non-numeric
		document.getElementById(s).value = document.getElementById(s).defaultValue;
		ss = s.substr(s.length - 1);
		calculations(ss);
	} else {	//cell passes
		ss = s.substr(s.length - 1);
		calculations(ss);
	}

}


var rough;
var speed;

function reset_chars() {
	if(DEBUG) alert("reset_chars()");

	GET["rough"] = rough;
	GET["speed030"] = speed;
	document.getElementById("t030").value = GET["speed030"];
	document.getElementById("tro").value = GET["rough"];
	document.getElementById("units").value = GET["units"];
	calculations("1");
	calculations("2");
	
}


function goAdvanced() {
//advanced=true&street=2401+Battersea+Pl&city=Milford+Mill&st=MD&zip=21244&lat=39.324&lon=-76.76&acc=8&clat=39.324&clon=-76.761&speed050=5.28&speed030=4.74&rough=0.3&units=feet&cpkwh=35&kwu=14500&period=60&interest=6.5&turbine=22&tower=1

	url = location.href;
	if(url.indexOf("street=") > 0) //check if we have already passed our HTTP GET arguments, if so then remove the old arguments	
		url = url.substr(0,url.indexOf("street=")) + "advanced=true&" + url.substr(url.indexOf("street=")); 
	else if(url.indexOf("?") > 0) //check if HTTP GET arguments exist yet
		url = url.substr(0,url.indexOf("?") + 1) + "advanced=true&" + url.substr(url.indexOf("?") + 1); 
	else
		url = url.concat("?advanced=true");

	answer = true;
	if(GET["speed030"])
		answer = confirm("Any changes made to the wind speed and surface roughness will be lost. Do you want to continue?");
	if(answer)		
		window.location = url;
}

function wind_class() {
	if(DEBUG)
		alert("wind_class()");
		
	if(GET["wpd050"] <=200)
		document.getElementById("windclass").innerHTML = "1";
	else if(GET["wpd050"] <=300)
		document.getElementById("windclass").innerHTML = "2";
	else if(GET["wpd050"] <=400)
		document.getElementById("windclass").innerHTML = "2";
	else if(GET["wpd050"] <=500)
		document.getElementById("windclass").innerHTML = "4";
	else if(GET["wpd050"] <=600)
		document.getElementById("windclass").innerHTML = "5";
	else if(GET["wpd050"] <=700)
		document.getElementById("windclass").innerHTML = "6";
	else if(GET["wpd050"] <=800)
		document.getElementById("windclass").innerHTML = "7";
	else
		document.getElementById("windclass").innerHTML = "8";
}

//////////////////////////////////////////////////////////////////
// Google Geocoding Functions
// from: evo_google_geocode_toolkit.js v0.1
//////////////////////////////////////////////////////////////////

function how_accurate(acc) {
//	alert("how_accurate");	//debug

	acc = acc - 0;
	switch(acc) {
		case 0:
			str = "Nowhere!";
			break;
		case 1:
			str = "Country";
			break;
		case 2:
			str = "State/Provice";
			break;
		case 3:
			str = "County/Municipality";
			break;
		case 4:
			str = "City/Town";
			break;
		case 5:
			str = "Postal Code";
			break;
		case 6:
			str = "Street Level";
			break;
		case 7:
			str = "Intersection";
			break;
		case 8:
			str = "Address"
			break;
	}
	str = "Accuracy Level: " + str;
	return str;
}