var civ_email = '';
var randomID = 'VBeJLEHm6z9rNDGU10jYBxB0a3';
function addScript(url){
  var obj=new JSONscriptRequest(url);      
  obj.buildScriptTag();
  obj.addScriptTag();
}
function survey(qorder, question_id, onclick){
	var button = document.getElementById("button_HrGaNH8SYQ");
	if(question_id === undefined)
      var req  = 'http://www.civicscience.com/widget/survey_js/index/steelers/'+qorder+'/?email='+civ_email+'&requestid='+randomID;
    else{
    	button.onClick='';
      var answer_id = getValue('HrGaNH8SYQ_q'+question_id);
      if(answer_id == 'fail'){
      	document.getElementById('q_error_HrGaNH8SYQ').innerHTML = '*';
      	button.onClick = onclick;
      	return;
      }	
      else
      var req  = 'http://www.civicscience.com/widget/survey_js/index/steelers/'+qorder+'/?email='+civ_email+'&q='+question_id+'&a='+answer_id+'&requestid='+randomID;
	}
	addScript(req);
}
function results(qorder){
	var req = (qorder == 'intro') ? 'http://www.civicscience.com/widget/survey_js/results/steelers/'+qorder+'/1?email='+civ_email : 'http://www.civicscience.com/widget/survey_js/results/steelers/'+qorder+'/?email='+civ_email;
	addScript(req);
}
function error(){document.getElementById('HrGaNH8SYQ').innerHTML='Error Loading Poll';}
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') 
        window.onload = func;
     else 
        window.onload = function() {
            if (oldonload) 
                oldonload();
            func();}
}
function loadCss(filename){
   var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 if (typeof fileref!="undefined")
  	document.getElementsByTagName("head")[0].appendChild(fileref);
}
addLoadEvent(function(){
	loadCss("http://www.civicscience.com/css/widget-js.css");
loadCss("http://www.civicscience.com/css/steelers.css");setupGroup();
})
// JSONscriptRequest
// Author: Jason Levitt
// Date: December 7th, 2005
function JSONscriptRequest(fullUrl) {
    this.fullUrl = fullUrl; 
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    this.headLoc = document.getElementsByTagName("head").item(0);
    this.scriptId = 'YJscriptId' + JSONscriptRequest.scriptCounter++;}
JSONscriptRequest.scriptCounter = 1;
JSONscriptRequest.prototype.buildScriptTag = function () {
    this.scriptObj = document.createElement("script");
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);} 
JSONscriptRequest.prototype.removeScriptTag = function () {
    this.headLoc.removeChild(this.scriptObj);  }
JSONscriptRequest.prototype.addScriptTag = function () {
    this.headLoc.appendChild(this.scriptObj);}
function groupSetup(data){
if(data !=null)
{	
	var dot = document.createElement("div");
	dot.id = "box_HrGaNH8SYQ";
	dot.style.position = "absolute"; 
	document.getElementById('steelers').parentNode.appendChild(dot);
	var xy =  findPos(document.getElementById('HrGaNH8SYQ'));
	dot.style.left=xy[0]+'px';
	dot.style.top=xy[1]+'px';
	var text = '<div class="csw" ><div class="shell_top">&nbsp;</div><div id="main_HrGaNH8SYQ" class="shell">';
	if(data.Questions){
	text += resultsSetup(data)+'</div>';
	}else if(data.Question)
		text += questionSetup(data)+'</div>';
	else{ 
	text += '<div class="page_title"><p><strong>E-Mail Address</strong></p></div><div class="text"><input type="text" class="form_field" id="email_HrGaNH8SYQ" onkeypress="return cswCheckSubmit('+data.OnClick.substring(0,data.OnClick.length - 3) +');" value="';
	if(get_cookie("civ_steelers_email"))
	text+= get_cookie ( "civ_steelers_email" );
	text +='" />';
	text +='<div id="error_HrGaNH8SYQ" class="form_error"></div><p>This information is used to protect against fraudulent voting. Your information is never shared.</p></div>';
	text +='</div><div class="shell_buttons centered"  id="button_HrGaNH8SYQ"><img src="http://www.civicscience.com/images/buttons/submit.png" alt="Submit" title="Submit" onClick = "'+data.OnClick+'"></div>';
	}
	text +='<div class="csw_close_tab" onClick="closeDiv();" id="close_HrGaNH8SYQ"><p></p></div></div>';
	dot.innerHTML = text;
	if(document.getElementById("email_HrGaNH8SYQ"))
		document.getElementById("email_HrGaNH8SYQ").focus();
}
else
	error();
}
function civButtons(Data, id){
	var button = '<div class="button_left"><img src="http://www.civicscience.com/images/buttons/left.png" onclick="'+Data.Back+'" alt="Previous" title="Previous"/>';
	button += Data.Forward ? '<img src="http://www.civicscience.com/images/buttons/right.png" onclick="'+Data.Forward+'" alt="Next" title="Next" style="margin-left: 35px;"/></div>' : '<div style="margin-left: 35px; width: 43px;">&nbsp;</div></div>';
	return button;
}
function closeDiv(){
document.getElementById('HrGaNH8SYQ').style.visibility='visible';
document.getElementById("box_HrGaNH8SYQ").style.display = 'none';
}
function civResults(Data){ Data != null ? (document.getElementById("main_HrGaNH8SYQ") ? document.getElementById("main_HrGaNH8SYQ").innerHTML=resultsSetup(Data) : groupSetup(Data)) : error(); }
function civQuestion(jsonData){ jsonData != null ? (document.getElementById("main_HrGaNH8SYQ") ? document.getElementById("main_HrGaNH8SYQ").innerHTML=questionSetup(jsonData) : groupSetup(jsonData)) : error();}
function civResult(jsonData){ jsonData != null ? document.getElementById("main_HrGaNH8SYQ").innerHTML=resultSetup(jsonData) : error();}
function validateEmail(elementValue){ 
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
 if(emailPattern.test(elementValue))
 {var current_date = new Date;
    var cookie_year = current_date.getFullYear ( );
    var cookie_month = current_date.getMonth ( ) + 1;
    var cookie_day = current_date.getDate ( );
    set_cookie ( "civ_steelers_email", elementValue, cookie_year, cookie_month, cookie_day );
 return true;
 }else
 return false; }
