function checkNav() {
  if (!document.getElementById) {
    clearInterval(domload)
    domload = null;
    return false; 
  }
  if (document.getElementById("menu") && !menuInit) {
    clearInterval(domload);
    $('menu').setStyle('opacity',0);
    domload = null;
    return true;
  } else {
    return false;
  }
}
var menuInit = false;
var domload = setInterval("checkNav()", 25);

var toggleContent = function() {
    if (this.hasClass('openContent')) {
        this.removeClass('openContent');
        this.getElement('img').setAttribute('src','/_images/bread.gif');
        this.getElement('img').setAttribute('width','5');
        this.getElement('img').setAttribute('height','10');
        this.getElement('img').setStyle('padding','0px 3px');
        if (this.getNext().tagName == 'DIV') {
            this.getNext().setStyle('display', 'none');
        }
        if (this.getNext().getNext().tagName == 'FORM') {
            this.getNext().getNext().setStyle('display', 'none');
        }
    } else {

        $('hp500').getElements('.openContent').each(function(content) {
            toggleContent.apply(content);
        });

        this.addClass('openContent');
        this.getElement('img').setAttribute('src', '/_images/arrow_down.gif');
        this.getElement('img').setAttribute('width','11');
        this.getElement('img').setAttribute('height','5');
        this.getElement('img').setStyle('padding','3px 0px');
        if (this.getNext().tagName == 'DIV') {
            this.getNext().setStyle('display', 'block');
        }
        if (this.getNext().getNext().tagName == 'FORM') {
            this.getNext().getNext().setStyle('display', 'block');
        }
    }
}

