// Arun JavaScript Document
// ========================
var xmlDoc;
var easting = 0;
var northing = 0;
var zoom = "500";
var mapWidth = 400;
var mapHeight = 400;

function resizeIframeToFitContent(iframe) {
    // This function resizes an IFrame object
    // to fit its content.
    // The IFrame tag must have a unique ID attribute.
   	if (document.getElementById("planiframe") != null) {
		//alert(document.getElementById('planiframe').contentWindow.document.body.scrollHeight);
	    iframe.height = document.getElementById('planiframe').contentWindow.document.body.scrollHeight;
	}
}

function search_setfocus() {
   window.document.searchform.Terms.focus();
   window.document.searchform.Terms.select();
}

function submit_form() {
   if (window.document.searchform.q.value=='') {
   } else {
      window.document.searchform.submit();
   }
}

function submit_refuse_form(){
   if (window.document.refuseform.street.value=='') {
      alert('Please enter a street name, part of a street name');
      window.document.refuseform.street.focus();
   } else {
      if (window.document.refuseform.street.value.length < 3) {
         alert('To search for a street, you must enter at least three charcaters.');
         window.document.refuseform.street.focus();
      } else {
         window.document.refuseform.submit();
      }
   }
}

function jumpMenu(targ,selObj,restore) {
   eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
   if (restore) {
      selObj.selectedIndex=0;
   }
}

function xmlLoadedStreet() {
   var numberFeatures = 0;
   for (featureCount=0; featureCount < xmlDoc.getElementsByTagName("Feature").length; featureCount++) {
      if (xmlDoc.getElementsByTagName("RecType")[featureCount].childNodes[0].nodeValue == 1) {
         numberFeatures++;
      }
   }
   if (numberFeatures == 0) {
      alert("Sorry, the street name could not be found");
      window.document.addressSearchForm.searchField.focus();
      window.document.addressSearchForm.searchField.select();
   } else {
      if (numberFeatures == 1) {
         easting = parseInt(xmlDoc.getElementsByTagName("MidX")[0].childNodes[0].nodeValue);
         northing = parseInt(xmlDoc.getElementsByTagName("MidY")[0].childNodes[0].nodeValue);
         window.location.href = 'http://www.arun.gov.uk/cgi-bin/buildpage.pl?mysql=3364&easting=' + easting + '&northing=' + northing;
      } else {
         var numberRows = document.getElementById('resultTable').rows.length;
         if (numberRows > 0) {
            for (rowCount=0; rowCount < numberRows; rowCount++) {
               document.getElementById('resultTable').deleteRow(0);
            }
         }
         var tableRow = document.getElementById('resultTable').insertRow(0);
         var tableCell = tableRow.insertCell(0);
         tableCell.innerHTML = "<strong>Search Results</strong>";
         for (rowCount=0; rowCount < numberFeatures; rowCount++) {
             var newRow = rowCount + 1;
             var tableRow = document.getElementById('resultTable').insertRow(newRow);
             var tableCell = tableRow.insertCell(0);
             easting = parseInt(xmlDoc.getElementsByTagName("MidX")[rowCount].childNodes[0].nodeValue);
             northing = parseInt(xmlDoc.getElementsByTagName("MidY")[rowCount].childNodes[0].nodeValue);
             tableCell.innerHTML = "<a href='http://www.arun.gov.uk/cgi-bin/buildpage.pl?mysql=3364&easting=" + easting + "&northing=" + northing + "'>" + xmlDoc.getElementsByTagName("Street")[rowCount].childNodes[0].nodeValue + "</a>";
         }
      }
      window.document.addressSearchForm.searchField.focus();
      window.document.addressSearchForm.searchField.select();
   }
}
function xmlLoadedStreetNotIE() {
   var numberFeatures = 0;
   var tagName = "";
   var tagData = "";
   var writeTag = "no";
   var streetElement = new Array();
   var midXElement = new Array();
   var midYElement = new Array();
   
   for (charCount=0; charCount < xmlDoc.responseText.length; charCount++) {
         if (xmlDoc.responseText.substr(charCount,1) == "<") {
			 tagName = tagName + xmlDoc.responseText.substr(charCount,1);
			 writeTag = "yes";
		 } else {
 		    if (xmlDoc.responseText.substr(charCount,1) == ">") {
			   tagName = tagName + xmlDoc.responseText.substr(charCount,1);
  		       writeTag = "no";
			   if (tagName.length > 7) {
			      if (tagName.substr(0,8) == "<Feature") { numberFeatures++; }
			   }
			   if (tagName == "</Street>") { streetElement[numberFeatures] = tagData; }
			   if (tagName == "</MidX>") { midXElement[numberFeatures] = tagData; }
			   if (tagName == "</MidY>") { midYElement[numberFeatures] = tagData; }
			   tagName = "";
			   tagData = "";
		    } else {
			   if (writeTag == "yes") {
			      tagName = tagName + xmlDoc.responseText.substr(charCount,1);
			   } else {
				  tagData = tagData + xmlDoc.responseText.substr(charCount,1);
			   }
			}
		 }
   }
   if (numberFeatures == 0) {
      alert("Sorry, the street name could not be found");
      window.document.addressSearchForm.searchField.focus();
      window.document.addressSearchForm.searchField.select();
   } else {
      if (numberFeatures == 1) {
         easting = parseInt(midXElement[1]);
         northing = parseInt(midYElement[1]);
         window.location.href = 'http://www.arun.gov.uk/cgi-bin/buildpage.pl?mysql=3364&easting=' + easting + '&northing=' + northing;
      } else {
		 var numberRows = document.getElementById('resultTable').rows.length;
         if (numberRows > 0) {
            for (rowCount=0; rowCount < numberRows; rowCount++) {
               document.getElementById('resultTable').deleteRow(0);
            }
         }
         var tableRow = document.getElementById('resultTable').insertRow(0);
         var tableCell = tableRow.insertCell(0);
         tableCell.innerHTML = "<strong>Search Results</strong>";
         for (rowCount=1; rowCount <= numberFeatures; rowCount++) {
             var newRow = rowCount;
             var tableRow = document.getElementById('resultTable').insertRow(newRow);
             var tableCell = tableRow.insertCell(0);
             easting = parseInt(midXElement[rowCount]);
             northing = parseInt(midYElement[rowCount]);
             tableCell.innerHTML = "<a href='http://www.arun.gov.uk/cgi-bin/buildpage.pl?mysql=3364&easting=" + easting + "&northing=" + northing + "'>" + streetElement[rowCount] + "</a>";
         }
	  }
   }
}

