var oXHR, oCaller, strUrl, retVal, blnCookieCheck, blnIsMozilla, strVoteID, strQuestionID, strQuestionText, strAnswerList, strImageList, strInputType, strDisplayResultTotal, strNumberColumns, strDisclaimer, strPreviousLink, strPromoText;
var strSecurity, strDisplayResults, strResultFormat, strResultText, strResultAltText, strCode, strURL, strTitle, blnLaunchNew, strCookieName, strNavObject, lastRequested, dbgString, strKey, strMessage, parentDiv, strVoted, tid, rTid;
var strAnsValue='';
var strCallerID=0;
var rzCount = 0;
var errCount = 0;
var CONST_RETRY_COUNT = 0;
var kExpired = false;
var clearFlag = false;
var votedFlag = false;
var isCoBrand = false;
var blnInline = false;
var vote_callbackFunc;

strNavObject = navigator;	

if(strNavObject.appName != "Microsoft Internet Explorer")
{
	blnIsMozilla = true;
}			

function gA(methodUrl, mode, callback)
{
	if(callback)
	{
		vote_callbackFunc = callback;
	}
	try
	{
        if(mode && mode == "1")
        {
            blnInline = true;
        }
		getQueryString();
		if(isCoBrand == false && blnInline == false)
		{
			var rsTop = screen.height / 6;
        	var rsLeft = screen.width / 3;	    
        	window.moveTo(rsLeft, rsTop);
		}
	}
	catch(e)
	{
	}		
	try
	{
		CONST_RETRY_COUNT = voteRetryCount;
		dbgString = ":: START ::  gA() called -";
   		lastRequested = methodUrl;
		dbgString = dbgString + "last requested url saved - " + lastRequested + " - ";
		oXHR = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			oXHR = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e1)
		{
			try
			{
				if(!oXHR && typeof XMLHttpRequest != 'undefined')
				{
					oXHR = new XMLHttpRequest();
					if (oXHR.overrideMimeType)
					{
						oXHR.overrideMimeType('text/xml');
					}
				}
			}
			catch(e2)
			{				    
				oXHR = null;
			}
		}
	}
	if(oXHR != null)				
	{		 
		dbgString = dbgString + "XML HTTP Object created - ";  
		try
		{
			oXHR.onreadystatechange = pR;
			oXHR.open("GET", methodUrl, true);
			oXHR.setRequestHeader("content-type", "application/x-www-form-urlencoded");
			dbgString = dbgString + "Requesting URL - ";  
			oXHR.send(null);
		}
		catch(err)
		{
			if(errCount<CONST_RETRY_COUNT)
	        {			 
	            errCount = errCount + 1;		
	            gA(lastRequested);
	        }
	        else
	        {
	            dbgString = dbgString + "failed when submitting request - ";   + err.description; 
	            sE("0");			
	            errCount = 0;
	        }
		}
	}
	else
	{
		dbgString = dbgString + "XML HTTP create failed - ";  
		sE("2");
	}
	return false;
}
			
function pR()
{	
	try
	{
	    if(oXHR.readyState == 4)
		{		        
			if(oXHR.status == 200 && strCallerID == 0)
			{				
			    dbgString = dbgString + "calling pV() - ";
				retVal = oXHR.responseXML.documentElement;									
				pV();
				if(vote_callbackFunc)
				{
					vote_callbackFunc();
				}
			}
			else if(oXHR.status == 200 && strCallerID == 1)
			{
			    dbgString = dbgString + "calling pVR() - ";  
				retVal = oXHR.responseXML.documentElement;	
				pVR();
				if(vote_callbackFunc)
				{
					vote_callbackFunc();
				}
			}
			else if(oXHR.status == 200 && strCallerID == 2)
			{
			    dbgString = dbgString + "calling cP() - ";  
				cP();
				if(vote_callbackFunc)
				{
					vote_callbackFunc();
				}
			}
			else
			{
			    dbgString = dbgString + "Caller ID is: " + strCallerID + ", Status code is " + oXHR.status + " - " ;  				    
				sE("0");
				if(vote_callbackFunc)
				{
					vote_callbackFunc();
				}
			}			
    	}
	}
	catch(e)
	{
	    sE("0");
	}
}	

function rZ(loopFlag)
{
	if(isCoBrand == false && blnInline == false)
	{			
		if(document.getElementById("hImage"))
		{
			var rsWidth = document.getElementById("hImage").width + 10;
		}
		else
		{
			var rsWidth = 310;
		}
		var rsHeight = document.getElementById("mDiv").offsetHeight + 100;
		try
		{	        
			window.resizeTo(rsWidth, rsHeight);
		}
		catch(e)
		{	       
		return true;
		}
		clearTimeout(rTid);
		if(rzCount<300 && loopFlag == true)
		{
			rTid = setTimeout("rZ(true)",1000);
			rzCount++;
		}
		else if(rzCount>=300 && kExpired == false && votedFlag == false)
		{
			sE("1");    	    
			kExpired = true;
		}
	}
}		
	
