  var newwindow;
  function poptastic(url){
    newwindow=window.open(url,'name','height=500,width=240,left=20,top=20,toolbar=no,menubar=no,directories=no,location=no,scrollbars=yes,status=no,resizable=yes,fullscreen=no');
    if (window.focus) {newwindow.focus()}
  }

  function sethtml(div,content)
  {
    var search = content;
    var script;

    while( script = search.match(/(<script[^>]+javascript[^>]+>\s*(<!--)?)/i))
    {
      search = search.substr(search.indexOf(RegExp.$1) + RegExp.$1.length);

      if (!(endscript = search.match(/((-->)?\s*<\/script>)/))) break;

      block = search.substr(0, search.indexOf(RegExp.$1));
      search = search.substring(block.length + RegExp.$1.length);

      var oScript = document.createElement('script');
      oScript.text = block;
      document.getElementsByTagName("head").item(0).appendChild(oScript);
    }

    document.getElementById(div).innerHTML=content;
  }

   var http_request = false;
   var request_done;
   function makePOSTRequest(url, parameters, contentdiv) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         // set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

      http_request.onreadystatechange = function() { alertContents(contentdiv); };
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents(contentdiv) {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            //document.getElementById(contentdiv).innerHTML = result;
            sethtml(contentdiv, result);
         } else {
            alert('There was a problem with the request.');
         }
      }
   }

   function loginGet(obj) {
      var poststr = "submit=true&lastaction=" + encodeURI( document.getElementById("last_action").value ) + "&username=" + encodeURI( document.getElementById("username").value ) +
                    "&password=" + encodeURI( document.getElementById("password").value );
      document.getElementById('logindiv').innerHTML = 'Authenticating..';
      makePOSTRequest('/ajaxlogin', poststr, 'logindiv');

   }

   function postReply(title, message, thread) {
     var poststr = "reply=true&title=" + encodeURIComponent(title) + "&message=" + encodeURIComponent(message) + "&thread=" + encodeURIComponent(thread);
     document.getElementById('post_reply').innerHTML = 'Posting Reply..';
     makePOSTRequest('/thread', poststr, 'content');
   }

   function refreshThread(thread){
     var poststr = "thread=" + thread;
     document.getElementById('content').innerHTML = '<img src="/images/loading.gif">';
     makePOSTRequest('/thread', poststr, 'content');
   }

   function showThread(thread, notracking){
     lastAction("refreshThread("+thread+");");
     var poststr = "thread=" + thread;
     document.getElementById('content').innerHTML = '<img src="/images/loading.gif">';
     makePOSTRequest('/thread', poststr, 'content');
     if(notracking == null){
       document.getElementById('trackHistory').src = '/css/track.php?page=thread&id='+thread;
     }
   }

   function watchThread(thread){
     var poststr = "watchthread=" + thread;
     makePOSTRequest('/thread', poststr, 'empty');
   }

   function changePage(page){
     var pages = document.getElementById('page_count').value;
     for(var i=1; i<=pages; i++){
       document.getElementById('page'+i+'html').style.display = 'none';
       document.getElementById('page'+i).style.background = '#FFFFFF';
       document.getElementById('pageb'+i).style.background = '#FFFFFF';
     }
     document.getElementById('page'+page+'html').style.display = '';
     document.getElementById('page'+page).style.background = '#e6e8e6';
     document.getElementById('pageb'+page).style.background = '#e6e8e6';
   }

   function showAccount(){
     var poststr = 'ajax=true';
     document.getElementById('content').innerHTML = '<img src="/images/loading.gif">';
     makePOSTRequest('/ajaxaccount', poststr, 'content');
   }

   function showTransfer(){
    alert('You must update your account information before you may continue.'); 
    window.location = '/transfer';
   } 

   function showHeader(){
     var poststr = '';
     makePOSTRequest('/headerlinks', poststr, 'header_links');
   }

   function denyPoints(id, varr){
     var poststr = 'post='+id;
     if(varr == 'true'){
       poststr = poststr + '&var=true';
     }
     makePOSTRequest('/denypoints', poststr, 'content');
   }

   function rewardPoints(id, varr){
     var poststr = 'post='+id;
     if(varr == 'true'){
       poststr = poststr + '&var=true';
     }
     makePOSTRequest('/rewardpoints', poststr, 'content');
   }

   function rewardAllPoints(){
     var poststr = 'all=true';
     makePOSTRequest('/rewardpoints', poststr, 'content');
   }

   function deletePost(id, varr){
     var poststr = 'post='+id;
     if(varr == 'true'){
       poststr = poststr + '&var=true';
     }
     makePOSTRequest('/deletepost', poststr, 'content');
   }

   function lastAction(string){
     document.getElementById('last_action').value = string;
   }

   function doReply(){
     document.getElementById('post_reply').style.display = '';
     document.getElementById('replybutton').style.display = 'none';
   }

   function doSearch(phrase){
     document.getElementById('submitsearch').disabled = true;
     document.getElementById('submitsearch').value = 'Searching...';
     document.getElementById('content').innerHTML = '<img src="/images/loading.gif">';
     var poststr = 'phrase='+encodeURIComponent(phrase);
     makePOSTRequest('/search', poststr, 'content');
   }

   function doQuote(id){
     document.getElementById('post_reply').style.display = '';
     document.getElementById('replybutton').style.display = 'none';
     document.getElementById('message').value = '[QUOTE '+id+']\n\n';
     document.getElementById('message').focus();
   }


function blink() {
  document.getElementById('show_answer').style.backgroundColor = '#efa663';
}

   function doAnswer(thread){
     var answer = '';
     var comments = document.mcq_form.mcq_comments.value;
     var mcq_answer = document.mcq_form.mcq_answer;
     for (var i=0; i < mcq_answer.length; i++){
       if (mcq_answer[i].checked){
         answer = mcq_answer[i].value;
       }
     }
     if(answer == ''){
       alert('You must select an answer.');
     }else {
       document.getElementById('postanswer').value = 'Submitting...';
       postReply(document.getElementById('title').value, '[ANSWER '+answer+']\n\n'+comments, thread);
     }
   }

   function change_parent_url(url){
     document.location.href=url;
   }	
  
   function grabElementById(id){
     return document.getElementById(id);
   }