function sendEmail(){
var email = document.getElementById("email_HrGaNH8SYQ") ? document.getElementById("email_HrGaNH8SYQ").value : civ_email;
	if(validateEmail(email)){
	civ_email = email;
	survey(1);
	}else{
	document.getElementById("error_HrGaNH8SYQ").innerHTML = 'Invalid Email Address';
	document.getElementById("email_HrGaNH8SYQ").focus();
}}
function findPos(obj) {
	var curleft = curtop = 0;
if (obj.offsetParent) {
do {curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
return [curleft,curtop];}}
function setupGroup(){
	var email=getQueryVariable("email");
	if(validateEmail(email))
		civ_email=email;
	var csw = document.createElement("div");
	csw.id = "csw_HrGaNH8SYQ";
	document.getElementById('steelers').parentNode.appendChild(csw);
	csw.setAttribute("class", "csw");
	csw.setAttribute("className", "csw");
	var text= '<div id="HrGaNH8SYQ"  class="shell_small">';
		 text += '<div class="poll_title"><img src="http://www.civicscience.com/images/steelers_title.png" width="114" height="38" alt="Weekly Fan Poll">';
	text +=	'</div><p>What is the key to beating the Chargers?</p><div class="one_button"><img src="http://www.civicscience.com/images/buttons/vote.png" alt="Vote" onclick="civDivCheck()" title="Vote" style=" cursor: pointer;"></div>';
		text +='<script type="text/javascript">var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));</script><script type="text/javascript">var pageTracker = _gat._getTracker("UA-4210807-2");pageTracker._trackPageview();</script></div>';
	csw.innerHTML = text;
	if(getQueryVariable("autoload"))
		civDivCheck();
}
function civDivCheck(){
	document.getElementById('HrGaNH8SYQ').style.visibility='hidden';
	document.getElementById("box_HrGaNH8SYQ") ? document.getElementById("box_HrGaNH8SYQ").style.display='block' : addScript('http://www.civicscience.com/widget/survey_js/index/steelers/1/?email='+civ_email);
}
function cswCheckSubmit(event, onclickVar) {
   var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
   if(keyCode == 13) {
   if (typeof onclickVar == 'function') 
	onclickVar();
	return false;
	}
	return true;}
function getValue(radioGroupName) {
	radios = document.getElementsByName(radioGroupName);
	for (i = 0; i < radios.length; i++) {
	if (radios[i].checked) return radios[i].value; }
	return 'fail';}	
function thankYou(Data){
if(Data != null){
var text = '<div class="page_title centered"><p><strong>Thank You!</strong></p></div>';
text +='<div class=\"text\"><p class=\"centered" style="margin-bottom: 40px; margin-top: 30px;">Take more polls and be heard at <a href="http://www.civicscience.com/">civicscience.com</a></p>';text +='</div><div class="add_widget"><a href="http://www.civicscience.com/client_services/registration/welcome/steelers" target="_blank"><img src="http://www.civicscience.com/images/buttons/add_widget.png" alt="Add Widget" title="Add Widget"></a></div></div>';
document.getElementById("button_HrGaNH8SYQ") ? document.getElementById("button_HrGaNH8SYQ").innerHTML = civButtons(Data) : text += '<div class="shell_buttons centered" id = "button_HrGaNH8SYQ">'+civButtons(Data)+'</div>';
document.getElementById("main_HrGaNH8SYQ").innerHTML=text;
}else
error();}
function resultSetup(data){
	var text ='<div class="text">';
	text +='<h2><strong>Q'+data.Question.Qorder+'</strong> '+data.Question.Topic+'</h2><div class="results_total">';
	for (var j in data.Question.Answers)
	  if(data.Question.Answers[j].Avg != undefined)
		if(data.Question.Answers[j].Avg > 0)
			text += '<img  title="'+data.Question.Answers[j].Avg+'% '+data.Question.Answers[j].Answer_Choice+'" alt="'+data.Question.Answers[j].Avg+'% '+data.Question.Answers[j].Answer_Choice+'" src="http://www.civicscience.com/images/img.php?x='+data.Question.Answers[j].Avg+'&color='+data.Question.Answers[j].Color+'&width=158">';					
	text +='</div><p style="margin-bottom: 5px;">'+data.Question.Qtext+'</p><div class="results_specific">';
	for (var j in data.Question.Answers)
	  if(data.Question.Answers[j].Color != undefined)
		text += '<div class="one_result" style="background-color: #'+data.Question.Answers[j].Color+';">'+data.Question.Answers[j].Avg+'% '+data.Question.Answers[j].Answer_Choice+'</div>';
	text +='</div></div></div>';
	document.getElementById("button_HrGaNH8SYQ") ? document.getElementById("button_HrGaNH8SYQ").innerHTML = civButtons(data) :  text += '<div class="shell_buttons centered" id = "button_HrGaNH8SYQ">'+civButtons(data)+'</div>';
	return text;
}
function resultsSetup(data){
	var text ='<div class="page_title centered"><p><strong>Poll Results</strong></p></div><div class="text">';
	for( var i in data.Questions)
	  if(data.Questions[i].Question != undefined) {
	    text += '<p><strong>Q'+data.Questions[i].Question.Qorder+'</strong> '+data.Questions[i].Question.Topic+'</p><div class="results_total">';
	    for (var j in data.Questions[i].Question.Answers)
	      if(data.Questions[i].Question.Answers[j].Avg > 0)
		  	text += '<img title="'+data.Questions[i].Question.Answers[j].Avg+'% '+data.Questions[i].Question.Answers[j].Answer_Choice+'" alt="'+data.Questions[i].Question.Answers[j].Avg+'% '+data.Questions[i].Question.Answers[j].Answer_Choice+'" src="http://www.civicscience.com/images/img.php?x='+data.Questions[i].Question.Answers[j].Avg+'&color='+data.Questions[i].Question.Answers[j].Color+'&width=158" />';
	    text+='</div>';
	  }
	document.getElementById("button_HrGaNH8SYQ") ? document.getElementById("button_HrGaNH8SYQ").innerHTML = '<img src="http://www.civicscience.com/images/buttons/details.png"  alt="Details" onClick="'+data.OnClick+'" />' : text +='</div></div><div class="shell_buttons centered" id = "button_HrGaNH8SYQ"><img src="http://www.civicscience.com/images/buttons/details.png"  alt="Details" onClick="'+data.OnClick+'" /></div>';
	return text;
}
function questionSetup(data){
	var text = '<div class="page_title centered"><p ><strong>Question '+data.Question.Qorder+' of 3</strong></p></div>';
	text +='<div class="question" ><p><span id="q_error_HrGaNH8SYQ" class="form_error"></span>'+data.Question.Qtext+'</p><table class="question_table" width="159px">';
	for (var i in data.Question.Answer_Choices)
	  if(data.Question.Answer_Choices[i].Answer_Choice_ID != undefined)
		text +='<tr><td class="left_cell"><input class="radio_field" type="radio" name="HrGaNH8SYQ_q'+data.Question.Question_ID+'" value="'+data.Question.Answer_Choices[i].Answer_Choice_ID+'" id = "HrGaNH8SYQ_'+data.Question.Answer_Choices[i].Answer_Choice_ID+'" class="radio_field" /></td><td class="right_cell"><p><label for="HrGaNH8SYQ_'+data.Question.Answer_Choices[i].Answer_Choice_ID +'">'+data.Question.Answer_Choices[i].Answer_Choice+'</label></p></td></tr>';
	text +='</table></div>';
	document.getElementById("button_HrGaNH8SYQ") ? document.getElementById("button_HrGaNH8SYQ").innerHTML = '<img src="http://www.civicscience.com/images/buttons/vote.png"  alt="Vote" onClick="'+data.OnClick+', '+data.Question.Question_ID+', \''+data.OnClick+'\')" title="Vote">' : text +='</div><div class="shell_buttons centered" id = "button_HrGaNH8SYQ"><img src="http://www.civicscience.com/images/buttons/vote.png"  alt="Vote" onClick="'+data.OnClick+', '+data.Question.Question_ID+')" title="Vote"></div>';
	return text;
}
function getQueryVariable(variable) {
  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] == variable) {
      return pair[1];
    }}return ''; }
function include(filename)
{	var head = document.getElementsByTagName('head')[0];
	script = document.createElement('script');
	script.src = filename;
	script.type = 'text/javascript';	
	head.appendChild(script);
}
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );
  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }
  if ( path )
        cookie_string += "; path=" + escape ( path );
  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  if ( secure )
        cookie_string += "; secure";
  document.cookie = cookie_string;
}
function get_cookie ( cookie_name )
{ var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  if (results  )
    return ( unescape ( results[2] ) );
  else
    return null;
}