var debugOn = false;

var CASE_POST_URL = "casesubmit.jsp";
var CAMPAIGN_ID   = "206";

/**
 * Structures the flow of form validation by calling methods created below.
 * You can read this and know what is being done to validate this particular form.
 * 1.  Checks that name has been entered.
 * 2.  Checks that email is 'valid'.  future- checks that email is not in database already.
 * 3.  Takes questionaire data and creates a single 'case description' to be posted to aafy database.
 */
function doFormValidation()
{
	var success  = false;
	    success  = this.mergeCaseDetails();
	
		document.aafy_questionaire.submit();
	/*
	if ( success  )
	{
		doFormSubmit();
	}
	*/	
}

function addPostParam( sParams, sParamName, sParamValue ) 
{
	if ( sParams.length > 0 )
	{
		sParams += "&";
	}
	
	return sParams + encodeURIComponent( sParamName  ) + "=" +
				     encodeURIComponent( sParamValue );
}

/**
 * Handles jumping state menu.
  */
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/** 
 * Can be used to do some kind of email validation
 */
function validateEmail()
{
	return 1;
}


/**
 * This is the bulk of this file, it merges all the questionaire data that cannot be mapped directly into the database;
 * by merging it into 'sCaseDetails' and then setting the form.casedetails field equal to the merged variables value. 
 */
function mergeCaseDetails()
{
	var sCaseDetails = "";
	var sSymptoms = "Symptoms: ";
	
	try
	{
		if (isSelected( document.aafy_questionaire.q1) ) 
		{
			var q1 = document.aafy_questionaire.q1.value;
			if (debugOn) { alert( q1 ); } 
			sSymptoms = sSymptoms + ' ' + q1 + '. ';
		}
		if (isSelected( document.aafy_questionaire.q2) ) 
		{ 
			var q2 = document.aafy_questionaire.q2.value;
			if (debugOn) { alert( q2 ); }
			sSymptoms = sSymptoms + ' ' + q2 + '. ';
		}
		if (isSelected( document.aafy_questionaire.q3) ) 
		{ 
			var q3 = document.aafy_questionaire.q3.value;
			if (debugOn) { alert( q3 ); }
			sSymptoms = sSymptoms + ' ' + q3 + '. ';
		}
		if (isSelected( document.aafy_questionaire.q4) ) 
		{ 
			var q4 = document.aafy_questionaire.q4.value;
			if (debugOn) { alert( q4 ); }
			sSymptoms = sSymptoms + ' ' + q4 + '. ';
		}
		if (isSelected( document.aafy_questionaire.q5) ) 
		{ 
			var q5 = document.aafy_questionaire.q5.value;
			if (debugOn) { alert( q5 ); }
			sSymptoms = sSymptoms + ' ' + q5 + '. ';
		}
		
		sCaseDetails = document.getElementById("casedetails").value;
		sCaseDetails = sSymptoms + ' \n' + 'Consumer\'s Comments: \n' + sCaseDetails;
		if (debugOn) {  alert( sCaseDetails ); }
		document.getElementById("casedetails").value = sCaseDetails;
		if (debugOn) { alert( 'final: ' + document.getElementById("casedetails").value ); }
	}
	catch (Exception)
	{
		alert( 'Error merging case details' ); 
		return 0;
	}
	
	return 1;
}

/**
 * Checks to see if checkbox is selected.
 */
function isSelected( cbName ) 
{
	return cbName.checked;
}
