function toggleEnable(tempName)
{
	eval("document.forms[0]." + tempName + ".disabled = false;");
}
function toggleDisable(tempName){

	eval("document.forms[0]." + tempName + ".disabled = true;");
	eval("document.forms[0]." + tempName + ".checked = false;");
}
function toggleEnableRadio(tempName)
{
	eval("for (var i = 0; i < document.forms[0]." + tempName + ".length; i++) {document.forms[0]." + tempName + "[i].disabled = false;}");
}
function toggleDisableRadio(tempName){
	eval("for (var i = 0; i < document.forms[0]." + tempName + ".length; i++) {document.forms[0]." + tempName + "[i].disabled = true;}");
	eval("for (var i = 0; i < document.forms[0]." + tempName + ".length; i++) {document.forms[0]." + tempName + "[i].checked = false;}");
}
function CheckRadioButtons(tempName)
{
	tempAnswered = false;
	eval("for (var i = 0; i < document.forms[0]." + tempName + ".length; i++) {if (document.forms[0]." + tempName + "[i].checked == true){tempAnswered = true; }}");
	eval("if (document.forms[0]." + tempName + "[0].disabled == true){ tempAnswered = true;}");
	if (tempAnswered)
	{

		return true;
	}
	else
	{
			alert("Please answer all required questions.");
		return false;
	}
}
//Contents for menu 2
var menu2=new Array()
menu2[0]='<a href="http://www.drugabuse.gov/drugpages/alcohol.html">Alcohol</a>'
menu2[1]='<a href="http://www.drugabuse.gov/drugpages/clubdrugs.html">Club Drugs</a>'
menu2[2]='<a href="http://www.drugabuse.gov/drugpages/cocaine.html">Cocaine</a>'
menu2[3]='<a href="http://www.drugabuse.gov/drugpages/heroin.html">Heroin</a>'
menu2[4]='<a href="http://www.drugabuse.gov/drugpages/inhalants.html">Inhalants</a>'
menu2[5]='<a href="http://www.drugabuse.gov/drugpages/acidLSD.html">LSD (Acid)</a>'
menu2[6]='<a href="http://www.drugabuse.gov/drugpages/marijuana.html">Marijuana</a>'
menu2[7]='<a href="http://www.drugabuse.gov/drugpages/mdma.html">MDMA (Ecstasy)</a>'
menu2[8]='<a href="http://www.drugabuse.gov/drugpages/methamphetamine.html">Methamphetamine</a>'
menu2[9]='<a href="http://www.drugabuse.gov/drugpages/nicotine.html">Nicotine</a>'
menu2[10]='<a href="http://www.drugabuse.gov/drugpages/pcp.html">PCP (Phencyclidine)</a>'
menu2[11]='<a href="http://www.drugabuse.gov/drugpages/prescription.html">Prescription Medications</a>'
menu2[12]='<a href="http://www.drugabuse.gov/drugpages/steroids.html">Steroids (Anabolic)</a>'
menu2[13]='<a href="http://www.drugabuse.gov/drugpages/steroids.html"><br></a>'
menu2[14]='<a href="http://www.drugabuse.gov/drugpages/cj.html">Crime & Drug Abuse Treatment</a>'
menu2[15]='<a href="http://www.drugabuse.gov/Infofacts/driving.html">Drugged Driving</a>'
menu2[16]='<a href="http://www.drugabuse.gov/drugpages/testing.html">Drug Testing</a>'
menu2[17]='<a href="http://www.drugabuse.gov/drugpages/HIV.html">HIV and Drug Abuse</a>'
menu2[18]='<a href="http://www.drugabuse.gov/consequences/">Medical Consequences of Drug Abuse</a>'
menu2[19]='<a href="http://www.drugabuse.gov/drugpages/prevention.html">Prevention Research</a>'
menu2[20]='<a href="http://www.drugabuse.gov/drugpages/PSAHome.html">Public Service Announcements</a>'
menu2[21]='<a href="http://www.drugabuse.gov/drugpages/stress.html">Stress & Drug Abuse</a>'
menu2[22]='<a href="http://www.drugabuse.gov/drugpages/treatment.html">Treatment Research</a>'
menu2[23]='<a href="http://www.drugabuse.gov/drugpages/stats.html">Trends and Statistics</a>'
var menuwidth='235px' //default menu width
var menubgcolor='#edf2eb'  //menu bgcolor
var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?
/////No further editting needed
var ie4=document.all
var ns6=document.getElementById&&!document.all
if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>');
function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null)
	{
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}
function showhide(obj, e, visible, hidden, menuwidth)
{
	if (ie4||ns6)
		dropmenuobj.style.left=dropmenuobj.style.top="-500px"
	if (menuwidth!=""){
		dropmenuobj.widthobj=dropmenuobj.style
		dropmenuobj.widthobj.width=menuwidth
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
		obj.visibility=visible
	else if (e.type=="click")
		obj.visibility=hidden
}
function iecompattest()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function clearbrowseredge(obj, whichedge)
{
var edgeoffset=0
	if (whichedge=="rightedge"){
		var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
		edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
	}
	else{
		var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
		var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
			if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
				edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
		}
	}
	return edgeoffset
}
function populatemenu(what)
{
	if (ie4||ns6)
		dropmenuobj.innerHTML=what.join("")
}
function dropdownmenu(obj, e, menucontents, menuwidth)
{
	if (window.event) event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()
	clearhidemenu()
	dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
	populatemenu(menucontents)
	if (ie4||ns6){
		showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
		dropmenuobj.x=getposOffset(obj, "left")
		dropmenuobj.y=getposOffset(obj, "top")
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
	}
	return clickreturnvalue()
}
function clickreturnvalue()
{
	if (ie4||ns6) return false
	else return true
}
function contains_ns6(a, b)
{
	while (b.parentNode)
	if ((b = b.parentNode) == a)
	return true;
	return false;
}
function dynamichide(e)
{
	if (ie4&&!dropmenuobj.contains(e.toElement))
		delayhidemenu()
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		delayhidemenu()
}
function hidemenu(e)
{
	if (typeof dropmenuobj!="undefined"){
		if (ie4||ns6)
			dropmenuobj.style.visibility="hidden"
	}
}
function delayhidemenu()
{
	if (ie4||ns6)
		delayhide=setTimeout("hidemenu()",disappeardelay)
}
function clearhidemenu()
{
	if (typeof delayhide!="undefined")
		clearTimeout(delayhide)
}
if (hidemenu_onclick=="yes")
	document.onclick=hidemenu

