var xmlHttp;
var riddleId;

/*****************************************************************************
Default browsercheck
******************************************************************************/
function checkBrowser(){
	this.ver=navigator.appVersion;
	this.dom=document.getElementById?1:0;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.opera=!(this.ie5 || this.ie4 || this.ns4 || this.ns5) && this.dom;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5);
	return this
}

function showCategory (category){
//		document.CatForm.CatDisplayer.value = category;
		document.title = "Raadsels van Spruit  ***" + category + "***   ";
}

function changeBg(){
	document.corner.background="sidebar_bg.jpg";
}

function showImage(Image) {
    parent.lower.location.href = Image;
    //return "Tja, en toen stond er een plaatje";
}

function showAnswer(riddleId,visibility) {
	var obj = document.getElementById(riddleId);
        obj.style.visibility = visibility;
}

function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

function stateChanged() 
{ 
	var fieldName = "saveTime"+riddleId;
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById(fieldName).innerHTML=xmlHttp.responseText;
	}
	if (xmlHttp.readyState==0)
	{ 
		document.getElementById(fieldName).innerHTML="The request is not initialized.";
	}
}

function ajaxUpdateScore(id,score)
{
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
  {
  	alert ("Your browser does not support AJAX!");
  	return;
  }; 
  
  var url="ajaxUpdateScore.asp";
  url=url+"?id="+id;
  url=url+"&score="+score;
//  xmlHttp.onreadystatechange=stateChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function truncDecimals(n) {
   var s = "" + Math.round(n * 100) / 100
   var i = s.indexOf('.')
   if (i < 0) return s// + ".00"
//   var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
   var t = s.substring(0, i)
   if (i + 2 == s.length) t += "0"
   return t
}

function drawPercentBar(percent,amount) 
  { 

	var width = 120;

	var color = "#ebbc19";
	var background = "#FFFFFF";
	var border = "#4C0039";

    if (!color) { color = "#B0B0B0"; }
    if (!background) { background = "none"; }
    if (!border) { border = "#000000"; }
 
    var pixels = width * (percent); 

    document.write("<div style=\"position: relative; line-height: 1em; background-color: " 
                   + background + "; border: 1px solid " + border + "; width: " 
                   + width + "px\">"); 
    document.write("<div style=\"height: 1.25em; width: " + pixels + "px; background-color: "
                   + color + ";\"><\/div>"); 
    document.write("<div style=\"position: absolute; text-align: center; padding-top: .25em; width: " 
                   + width + "px; top: 0; left: 0\">" + truncDecimals(percent*100) + "% leuk, #" + amount + "<\/div>");
    document.write("<\/div>"); 
  } 
  