/* Utility functions */
function addEvent(obj, evType, fn) {
  /* adds an eventListener for browsers which support it Written by Scott Andrew */
  if (obj.addEventListener) { obj.addEventListener(evType, fn, true); return true; }
  else if (obj.attachEvent) { var r = obj.attachEvent("on"+evType, fn); return r; }
  else { return false; }
}
function element(id) {
  var e = false;
  if (document.getElementById) { e = document.getElementById(id); }
  else if (document.all) { e = document.all(id); }
  return e;
}
// login
function toPassword(objOldInput) {
	var objNewElement = document.createElement('input');
	objNewElement.setAttribute('type', 'password');
    objNewElement.setAttribute('name', objOldInput.name);
    if(objOldInput.id) objNewElement.setAttribute('id', objOldInput.id);
    if(objOldInput.style) objNewElement.setAttribute('style', 'display:block;');
	objOldInput.parentNode.replaceChild(objNewElement, objOldInput);
	toPassword.el = objNewElement;
	setTimeout('toPassword.el.focus()',100);
	return true;
}
// menu functions
function hasULchildren(linode) {
	var uls = linode.getElementsByTagName('ul')[0];
	if(uls) return true;
	return false;
}
function efMenu(menuid, menutype) {
	var menudiv = element(menuid);
	var listitems = menudiv.getElementsByTagName('li');
	if(listitems){
		for(var i=0; i<listitems.length; i++){
			var listitem = listitems[i];
			if(hasULchildren(listitem)) {
				listitem.onmouseover = function (e) {
					if (this.firstChild.nodeName.toUpperCase() == 'A') {
						if(this.firstChild.className.indexOf('active') != -1) { this.firstChild.className = 'active mouse'; }
						else { this.firstChild.className = 'mouse'; }
					}
					for (var i=0; i < this.childNodes.length; i++) {
						var child = this.childNodes[i];
						if (child.nodeName.toUpperCase() == 'UL') {child.style.visibility = 'visible'; }
					}
					return false;
				};
				listitem.onmouseout = function (e) {
					for (var i=0; i < this.childNodes.length; i++) {
						var child = this.childNodes[i];
						if (child.nodeName.toUpperCase() == 'UL') {	child.style.visibility = 'hidden';}
					}
					if (this.firstChild.nodeName.toUpperCase() == 'A') {
						if(this.firstChild.className.indexOf('active') != -1){ this.firstChild.className = 'active'; }
						else { this.firstChild.className = ''; }
					}
					return false;
				};
			}
		}
	}
	return void(0);
}
// de functie displayResultBox wordt ook gebruikt in xdis.js
function displayResultBox(string){
	var objResultBox = element('results');
	if(objResultBox) objResultBox.innerHTML = string;
}
// config for EFbox
function EFdata(){
	this.href = '';
	this.title = '';
	this.content = '';
	this.hideble = false;
}
// config for google maps
function classConfig(){
	this.host = '';
}
var popup = '';
function openPopup(url, name, w, h, menubar, scroll){
	var centerX, centerY, windowLeft, windowTop;
	if(document.getElementById) {
		centerX = parseInt(screen.width / 2);
		centerY = parseInt(screen.height / 2);
	} else {
		centerX = parseInt(screen.availWidth / 2);
		centerY = parseInt(screen.availHeight / 2);
	}
	windowLeft = centerX - parseInt(w/2);
	windowTop = centerY - parseInt(h/2);
	var parameters  = 'toolbar=no,location=no,resizable=yes,menubar=' + menubar;
	parameters += ',width=' + w + ',height=' + h + ',top=' + windowTop + ',left=' + windowLeft;
	if(scroll != null) parameters += ',scrollbars=yes';
	if (!popup.closed && popup.location) {
  		popup.location.href = url;
 	} else {
 		popup = window.open(url, name, parameters);
  		if(!popup.opener) popup.opener = self;
 	}
	if (window.focus) {popup.focus()}
	return false;
}