function check_street() {
   var upperStreet = window.document.addressSearchForm.searchField.value.toUpperCase();
   if (upperStreet == "") {
      alert("Please enter a street name");
      window.document.addressSearchForm.searchField.focus();
   } else {
      if (window.ActiveXObject) {
         xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
         xmlDoc.async=false;
         xmlDoc.load("http://www.arun.gov.uk/maps/planaccess2/dialogbox_InfoPointViewer.asp?infomode=xml&theme=BaseMapMain&layername=ArunStreetGaz&fieldname=StreetName&fieldvalue=" + upperStreet);
         xmlLoadedStreet();
      }
	  else if (typeof XMLHttpRequest != 'undefined') {
		 xmlDoc = new XMLHttpRequest();
		 xmlDoc.onreadystatechange = function() {
			 if (xmlDoc.readyState == 4) {
				 xmlLoadedStreetNotIE();
			 }
		 }
		 xmlDoc.open("GET","http://www.arun.gov.uk/maps/planaccess2/dialogbox_InfoPointViewer.asp?infomode=xml&theme=BaseMapMain&layername=ArunStreetGaz&fieldname=StreetName&fieldvalue=" + upperStreet,true);
		 xmlDoc.send(null);
      }
   }
}

function update_map(switchTheme) {
   document.planaccess.easting.value = easting;
   document.planaccess.northing.value = northing;
   document.planaccess.zoom.value = zoom;
   if (location.search.indexOf("mysql=3524&easting") > 0) {
      var themeName = "BaseMapMain";
   } else {
      if (switchTheme == "Y") {
         if (document.getElementById('currentView').innerHTML == "Switch to Aerial View") {
            document.getElementById('currentView').innerHTML = "Switch to Map View";
         } else {
            document.getElementById('currentView').innerHTML = "Switch to Aerial View";
         }
      }
      if (document.getElementById('currentView').innerHTML == "Switch to Aerial View") {
         var themeName = "BaseMapMain";
      } else {
         var themeName = "AerialMain";
      }
   }
   document.planaccess.arunMap.src = "http://www.arun.gov.uk/maps/planaccess2/getmapimage.asp?Theme=" + themeName + "&zoom=" + zoom + "&mapwidth=400&mapheight=400&easting=" + easting + "&northing=" + northing;
}

