      
      var http = getHTTPObject(); // We create the HTTP Object
var NORMAL_STATE = 4;

function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function getHTTPObject() {
	var http_object;

	// MSIE Proprietary method

	/*@cc_on
	@if (@_jscript_version >= 5)
		try {
			http_object = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				http_object = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (E) {
				http_object = false;
			}
		}
	@else
		xmlhttp = http_object;
	@end @*/


	// Mozilla and others method

	if (!http_object && typeof XMLHttpRequest != 'undefined') {
		try {
			http_object = new XMLHttpRequest();
		}
		catch (e) {
			http_object = false;
		}
	}

	return http_object;
}

function loadingDiv(div, message)
{
  thediv = document.getElementById(div);
  thediv.innerHTML = '<p>Now Loading <br /> <img src="/images/ajaxLoading1.gif" alt="Loading" /> </p><p>'+message+'</p>';
}

// check to make sure that the browser can
// handle window.addEventListener
if (window.addEventListener) {
    // create the keys and konami variables
    var keys = [],
        konami = "38,38,40,40,37,39,37,39,66,65";
 
    // bind the keydown event to the Konami function
    window.addEventListener("keydown", function(e){
        // push the keycode to the 'keys' array
        keys.push(e.keyCode);
 
        // and check to see if the user has entered
        // the Konami code
        if (keys.toString().indexOf(konami) >= 0) {
            // do something such as:
            // alert('Konami');
            document.location = 'http://wiki.the-big-bang-theory.com/wiki/Vintage_Game_Night';
            // and finally clean up the keys array
            keys = [];
        };
    }, true);
};
      
      function pollVote()
{
  var rads=document.getElementsByName('op');
  for(var j=0;j<rads.length;j++){
  if(rads[j].checked == true){
    option = rads[j].value;
  }
  }
  pollid = document.getElementById('pollid').value;
  showTitle = document.getElementById('showTitle').value;
  pars = 'op='+option+'&pollid='+pollid+'&showtitle='+showTitle;
  
  //Show we are doing something;
  loadingDiv('pollarea', 'We are submitting your vote');
       
  http.open('POST', '/?act=polls&action=quickvote', true);
  		
  //Send the proper header information along with the request
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", pars.length);
  http.setRequestHeader("Connection", "close");
  
  http.onreadystatechange = pollVoted;
  http.send(pars);
}

function pollVoted()
{
  if (http.readyState == NORMAL_STATE) {
	document.getElementById('pollarea').innerHTML =  http.responseText;
	if(document.getElementById('submitbutton'))
	 document.getElementById('submitbutton').style.display = 'none';
  document.getElementById('srlink').style.display = 'none';  	 
 }	
}

function newPoll()
{
  //Get current poll;
  pollid = document.getElementById('pollid').value;

  //Show we are doing something;
  loadingDiv('pollarea', 'We are fetching a new poll');

  //Start the AJAX;
  http.open('GET', '/?act=polls&action=quickpoll&pollid='+pollid, true);  
  http.onreadystatechange = pollChange;
  http.send(null);
}

function pollChange()
{
  if (http.readyState == NORMAL_STATE) {
    pollcon = http.responseText.split('|#|');
    document.getElementById('pollid').value = pollcon[0];
  	document.getElementById('pollarea').innerHTML =  pollcon[1];
  	document.getElementById('submitbutton').style.display = 'block';
  	document.getElementById('srlink').style.display = 'inline';  	
  }	
}

function showResults()
{
  //Get current poll;
  pollid = document.getElementById('pollid').value;

  //Show we are doing something;
  loadingDiv('pollarea', 'We are fetching the results');

  //Start the AJAX;
  http.open('GET', '/?act=polls&action=quickresults&pollid='+pollid, true);  
  http.onreadystatechange = pollResults;
  http.send(null);
}

function pollResults()
{
  if (http.readyState == NORMAL_STATE) {
    pollcon = http.responseText;
  	document.getElementById('pollarea').innerHTML =  pollcon;
  	document.getElementById('submitbutton').style.display = 'none';
  	document.getElementById('srlink').style.display = 'none';  	
  }	
}
      
          function mathCheck()
    {
      m = m1 + m2;
      v = document.getElementById('Math'+nkey).value;
      
      if(v == m)
      {
        document.getElementById('MathResult').innerHTML = '<img src="images/tick.png" alt="Success" />';
        document.getElementById('Math'+nkey).style.backgroundColor = '#EEF3E2';
        document.getElementById('Math'+nkey).style.border = '1px solid #556B2F';
        return true;
      } else {
        document.getElementById('MathResult').innerHTML = '<img src="images/cross.png" alt="Failure" />';
        document.getElementById('Math'+nkey).style.backgroundColor = '#FEF0C9';
        document.getElementById('Math'+nkey).style.border = '1px solid #A52A2A';
                  
        return false;
      }   
    }
    
  
  function submitCheck()
    {
      if(!mathCheck())
      {
        alert('You must answer the maths question correctly.');
        return false;
      } else
        return true;   
    }