function pV()	
{
	try
	{			
		if(blnIsMozilla) 
		{
			var mozIdx = 1;
		}				
		else 
		{
			var mozIdx = 0;
		}
		if(retVal.childNodes.length > 0 && retVal.childNodes[mozIdx].nodeName == "VoteData" || retVal.childNodes[mozIdx].nodeName == "VoteDataQ" || retVal.childNodes[mozIdx].nodeName == "VoteDataB")
		{
			dbgString = dbgString + "XML document valid - ";  				
			strVoteID = retVal.getElementsByTagName("id")[0].firstChild.nodeValue;
			strQuestionID = retVal.getElementsByTagName("QuestionID")[0].firstChild.nodeValue;
			strQuestionText = retVal.getElementsByTagName("question_text")[0].firstChild.nodeValue;									
			strInputType = retVal.getElementsByTagName("input_type")[0].firstChild.nodeValue;
			if(retVal.getElementsByTagName("answer_list")[0].firstChild)
			{
				strAnswerList = retVal.getElementsByTagName("answer_list")[0].firstChild.nodeValue;
			}
			if(retVal.getElementsByTagName("image_list")[0].firstChild)
			{
				strImageList = retVal.getElementsByTagName("image_list")[0].firstChild.nodeValue;
			}
			strDisplayResultTotal = retVal.getElementsByTagName("display_result_total")[0].firstChild.nodeValue;
			if(retVal.getElementsByTagName("vote_disclaimer")[0].firstChild)
			{
				strDisclaimer = retVal.getElementsByTagName("vote_disclaimer")[0].firstChild.nodeValue;
			}
			if(retVal.getElementsByTagName("previous_results_link")[0].firstChild)
			{
				strPreviousLink = retVal.getElementsByTagName("previous_results_link")[0].firstChild.nodeValue;
			}
			if(retVal.getElementsByTagName("promo_text")[0].firstChild)
			{
				strPromoText = retVal.getElementsByTagName("promo_text")[0].firstChild.nodeValue;
			}
			if(retVal.getElementsByTagName("number_columns")[0].firstChild)
			{
				strNumberColumns = retVal.getElementsByTagName("number_columns")[0].firstChild.nodeValue;
			}	
			if(retVal.getElementsByTagName("security")[0].firstChild)
			{
				strSecurity = retVal.getElementsByTagName("security")[0].firstChild.nodeValue;
			}
			if(retVal.getElementsByTagName("display_results")[0].firstChild)
			{
				strDisplayResults = retVal.getElementsByTagName("display_results")[0].firstChild.nodeValue;
			}
			if(retVal.getElementsByTagName("result_format")[0].firstChild)
			{
				strResultFormat = retVal.getElementsByTagName("result_format")[0].firstChild.nodeValue;
			}
			if(retVal.getElementsByTagName("result_alt_text")[0].firstChild)
			{
				strResultAltText = retVal.getElementsByTagName("result_alt_text")[0].firstChild.nodeValue;
			}			
			dbgString = dbgString + "Checking cookie - ";  
			strCookieName = "vt_" + strQuestionID;	
			cCK();					
            
            if(blnInline == false)
            {
			    dbgString = dbgString + "Show question - ";  
			    sQ();
			}
			if(blnInline == false)
			{
			    if (blnCookieCheck == false)
			    {
				    dbgString = dbgString + "Cookie check false - ";  
				    if(strInputType == 1)
				    {
					    dbgString = dbgString + "Creating radio buttons - ";  
					    cRB();
					    dbgString = dbgString + "Show related links - ";  
					    sRL();
					    dbgString = dbgString + "Show other links - ";  
					    sOL();
				    }
				    if(strInputType == 2 || strInputType == 3)
				    {
					    dbgString = dbgString + "Creating image buttons - ";  
					    cIBC();
				    }					
				    if(strInputType == 4)
				    {
					    dbgString = dbgString + "Creating image + radio combo buttons - ";  
					    cIRBC();
				    }
				    dbgString = dbgString + "Extract security key - ";  
			        eK();
			    }
			}
			else 
			{
			    if(blnCookieCheck == false)
			    { 
			        dbgString = dbgString + "Extract security key - ";  
			        eK();
			        sInline();
			    }
			}
			
			if(blnInline == false)
			{
			    if(jsVoteBGImage!='' && jsVoteBGImage!='none')
			    {
				    document.body.style.backgroundImage = "url('" + jsVoteBGImage + "')";
			    }				
			    document.body.style.backgroundColor = jsVoteColorBG;				
            }
            
            if(blnInline == false)
            {			
			    if(blnCookieCheck == true)						
			    {		
				    dbgString = dbgString + "Cookie check true - "; 
				    votedFlag = true; 
				    sRe();
				    sRL();
				    sOL();
			    }					
			    dbgString = dbgString + "Show AD - ";  
			    sAd();				
			    dbgString = dbgString + "After Show AD - ";  
			    rTid = 0;				
			    rTid = setTimeout("rZ(true)",1000);
			    dbgString = dbgString + ":: END::  ";  
			}
			else if(blnInline == true)
			{
			    if(blnCookieCheck == true)
			    {			    
			        strResultText = "";
			        sRe();
			    }
			}
		}
		else
		{
			dbgString = dbgString + "0 / invalid nodes - pV() - " + retVal.childNodes.length + " nodes - "; 
			sE("0");
		}					
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in pV() - " + e.description + " - ";
		sE("0");
	}
}		