function update_small_map(switchTheme) {
   easting = parseInt(location.search.substring((location.search.indexOf("?easting=") + 9), (location.search.indexOf("?easting=") + 15)));
   northing = parseInt(location.search.substring((location.search.indexOf("&northing=") + 10), (location.search.indexOf("&northing=") + 16)));
   if (switchTheme == "Y") {
      if (document.getElementById('currentView').innerHTML == "Aerial Photo") {
         document.getElementById('currentView').innerHTML = "Map";
      } else {
         document.getElementById('currentView').innerHTML = "Aerial Photo";
      }
   }
   if (document.getElementById('currentView').innerHTML == "Aerial Photo") {
      var themeName = "BaseMapMain";
   } else {
      var themeName = "AerialMain";
   }
   document.arunMap.src = "http://www.arun.gov.uk/maps/planaccess2/getmapimage.asp?Theme=" + themeName + "&zoom=100&mapwidth=200&mapheight=200&easting=" + easting + "&northing=" + northing;
}

function showMap() {
   if ((location.search.indexOf("mysql=3364&easting") > 0) || (location.search.indexOf("mysql=3524&easting") > 0)) {
      easting = parseInt(location.search.substring((location.search.indexOf("&easting=") + 9), (location.search.indexOf("&easting=") + 15)));
      northing = parseInt(location.search.substring((location.search.indexOf("&northing=") + 10), (location.search.indexOf("&northing=") + 16)));
      update_map();
   } else {
      if (location.search.indexOf("mysql=3363") > 0) {
         window.document.addressSearchForm.searchField.focus();
      } else {
         if (location.search.indexOf("action=newEvent") > 0) {
            window.document.newEventForm.title.focus();
		 } else {
			if (location.search.indexOf("mysql=3693") > 0) {
				document.getElementById('ProjectName').focus();
			}
         }
      }
   }
}

function zoomMap(zoomMetres) {
   if (zoom != zoomMetres) {
      zoom = zoomMetres;
      update_map("N");
   }
}

function panMap(panDirection) {
   switch (panDirection) {
           case "n":
                northing = northing + zoom/2;
                break;
           case "ne":
                northing = northing + zoom/2;
                easting = easting + zoom/2;
                break;
           case "nw":
                northing = northing + zoom/2;
                easting = easting - zoom/2;
                break;
           case "e":
                easting = easting + zoom/2;
                break;
           case "s":
                northing = northing - zoom/2;
                break;
           case "se":
                northing = northing - zoom/2;
                easting = easting + zoom/2;
                break;
           case "sw":
                northing = northing - zoom/2;
                easting = easting - zoom/2;
                break;
           case "w":
                easting = easting - zoom/2;
                break;
   }
   update_map("N");
}

function getProperty(mouseEvent) {
   var internetExplorer=document.all;
   if (!mouseEvent) { mouseEvent = window.event; }
   if (internetExplorer) {
      var mouseX = mouseEvent.offsetX;
      var mouseY = mouseEvent.offsetY;
   } else {
      var mouseX = mouseEvent.pageX - document.planaccess.arunMap.x;
      var mouseY = mouseEvent.pageY - document.planaccess.arunMap.y;
   }
   var mapWest = easting - (zoom/2);
   var mapEast = easting + (zoom/2);
   var mapNorth = northing - (zoom/2);
   var mapSouth = northing + (zoom/2);
   var propEasting = Math.round(((mouseX / mapWidth) * (mapEast - mapWest)) + mapWest);
   var propNorthing = Math.round(mapSouth - ((mouseY / mapHeight) * (mapSouth - mapNorth)));
   if (zoom == '100') {
      window.location.href = 'http://www.arun.gov.uk/maps/propertyaccount/parser.asp?easting=' + propEasting + '&northing=' + propNorthing;
   } else {
      zoom = '100';
      easting = propEasting;
      northing = propNorthing;
      update_map("N");
   }
}

