// JavaScript Document
function validateForm() 
{
	
 var okSoFar=true
 with (document.contact_us)
 {
  var foundAt = email.value.indexOf("@",0)
  
  if ((name.value=="" && okSoFar))
  {
    okSoFar=false
    alert("Please enter your name.")
    name.focus()
  }
  
  if (foundAt < 1 && okSoFar)
  {
    okSoFar = false
    alert ("Please enter a valid email address.")
    email.focus()
  }
  if ((thesubject.value=="" && okSoFar))
  {
    okSoFar=false
    alert("Please enter a subject.")
    thesubject.focus()
  }
  if ((themessage.value=="" && okSoFar))
  {
    okSoFar=false
    alert("Please enter a message.")
    themessage.focus()
  }
  
  if (okSoFar==true)  
  {
   block_spam_bots.value=4*3;//spam bots currently cant read JavaScript, if could then they'd fail the maths!
//   submit();
   return true;
  } 
  else {
	  return false;
  }
 }
}

function validatePetition() 
{
	
 var okSoFar=true
 with (document.contact_councillors)
 {
  var foundAt = email.value.indexOf("@",0)
  if ((name.value=="" && okSoFar))
  {
    okSoFar=false
    alert("Please enter your name.")
    name.focus()
  }
  
  if (foundAt < 1 && okSoFar && !audience[4].checked)
  {
    okSoFar = false
    alert ("Please enter a valid email address.")
    email.focus()
  } 
  
  if ((street.value=="" && okSoFar))
  {
    okSoFar=false
    alert("Street address is required. It helps Councillors differentiate between spam and concerns from real residents.")
    street.focus()
  }  
  
  if ((thesubject.value=="" && okSoFar && !audience[4].checked))
  {
    okSoFar=false
    alert("Please enter a subject.")
    thesubject.focus()
  }

  if ((themessage.value=="" && okSoFar))
  {
	if (themessage.value=="")
	{
		random_msg(1)
	}
	
    okSoFar=true
  }
  
  if (okSoFar==true)  
  {
   block_spam_bots.value=4*3;//spam bots currently cant read JavaScript, if could then they'd fail the maths!
//   submit();
   return true;
  } 
  else {
	  return false;
  }
 }
}


function random_msg(randomnumber)
{
	with (document.contact_councillors)
	{
		//var randomnumber=Math.floor(Math.random()*11);
		
                if (randomnumber == 0)
                {
                    themessage.value = custom.value
                }
                else
                {
		    switch(randomnumber)
		    {
		      case 1:
                        themessage.value="Hi,\n\nI live in Milton and am very concerned about the traffic situation on Derry Road, between Bronte Street and Tremaine Road.  Specifically, I am worried about the impact of not having the CN Rail underpass on Derry.  Thousands of cars cross the rail track every day, causing an enormous waste of time and money due to slow rail crossings.  On top of that I can\'t imagine the environmental impact caused by idling cars.  Over 10,000 residents already live west of the tracks, \'landlocked\', in Garry Carr\'s own words.  \n\nI urge the Halton Regional Council to consider the plight of residents west of the escarpment and move up the construction of this underpass from 2016-2017 to 2010-2011. \n\nThank you.\n\n";		        
		        break;
		      case 2:
                        themessage.value="Dear Councillors,\n\nI am writing to ask you to support the grade separation on Derry Road, between Bronte Street and Tremaine Road.\n\nIn 2007 the Town of Milton passed a motion that called on the Region to commit to constructing a CN Rail underpass on Derry Road.   In fact, Halton's Regional Chair, Gary Carr, himself admitted that 'the grade separation of the railway should have happened years ago and was an example of bad planning by both Halton Region and the Town of Milton'.  To quote Gary Carr, 'the whole subdivision is sort of landlocked.' \n\nI believe the grade separation on Derry should be a top priority for the region.  \n\nI thank you for your time and hope that you will seriously consider my request.\n\n";
		        break;
		      case 3:
                        themessage.value="Dear Halton Councillors,\n\nI am writing to ask you to support the grade separation on Derry Road, between Bronte Street and Tremaine Road.  \n\nHalton\'s Chair, Gary Carr, has himself admitted that not having a CN Rail underpass on Derry was \'an example of poor planning\'.  I urge the Council to correct the mistake now rather than waiting until 2016-2017, when thousands more residents will join the already 10,000+ community impacted by the gridlock.  \n\nI think this should be an urgent priority for the Region.  This will benefit the community by reducing traffic gridlock and improving the quality of air in the area.  \n\nI look forward to seeing a vote on this matter soon.\n\n";
		        break;
		      case 4:
		      default:
                        themessage.value="Dear Regional Councillors:\n\nI am a resident of Milton.  I am writing to express my concern about the fact that the grade separation on Derry is not planned to finish until 2017.  I understand that the topic to accelerate the project has been discussed.  However, after experiencing the traffic I feel that the project should have been completed by now.   I know that the Regional Chair, Gary Carr, agrees with me and has admitted not having the underpass done already was an example of 'poor planning'.  I hope the Council will correct this mistake promptly.\n\nOver 10,000 residents live West of the CN Rail track on Derry.  Many of us have to go East on Derry since we work in Mississauga or other GTA cities.  This does not just cause undue hardship, but it is also bad for the environment since traffic gives off myriad pollutants that decrease our air quality.  I have seen traffic back up all the way to Tremaine when a train crosses, which takes a while to clear up. \n\nI hope the Council will empathize with me and will consider this an utmost priority.  \n\nA Concerned Resident,\n\n";
		        break;
		      		    
		    }
                    themessage.value = themessage.value + name.value + "\n" + street.value + "\n" + "Milton, ON\n" + phone.value;
		}
	}
}

function updateCustom()
{
    with (document.contact_councillors)
    {
        custom.value=themessage.value;
        //Randomize.custom.checked = true;
        
    }
}

// --></script>