function cIBC()
{
	try
	{
		dbgString = dbgString + "Within cIBC() - ";  					
		var arrImgValues = new Array();
		arrImgValues = strImageList.split(";");
		var iLoop;
		var arrAnsValues = new Array();
		if(strAnswerList)
		{
			arrAnsValues = strAnswerList.split(";");
		}
		strHTML = "<table width=90% cellpadding='10px'><tr>";
		var cCount=0;
		var oDiv = document.getElementById("c1");							 
		oDiv.style.paddingLeft = "10px";
		oDiv.style.paddingRight = "24px";
		oDiv.style.paddingTop = "10px";		
		for(iLoop = 0; iLoop < arrImgValues.length; iLoop++)
		{														
			if(strInputType == 3)
			{
				var iStr = "<img src=" + arrImgValues[iLoop] + "> <INPUT id="+"rd" + "_" + iLoop + "_" + strQuestionID +" name=radio style=CURSOR:hand tabIndex=0 type=radio value='" + escape(arrAnsValues[iLoop]) + "' onclick='pA(this.value, this.id)'>";
				if(strNumberColumns > 1)
				{	
					if(cCount==2)
					{
						strHTML = strHTML + "</tr><tr><td width='125px'>" + iStr + arrAnsValues[iLoop] + "</td>";
						cCount=1;
					}
					else
					{
						cCount++;
						strHTML = strHTML + "<td width='125px'>" + iStr + arrAnsValues[iLoop] + "</td>";
					}
				}
				else
				{
					if(iLoop == 0)
					{
						strHTML= strHTML + "<td width='125px'>" + iStr + arrAnsValues[iLoop] + "</td></tr>";							
					}
					else
					{
						strHTML= strHTML + "<tr><td width='125px'>" + iStr + arrAnsValues[iLoop] + "</td></tr>";							
					}
				}
			}
			else
			{						
				var iStr = "<img id="+"rd" + "_" + iLoop + "_" + strQuestionID +" style=CURSOR:hand tabIndex=0 src=" + arrImgValues[iLoop] + " onclick='pA(this.src, this.id)'>";
				if(strNumberColumns > 1)
				{	
					if(cCount==2)
					{
						strHTML = strHTML + "</tr><tr><td>" + iStr + "</td>";
						cCount=1;
					}
					else
					{
						cCount++;
						strHTML = strHTML + "<td>" + iStr + "</td>";
					}
				}
				else
				{
					if(iLoop == 0)
					{
						strHTML= strHTML + "<td>" + iStr + "</td></tr>";
					}
					else
					{
						strHTML= strHTML + "<tr><td style=padding-top:'10px'>" + iStr + "</td></tr>";
					}
				}					
			}
		}		
		if(strInputType == 3)
		{
			strHTML = strHTML + "</tr></table>";
		}
		else
		{
			strHTML = strHTML + "</table>";
		}
		oDiv.style.paddingBottom = "15px";
		oDiv.innerHTML = strHTML;
		
		if(strInputType == 3)
		{
			cSB();
		}
		sRL();
		sOL();			
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in cIBC() - " + e.description + " - ";  
	}
}		
	
function cSB()
{
	try
	{
		dbgString = dbgString + "Within cSB() - ";
		if(jsSubmitImg != '' && jsSubmitImg != 'none')
		{
			document.getElementById("parentDiv").innerHTML = document.getElementById("parentDiv").innerHTML + "<img id='imgSubmit' src='" + jsSubmitImg +"' style=cursor:hand;margin:8px;margin-left:24px;margin-right:0px onclick='pVA()'>"
		}
		else
		{
			document.getElementById("parentDiv").innerHTML = document.getElementById("parentDiv").innerHTML + "<INPUT TYPE=button ID=btnSubmit VALUE='Submit' onclick='pVA()' style=cursor:hand;margin:8px;margin-left:24px;margin-right:0px>"
		}
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in cSB() - " + e.description + " - ";  
	}		
}

function cIRBC()
{
	try
	{
		dbgString = dbgString + "Within cIRBC() - ";
		
		var objSpacer = document.getElementById("c2");					
		var strHTML;

		objSpacer.style.paddingLeft = "24px";
		objSpacer.style.paddingRight = "24px";
		objSpacer.style.paddingTop = "24px";
		
		strHTML = "<img src=" + strImageList + ">";
		document.getElementById("c2").innerHTML = strHTML;
		
		cRB();					
		sRL();
		sOL();			
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in cIRBC() - " + e.description + " - ";  
	}

}			

function cRB()
{		
	try
	{
		dbgString = dbgString + "Within cRB() - ";
		var arrAnsValues = new Array();
		var arrImgValues = new Array();
		if(strAnswerList)
		{
			arrAnsValues = strAnswerList.split(";");
		}
		if(strImageList)
		{
			arrImgValues = strImageList.split(";");
		}		
		strHTML = "<table width=90% cellpadding='10px' ><tr>";
		var cCount;
		var oDiv = document.getElementById("c3");							 
		oDiv.style.padding = "24px";
		oDiv.style.paddingTop = "10px";
		var iLoop;				
		if (!strImageList || (strImageList != '' && strInputType == 4))
		{		
			cCount=0;			
			for(iLoop = 0; iLoop < arrAnsValues.length; iLoop++)
			{
				var iStr = "<INPUT id="+"rd" + "_" + iLoop + "_" + strQuestionID +" name=radio style='CURSOR: hand' tabIndex=0 type=radio value='" + escape(arrAnsValues[iLoop]) + "' onclick='pA(this.value, this.id)'>";
				if(strNumberColumns > 1)
				{	
					if(cCount==2)					
					{
						strHTML = strHTML + "</tr><tr><td>" + iStr + arrAnsValues[iLoop] + "</td>";
						cCount=1;
					}
					else
					{
						cCount++;
						strHTML = strHTML + "<td>" + iStr + arrAnsValues[iLoop] + "</td>";
					}					
				}
				else
				{					
					if(iLoop == 0)
					{
						strHTML= strHTML + "<td>" + iStr + arrAnsValues[iLoop] + "</td></tr>";							
					}
					else
					{
						strHTML= strHTML + "<tr><td>" + iStr + arrAnsValues[iLoop] + "</td></tr>";							
					}
				}
			}
		}
		else
		{	
			cCount=0;
			for(iLoop  = 0; iLoop < arrAnsValues.length; iLoop++)
			{
				var iStr = "<img src=" + arrImgValues[iLoop] + "> <INPUT id="+"rd" + "_" + iLoop + "_" + strQuestionID +" name=radio style='CURSOR: hand' tabIndex=0 type=radio value='" + escape(arrAnsValues[iLoop]) + "' onclick='pA(this.value, this.id)'>";
				if(strNumberColumns > 1)
				{	
					if(cCount==2)
					{
						strHTML = strHTML + "</tr><tr><td width='125px'>" + iStr + "</td>";
						cCount=1;
					}
					else
					{
						cCount++;
						strHTML = strHTML + "<td width='125px'>" + iStr + "</td>";
					}
				}
				else
				{
					if(iLoop == 0)
					{
						strHTML = strHTML + "<td width='125px'>" + iStr + "</td></tr>";							
					}
					else
					{
						strHTML = strHTML + "<tr><td style=padding-top:'10px' width='125px'>" + iStr + "</td></tr>";
					}
				}
			}
		}				
		if(strNumberColumns > 1)
		{
			strHTML = strHTML + "</tr></table>";
		}
		else
		{
			strHTML = strHTML + "</table>";
		}
		oDiv.innerHTML=strHTML;
		oDiv.style.paddingBottom = "15px";
		cSB();					
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in cRB() - " + e.description + " - ";  
	}
}		

