<!--


//used to toggle sub-navigation menus on/off
nav_status = new Array();
function toggleNav(theId){
	if(document.getElementById){
		var switch_id = document.getElementById(theId);
		if(nav_status[theId] != 'show'){
			switch_id.className = 'show';
			nav_status[theId] = 'show';
		}else{
			switch_id.className = 'hide';
			nav_status[theId] = 'hide';
		}//if
		
	}//if
	
}//toggleNav



//used for the quiz on homepage
var currQ = 1;
var theAns;
var currScore = 0;

function initQuiz(theAns){

	if(theAns == null){
		theAns = 0;
	}else if(theAns != null){
		currScore += eval(theAns);
	}
	
	if(document.getElementById){
		pQ = document.getElementById('the_question');
		bY = document.getElementById('button_yes');
		bN = document.getElementById('button_no');
		switch(currQ){
			case 1:
				pQ.innerHTML = "<span class='green_small'>Question " + currQ + " of 5</span><br />Do you need to take your reliever inhaler (usually blue) 3 or more times a week because of asthma symptoms?";
				currQ++;
				break;
			case 2:
				pQ.innerHTML = "<span class='green_small'>Question " + currQ + " of 5</span><br />Do you have any asthma symptoms (cough, short of breath, wheeze, chest tightness) on 3 or more days a week?";
				currQ++;
				break;
			case 3:
				pQ.innerHTML = "<span class='green_small'>Question " + currQ + " of 5</span><br />Does your asthma in any way limit your ability to exercise or play sports?";
				currQ++;
				break;
			case 4:
				pQ.innerHTML = "<span class='green_small'>Question " + currQ + " of 5</span><br />In an average week, do you wake up at night once or more times because of your asthma?";
				currQ++;
				break;
			case 5:
				pQ.innerHTML = "<span class='green_small'>Question " + currQ + " of 5</span><br />In the last month, have you missed any school or work because of asthma?";
				currQ++;
				break;
			case 6:
				bY.className = 'hide';
				bN.className = 'hide';
				if(currScore == 0){
					pQ.innerHTML = "You answered <strong>NO to ALL</strong> of these questions, your asthma is likely under control.";
				}else if(currScore > 0){
					pQ.innerHTML = "You answered <strong>YES to " + currScore + "</strong> of these questions, your asthma is likely not under full control. The vast majority of people should be able to get their asthma under good control.<br /><br /> To find out how, <strong>call our Asthma Action Helpline at 1-800-668-7682</strong> or make an appointment to see your doctor.  ";
				}
				break;
		}//switch
	}//if
}//initQuiz


//******************************************************************************************************//