function openResellerlocator(){
	openPopup('http://'+ef_config.host+'/resellerlocator', 'locator');
}
function foldBox(boxId, state){
	if(state == 'closed'){ $(boxId+" form").hide(); }
	$(boxId+" p.intro").css('cursor','pointer');
	$(boxId+" p.intro").click(function(){
		var checkElement = $(boxId+" form");
		if((checkElement.is('form')) && (checkElement.is(':visible'))) { $(boxId+" div.box").css('background','none'); checkElement.slideUp('normal'); return false; }
		if((checkElement.is('form')) && (!checkElement.is(':visible'))) { $(boxId+" div.box").css('background','url(/skins/default/pics/bgBoxContactEnd.jpg) no-repeat 0 100%'); checkElement.slideDown('normal'); return false; }
		return void(0);
	});
}
function loginReload(){
	var reload = function() {location.reload()}
	setTimeout(reload, 500);
}
function login(){
	var sName, sPass, auth = false, sbmt = false;
	var lform = element('loginform');
	if(lform){
		sName = lform.loginname.value;
		if(sName.indexOf('@') != -1 && document.getElementById('passwd').value=='') { $('#pass-temp').css("display","block"); }
		else {sbmt=true; }
		sPass = lform.loginword.value;
		if(sPass != ''){ sbmt=true; }
		if(sbmt == true){
		$.post('http://' +ef_config.host+ '/remote/logincheck.php', { username: sName, password : sPass },
	  		function(data){
	  			//als de gebruikersnaam nog niet ingevuld is
	  			if(sPass == ''){
	  				if(data.code == 'PASSWD' || data.code == 'ERROR') $('#pass-temp').css("display","block");
	  			}
	  			if(data.code == 'OK') { $('#loginFields').hide(); loginReload(); $('#loginresult').html('<p>'+data.value+'</p>'); }
				//zorgt ervoor dat een melding maar 1 keer wordt weergegeven
	  			var productElement = document.getElementById('melding');
	  			if (productElement != null){
	  				var remove = (productElement.parentNode).removeChild(productElement);
	  				$('#loginFields').append('<span id="melding">'+data.value+'</span>');
	  			}
	  			else{
	  				$('#loginFields').append('<span id="melding">'+data.value+'</span>');
	  			}
	  	}, 'json'); }
	}
	return void(0);
}
function forgotpass(){
	openPopup('http://'+ef_config.host+'/content/password.php?act=forgot', 'password',400, 420, 0 );
	return void(0);
}
function changepass(){
	openPopup('http://'+ef_config.host+'/content/password.php?act=change', 'password',400, 420, 0 );
	return void(0);
}
jQuery.fn.liScroll = function(settings) {
	settings = jQuery.extend({ travelocity: 0.04 }, settings);
	return this.each(function(){
		var $strip = jQuery(this);
		$strip.addClass("newsticker")
		var stripWidth = 0;
		var $mask = $strip.wrap("<div class='mask'></div>");
		var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");
		var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width
		$strip.find("li").each(function(i){
			stripWidth += jQuery(this, i).width();
		});
		$strip.width(stripWidth);
		var defTiming = stripWidth/settings.travelocity;
		var totalTravel = stripWidth+containerWidth;
		function scrollnews(spazio, tempo){
			$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
		}
		scrollnews(totalTravel, defTiming);
		$strip.hover(function(){
			jQuery(this).stop();
		},
		function(){
			var offset = jQuery(this).offset();
			var residualSpace = offset.left + stripWidth;
			var residualTime = residualSpace/settings.travelocity;
			scrollnews(residualSpace, residualTime);
		});
		$strip.css('visibility','visible');
	});
};

 function changePasswdBox()
 {
    $('#pass-temp').css("display","none");
    $('#passwd').css("display","block");
    document.getElementById('passwd').focus();
 }
 function restorePasswdBox()
 {
    if(document.getElementById('passwd').value=='')
    {
    	$('#pass-temp').css("display","none");
  		$('#passwd').css("display","none");
    }
    else{
    	$('#pass-temp').css("display","none");
    }
 }
