// JavaScript Document
var i = 0;

function averageRadios(cookieName){
	var numFields = 6;
	var total = 0;
	for(var i=0; i<numFields; i++){
		var index = i+1;
		var option = Number( getCheckedValue(document.forms['surveyForm'].elements['option' + index]) );
		total += option;
	}	
	var average = (total/numFields)/3;
	setCookie(cookieName, average, 30);
}



function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" :";expires="+exdate.toGMTString());
}

function getCookie(c_name){
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{ 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	  }
	return "";
}

// return an empty string if none are checked, or
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function drawBars(cookieName){
	var html = "";
	var height;
	var average = getCookie(cookieName);
	var userMatch;
	var image;
	if(average != ""){
		var userMatch = Math.round(average * 11);
	}else{
		var userMatch = 13;
	}
	for(var i=0; i<12; i++){
		if(userMatch == i){
			height = 48;
		}else{
			height = 32;
		}
		if(i<3){
			 image = "green.gif";
		}else if(i<6){
			image = "yellow.gif";
		}else if(i<9){
			image = "orange.gif";
		}else{
			image = "red.gif";
		}
//		html += "<image src=\"images/" + image  + "\" width=\"15\" height=\"" + height + "\" /> ";`
		html += "<img src=\"images/" + image  + "\" style=\"width: 1.5em; height: " + (height/10) +  "em;\" />\n";
	}
	var obj = document.getElementById("bars");
	obj.innerHTML = html;
	images.setAll();
}

function printMessage(cookieName){
	var average = getCookie(cookieName);
	if(average != ""){
		var userMatch = Math.round(average * 11);
	}else{
		var userMatch = 13;
	}
	var html = "";
	var htmlTitle = "";
	if(userMatch<3){
		htmlTitle += "<img src=\"images/results_green_title.jpg\" width=\"899\" height=\"73\" />";
		html += "<img src=\"images/results_green_body.jpg\" width=\"607\" height=\"222\" />";
	}else if(userMatch<6){
		htmlTitle += "<img src=\"images/results_yellow_title.jpg\" width=\"899\" height=\"73\" />";
		html += "<img src=\"images/results_yellow_body.jpg\" width=\"607\" height=\"222\" />";
	}else if(userMatch<9){
		htmlTitle += "<img src=\"images/results_orange_title.jpg\" width=\"899\" height=\"73\" />";
		html += "<img src=\"images/results_orange_body.jpg\" width=\"607\" height=\"222\" />";
	}else if(userMatch<12){
		htmlTitle += "<img src=\"images/results_red_title.jpg\" width=\"899\" height=\"73\" />";
		html += "<img src=\"images/results_red_body.jpg\" width=\"607\" height=\"222\" />";
	}else{
		htmlTitle += "<img src=\"images/results_green_title.jpg\" width=\"899\" height=\"73\" />";
		html += "<img src=\"images/results_green_body.jpg\" width=\"607\" height=\"222\" />";
	}
	var obj = document.getElementById("flexMessage");
	obj.innerHTML = html;
	var title = document.getElementById("flexTitle");
	title.innerHTML = htmlTitle;
	images.setAll();
}





function checkUser(id){
	var currentUser = getCheckedValue(document.forms['tripleFlexCheck'].elements['tripleFlexUser']);
	if(currentUser == "yes"){
		var axel = Math.random()+"";
		var a = axel * 10000000000000;
		var html = '<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1659706;type=tripl026;cat=22tri891;ord='+ a + '?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>';
		var obj = document.getElementById("iFrameContainer");
		obj.innerHTML = html;
//		window.location="flextest_1.asp";
		document.getElementById('tripleFlexCheck').style.display = 'none';
		document.getElementById('surveyForm').style.display      = 'block';
	}else{
		document.getElementById('flexCheckSm_question_2').style.display      = 'block';
//		showDiv("jointCareContainer");
	}
	images.setAll();
}

function checkJointCare(id){
	var usesJointCare = getCheckedValue(document.forms['tripleFlexCheck'].elements['jointCare']);
	if(usesJointCare == "no"){
		var axel = Math.random()+"";
		var a = axel * 10000000000000;
		var html = '<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1659706;type=tripl026;cat=23tri592;ord='+ a + '?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>';
		var obj = document.getElementById("iFrameContainer");
		obj.innerHTML = html;
		//window.location="flextest_"+ id + ".asp";
//		window.location="flextest_1.asp";
		document.getElementById('tripleFlexCheck').style.display = 'none';
		document.getElementById('surveyForm').style.display      = 'block';
	}else{
		document.getElementById('flexCheckSm_question_3').style.display      = 'block';
	}
	// take care of new images
		images.setAll();
}

function whichProduct(id){
	var productType = getCheckedValue(document.forms['tripleFlexCheck'].elements['jointCareProduct']);
	var axel = Math.random()+"";
	var a = axel * 10000000000000;
	var html = "";
	
	if(productType == "OsteoBiFlex"){
		html = '<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1659706;type=tripl026;cat=23tri592;ord='+ a + '?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>';
	}else if(productType == "MoveFree"){
		html = '<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1659706;type=tripl026;cat=25tri247;ord='+ a + '?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>';
	}else if(productType == "Flexamin"){
		html = '<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1659706;type=tripl026;cat=26tri793;ord='+ a + '?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>';
	}else if(productType == "Other"){
		html = '<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1659706;type=tripl026;cat=27tri945;ord='+ a + '?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>';
	}
	var obj = document.getElementById("iFrameContainer");
	obj.innerHTML = html;
		document.getElementById('tripleFlexCheck').style.display = 'none';
		document.getElementById('surveyForm').style.display      = 'block';
		images.setAll();
}

function showDiv(divid){
   if (document.layers) document.layers[divid].display="block";
   else document.getElementById(divid).style.display="block";
	images.setAll();
}
function hideDiv(divid){
   if (document.layers) document.layers[divid].display="none";
   else document.getElementById(divid).style.display="none";
	images.setAll();
}