function sQ()	
{		
	try
	{			
		dbgString = dbgString + "Within sQ() - ";
		if(!isCoBrand)
		{
			document.getElementById("qDiv").innerHTML = "<img id=hImage src=" + jsVoteHImage + " STYLE=valign:top; position:absolute; left:0; top:0><br><div id='qTextDiv' STYLE=padding-left:10px;padding-right=10px;padding-top:10px;width:280px;font-color:" + jsVoteQColor +">" + strQuestionText + "</div>";
		}
		else
		{
			document.getElementById("qDiv").innerHTML = "<div id='qTextDiv' STYLE=padding-left:10px;padding-right=10px;padding-top:10px;width:280px;font-color:" + jsVoteQColor +">" + strQuestionText + "</div>";
		}	
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in sQ() - " + e.description + " - ";  
	}
}		
	
function sRL()
{
	try
	{	
		dbgString = dbgString + "Within sRL() - ";						
		if(blnIsMozilla) 
		{
			var mozIdx = 3;
		}				
		else 
		{
			var mozIdx = 1
		}
		
		if (retVal.childNodes.length > 1 && retVal.childNodes[mozIdx].nodeName != "TblEncrypt" && retVal.childNodes[mozIdx].nodeName != "TblSettings")
		{			
			var iLoop = 0;
			var intLinks = 0;
			for(iLoop = 0; iLoop < retVal.childNodes.length; iLoop++)
			{
				if(retVal.childNodes[iLoop].nodeName == "VoteData1" || retVal.childNodes[iLoop].nodeName == "VoteDataQ1")
				{
					intLinks++;
				}
			}			
			
			var oDiv1 = document.getElementById("oDivRelatedLinksData");
			oDiv1.style.marginLeft = "8px";
			oDiv1.style.paddingLeft = "8px";	
			oDiv1.style.paddingTop = "8px";	
			oDiv1.style.width = "260px";	 
			strCode="<table id=relatedLinkstable class=vote_rellink_table><tr><th class=vote_rellink_header> RELATED LINKS </th></tr><tr><td><ul>";
			for(iLoop = 0; iLoop < intLinks; iLoop++)
			{ 
				if(retVal.getElementsByTagName("ID")[iLoop].firstChild)
				{					
					strTitle = retVal.getElementsByTagName("TITLE")[iLoop].firstChild.nodeValue;
					strURL = retVal.getElementsByTagName("URL")[iLoop].firstChild.nodeValue;					
					if(retVal.getElementsByTagName("LAUNCH_NEW")[iLoop].firstChild.nodeValue == "true")
					{
						blnLaunchNew = true;
					}
					else
					{
						blnLaunchNew = false;
					}
					strCode = strCode + "<li><a ";				
					if(blnLaunchNew)
					{
						strCode = strCode+ "target='new' href=" + strURL + ">" + strTitle + "</a></li>";
					}
					else
					{
						strCode = strCode+ "href='#' onClick='lC(\"" + strURL + "\")'>" + strTitle + "</a></li>";
					}
				}						
			}
			strCode = strCode + "</ul></td></tr></table>";
			oDiv1.innerHTML=strCode;
		}
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in sRL() - " + e.description + " - ";  
	}
}		
	
function sOL()
{
	try
	{
		dbgString = dbgString + "Within sOL() - ";
		
		var oDiv = document.getElementById("oDivOtherLinks");
		oDiv.style.height = "25px";
		oDiv.style.width = "325px";
		var stHTML;
		stHTML = "<br><table border='0' align='left' width='100%' id='table1'><tr><td valign='center' align='left'>";
		if(strDisclaimer && strDisclaimer != '')
		{		
			stHTML = stHTML + "<a href='#' id='disclaimerLink' STYLE=padding-top:10px;padding-left:10px;font-family:Verdana,Arial,Helvetica;color:#666666;text-decoration:underline;font-weight:normal;font-size:9px onclick='sD()'> Disclaimer -> </a>";			
		}
		stHTML = stHTML + "</td><td valign='center' align='right'>";
		if(strPreviousLink && strPreviousLink != '')
		{
			stHTML = stHTML + "<a href='#' STYLE=padding-top:10px;padding-right:45px;font-family:Verdana,Arial,Helvetica;color:#666666;text-decoration:underline;font-weight:normal;font-size:9px onClick='lC(strPreviousLink)'> Previous results </a>";
		}
		stHTML = stHTML +  "</td></tr></table><br></div>";
		oDiv.innerHTML=stHTML;
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in sOL() - " + e.description + " - ";  
	}
}

function pA(ansParam, objectID)
{
	try
	{
		dbgString = dbgString + "Within pA() - ";
		strAnsValue = unescape(ansParam);
		if(strInputType == 2)					
		{
			strPos=strAnsValue.lastIndexOf("/img");
			if(strPos != -1)
			{
				strAnsValue=strAnsValue.substring(strPos);
			}		
			pVA();
		}
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in pA() - " + e.description + " - ";  
	}
}	
		
