/* --- (INFORMATION) ----------------------------------------------------
File:
Author:
Date Created:
Last Modified:
Last Modified By:
Description:

------------------------------------------------------------ (END) --- */

/* START IMPACT FACT */
function getText(x)
{
	var category = x;
	// display the loading image
	document.getElementById( 'impact_fact_container' ).innerHTML = "<div align='center'><br /><br /><br /><img src='images/ajax_loading.gif' /><br>Loading...</div>";
	// clear the error div
	//document.getElementById( 'impact_fact_container' ).innerHTML = "";
	DWREngine._execute(_cfscriptVotingLocation, null, 'getCategory', category, getChoiceForCategoryResult);
}

function getChoiceForCategoryResult(result)
{
		document.getElementById('impact_fact_container').innerHTML = result;
}
/* END IMPACT FACT */



/* START SURVEY */
function submitform()
{
	if(document.form_survey.onsubmit())
	{
		document.form_survey.submit();
	}
}
// check the poll for selections
function checkPoll()
{
	var check = 0;
	var titlecnt = 0;
   	//loop through radio buttons and check for values
   	for (var i = 0; i < 3; i++)
   	{
    	var checked = document.form_survey.poll[i].checked;
     	if (checked)
      	{
       		check = 1;
			titlecnt = i + 1;				
      	}
    }
	//if checked post the form
	if (check == 1)
	{
		//alert('YOU SELECTED AN OPTION');
		//return true;
		// display the loading image
		var pollid = DWRUtil.getValue("pollid");
		document.getElementById( 'form_container' ).innerHTML = "<div align='center'><br /><br /><br /><img src='images/ajax_loading.gif' /></div>";
		DWREngine._execute(_cfscriptSurveyLocation, null, 'getSurvey', pollid, titlecnt, surveyResult);
	}
	else
	{
     	alert ("Please make a choice.");
     	return false;
    }
}
function surveyResult(result)
{
	
	document.getElementById('survey_container').innerHTML = result;
}

function getResults(survey) {
	
	var pollid = survey;
	// display the loading image
	document.getElementById( 'survey_container' ).innerHTML = "<div style='color: #ffffff;' align='center'><br /><br /><br /><br /><img src='images/ajax_loading.gif' /><br>Loading...</div>";
	DWREngine._execute(_cfscriptSurveyLocation, null, 'getPollResults', pollid, surveyResult);
}
function getPollLabels(survey){
	var labelpollid = survey;
	// display the loading image
	
	document.getElementById( 'survey_container' ).innerHTML = "<div style='color: #ffffff;' align='center'><br /><br /><br /><br /><br /><img src='images/ajax_loading.gif' /><br>Loading...</div>";
	DWREngine._execute(_cfscriptSurveyLocation, null, 'getPollLabels', labelpollid, surveyResult);	
}
/* END SURVEY */


/* START CALENDAR */
	
function go_date(thenewdate)
{
	var neweventdate = thenewdate;
	// display the loading image
	
	document.getElementById( 'calendar_container' ).innerHTML = "<div align='center'><br /><br /><br /><br /><br /><br /><br /><img src='images/ajax_loading.gif' /><br>Loading...</div>";
	// clear the error div
	//document.getElementById( 'impact_fact_container' ).innerHTML = "";
	DWREngine._execute(_cfscriptCalendarLocation, null, 'getNewDate', neweventdate, getDateResult);
}
function getDateResult(result)
{
	document.getElementById('calendar_container').innerHTML = result;
}


/* END CALENDAR */


/* START PHOTO GALLERY */
function getPhoto(photo)
{
	var photoid = photo;

	// display the loading image
	document.getElementById( 'photo_container' ).innerHTML = "<div align='center'><br /><br /><br /><br /><br /><br /><br /><img src='images/ajax_loading.gif' /><br>Loading...</div>";
	// clear the error div
	//document.getElementById( 'impact_fact_container' ).innerHTML = "";
	DWREngine._execute(_cfscriptPhotoLocation, null, 'getPhoto', photoid, getPhotoResult);
}
function getPhotoResult(result)
{
	
	document.getElementById('photo_container').innerHTML = result;
}
/* END PHOTO GALLERY */

function PopPic(photoid) 
	{
		w = 475;//Math.floor(800);
	     h = 323; Math.floor(screen.availHeight-60);
		jx = window.open('photo.cfm?photoid=' + photoid,'regwindow', 'width='+w+',height='+h+',top=1, left=1, resizable=no, scrollbars=no, status=no');
	
	}
function PopPicTall(photoid) 
	{
		w = 323;//Math.floor(800);
	     h = 475; Math.floor(screen.availHeight-60);
		jx = window.open('photo.cfm?photoid=' + photoid,'regwindow', 'width='+w+',height='+h+',top=1, left=1, resizable=no, scrollbars=no, status=no');
	
	}


