function getMsg(nValue)
{
	var strMsg="Based on your answers, we feel your drinking habits are under control.";
	nValue = parseInt(nValue);
	if(nValue>7 && nValue<16){
		strMsg="Based on your answers we advise that you seek advice on reducing hazardous drinking.";
	}else if(nValue>16 && nValue<20){
		strMsg="Based on your answers, we strongly advise you to contact HAGAM or another specialist agency to get help.";
	}else if(nValue>19){
		strMsg="Your answers indicate possible alcohol dependence - We strongly advise you to seek professional help from your GP or contact HAGAM.";
	}

return(strMsg);
}

function getMsg1(nValue)
{
	//alert('hi');
	var strMsg="Based on your answers, we feel your drinking habits are under control.";
	 nValue = parseInt(nValue);
	//alert (nValue)
	num=parseInt((nValue/8)*100);
	//alert(num);
		if(num>=0 && num<40){
		strMsg="You scored "+num+"%. Good try, but you haven't reached the average score of people who completed the quiz this time. Don't give up! Why not check out our <a href='index.php?page=22&ln=3'>  Alcohol </a> information page?";
	}else if(num>39 && num<60){
		strMsg="You scored "+num+"% That is the average score of people who completed this quiz. How would you like to be exceptional? Why not check out our <a href='index.php?page=22&ln=3'>Alcohol </a>information page?";
	}else if(num>59){
		strMsg="You scored "+num+"%. Congratulations!!! This is above the average score of people who completed this quiz. You have a very good knowledge base. You might like to check out the<a href='index.php?page=22&ln=3'> Alcohol </a>or <a href='index.php?page=2&ln=2'>Drugs Information </a> section of our website to see what else you can learn.";
	}

return(strMsg);
}




var _qcounter=1;
var _avalue=0;
var  question=[1, 2, 3, 4, 5, 6, 7, 8];
var  que=[1, 2, 3, 4, 5, 6, 7, 8,9,10,11,12,13,14,15,16];

function goToNext1(pageno){
	var b;
	b=getCheckedValue(document.forms['frmQuestionForm1'].elements['rdquestion_'+question[_qcounter-1]]);	
    if(b!=""){
		goToNext(pageno);
	}else{
		alert("Please answer this question.");
	}
}
function goToNext4(pageno){
	if(getCheckedValue(document.forms['frmQuestionForm2'].elements['rdquestion_'+_qcounter])!=""){
		goToNext(pageno);
	}else{
		alert("Please answer this question.");
	}
}



function goToNext(pageno)
{
	//debugger;
	//alert(pageno)
	var currentNun=_qcounter;
	
	var rdbCounter  = currentNun-1;
	var rdbQcounter  = currentNun;
	
	var strMsg="";
	_qcounter++;
	var page_question=9;
	
	if(pageno=='25')
		 page_question=11;
	
	try{	
		
		document.getElementById("prevBtn").className='answer-hide';			
		document.getElementById("nextBtn").className='answer-show';
		
		if(pageno=='24')
		{
			 document.getElementById('answer').innerHTML="";
			 document.getElementById("answer").className='answer-show';
			 document.getElementById("startAgainBtn").className='answer-hide';	
			 document.getElementById("checkBtn").className='answer-hide';
		}
		
		if(pageno=='24' && _qcounter == 8 )
		{
				document.getElementById("nextBtn").className='answer-hide';
				document.getElementById("prevBtn").className='answer-show';	
				document.getElementById("checkBtn").className='answer-show';
				document.getElementById("question_9").innerHTML="";
				
		}
		if(pageno=='25' && _qcounter ==10 )
		{
			
				document.getElementById("nextBtn").className='answer-show';
				document.getElementById("prevBtn").className='answer-show';	
				document.getElementById("question_11").innerHTML="";
				
		}	
		if(_qcounter > 1)
			document.getElementById("prevBtn").className='answer-show';
					
		if((_qcounter-1) < page_question)
		{
			
			if(pageno=='24' && _qcounter<page_question)
			{
				document.getElementById("question_"+question[rdbCounter]).className='answer-hide';
				document.getElementById("question_"+question[rdbQcounter]).className='answer-show';
				
			}
			if(pageno=='25' && _qcounter<page_question)
			{
				document.getElementById("question_"+currentNun).className='answer-hide';
			document.getElementById("question_"+_qcounter).className='answer-show';	
				
			}
			if(pageno=='25')
			{
				_avalue=_avalue + parseInt(getCheckedValue(document.forms['frmQuestionForm2'].elements['rdquestion_'+currentNun]));
				
			}
				
			if(pageno=='24'){
				_avalue=_avalue + parseInt(getCheckedValue(document.forms['frmQuestionForm1'].elements['rdquestion_'+question[rdbCounter]]));
			}
				
	   }
	 if(pageno=='25' &&_qcounter==11)
	   {
		  
		   
				document.getElementById("prevBtn").className='answer-hide';
				document.getElementById("question_11").className='answer-show';
				document.getElementById("question_11").innerHTML=getMsg(_avalue);
				document.getElementById("question_"+currentNun).className='answer-hide';
				document.getElementById("nextBtn").className='answer-hide';						
		}
	
		if(pageno=='24' &&_qcounter==9)
		{
				document.getElementById("nextBtn").className='answer-hide';
				document.getElementById("prevBtn").className='answer-hide';
				 document.getElementById("startAgainBtn").className='answer-show';	
				document.getElementById("question_"+question[rdbCounter]).className='answer-hide';
				document.getElementById("question_9").className='answer-show';
				
				document.getElementById("question_9").innerHTML=getMsg1(_avalue);	
				var _ava ="<img border='0' src='uploads/image/ribbons-awards.jpg' alt='Ribbons awards' />"
				document.getElementById("answer1").className='answer-show';
						document.getElementById("answer1").innerHTML="";
						document.getElementById("answer1").innerHTML=_ava;
			}	
		
		
	}catch(e){}	

}











