/****************************************************************************************
2009 Copyright (c) Dow AgroSciences LLC.

VERSION 1.0
AUTHOR Ben Rondot

DATE        NAME           DESCRIPTON
12/17/2008  Ben Rondot     Initial creation.
05/25/2010  Ben Rondot     Added "Latest News" headlines to the "fast fact" area. Facts and news items will now rotate.

****************************************************************************************/
/****************************************************************************************/

///////////////////////////////////
// Refreshes "fast fact" questions and answers when page is first visited or refreshed
///////////////////////////////////
function newQuestion() {
	// Check users browser for campatibility. If not, abort function
	if (!document.getElementById) return false;
	if (!document.getElementById("content-rotation")) return false;
	// Find Id "indexQandA"
	var getQuestion = document.getElementById("content-rotation");
	// Array of all questions and answers
	var questionList=new Array();
	questionList[1]= '<div class="index-content-sub-title">Fast Fact</div>'
	+'<div id="index-q-and-a">'
			+ '<div id="index-q-sentence">Does chlorpyrifos cause cancer?</div>'
			+ '<div id="index-a-sentence">No regulatory body in the world considers chlorpyrifos a cause of cancer. The conclusions of these regulatory bodies are consistent with the weight of the scientific evidence.</div>'
			+'</div>';
	questionList[2]='<div class="index-content-sub-title">Fast Fact</div>'
	+'<div id="index-q-and-a">'
			+ '<div id="index-q-sentence">Is chlorpyrifos registered for use outside of the U.S.?</div>'
			+ '<div id="index-a-sentence">Chlorpyrifos is registered in about 100 countries, including industrialized nations such as Canada, Japan, and the UK.</div>'
			+'</div>';
	questionList[3]='<div class="index-content-sub-title">Fast Fact</div>'
	+'<div id="index-q-and-a">'
			+ '<div id="index-q-sentence">Is chlorpyrifos a new product?</div>'
			+ '<div id="index-a-sentence">No. Chlorpyrifos has been on the market for 40 years.</div>'
			+'</div>';
	questionList[4]='<div class="index-content-sub-title">Fast Fact</div>'
	+'<div id="index-q-and-a">'
			+ '<div id="index-q-sentence">Has chlorpyrifos been subjected to rigorous scientific study?</div>'
			+ '<div id="index-a-sentence">Chlorpyrifos is one of the most heavily-research pesticides on the market, with over 5000 studies supporting its use.</div>'
			+'</div>';
	questionList[5]='<div class="index-content-sub-title">Fast Fact</div>'
	+'<div id="index-q-and-a">'
			+ '<div id="index-q-sentence">What crops does chlorpyrifos protect?</div>'
			+ '<div id="index-a-sentence">More than 50, including cotton, rice, fruit, vegetable, and seed and nut crops.</div>'
			+'</div>';
	questionList[6]='<div class="index-content-sub-title">Fast Fact</div>'
	+'<div id="index-q-and-a">'
			+ '<div id="index-q-sentence">Is chlorpyrifos used in the home for pest control?</div>'
			+ '<div id="index-a-sentence">Chlorpyrifos is no longer registered in the U.S. for home use, except in ant and roach baits contained in child-proof packaging.</div>'
			+'</div>';
	questionList[7]='<div class="index-content-sub-title">Latest News</div>'
			+'<div id="index-q-and-a">'
			+ '<div id="index-news-sentence"><a href="/news/index.htm#news01">Impasse Reached on West Coast Endangered Species Act Restrictions</a> - 05/10/10</div>'
			+'</div>';
	questionList[8]='<div class="index-content-sub-title">Latest News</div>'
			+'<div id="index-q-and-a">'
			+ '<div id="index-news-sentence"><a href="/news/index.htm#news02">CropLife America and Three Registrants Give Notice That They Are Prepared to Sue EPA Over Endangered Species Act Restrictions</a> - 04/16/10</div>'
			+'</div>';
	questionList[9]='<div class="index-content-sub-title">Latest News</div>'
			+'<div id="index-q-and-a">'
			+ '<div id="index-news-sentence"><a href="/news/index.htm#news03">From Capitol Press: States Weigh in on EPA&#39;s No-spray Buffers</a> -  03/21/10</div>'
			+'</div>';
			
	//math formula to call random question and answers 
	var i=Math.floor(Math.random()*questionList.length);
	if (i==0){
		 i=1;
	}
	// Switch html content with js
	getQuestion.innerHTML = questionList[i];
}

///////////////////////////////////	
// Contact us page
// Validates form. Required fields must not be left blank
///////////////////////////////////

function validate_form(form) {
  var errormsg = new String ("The following field(s) must not be left blank: \n\n");
  var blnerror = false;
  if (form.sFName.value == "") {errormsg = errormsg + "First Name\n"; blnerror=true;}
  if (form.sLName.value == "") {errormsg = errormsg + "Last Name\n"; blnerror=true;}
  if (form.sEmail.value == "") {errormsg = errormsg + "Email Address\n"; blnerror=true;}
  if (form.sConfirmEmail.value == "") {errormsg = errormsg + "Confirm Email Address\n"; blnerror=true;}
  if (form.comments.value == "") {errormsg = errormsg + "Enter your question or comment\n"; blnerror=true;}
  if (form.sEmail && form.sEmail.value.indexOf("@") == -1) {
    if (blnerror) {errormsg += "\nInvalid email address.";}
    else {errormsg = "Invalid email address."; blnerror=true;}
  }
  if (blnerror) {alert(errormsg); return false;} else {
if (form.sRedirectPath.value != '') {
form.sRedirectPath.value = form.sRedirectPath.value + "?sFName=" + form.sFName.value;
}
 form.recipient.value = JSrot13(form.recipient.value);
 return true;}
  return null;
}

///////////////////////////////////
//Loads all functions to the page
///////////////////////////////////
function addLoadEvent(func) { 
	  var oldonload = window.onload; 
	  if (typeof window.onload != 'function') { 
	    window.onload = func; 
	  } else { 
	    window.onload = function() { 
	      if (oldonload) { 
	        oldonload(); 
	      } 
	      func(); 
	    } 
	  } 
	} 
	 
addLoadEvent(newQuestion); 