function pVA()				
{
	try
	{	        
	    dbgString = dbgString + "Within pVA() - ";
		if(strAnsValue != '')
		{
		    if(blnInline == false)
		    {
			    var wDiv = document.getElementById("wDiv");
			    var hCalc = document.getElementById("mDiv").offsetHeight + 100;
			    if(!isCoBrand)
			    {
				    var hWidth = document.getElementById("hImage").width + 5;
			    }
			    wDiv.innerHTML = "<img src='/share/img/al1.gif' style=margin-top:5px;margin-left:5px> Working on your request...";									
			    wDiv.style.position="absolute";
			    wDiv.style.backgroundColor = "Lightyellow";
			    wDiv.style.height="30px";
			    wDiv.style.top= hCalc - 115;			
			    wDiv.style.left= 0;
			    wDiv.style.visibility="visible";
			    wDiv.style.borderStyle = "solid";
			    wDiv.style.borderWidth = "1px";	
			    wDiv.style.paddingTop = "2px";		
			    wDiv.style.paddingLeft = "4px";		
			    wDiv.style.paddingRight = "4px";		
			    wDiv.style.paddingBottom = "8px";					
			}
			strUrl = "/share/ws/vote/getVoteData.asmx/processVoteAns?q=" + strQuestionID +"&a=" + strAnsValue+ "&k=" +strKey +"&m=" + strMessage;
			strCallerID = 1;			
			gA(strUrl);			
			if(strSecurity == "2")
			{	
				sCK(strCookieName,strAnsValue,7);									
			}
			votedFlag = true;						
		}
	}
	catch(e)
	{
		if(errCount<CONST_RETRY_COUNT)
		{			 
			errCount = errCount + 1;		
			pVA();
		}
		else
		{
			dbgString = dbgString + "Could not post voted option to the server: processVoteAns - pVA() " + e.description; 
			sE("0");			
			errCount = 0;
		}
	} 
}		

function sD()			
{
	try
	{
		dbgString = dbgString + "Within sD() - ";
		if(strDisclaimer && strDisclaimer != '')
		{
			var oDek = document.getElementById("dek");
			oDek.style.position = "absolute";
			oDek.style.width = "200";
			oDek.style.padding = "4px";
			oDek.style.border = "1px";
			oDek.style.backgroundColor = "#e7ecf7";
			var skn = document.getElementById("dek").style;
			var tid = 0;		
			skn.left = 83;
			skn.top = document.all.oDivOtherLinks.offsetTop + 22;
			skn.borderStyle = "solid";
			skn.borderWidth = "1px";
			var content = strDisclaimer + "<div align=right><a href='javascript:k()'>close</a> X</div>";
			document.getElementById("dek").innerHTML = content;
			skn.visibility = 'visible';
			tid = setTimeout("k()",5000);
		}
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in sD() - " + e.description + " - ";  
	}
}
	
function k()
{
	try
	{
		dbgString = dbgString + "Within k() - ";
		document.getElementById("dek").style.visibility = "hidden";
		clearTimeout(tid);
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in k() - " + e.description + " - ";  
	}
}		

function sCK(name,value,days)
{
	try
	{
		dbgString = dbgString + "Within sCK() - ";			
		if (days)
		{
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires=" + date.toGMTString();
		}
		else
		{ 
			var expires = "";
		}
		document.cookie = name + "=" + escape(value) + expires + "; path=/";
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in sCK() - " + e.description + " - ";  
	}
}

function cCK()
{
	try
	{
		dbgString = dbgString + "Within cCK() - ";
		var nameEQ = "vt_" + strQuestionID + "=";
		var ca = document.cookie.split(';');
		for(var i=0; i < ca.length; i++)
		{
			var c = ca[i];
			while (c.charAt(0) == ' ')
			{
				c = c.substring(1, c.length);										
			}
			if(c.indexOf(nameEQ) == 0)
			{
				blnCookieCheck = true;
				strVoted = unescape(c.substring(nameEQ.length,c.length));
				break;
			}
			else
			{
				blnCookieCheck = false;
			}
		}				
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in cCK() - " + e.description + " - ";  
	}
}	

function eK()
{		
	try
	{
		dbgString = dbgString + "Within eK() - ";			
		if(retVal.childNodes.length > 0)
		{
			strKey = retVal.getElementsByTagName("key")[0].firstChild.nodeValue;
			strMessage = retVal.getElementsByTagName("Msg")[0].firstChild.nodeValue;
		}
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in eK() - " + e.description + " - ";  
	}
}			

