
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


// special window.open exclusively for the Survey
function openNew(URL) {
	window.open(URL, target="_printChild", 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=1,resizable=1,width=625,height=650');
}

// get the values from the quiz, create a concatenated number, and open the appropriate html
function scorequiz() {
	
	var f1 = getChecked(document.quiz.QA);
	var f2 = getChecked(document.quiz.QB);
	var f3 = getChecked(document.quiz.QC);
	var f4 = getChecked(document.quiz.QD);
	if ((f1 == null) || (f2 == null) || (f3 == null) || (f4 == null) ) {
		location.href="/secure/GeneralContent/migraine/isit_working_error.asp";
		}
	else {
	
		var totalScore = ((f1) + (f2) + (f3) + (f4));
		if (totalScore == "1468") {
			location.href=("results/" + totalScore + ".asp");
			}
		else {
			location.href="results/" + totalScore + ".asp";
			//openNew("results/" + totalScore + "print.asp");
		}
	}
}

// identify which is checked from each group
function getChecked(group) {
	for ( var i=0; i<group.length; i++ ) {
		 if ( group[i].checked == true ) {
			  return group[i].value;
		 }
	}
}


// define the default number of days for cookie expiration
var expDays = 365;

// which page should be popped for the one-time survey
var page = "/secure/GeneralContent/survey/take_survey.asp";
var windowprops = "width=600,height=500,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes";

// get the specific value of the cookie
function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
		return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

// set the cookie with an expiration equal to what is defined above
function SetCookie (name, value) {  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}

// set the old cookie to an expired time to delete it if necessary
function DeleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

// add 1 to the cookie if they've been here before
function amt() {
	var count = GetCookie('count')
	if(count == null) {
		SetCookie('count','1')
		return 1
	}
	else {
		var newcount = parseInt(count) + 1;
		DeleteCookie('count')
		SetCookie('count',newcount,exp);
		return count
   }
}

// get the value of the cookie, detect if it's null or not
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

// generate a number between 1 and 101
var randomNum = Math.round(Math.random() * 100) + 1;

// if that number is above 90, pop the survey page.
function getRandomNum() {
 	if (randomNum >= 90) {
		checkCount();
		}
	}

// see if they've received the cookie before now
function checkCount() { 
	var count = GetCookie('count');
	if (count == null) 
	{
		count=1;
		SetCookie('count', count, exp);
/*		window.open(page, "", windowprops); */
	}
	else
	{
		count++;
		SetCookie('count', count, exp);
   }
}

/******************/
/* POLL FUNCTIONS */
/******************/

var graphimageP="/images/rightCol/poll_bar.gif";
var thePollName="";
var formCookie="taken";

// set the cookie to show the poll has been taken
function takePoll() {
	SetCookie('poll_Name',thePollName, exp);
}

// set the cookie for the form
function closeForm() {
	SetCookie('form_Name',formCookie, exp);
	parent.location.reload();
}

// show the correct DIV for the poll status
function miniInit() {
 setTimeout("setPollLayer();",500);
 setTimeout("setFormLayer();",1000);
}

function setFormLayer() {
	SetCookie('cookieEnable', "yes", exp);
	if (GetCookie('cookieEnable') == null) {
		MM_showHideLayers('formLayer','','hide');
	} else {
		if (GetCookie('form_Name') != formCookie) {
			MM_showHideLayers('formLayer','','show');
		} else {
			MM_showHideLayers('formLayer','','hide');
		}
	}
}

function setPollLayer() {
	SetCookie('cookieEnable', "yes", exp);
	if (GetCookie('cookieEnable') == null) {
		MM_showHideLayers('pollQuestion','','hide','pollResults','','show');
	}
	else {
		if (GetCookie('poll_Name') != thePollName) {
			MM_showHideLayers('pollQuestion','','show','pollResults','','hide');
		}
		else {
			MM_showHideLayers('pollQuestion','','hide','pollResults','','show');
		}
	}
}


//DEFINE GRAPH VALUES [Item name, Percentage value]

function graphitP(grapha, graphb, gwidth) {
	var arrLen = grapha.length;
	var graphc = new Array();
	for (var arrLoop = 0; arrLoop < arrLen; arrLoop++) {
		graphc[arrLoop] = [grapha[arrLoop], graphb[arrLoop]];
	}

	outputP='<table border="0" cellspacing="0" cellpadding="0">'
	for (i=0;i<graphc.length;i++) {
		calwidthP=gwidth*(parseInt(graphc[i][1])/100)
		outputP+='<tr class="headImgTxt"><td class="headImgTxt" colspan="3">'+graphc[i][0]+'&nbsp;:&nbsp;'+graphc[i][1]+'</td></tr><tr><td width="1"><img src="/images/rightCol/poll_left.gif" width="1" height="11"></td><td width="118" background="/images/rightCol/poll_bg.gif"><img src="/images/spacer.gif" width="1" height="2"><img src="'+graphimageP+'" width="'+calwidthP+'" height="7"></td><td width="1"><img src="/images/rightCol/poll_left.gif" width="1" height="11"></td></tr>'
	}
	outputP+='</table>';
	document.write(outputP);
}
