
//*****************************************************
//Created By:     	Sanjay D
//Date Created:  	26.02.2004
//Modified By:      Shailesh Shahane
//Date Modified:    29.12.2006
//This Java script contains XML code
//*****************************************************


//--------------------

var $a={
$b:(typeof ActiveXObject!="undefined"),
$z:document.implementation&&document.implementation.createDocument,
$d:(typeof XMLHttpRequest!="undefined")};
$a.ARR_XMLHTTP_VERS=["MSXML2.XmlHttp.5.0","MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.3.0","MSXML2.XmlHttp","Microsoft.XmlHttp"];
$a.ARR_DOM_VERS=["MSXML2.DOMDocument.5.0","MSXML2.DOMDocument.4.0","MSXML2.DOMDocument.3.0","MSXML2.DOMDocument","Microsoft.XmlDom"];
$a.useDom=true;
$a.DOM_VER='';

function zXmlDom(){};

zXmlDom.createDocument=function(){
try
{

if($a.useDom==true)
{
var $f=document.implementation.createDocument("","",null);
$f.parseError={valueOf:function()
{return this.errorCode;},toString:function(){return this.errorCode.toString()}};
//$f.$L();
$f.addEventListener("load",function(){this.$M();this.$N(4);},false);
return $f;
}
else if($a.useActiveX==true){
if($a.DOM_VER=='')
{
for(var i=0;i<$a.ARR_DOM_VERS.length;i++)
{
try
{
new ActiveXObject($a.ARR_DOM_VERS[i]);
$a.DOM_VER=$a.ARR_DOM_VERS[i];
break;
}
catch($e){
}
}
}
                                                                          
if($a.DOM_VER!='')
{
return new ActiveXObject($a.DOM_VER);
}
else
{throw new Error("Could not create XML DOM document.");
}
}
else{
alert("Your browser doesn't support an XML DOM document.");

//throw new Error("Your browser doesn't support an XML DOM document.");
}
}
catch(e)
{
}
};
var $g=null;if(typeof $h!="undefined"){$g=$h;}
else if(typeof Document!="undefined"){$g=Document;};
if($g&&!window.opera){$g.prototype.readyState=0;
$g.prototype.onreadystatechange=null;
$g.prototype.$N=function($i){this.readyState=$i;if(typeof this.onreadystatechange=="function")
{
this.onreadystatechange();}};
$g.prototype.$L=function(){this.parseError.errorCode=0;this.parseError.filepos=-1;
this.parseError.line=-1;this.parseError.linepos=-1;this.parseError.reason=null;
this.parseError.srcText=null;this.parseError.url=null;};
$g.prototype.$M=function(){if(this.documentElement.tagName=="parsererror"){var $j=/>([\s\S]*?)Location:([\s\S]*?)Line Number(\d+), Column(\d+):<sourcetext>([\s\S]*?)(?:\-*\^)/;$j.test(this.xml);this.parseError.errorCode=-999999;this.parseError.reason=RegExp.$1;this.parseError.url=RegExp.$2;this.parseError.line=parseInt(RegExp.$3);this.parseError.linepos=parseInt(RegExp.$4);this.parseError.srcText=RegExp.$5;}};$g.prototype.loadXML=function($k){this.$L();this.$N(1);var $l=new DOMParser();var $f=$l.parseFromString($k,"text/xml");while(this.firstChild){this.removeChild(this.firstChild);};for(var i=0;i<$f.childNodes.length;i++){var $m=this.importNode($f.childNodes[i],true);this.appendChild($m);};this.$M();this.$N(4);};$g.prototype.$O=$g.prototype.load;$g.prototype.load=function($n){this.$L();this.$N(1);this.$O($n);};Node.prototype.__defineGetter__("xml",function(){var $o=new XMLSerializer();return $o.serializeToString(this,"text/xml");});Node.prototype.__defineGetter__("text",function(){var $p="";for(var i=0;i<this.childNodes.length;i++){if(this.childNodes[i].hasChildNodes()){$p+=this.childNodes[i].text;}else{$p+=this.childNodes[i].nodeValue;}};return $p;});};function zXslt(){};zXslt.transformToText=function($q,$r){if(typeof $s!="undefined"){var $t=new $s();$t.importStylesheet($r);var $u=$t.transformToDocument($q);var $v=$u.xml;if($v.indexOf("<transformiix:result")>-1){$v=$v.substring($v.indexOf(">")+1,$v.lastIndexOf("<"));};return $v;}else if($a.useActiveX){return $q.transformNode($r);}else{throw new Error("No XSLT engine found.");}};function zXPath(){};zXPath.selectNodes=function($w,$x,$y){if(typeof $z!="undefined"){$A=$A||{};var $B=function($Z){return $A[$Z];};var $D=new $z();var $E=$D.evaluate($x,$w,$B,$F.ORDERED_NODE_ITERATOR_TYPE,null);var $G=new Array;if($E!=null){var $H=$E.iterateNext();while($H){$G.push($H);$H=$E.iterateNext();}};return $G;}else if($a.useActiveX){if($A){var $y="";for(var $I in $A){$y+="xmlns:"+$I+"="+$A[$I]+" ";};$w.ownerDocument.setProperty("SelectionNamespaces",$y);};return $w.selectNodes($x);}else{throw new Error("No XPath engine found.");}};zXPath.selectSingleNode=function($w,$x,$A){if(typeof $z!="undefined"){$A=$A||{};var $B=function($Z){return $A[$Z];};var $D=new $z();var $E=$D.evaluate($x,$w,$B,$F.FIRST_ORDERED_NODE_TYPE,null);if($E!=null){return $E.singleNodeValue;}else{return null;}}else if($J.useActiveX){if($A){var $y="";for(var $I in $A){$y+="xmlns:"+$I+"="+$A[$I]+" ";};$w.ownerDocument.setProperty("SelectionNamespaces",$y);};return $w.selectSingleNode($x);}else{throw new Error("No XPath engine found.")}};function zXMLSerializer(){};zXMLSerializer.prototype.serializeToString=function($K){var $k="";switch($K.nodeType){case 1:$k="<"+$K.tagName;for(var i=0;i<$K.attributes.length;i++){$k+=" "+$K.attributes[i].name+"=\"" + oNode.attributes[i].value + "\"";};$k+=">";for(var i=0;i<$K.childNodes.length;i++){$k+=this.serializeToString($K.childNodes[i]);};$k+="</"+$K.tagName+">";break;case 3:$k=$K.nodeValue;break;case 4:$k="<![CDATA["+$K.nodeValue+"]]>";break;case 7:$k="<?"+$K.nodevalue+"?>";break;case 8:$k="<!--"+$K.nodevalue+"-->";break;case 9:for(var i=0;i<$K.childNodes.length;i++){$k+=this.serializeToString($K.childNodes[i]);};break;};return $k;};