window.addEvent('domready',function() {
  //Op de homepage is het logo geen link
  if (location.pathname == '/') {
    var logoimg = $('logolink').getChildren()[0];
    $('logolink').replaceWith(logoimg);
  }
  
  showMenu();
  makeAnchors();
  setHeight();
  setSideContentOpacity();
  var hotspotImg = '/_images/btn_chk.png'; //'/_images/hotspot_o.png';
  if ($('hp500_hotspot_1')) {
    $('hp500_hotspot_1').addEvent('mouseenter', function() {
        $(this).setProperty('src', hotspotImg);
        $('hp500_hotspot_text').setHTML('<h4>No mistints and nozzle issues with our RNC</h4><p>With current simultaneous dispensers the nozzles often produce problems. Examples of this are contamination (intermixing of colorants) and drying of colorants. Only intensive and frequent cleaning can prevent these problems. Such cleaning is a difficult and time-consuming task for the operator.</p><p>For the HP500 we have developed a unique system: <strong>Rotary Nozzle Closure (RNC)</strong>.</p><p><strong>Operation</strong>: immediately after dispensing, all nozzles are closed with an airtight seal by a metal plate. This plate is then cleaned automatically with a brush and cleaning fluid.</p><p><strong>Result</strong>: no residue left to dry. The only maintenance that the operator has to perform is refilling the fluid in the brush tray.</p><p><strong>Conclusion: No loss of time and no mistints due to contamination.</strong></p>');
        $('hp500_hotspot_text').setStyle('display', 'block');
    })
  }

  if ($('hp500_hotspot_2')) {
    $('hp500_hotspot_2').addEvent('mouseenter', function() {
        $(this).setProperty('src', hotspotImg);
        $('hp500_hotspot_text').setHTML('<h4>Always optimal conditions for your colorants with our IPS & IPR</h4><p>The HP500 has been specially developed to be capable of operating with all types of colorants. Each colorant has unique properties and the HP is therefore equipped with two innovative systems:</p><ol><li><strong>IPS</strong>: Individually Programmable Stirring</li><li><strong>IPR</strong>: Individually Programmable Recirculation</li></ol><p><strong>What are the benefits of IPS?</strong><br />With this function you can set the stirring frequency and duration individually for each colorant. This prevents sedimentation in the canister. Where required by the paste, IPS enables you to limit stirring.</p><p><strong>What can IPR mean for you?</strong><br />In order to prevent sedimentation in the hoses the HP500 provides the possibility of applying recirculation. As this is not always necessary or desirable, you can configure the number of recirculation lines and the settings individually.</p>');
        $('hp500_hotspot_text').setStyle('display', 'block');
    })
  }

 if ($('hp500_hotspot_3')) {
    $('hp500_hotspot_3').addEvent('mouseenter', function() {
        $(this).setProperty('src', hotspotImg);
        $('hp500_hotspot_text').setHTML('<h3>High speed simultaneous dispensing 0.3 - 0.5L/min</h3>');
        $('hp500_hotspot_text').setStyle('display', 'block');
    })
  }

  if ($('hp500_hotspot_4')) {
    $('hp500_hotspot_4').addEvent('mouseenter', function() {
        $(this).setProperty('src', hotspotImg);
        $('hp500_hotspot_text').setHTML('<h4>Easy service with the proven HA</h4><p>Contrary to the turntable dispenser, all pump canister modules of the HP 500 are mounted statically in the frame. Each module consists of the following elements:</p><ul><li>a canister</li><li>a piston pump</li><li>the Blendorama disk valve</li><li>2 motors</li><li>a PCB</li></ul><p>All these components have proven reliability. Each pump is individually driven, as a result of which the HP500 can dispense simultaneously through four channels with great accuracy.</p><p>This makes the HP500 one of the very fastest dispensers in the market. A major advantage of the modular construction is that modules can be replaced individually. If a fault occurs in a module, the machine can simply continue in operation.</p>');
        $('hp500_hotspot_text').setStyle('display', 'block');
    })
  }

  if ($('hp500_hotspot_5')) {
    $('hp500_hotspot_5').addEvent('mouseenter', function() {
        $(this).setProperty('src', hotspotImg);
        $('hp500_hotspot_text').setHTML("<h4>Every operator's favourite: Optimum ergonomics</h4><p>In addition to all the above-mentioned benefits of the HP500, which already make the operator's life a lot easier, we have endeavoured to achieve a design that provides optimum ergonomics for the operator.</p><p>This provides the operator with: good refilling height and all requisites within reach (keyboard, screen, label printer).</p>");
        $('hp500_hotspot_text').setStyle('display', 'block');
    })
  }

  if ($('hp500')) {
    $('hp500').getElements('h2').each(function(handler) {
        handler.addEvent('click', toggleContent);
    });
  }

  if ($('newsname') && $('newsemail')) {

	  //alert('JA');
  
	  $('newsname').addEvent('focus', function() {
		if ($('newsname').value == 'Name') {
			$('newsname').value = '';
		}
	  });

	  $('newsname').addEvent('blur', function() {
		if ($('newsname').value == '') {
			$('newsname').value = 'Name';
		}
	  });

	  $('newsemail').addEvent('focus', function() {
		if ($('newsemail').value == 'E-mail') {
			$('newsemail').value = '';
		}
	  });

	  $('newsemail').addEvent('blur', function() {
		if ($('newsemail').value == '') {
			$('newsemail').value = 'E-mail';
		}
	  });
  }
  
  $('q').addEvent('focus', function() {
	if ($('q').value == 'Search') {
		$('q').value = '';
	}
  });

  $('q').addEvent('blur', function() {
	if ($('q').value == '') {
		$('q').value = 'Search';
	}
  });

});
/*----------------------------------------------------------------------------------------------------*/

function makeAnchors()
{
	var i = 1;
	if (location.href.contains('prismapro'))	{
		$$("h3").each(function(el) { el.id = "f" + i; i++ });
	}
}

/*----------------------------------------------------------------------------------------------------*/

function setHeight() {
  var contentHeight = $('main').getStyle('height').toInt();
  var minHeight = 200;
  if (contentHeight == minHeight){
	  $('main').setStyle('height', 'inherit');
  }
  if (contentHeight < minHeight) $('main').setStyle('height',minHeight+'px');
}