function goToPrev(pageno){	

	var currentNun=_qcounter;
	
	_qcounter--;
	
	try{
	
		if(pageno=='24')
		{
			 document.getElementById('answer').innerHTML="";
			 document.getElementById("answer").className='answer-show';
			 document.getElementById("startAgainBtn").className='answer-hide';	
			 document.getElementById("checkBtn").className='answer-hide';
		}
			
		if(_qcounter > 0 && pageno=='24')
		{
			document.getElementById("question_"+question[currentNun-1]).className='answer-hide';
			document.getElementById("question_"+question[_qcounter-1]).className='answer-show';
			
			
			if(pageno=='24')
			{
				if((getCheckedValue(document.forms['frmQuestionForm1'].elements['rdquestion_'+question[_qcounter-1]]))=='0')
				{
					_avalue=_avalue;
				}
				else
				{
				_avalue=_avalue-parseInt('1');
				}
				for(var i =question[_qcounter-1]; i <8; i++)
				{
				rdbReferesh(document.forms['frmQuestionForm1'].elements['rdquestion_'+i]);
				}
			}
		}
		if(_qcounter > 0 && pageno=='25')
		{
			document.getElementById("question_"+currentNun).className='answer-hide';
			document.getElementById("question_"+_qcounter).className='answer-show';
			
			if(pageno=='25')
			{
				
				_avalue=_avalue - parseInt(getCheckedValue(document.forms['frmQuestionForm2'].elements['rdquestion_'+_qcounter]));	
				for(var i =_qcounter; i <10; i++)
				{
				rdbReferesh(document.forms['frmQuestionForm2'].elements['rdquestion_'+i]);
				}
			}
			
			
		}
		
		if(_qcounter > 1){
			document.getElementById("prevBtn").className='answer-show';
			}
			else
			{
			_avalue=0;
			document.getElementById("prevBtn").className='answer-hide';
		}	
	
		document.getElementById("nextBtn").className='answer-show';
			
	}catch(e){}
}

function chcked()
{
	var currentNun=_qcounter;
	if(document.getElementById('rdquestion_'+currentNun).checked==false)
	{
		alert('please click atlease 1 question.')
		return false;
	}
	return true;
}
function goToNext3()
{
	var b;
		b=getCheckedValue(document.forms['frmQuestionForm'].elements['rdquestion_'+que[_qcounter-1]]);	
	
	if(b!=""){
		goToNext2();
	}else{
		alert("Please answer this question.");
	}
}

