var qnum=10;
var score=0;
var could_have_scored=0;
var total_points=30;
var questions_tried=0;
var score_string="";


columns1 = new Array(4);      
columns2 = new Array(4);   
columns3 = new Array(4);
columns4 = new Array(4);
columns5 = new Array(4);
columns6 = new Array(4);      
columns7 = new Array(4);   
columns8 = new Array(4);
columns9 = new Array(4);
columns10 = new Array(4);


tries = new Array();
tries[0] = columns1;
tries[1] = columns2;
tries[2] = columns3;
tries[3] = columns4;
tries[4] = columns5;
tries[5] = columns6;
tries[6] = columns7;
tries[7] = columns8;
tries[8] = columns9;
tries[9] = columns10;


for (i=0; i < qnum; i++)
for (j=0; j < 4; j++) { tries[i][j] = 0; } 

var answers_array=new Array()

//<p align=\"right\"><i>- Sandeha Nivarani chapter 11</i> </p>

answers_array[0]="<p align=\"justify\">Swami expands: &ldquo;The Guru has very often to tell you that you have forgotten your real name or that you have lost the most precious part of yourself and yet are unaware of the loss. The Guru is the physician for the illness which brings about the suffering of alternate birth and death. He is an adept at the treatment needed for the cure.<br>  <br>  If you do not get such a Guru, pray to the Lord Himself to show you the way and He will surely come to your rescue.&rdquo;<br>  <br>  <a href=\"http://www.sssbpt.info/ssspeaks/volume01/sss01-03.pdf%20\">To view the entire Divine Discourse click here: Sathya Sai Speaks - Volume01</a></p>";	

answers_array[1]="<p align=\"justify\">Swami narrates: &ldquo;Wherever he placed his foot a stone lotus sprang up. Thus he got the name of Padmapada. When he brought the clothes to the Guru, the guru was so pleased with the disciple's devotion that he showered his Grace on him, and immediately Padmapada became a great scholar. This is the greatness of service to the Guru and the Grace it can evoke from him. <br>  <br>If you can earn Swami's Grace then everything will be added unto you and you will be happy here and hereafter. Whatever work is being done by you, do it with utmost sincerity.&rdquo;<br><br><a href=\"http://www.sssbpt.info/ssspeaks/volume18/sss18-15.pdf\">To view the entire Divine Discourse click here: Sathya Sai Speaks - Volume18</a> </p>";	

answers_array[2]="<p align=\"justify\"><p>Swami guides us further: &ldquo;If you have daya, dama and dharma (sympathy, self-control and righteousness), that will take you beyond the realm of the three gunas (qualities of the mind); there is no need then for getting a Naama (Name) from the Guru and repeating it. The aajna (command) of the Guru or the Lord is even more important than the Name of the Guru or the Name of the Lord. Of what use is the repetition of the Name, without at the same time purifying the impulses by the observance of His commands.&rdquo;</p><p> <a href=\"http://www.sssbpt.info/ssspeaks/volume04/sss04-20.pdf%20\">To view the entire Divine Discourse click here: Sathya Sai Speaks - Volume04</a></p></p>";	

answers_array[3]="<p align=\"justify\"><p>Swami reveals: &ldquo;God, the God within, is the Guru of Gurus. His Grace can make the blind see, the lame walk and the dumb speak. By a mere touch, He can demolish the sins of the past and erect the basis for peace and joy. God can be adored, worshipped and even-imagined or pictured by man only in human form, so long as the consciousness as man persists, so long as man cannot escape from this necessity. How can he travel beyond his limits? He can visualize God only as man, with super-human or supra-human power, wisdom, love, compassion. He can never describe or delineate the formless, the attributeless, the qualityless. It is only by means of form and attribute that one can pray, adore, worship or feel the presence. And the form has to be human. Little minds with no faith may argue that God cannot come as Man but in fact God can be recognized only as Man by human. This explains the statement, &quot;Dhaivam maanusha ruupena&quot; - &quot;God through human form,&quot; found in the scriptures.</p><p><a href=\"http://www.sssbpt.info/ssspeaks/volume14/sss14-52.pdf%20\">To view the entire Divine Discourse click here: Sathya Sai Speaks - Volume14</a> </p></p>";	

