function body_onload()
{
  document.getElementById('div_maindesc').style.display = '';
  document.getElementById('div_login').style.display = 'none';
  buildPage();
}

function buildPage()
{
  var elem;
  
  for(var i=0;i<txt.length;i++)
  {
    elem = document.getElementById('div_'+txt[i][2])
    elem.innerHTML = txt[i][3];
  } 
  
  buildBrands();
  
  getFrontImage();
    
  if (m=='admin' || l)
    document.getElementById('div_login').style.display = '';
    
  if (l)
  {
    document.getElementById('div_login').innerHTML = createLogoutWindow();  
    document.getElementById('div_maindesc').className += ' clickable';
  }
  else
    document.getElementById('div_login').innerHTML = createLoginWindow();
}

function buildBrands()
{
  var sHTML = '<table id="tblBrands">';
  
  for(var i=0;i<brnd.length;i++)  {
    sHTML+='<tr>'+(l?'<td><img src="./img/edit.gif" width="16px" height="16px" class="clickable" onclick="dbl_brand()"></td>':'')+'<td class="aBrand" onmouseover="mo_brand(this,'+brnd[i][0]+')" onmouseout="mout_brand(this)"><a href="#" class="aBrand" onclick="showCollection('+brnd[i][0]+')">'+brnd[i][1]+'</a></td></tr>';
  }
  sHTML+='</table>';
  
  document.getElementById('div_merken').innerHTML = sHTML;
}

function mo_brand(elem, id)
{
  //if(l)
  //  elem.style.border = "dotted 1px #696969"
}

function mout_brand(elem)
{
  //if (l)   
  // elem.style.border = "solid 1px #FFFFFF"
}

function showCollection(id)
{
  document.forms['frmMain'].action='collection.asp?pg='+id;
  document.forms['frmMain'].submit();
}

function dbl_brand()
{
  document.forms['frmMain'].action='editbrands.asp';
  document.forms['frmMain'].submit();
}

function createLoginWindow()
{
  var sHTML = ''+
              '<table><tr><td class="loginLabel">loginnaam</td></tr><tr><td><input type="text" class="input" name="txtUN" id="txtUN"></td></tr>'+
              '<tr><td class="loginLabel">wachtwoord</td></tr><tr><td><input type="password" class="input" name="txtPw" id="txtPw"></td></tr>'+
              '<tr><td class="loginLabel"><button onclick="login()">inloggen!</button></td></tr></table>';
  
  return sHTML;
}

function createLogoutWindow()
{
  var sHTML = '<nobr><span id="div_logintext" class="loginLabel">'+sNaam+' - </span><span class="loginLabel clickable" onclick="logout()">uitloggen</span><nobr>';
  
  return sHTML;
}

function login()
{
  document.getElementById("hdnA").value = 'login';
  document.getElementById("hdnUserName").value = document.getElementById("txtUN").value
  document.getElementById("hdnPassword").value = document.getElementById("txtPw").value
  
  document.forms['frmMain'].action='default.asp?mode=admin';
  document.forms['frmMain'].submit();
}

function logout()
{
  document.getElementById("hdnA").value = 'logout';
  document.forms['frmMain'].action='default.asp?mode=admin';
  document.forms['frmMain'].submit();
}

function editmaindesc(textcode)
{
  var ret;
  var sw = (screen.width -440) / 2;
  var sh = (screen.height -280) / 2;
  
  if (l)
    ret = window.open('./edittext.asp?t='+textcode,'Wijzigen','width=540px; height=350px; top='+sh+'; left='+sw); 
}

function getHeadText(p)
{
  for(var j=0;j<txt.length;j++)
  {
    if(txt[j][2]==p)
      return txt[j][4];
  }
}

function getMainText(p)
{
  return document.getElementById('div_'+p).innerText
}

function et(cod, txt)
{
  document.getElementById('div_'+cod).innerText = txt;
}

function getFrontImage()
{
  var sNr = parseInt((Math.random()*3)+1,10);
  var img1 = '<img src="./collectie/homepage/set'+sNr+'/foto1.jpg">';
  var img2 = '<img src="./collectie/homepage/set'+sNr+'/foto2.jpg">';
  var img3 = '<img src="./collectie/homepage/set'+sNr+'/foto3.jpg">';
  
  document.getElementById('div_foto1').innerHTML = img1;
  document.getElementById('div_foto2').innerHTML = img2;
  document.getElementById('div_foto3').innerHTML = img3;
}  

