$(document).ready(function(){
	var active = $('#nav .active');
	$('#nav li').mouseover(function(){
		$('#nav li').each(function(){
			$(this).removeClass('active');
		});
	});
	$('#nav li').mouseout(function(){
		$(active).addClass('active');
	});
});


/* SUBMIT A STORY FORM VALIDATION */
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 ValidateSubmitStory(form) {
	
	var checked = 0;
	var checked = form.agree.checked;
	if (checked)
   	{
   		check = 1;
   	}
	if (form.first_name.value == '') {
		alert("Please fill in your first name.");
		form.first_name.focus();
		form.first_name.select();
		return false;
	}
	if (form.last_name.value == '') {
		alert("Please fill in your last name.");
		form.last_name.focus();
		form.last_name.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 (form.title.value == '') {
		alert("Please fill in a title.");
		form.title.focus();
		form.title.select();
		return false;
	}
	if (form.story.value == '') {
		alert("Please fill in your story.");
		form.story.focus();
		form.story.select();
		return false;
	}
	if (checked == 0)
	{
     	alert ("You must agree to check this box.");
     	return false;
    }
		
//if we made it to here, everything's valid, so return true
return true
}











/* START POLL */
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 < 2; 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("function_poll.cfm", 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/indicator_circle_ball.gif' /><br>Loading...</div>";
	DWREngine._execute(_cfscriptSurveyLocation, null, 'getPollResults', pollid, surveyResult);
}
function getPollLabels(survey){
	var labelpollid = survey;
	// display the loading image
	
	document.getElementById( 'poll' ).innerHTML = "<div style='color: #ffffff;' align='center'><br /><br /><br /><br /><br /><img src='images/indicator_circle_ball.gif' /><br>Loading...</div>";
	DWREngine._execute("function_poll.cfm", null, 'getPollLabels', labelpollid, surveyResult);	
}
/* END POLL */