function pVR()
{	
	dbgString = dbgString + "Within pVR() - ";	
	try
	{				
	    strResultText = "<div id='qOptions' class=qoptions>";
		if(document.getElementById("wDiv")){
			document.getElementById("wDiv").style.visibility="hidden";
		}
		document.removeChildNodes = function(node) {while (node.childNodes.length>0) {node.removeChild(node.childNodes[0]);}}
		document.removeChildNodes(document.getElementById("oAdDiv"));
		document.removeChildNodes(document.getElementById("qtext"));
		if(blnInline == false)
		{
    		sAd();
    	}
		if (retVal.childNodes.length > 0)
		{	
			if(blnIsMozilla)
			{
				var mozIdx = 3;
			}				
			else
			{
				var mozIdx = 1; 
			}
			document.removeChildNodes = function(node) {while (node.childNodes.length > 0) {node.removeChild(node.childNodes[0]);}}
			document.removeChildNodes(document.getElementById("parentDiv")); 
			document.getElementById("qDiv").style.visibility = "visible";
			document.getElementById("altDiv").style.visibility = "visible";					
			var iLoop;
			var cCount;
			var strAnsString = "<table><tr>";
			var ansDiv = document.getElementById("ansDiv");
			ansDiv.style.padding = "24px";
			ansDiv.style.paddingTop = "15px";
			ansDiv.style.paddingBottom = "2px";				
			if(strDisplayResults != "1")
			{
				document.getElementById("ansDiv").style.fontWeight = "bold";
				document.getElementById("ansDiv").innerHTML = strResultAltText;
			}
			else if(strDisplayResults == "1")
			{				
				var intLinks = 0;
				for(iLoop=0; iLoop < retVal.childNodes.length; iLoop++)
				{
					if(retVal.childNodes[iLoop].nodeName == "VCount")
					{
						intLinks++;
					}
				}			
				cCount=0; 
				for(iLoop = 0; iLoop < intLinks; iLoop++)
				{								
					var strAns = retVal.getElementsByTagName("ANS_VALUE")[iLoop].firstChild.nodeValue;
					var strAnsCounter = retVal.getElementsByTagName("COUNTER")[iLoop].firstChild.nodeValue;
					var strTotalVote = retVal.getElementsByTagName("TOTAL_VOTE")[iLoop].firstChild.nodeValue;
					if(retVal.getElementsByTagName("AVG_SCORE")[iLoop].firstChild)
					{
						var strAvgScore = retVal.getElementsByTagName("AVG_SCORE")[iLoop].firstChild.nodeValue;
					}
					var strWidth = retVal.getElementsByTagName("WIDTH")[iLoop].firstChild.nodeValue;
					if(parseInt(strTotalVote) <= 0)
					{
						strTotalVote = "1";
						strAvgScore = "1";
						if(strAnsValue == strAns)
						{
							strWidth = "50";
							if(strResultFormat && (strResultFormat == "1" || strResultFormat == "4" || strResultFormat == "5"))
							{
								strAnsCounter = "100%";
							}
							else if(strResultFormat && strResultFormat == "3")
							{
								strAnsCounter = "100% [1]";
							}
							else
							{
								strAnsCounter = "1";	
							}
						} 
					}
					if(blnInline == false)
				    {
					    if(strInputType == 2 || strInputType == 3)
					    {							
						    if(strNumberColumns > 1)
						    {
							    var iStr = "<DIV id=ansValue STYLE=padding-bottom:8px;font-weight:bold><img src=" + strAns + "> </DIV><table><tr><td id=td" + "_" + iLoop +" STYLE=background-color:" + jsVoteResultColor + ";height:20px;width:"+strWidth +"></td><td valign='middle'>" +strAnsCounter +"</td></tr></table>";
							    if(cCount==2)
							    {
								    strAnsString = strAnsString+ "</tr><tr><td width='125px' style=padding-bottom:'8px'>" + iStr + "</td>";
								    cCount=1;
							    }
							    else
							    {
								    cCount++;
								    strAnsString = strAnsString + "<td width='125px' style=padding-bottom:'8px'>" + iStr + "</td>";
							    }
						    }
						    else
						    {
							    var iStr = "<DIV id=ansValue STYLE=padding-bottom:8px;font-weight:bold;width:250><img src=" + strAns + "> </DIV><table><tr><td id=td" + "_" + iLoop +" STYLE=background-color:" + jsVoteResultColor + ";height:20px;width:"+strWidth +"></td><td valign='middle'>" +strAnsCounter +"</td></tr></table>";
							    if(iLoop == 0)
							    {
								    strAnsString = strAnsString+ "<td width='125px' style=padding-bottom:'8px'>" + iStr + "</td></tr>";
							    }
							    else
							    {
								    strAnsString = strAnsString+ "<tr><td width='125px' style=padding-bottom:'8px'>" + iStr + "</td></tr>";							
							    }
						    }
					    }
					    else
					    {							
						    if(strNumberColumns > 1)
						    {	
							    var iStr = "<DIV id=ansValue STYLE=padding-bottom:8px;font-weight:bold>" + strAns +"</DIV><table><tr><td id=td" + "_" + iLoop +" STYLE=background-color:" + jsVoteResultColor + ";height:20px;width:"+strWidth +"></td><td valign='middle'>" +strAnsCounter +"</td></tr></table>";
							    if(cCount==2)
							    {
								    strAnsString = strAnsString+ "</tr><tr><td width='125px' style=padding-bottom:'8px'>" + iStr + "</td>";
								    cCount=1;
							    }
							    else
							    {
								    cCount++;
								    strAnsString = strAnsString + "<td width='125px' style=padding-bottom:'8px'>" + iStr + "</td>";
							    }
						    }
						    else
						    {
							    var iStr = "<DIV id=ansValue STYLE=padding-bottom:8px;font-weight:bold;width:250>" + strAns +"</DIV><table><tr><td id=td" + "_" + iLoop +" STYLE=background-color:" + jsVoteResultColor + ";height:20px;width:"+strWidth +"></td><td valign='middle'>" +strAnsCounter +"</td></tr></table>";
							    if(iLoop == 0)
							    {
								    strAnsString = strAnsString + "<td width='125px' style=padding-bottom:'8px'>" + iStr + "</td></tr>";							
							    }
							    else
							    {
								    strAnsString = strAnsString + "<tr><td width='125px' style=padding-bottom:'8px'>" + iStr + "</td></tr>";
							    }
						    }
					    }		
					}
					else if(blnInline == true)
					{
					     sInlineResults(strAns, strAnsCounter, strTotalVote, strWidth, strAvgScore,'', iLoop, intLinks);
					}
				}
				if(blnInline == false)
				{				
				    if(strNumberColumns > 1) 
				    {
					    strAnsString = strAnsString + "</tr></table>";
				    }
				    else
				    {
					    strAnsString = strAnsString + "</table>";				
				    }							
				    ansDiv.innerHTML = strAnsString;
				    if(strDisplayResultTotal && strDisplayResultTotal == 1)
				    {
					    ansDiv.innerHTML = strAnsString + "<br> <b>Total Votes: " + strTotalVote +"<br>";
				    }
				    if(strDisplayResultTotal && strDisplayResultTotal == 2)
				    {
					    ansDiv.innerHTML = strAnsString + "<br> <b>Total Votes: " + strTotalVote + "<br> <b> Average score: " + strAvgScore;
				    }
				    if(strDisplayResultTotal && strDisplayResultTotal == 3)
				    {
					    if(!blnCookieCheck)
					    {
						    if(strInputType == "2")
						    {
							    ansDiv.innerHTML = strAnsString + "<br> <b> Your vote: <img src='" + strAnsValue + "'> <br> <b>Total Votes: " + strTotalVote + "<br> <b> Average score: " + strAvgScore;
						    }
						    else
						    {
							    ansDiv.innerHTML = strAnsString + "<br> <b> Your vote: " + strAnsValue + "<br> <b>Total Votes: " + strTotalVote + "<br> <b> Average score: " + strAvgScore;
						    }
					    }
					    else
					    {
						    if(strInputType == "2")
						    {
							    ansDiv.innerHTML = strAnsString + "<br> <b> Your vote: <img src='" + strVoted + "'> <br> <b>Total Votes: " + strTotalVote + "<br> <b> Average score: " + strAvgScore;
						    }
						    else
						    {
							    ansDiv.innerHTML = strAnsString + "<br> <b> Your vote: " + strVoted + "<br> <b>Total Votes: " + strTotalVote + "<br> <b> Average score: " + strAvgScore;
						    }
					    }
				    }
				    if(strSecurity=="1")
				    {
					    ansDiv.innerHTML = strAnsString + "<br> <a href='#' STYLE=padding-top:10px;font-family:Verdana,Arial,Helvetica;color:#666666;text-decoration:underline;font-weight:normal;font-size:9px onclick='rl();'> Vote again </a>";
				    }
				    rTid = 0;
    			    rTid = setTimeout("rZ(true)",1000);				
			    }
			    else if(blnInline == true)
			    {
			        setInlineQuestion();
			    }				
    		}		
		}
		strResultText = strResultText + "</div>";
		var vContainer = document.getElementById("voteContainer");
		if(vContainer)
		{
			vContainer.style.display = 'block';
		}	
	}
	catch(e)
	{
		if(errCount<CONST_RETRY_COUNT)
		{
			errCount = errCount + 1;
			pVR();			    			
		}
		else
		{
			dbgString = dbgString + "Web service returned XMLDcocument with 0 nodes / invalid nodes: processVoteResults: PVR(): " + e.description; 
			sE("0");			
			errCount = 0;
		}			
	}
}	
		