answers_array[4]="<p align=\"justify\"><p>Swami clarifies: \"No, they are only teachers.\" And then, giving minute details, He imparts the knowledge of the true measure of Brahmaananda: &ldquo;What kind of joy does a man experience when he is happy, healthy and contented? What is the type of joy that man derives out of wealth, properties, pleasures and fortune? This is called Manushyaananda (human joy). Hundred times more than Manushyaananda is Indhrananda; hundred times, more than Indhrananda is Dhevendhrananda; hundred times more than Dhevendhrananda is Dhevaananda; hundred times more than Dhevaananda is Brihaspathi Ananda; hundred times more than Brihaspathi Ananda is Prajaapathi Ananda; hundred times more than Prajaapathi Ananda is Brahmaananda. This is the true measure of Brahmaananda. </p><p>&hellip;.This Brahmaananda transcends the material, moral, religious and spiritual aspects of life. The true Guru is one who experiences the supreme bliss of Brahmaananda. Who is he? None except God has the competence to experience such bliss. </p><p><a href=\"http://www.sssbpt.info/ssspeaks/volume25/sss25-22.pdf%20\">To view the entire Divine Discourse click here: Sathya Sai Speaks - Volume25</a></p></p>";	

answers_array[5]="<p align=\"justify\"><p>Swami continues: &ldquo;Man has the potency to elevate himself to this Ananda. Only he has to get rid of the obstacles that deny this experience. He is Brahmam and so his nature is Brahma-anandam. But, he does not know that all he believes he knows is known only as distorted or deluded. His waking experiences are as unreal and self-contrived as his dream experiences.&rdquo;</p><p><a href=\"http://www.sssbpt.info/ssspeaks/volume18/sss18-14.pdf\">To view the entire Divine Discourse click here: Sathya Sai Speaks - Volume18</a></p></p>";	

answers_array[6]="<p align=\"justify\"><p>Swami reveals to us: &ldquo;After writing the 18 puranas, he summed up their message in one line.&rdquo;Paropakaarah punyaaya; paapaaya parapeedanam&quot;. (Helping others is meritorious; harming others is sinful). &quot;Help ever; hurt never.&rdquo; Vyasa was the great teacher who gave many profound and sacred truths to man-kind. Hence his birthday is celebrated as Guru Poornima (the Full moon day dedicated to the preceptor). </p><p>To offer fruits, dakshina and other things to a teacher on Guru Poornima day is not the right way of worshipping the guru. Those who accept such gifts are worldly preceptors. Real gurus are to be worshipped by pradakshina, by revering them with heart and soul.&rdquo;</p><p><a href=\"http://www.sssbpt.info/ssspeaks/volume22/sss22-23.pdf\">To view the entire Divine Discourse click here: Sathya Sai Speaks - Volume22</a> </p></p>";

answers_array[7]="<p align=\"justify\"><p>Swami reveals: &ldquo;The true Guru is one who has no ego or selfishness, and who can raise the shishya to his own level. Donning the saffron robe, mouthing a few manthras (sacred formulas) and expounding some texts are the signs of many Gurus these days. The signs of a true Guru are large-heartedness, absolute selflessness, purity in living, freedom from acquisitiveness, absence of envy, and equal mindedness in his conduct towards everyone. </p><p>Freedom from envy is an essential quality in a Guru or shishya, because envy is the root cause of many evils. The Guru's role is to lead the shishya on the Godward path. He must teach the shishya the true purpose for which each of his sense organs is to be used - his eyes, his tongue, and his limbs. All the senses are to be used for discovering and experiencing the Divine.&rdquo;</p><p><a href=\"http://www.sssbpt.info/ssspeaks/volume17/sss17-14.pdf\">To view the entire Divine Discourse click here: Sathya Sai Speaks - Volume17</a></p></p>";	

