function formatPrice(value) {
  result="€ "+Math.floor(value)+",";
  var cents=100*(value-Math.floor(value))+0.5;
  result += Math.floor(cents/10);
  result += Math.floor(cents%10);
  return result;
}

function blurPageOn(newContent) {
  document.getElementById('blurpage').innerHTML = newContent;
  document.getElementById('blurpage').style.display = 'inline';
}
function blurPageOff() {
  document.getElementById('blurpage').style.display = 'none';
}

function getCurrentDpyDate() {
  var d = new Date();
  var curr_seconds = '0' + d.getSeconds();
  var curr_minute = '0' + d.getMinutes();
  var curr_hour = '0' + d.getHours();
  var curr_date = '0' + d.getDate();
  var curr_month = '0' + d.getMonth();
  var curr_year = '0' + d.getFullYear();
  return curr_year.substring(curr_year.length-4,curr_year.length) +
         curr_month.substring(curr_month.length-2,curr_month.length) + 
         curr_date.substring(curr_date.length-2,curr_date.length) +
         curr_hour.substring(curr_hour.length-2,curr_hour.length) +
         curr_minute.substring(curr_minute.length-2,curr_minute.length) +
         curr_seconds.substring(curr_seconds.length-2,curr_seconds.length);
}

function encodeHtml(str) {
  var encodedHtml = str;
  encodedHtml = encodedHtml.replace(/\'/g,"&#39;");
  encodedHtml = encodedHtml.replace(/\"/g,"&quot;");
  encodedHtml = encodedHtml.replace(/</g, "&lt;");
  encodedHtml = encodedHtml.replace(/>/g, "&gt;");
  encodedHtml = encodedHtml.replace(/\n/g, "<br />");
  return encodedHtml;
}

function toggleHide(itemId)
{
  if (document.getElementById(itemId).style.display=='none')
    { document.getElementById(itemId).style.display='inline'; }
    else { document.getElementById(itemId).style.display='none'; }
}

function searchKeyPress(e)
{
    if (bron=checkBrowser()!="IE")
        Key = e.which;
    else
        Key = window.event.keyCode;
    if (Key == 13) searchClick();
}

function openPage(pageid, otherquery)
{
  if (typeof(otherquery)=="undefined") otherquery="";
  top.location.href="home.php?pid=" + pageid + otherquery;
}

function openExternal(pageurl)
{
  newwindow=open(pageurl);
}

function printable(pageurl, querystring)
{
  window.open(pageurl + "?" + querystring + "&printable", "printversion",
              'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,' +
              'resizable=1,width=640,height=480,left=320,top=272');
}

function drawpng(pngfile, width, height, title)
{
  if(checkBrowser()=="IE")
  {
    document.write("<SPAN style=\"width: " + width + "px; height: " + height +
                   "px; display:inline-block; " +
                   "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" +
                   "(src='" + pngfile + "', sizingMethod='scale');\" title=\"" +
                   title + "\"></SPAN>");
  }
  else
  {
    document.write('<IMG border=0 SRC=\'' + pngfile + '\' TITLE=\'' + title +
                   '\' WIDTH=' + width + ' HEIGHT=' + height + '>');
  }
}

function dpyDateString(vartimestamp, vartype)
{
  intyear=parseInt(vartimestamp.charAt(0) + vartimestamp.charAt(1) + vartimestamp.charAt(2) + vartimestamp.charAt(3), 10);
  stryear=vartimestamp.charAt(0) + vartimestamp.charAt(1) + vartimestamp.charAt(2) + vartimestamp.charAt(3);
  intmonth=parseInt(vartimestamp.charAt(4) + vartimestamp.charAt(5),10);
  strmonth=vartimestamp.charAt(4) + vartimestamp.charAt(5);
  intday=parseInt(vartimestamp.charAt(6) + vartimestamp.charAt(7), 10);
  strday=vartimestamp.charAt(6) + vartimestamp.charAt(7);
  inthours=parseInt(vartimestamp.charAt(8) + vartimestamp.charAt(9), 10);
  strhours=vartimestamp.charAt(8) + vartimestamp.charAt(9);
  intminutes=parseInt(vartimestamp.charAt(10) + vartimestamp.charAt(11), 10);
  strminutes=vartimestamp.charAt(10) + vartimestamp.charAt(11);
  intseconds=parseInt(vartimestamp.charAt(12) + vartimestamp.charAt(13), 10);
  strseconds=vartimestamp.charAt(12) + vartimestamp.charAt(13);

  datenamedutch = new Array("0-base-dummy", "januari", "februari", "maart",
                            "april", "mei", "juni", "juli", "augustus",
                            "september", "oktober", "november", "december");
                               

  switch(vartype) {
    case 0: //2006-01-18 10:04:05
      return (stryear + "-" + strmonth + "-" + strday + " " + strhours + ":" + strminutes + ":" + strseconds);
      break;
    case 1: //18 Januari 2006
      return intday + " " + datenamedutch[intmonth] + " " + stryear;
      break;
    case 2: //20:00 en //8:00
      return inthours + ":" + strminutes;
    default: //2006-01-18 10:04:05
      return (stryear + "-" + strmonth + "-" + strday + " " + strhours + ":" + strminutes + ":" + strseconds);
      break;
  }
}

function searchClick()
{
  if(document.getElementById("searchRadioSite").checked)
  {
    top.location.href="home.php?pid=6&search=" +
                       document.getElementById("searchBarInput").value;
  }
  else
  {
    if (document.getElementById("searchRadioProfiles").checked)
    {
      top.location.href="home.php?pid=7&search=" +
                         document.getElementById("searchBarInput").value;
    }
    else
    {
      top.location.href="http://www.google.nl/search?q=" +
                         document.getElementById("searchBarInput").value;
    }
  }
}

function topBarButtonMouseOver(e)
{
  bron=checkBrowser()=="IE" ? bron=e.srcElement : bron=e.target;
  bron.className="topbarButtonMouseOver";
};

function topBarButtonMouseOut(e)
{
  bron=checkBrowser()=="IE" ? bron=e.srcElement : bron=e.target;
  bron.className="topbarButton";
};

function checkBrowser()
{
  browser="";
  navUsrAgnt = navigator.userAgent;
  if(navUsrAgnt.indexOf("Firefox")!= -1) {return "FF"}; //FireFox
  if(navUsrAgnt.indexOf("MSIE")!= -1)    {return "IE"}; //Internet Explorer
  if(navUsrAgnt.indexOf("Netscape")!= -1){return "NN"}; //Netscape Navigator
  if(navUsrAgnt.indexOf("Opera")!= -1)   {return "OP"}; //Opera
  if(browser="")                         {return "UN"}; //Unknown
};

function startPage() //functions started at pageload.
{
  pageResize();
  createMenu(); 
}

function pageResize()
{
  var myWidth = 0;
  var myHeight = 0;

  var topBarRightElement;
  var topBarRightWidth = 0;
  var topBarRightHeigth = 0;

  var logoBarElement;
  var logoBarWidth = 0;
  var logoBarHeigth = 0;

  topBarRightElement = document.getElementById("TopBarRight");
  topBarRightWidth = topBarRightElement.offsetWidth;
  topBarRightHeight = topBarRightElement.offsetHeight;

  logoBarElement = document.getElementById("logoBar");
  logoBarWidth = logoBarElement.offsetWidth;
  logoBarHeight = logoBarElement.offsetHeight;

  searchBarElement = document.getElementById("searchBar");
  searchBarWidth = searchBarElement.offsetWidth;
  searchBarHeight = searchBarElement.offsetHeight;

  iconBarElement = document.getElementById("iconBar");
  iconBarWidth = iconBarElement.offsetWidth;
  iconBarHeight = iconBarElement.offsetHeight;

  if(checkBrowser()=="IE")
  {
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  else
  {
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  }
  document.getElementById("TopBarLeft").style.width = parseInt(myWidth -
                                                             topBarRightWidth);
  document.getElementById("TopBarLeft").style.height = 22;
  document.getElementById("TopBarLeft").style.top = 0;
  document.getElementById("TopBarLeft").style.left = 0;
  document.getElementById("TopBarLeftGradient").style.width =
                            document.getElementById("TopBarLeft").style.width;
  document.getElementById("TopBarLeftGradient").style.height =
                            document.getElementById("TopBarLeft").style.height;
  document.getElementById("TopBarRight").style.left =
                             document.getElementById("TopBarLeft").style.width;

  document.getElementById("logoBar").style.width = parseInt(myWidth -
                                                               searchBarWidth);
  document.getElementById("logoBar").style.height = 44;
  document.getElementById("logoBar").style.top = 22;
  document.getElementById("logoBar").style.left = 0;
  document.getElementById("logoBarGradient").style.width =
                                document.getElementById("logoBar").style.width;
  document.getElementById("logoBarGradient").style.height =
                              document.getElementById("logoBar").style.height;
  document.getElementById("searchBar").style.left =
                                document.getElementById("logoBar").style.width;

  document.getElementById("titleBar").style.width = parseInt(myWidth -
                                                                iconBarWidth);
  document.getElementById("titleBar").style.height = 34;
  document.getElementById("titleBar").style.top = 66;
  document.getElementById("titleBar").style.left = 0;
  document.getElementById("iconBar").style.left = 
                               document.getElementById("titleBar").style.width;

  document.getElementById("footerBar").style.width = myWidth;
  document.getElementById("footerBar").style.height = 80;
  document.getElementById("footerBar").style.top = myHeight-80;

  document.getElementById("menu").style.left = 0;
  document.getElementById("menu").style.height = myHeight - (
                            document.getElementById("footerBar").offsetHeight +
                            document.getElementById("TopBarLeft").offsetHeight +
                            document.getElementById("logoBar").offsetHeight +
                            document.getElementById("titleBar").offsetHeight);
  
  document.getElementById("Ads").style.left = myWidth - 151;
  //document.getElementById("Ads").style.height = myHeight - 122;
  document.getElementById("Ads").style.height = (myHeight - (
                            document.getElementById("footerBar").offsetHeight +
                            document.getElementById("TopBarLeft").offsetHeight +
                            document.getElementById("logoBar").offsetHeight +
                            document.getElementById("titleBar").offsetHeight));


  document.getElementById("bodyContents").style.width = myWidth - 332;
//  document.getElementById("bodyContents").style.height = myHeight - 122;
  document.getElementById("bodyContents").style.height = myHeight - (
                            document.getElementById("footerBar").offsetHeight +
                            document.getElementById("TopBarLeft").offsetHeight +
                            document.getElementById("logoBar").offsetHeight +
                            document.getElementById("titleBar").offsetHeight);  
  
  document.getElementById("TopBarLeft").style.visibility = "visible";
  document.getElementById("TopBarLeftGradient").style.visibility = "visible";
  document.getElementById("TopBarRight").style.visibility = "visible";
  document.getElementById("logoBar").style.visibility = "visible";
  document.getElementById("logoBarGradient").style.visibility = "visible";
  document.getElementById("logo").style.visibility = "visible";  
  document.getElementById("searchBar").style.visibility = "visible";
  document.getElementById("titleBar").style.visibility = "visible";
  document.getElementById("iconBar").style.visibility = "visible";
  document.getElementById("footerBar").style.visibility = "visible";
  document.getElementById("menu").style.visibility = "visible";
  document.getElementById("Ads").style.visibility = "visible";
  document.getElementById("bodyContents").style.visibility = "visible";
}

function searchBarButtonMouseOver(e)
{
  bron=checkBrowser()=="IE" ? bron=e.srcElement : bron=e.target;
  bron.className="searchBarButtonMouseOver";
}

function searchBarButtonMouseOut(e)
{
  bron=checkBrowser()=="IE" ? bron=e.srcElement : bron=e.target;
  bron.className="searchBarButton";
}

function topBarRightButtonMouseOver(e)
{
  bron=checkBrowser()=="IE" ? bron=e.srcElement : bron=e.target;
  bron.className="topBarRightButtonMouseOver";
};

function topBarRightButtonMouseOut(e)
{
  bron=checkBrowser()=="IE" ? bron=e.srcElement : bron=e.target;
  bron.className="topBarRightButton";
};

function setStyle(e, stl)
{
  bron=checkBrowser()=="IE" ? bron=e.srcElement : bron=e.target;
  bron.className=stl;
};