/* FORM VALIDATION */

function ClearName(textbox) {
  if (textbox.value == 'Type Your Name Here') { textbox.value='';}
}

function FillName(textbox) {
  if (textbox.value == '') { textbox.value='Type Your Name Here';}
}

function ClearPhone(textbox) {
  if (textbox.value == 'Type Your Phone Number Here') { textbox.value='';}
}

function FillPhone(textbox) {
  if (textbox.value == '') { textbox.value='Type Your Phone Number Here';}
}

function ClearEmail(textbox) {
  if (textbox.value == 'Type Your Email Here') { textbox.value='';}
}

function FillEmail(textbox) {
  if (textbox.value == '') { textbox.value='Type Your Email Here';}
}

function ClearSubject(textbox) {
  if (textbox.value == 'Type Your Subject Here') { textbox.value='';}
}

function FillSubject(textbox) {
  if (textbox.value == '') { textbox.value='Type Your Subject Here';}
}

function ClearMessage(textbox) {
  if (textbox.value == 'Type Your Message Here') { textbox.value='';}
}

function FillMessage(textbox) {
  if (textbox.value == '') { textbox.value='Type Your Message Here';}
}
function ClearAddress(textbox) {
  if (textbox.value == 'Type Your Address Here') { textbox.value='';}
}

function FillAddress(textbox) {
  if (textbox.value == '') { textbox.value='Type Your Address Here';}
}
function ClearYOB(textbox) {
  if (textbox.value == 'Type Your Year Of Birth Here') { textbox.value='';}
}

function FillYOB(textbox) {
  if (textbox.value == '') { textbox.value='Type Your Year Of Birth Here';}
}
/* LIMIT THE YEAR OF BIRTH FIELD TO FOUR CHARACTERS */
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}


/* IMPACT AND VOLUNTEERING FORM VALIDATION */
/* VALID EMAIL FOR FORM */
function validEmail(email) {
	invalidChars = ' !#$%^&*(){}[]+=~`?/:;,"'

	
	if (email == "") {
		return false;
	}
	for (i=0; i<invalidChars.length; i++) { //does it contain any invalid characters?
		badChar = invalidChars.charAt(i);
		if (email.indexOf(badChar,0) > -1) {
			return false;
		}
	}
	atPos = email.indexOf("@",1)  		//there must be one "@" symbol
		if (atPos == -1) {
		return false;
	}
	if (email.indexOf("@",atPos+1) != -1) { //and only one "@"
		return false;
	}
	periodPos = email.indexOf(".",atPos+1)  //and at least one "." after the "@"
		if (periodPos == -1) {
		return false;
	}
	if (email.charAt(atPos+1) == ".") {	//is there a "." right after the "@"
		return false;
	}
	if (periodPos+3 > email.length) {  	//must be at least 2 characters after the "."
		return false;
	}
	return true;
}
function formValidation(form) {
	//var form_name = form.name.value.toLowerCase();
	//alert(form_name);	
	if (form.name.value.toLowerCase() == 'type your name here') {
		alert("A Valid Name Is Required.");
		form.name.focus();
		form.name.select();
		return false;
	}
	if (form.name.value == '') {
		alert("Please Fill In Your Name.");
		form.name.focus();
		form.name.select();
		return false;
	}
	//if (form.phone_number.value == '') {
		//alert("A Phone Number is required.");
		//form.phone_number.focus();
		//form.phone_number.select();
		//return false;
	//}
	if (!validEmail(form.email.value)) {
		alert("A valid E-mail Address is required.");
		form.email.focus();
		form.email.select();
		return false;
	}
		
//if we made it to here, everything's valid, so return true
return true
}

function form_jump_month(form) {
	var myindex = form.select_month.selectedIndex
	//if (myindex==0) return false;
	{
		parent.location=form.select_month.options[myindex].value;
		return true;
	}
}
/* IMPACT FORM RADIO BUTTON UNCHECK */
function clear_impact_radio_buttons() 
{
	getRadios = document.getElementsByTagName("input")
	for (x=0; x < getRadios.length; x++) 
	{
		if (getRadios[x].type == "radio" && getRadios[x].checked)
		//alert(getRadios[x].value)
		if (getRadios[x].value != 0)
		{
			getRadios[x].checked = false;
		}
	}
}
function clear_general_radio_buttons() 
{
	getRadios = document.getElementsByTagName("input")
	for (x=0; x < getRadios.length; x++) 
	{
		if (getRadios[x].type == "radio" && getRadios[x].checked)
		//alert(getRadios[x].value)
		if (getRadios[x].value == 0)
		{
			getRadios[x].checked = false;
		}
	}
}





