logging__ = false;
xsltdebug__ = false;
current_processing = 0;
loading="<span class=\"loading\">Loading..<blink>.</blink></span>";

// threadsafe asynchronous XMLHTTPRequest code
function ajaxSend(url, callback, method, args){
   // we use a javascript feature here called "inner functions"
   // using these means the local variables retain their values after the outer function
   // has returned. this is useful for thread safety, so
   // reassigning the onreadystatechange function doesn't stomp over earlier requests.
   function ajaxBindCallback(){
      if (ajaxRequest.readyState == 4) {
         if (ajaxRequest.status == 200) {
            if (ajaxCallback){
               ajaxCallback(ajaxRequest.responseText);
            } else {
               alert('no callback defined');
            }
         } else {
            //alert("There was a problem retrieving the xml data:\n" + ajaxRequest.status + ":\t" + ajaxRequest.statusText + "\n" + ajaxRequest.responseText);
            document.getElementById('debug').innerHtml = "<pre>There was a problem retrieving the xml data:\n" + ajaxRequest.status + ":\t" + ajaxRequest.statusText + "\n" + ajaxRequest.responseText+"</pre>"
         }
      }
   }
   
   // use a local variable to hold our request and callback until the inner function is called...
   var ajaxRequest = null;
   var ajaxCallback = callback;
   
   // bind our callback then hit the server...
   if (window.XMLHttpRequest) {
      // moz et al
      ajaxRequest = new XMLHttpRequest();
      ajaxRequest.onreadystatechange = ajaxBindCallback;
      if (method != "POST"){
         ajaxRequest.open("GET", url, true);
         ajaxRequest.send(null);
      }else{
         ajaxRequest.open("POST", url, true);
         ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
         ajaxRequest.send(args);
      }
   } else if (window.ActiveXObject) {
      // ie
      ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
      if (ajaxRequest) {
         if (method != "POST"){
            ajaxRequest.onreadystatechange = ajaxBindCallback;
            ajaxRequest.open("GET", url, true);
            ajaxRequest.send();
         }else{
            ajaxRequest.open("POST", url, true);
            ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
            ajaxRequest.send(str);
         }
      }
   }
}
function getFormValues(fobj,valFunc){
   var str = "";
   var valueArr = null;
   var val = "";
   var cmd = "";
   for(var i = 0;i < fobj.elements.length;i++){
      switch(fobj.elements[i].type){
         case "text":
            if(valFunc){
               //use single quotes for argument so that the value of
               //fobj.elements[i].value is treated as a string not a literal
               cmd = valFunc + "(" + 'fobj.elements[i].value' + ")";
               val = eval(cmd)
            }
            str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
            break;
         case "select-one":
            str += fobj.elements[i].name + "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
            break;
      }
   }
   str = str.substr(0,(str.length - 1));
   return str;
}
function thanks(t){
   document.getElementById(writein).innerHTML = t;
   current_processing+=1;
   processor();
}
function display(t){
   document.getElementById(writein).innerHTML = t;
}
function voteLoaded(t){
   var resp = eval('(' + t + ')');
   votebox = document.getElementById("vote"+resp['id'])
   document.getElementById("votes"+resp['id']).innerHTML = resp['votes'];
   votebox.innerHTML = "Voted";
   votebox.className = "votedbox";
}
function vote(url, id){
   writein = "votes"+id;
   ajaxSend(url, voteLoaded);
}
function checkvotesLoaded(t){
   var resp = eval('(' + t + ')');
   for (i=0; i<resp['submissionvotes'].length; i++){
      votebox = document.getElementById("vote"+resp['submissionvotes'][i])
      votebox.innerHTML = "Voted";
      votebox.className = "votedbox";
   }
}
function checkvotes(ids){
   ajaxSend("/checkvotes"+ids+".json", checkvotesLoaded);
}