function goToNext2(){
	
	
	var currentNun=_qcounter;
	var rdbCounter  = currentNun-1;
	var rdbQcounter  = currentNun;
	var page_question=16;
	_qcounter++;
	
	try{	
		
		document.getElementById("prevBtn").className='answer-hide';			
		document.getElementById("nextBtn").className='answer-show';
		document.getElementById('answer').innerHTML="&nbsp;";
		document.getElementById("answer").className='answer-show';
		document.getElementById("startAgainBtn").className='answer-hide';	
		document.getElementById("checkBtn").className='answer-hide';
		if(_qcounter == 15 )
		{
				document.getElementById("nextBtn").className='answer-hide';
				document.getElementById("prevBtn").className='answer-show';	
				document.getElementById("checkBtn").className='answer-show';
				
			}
		
		if(_qcounter==16){
				document.getElementById("nextBtn").className='answer-hide';
				document.getElementById("prevBtn").className='answer-hide';	
				document.getElementById("checkBtn").className='answer-hide';
				document.getElementById("startAgainBtn").className='answer-show';
				
			document.getElementById("question_"+que[rdbCounter]).className='answer-hide';
				var _ava ="<img border='0' src='uploads/image/ribbons-awards.jpg' alt='Ribbons awards' />"
				document.getElementById("answer1").className='answer-show';
						document.getElementById("answer1").innerHTML="";
						document.getElementById("answer1").innerHTML=_ava;

			}
				
			
		if(_qcounter > 1&&_qcounter!=16)
			document.getElementById("prevBtn").className='answer-show';
			
		for(var i =que[_qcounter-1]; i <15; i++)
				{
				rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_'+i]);
				}
		if(_qcounter < page_question)
		{
							
			document.getElementById("question_"+que[rdbCounter]).className='answer-hide';
				document.getElementById("question_"+que[rdbQcounter]).className='answer-show';
		}
		
		if(_qcounter==16)
		{
			document.getElementById("question_16").className='answer-show';
		}
	}catch(e){}	

}
function goToPrev2(){	

	var currentNun=_qcounter;
	_qcounter--;
	
	try{
		
		 document.getElementById('answer').innerHTML="&nbsp;";
		 document.getElementById("answer").className='answer-show';
		 document.getElementById("startAgainBtn").className='answer-hide';
		 document.getElementById("checkBtn").className='answer-hide';
		
			
		if(_qcounter > 0)
		{
			document.getElementById("question_"+que[currentNun-1]).className='answer-hide';
			document.getElementById("question_"+que[_qcounter-1]).className='answer-show';
			
			if((getCheckedValue(document.forms['frmQuestionForm'].elements['rdquestion_'+que[_qcounter-1]]))=='0')
				{
					
					_avalue11 = parseInt(_avalue11);
				}
				else
				{
				
					_avalue11 = parseInt(_avalue11)-parseInt('1');
				}
			
			
		      for(var i =(que[_qcounter-1]); i <15; i++)
				{
				  rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_'+i]);
				}
		}
		
		if(_qcounter > 1)
		{
			for(var i =(que[_qcounter-1]); i <15; i++)
				{
				rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_'+i]);
				}
			document.getElementById("prevBtn").className='answer-show';
			
			}
			else
			{
			
			document.getElementById("prevBtn").className='answer-hide';
		}	
		
		document.getElementById("nextBtn").className='answer-show';
	}catch(e){}
}



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 rdbReferesh(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		radioObj.checked=false;
			
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked=false;
		
	}
	return "";
}

function rdValue(_rdValue,pageno){
	
	if(pageno=='24')
	{
	var _avalue ="<img src='images/big-tick.gif' border='0' />";
		if(_rdValue==0)
			_avalue ="<img src='images/cross-big.gif' border='0' />";
		
		document.getElementById("answer").className='answer-show';
		document.getElementById("answer").innerHTML="";
		document.getElementById("answer").innerHTML=_avalue;
		//UpdateMsg();
	}else if(pageno=='29')
	{
		document.getElementById("answer").className='answer-show';
		document.getElementById("answer").innerHTML="&nbsp;";
		document.getElementById("answer").innerHTML=_rdValue;
	}
	
}
var _avalue11=0;
function rdValue1(_rdValue,pageno,_avalue2)
{
	
	var currentNun=_qcounter;
	
	if(pageno=='24')
	{
	var _avalue ="<img src='images/big-tick.gif' border='0' />";
		if(_rdValue==0)
			_avalue ="<img src='images/cross-big.gif' border='0' />";
		
		document.getElementById("answer").className='answer-show';
		document.getElementById("answer").innerHTML="";
		document.getElementById("answer").innerHTML=_avalue;
		//UpdateMsg();
	}
	
	else if(pageno=='29')
	{
		document.getElementById("answer").className='answer-show';
		document.getElementById("answer").innerHTML="&nbsp;";
		document.getElementById("answer").innerHTML=_rdValue;
		
		_avalue11=parseInt(_avalue11) +parseInt( _avalue2);
		if(_qcounter==15)
		{
			
			
			var strMsg="Based on your answers, we feel your drinking habits are under control.";
			_avalue11 = parseInt(_avalue11);
			num=parseInt((_avalue11/15)*100);
		if(num>=0 && num<40)
		{
		strMsg="You scored "+num+"%. Good try, but you have some way to go to get the smarts. Don't give up! Why not check out the <a href='index.php?page=2&ln=2'>Drugs Information </a>Drugs </a> section of our website?";
	}
	else if(num>39 && num<60)
	{
		strMsg="You scored "+num+"% You certainly Got the Smarts! Do you think you can beat the average score? Why not check out the <a href='index.php?page=2&ln=2'>Drugs Information </a> Drugs </a> section of our website?";
	}else if(num>59
			 ){
		strMsg="You've done it! You scored "+num+"%. This beats the average score of people who completed the quiz. Your knowledge base is great. You may like to check out the <a href='index.php?page=2&ln=2'>Drugs Information </a>section of our website to see what else you can learn.";
	}
document.getElementById("question_16").innerHTML=strMsg;
//document.getElementById("prevBtn").className='answer-hide';	

		}
		
	}
	
	
}