answers_array[8]="<p align=\"justify\">Swami explains why: \"Of these eight Gurus, the Kaarana Guru is the foremost. Through various teachings and practices, he helps the individual to progress from the human to the divine consciousness. Only the divine can act as such a teacher. All other Gurus can be helpful only to a limited extent. There are, moreover, persons who claim to be Gurus, but who are really after the disciple's money. They trade in mantras and tantras. Self-realization is not to be got through mantras or tantras. Only by the purification of the mind can the Omni-self be realized.\" <a href=\"http://www.sssbpt.info/ssspeaks/volume19/sss19-14.pdf\">To view the entire Divine Discourse click here: Sathya Sai Speaks - Volume19</a></p>";	

answers_array[9]="<p align=\"justify\"><p>Swami exhorts: &ldquo;&quot;God is&quot; (&quot;Devudunnaadu,&quot; in Telugu). Make this your sheet-anchor. If you go on reciting it, thinking over it, acting up to it and conveying it to others, immersing yourself in the bliss of this experience, you will be making the greatest contribution to the welfare of the world. </p><p>Consider this mantra as the message for this Guru Poornima and proclaim it in all circumstances and at all places with all the conviction and strength you can command. The world can be turned into an earthly paradise if you strengthen your faith in God and demonstrate it in your actions. &hellip;From today, develop your faith in God; engage yourselves in dedicated service to society and make your lives purposeful and helpful to those in distress or need. Remember that whomsoever you may serve, you are serving God. This is My benediction for all of you.&rdquo;</p><p><a href=\"http://www.sssbpt.info/ssspeaks/volume19/sss19-14.pdf%20\">To view the entire Divine Discourse click here: Sathya Sai Speaks - Volume19</a> </p></p>";	


//<img src=\"images/14_TestYourSQ/discourse/01.jpg\" alt='image' width='175' height='250' border='1' align='right'>
var answer_images=new Array()
answer_images[0]="";
answer_images[1]="";
answer_images[2]="";
answer_images[3]="";
answer_images[4]="";
answer_images[5]="";
answer_images[6]="";
answer_images[7]="";
answer_images[8]="";
answer_images[9]="";


var right_answers=new Array()
right_answers[0]="2";
right_answers[1]="1";
right_answers[2]="4";
right_answers[3]="2";
right_answers[4]="3";
right_answers[5]="1";
right_answers[6]="2";
right_answers[7]="4";
right_answers[8]="3";
right_answers[9]="1";

var lock=new Array()

lock[0]="0";
lock[1]="0";
lock[2]="0";
lock[3]="0";
lock[4]="0";
lock[5]="0";
lock[6]="0";
lock[7]="0";
lock[8]="0";
lock[9]="0";

var first_attempt= new Array();
first_attempt[0]="Congrats! You have got it right in the very first attempt! You get 3 Points";
first_attempt[1]="Great! First attempt and right! You get 3 Points";
first_attempt[2]="You've got it in the very first attempt!! You get 3 Points";
first_attempt[3]="Well done! First click and right answer! You get 3 Points";
first_attempt[4]="You got it! Great going! You get 3 Points";
first_attempt[5]="Correct! You make it so easy! You get 3 Points";
first_attempt[6]="That's right! You are doing well! You get 3 Points";
first_attempt[7]="Absolutely correct! Well done! You get 3 Points";

var second_attempt= new Array();
second_attempt[0]="Good! You have got it right now! You get 2 Points";
second_attempt[1]="Yes! You got it now! You get 2 Points";
second_attempt[2]="That's right! Now you got it! You get 2 Points";
second_attempt[3]="Right! That's the answer! You get 2 Points";
second_attempt[4]="Yes! Now you have got it! You get 2 Points";
second_attempt[5]="That's right! Good try! You get 2 Points";
second_attempt[6]="Good! Thats the correct answer! You get 2 Points";
second_attempt[7]="You have now answered correctly! Well done! You get 2 Points";


var third_attempt= new Array();
third_attempt[0]="Finally! You got it right! You get 1 Point";
third_attempt[1]="Now you've got it! You get 1 Point";
third_attempt[2]="That's right! You get 1 Point";
third_attempt[3]="Correct! You have got it right now! You get 1 Point";
third_attempt[4]="Yes! That's the answer we were looking for! You get 1 Point";
third_attempt[5]="Finally! You guessed it right! You get 1 Point";
third_attempt[6]="Nice try! You did get it finally! You get 1 Point";
third_attempt[7]="Yes! Nice guess! You get 1 Point";