function sRe()		
{
	try
	{
	    dbgString = dbgString + "Within sRE() - ";			
		strUrl = "/share/ws/vote/getVoteData.asmx/showResults?q=" + strQuestionID;
		strCallerID = 1;
		gA(strUrl);					
	}
	catch(e)
	{
		if(errCount<CONST_RETRY_COUNT)
		{
			errCount = errCount + 1;
			sRe();			    
		}
		else
		{
			dbgString = dbgString + "Could not submit request to fetch vote results: ShowResults: sRe(): " + e.description; 
			sE("0");			
			errCount = 0;
		}			
	}
}			

function sE(flag)
{
	try
	{
	    if(blnInline == false)
	    {	
		    var oErr = document.getElementById("oErr");
		    oErr.style.fontWeight = "bold";
		    oErr.style.color = "Blue";
		    oErr.style.fontSize = "8pt";
		    oErr.style.padding = "24px";
		    if(flag && flag=="0")
		    {
			    oErr.innerHTML = "Sorry!  There was a problem while processing your request for this vote. <br><br><div STYLE=padding-top:10px;font-family:Verdana,Arial,Helvetica;color:black;font-weight:normal;font-size:11px><ul><li> To try again please <a href='#' onclick='window.location.reload()'>click here </a></li></ul></div>";
		    }
		    else if(flag && flag=="1")
		    {
			    oErr.innerHTML = "Sorry!  Your voting session has timed out. <br><br><div STYLE=padding-top:10px;font-family:Verdana,Arial,Helvetica;color:black;font-weight:normal;font-size:11px><ul><li> To try again please <a href='#' onclick='window.location.reload()'>click here </a></li></ul></div>";
		    }   
		    else if(flag && flag=="2")
		    {
			    oErr.innerHTML = "Sorry!  Your browser does not support this functionality. <br><br><div STYLE=padding-top:10px;font-family:Verdana,Arial,Helvetica;color:black;font-weight:normal;font-size:11px><ul><li> To try again please <a href='#' onclick='window.location.reload()'>click here </a></li></ul></div>";
		    }   

		    if(document.getElementById("wDiv"))
		    {
				    document.getElementById("wDiv").style.visibility="hidden";
		    }
    		
		    document.removeChildNodes = function(node) {while (node.childNodes.length>0) {node.removeChild(node.childNodes[0]);}}
    		
		    if(document.getElementById("qTextDiv"))
		    {
			    document.getElementById("qTextDiv").innerHTML = '';			
		    }
		    if(document.getElementById("wDiv"))
		    {
			    document.removeChildNodes(document.getElementById("wDiv"));
		    } 
    		
		    if(document.getElementById("parentDiv"))
		    {
			    document.removeChildNodes(document.getElementById("parentDiv"));
		    }
  		
	        rTid = 0;
	        rTid = setTimeout("rZ(false)",1000);
		}
		if(blnDebug == true && flag != "1")
	    {
		    pE(false)
	    }
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in sE() - " + e.description + " - ";  
	}		
}	

