// JavaScript Document


///Auto Formats Phone Number

function validate_form()
{
	if (document.registration.terms.checked == true)
	{
	var canSubmit = true;
	if (document.registration.nominate.value == 'Individual')
	{
		var individual = true;	
	} else {
		var individual = false;
	}
	
	var toAlert = "The Following Fields are missing:\n";
		if (!individual)
		{
			if (document.registration.companyName.value == '')
			{
				if (document.registration.nominate.value == 'company')
				{
					toAlert += "Company Name\n";
					canSubmit = false;		
				}
				if (document.registration.nominate.value == 'nonProfit')
				{
					toAlert += "Non Profit Group Name\n";
					canSubmit = false;			
				}
			}
		
		}
		if (document.getElementsByName('firstName')[0].value == '')
		{
			toAlert += "First Name\n";
			canSubmit = false;
		}
		
		if (document.getElementsByName('lastName')[0].value == '')
		{
			toAlert += "Last Name\n";
			canSubmit = false;
		}
	
		if (document.registration.address.value == '')
		{
			toAlert += "Address\n";
			canSubmit = false;
			
		}
		
		if (document.registration.city.value == '')
		{
			toAlert += "City\n";
			canSubmit = false;
		}
		if (document.registration.country.value == '')
		{
			toAlert += "Country\n";
			canSubmit = false;
		}
		if (document.registration.postalZip.value == '')
		{
			toAlert += "Postal Code or Zip Code\n";
			canSubmit = false;	
		}
		if (document.registration.directTel.value == '')
		{
			toAlert += "Telephone Number\n";
			canSubmit = false;
		}

				
		if (document.getElementsByName('personalEmail')[0].value == '')
		{
				toAlert += "Personal Email\n";
				canSubmit = false;
		} else {
			// Confirms Email is correctly entered
				var apos=document.getElementsByName('personalEmail')[0].value.indexOf("@");
				var dotpos=document.getElementsByName('personalEmail')[0].value.lastIndexOf(".");
				if (apos<1||dotpos-apos<2) {
					toAlert += "Email is present but not valid\n";
					canSubmit = false;
				}
		}
			
			///////
		var letter = '';	
		var numOfEntries = 0;
		for (i = 1; i <= 3; i++)
		{
			for (j = 0; j < 3; j++)
			{
				if (j == 0) { letter = 'a' };
				if (j == 1) { letter = 'b' };
				if (j == 2) { letter = 'c' };
				var category = document.getElementsByName('category' + i + letter);
				
				if (category[0].value != 'null')
				{
					var input = document.getElementsByName('input' + i + letter);
					numOfEntries++;
					
					if (input[0].value == '')
					{
						toAlert += "You have one or more categories that are missing entry text.\n";
						canSubmit = false;
						i = 10;
						j = 10;
						
					}
				}
				
				
			}		
		}
		

		
		for (i = 1; i <= 3; i++)
		{
			var hero = document.getElementById('heroId' + i);
			if (hero.checked == true)
			{
				numOfEntries++;
				if ((document.getElementsByName('firstNameHero' + i)[0].value == '') ||
					(document.getElementsByName('lastNameHero' + i)[0].value == '') ||
					(document.getElementsByName('personalEmailHero' + i)[0].value == '') ||
					(document.getElementsByName('directTelHero' + i)[0].value == '') ||
					(document.getElementsByName('cityHero' + i)[0].value == '') ||
					(document.getElementsByName('countryHero' + i)[0].value == '') ||
					(document.getElementsByName('essayHero' + i)[0].value == ''))
				{
					toAlert += "You have one or more fields missing for the Hero you have nominated.\n";	
					canSubmit = false;
					i = 10; 
					break;
				}
			}
		}
		
		if (numOfEntries == '0')
		{
			toAlert += "You have not selected any categories or heroes to nominate.\n";	
		}
			
			
				
				
		
		
		////////
		if ((document.registration.age.checked != 'true') && (individual))
		{
			toAlert = "Unfortunatly, you need to be over the age of 18 to apply. If you are, please check the box \"I am over the age of 18\"";	

		}
	
		if (canSubmit == false)
		{
			alert (toAlert);
			return false;
		} else {
			if (confirm('Please make sure that all the information you have entered is correct as you will not have a chance to change it after this point. \n\n If you would like to review the information you have entered, click "Cancel".'))
			{
				return true;
			} else {
				return false;
			}
			
		}
		
	} else {
		alert('Please read over the Terms and Conditions on the right before submiting');
		return false;
	}
		
		
}

