//Function to change Background image of menuitem when pushed
function MenuItemBackgroundPushed(item){
  var image = "assets/button_mnu_"+item+"_push.png";
  document.getElementById(item).style.background = "url("+image+")";
  new PNG(item, image);
  }
//Function to change Background image of menuitem when up
function MenuItemBackgroundUp(item){
  var image = "assets/button_mnu_"+item+".png"
  document.getElementById(item).style.background = "url("+image+")";
  new PNG(item, image);  
  }
//Function to change ScrollBackground image
function ScrollBackgroundUp(){
  if(document.getElementById("scrolling")){
    var scrollobj = "scrolling";
    }
  if(document.getElementById("scrolling_bedrijf")){
    var scrollobj = "scrolling_bedrijf";
    }
  
  var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
  if(IE6){
    var image = "assets/scroll-normal_ie6.png";    
    }
  else{
    var image = "assets/scroll-normal.png";    
    }
  document.getElementById(scrollobj).style.background = "url("+image+")";
  document.getElementById(scrollobj).style.backgroundRepeat = "no-repeat";
  }
function ScrollBackgroundDown(pos){
  if(document.getElementById("scrolling")){  
    var scrollobj = "scrolling";
    }
  if(document.getElementById("scrolling_bedrijf")){
    var scrollobj = "scrolling_bedrijf";
    }
  var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
  if(IE6){
    var image = "assets/scroll-"+pos+"_ie6.png";    
    }
  else{
    var image = "assets/scroll-"+pos+".png";    
    }  
  document.getElementById(scrollobj).style.background = "url("+image+")";
  document.getElementById(scrollobj).style.backgroundRepeat = "no-repeat";
  }
  

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function setContent() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
    
    if(windowHeight < 800){
      windowHeight = 800;
      document.getElementById("container").style.minHeight = "850px";
      document.getElementById("container").style.height = "850px";      
      }
    else{
      document.getElementById("container").style.minHeight = "100%";
      document.getElementById("container").style.height = "100%";
      }
    
    if(windowHeight > 0){
      var boxheight = windowHeight - 214 - 30 - 10;
      document.getElementById("main_leftside").style.height = boxheight + "px";
      document.getElementById("main_rightside").style.height = boxheight + "px";            
      //Left
      //Check leftelement
      if(document.getElementById('home_left')){	var contentElement = document.getElementById('home_left');}
      if(document.getElementById('bedrijf_left')){	var contentElement = document.getElementById('bedrijf_left');}
      if(document.getElementById('info_left')){	var contentElement = document.getElementById('info_left');}
      if(document.getElementById('contact_left')){	var contentElement = document.getElementById('contact_left');}
      
			var contentHeight = contentElement.offsetHeight;		

      if (boxheight - contentHeight > 0) {
				contentElement.style.position = 'relative';        
				contentElement.style.top = ((boxheight / 2) - (contentHeight / 2)) + 'px';
			  }
			else {
				contentElement.style.position = 'static';
			  }      
      //Right   
      //Check rightelement  
      if(document.getElementById('home_right')){	var contentElement = document.getElementById('home_right');}
      if(document.getElementById('bedrijf_right')){	var contentElement = document.getElementById('bedrijf_right');}
      if(document.getElementById('info_right')){	var contentElement = document.getElementById('info_right');}
      if(document.getElementById('contact_right')){	var contentElement = document.getElementById('contact_right');}
      
			var contentHeight = contentElement.offsetHeight;		      

      if (boxheight - contentHeight > 0) {
				contentElement.style.position = 'relative';
				contentElement.style.top = ((boxheight / 2) - (contentHeight / 2)) + 'px';
			  }
			else {
				contentElement.style.position = 'static';
			  }
		}
	}
}

function initScrollLayer() {
  if(document.getElementById('wn_lijst')){
    var wndo = new dw_scrollObj('wn_lijst', 'lyr1_lijst', null);
    dw_scrollObj.GeckoTableBugFix('wn_lijst'); 
    }
  if(document.getElementById('wn_lijst_bedrijf')){
    var wndo = new dw_scrollObj('wn_lijst_bedrijf', 'lyr1_lijst', null);
    dw_scrollObj.GeckoTableBugFix('wn_lijst_bedrijf'); 
    }
  }

function preloadImages() {
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
  }

function preloadProjectImages(){
  preloadImages('assets/button_mnu_home.png', 'assets/button_mnu_company.png', 'assets/button_mnu_info.png', 'assets/button_mnu_contact.png', 'assets/button_mnu_home_push.png', 'assets/button_mnu_company_push.png', 'assets/button_mnu_info_push.png', 'assets/button_mnu_contact_push.png', 'assets/scroll-normal.png','assets/scroll-down.png','assets/scroll-up.png');

  new PNG("home", "assets/button_mnu_home.png");
  new PNG("company", "assets/button_mnu_company.png");  
  new PNG("info", "assets/button_mnu_info.png");
  new PNG("contact", "assets/button_mnu_contact.png");  
  }
  