function cP()
{	
	try
	{	
		if(clearFlag == true)
		{
			document.getElementById("oErr").innerHTML="This incident has now been reported." ;		    
		}
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in cP() - " + e.description + " - ";  
	}
}

function pE(flag)
{
	try
	{
		strUrl="/share/ws/vote/getVoteData.asmx/postError?c=" + dbgString;
		strCallerID=2;
		clearFlag = flag;
		gA(strUrl);		
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in pE() - " + e.description + " - ";  
	}
}	

function rl()
{
	try
	{
		dbgString = dbgString + "Within rL() - ";
		window.location.reload()
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in rl() - " + e.description + " - ";  
	}
}

function sAd()
{
	try
	{
		if(!isCoBrand)
		{
			dbgString = dbgString + "Within sAd() - ";
			if(strPromoText && strPromoText.length > 0 && strPromoText != '&nbsp;')
			{
				var oa = document.getElementById("oPromoDiv");
				oa.style.padding = "10px";
				oa.innerHTML = strPromoText;		
			}
			else
			{	
				jsVoteAd = jsVoteAd + "/METHOD=IFRAME/FRAMESIZE=234X60";
				var oAd = spac_returnAd(jsVoteAd);
				var oa = document.getElementById("oAdDiv");
				oa.style.paddingTop = "10px";
				oa.innerHTML = "<table width='100%' border='0'><tr><td align='center'>" + oAd + "</td></tr></table>";		
			}
		}
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in sAD() - " + e.description + " - ";  
	}
}

function lC(surl)
{
	try
	{
		dbgString = dbgString + "Within lC() - ";
		window.opener.location = surl;
		window.close();
	}
	catch(e)
	{
		dbgString = dbgString + "Exception in lC() - " + e.description + " - ";  
	}
}


function getQueryString()
{
	var query = window.location.search.substring(1); 
	var vars = query.split('&'); 
	for (var i=0;i<vars.length;i++) 
	{
		var pair = vars[i].split('='); 
		if (pair[0] == 'vportal')
		{ 
			isCoBrand = true;			
		} 		
	}
}

function sInline()
{
    var qText = document.getElementById("qtext");
    var vContainer = document.getElementById("voteContainer");
    if(vContainer)
    {
		vContainer.style.display = 'block';
	}	
	var arrImgValues = new Array();
	var arrAnsValues = new Array();
	if(strImageList)
	{
		arrImgValues = strImageList.split(";");
	}
	if(strAnswerList)
	{
		arrAnsValues = strAnswerList.split(";");
	}
	
	var iLoop;
	var strHTML ="<div id='qOptions' class='qOptions'>";
	if(strAnswerList)
	{
		for(iLoop = 0; iLoop < arrAnsValues.length; iLoop++)
		{														
			var iStr = "<div class='qRadio'><input type='radio' id='rd" + "_" + iLoop + "_" + strQuestionID +"' name='rbvote' tabIndex='0' value='" + arrAnsValues[iLoop] + "' onclick='pA(this.value, this.id)'/>" + arrAnsValues[iLoop] + "</div>";
			strHTML= strHTML + iStr;
		}
		strHTML = strHTML + "<div class='votebtn'><a href='javascript:void()' onclick='pVA()' id='VOTENOW' />VOTE NOW</a></div>" 
	}
	else
	{
		for(iLoop = 0; iLoop < arrImgValues.length; iLoop++)
		{														
			var iStr = "<div class='q" + iLoop +"'><img id="+"rd" + "_" + iLoop + "_" + strQuestionID +" tabIndex=0 src=" + arrImgValues[iLoop] + " onclick='pA(this.src, this.id)'></div>";
			strHTML= strHTML + iStr;
		}
	}

	strHTML = strHTML + "</div>";

    if (JS_TRACK_SWITCH) { 
        if (JS_TRACK_SWITCH.toLowerCase() == "on" && JS_SITEID == '282') { 
            var urlStart = strQuestionText.indexOf("href=");

            if (urlStart && urlStart != -1) {
                var txtStart = strQuestionText.substring(0, urlStart);
                var txtEnd = strQuestionText.substring(urlStart, strQuestionText.length);

                strQuestionText = txtStart + 'onclick="AdTrack.t(this,\'HL_NH_VOTE\',\'1\')"' + txtEnd;
            } 
        }
    }
	
    qText.innerHTML = "<div class=qquestion >" + strQuestionText + "</div>" + strHTML;
}

function setInlineQuestion()
{
    var qText = document.getElementById("qtext");    
    qText.innerHTML = "<div class=qquestion >" + strQuestionText + "</div>" + strResultText;
}

function sInlineResults(ans, counter, total, width, avgscore, misc, cnt, answercnt)
{	   	
	if(strAnswerList)
	{    
		strResultText = strResultText + "<div class='q" + cnt + "  answerblock'><div class='qanswer'>" + ans + "</div>";
		strResultText = strResultText + "<div class='qbar'><span class='bar' style='width:" + width + "px;'></span>";
		strResultText = strResultText + "<span class='qval'>" + counter + "</span></div></div>";
		if((answercnt-1) == cnt)  //  add total to end of html string
			strResultText = strResultText + "<div class='qtotal'>Total Votes: " + total + "</div>";
	}
	else
	{
		if(JS_VOTE_SRV_URL && JS_VOTE_SRV_URL == '1')
		{
			var _ans = ans.split(".");
			ans = _ans[0] + "_s." + _ans[1];
		} 
		strResultText = strResultText + "<div class='q" + cnt + "'><div class='q" + cnt + "img'><img src=" + ans + "></div>";
		strResultText = strResultText + "<div class='q" + cnt + "bar'><span style=width:" + width + "px;background-color:" +  jsVoteResultColor + "></span></div>";
		strResultText = strResultText + "<span class='q" + cnt + "val'>" + counter + "</span></div>";
	}     
}