//Menu
function deselectAllMenu(node) {
  var par = node.parentNode;
  for(var i=0; i<par.childNodes.length; i++) {
    var child = par.childNodes[i];
    if(child.nodeType==1)
      child.className="";
  }
  node.className="selected";
}

function loadModule(file, container, data) {
  var req = new AjaxRequest(file,"POST",data);
    
  req.onstatechange = function()  {
    if(req.xmlhttp.readyState == 4) {
      var node = document.getElementById(container);
      if (node.hasChildNodes())
        node.removeChild(node.childNodes[0]);
            
      node.innerHTML = req.xmlhttp.responseText;
      var script = node.getElementsByTagName("script");

      for(var i=0; i<script.length; i++) {
          eval(script[i].innerHTML);
      }
    }
  }
  req.doRequest();
}

//Webshop
function sendWebshopForm(node,errortext) {
var form = node.parentNode;
if (form.firstname.value=='' || form.lastname.value=='' || form.postalcode.value=='' || form.address.value=='' || form.city.value=='' || form.email.value=='')
  alert(errortext);
else {
  var url = 'ajax=1&sendmail=1&firstname='+form.firstname.value+'&lastname='+form.lastname.value+'&postalcode='+form.postalcode.value+'&address='+form.address.value+'&city='+form.city.value+'&email='+form.email.value;
  loadModule('webshop.php','content',url);
}
}

var closetimeout = null;
var aktpageid = 0;
//Submenu
function showSubMenu(pageid) {
  var sub = document.getElementById('submenu');
  if (aktpageid!=pageid) {
    var node = document.getElementById('menu_page_'+pageid);
    var content = node.nextSibling.innerHTML;
    sub.innerHTML = content;
    sub.style.display='block';
    aktpageid = pageid;
  }
  if(closetimeout!=null)
    clearTimeout(closetimeout);
}

function hideSubMenu() {
  if(closetimeout!=null)
    clearTimeout(closetimeout);
  closetimeout = setTimeout(closeSubMenu, 1000);
}

function closeSubMenu() {
  var sub = document.getElementById('submenu');
  sub.style.display='none';
  sub.innerHTML="";
  aktpageid = 0;
  clearTimeout(closetimeout);
}

//GENERAL
function getScreenSize(type) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  if(type=='width')
    return myWidth;
  else
    return myHeight;  
}

function resizeSite() {
  var width = getScreenSize('width');
  var height = getScreenSize('height');
  
  var xdiff = width-2520;
  var ydiff = height-1575;
  
  var wallp = document.getElementById('wallpaper');
  
  wallp.style.left=(xdiff/2)+"px";
  wallp.style.width=(width+(xdiff/2*-1))+"px";
  wallp.style.top=ydiff+"px";
  wallp.style.visibility="visible";
  setTimeout(function() { document.getElementById('wallpaper').className = "wallpaper"; }, 300);
                                                        
  var sponsorbar = document.getElementById('sponsorbar_new');
  sponsorbar.style.left = (width-950)/2+"px"; 
  var raika = document.getElementById('raika');
  raika.style.left = (((width-183)/2)+6)+"px";   
       
  var site = document.getElementById("website");
  site.style.left=((width-1024)/2)+"px";
  site.style.top=((height-542)/2)+"px";
  if((height-542)/2<0)
    site.style.top="0px";
  if((width-1024)/2<0)
    site.style.left="0px";
    
  var view = document.getElementById("viewport");
  view.style.width=width+"px";
  view.style.height=height+"px";     
}

/*OLD function resizeSite() {
  var width = getScreenSize('width');
  var height = getScreenSize('height');

  var xdiff = width-1650;
  var ydiff = height-1050;

  var left = document.getElementById('bgleft');
  var right = document.getElementById('bgright');
  var wallp = document.getElementById('wallpaper');
  
  left.style.width=(xdiff>0)?((xdiff/2)+"px"):0;
  right.style.width=(xdiff>0)?((xdiff/2)+"px"):0;

  if(xdiff<=0) {
    left.style.display="none";
    right.style.display="none";
  } else {
    left.style.display="block";
    right.style.display="block";
  }

  wallp.style.left=(xdiff/2)+"px";
  wallp.style.width=(width+(xdiff/2*-1))+"px";
  wallp.style.top=ydiff+"px";
  wallp.style.visibility="visible";
  left.style.top=ydiff+"px";
  right.style.top=ydiff+"px";

  var site = document.getElementById("website");
  site.style.left=((width-1024)/2)+"px";
  site.style.top=((height-582)/2)+"px";
  if((height-582)/2<0)
    site.style.top="0px";
  if((width-1024)/2<0)
    site.style.left="0px";
 
  var view = document.getElementById("viewport");
  view.style.width=width+"px";
  view.style.height=height+"px";  
}*/