/**
 * @desc a short description
 * a longer description, possibly multi-line
 *
 * @todo something that needs doing to this file
HISTORY
mm/dd/2009 - kjb - edits performed on this date
*/
$(document).ready(function(){
	preloadImages();
	$("div#feedback_area").hide();
	$("input#feedback_send").after('<input type="button" value="Send" name="feedback_send" id="feedback_send" />').remove();

	var questionnum = $("input#question").val();
	if (questionnum != "1") {
		$("a#instrux_link").text("Show Instructions");
		$("div#surveyinstrux div").hide();
	}
	$("a#feedback_link").click(function(){
		$("div#feedback_area").toggle('slow');
	});
	$("a#restart_link").click(function(){
		window.location='?RESETDATA=Yes';
	});
	$("a#print_link").click(function(){
		window.print();
		return false;
	});
	$("a#instrux_link").click(function(){
		linktext = $(this).text();
		if (linktext == "Hide Instructions")
		{
			$(this).text("Show Instructions");
		}
		else
		{
			$(this).text("Hide Instructions");
		}
		$("div#surveyinstrux div").toggle();

		return false;
	});
	$("div#feedback_area input[@type=button]").click(function(){
		var feedback = $("textarea#feedback_text").val();
		$.get("/nmassist/my_nidascreen/comment", { comment: feedback },
			function(data) {
				$("textarea#feedback_text").value='';
				$("div#feedback_area").hide('fast').after(data);
			}
		);
		return false;
	});
	$("input[type=text]").keyup(function(){
		var val = $(this).val();
		if (val.length > 0)
		{
			$(this).parent().parent().children("td:first").children("input").attr('checked',1);
		}
	});
	if (jQuery.browser['msie']==true &&jQuery.browser['version']=='8.0')
	{
		$("div#question_title").css({
			'text-align':"left", 'top':"4px"
		});
		$("div#question_nav").css({
			'top':"0px"
		});
		$("div#surveyhead h2").css({
			'margin-bottom':"1em"
		});
		$("div#surveyhead").css({
			'text-align':"left"
		});
	}
});