function ShowPoiPopUp() {
   window.open("http://www.arun.gov.uk/maps/planaccess2/planaccess.asp?theme=BaseMapMain&mapbuttons=11111&minzoomlevel=100&maxzoomlevel=10000&framepanels=0010000&style=propertyaccount","newwindow", config="height=600px, width=800px, toolbar=no, menubar=no, scrollbars=no, resizable=no, directories=no, status=no");
}
function ValidAmount(formField) {
   var validChars = "0123456789.";
   var ValidAmount=true;
   var formChar;
 
   for (i = 0; i < formField.length && ValidAmount == true; i++) { 
      formChar = formField.charAt(i); 
      if (validChars.indexOf(formChar) == -1) { ValidAmount = false; }
   }
   return ValidAmount;
}

function ValidateCleanAndSafeForm() {
	var errorNumber = 0;
	
	// Question 1 - NAME & BRIEF DESCRIPTION OF PROJECT 
	if (document.getElementById("ProjectName").value == "" || document.getElementById("ProjectName").value == "You must answer this question") {
		errorNumber = 1;
		document.getElementById("ProjectName").style.backgroundColor = "#FF0000";
		document.getElementById("ProjectName").value = "You must answer this question";
	} else {
		document.getElementById("ProjectName").style.backgroundColor = "#FFFFFF";
	}
	// Question 2 - PROJECT LEAD & CONTACT DETAILS
	if (document.getElementById("ProjectLead").value == "" || document.getElementById("ProjectLead").value == "You must answer this question") {
		if (errorNumber == 0) {	errorNumber = 2; }
		document.getElementById("ProjectLead").style.backgroundColor = "#FF0000";
		document.getElementById("ProjectLead").value = "You must answer this question";
	} else {
		document.getElementById("ProjectLead").style.backgroundColor = "#FFFFFF";
	}
	// Question 3 - WHAT WILL THE PROJECT COST IN TOTAL?
	if (document.getElementById("ProjectCost").value == "" || document.getElementById("ProjectCost").value == "Enter Amount") {
		if (errorNumber == 0) {	errorNumber = 3; }
		document.getElementById("ProjectCost").style.backgroundColor = "#FF0000";
		document.getElementById("ProjectCost").value = "Enter Amount";
	} else {
		if (ValidAmount(document.getElementById("ProjectCost").value) == false) {
			if (errorNumber == 0) {	errorNumber = 3; }
			document.getElementById("ProjectCost").style.backgroundColor = "#FF0000";
		} else {
			document.getElementById("ProjectCost").style.backgroundColor = "#FFFFFF";
		}
	}
	// Question 4 - HOW MUCH FUNDING DO YOU REQUIRE FROM THE CLEAN AND SAFE GRANT FUND?
	if (document.getElementById("FundingRequired").value == "" || document.getElementById("FundingRequired").value == "Enter amount") {
		if (errorNumber == 0) {	errorNumber = 4; }
		document.getElementById("FundingRequired").style.backgroundColor = "#FF0000";
		document.getElementById("FundingRequired").value = "Enter amount";
	} else {
		if (ValidAmount(document.getElementById("FundingRequired").value) == false) {
			if (errorNumber == 0) {	errorNumber = 4; }
			document.getElementById("FundingRequired").style.backgroundColor = "#FF0000";
		} else {
			document.getElementById("FundingRequired").style.backgroundColor = "#FFFFFF";
		}
	}
	if (document.getElementById("FundingItem1").value == "" || document.getElementById("FundingItem1").value == "You must answer this question") {
		if (errorNumber == 0) {	errorNumber = 5; }
		document.getElementById("FundingItem1").style.backgroundColor = "#FF0000";
		document.getElementById("FundingItem1").value = "You must answer this question";
	} else {
		document.getElementById("FundingItem1").style.backgroundColor = "#FFFFFF";
	}
	if (document.getElementById("FundingItemAmount1").value == "" || document.getElementById("FundingItemAmount1").value == "Enter amount") {
		if (errorNumber == 0) {	errorNumber = 6; }
		document.getElementById("FundingItemAmount1").style.backgroundColor = "#FF0000";
		document.getElementById("FundingItemAmount1").value = "Enter amount";
	} else {
		if (ValidAmount(document.getElementById("FundingItemAmount1").value) == false) {
			if (errorNumber == 0) {	errorNumber = 6; }
			document.getElementById("FundingItemAmount1").style.backgroundColor = "#FF0000";
		} else {
			document.getElementById("FundingItemAmount1").style.backgroundColor = "#FFFFFF";
		}
	}
	// Question 5 - WHICH OTHER ORGANISATIONS ARE PROVIDING FUNDING FOR THE PROJECT? 
	if (document.getElementById("Source1").value == "" || document.getElementById("Source1").value == "You must answer this question") {
		if (errorNumber == 0) {	errorNumber = 7; }
		document.getElementById("Source1").style.backgroundColor = "#FF0000";
		document.getElementById("Source1").value = "You must answer this question";
	} else {
		document.getElementById("Source1").style.backgroundColor = "#FFFFFF";
	}
	if (document.getElementById("SourceConfirmed1_0").checked != 1 && document.getElementById("SourceConfirmed1_1").checked != 1) {
		if (errorNumber == 0) {	errorNumber = 8; }
	}
	if (document.getElementById("SourceAmount1_2009").value == "" || document.getElementById("SourceAmount1_2009").value == "Enter amount") {
		if (errorNumber == 0) {	errorNumber = 9; }
		document.getElementById("SourceAmount1_2009").style.backgroundColor = "#FF0000";
		document.getElementById("SourceAmount1_2009").value = "Enter amount";
	} else {
		if (ValidAmount(document.getElementById("SourceAmount1_2009").value) == false) {
			if (errorNumber == 0) {	errorNumber = 9; }
			document.getElementById("SourceAmount1_2009").style.backgroundColor = "#FF0000";
		} else {
			document.getElementById("SourceAmount1_2009").style.backgroundColor = "#FFFFFF";
		}
	}
	if (document.getElementById("SourceAmount1_2010").value == "" || document.getElementById("SourceAmount1_2010").value == "Enter amount") {
		if (errorNumber == 0) {	errorNumber = 10; }
		document.getElementById("SourceAmount1_2010").style.backgroundColor = "#FF0000";
		document.getElementById("SourceAmount1_2010").value = "Enter amount";
	} else {
		if (ValidAmount(document.getElementById("SourceAmount1_2010").value) == false) {
			if (errorNumber == 0) {	errorNumber = 10; }
			document.getElementById("SourceAmount1_2010").style.backgroundColor = "#FF0000";
		} else {
			document.getElementById("SourceAmount1_2010").style.backgroundColor = "#FFFFFF";
		}
	}
	// Question 6 - WHAT WILL YOUR ORGANISATION BE PUTTING INTO THE PROJECT?
	if (document.getElementById("YourOrg2009").value == "" || document.getElementById("YourOrg2009").value == "Enter amount") {
		if (errorNumber == 0) {	errorNumber = 11; }
		document.getElementById("YourOrg2009").style.backgroundColor = "#FF0000";
		document.getElementById("YourOrg2009").value = "Enter amount";
	} else {
		if (ValidAmount(document.getElementById("YourOrg2009").value) == false) {
			if (errorNumber == 0) {	errorNumber = 11; }
			document.getElementById("YourOrg2009").style.backgroundColor = "#FF0000";
		} else {
			document.getElementById("YourOrg2009").style.backgroundColor = "#FFFFFF";
		}
	}
	if (document.getElementById("YourOrg2010").value == "" || document.getElementById("YourOrg2010").value == "Enter amount") {
		if (errorNumber == 0) {	errorNumber = 12; }
		document.getElementById("YourOrg2010").style.backgroundColor = "#FF0000";
		document.getElementById("YourOrg2010").value = "Enter amount";
	} else {
		if (ValidAmount(document.getElementById("YourOrg2010").value) == false) {
			if (errorNumber == 0) {	errorNumber = 12; }
			document.getElementById("YourOrg2010").style.backgroundColor = "#FF0000";
		} else {
			document.getElementById("YourOrg2010").style.backgroundColor = "#FFFFFF";
		}
	}
	if (document.getElementById("NonFinancial").value == "" || document.getElementById("NonFinancial").value == "You must answer this question") {
		if (errorNumber == 0) {	errorNumber = 13; }
		document.getElementById("NonFinancial").style.backgroundColor = "#FF0000";
		document.getElementById("NonFinancial").value = "You must answer this question";
	} else {
		document.getElementById("NonFinancial").style.backgroundColor = "#FFFFFF";
	}
	// Question 7 - WHO ELSE IS INVOLVED IN THE PROJECT?
	if (document.getElementById("WhoElse").value == "" || document.getElementById("WhoElse").value == "You must answer this question") {
		if (errorNumber == 0) {	errorNumber = 14; }
		document.getElementById("WhoElse").style.backgroundColor = "#FF0000";
		document.getElementById("WhoElse").value = "You must answer this question";
	} else {
		document.getElementById("WhoElse").style.backgroundColor = "#FFFFFF";
	}
	// Question 8 - WHEN WILL THE PROJECT START AND HOW LONG WILL IT RUN FOR?
	if (document.getElementById("ProjectStart").value == "" || document.getElementById("ProjectStart").value == "You must answer this question") {
		if (errorNumber == 0) {	errorNumber = 15; }
		document.getElementById("ProjectStart").style.backgroundColor = "#FF0000";
		document.getElementById("ProjectStart").value = "You must answer this question";
	} else {
		document.getElementById("ProjectStart").style.backgroundColor = "#FFFFFF";
	}
	// Question 9 - HOW WILL YOUR PROJECT MAKE ARUN CLEANER/ SAFER/ GREENER?
	if (document.getElementById("HowMake").value == "" || document.getElementById("HowMake").value == "You must answer this question") {
		if (errorNumber == 0) {	errorNumber = 16; }
		document.getElementById("HowMake").style.backgroundColor = "#FF0000";
		document.getElementById("HowMake").value = "You must answer this question";
	} else {
		document.getElementById("HowMake").style.backgroundColor = "#FFFFFF";
	}
	// Question 10 - WHAT WILL THE PROJECT ACHIEVE EACH YEAR?
	if (document.getElementById("Achieve2009").value == "" || document.getElementById("Achieve2009").value == "You must answer this question") {
		if (errorNumber == 0) {	errorNumber = 17; }
		document.getElementById("Achieve2009").style.backgroundColor = "#FF0000";
		document.getElementById("Achieve2009").value = "You must answer this question";
	} else {
		document.getElementById("Achieve2009").style.backgroundColor = "#FFFFFF";
	}
	if (document.getElementById("Achieve2010").value == "" || document.getElementById("Achieve2010").value == "You must answer this question") {
		if (errorNumber == 0) {	errorNumber = 18; }
		document.getElementById("Achieve2010").style.backgroundColor = "#FF0000";
		document.getElementById("Achieve2010").value = "You must answer this question";
	} else {
		document.getElementById("Achieve2010").style.backgroundColor = "#FFFFFF";
	}
	// Question 11 - WHAT OUTCOMES ARE YOU EXPECTING AND HOW WILL YOU MEASURE THEM?
	if (document.getElementById("Outcomes").value == "" || document.getElementById("Outcomes").value == "You must answer this question") {
		if (errorNumber == 0) {	errorNumber = 19; }
		document.getElementById("Outcomes").style.backgroundColor = "#FF0000";
		document.getElementById("Outcomes").value = "You must answer this question";
	} else {
		document.getElementById("Outcomes").style.backgroundColor = "#FFFFFF";
	}
	// Question 12 - RISK
	if (document.getElementById("Risks").value == "" || document.getElementById("Risks").value == "You must answer this question") {
		if (errorNumber == 0) {	errorNumber = 20; }
		document.getElementById("Risks").style.backgroundColor = "#FF0000";
		document.getElementById("Risks").value = "You must answer this question";
	} else {
		document.getElementById("Risks").style.backgroundColor = "#FFFFFF";
	}
	// Question 13 - HOW WILL YOU SUSTAIN THIS PROJECT AFTER THE GRANT IS USED? DO YOU HAVE AN 'EXIT STRATEGY'?
	if (document.getElementById("HowSustain").value == "" || document.getElementById("HowSustain").value == "You must answer this question") {
		if (errorNumber == 0) {	errorNumber = 21; }
		document.getElementById("HowSustain").style.backgroundColor = "#FF0000";
		document.getElementById("HowSustain").value = "You must answer this question";
	} else {
		document.getElementById("HowSustain").style.backgroundColor = "#FFFFFF";
	}
	// Question 14 - DATE OF THIS APPLICATION
	if (document.getElementById("ApplicationDate").value == "" || document.getElementById("ApplicationDate").value == "You must answer this question") {
		if (errorNumber == 0) {	errorNumber = 22; }
		document.getElementById("ApplicationDate").style.backgroundColor = "#FF0000";
		document.getElementById("ApplicationDate").value = "You must answer this question";
	} else {
		document.getElementById("ApplicationDate").style.backgroundColor = "#FFFFFF";
	}
	// Question 15 - Please provide details regarding to whom and where the cheque should be sent, should you be successful with this bid
	if (document.getElementById("ContactDetails").value == "" || document.getElementById("ContactDetails").value == "You must answer this question") {
		if (errorNumber == 0) {	errorNumber = 23; }
		document.getElementById("ContactDetails").style.backgroundColor = "#FF0000";
		document.getElementById("ContactDetails").value = "You must answer this question";
	} else {
		document.getElementById("ContactDetails").style.backgroundColor = "#FFFFFF";
	}
	// Check for errors and submit form if all is okay
	if (errorNumber > 0) {
		if (errorNumber == 1) {
			document.getElementById("ProjectName").select();
			document.getElementById("ProjectName").focus();
		}
		if (errorNumber == 2) {
			document.getElementById("ProjectLead").select();
			document.getElementById("ProjectLead").focus();
		}
		if (errorNumber == 3) {
			document.getElementById("ProjectCost").select();
			document.getElementById("ProjectCost").focus();
		}
		if (errorNumber == 4) {
			document.getElementById("FundingRequired").select();
			document.getElementById("FundingRequired").focus();
		}
		if (errorNumber == 5) {
			document.getElementById("FundingItem1").select();
			document.getElementById("FundingItem1").focus();
		}
		if (errorNumber == 6) {
			document.getElementById("FundingItemAmount1").select();
			document.getElementById("FundingItemAmount1").focus();
		}
		if (errorNumber == 7) {
			document.getElementById("Source1").select();
			document.getElementById("Source1").focus();
		}
		if (errorNumber == 8) {
			document.getElementById("SourceConfirmed1_0").focus();
		}
		if (errorNumber == 9) {
			document.getElementById("SourceAmount1_2009").select();
			document.getElementById("SourceAmount1_2009").focus();
		}
		if (errorNumber == 10) {
			document.getElementById("SourceAmount1_2010").select();
			document.getElementById("SourceAmount1_2010").focus();
		}
		if (errorNumber == 11) {
			document.getElementById("YourOrg2009").select();
			document.getElementById("YourOrg2009").focus();
		}
		if (errorNumber == 12) {
			document.getElementById("YourOrg2010").select();
			document.getElementById("YourOrg2010").focus();
		}
		if (errorNumber == 13) {
			document.getElementById("NonFinancial").select();
			document.getElementById("NonFinancial").focus();
		}
		if (errorNumber == 14) {
			document.getElementById("WhoElse").select();
			document.getElementById("WhoElse").focus();
		}
		if (errorNumber == 15) {
			document.getElementById("ProjectStart").select();
			document.getElementById("ProjectStart").focus();
		}
		if (errorNumber == 16) {
			document.getElementById("HowMake").select();
			document.getElementById("HowMake").focus();
		}
		if (errorNumber == 17) {
			document.getElementById("Achieve2009").select();
			document.getElementById("Achieve2009").focus();
		}
		if (errorNumber == 18) {
			document.getElementById("Achieve2010").select();
			document.getElementById("Achieve2010").focus();
		}
		if (errorNumber == 19) {
			document.getElementById("Outcomes").select();
			document.getElementById("Outcomes").focus();
		}
		if (errorNumber == 20) {
			document.getElementById("Risks").select();
			document.getElementById("Risks").focus();
		}
		if (errorNumber == 21) {
			document.getElementById("HowSustain").select();
			document.getElementById("HowSustain").focus();
		}
		if (errorNumber == 22) {
			document.getElementById("ApplicationDate").select();
			document.getElementById("ApplicationDate").focus();
		}
		if (errorNumber == 23) {
			document.getElementById("ContactDetails").select();
			document.getElementById("ContactDetails").focus();
		}
	} else {
		document.CleanAndSafe.submit();
	}
}