function showOtherNominee() {
	var age = document.getElementById('ageField');
	var company = document.getElementById('fieldCompany');
	age.style.display = 'none';
	
	if (document.registration.nominate.value == 'myself')
	{
		age.style.display = 'block';
		company.style.display = 'none';
	} 
	if (document.registration.nominate.value == 'company')
	{
		document.getElementById('companyName').innerHTML = "Company Name";
		age.style.display = 'none';
		company.style.display = 'block';
	}
	if (document.registration.nominate.value == 'nonProfit')
	{
		document.getElementById('companyName').innerHTML = "Non Profit Group";
		age.style.display = 'none';
		company.style.display = 'block';
	}
}

function changeCategory(that, selCat)
{	
	
	thisCode = that.name.split("y",2);
	updatePrice();
	var entryField = document.getElementById('entry' + thisCode[1]);
	var textField = document.getElementById('descript' + thisCode[1]);
	var awardText = '';
	if(that.value != 'null')
	{	
		if (selCat != '')
		{
			document.getElementsByName('category' + selCat)[0].disabled = '';
		}
			entryField.style.display = 'block';
		switch(that.value)
		{
			case '6':
			awardText = "This award recognizes leadership in <strong>reducing</strong> a product\'s carbon footprint: using materials which have been harvested, processed, and assembled locally, minimizing packaging, maximizing shipping density in freight containers, and shipping via boat/rail rather than truck/air.";
			break;
			
			case '7':
			awardText = "This award recognizes leadership in product reuse and reuseability, in durability and extended service life, in different potential uses of the product, and in reconfigurability and modularity (ie: to maximize future reuse of some or all of the product).";
			break;
			
			case '8':
			awardText = "This award recognizes leadership in product recycling and recycleability, including maximal use of recycled content above industry norm for the product's market niche, and maximizing the ability of the product to be recycled in the future.";
			break;
			
			case '9':
			awardText = "This award will be given to the best residential energy conservation product that balances affordability, simplicity of design, unintrusiveness, innovation, compliance to industry standards, quality of performance, and payback.";
			break;
			
			case '37':
			awardText = "This award will be given to the best commercial energy conservation product that balances affordability, simplicity of design, unintrusiveness, innovation, compliance to industry standards, quality of performance, and payback.";
			break;
			
			case '10':
			awardText = "This award will be given to the best water conservation product that balances affordability, simplicity of design, unintrusiveness, innovation, compliance to industry standards, and quality of performance.";
			break;
			
			case '11':
			awardText = "This award will be given to the best water reuse product that balances affordability, simplicity of design, unintrusiveness, innovation, compliance to industry standards, and quality of performance.";
			break;
			
			case '12':
			awardText = "This award will be given to the product that best enhances the indoor environment while balancing affordability, simplicity of design, unintrusiveness, innovation, compliance to industry standards, and quality of performance.";
			break;
			
			case '13':
			awardText = "This award honours the best residential scale electrical generation product, based on electricty from renewable energy, which balances affordability, simplicity of design, unintrusiveness, innovation, compliance to industry standards, and quality of performance.";
			break;
			
			case '14':
			awardText = "This award honours the best commercial scale electrical generation product, based on electricty from renewable energy, which balances affordability, simplicity of design, unintrusiveness, innovation, compliance to industry standards, and quality of performance.";
			break;
			
			case '15':
			awardText = "This award honours the best residential scale thermal energy conversion product, based on renewable energy, which balances affordability, simplicity of design, unintrusiveness, innovation, compliance to industry standards, and quality of performance.";
			break;
			
			case '16':
			awardText = "This award honours the best commercial scale thermal energy conversion product, based on renewable energy, which balances affordability, simplicity of design, unintrusiveness, innovation, compliance to industry standards, and quality of performance.";
			break;
			
			case '17':
			awardText = "This award honours the most affordable renewable energy product globally, where affordability is measured as the normalized cost per unit of energy delivered over the first year performing in Toronto, ON, Canada, modelled with RETScreen (www.retscreen.net), expressed in $CDN/kWh (Canadian dollars per kWh of energy delivered).";
			break;
			
			case '18':
			awardText = "This award honours the most simple renewable energy product globally, where \"simplicity\" refers both to the simplicity of construction, and the simplicity of ongoing operation and maintenance.";
			break;
			
			case '19':
			awardText = "This award will recognize the most innovative new farm based renewable energy product available in 2009, and will consider affordability, simplicity of construction, intrusiveness, and demonstrated improvement or technical uniqueness over other competing products.";
			break;
			
			case '20':
			awardText = "This award will recognize the most innovative new renewable energy product globally available in 2009, and will consider affordability, simplicity of construction, intrusiveness, and demonstrated improvement or technical uniqueness over other competing products.";
			break;
			
			case '21':
			awardText = "This award will recognize the renewable energy product that demonstrates greatest success in either it's local market or the global market, where success will be measured by gross sales, greatest annual growth over the last two years, least defects/service calls over the same period, and most positive customer feedback.";
			break;
			
			case '22':
			awardText = "This award will recognize the most fuel-efficient vehicle of 2009. Vehicles of any fuel type are eligible.";
			break;
			
			case '23':
			awardText = "The overall Best Vehicle award will be given to the vehicle that can demonstrate exceptional fuel efficiency, friendliness to environmentally preferable fuels, and minimal overall emissions (including greenhouse gas emissions).";
			break;
			
			case '26':
			awardText = "The Best Builder/Developer may be from any sector (residential, commercial, other, new construction, renovation or reconstruction, etc), and this award will be given to the builder or developer best able to demonstrate a corporate sustainability policy, evidence of internal projects already implemented, commitment to and experience with third-party \"green\" building certification programs, and experience with net-zero construction.";
			break;
			
			case '27':
			awardText = "This award will honour a municipality that has accepted the challenge of climate change and who now leads by their example with advanced \"green\" policies in place and/or under development, actual municipal \"green\" projects completed to date, further projects in progress, and current public education/engagements efforts.";
			break;
			
			case '28':
			awardText = "This award will recognize one project above all others as an example of sustainability. The winning project must involve third-party testing under a regionally accepted green building program, must demonstrate local municipal support, must have quantified results (ie: work must be at least partially done and consistently with the design), must include lessons that may be integrated into other projects, and must pursue net-zero energy and water use.";
			break;
			
			case '29':
			awardText = "The Best Business award will be given to the one business that most exceptionally demonstrates leadership in corporate \"green\" (sustainability) policies, internal and external projects implemented, commitment to third-party green building programs for their buildings, and overall reduction of their corporate carbon footprint.";
			break;
			
			case '32':
			awardText = "There are many champions in the NGO community that have helped make this world a better place, and this award will recognize one NGO above all others globally that has been successful in working with local government to implement new policy development(s), that continues to be actively engaged in policy development, that has engaged the public successfully, and/or that can demonstrate the impact they have had measurably combatting climate change.";
			break;
			
			case '33':
			awardText = "This award will honour a municipality that has accepted the challenge of climate change and who now leads by their example with advanced \"green\" policies in place and/or under development, actual municipal \"green\" projects completed to date, further projects in progress, and current public education/engagements efforts.";
			break;
			
			case '34':
			awardText = "This award will recognize one project above all others as an example of sustainability. The winning project must involve third-party testing under a regionally accepted green building program, must demonstrate local municipal support, must have quantified results (ie: work must be at least partially done and consistently with the design), must include lessons that may be integrated into other projects, and must pursue net-zero energy and water use.";
			break;
			
			case '35':
			awardText = "The Best Business award will be given to the one business that most exceptionally demonstrates leadership in corporate \"green\" (sustainability) policies, internal and external projects implemented, commitment to third-party green building programs for their buildings, and overall reduction of their corporate carbon footprint.";
			break;
			
			case '36':
			awardText = "The Best Builder/Developer may be from any sector (residential, commercial, other, new construction, renovation or reconstruction, etc), and this award will be given to the builder or developer best able to demonstrate a corporate sustainability policy, evidence of internal projects already implemented, commitment to and experience with third-party \"green\" building certification programs, and experience with net-zero construction.";
			break;
			
	
			
		}
			textField.innerHTML = "<p style='font-size: 11px;'>" + awardText + "<br /><br /><strong>Tell us why you believe you/your nominee should be the recipient of this award (1200 characters or less):<br /></strong><br /><em>(Note: Nominees who succcessfully pass the first round review will be contacted for more detailed information in the second round).</em>";
		
	} else {
		//document.getElementsByName('category' + selCat)[0].disabled = 'disabled';
		//document.getElementsByName('category' + selCat.charAt(0) + 'c')[0].disabled = 'disabled';
		entryField.style.display = 'none';
	}
}

