//
// Copyright 2005-2006 CodeDroids ApS
//
function toggleForm(ident) {
  var form = xGetElementById(ident);
  var field = xGetElementById(field);
  if(form.style.display=='none') {
    form.style.display='block';
  } else {
    form.style.display='none';
  }
}
function focusForm() {
  var form = document.forms[0];
  if(form) {
    for(i=0; true; i++) {
      var elem = form.elements[i];
      if(!elem)
        break;
      if(! (elem.type=='hidden' || elem.disabled) ) {
        elem.focus();
        break;
      }
    }
  }
}
function winOnLoad()
{
  var ele = xGetElementById('ScrollArea');
  if (ele && xDef(ele.style, ele.offsetHeight)) { // another compatibility check
    xAddEventListener(window, 'resize', winOnResize, false);
    adjustLayout(); 
  }
  xShow('Body');
  initLeftMenu();
  focusForm();
}
function winOnLoadIE()
{
  xShow('Body');
  initLeftMenu();
  focusForm();
}
function winOnResize()
{
  adjustLayout();
}
function adjustLayout()
{
  var clientW = xClientWidth();
  var posL = Math.max( (clientW - 802) / 2, 0);
  xLeft('LeftCol', posL);
  xLeft('RightCol', posL + 629);
  xLeft('Logos', posL + 629);
  xLeft('SubNav', posL + 173);
  xLeft('SubNav1',  posL + 173);
  xLeft('SubNav2',  posL + 173 + 152);
  xLeft('SubNav3',  posL + 173 + 304);
  xLeft('TextCol',  posL + 173);
  xLeft('Footer', posL);
  var bd = xGetElementById('Body');
  bd.style.backgroundPosition='center top';
}
function openTellFriend(uri, pageUri, theLocale, site) {	
  if (window.location.search != "") {
    pageUri += window.location.search;		
  }
  pageUri = encodeURIComponent(pageUri); 
  if(theLocale)
    pageUri = "?__locale=" + theLocale + "&uri=" + pageUri + "&site=" + site;
  else
    pageUri = "?uri=" + pageUri + "&site=" + site;
  window.open(uri + pageUri, "tellfriend", "width=600,height=420,dependent=yes,status=no,toolbar=no,location=no,scrollbars=yes,resizable=yes");
}


function goToLocation(jump) {
  var value = jump[jump.selectedIndex].value;
  window.location.href = value;
  return false;
}

function switchHeader2Image(imageURL) {
  if(!document.getElementById || !document.getElementsByTagName)
    return;
  var ca = document.getElementById('ScrollArea');
  var h1s = ca.getElementsByTagName('h1');
  if(h1s != null && h1s.length > 0) {
    var h1 = h1s[0];
    var img = document.createElement('img');
    img.src=imageURL;
    img.alt=h1.firstChild.nodeValue;
    img.className='h1Img';
    //h1.parentNode.replaceChild();
    h1.parentNode.insertBefore(img, h1);
    h1.parentNode.removeChild(h1);
  }
}
function addHeaderImage(imageURL, imageAlt) {
  if(!document.getElementById || !document.getElementsByTagName)
    return;
  var ca = document.getElementById('ScrollArea');
  var h1s = ca.getElementsByTagName('h1');
  if(h1s != null && h1s.length > 0) {
    var h1 = h1s[0];
    var img = document.createElement('img');
    img.src=imageURL;
    img.alt=imageAlt;
    img.className='h1Img';
    h1.parentNode.insertBefore(img, h1);
  }
}
function addHeaderSpace() {
  if(!document.getElementById || !document.getElementsByTagName)
    return;
  var ca = document.getElementById('ScrollArea');
  var h1s = ca.getElementsByTagName('h1');
  if(h1s != null && h1s.length > 0) {
    var h1 = h1s[0];
    if(h1.parentNode == ca) {
      if (h1.className=="")
        h1.className="FirstOnPage";
      else
        h1.className+=" FirstOnPage";
    }
  }
}

function cd_mobfuscate(dom, name) {
  document.write(name+"@"+dom);
}
function cd_m2obfuscate_l(dom, name, subj, pre, txt, post) {
  document.write("<a href='mailto:");
  document.write(name+"@"+dom);
  if(subj!=null && subj.length > 0)
    document.write("?"+subj);
  document.write("'>"+pre+(txt==null ? (name+"@"+dom) : txt)+post+"</a>");
}
function cd_m2obfuscate(dom, name) {
  cd_m2obfuscate_l(dom, name, null, '', null, '');
}
function cd_m2obfuscate1(dom, name, subj) {
  document.write("<a href='mailto:");
  document.write(name+"@"+dom);
  if(subj!=null && subj.length > 0)
    document.write("?"+subj);
  document.write("'>");
}
function cd_m2obfuscate2(dom, name) {
  document.write(name+"@"+dom);
}
function cd_m2obfuscate3() {
  document.write("</a>");
}

// stuff for preventing automatic load of iframe contents
var ifr;
function patchIFr(posterImg) {
   ifr = document.getElementById('movie');
   ifrparent = ifr.parentNode;
   a = document.createElement('a');
   a.href="javascript:startIFr()";
   a.setAttribute("id", "movieposter");
   img = document.createElement('img');
   img.src = posterImg;
   img.style.width="322px";
   img.style.height="314px";
   img.style.border="0";
   a.appendChild(img);
   ifrparent.replaceChild(a, ifr);
}
function startIFr() {
   a = document.getElementById('movieposter');
   aparent = a.parentNode;
   aparent.replaceChild(ifr, a)
}

