var addNumTrees=1;
var treeTypes=1;

function addAnotherTreeType(){
	var treeTypesSpan=document.getElementById("treeTypes");
	var typesInnerHtml=treeTypesSpan.innerHTML;
	var storeCurrentData=storeCurrent();
	treeTypes=treeTypes+1;
	var theNewInnerHTML=typesInnerHtml+getTreeTypeSpan(treeTypes);
	treeTypesSpan.innerHTML=theNewInnerHTML;
	restoreData(storeCurrentData);
}
function storeCurrent(){
	var current=new Array();
	for(var i=1;i<=treeTypes;i++){
		var spanName="tree"+i;
		if(document.getElementById(spanName).innerHTML.length>0){
			current[current.length]=getCurrent(i);
		}
	}
	return(current);
}
function getCurrent(spanNumber){
	var theArray=new Array();
	theArray[0]=spanNumber;
	var theId="treeSpecies"+spanNumber;
	theArray[1]=document.getElementById(theId).selectedIndex;
	theId="treeHeight"+spanNumber;
	for (i=0;i<document.RegTree[theId].length;i++)
	{
		if(document.RegTree[theId][i].checked)
		{
			theArray[2]=document.RegTree[theId][i].id;	
		}
	}
	theId="treeQuantity"+spanNumber;
	theArray[3]=document.getElementById(theId).value;	
	theId="Where Did You Get Your Tree "+spanNumber;
	for (i=0;i<document.RegTree[theId].length;i++)
	{
		if(document.RegTree[theId][i].checked)
		{
			theArray[4]=document.RegTree[theId][i].id;	
		}
	}
	theId="Where Did You Get Your Tree - Local Nursery "+spanNumber;
	theArray[5]=document.getElementById(theId).value;
	theId="Where Did You Get Your Tree - Other "+spanNumber;
	theArray[6]=document.getElementById(theId).value;
	return(theArray);
}
function restoreData(storedData){
	for(var i=0;i<storedData.length;i++)
	{
		var spanNumber=storedData[i][0];
		var theId="treeSpecies"+spanNumber;
		document.getElementById(theId).selectedIndex=storedData[i][1];
		theId=storedData[i][2];
		if (theId != undefined){			
			document.RegTree[theId].checked=true;
		}
		theId="treeQuantity"+spanNumber;
		document.getElementById(theId).value=storedData[i][3];
		theId=storedData[i][4];
		if (theId != undefined){
			document.RegTree[theId].checked=true;
		}
		theId="Where Did You Get Your Tree - Local Nursery "+spanNumber;
		document.getElementById(theId).value=storedData[i][5];
		theId="Where Did You Get Your Tree - Other "+spanNumber;
		document.getElementById(theId).value=storedData[i][6];
	}
}
function getTreeTypeSpan(typeNumber){
	var displayTypeNum = typeNumber-1
	var theSpan='<span id="tree'+typeNumber+'"><p class="headline">Species '+ displayTypeNum+'</p>';
	
	theSpan=theSpan+'<table><tbody><tr><td class="contactLabel"><span class="red_bold">*</span>What kind of tree did you plant?</td>';
	theSpan=theSpan+'<td class="contactField"><select id="treeSpecies'+typeNumber+'" name="Tree Species '+typeNumber+'"><option selected value="">Plese select the appropriate species</option>';
	theSpan=theSpan+'<option value="Arborvitae (Thuja)">Arborvitae (Thuja)</option>';
	theSpan=theSpan+'<option value="Ash (Fraxinus)">Ash (Fraxinus)</option>';
	theSpan=theSpan+'<option value="Beech (Fagus)">Beech (Fagus)</option>';
	theSpan=theSpan+'<option value="Birch (Betula)">Birch (Betula)</option>';
	theSpan=theSpan+'<option value="Catalpa (Catalpa)">Catalpa (Catalpa)</option>';
	theSpan=theSpan+'<option value="Cedar (Cedrus)">Cedar (Cedrus)</option>';
	theSpan=theSpan+'<option value="Cedar, Atlantic White (Chamaecyparis)">Cedar, Atlantic White (Chamaecyparis)</option>';
	theSpan=theSpan+'<option value="Cherry (Prunus)">Cherry (Prunus)</option>';
	theSpan=theSpan+'<option value="Coffee Tree, Kentucky (Gymnocladus)">Coffee Tree, Kentucky (Gymnocladus)</option>';
	theSpan=theSpan+'<option value="Cornelian Cherry (Cornus)">Cornelian Cherry (Cornus)</option>';
	theSpan=theSpan+'<option value="Crabapple (Malus)">Crabapple (Malus)</option>';
	theSpan=theSpan+'<option value="Crepe myrtle (Lagerstroemia)">Crepe myrtle (Lagerstroemia)</option>';
	theSpan=theSpan+'<option value="Cryptomeria (Cryptomeria)">Cryptomeria (Cryptomeria)</option>';
	theSpan=theSpan+'<option value="Cypress (Taxodium)">Cypress (Taxodium)</option>';
	theSpan=theSpan+'<option value="Cypress (Chamaecyparis)">Cypress (Chamaecyparis)</option>';
	theSpan=theSpan+'<option value="Dogwood (Cornus)">Dogwood (Cornus)</option>';
	theSpan=theSpan+'<option value="Dovetree (Davidia)">Dovetree (Davidia)</option>';
	theSpan=theSpan+'<option value="Elm (Ulmus)">Elm (Ulmus)</option>';
	theSpan=theSpan+'<option value="Fig (Ficus)">Fig (Ficus)</option>';
	theSpan=theSpan+'<option value="Filbert (Corylus)">Filbert (Corylus)</option>';
	theSpan=theSpan+'<option value="Fir (Abies)">Fir (Abies)</option>';
	theSpan=theSpan+'<option value="Fringetree (Chionanthus)">Fringetree (Chionanthus)</option>';
	theSpan=theSpan+'<option value="Ginkgo (Ginkgo)">Ginkgo (Ginkgo)</option>';
	theSpan=theSpan+'<option value="Goldenchain tree (Laburnum)">Goldenchain tree (Laburnum)</option>';
	theSpan=theSpan+'<option value="Goldenraintree (Koelreuteria)">Goldenraintree (Koelreuteria)</option>';
	theSpan=theSpan+'<option value="Hackberry (Celtis)">Hackberry (Celtis)</option>';
	theSpan=theSpan+'<option value="Hawthorn (Crataegus)">Hawthorn (Crataegus)</option>';
	theSpan=theSpan+'<option value="Hickory (Carya)">Hickory (Carya)</option>';
	theSpan=theSpan+'<option value="Holly (Ilex)">Holly (Ilex)</option>';
	theSpan=theSpan+'<option value="Honeylocust (Gleditsia)">Honeylocust (Gleditsia)</option>';
	theSpan=theSpan+'<option value="Hophornbeam (Ostrya)">Hophornbeam (Ostrya)</option>';
	theSpan=theSpan+'<option value="Hornbeam (Carpinus)">Hornbeam (Carpinus)</option>';
	theSpan=theSpan+'<option value="Horsechestnut (Aesculus)">Horsechestnut (Aesculus)</option>';
	theSpan=theSpan+'<option value="Japanese lilac tree (Syringa)">Japanese lilac tree (Syringa)</option>';
	theSpan=theSpan+'<option value="Juniper (Juniperus)">Juniper (Juniperus)</option>';
	theSpan=theSpan+'<option value="Kasturatree (Cercidiphyllum)">Kasturatree (Cercidiphyllum)</option>';
	theSpan=theSpan+'<option value="Larch (Larix)">Larch (Larix)</option>';
	theSpan=theSpan+'<option value="Linden (Tilia)">Linden (Tilia)</option>';
	theSpan=theSpan+'<option value="Locust (Robinia)">Locust (Robinia)</option>';
	theSpan=theSpan+'<option value="Maackia (Maackia)">Maackia (Maackia)</option>';
	theSpan=theSpan+'<option value="Magnolia (Magnolia)">Magnolia (Magnolia)</option>';
	theSpan=theSpan+'<option value="Maple (Acer)">Maple (Acer)</option>';
	theSpan=theSpan+'<option value="Mountain ash (Sorbus)">Mountain ash (Sorbus)</option>';
	theSpan=theSpan+'<option value="Oak (Quercus)">Oak (Quercus)</option>';
	theSpan=theSpan+'<option value="Olive (Elaeagnus)">Olive (Elaeagnus)</option>';
	theSpan=theSpan+'<option value="Pagodatree (Styphnolobium)">Pagodatree (Styphnolobium)</option>';
	theSpan=theSpan+'<option value="Parrotia (Parrotia)">Parrotia (Parrotia)</option>';
	theSpan=theSpan+'<option value="Pear (Pyrus)">Pear (Pyrus)</option>';
	theSpan=theSpan+'<option value="Pine (Pinus)">Pine (Pinus)</option>';
	theSpan=theSpan+'<option value="Planetree (Platanus x acerifolia)">Planetree (Platanus x acerifolia)</option>';
	theSpan=theSpan+'<option value="Plum (Prunus cerasifera)">Plum (Prunus cerasifera)</option>';
	theSpan=theSpan+'<option value="Popular (Populus)">Popular (Populus)</option>';
	theSpan=theSpan+'<option value="Redbud (Cercis)">Redbud (Cercis)</option>';
	theSpan=theSpan+'<option value="Redcedar (Juniperus)">Redcedar (Juniperus)</option>';
	theSpan=theSpan+'<option value="Redwood (Metasequoia)">Redwood (Metasequoia)</option>';
	theSpan=theSpan+'<option value="Rubber tree (Eucommia)">Rubber tree (Eucommia)</option>';
	theSpan=theSpan+'<option value="Serviceberry (Amelanchier)">Serviceberry (Amelanchier)</option>';
	theSpan=theSpan+'<option value="Silverbell (Halesia)">Silverbell (Halesia)</option>';
	theSpan=theSpan+'<option value="Smoke tree (Cotinus)">Smoke tree (Cotinus)</option>';
	theSpan=theSpan+'<option value="Snowbell (Styrax)">Snowbell (Styrax)</option>';
	theSpan=theSpan+'<option value="Sourwood (Oxydendron)">Sourwood (Oxydendron)</option>';
	theSpan=theSpan+'<option value="Spruce (Picea)">Spruce (Picea)</option>';
	theSpan=theSpan+'<option value="Stewartia (Stewartia)">Stewartia (Stewartia)</option>';
	theSpan=theSpan+'<option value="Sweetgum (Liquidambar)">Sweetgum (Liquidambar)</option>';
	theSpan=theSpan+'<option value="Sycamore (Platanus)">Sycamore (Platanus)</option>';
	theSpan=theSpan+'<option value="Tuliptree (Liriodendron)">Tuliptree (Liriodendron)</option>';
	theSpan=theSpan+'<option value="Tupelo (Nyssa)">Tupelo (Nyssa)</option>';
	theSpan=theSpan+'<option value="Walnut (Juglans)">Walnut (Juglans)</option>';
	theSpan=theSpan+'<option value="Willow (Salix)">Willow (Salix)</option>';
	theSpan=theSpan+'<option value="Witchhazel (Hamamellis)">Witchhazel (Hamamellis)</option>';
	theSpan=theSpan+'<option value="Yellowwood (Cladrastis)">Yellowwood (Cladrastis)</option>';
	theSpan=theSpan+'<option value="Zelkova (Zelkova)">Zelkova (Zelkova)</option>';
	theSpan=theSpan+'<option value="Unkown">Unkown</option></select></td>';
	theSpan=theSpan+'<tr><td colspan="2"><img border="0" alt="" src="../../includes/site_images/spacers/spacer.gif" width="484" height="3"></td></tr>';
	theSpan=theSpan+'<tr><td colspan="2"><table border="0" cellspacing="0" cellpadding="0" width="0"><tbody><tr><td colspan="5"><span class="red_bold">*</span>Please specify tree height at time of planting - see graphic below:</td></tr><tr><td colspan="5"><img border="0" alt="" src="../../includes/site_images/spacers/spacer.gif" width="484" height="3"></td></tr>';
	theSpan=theSpan+'<tr><td onclick="document.getElementById(\'Tree'+typeNumber+'_2-3\').checked=true;" align="middle"><img border="0" alt="2-3 ft." src="http://www.milliontreesnyc.org/images/misc/2-3.gif" width="99" height="133"><br><input id="Tree'+typeNumber+'_2-3" value="2-3 ft." type="radio" name="treeHeight'+typeNumber+'"> 2-3 ft.</td><td background="../../includes/site_images/misc/vert_dots.gif" width="1"><img border="0" alt="" src="../../includes/site_images/spacers/spacer.gif" width="1" height="155"></td>';
	theSpan=theSpan+'<td onclick="document.getElementById(\'Tree'+typeNumber+'_4-5\').checked=true;" align="middle"><img border="0" alt="4-5 ft." src="http://www.milliontreesnyc.org/images/misc/4-5.gif" width="99" height="133"><br><input id="Tree'+typeNumber+'_4-5" value="4-5 ft." type="radio" name="treeHeight'+typeNumber+'"> 4-5 ft.</td><td background="../../includes/site_images/misc/vert_dots.gif" width="1"><img border="0" alt="" src="../../includes/site_images/spacers/spacer.gif" width="1" height="155"></td>';
	theSpan=theSpan+'<td onclick="document.getElementById(\'Tree'+typeNumber+'1_6up\').checked=true;" align="middle"><img border="0" alt="6 ft. &amp; up" src="http://www.milliontreesnyc.org/images/misc/6up.gif" width="99" height="133"><br><input id="Tree'+typeNumber+'_6up" value="6ft. &amp; up" type="radio" name="treeHeight'+typeNumber+'"> 6 ft. &amp; up</td></tr>';
	theSpan=theSpan+'<tr><td colspan="5"><img border="0" alt="" src="../../includes/site_images/spacers/spacer.gif" width="484" height="3"></td></tr><tr><td colspan="5"><p>REMEMBER: MillionTreesNYC is not counting trees planted in planter boxes, shrubs or seedlings (trees less than&#160;2 feet tall).</p></td></tr></tbody></table></td></tr>';
	theSpan=theSpan+'<tr><td colspan="2"><img border="0" alt="" src="../../includes/site_images/spacers/spacer.gif" width="484" height="3"></td></tr><tr><td class="contactLabel"><span class="red_bold">*</span>How many of the selected species did you plant?</td><td class="contactField"><input id="treeQuantity'+typeNumber+'" maxlength="10" size="10" name="Tree Quantity '+typeNumber+'"></td></tr>';
	theSpan=theSpan+'<tr><td colspan="2"><img border="0" alt="" src="../../includes/site_images/spacers/spacer.gif" width="484" height="3"></td></tr><tr><td class="contactLabel"><span class="red_bold">*</span>Where Did You Get Your Tree(s)?</td><td class="contactField"><input value="Local Nursery" type="radio" id="Tree'+typeNumber+'_LocalNursery" name="Where Did You Get Your Tree '+typeNumber+'">Local Nursery, please specify:<br><input style="WIDTH: 283px; HEIGHT: 22px" maxlength="50" size="41" name="Where Did You Get Your Tree - Local Nursery '+typeNumber+'" id="Where Did You Get Your Tree - Local Nursery '+typeNumber+'"><br><input value="Tree Giveaway" id="Tree'+typeNumber+'_TreeGiveaway" type="radio" name="Where Did You Get Your Tree '+typeNumber+'">MillionsTreesNYC Tree Giveaway<br><input value="Retail Location" id="Tree'+typeNumber+'_RetailLocation" type="radio" name="Where Did You Get Your Tree '+typeNumber+'">Retail Location<br><input value="Other" id="Tree'+typeNumber+'_Other" type="radio" name="Where Did You Get Your Tree '+typeNumber+'">Other, please specify:<br><input style="WIDTH: 283px; HEIGHT: 22px" maxlength="50" size="41" name="Where Did You Get Your Tree - Other '+typeNumber+'" id="Where Did You Get Your Tree - Other '+typeNumber+'"> </td></tr>';
	
	theSpan=theSpan+'</tbody></table>';
	if (typeNumber != 2){
		theSpan=theSpan+'<p align="right"><a href="javascript:removeTreeType('+typeNumber+')">Remove This Tree</a></p>';
	}
	theSpan=theSpan+'</span><!--end span tree'+typeNumber+'-->';
	return(theSpan);
}
function removeTreeType(typeNumber){
	var theSpanName="tree"+typeNumber;
	var theSpan=document.getElementById(theSpanName);
	theSpan.innerHTML="";
}