/*----------------------------------------------------------------------------------------------------*/
function showMenu() {
  myLocation = location.pathname;

  if (myLocation == '/software/login.asp') myLocation = '/software/';
  if (myLocation == '/options/login.asp') myLocation = '/options/';
  if (myLocation == '/options/index.asp') myLocation = '/options/';
  
  if (myLocation != '/' && myLocation != '/products/' && myLocation != '/ecs/' && myLocation != '/search/' && myLocation != '/downloads/' && myLocation != '/service/' && myLocation != '/chinese/') {
    var divId = myLocation.replace(/\//g,'');
    
    if (divId == 'news' || divId == 'careers' || divId == 'exhibitions' || divId == 'contact') divId = 'about'; 
	if (divId == 'options') divId = 'options';

    if ($$('#'+divId+' .submenu') != '') {
		$$('#'+divId+' .submenu').setProperty('id','active');

		// Create div-spacer, width the submenu's height
		var spacer = new Element('div');
		var subHeight = $('active').getStyle('height').toInt()+50;
		spacer.setStyle('height',subHeight+'px');
		var sidecontent = $$('#content .left')[0];
		if (sidecontent.getFirst()) spacer.injectBefore(sidecontent.getFirst());
    }
  }
  //getActiveMenu();
  $('menu').setStyle('opacity',1);
  menuInit = true;
}
/*----------------------------------------------------------------------------------------------------*/

function getActiveMenu() {
  var width = 0;
  var i, leftDist;
  $('active').getChildren().each(function(li) {
    i = li.getStyle('width').toInt()
    width = width + i;
  });
   
  $$('.submenu').each(function(hide) {
    if (hide.getProperty('id') != 'active') hide.setStyle('display','none');
  });
}
/*----------------------------------------------------------------------------------------------------*/

function setSideContentOpacity() {
  $$('.sidecontent').each(function(sideContent) {
    var height = sideContent.getChildren()[0].getStyle('height');
    var innerdiv = new Element('div',{
      'styles': {
        'height': height,
        'opacity': 0.7
      },
      'class': 'transbg'
    });
    sideContent.setStyle('height',height);
    innerdiv.injectInside(sideContent);
  });
}
/*----------------------------------------------------------------------------------------------------*/

function selectedLink(link) {
  $$('#productsubnav a').each(function(subLink) {
    subLink.removeClass('selected');
  });
  $(link).addClass('selected');
}

/*----------------------------------------------------------------------------------------------------*/

function toggleSub(aId) {
  var subHeight = 10;
  var sub = $(aId).getParent().getChildren()[1];
  if (sub.getStyle('display') == 'none') {
    sub.setStyle('display','block');
    subHeight = subHeight + sub.getStyle('height').toInt();
    $$('.sidecontent').getChildren()[0].each(function(div) {
      var divHeight = div.getStyle('height').toInt();
      div.setStyle('height',divHeight+subHeight+'px  ');
    });
    $$('.sidecontent')[0].setStyle('height',$$('.sidecontent')[0].getStyle('height').toInt()+subHeight+'px  ');
  } else {
    subHeight = subHeight + sub.getStyle('height').toInt();
    sub.setStyle('display','none');
    $$('.sidecontent').getChildren()[0].each(function(div) {
      var divHeight = div.getStyle('height').toInt();
      div.setStyle('height',divHeight-subHeight+'px  ');
    });
    $$('.sidecontent')[0].setStyle('height',$$('.sidecontent')[0].getStyle('height').toInt()-subHeight+'px  ');    
  }
}

/*----------------------------------------------------------------------------------------------------*/
function getProductData(prodId,dataDescr) {
  var myProduct = new Ajax('/_private/ajax.asp?rnd='+$random(10,999)+'&product='+prodId+'&'+dataDescr,{method:'get',update:$('main')});
  myProduct.request().chain(setHeight).chain(updateLinks);
}
/*----------------------------------------------------------------------------------------------------*/
function updateRegionInfo(regionId) {
  var region = new Ajax('/_private/ajax.asp?rnd='+$random(10,999)+'&region='+regionId,{method:'get',update:$('regioninfo')});
  if (regionId == "") {
	$("googlemap").setStyle("display", "block");
	$("regioninfo").setStyle("display", "none");
  } else {
	$("googlemap").setStyle("display", "none");
	$("regioninfo").setStyle("display", "block");
  }
  region.request().chain(setHeight);
}

/*function updateRegionInfo(regionId)
{
	window.location = "?addresses=1&continent=" + regionId;
}*/

/*----------------------------------------------------------------------------------------------------*/
function getProdsByCat(catId) {
	
	$('downloadproduct').innerHTML = '';
	$('downloadtype').innerHTML = '';
	
	if (catId != '') {
		var prodcat = new Ajax('/_private/ajax.asp?rnd='+$random(10,999)+'&prodbycat='+catId,{method:'get',update:$('downloadproduct')});
		prodcat.request();
	}

	getDownloadItems()
}

/*----------------------------------------------------------------------------------------------------*/
function showDownloadTypes(prodId) {

	$('downloadtype').innerHTML = '';
	
	if (prodId != '') {
		var downcat = new Ajax('/_private/ajax.asp?rnd='+$random(10,999)+'&downloadtypes=1',{method:'get',update:$('downloadtype')});
		downcat.request();
	}

	getDownloadItems()
}

/*----------------------------------------------------------------------------------------------------*/
function getDownloadItems() {

	var dCat  = $('groupfilter')   ? $('groupfilter').options[$('groupfilter').selectedIndex].text : 'empty';
	var dProd = $('productfilter') ? $('productfilter').value : 'empty';
	var dType = $('typefilter')	   ? $('typefilter').value	  : 'empty';

	if (dCat == 'Choose a productgroup...')	{
		dCat = 'empty';
	}

	var downloads = new Ajax('/_private/ajax.asp?rnd='+$random(10,999)+'&getdownloaditems=1&dcat=' + dCat + '&dprod=' + dProd + '&dtype=' + dType,{method:'get',update:$('downloaditems')});
	downloads.request();
}


/*----------------------------------------------------------------------------------------------------*/
function showDownTypes(catId) {
  var downType = new Ajax('/_private/ajax.asp?rnd='+$random(10,999)+'&downtypes='+catId,{method:'get',update:$('downtype')});
  downType.request();
}

/*----------------------------------------------------------------------------------------------------*/
function showDownloads(downType,prodId) {
  var downloads = new Ajax('/_private/ajax.asp?rnd='+$random(10,999)+'&getdownloads='+prodId+'&type='+downType,{method:'get',update:$('downloadresult')});
  downloads.request();
}

/*----------------------------------------------------------------------------------------------------*/
function updateDownCount(downType,userId,softwareId) {
  var count = new Ajax('/_private/ajax.asp?rnd='+$random(10,999)+'&updatedownload='+softwareId+'&user='+userId+'&type='+downType,{method:'get'});
  count.request();
}

function updateLinks()
{
	$$('a[rel=external]').each(function(extLink) {
		extLink.setProperty('target', '_blank');
	});
}


window.addEvent('domready',function() {
  // External links open in new window
  $$('a[rel=external]').each(function(extLink) {
    extLink.setProperty('target','_blank');
  });
  
  if($$('form')[0]) {
    var myForm = new Form($$('form')[0]);
  }

  if ($('newsform')) {
	var myNewsForm = new Form($('newsform'));
  }

});

var Form = new Class({
  initialize: function(frm) {
    this.form = frm;
    this.form.addEvent('submit',this.frmCheck);
  },
   
  frmCheck: function(ev) {

    var misFld = false;
    var e = new Event(ev);
    e.stop();

	if (this.newsname) {
		if (this.newsname.value == 'Name') {
			this.newsname.value = '';
		}
	}

	if (this.newsemail) {
		if (this.newsemail.value == 'E-mail') {
			this.newsemail.value = '';
		}
	}
    
    $$('.reqFld').each(function(fld) {
      fld.removeClass('missingField');
      if(fld.getValue() == '') {
        fld.addClass('missingField');
        misFld = true;
      }
    });
    if(misFld == true) {
      alert('Missing required fields.');
    } else {
	  this.submit();
    }
  }
});