var final_score_messages= new Array();
final_score_messages[0]=" <strong>Very Good</strong>, Keep it up!";
final_score_messages[1]=" <strong>Good</strong>, you have scored well.";
final_score_messages[2]=" Good attempt. Thank you very much for trying the quiz";
final_score_messages[3]=" Good Try. Thank you very much for trying the quiz";

var right_textanswers=new Array();
var your_answers=new Array();
var your_textanswers=new Array();


function set_string(){
	
	if (questions_tried == 1)
		score_string="You get "+score+" out of "+could_have_scored+" for the 1st question.";
		
	else
		score_string="You get "+score+" out of "+could_have_scored+" for the "+questions_tried+" questions you attempted.";
}

function check(i){
    
	var answerarea="answer_area"+i;
	var sum =0;
	var random_num = Math.round(7*Math.random());
	
	//check if tries are allowed
	for(a=0;a<4;a++){sum += tries[i][a];}
	if (sum>=3){ 
		var radiobuttonname="l"+i+"_"+lock[i];
		document.getElementById(radiobuttonname).checked = true;
		return true;
		}
	
	//if tries are allowed
	sum = 0;
	document.getElementById(answerarea).innerHTML="";
	document.getElementById("score_area").innerHTML="";
	
	for(a=0;a<4;a++){
			var radiobuttonname="l"+i+"_"+a;
			var labelname="label"+i+"_"+a;
			if(document.getElementById(radiobuttonname).checked){
				your_answers[i]=document.getElementById(radiobuttonname).value;
				your_textanswers[i]=document.getElementById(labelname).innerHTML;
				tries[i][a]=1;
				lock[i]=a;
				}
			if(document.getElementById(radiobuttonname).value==right_answers[i]){
				right_textanswers[i]=document.getElementById(labelname).innerHTML;
				}
			sum += tries[i][a];	
		}
		if(your_answers[i]==right_answers[i]){
			var chancestogo=4-sum;
			if(chancestogo==3){
			score+=3;
			could_have_scored+=3;
			questions_tried+=1;
			set_string();
			document.getElementById(answerarea).innerHTML += "<table width='100%'  style='background-color:#CCFFCC;border:0;font-size:10pt;font-family:Arial' cellpadding='5'><tr><td width='78%'><font color='#000088'><b>"+ first_attempt[random_num] +"</b></font><br><br><font color='green'><b>Correct Answer : </b></font><font color='brown'>"+your_textanswers[i] + "</font><p align='justify'> <font color='#000088'>" + answers_array[i]+ " <br> <strong>SCORE:</strong> "+score_string+"</font></p></td><td width='22%'>"+ answer_images[i]+"</td></tr></table>";
			
			
			}
			if(chancestogo==2){
			score+=2;
			could_have_scored+=3;
			questions_tried+=1;
			set_string();
			document.getElementById(answerarea).innerHTML += "<table width='100%'  style='background-color:#CCFFCC;border:0;font-size:10pt;font-family:Arial' cellpadding='5'><tr><td width='78%'><font color='#000088'><b>"+ second_attempt[random_num] +"</b></font><br><br><font color='green'><b>Correct Answer : </b></font><font color='brown'>"+your_textanswers[i] + "</font><p align='justify'> <font color='#000088'>" + answers_array[i]+ " <br> <strong>SCORE:</strong> "+score_string+"</font></p></td><td width='22%'>"+ answer_images[i]+"</td></tr></table>";
			
			
			}
			if(chancestogo==1){
			score+=1;
			could_have_scored+=3;
			questions_tried+=1;
			set_string();
			document.getElementById(answerarea).innerHTML += "<table width='100%'  style='background-color:#CCFFCC;border:0;font-size:10pt;font-family:Arial' cellpadding='5'><tr><td width='78%'><font color='#000088'><b>"+ third_attempt[random_num] +"</b></font><br><br><font color='green'><b>Correct Answer : </b></font><font color='brown'>"+your_textanswers[i] + "</font><p align='justify'> <font color='#000088'>" + answers_array[i]+ " <br> <strong>SCORE:</strong>"+score_string+"</font></p></td><td width='22%'>"+ answer_images[i]+"</td></tr></table>";
			
			
			}
			
			
			for (j=0; j < 4; j++) { tries[i][j] = 1; }
			 
		}
		if(your_answers[i]!=right_answers[i]){
			if(sum >=3){
			could_have_scored+=3;
			questions_tried+=1;
			set_string();
			document.getElementById(answerarea).innerHTML += "<table width='100%'  style='background-color:#FFCCCC;border:0;font-size:10pt;font-family:Arial' cellpadding='5'><tr><td width='78%'><font color='brown'><b>Wrong... <br><br>Your Answer : </b>"+your_textanswers[i] +"</font><br><font color='green'><b>Correct Answer : </b></font><font color='brown'>"+right_textanswers[i] + "</font><p align='justify'> <font color='#000088'>" + answers_array[i]+ " <br> <strong>SCORE:</strong>"+score_string+"</font></p></td><td width='22%'>"+ answer_images[i]+"</td></tr></table>";
			
			
			}
			else{
					var chancestogo=3-sum;
					if(chancestogo==1){
					document.getElementById(answerarea).innerHTML+="<p><table width='100%' style='background-color:#FFCCCC;border:1 black;font-size:10pt;font-family:Arial' cellpadding='5'><tr><td style='color:brown'><b>Sorry... this is not the right answer.<br>You have just one more chance to go....</b></td></tr></table>";
					
					}
					else{
					document.getElementById(answerarea).innerHTML+="<p><table width='100%' style='background-color:#FFCCCC;border:1 black;font-size:10pt;font-family:Arial' cellpadding='5'><tr><td style='color:brown'><b>Sorry... this is not the right answer.<br>You have two more chances to go....</b></td></tr></table>";
					
					}
				}
		}
		
	document.getElementById(answerarea).style.display="inline";
	if (questions_tried == qnum)
	{ if(score >= 25)
		{
			document.getElementById("score_area").innerHTML += "<table width='100%'  style='background-color:#FFCC99;border:0;font-size:10pt;font-family:Arial' cellpadding='5'><tr><td width='100%'><p align='justify'> <font color='#000088'> <br> <strong>SCORE:</strong> [ "+score+" of "+total_points+" ]"+final_score_messages[0]+"</font></p> </td></tr></table>";
		}
		if(score >= 15 && score <25)
		{
			document.getElementById("score_area").innerHTML += "<table width='100%'  style='background-color:#FFCC99;border:0;font-size:10pt;font-family:Arial' cellpadding='5'><tr><td width='100%'><p align='justify'> <font color='#000088'> <br> <strong>SCORE:</strong> [ "+score+" of "+total_points+" ]"+final_score_messages[1]+"</font></p> </td></tr></table>";
		}
		if(score >=5 && score< 15)
		{
			document.getElementById("score_area").innerHTML += "<table width='100%'  style='background-color:#FFCC99;border:0;font-size:10pt;font-family:Arial' cellpadding='5'><tr><td width='100%'><p align='justify'> <font color='#000088'> <br> <strong>SCORE:</strong> [ "+score+" of "+total_points+" ]"+final_score_messages[2]+"</font></p> </td></tr></table>";
		}
		if(score <5)
		{
			document.getElementById("score_area").innerHTML += "<table width='100%'  style='background-color:#FFCC99;border:0;font-size:10pt;font-family:Arial' cellpadding='5'><tr><td width='100%'><p align='justify'> <font color='#000088'> <strong>SCORE:</strong> [ "+score+" of "+total_points+" ]"+final_score_messages[3]+"</font></p> </td></tr></table>";
		}
			
	document.getElementById("score_area").style.display="inline";
	}
	
}


function reset_all(){
	document.question_form.reset();
	for (i=0; i<=qnum; i++){
		var answerarea="answer_area"+i;
		for (j=0; j < 4; j++) { tries[i][j] = 0; } 
		document.getElementById(answerarea).innerHTML="";
		document.getElementById(answerarea).style.display="none";
		document.getElementById("score_area").innerHTML="";
		document.getElementById("score_area").style.display="none";
		document.location.href = "quiz.htm#";
		score=0;
		questions_tried=0;
		could_have_scored=0;
		score_string="";
	}
	
}
