//
//   
//    Copyright     :   Confidential and Proprietary. 
//                      Copyright RISI, 2007
//                                      
//    File name     :   ajaxresponse.js
//   
//    Description   :   Javascript to handle ajax
//   
//    Author        :   Cognizant
//   
//    Date          :   Sep 25, 2007
//    
//    Modification History      
//   
//    Revision No.      Author              Date                Comments
//      
//   
//
function ajaxresponse(){
	var MSXML_DOM		=getDom("<Technolgy/>");
	//var MSXML_XMLHTTP	= "Msxml2.XMLHTTP.3.0";
	var MSXML_XMLHTTP	= getXmlHttpObject() ;
	var UNINITIALIZED = 0;
	var LOADING = 1;   
	var LOADED = 2;
	var INTERACTIVE = 3;
	var COMPLETE = 4;
	var SUBMIT_SERVLET_URL = "/ajax"; 
	var pageName="";
	var fromPageName="";
	var isIE = navigator.userAgent.toLowerCase().indexOf("msie") > -1;
	var isMoz = document.implementation && document.implementation.createDocument;
	var pollPosition =  0; // Modified by Cognizant Offshore for Bug 64400

	

	
	var AjaxRequest;
	//var oXmlHttp = new XMLHttpRequest();

	

		function getXmlHttpObject() {

             if (window.ActiveXObject) {

				    return new ActiveXObject("Microsoft.XMLHTTP");

             }

             if (document.implementation && document.implementation.createDocument) {

				                       return new XMLHttpRequest();

             }
	  }

	function getDom(xml)
	{
		  if (window.ActiveXObject) {

                        var dom=new ActiveXObject("Microsoft.XMLDOm");
        }

            if (document.implementation && document.implementation.createDocument) {

                        var domParser=new DOMParser();

                        var dom = domParser.parseFromString (xml,"text/xml");
            }

            return dom;
	}
		
	
	this.initializeAjaxRequest = function()
	{
		AjaxRequest = getXmlHttpObject();
	};
	
	
// Modified by Cognizant Offshore for Bug 64400 - Starts
	
	 this.fetchSubmit = function(position)
	 {
	 	pollPosition = position;
		try 
		{
			var ansA="0";
			var ansB="0";
			var ansC="0";
			var ansD="0";
			var ansE="0";
			var ansF="0";
			var ansG="0";
			var ansH="0";
			var ansI="0";
			var ansJ="0";
			
			var formName = "pollForm"+position;			
			var radlen = document.forms[formName].ans.length;			
			  if(radlen>=1){
			  	if(document.forms[formName].ans[0].checked==true){
			 		ansA=1;		
			  	}
			  }
			  if(radlen>=2){
			  if(document.forms[formName].ans[1].checked==true){
				ansB=1;			
			  	}
			  }
			  if(radlen>=3){

			  if(document.forms[formName].ans[2].checked==true){
			  	ansC=1;  	
			  	}
			  }
			if(radlen>=4){

			  if(document.forms[formName].ans[3].checked==true){
			 	ansD=1;		
			  	}
			  }
			  if(radlen>=5){

			  if(document.forms[formName].ans[4].checked==true){
				ansE=1;			
			  	}
			  }
			  if(radlen>=6){

			  if(document.forms[formName].ans[5].checked==true){
			  	ansF=1;  	
			  	}
			  }
			 if(radlen>=7){

			  if(document.forms[formName].ans[6].checked==true){
			 	ansG=1;		
			  	}
			  }
			  if(radlen>=8){

			  if(document.forms[formName].ans[7].checked==true){
				ansH=1;			
			  	}
			  }
			  if(radlen>=9){

			  if(document.forms[formName].ans[8].checked==true){
			  	ansI=1;  	
			  	}
			  }
			  if(radlen>=10){

			  if(document.forms[formName].ans[9].checked==true){
			  	ansj=1;  	
			  	}
			  }


			var pollId= document.getElementById("pollId"+pollPosition).value;
// Modified by Cognizant Offshore for Bug 64400 - Ends
			  		
			
			this.initializeAjaxRequest();
			if(AjaxRequest)
			{		
					var xmlDoc = MSXML_DOM; 
					AjaxRequest.onreadystatechange = this.checkState; 
					AjaxRequest.open("POST",SUBMIT_SERVLET_URL+"?ansA="+ansA+"&ansB="+ansB+"&ansC="+ansC+"&ansD="+ansD+"&ansE="+ansE+"&ansF="+ansF+"&ansG="+ansG+"&ansH="+ansH+"&ansI="+ansI+"&ansJ="+ansJ+"&pollId="+pollId,true); 
					AjaxRequest.send(xmlDoc.xml); 
			}
			else
			{   
				alert(MSXML_XMLHTTP + " request could not be created.");
				return;
			}
		}
		catch(e) 
		{
			alert(e.description);
		}
	};
	
	this.checkState = function() {

		
		if(AjaxRequest.readyState == COMPLETE) {
			try {
				var xmlDoc = MSXML_DOM;
				
				var ajaxres=(AjaxRequest.responseText).split("</Techchannels>");
				ajaxres=ajaxres[0]+"</Techchannels>";

				if(isMoz && getDom(ajaxres)) 
				{
				    xmlDoc=getDom(ajaxres);
					pollReq.populateTable(xmlDoc);
				}
				else if(isIE && xmlDoc.loadXML(ajaxres)) 
				{
					pollReq.populateTable(xmlDoc);
				}
				else 
				{
					alert("Unable to load response xml."+AjaxRequest.responsetext);
				}
			}	
			catch(e) {
				alert(e.description);
			}
			
		}
		else if(AjaxRequest.readyState == INTERACTIVE) {	
		}		
	};

	this.populateTable = function(xmlDoc) {
		
		
		
		//var pollQuestion= xmlDoc.getElementsByTagName("pollQuestion");
		var pollDate= xmlDoc.getElementsByTagName("pollDate");
		var pollAns1= xmlDoc.getElementsByTagName("pollAns1");
		var pollAns2= xmlDoc.getElementsByTagName("pollAns2");
		var pollAns3= xmlDoc.getElementsByTagName("pollAns3");
		var pollAns4= xmlDoc.getElementsByTagName("pollAns4");
		var pollAns5= xmlDoc.getElementsByTagName("pollAns5");
		var pollAns6= xmlDoc.getElementsByTagName("pollAns6");
		var pollAns7= xmlDoc.getElementsByTagName("pollAns7");
		var pollAns8= xmlDoc.getElementsByTagName("pollAns8");
		var pollAns9= xmlDoc.getElementsByTagName("pollAns9");
		var pollAns10= xmlDoc.getElementsByTagName("pollAns10");



		var pollVal1= xmlDoc.getElementsByTagName("pollVal1");
		var pollVal2= xmlDoc.getElementsByTagName("pollVal2");
		if(xmlDoc.getElementsByTagName("pollVal3") != null){
		var pollVal3= xmlDoc.getElementsByTagName("pollVal3");
		}
		if(xmlDoc.getElementsByTagName("pollVal4") != null){
		var pollVal4= xmlDoc.getElementsByTagName("pollVal4");
		}
		if(xmlDoc.getElementsByTagName("pollVal5") != null){
		var pollVal5= xmlDoc.getElementsByTagName("pollVal5");
		}
		if(xmlDoc.getElementsByTagName("pollVal6") != null){
		var pollVal6= xmlDoc.getElementsByTagName("pollVal6");
		}
		if(xmlDoc.getElementsByTagName("pollVal7") != null){
		var pollVal7= xmlDoc.getElementsByTagName("pollVal7");
		}
		if(xmlDoc.getElementsByTagName("pollVal8") != null){
		var pollVal8= xmlDoc.getElementsByTagName("pollVal8");
		}
		if(xmlDoc.getElementsByTagName("pollVal9") != null){
		var pollVal9= xmlDoc.getElementsByTagName("pollVal9");
		}
		if(xmlDoc.getElementsByTagName("pollVal10") != null){
		var pollVal10= xmlDoc.getElementsByTagName("pollVal10");
		}


		var pollPer1= xmlDoc.getElementsByTagName("pollPer1");
		var pollPer2= xmlDoc.getElementsByTagName("pollPer2");
		if(xmlDoc.getElementsByTagName("pollPer3") != null){
		var pollPer3= xmlDoc.getElementsByTagName("pollPer3");
		}
		if(xmlDoc.getElementsByTagName("pollPer4") != null){
		var pollPer4= xmlDoc.getElementsByTagName("pollPer4");
		}
		if(xmlDoc.getElementsByTagName("pollPer5") != null){
		var pollPer5= xmlDoc.getElementsByTagName("pollPer5");
		}
		if(xmlDoc.getElementsByTagName("pollPer6") != null){
		var pollPer6= xmlDoc.getElementsByTagName("pollPer6");
		}
		if(xmlDoc.getElementsByTagName("pollPer7") != null){
		var pollPer7= xmlDoc.getElementsByTagName("pollPer7");
		}
		if(xmlDoc.getElementsByTagName("pollPer8") != null){
		var pollPer8= xmlDoc.getElementsByTagName("pollPer8");
		}
		if(xmlDoc.getElementsByTagName("pollPer9") != null){
		var pollPer9= xmlDoc.getElementsByTagName("pollPer9");
		}
		if(xmlDoc.getElementsByTagName("pollPer10") != null){
		var pollPer10= xmlDoc.getElementsByTagName("pollPer10");
		}

// Modified by Cognizant Offshore for Bug 64400 - Starts
	
		document.getElementById("pollAnswers"+pollPosition).innerHTML="";
		document.getElementById("result"+pollPosition).style.visibility='visible';
		document.getElementById("firstAns"+pollPosition).innerHTML="<img id='image1"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result1"+pollPosition+"'></span></p>";
		document.getElementById("secndAns"+pollPosition).innerHTML="<img id='image2"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result2"+pollPosition+"'></span></p>";
		document.getElementById("image1"+pollPosition).src="/community/images/poll_1.gif";
		document.getElementById("image2"+pollPosition).src="/community/images/poll_2.gif";
		
		if(isIE)
             {
		document.getElementById("ans1"+pollPosition).innerText=pollAns1[0].firstChild.nodeValue;
		document.getElementById("ans2"+pollPosition).innerText=pollAns2[0].firstChild.nodeValue;
		if((pollAns3[0].firstChild != null))
		{

		document.getElementById("thiredAns"+pollPosition).innerHTML="<img id='image3"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result3"+pollPosition+"'></span></p>"
		document.getElementById("image3"+pollPosition).src="/community/images/poll_3.gif";

		document.getElementById("ans3"+pollPosition).innerText=pollAns3[0].firstChild.nodeValue;
		}
		if((pollAns4[0].firstChild != null))
		{
		document.getElementById("fourthAns"+pollPosition).innerHTML="<img id='image4"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result4"+pollPosition+"'></span></p>"
		document.getElementById("image4"+pollPosition).src="/community/images/poll_1.gif";

		document.getElementById("ans4"+pollPosition).innerText=pollAns4[0].firstChild.nodeValue;
		}
		if((pollAns5[0].firstChild != null))
		{	
			document.getElementById("fifthAns"+pollPosition).innerHTML="<img id='image5"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result5"+pollPosition+"'></span></p>"
			document.getElementById("image5"+pollPosition).src="/community/images/poll_2.gif";

			document.getElementById("ans5"+pollPosition).innerText=pollAns5[0].firstChild.nodeValue;
		}
		if((pollAns6[0].firstChild != null))
		{
			document.getElementById("sixthAns"+pollPosition).innerHTML="<img id='image6"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result6"+pollPosition+"'></span></p>"
			document.getElementById("image6"+pollPosition).src="/community/images/poll_3.gif";

			document.getElementById("ans6"+pollPosition).innerText=pollAns6[0].firstChild.nodeValue;
		}
		if((pollAns7[0].firstChild != null))
		{
			document.getElementById("seventhAns"+pollPosition).innerHTML="<img id='image7"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result7"+pollPosition+"'></span></p>"
			document.getElementById("image7"+pollPosition).src="/community/images/poll_1.gif";

			document.getElementById("ans7"+pollPosition).innerText=pollAns7[0].firstChild.nodeValue;
		}
		if((pollAns8[0].firstChild != null))
		{
			document.getElementById("eighthAns"+pollPosition).innerHTML="<img id='image8"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result8"+pollPosition+"'></span></p>"
			document.getElementById("image8"+pollPosition).src="/community/images/poll_2.gif";

			document.getElementById("ans8"+pollPosition).innerText=pollAns8[0].firstChild.nodeValue;
		}
		if((pollAns9[0].firstChild != null))
		{
			document.getElementById("ninthAns"+pollPosition).innerHTML="<img id='image9"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result9"+pollPosition+"'></span></p>"
			document.getElementById("image9"+pollPosition).src="/community/images/poll_3.gif";

			document.getElementById("ans9"+pollPosition).innerText=pollAns9[0].firstChild.nodeValue;
		}
		if((pollAns10[0].firstChild != null))
		{
			document.getElementById("tenthAns"+pollPosition).innerHTML="<img id='image10"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result10"+pollPosition+"'></span></p>"
			document.getElementById("image10"+pollPosition).src="/community/images/poll_1.gif";

			document.getElementById("ans10"+pollPosition).innerText=pollAns10[0].firstChild.nodeValue;
		}
	      }
		else
		{
		
		document.getElementById("ans1"+pollPosition).textContent=pollAns1[0].firstChild.nodeValue;
		document.getElementById("ans2"+pollPosition).textContent=pollAns2[0].firstChild.nodeValue;
		if((pollAns3[0].firstChild != null))
		{
		document.getElementById("thiredAns"+pollPosition).innerHTML="<img id='image3"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result3"+pollPosition+"'></span></p>"
		document.getElementById("image3"+pollPosition).src="/community/images/poll_3.gif";

		document.getElementById("ans3"+pollPosition).textContent=pollAns3[0].firstChild.nodeValue;
		}
		if((pollAns4[0].firstChild != null))
		{
		document.getElementById("fourthAns"+pollPosition).innerHTML="<img id='image4"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result4"+pollPosition+"'></span></p>"
		document.getElementById("image4"+pollPosition).src="/community/images/poll_1.gif";

		document.getElementById("ans4"+pollPosition).textContent=pollAns4[0].firstChild.nodeValue;
		}
		if((pollAns5[0].firstChild != null))
		{
		document.getElementById("fifthAns"+pollPosition).innerHTML="<img id='image5"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result5"+pollPosition+"'></span></p>"
		document.getElementById("image5"+pollPosition).src="/community/images/poll_2.gif";

		document.getElementById("ans5"+pollPosition).textContent=pollAns5[0].firstChild.nodeValue;
		}
		if((pollAns6[0].firstChild != null))
		{
			document.getElementById("sixthAns"+pollPosition).innerHTML="<img id='image6"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result6"+pollPosition+"'></span></p>"
			document.getElementById("image6"+pollPosition).src="/community/images/poll_3.gif";
		document.getElementById("ans6"+pollPosition).textContent=pollAns6[0].firstChild.nodeValue;
		}
		if((pollAns7[0].firstChild != null))
		{
			document.getElementById("seventhAns"+pollPosition).innerHTML="<img id='image7"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result7"+pollPosition+"'></span></p>"
			document.getElementById("image7"+pollPosition).src="/community/images/poll_1.gif";
		document.getElementById("ans7"+pollPosition).textContent=pollAns7[0].firstChild.nodeValue;
		}
		if((pollAns8[0].firstChild != null))
		{
			document.getElementById("eighthAns"+pollPosition).innerHTML="<img id='image8"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result8"+pollPosition+"'></span></p>"
			document.getElementById("image8"+pollPosition).src="/community/images/poll_2.gif";

		document.getElementById("ans8"+pollPosition).textContent=pollAns8[0].firstChild.nodeValue;
		}
		if((pollAns9[0].firstChild != null))
		{
			document.getElementById("ninthAns"+pollPosition).innerHTML="<img id='image9"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result9"+pollPosition+"'></span></p>"
			document.getElementById("image9"+pollPosition).src="/community/images/poll_3.gif";
		document.getElementById("ans9"+pollPosition).textContent=pollAns9[0].firstChild.nodeValue;
		}
		if((pollAns10[0].firstChild != null))
		{
			document.getElementById("tenthAns"+pollPosition).innerHTML="<img id='image10"+pollPosition+"' height='8'>&nbsp;&nbsp;<span class='polltxt' id='result10"+pollPosition+"'></span></p>"
			document.getElementById("image10"+pollPosition).src="/community/images/poll_1.gif";

		document.getElementById("ans10"+pollPosition).textContent=pollAns10[0].firstChild.nodeValue;
		}

		}
	
		document.getElementById("image1"+pollPosition).width=pollPer1[0].firstChild.nodeValue;
		document.getElementById("image2"+pollPosition).width=pollPer2[0].firstChild.nodeValue;
		if((pollAns3[0].firstChild != null))
		{
		document.getElementById("image3"+pollPosition).width=pollPer3[0].firstChild.nodeValue;
		}
		if((pollAns4[0].firstChild != null))
		{
		document.getElementById("image4"+pollPosition).width=pollPer4[0].firstChild.nodeValue;
		}
		if((pollAns5[0].firstChild != null))
		{
		document.getElementById("image5"+pollPosition).width=pollPer5[0].firstChild.nodeValue;
		}
		if((pollAns6[0].firstChild != null))
		{
		document.getElementById("image6"+pollPosition).width=pollPer6[0].firstChild.nodeValue;
		}
		if((pollAns7[0].firstChild != null))
		{
		document.getElementById("image7"+pollPosition).width=pollPer7[0].firstChild.nodeValue;
		}
		if((pollAns8[0].firstChild != null))
		{
		document.getElementById("image8"+pollPosition).width=pollPer8[0].firstChild.nodeValue;
		}
		if((pollAns9[0].firstChild != null))
		{
		document.getElementById("image9"+pollPosition).width=pollPer9[0].firstChild.nodeValue;
		}
		if((pollAns10[0].firstChild != null))
		{
		document.getElementById("image10"+pollPosition).width=pollPer10[0].firstChild.nodeValue;
		}
		if(isIE)
		{
		document.getElementById("result1"+pollPosition).innerText=pollVal1[0].firstChild.nodeValue;
		document.getElementById("result2"+pollPosition).innerText=pollVal2[0].firstChild.nodeValue;
		if((pollAns3[0].firstChild != null))
		{
		document.getElementById("result3"+pollPosition).innerText=pollVal3[0].firstChild.nodeValue;
		}
		if((pollAns4[0].firstChild != null))
		{
		document.getElementById("result4"+pollPosition).innerText=pollVal4[0].firstChild.nodeValue;
		}
		if((pollAns5[0].firstChild != null))
		{
		document.getElementById("result5"+pollPosition).innerText=pollVal5[0].firstChild.nodeValue;
		}
		if((pollAns6[0].firstChild != null))
		{
		document.getElementById("result6"+pollPosition).innerText=pollVal6[0].firstChild.nodeValue;
		}
		if((pollAns7[0].firstChild != null))
		{
		document.getElementById("result7"+pollPosition).innerText=pollVal7[0].firstChild.nodeValue;
		}
		if((pollAns8[0].firstChild != null))
		{
		document.getElementById("result8"+pollPosition).innerText=pollVal8[0].firstChild.nodeValue;
		}
		if((pollAns9[0].firstChild != null))
		{
		document.getElementById("result9"+pollPosition).innerText=pollVal9[0].firstChild.nodeValue;
		}
		if((pollAns10[0].firstChild != null))
		{
		document.getElementById("result10"+pollPosition).innerText=pollVal10[0].firstChild.nodeValue;
       	}
	      }
		else
		{
		document.getElementById("result1"+pollPosition).textContent=pollVal1[0].firstChild.nodeValue;
		document.getElementById("result2"+pollPosition).textContent=pollVal2[0].firstChild.nodeValue;
		if((pollAns3[0].firstChild != null))
		{
		document.getElementById("result3"+pollPosition).textContent=pollVal3[0].firstChild.nodeValue;
		}
		if((pollAns4[0].firstChild != null))
		{
		document.getElementById("result4"+pollPosition).textContent=pollVal4[0].firstChild.nodeValue;
		}
		if((pollAns5[0].firstChild != null))
		{
		document.getElementById("result5"+pollPosition).textContent=pollVal5[0].firstChild.nodeValue;
		}
		if((pollAns6[0].firstChild != null))
		{
		document.getElementById("result6"+pollPosition).textContent=pollVal6[0].firstChild.nodeValue;
		}
		if((pollAns7[0].firstChild != null))
		{
		document.getElementById("result7"+pollPosition).textContent=pollVal7[0].firstChild.nodeValue;
		}
		if((pollAns8[0].firstChild != null))
		{
		document.getElementById("result8"+pollPosition).textContent=pollVal8[0].firstChild.nodeValue;
		}
		if((pollAns9[0].firstChild != null))
		{
		document.getElementById("result9"+pollPosition).textContent=pollVal9[0].firstChild.nodeValue;
		}
		if((pollAns10[0].firstChild != null))
		{
		document.getElementById("result10"+pollPosition).textContent=pollVal10[0].firstChild.nodeValue;
       	}
// Modified by Cognizant Offshore for Bug 64400 - Ends
		}		
	};	
}