var sec = 01;   // set the seconds //DONT CHANGE THIS
var min = 01;   // set the minutes //DONT CHANGE THIS
var SD = null;


// JavaScript Document
function changeQuestion(option)
{

var httpxml;

try
{
//firefox,opera,safri
httpxml = new XMLHttpRequest();

}
catch(e)
{

//internet explorer
try
{
httpxml = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
httpxml = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{	  
return false;
}
}
}

function bindTimeDropDown() 
{
	if(httpxml.readyState==4)
	{
			if(httpxml.status==200)
			{
			//alert(httpxml.responseText);
					document.getElementById("question").innerHTML=httpxml.responseText;
					if( SD )
					window.clearTimeout( SD ); 
					sec = 60; //DONT CHANGE THIS
					min = 00; //DONT CHANGE THIS
					SD=window.setTimeout("countDown();", 1000);
			}
	
	}
}

if(option == 1)
{
	for (var i=0; i < document.frmQuestion.questAnswer.length; i++)
	{
		if (document.frmQuestion.questAnswer[i].checked)
		{
			var optionselected = document.frmQuestion.questAnswer[i].value;
		}
	}

//var optionselected = document.getElementsByName("questAnswer").value;

//alert(optionselected);
}
if(option==1)
{
var url = "temp-question.php?selected="+optionselected;
}
else
{
var url = "temp-question.php";	
}
httpxml.onreadystatechange=bindTimeDropDown;
httpxml.open("GET",url,true);
httpxml.send(null);

}

function countDown() {
//alert(sec);
sec--;
if (sec == -01) {
sec = 59;
min = min - 1;
} else {
min = min;
}
if (sec<=9) { sec = "0" + sec; }
time = "Time remaining for the question is : "+ sec + " sec ";
document.getElementById( "theTime" ).innerHTML = time;
SD = window.setTimeout("countDown()", 1000);
if (min == '00' && sec == '00') { 
	sec = "01"; 
	window.clearTimeout( SD ); 
	changeQuestion(1);
	}
}


function checkOptionselected()
{
	for (var i=0; i < document.frmQuestion.questAnswer.length; i++)
	{
		if (document.frmQuestion.questAnswer[i].checked)
		{			
		  var optionselected = document.frmQuestion.questAnswer[i].value;
		}
	}
	if(optionselected != 1 && optionselected != 2 && optionselected != 3 && optionselected != 4)
	{
		document.getElementById("selOption").style.color= "red";
		document.getElementById("selOption").innerHTML = "You have to select an answer to move to next question";
	}
	else
	{
		//alert("i am here");
		changeQuestion(1);
	}
}


function chkTheTerms()
{	
	if(document.frmTesthome.chkTerms.checked)
	{
		window.location.href = "test-questions.php";
	}
	else
	{
		alert("Accept the terms and conditions to proceed with the test");
	}
}

function chkTheTermsContinue()
{	
	if(document.frmTesthome.chkTermsContinue.checked)
	{
		window.location.href = "test-continue.php";
	}
	else
	{
		alert("Accept the terms and conditions to proceed with the test");
	}
}
/*
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() { if ( oldonload ){ oldonload(); } func(); }
	}
}
*/


function changeQuestionSample(option)
{

var httpxml;

		try
		{
		//firefox,opera,safri
		httpxml = new XMLHttpRequest();
		
		}
		catch(e)
		{
		
		//internet explorer
			try
			{
			httpxml = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e)
			{
					try
					{
					httpxml = new ActiveXObject("Microsoft.XMLHTTP");
					}
					catch(e)
					{	  
					return false;
					}
			}
		}

function bindSample() 
{
	if(httpxml.readyState==4)
		{
		if(httpxml.status==200)
			{
			//alert(httpxml.responseText);
			document.getElementById("question").innerHTML=httpxml.responseText;
			if( SD )
					window.clearTimeout( SD ); 
					sec = 60; //DONT CHANGE THIS
					min = 00; //DONT CHANGE THIS
					SD=window.setTimeout("countDownSample();", 1000);
			}
		
		}
}

	if(option == 1)
	{
		for (var i=0; i < document.frmQuestion.questAnswer.length; i++)
		{
			if (document.frmQuestion.questAnswer[i].checked)
			{
			var optionselected = document.frmQuestion.questAnswer[i].value;
			}
		}
	
	//var optionselected = document.getElementsByName("questAnswer").value;
	
	//alert(optionselected);
	}
	if(option==1)
	{
		var url = "sampletemp-question.php?selected="+optionselected;
	}
	else
	{
		var url = "sampletemp-question.php";	
	}
	httpxml.onreadystatechange=bindSample;
	httpxml.open("GET",url,true);
	httpxml.send(null);

}

function countDownSample() {
sec--;
if (sec == -01) {
sec = 59;
min = min - 1;
} else {
min = min;
}
if (sec<=9) { sec = "0" + sec; }
//time = (min<=9 ? "0" + min : min) + " min and " + sec + " sec ";
//document.getElementById( "theTime" ).innerHTML = time;
//if (document.getElementById) { theTime.innerHTML = time; }
SD=window.setTimeout("countDownSample();", 1000);
if (min == '00' && sec == '00') { 
	sec = "01"; 
	window.clearTimeout(SD); 
	changeQuestionSample(1);
	//alert("I am Coming");
	}
}

function checkOptionselectedSample()
{
	for (var i=0; i < document.frmQuestion.questAnswer.length; i++)
	{
		if (document.frmQuestion.questAnswer[i].checked)
		{
		  var optionselected = document.frmQuestion.questAnswer[i].value;
		}
	}
	if(optionselected != 1 && optionselected != 2 && optionselected != 3 && optionselected != 4)
	{
		alert("You have to select an answer to move to next question");
	}
	else
	{
		//alert("i am here");
		changeQuestionSample(1);
	}
}