function validateContest(){
	if(document.getElementById){
		
		resetErrors();
		
		var elName = document.getElementById('txtName');
		var elPhone = document.getElementById('txtPhone');
		var elEmail = document.getElementById('txtEmail');
		var elAge = document.getElementById('txtAge');
//		var elAddress = document.getElementById('txtAddress');
		var elPostal = document.getElementById('txtPostal');
//		var elCity = document.getElementById('txtCity');
		var elMale = document.getElementById('radMale');
		var elFemale = document.getElementById('radFemale');
		var elMessage = document.getElementById('txtMessage');
		var elSubmit = document.getElementById('btnSubmit');
		var elError = document.getElementById('errorMessage');
		var elForm = document.getElementById('f1');
		
		var emailRegEx = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
		var emailOk = emailRegEx.exec(elEmail.value);
		
		var ageIsNumeric = /^(-)?(\d*)(\.?)(\d*)$/;
		var ageOk = ageIsNumeric.exec(elAge.value);
		
		var postalRegEx = /\D\d\D\s\d\D\d$/;
		var postalOk = postalRegEx.exec(elPostal.value);
		
		if(elName.value == ""){
			elError.className = 'error_message';
			elError.innerHTML = "Name is Missing.";
			elName.focus();
			elName.style.backgroundColor = "#E6939D";
		}else if(elPhone.value == ""){
			elError.className = 'error_message';
			elError.innerHTML = "Phone Number is Missing.";
			elPhone.focus();
			elPhone.style.backgroundColor = "#E6939D";
		}else if(elEmail.value == ""){
			elError.className = 'error_message';
			elError.innerHTML = "Email Address is Missing";
			elEmail.focus();
			elEmail.style.backgroundColor = '#E6939D';
		}else if(!emailOk){
			elError.className = 'error_message';
			elError.innerHTML = "Email Address is not Valid.";
			elEmail.focus();
			elEmail.select();
			elEmail.style.backgroundColor = '#E6939D';
		}else if((elAge.value != "" && !ageOk ) || (elAge.value != "" && elAge.value >= 110)){
			elError.className = 'error_message';
			elError.innerHTML = "Age is Not Valid.";
			elAge.focus();
			elAge.select();
			elAge.style.backgroundColor = '#E6939D';
		}else if(elPostal.value != "" && !postalOk){
			elError.className = 'error_message';
			elError.innerHTML = "Postal Code is Not Valid. (format: x9x 9x9)";
			elPostal.focus();
			elPostal.select();
			elPostal.style.backgroundColor = '#E6939D';
		}else if(!elMale.checked && !elFemale.checked){
			elError.className = 'error_message';
			elError.innerHTML = "Please Select Your Gender.";
			elFemale.focus();
		}else if(elMessage.value == ""){
			elError.className = 'error_message';
			elError.innerHTML = "Please Tell Us Your Story.";
			elMessage.focus();
			elMessage.style.backgroundColor = '#E6939D';
		}else if(wordCount(elMessage.value) > 100){
			elError.className = 'error_message';
			elError.innerHTML = "Story Must be Less Than 100 Words.";
			elMessage.focus();
			elMessage.style.backgroundColor = '#E6939D';
		}else{ 
			elError.className = 'error_message';
			checkIFrame();
		}
	}//if
}//validateContest


//******************************************************************************************************//
/* resets all error messages and text fields */
function resetErrors(){
	if(document.getElementById){
		elError = document.getElementById('errorMessage');	//error message
		elMessage = document.getElementById('txtMessage'); //textarea
		elError.innerHTML = "";
		//loop through all input elements		
		var inputs = document.getElementsByTagName('input');
		for(i=0; i<inputs.length; i++){
			//reset background color of text fields
			if(inputs[i].id.indexOf('txt') == 0){
				inputs[i].style.backgroundColor = '#F1F1F2';
			}
		}//for
		//reset background color of textarea
		elMessage.style.backgroundColor = '#F1F1F2';
	}//if
}//resetErrors

//******************************************************************************************************//
/* counts the number of words in a string */
function wordCount(str){
	var a = str.split(/\s+/g);	//split sentence into an array of words
	return a.length;
}//wordCount



//******************************************************************************************************//
/* ajax function */
//******************************************************************************************************//
var oIFrame = null;

function createIFrame() {
	var oIFrameElement = document.createElement("iframe");
	oIFrameElement.width=0;
	oIFrameElement.height=0;
	oIFrameElement.frameBorder=0;
	oIFrameElement.name = "hiddenFrame";
	oIFrameElement.id = "hiddenFrame";
	document.body.appendChild(oIFrameElement);
	
	oIFrame = frames["hiddenFrame"];
}
		   
function checkIFrame() {
	if (!oIFrame) {
		createIFrame();                
	} 
	setTimeout(function () {
		oIFrame.location = "contest_proxy.html";
	}, 10);                              
}

function formReady() {
	var oHiddenForm = oIFrame.document.forms[0];
	var oForm = document.forms[0];
	
	for (var i=0 ; i < oForm.elements.length; i++) {
		var oHidden = oIFrame.document.createElement("input");
		oHidden.type = "hidden";
		oHidden.name = oForm.elements[i].name;
		oHidden.value = oForm.elements[i].value;
		oHiddenForm.appendChild(oHidden);
	}
	
	oHiddenForm.action = oForm.action;
	oHiddenForm.submit();
};

function saveResult(sMessage) {
	var divStatus = document.getElementById("errorMessage");
	divStatus.innerHTML = sMessage;            
}





























//-->