function updatePrice()
{
	tax = .05;
	var cost = 0;
	var numberOfEntries = 0;
	if ((document.getElementsByName('category1a')[0].value != 'null') && (document.getElementsByName('category1a')[0].disabled != 'disabled' )) { cost += 250;
	numberOfEntries++;};
	if ((document.getElementsByName('category1b')[0].value != 'null') && (document.getElementsByName('category1a')[0].disabled != 'disabled' )) { cost += 250 ;
	numberOfEntries++;};
	if ((document.getElementsByName('category1c')[0].value != 'null') && (document.getElementsByName('category1a')[0].disabled != 'disabled' )) { cost += 250 ;
	numberOfEntries++;};
	if ((document.getElementsByName('category2a')[0].value != 'null') && (document.getElementsByName('category1a')[0].disabled != 'disabled' )) { cost += 250 ;
	numberOfEntries++;};
	if ((document.getElementsByName('category2b')[0].value != 'null') && (document.getElementsByName('category1a')[0].disabled != 'disabled' )) { cost += 250 ;
	numberOfEntries++;};
	if ((document.getElementsByName('category2c')[0].value != 'null') && (document.getElementsByName('category1a')[0].disabled != 'disabled' )) { cost += 250; 
	numberOfEntries++;};
	if ((document.getElementsByName('category3a')[0].value != 'null') && (document.getElementsByName('category1a')[0].disabled != 'disabled' )) { cost += 250; 
	numberOfEntries++;};
	if ((document.getElementsByName('category3b')[0].value != 'null') && (document.getElementsByName('category1a')[0].disabled != 'disabled' )) { cost += 250; 
	numberOfEntries++;};
	if ((document.getElementsByName('category3c')[0].value != 'null') && (document.getElementsByName('category1a')[0].disabled != 'disabled' )) { cost += 250 ;
	numberOfEntries++;};
	
	document.getElementById('inputNum').value = numberOfEntries;	
	document.getElementById('spanCost').innerHTML = cost.toFixed(2);
	document.getElementById('inputCost').value = cost;
	document.getElementById('spanEntries').innerHTML = numberOfEntries;
	var costTax = cost * tax;
	var total = costTax + cost;
	document.getElementById('spanTax').innerHTML = costTax.toFixed(2);
	document.getElementById('spanTotal').innerHTML = total.toFixed(2);	
	

	
	
}

function showOtherNominee() {
	var age = document.getElementById('ageField');
	var companyNom = document.getElementById('fieldCompany');
	companyNom.style.display = 'none';
	age.style.display = 'none';
	
	if (document.registration.nominate.value == 'Company')
	{
		companyNom.style.display = 'block';
		document.getElementById('companyName').innerHTML = 'Company Name';
		
	} 
	if (document.registration.nominate.value == 'Non-Profit Group')
	{
		companyNom.style.display = 'block';
		document.getElementById('companyName').innerHTML = 'Non Profit Group';
	} 
	if (document.registration.nominate.value == 'Individual')
	{
		age.style.display = 'block';
	} 
}

function showHeroBox(that)
{
	if (document.getElementById('heroId' + that).checked == true)
	{
		document.getElementById('heroDiv' + that).style.display = 'block';
	} else {
		document.getElementById('heroDiv' + that).style.display = 'none';	
	}
}