function startAgain()
{

	question.sort(function() {return  0.5 - Math.random()})
	_qcounter=1;
		
		 _avalue=0;
		rdbReferesh(document.forms['frmQuestionForm1'].elements['rdquestion_1']);
		rdbReferesh(document.forms['frmQuestionForm1'].elements['rdquestion_2']);
		rdbReferesh(document.forms['frmQuestionForm1'].elements['rdquestion_3']);
		rdbReferesh(document.forms['frmQuestionForm1'].elements['rdquestion_4']);
		rdbReferesh(document.forms['frmQuestionForm1'].elements['rdquestion_5']);
		rdbReferesh(document.forms['frmQuestionForm1'].elements['rdquestion_6']);
		rdbReferesh(document.forms['frmQuestionForm1'].elements['rdquestion_7']);
		rdbReferesh(document.forms['frmQuestionForm1'].elements['rdquestion_8']);
		
		
		
		
		document.getElementById("prevBtn").className='answer-hide';
		document.getElementById("startAgainBtn").className='answer-hide';	
		document.getElementById("nextBtn").className='answer-show';
		document.getElementById("question_1").className='answer-hide';
		document.getElementById("question_9").className='answer-hide';
		document.getElementById("question_"+question[_qcounter-1]).className='answer-show';
		document.getElementById('answer').innerHTML="";
		document.getElementById("answer").className='answer-hide';
		document.getElementById("answer1").className='answer-hide';
		
}

function startAgain2(){
	que.sort(function() {return  0.5 - Math.random()})
	_qcounter=1;
	_avalue11=0;
	
	rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_1']);
	rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_2']);
	rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_3']);
	rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_4']);
	rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_5']);
	rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_6']);
	rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_7']);
	rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_8']);
	rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_9']);
	rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_10']);
	rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_11']);
	rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_12']);
	
		document.getElementById("prevBtn").className='answer-hide';
		document.getElementById("startAgainBtn").className='answer-hide';	
		document.getElementById("nextBtn").className='answer-show';
		document.getElementById("question_1").className='answer-hide';
		document.getElementById("question_13").className='answer-hide';
		document.getElementById("answer1").className='answer-hide';
		
		document.getElementById("question_"+que[_qcounter-1]).className='answer-show';
		document.getElementById('answer').innerHTML="";
		document.getElementById("answer").className='answer-hide';
}


function funrefresh()
{
	    rdbReferesh(document.forms['frmQuestionForm1'].elements['rdquestion_1']);
		rdbReferesh(document.forms['frmQuestionForm1'].elements['rdquestion_2']);
		rdbReferesh(document.forms['frmQuestionForm1'].elements['rdquestion_3']);
		rdbReferesh(document.forms['frmQuestionForm1'].elements['rdquestion_4']);
		rdbReferesh(document.forms['frmQuestionForm1'].elements['rdquestion_5']);
		rdbReferesh(document.forms['frmQuestionForm1'].elements['rdquestion_6']);
		rdbReferesh(document.forms['frmQuestionForm1'].elements['rdquestion_7']);
		rdbReferesh(document.forms['frmQuestionForm1'].elements['rdquestion_8']);
}


function funrefresh1()
{
	    rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_1']);
		rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_2']);
		rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_3']);
		rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_4']);
		rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_5']);
		rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_6']);
		rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_7']);
		rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_8']);
		rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_9']);
		rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_10']);
		rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_11']);
		rdbReferesh(document.forms['frmQuestionForm'].elements['rdquestion_12']);
		
}
function funrefresh2()
{
	
	    rdbReferesh(document.forms['frmQuestionForm2'].elements['rdquestion_1']);
		rdbReferesh(document.forms['frmQuestionForm2'].elements['rdquestion_2']);
		rdbReferesh(document.forms['frmQuestionForm2'].elements['rdquestion_3']);
		rdbReferesh(document.forms['frmQuestionForm2'].elements['rdquestion_4']);
		rdbReferesh(document.forms['frmQuestionForm2'].elements['rdquestion_5']);
		rdbReferesh(document.forms['frmQuestionForm2'].elements['rdquestion_6']);
		rdbReferesh(document.forms['frmQuestionForm2'].elements['rdquestion_7']);
		rdbReferesh(document.forms['frmQuestionForm2'].elements['rdquestion_8']);
		rdbReferesh(document.forms['frmQuestionForm2'].elements['rdquestion_9']);
		rdbReferesh(document.forms['frmQuestionForm2'].elements['rdquestion_10']);
		
		
}