window.onload = function() {  
  setContent();
  initScrollLayer();  
  preloadProjectImages();
	}
window.onresize = function() {
  setContent();
  preloadProjectImages();
	}
window.onfocus = function(){
  preloadProjectImages();
  }

function SendContactForm(){  
  //Fill in values
  document.getElementById("action").value = "send";
  var send = true;
  //check valid emailadres
  if(!isValidEmail(document.getElementById("email").value)) {
    document.getElementById("contactmessage").innerHTML = "Gelieve correct EMAILadres in te vullen";
    send = false;
    }
  //check email and question
  if(trim(document.getElementById("email").value) == "" || trim(document.getElementById("vraag").value) == ""){
    document.getElementById("contactmessage").innerHTML = "Gelieve EMAIL & VRAAG in te vullen aub";
    send = false;
    }
  if(send == true){  
    document.getElementById("contactform").submit();
    }
  }
function ResetMessage(){
  document.getElementById("contactmessage").innerHTML = "";
  }
function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}

/*  
function CheckPngElements(){
  var el2check = new Array("div","h1","p","ul","li");  
  var el2check = new Array("div");    
  obj = document.getElementById("container");
  for (i=0; i<el2check.length; i++){
    var actcheck = obj.getElementsByTagName(el2check[i]);
    //window.alert(actcheck.length);
    
    for(j=0;j<actcheck.length;j++){
      img = document.getElementById(actcheck[j].id);
      if(img.currentStyle){
        bkgImg = img.currentStyle.backgroundImage;
        }
      else{
        bkgImg = getComputedStyle(img, null).getPropertyValue('background-image');
        window.alert("e" + bkgImg);        
        }
      if(bkgImg != "none"){
        //new PNG(actcheck[j].id, bkgImg);
        }
      }
    }
  }*/
   
var isExp = (navigator.userAgent.indexOf("MSIE") != -1 && navigator.userAgent.indexOf("Opera") == -1);
var isnotIE7 = false;

if(isExp){
  var version = navigator.userAgent.split("MSIE ")[1];
  version = version.split(";")[0];
  version = parseInt(version);
  isnotIE7 = (version < 7);
  }  

function PNG(htmlDiv, png){
  if (isExp && isnotIE7){
    if (document.getElementById(htmlDiv)){
      this.div = document.getElementById(htmlDiv);
	    this.png = png;
      this.makeTransparent();
      }
    }
  }

PNG.prototype = {
  makeTransparent: function(){
    this.div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src = '" + this.png + "', sizingMethod = 'scale')";
    this.div.style.backgroundImage = "url('pixel.gif')";
    }
  }
  
function ClickContactPerson(person){
  var cp_array = new Array("lindseth", "kristof", "willy");
  for(var i=0;i<cp_array.length;i++){
    var checkbox = "contperscheck_" + cp_array[i];
    if(person == cp_array[i]){
      if(person == document.getElementById("activecontactpersoon").value){
        document.getElementById("activecontactpersoon").value = "";
        img = "assets/vink-off.png";
        }
      else{
        document.getElementById("activecontactpersoon").value = person;
        img = "assets/vink-on.png";
        }      
      }
    else{
      img = "assets/vink-off.png";
      }    
    if(document.all){
      document.getElementById(checkbox).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+img+",sizingMethod='scale')";
      }
    if(document.getElementById&&!document.all){
      document.getElementById(checkbox).src = img;
      } 
    }
  }
  
function CreateSlider(){
  document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="565px" height="370px" id="jukebox" align="middle">\n');
  document.write('<param name="movie" value="scrollhorizontal.swf" />\n');
  document.write('<param name="quality" value="high" />\n');
  document.write('<param name="wmode" value="transparent" />\n');
  document.write('<param name="bgcolor" value="#660000" />\n');
  document.write('<embed src="scrollhorizontal.swf" quality="high" wmode="transparent" bgcolor="#660000" width="565px" height="370px" name="jukebox" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></embed>\n');
  document.write('</object>\n');
  }
 
function CloudBuilder(){
  document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="579" height="227" id="vanoverbeke_clouds" align="top">');
  document.write('<param name="allowScriptAccess" value="sameDomain" />');
  document.write('<param name="movie" value="vanoverbeke_clouds.swf" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#000000" /><embed src="vanoverbeke_clouds.swf" menu="false" quality="high" wmode="transparent" bgcolor="#000000" width="579" height="227" name="vanoverbeke_clouds" align="top" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
  document.write('</object>');
  }
  
function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}