//=====================









var stylesheet;
 var source;
 
if (window.ActiveXObject)               // IE
        {
         
 stylesheet=new ActiveXObject("Microsoft.xmldom");
 source=new ActiveXObject("Microsoft.xmldom");      
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {
          stylesheet=zXmlDom.createDocument();
         source=zXmlDom.createDocument();

}
stylesheet.async=false;

source.async=false;



var sortField = null;
var deltas = null;
var pageSize=1;
var curPage=1;
var lastPage=0;
var editPending=false;
var editedquestion=0;
var flagQ="N";
var unAnsQ="N";

var qNode;
var deltasRow;
			

   function LoadXML()
{  
 stylesheet.load("../xml_xsl/questionXSL.xsl");
			lastPage=Math.floor((source.documentElement.childNodes.length)/pageSize)-1;
  if (window.ActiveXObject)               // IE
        {
			//sortField = stylesheet.selectSingleNode("//@order-by");
			viewRange = stylesheet.selectSingleNode("//@test");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  

         viewRange =stylesheet.evaluate("//@test", stylesheet, null, 9, null).singleNodeValue;
      
     }
 deltas = source.cloneNode(false);
			deltas.appendChild(deltas.createElement("xml"));  
			
			display(true);
		
			startclock();
			
}











function nextPage()
{
	if (curPage == lastPage) 
		{
		if (window.ActiveXObject)               // IE
        {
        qNode=source.selectSingleNode("/xml");
        }
        else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
        {  
        qNode=source.evaluate("/xml", source, null, 9, null).singleNodeValue;
     
        }
		alert("This is the last question in the '"+ qNode.getAttribute("submode") + "' mode.\n Now you will see the first question in this mode .");
		//exit();
		curPage = 1;
		}
	else 
	{
	curPage++;
	}
	
	
		if (window.ActiveXObject)               // IE
        {
          if (flagQ=="Y" && source.selectNodes("/xml/question[@flagged='1']").length>0)
	{
		deltasRow=source.selectSingleNode("/xml/question["+(curPage-1)+"]");
		if (deltasRow.getAttribute("flagged")=="0")
			nextPage();
	}
	else
		flagQ="N";
		
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
     //var tmpNode = source.evaluate("/xml/question[@flagged='1']", source, null, 9, null).singleNodeValue;
//     var tmpNode =document.evaluate("/xml/question[@flagged='1']", source, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
     var tmpNode =source.evaluate("/xml/question[@flagged='1']", source, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); //FF
		     
          if (flagQ=="Y" && tmpNode.snapshotLength>0)
	{
		  deltasRow=source.evaluate("/xml/question["+(curPage)+"]", source, null, 9, null).singleNodeValue;
	
		if (deltasRow.getAttribute("flagged")=="0")
			nextPage();
	}
	else
		flagQ="N";
		
      
     }
     
   var len;
		
		if (window.ActiveXObject)               // IE
        {
		 qNode=source.selectNodes("/xml/question[@answered='0']");
		 len=qNode.length;
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        //qNode=source.evaluate("/xml/question[@answered='0']", source, null, 9, null).singleNodeValue;
        
        //qNode= document.evaluate("/xml/question[@answered='0']", source, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

		qNode= source.evaluate("/xml/question[@answered='0']", source, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); //FF
		     
        len= qNode.snapshotLength;
          
     }
		
		
	if (unAnsQ=="Y" && len>0)
	{
	if (window.ActiveXObject)               // IE
        {
		deltasRow=source.selectSingleNode("/xml/question["+(curPage-1)+"]");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        deltasRow=source.evaluate("/xml/question["+(curPage)+"]", source, null, 9, null).singleNodeValue;
     }
		
		if (deltasRow.getAttribute("answered")=="1")
			nextPage();
	}
	else
		unAnsQ="N";

		
	display(true);

}			


function previousPage()
{

	if (curPage== 1) 
		{
		
		if (window.ActiveXObject)               // IE
        {
		qNode=source.selectSingleNode("/xml");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        qNode=source.evaluate("/xml", source, null, 9, null).singleNodeValue;
     }
     
		alert("This is the first question in the '"+ qNode.getAttribute("submode") + "' mode.\n Now you will see the last question in this mode .");
		//exit();
		curPage = lastPage;
		}
	else 
		curPage--;
		

		
		
	
	if (window.ActiveXObject)               // IE
        {
         if (flagQ=="Y" && source.selectNodes("/xml/question[@flagged='1']").length>0)
	{
		deltasRow=source.selectSingleNode("/xml/question["+(curPage-1)+"]");
	
		if (deltasRow.getAttribute("flagged")=="0")
			previousPage();
	}
	else
		flagQ="N";
		
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
    // var tmpnode = source.evaluate("/xml/question[@flagged='1']", source, null, 9, null).singleNodeValue;
        //var tmpnode = document.evaluate("/xml/question[@flagged='1']", source, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
	var tmpnode = source.evaluate("/xml/question[@flagged='1']", source, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
		     
         if (flagQ=="Y" && tmpnode.snapshotLength>0)
	{
		deltasRow=source.evaluate("/xml/question["+(curPage)+"]", source, null, 9, null).singleNodeValue;
	
		if (deltasRow.getAttribute("flagged")=="0")
			previousPage();
	}
	else
		flagQ="N";
		
        
     }
     
    
		var len;
				if (window.ActiveXObject)               // IE
        {
		qNode=source.selectNodes("/xml/question[@answered='0']");
		len=qNode.length;
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
       // qNode=source.evaluate("/xml/question[@answered='0']", source, null, 9, null).singleNodeValue;
       //qNode= document.evaluate("/xml/question[@answered='0']", source, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

	qNode= source.evaluate("/xml/question[@answered='0']", source, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
		   len=qNode.snapshotLength;
     }
     
	if (unAnsQ=="Y" && len>0)
	{
		if (window.ActiveXObject)               // IE
        {
		deltasRow=source.selectSingleNode("/xml/question["+(curPage-1)+"]");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        deltasRow=source.evaluate("/xml/question["+(curPage)+"]", source, null, 9, null).singleNodeValue;
     }
     
		if (deltasRow.getAttribute("answered")=="1")
			previousPage();
	}
	else
		unAnsQ="N";
		
	
	display(true);
}			
    
function showAns()
{

	if (window.ActiveXObject)               // IE
        {
		deltasRow=source.selectSingleNode("/xml/question["+(curPage-1)+"]");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        deltasRow=source.evaluate("/xml/question["+(curPage)+"]", source, null, 9, null).singleNodeValue;
     }
     
     

	deltasRow.setAttribute("show_ans_explanation","1");
	
	
	for (var i=0 ;i<deltasRow.childNodes.length ;i++)
	{
	
		if (window.ActiveXObject)               // IE
        {
		if (deltasRow.childNodes(i).getAttribute("correct")=="1")
		{
			deltasRow.childNodes(i).setAttribute("choice_img","../images/correct_answer.jpg");
		}
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
       if (deltasRow.childNodes[i].getAttribute("correct")=="1")
		{
			deltasRow.childNodes[i].setAttribute("choice_img","../images/correct_answer.jpg");
		}
       }
       
		
	}	
	display(true);
}		

function ShowResult()
{
		if (window.ActiveXObject)               // IE
        {
		deltasRow=source.selectSingleNode("/xml");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        deltasRow=source.evaluate("/xml", source, null, 9, null).singleNodeValue;
     }
     
     
	if (deltasRow.getAttribute("showhide")=="show")
		deltasRow.setAttribute("showhide","hide");
	else
		deltasRow.setAttribute("showhide","show");
	display(true);
}

function FlagQ()
{
	if (window.ActiveXObject)               // IE
        {
		deltasRow=source.selectSingleNode("/xml/question["+(curPage-1)+"]");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        deltasRow=source.evaluate("/xml/question["+(curPage)+"]", source, null, 9, null).singleNodeValue;
     }
     
	deltasRow.setAttribute("flagged","1");
	
	updateResult();
	display(true);
}
	
function Review()
{
if (window.ActiveXObject)               // IE
        {
		qNode=source.selectSingleNode("/xml");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        qNode=source.evaluate("/xml", source, null, 9, null).singleNodeValue;
     }
     
	qNode.setAttribute("mode","Review");
	display(true);
}

function ReviewFlagged()
{
	unAnsQ="N";
   
	var len;
if (window.ActiveXObject)               // IE
        {
		deltasRow=source.selectNodes("/xml/question[@flagged='1']");
		len=deltasRow.length;
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
       //deltasRow=document.evaluate("/xml/question[@flagged='1']", source, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
deltasRow=source.evaluate("/xml/question[@flagged='1']", source, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); //FF
     
       len=deltasRow.snapshotLength;
        
     }
 
      
	if (len>0)
	{	
	if (window.ActiveXObject)               // IE
        {
		qNode=source.selectSingleNode("/xml");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        qNode=source.evaluate("/xml", source, null, 9, null).singleNodeValue;
     }
		qNode.setAttribute("submode","Review Flagged");
		flagQ="Y";
		curPage = 0;
		nextPage();
	}
	else
		alert("No Questions are flagged yet.You can click on the 'All' Button to review all questions.");
	
}

function ReviewUnanswered()
{
var len;
	if (window.ActiveXObject)               // IE
        {
		qNode=source.selectNodes("/xml/question[@answered='0']");
		len=qNode.length;
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
       // qNode=source.evaluate("/xml/question[@answered='0']", source, null, 9, null).singleNodeValue;
       //qNode= document.evaluate("/xml/question[@answered='0']", source, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
	qNode= source.evaluate("/xml/question[@answered='0']", source, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

	   len= qNode.snapshotLength;
     
     }
     	
	if (len==0)
	{
		alert("You have answered all questions.\n You can click on the 'All' Button to review all questions.");
		return;
	}
	
	flagQ="N";
	
	if (window.ActiveXObject)               // IE
        {
		deltasRow=source.selectNodes("/xml/question[@answered='1']");
		len=deltasRow.length;
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        //deltasRow=source.evaluate("/xml/question[@answered='1']", source, null, 9, null).singleNodeValue;
      // deltasRow= document.evaluate("/xml/question[@answered='1']", source, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

 deltasRow= source.evaluate("/xml/question[@answered='1']", source, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
		len=deltasRow.snapshotLength;
     }
     
	if (len>0)
	{		
	
	if (window.ActiveXObject)               // IE
        {
		qNode=source.selectSingleNode("/xml");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        qNode=source.evaluate("/xml", source, null, 9, null).singleNodeValue;
     }
     
		qNode.setAttribute("submode","Review Unanswered");
		unAnsQ="Y";
		curPage = 0;
		nextPage();
	}
	else
		alert("You have not answered any questions yet.");
		
}

function ReviewAll()
{
if (window.ActiveXObject)               // IE
        {
		qNode=source.selectSingleNode("/xml");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        qNode=source.evaluate("/xml", source, null, 9, null).singleNodeValue;
     }
     
	qNode.setAttribute("mode","All");
	qNode.setAttribute("submode","All");
	flagQ="N";
	unAnsQ="N";
	curPage = 0;
	nextPage();
		
}

function EndTest()
{

if (window.ActiveXObject)
	    {
	    
				var resultXSL=new ActiveXObject("Microsoft.xmldom");
	resultXSL.async=false;
	resultXSL.load("../xml_xsl/resultXSL.xsl");
	question.innerHTML =source.documentElement.transformNode(resultXSL);
	timetaken.innerHTML = testTime;	
	
		}
		else if (document.implementation && document.implementation.createDocument)
    	{
    	
    		var resultXSL=zXmlDom.createDocument();;
	resultXSL.async=false;
	resultXSL.load("../xml_xsl/resultXSL.xsl");
	
	
	
    	var xsltProcessor = new XSLTProcessor(); 
        xsltProcessor.importStylesheet(resultXSL); 
        result = xsltProcessor.transformToDocument(source); 
	   	document.getElementById("question").innerHTML =result.xml;
		document.getElementById("timetaken").innerHTML = testTime;	
	
    	}
    	


  
} 			

function PostResult()
{   


if (window.ActiveXObject)               // IE
        {
		qNode=source.selectSingleNode("/xml");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        qNode=source.evaluate("/xml", source, null, 9, null).singleNodeValue;
     }
     
    if (qNode.getAttribute("test_type")=="mock")
		{
		alert("Thanks for taking mock test");
		//window.location.href="../asp/mock_test.asp"
		window.close();
		}
	//Commented to update questions stats for random tests using Post xml data page
    //else if (source.selectSingleNode("/xml").getAttribute("test_type")=="random")
	//	{
	//	alert("Thanks for taking random test");
	//	window.close();
	//	}
	
	
 else if (qNode.getAttribute("user_account_id")=="1")
		{
		input_box=confirm("Only paid users can post the test results.\n\nClick OK to go back");
		if (input_box==true)
			{
			     if (qNode.getAttribute("test_type")=="random")
			    {
			        window.location.href="take_a_test.asp"			        
			    }// random
			    else if (qNode.getAttribute("test_type")=="basic")
			    {
			         window.location.href="basic_tutorial_list.asp"		
			    }// basic
			    
			     else if (qNode.getAttribute("test_type")=="advance")
			    {
			         window.location.href="advance_preparation.asp"		
			    }// advance
			    else
			    {
			        window.location.href="account_details.asp"
			    }//default
			}//if (input_box==true)

		} 
    else 
    {
        
		alert("Your test results will now be updated into the database.\nThis may take a minute.\nPlease be patient until you see database updated message.");
		// get ready to post updates to server
		
var objHTTP;

objHTTP =null;		
		  

// code for Mozilla, etc.
//if (window.XMLHttpRequest)
if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
  {
  
  //alert('Data is posted'); 
  objHTTP=new XMLHttpRequest();
  }
// code for IE
else if (window.ActiveXObject)
  {
  objHTTP=new ActiveXObject("Microsoft.XMLHTTP")
  }
  
		objHTTP.open("POST","post_xml_data.asp",false);
		// send the IDispatch xmldom to server through IStream interface
		try
		{
		//alert(getPostXML())
		objHTTP.send(getPostXML());
		}
		catch(e)
		{
		}
		
		//window.location='view_tutorial_details.asp?Tut_id=' + source.selectSingleNode("/xml").getAttribute("tutorial_id")

		if (qNode.getAttribute("test_type")=="random")
		{
			input_box=confirm(objHTTP.responseText + "\n\nStart a new test?");
			if (input_box==true)
			{
			     window.location.href="display_question.asp?test_type=random";
       			}
			else if(input_box==false)
			{
		window.location.href="take_a_test.asp";
			//window.opener.location.reload();
			//window.close();
			}
		}
		else
		{
			input_box=confirm(objHTTP.responseText + "\n\nClick OK to go back.");
			if (input_box==true)
			{
			        if (qNode.getAttribute("test_type")=="basic")
			        {
			            window.location.href="../asp/basic_tutorial_list.asp"
			        }
			        if (qNode.getAttribute("test_type")=="advance")
			        {
			            window.location.href="../asp/advance_preparation.asp"
			        }
			        
			        
			    
			//opener.location.reload();
		    	//window.close();
		    }
		}
    
    }
}	




function getPostXML()
{
	var deltas=null;
	deltas = source.cloneNode(false);
	
	deltasRow=null;
	
	// create a new deltas node
	deltasRow=deltas.createElement("xml");
	
	if (window.ActiveXObject)               // IE
        {
		qNode=source.selectSingleNode("/xml");
         }
   else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        qNode=source.evaluate("/xml", source, null, 9, null).singleNodeValue;
     }
     
	deltasRow.setAttribute("user_id",qNode.getAttribute("user_id"));
	deltasRow.setAttribute("user_name",qNode.getAttribute("user_name"));
	deltasRow.setAttribute("user_account_id",qNode.getAttribute("user_account_id"));
	deltasRow.setAttribute("test_type",qNode.getAttribute("test_type"));
	deltas.appendChild(deltasRow);
 	
    for  (var i=1;i<qNode.childNodes.length;i++)
    if (window.ActiveXObject)
	    {
			if 	(qNode.childNodes(i).getAttribute("answered") =="1"  || qNode.childNodes(i).getAttribute("save_q") =="1" || qNode.childNodes(i).getAttribute("user_complexity") != qNode.childNodes(i).getAttribute("complexity"))
		{
		// create a new deltas node
		deltasRow=deltas.createElement("question");
		deltasRow.setAttribute("id",qNode.childNodes(i).getAttribute("id"));
		deltasRow.setAttribute("answered",qNode.childNodes(i).getAttribute("answered"));
		deltasRow.setAttribute("save_q",qNode.childNodes(i).getAttribute("save_q"));
		deltasRow.setAttribute("user_complexity",qNode.childNodes(i).getAttribute("user_complexity"));
		deltasRow.setAttribute("complexity",qNode.childNodes(i).getAttribute("complexity"));
		deltasRow.setAttribute("is_correct",qNode.childNodes(i).getAttribute("is_correct"));
		deltas.documentElement.appendChild(deltasRow);
	}
		}
		else if (document.implementation && document.implementation.createDocument)
    	{
    	if 	(qNode.childNodes[i].getAttribute("answered") =="1"  || qNode.childNodes[i].getAttribute("save_q") =="1" || qNode.childNodes[i].getAttribute("user_complexity") != qNode.childNodes[i].getAttribute("complexity"))
		{
		// create a new deltas node
		deltasRow=deltas.createElement("question");
		deltasRow.setAttribute("id",qNode.childNodes[i].getAttribute("id"));
		deltasRow.setAttribute("answered",qNode.childNodes[i].getAttribute("answered"));
		deltasRow.setAttribute("save_q",qNode.childNodes[i].getAttribute("save_q"));
		deltasRow.setAttribute("user_complexity",qNode.childNodes[i].getAttribute("user_complexity"));
		deltasRow.setAttribute("complexity",qNode.childNodes[i].getAttribute("complexity"));
		deltasRow.setAttribute("is_correct",qNode.childNodes[i].getAttribute("is_correct"));
		deltas.documentElement.appendChild(deltasRow);
	}
    	}
		

	return deltas.xml;
}

function GoBack()
{  
    display(true);
}
   

    
function display(refreshMe)
{

	if (refreshMe==true)
	{
		viewRange.value="position()="+(curPage)+"";
		status="Current page "+(curPage+1)+"/"+(lastPage+1)
		
		if (window.ActiveXObject)
	    {
			question.innerHTML = source.documentElement.transformNode(stylesheet);
		}
		else if (document.implementation && document.implementation.createDocument)
    	{
    	var xsltProcessor = new XSLTProcessor(); 
        xsltProcessor.importStylesheet(stylesheet); 
        result = xsltProcessor.transformToDocument(source); 
        
	   	document.getElementById("question").innerHTML =result.xml;
    	}
    	
    	
	}	
}	












function updateComplexity(obj,qid)
{	

if (window.ActiveXObject)               // IE
        {
		deltasRow=source.selectSingleNode("/xml/question[@id='"+qid+"']");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        deltasRow=source.evaluate("/xml/question[@id='"+qid+"']", source, null, 9, null).singleNodeValue;
     }
     
	
	if (deltasRow.getAttribute("user_complexity")!=obj.value)
		deltasRow.setAttribute("user_complexity",obj.value);					
	
	
}

function updateSaveQ(obj,qid)
{	
	if (window.ActiveXObject)               // IE
        {
		deltasRow=source.selectSingleNode("/xml/question[@id='"+qid+"']");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        deltasRow=source.evaluate("/xml/question[@id='"+qid+"']", source, null, 9, null).singleNodeValue;
     }
	deltasRow.setAttribute("save_q",obj.value)					
}



function updateResult()
{// Look for the deltas node with the passed in primary key
var question;
if (window.ActiveXObject)               // IE
        {
		question=source.selectSingleNode("/xml");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        question=source.evaluate("/xml", source, null, 9, null).singleNodeValue;
     }
     
	
	
	var x=0,y=0,z=0,f=0;
	
	for ( i=1 ;i<question.childNodes.length ;i++)
	{	
	
	if (window.ActiveXObject)               // IE
        {
		if (question.childNodes(i).getAttribute("answered")=="1")
		{
			z = z +1 ;	
			if (question.childNodes(i).getAttribute("is_correct")=="1")
				x = x +1 ;	
			else
				y = y +1 ;	
		}
		if (question.childNodes(i).getAttribute("flagged")=="1")
		{
			f = f +1 ;	
		}
        }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        if (question.childNodes[i].getAttribute("answered")=="1")
		{
			z = z +1 ;	
			if (question.childNodes[i].getAttribute("is_correct")=="1")
				x = x +1 ;	
			else
				y = y +1 ;	
		}
		if (question.childNodes[i].getAttribute("flagged")=="1")
		{
			f = f +1 ;	
		}
     }
     
     
		
	}		
	
	var q1;
	if (window.ActiveXObject)               // IE
        {
		q1=question.selectSingleNode("result");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        q1=source.evaluate("/xml/result", source, null, 9, null).singleNodeValue;
     }
     
     
	q1.setAttribute("tot_q_flagged",f );
	q1.setAttribute("tot_q_answered",z );
	q1.setAttribute("tot_q_correct",x );
	q1.setAttribute("tot_q_wrong",y );
}











function updateXML(obj,qid)
{	
	
	if (window.ActiveXObject)               // IE
        {
		deltasRow=source.selectSingleNode("/xml/question[@id='"+qid+"']/choice[@id='"+ obj.id +"']");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        deltasRow=source.evaluate("/xml/question[@id='"+qid+"']/choice[@id='"+ obj.id +"']", source, null, 9, null).singleNodeValue;
     }
	
	var question;
	if (window.ActiveXObject)               // IE
        {
		question=source.selectSingleNode("/xml");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
        question=source.evaluate("/xml", source, null, 9, null).singleNodeValue;
     }
	var q1;
	
		if (window.ActiveXObject)               // IE
        {
		q1 = question.selectSingleNode("question[@id='"+qid+"']");
		
	    }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
     
    q1 =source.evaluate("/xml/question[@id='"+qid+"']", source, null, 9, null).singleNodeValue;
	
     }
	
 if (q1.getAttribute("show_ans_explanation")=="1")
		return;
	
	var z=0,t=0;
	//Check if more answers are selected than expected
	for (var i=0 ;i<q1.childNodes.length ;i++)
	{
	if (window.ActiveXObject)               // IE
        {
	if (q1.childNodes(i).getAttribute("selected")=="1")
			z = z +1 ;	
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
       if (q1.childNodes[i].getAttribute("selected")=="1")
			z = z +1 ;	
     }
		
	}	
	
	
	if (deltasRow.getAttribute("selected")=="1")
		z=z-1;
	else
		z=z+1;
	
	
	t=q1.getAttribute("tot_answers");
	
	if (z>t) 
	{
		alert("You are about select more answers than expected.\nPlease unselect any of other choices before selecting this new choice.");
		return;
	}
	 	
	if (deltasRow.getAttribute("selected")=="1")
		{
		deltasRow.setAttribute("choice_img","../images/check_off.jpg");
		deltasRow.setAttribute("selected","0");								
		}
	else
		{
		deltasRow.setAttribute("choice_img","../images/check_on.jpg");
		deltasRow.setAttribute("selected","1");	
									
		}
	
	q1.setAttribute("answered","0");
	q1.setAttribute("flagged","0");
	q1.setAttribute("is_correct","1");
	
	for (var i=0 ;i<q1.childNodes.length ;i++)
	{
		
			if (window.ActiveXObject)               // IE
        {
        if (q1.childNodes(i).getAttribute("selected")=="1")
		{
		
	
			q1.setAttribute("answered","1");
			q1.setAttribute("flagged","0");
		}
		if (q1.childNodes(i).getAttribute("correct")=="1" && q1.childNodes(i).getAttribute("selected")=="0" )
			q1.setAttribute("is_correct","0");
         }
  else if (document.implementation && document.implementation.createDocument)    //MOZILLA,NS
     {  
     if (q1.childNodes[i].getAttribute("selected")=="1")
		{
			q1.setAttribute("answered","1");
			q1.setAttribute("flagged","0");
		}
       if (q1.childNodes[i].getAttribute("correct")=="1" && q1.childNodes[i].getAttribute("selected")=="0" )
			q1.setAttribute("is_correct","0");
     }
 
	}
	updateResult();
	
    display(true);
}






function CalcKey(value)
{
var srclen=0;
var temp=value;
for(i=0;i<temp.length;i++)
{
srclen=srclen+temp.charCodeAt(i);
}
if(srclen==0)
{
//alert('Please Enter the appropriate Key');
}
return srclen;

}




function Decryption(value)

{
var txt=value;
var j=3;
var temp1;
var res="";
var srclen=0;
srclen=CalcKey('oBsIT');
if(srclen>0)
{
if(txt.length>0)
{
for(i=0;i<txt.length;i+=3)
{

var temp=txt.substring(i,j);
temp1=(parseInt(temp)-srclen);
var t=unescape('%'+temp1.toString(16));
if(t=='%d' || t=='%a')
{
res=res+' ';
}
else
{
res=res+t
} 
j+=3;
}
return res;
}
else
{
//alert('Some error occured while loading the test');
}
}
}
