
/** check if all required fields are not empty in login form **/
function check_loginform(theForm) {
  if (theForm.loginname.value=='') {
    alert(words['emptyloginname']);
    theForm.loginname.focus();
    return false;
  }
  if (theForm.password.value=='') {
    alert(words['emptypassword']);
    theForm.password.focus();
    return false;
  }
  return true;
}

/** check if all required fields are not empty in contact form **/
function check_contactform(theForm) {
  if (theForm.naam.value=='') {
    alert(words['emptycontactachternaam']);
    theForm.naam.focus();
    return false;
  }
  if (theForm.bedrijf.value=='') {
    alert(words['emptycontactbedrijfsnaam']);
    theForm.bedrijf.focus();
    return false;
  }
  if (theForm.email.value=='') {
    alert(words['emptycontactemail']);
    theForm.email.focus();
    return false;
  }
  if (!checkemail(theForm.email.value)) {
    alert(words['nonvalidcontactemail']);
    theForm.email.focus();
    return false;
  }
  return true;
}

/** Email validation **/
function checkemail(str){
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	return (filter.test(str));
}

/** check if all required fields are not empty in search form **/
function check_searchform(theForm) {
  if (theForm.words.value=='' || theForm.words.value==words['defaultsearch']) {
    alert(words['emptywords']);
    theForm.words.focus();
    return false;
  }
  return true;
}

/** function to add events to windows onload **/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

              
/** Initialise topmenu **/
function initMenu() {
  for (key in menus) {
    var menu = document.getElementById(key);
    var submenu = document.getElementById(menus[key]);
    if(menu.attachEvent){ 
      menu.attachEvent('onmouseover', showSubmenu); 
    } else { 
      menu.addEventListener('mouseover',showSubmenu,false);
    }
    var width=parseInt(menu.getAttribute('width'))-16; // subtract padding
    if ((submenu.offsetWidth)<width) {
      submenu.style.width=width+'px';
    } else {
			// mie6 fix, make submenu wide enough to hold text 
			submenu.style.width=submenu.offsetWidth+'px';
		}
  }
  if (document.attachEvent){
    document.attachEvent('onclick',hideAllMenus);
  } else {
    document.addEventListener('click',hideAllMenus,false);
  }
}

function determineWidth() {
  return "200px";
}

/** Show the submenu of the menu the mouse is hovering over**/
function showSubmenu(e) {
  var menu;
  if (!e) var e = window.event;
  if (e.target) menu = e.target;
  else if (e.srcElement) menu = e.srcElement;
  if (menu.nodeType == 3) // opvangen Safari bug
    menu = menu.parentNode;
  var submenu=document.getElementById(menus[menu.id]);
  var left=parseInt(getX(menu));
  submenu.style.left=left+'px';
  var top=parseInt(getY(menu))+parseInt(menu.getAttribute('height'))+2;
  submenu.style.top=top+'px';
  for (key in menus) {
    if (key!=menu) {
      hideSubmenu(menus[key]);
    }
  }
  submenu.style.visibility='visible';
}

/** Hide submenu with given id **/
function hideSubmenu(id) {
  var submenu=document.getElementById(id);
  submenu.style.visibility='hidden';
}

/** Hide all submenus, except submenu or menu the mouse is on **/
function hideAllMenus(e) {
  var current;
  if (!e) var e = window.event;
  if (e.target) current = e.target;
  else if (e.srcElement) current = e.srcElement;
  if (current.nodeType == 3) // opvangen Safari bug
    current = current.parentNode;
  for (key in menus) {
    if (key!=current.id && current.id!=menus[key]) {
      hideSubmenu(menus[key]);
    }
  }
}

/** Get absolute top of element **/
function getY(oElement) {
  var iReturnValue = 0;
  while( oElement != null ) {
    iReturnValue += oElement.offsetTop;
    oElement = oElement.offsetParent;
  }
  return iReturnValue;
}

/** Get absolute left of element **/
function getX(oElement) {
  var iReturnValue = 0;
  while( oElement != null ) {
    iReturnValue += oElement.offsetLeft;
    oElement = oElement.offsetParent;
  }
  return iReturnValue;
}

/** Initialises searchform **/
function initSearchform() {
  var searchfield=document.searchform.words;
  if (searchfield.value=='') {
    searchfield.value=words['defaultsearch'];
  }
  if (searchfield.attachEvent){
    searchfield.attachEvent('onclick',initSearchvalue);
  } else {
    searchfield.addEventListener('click',initSearchvalue,false);
  }
}

/**  Initialises search field value when clicked upon **/
function initSearchvalue(e) {
  var searchfield=document.searchform.words;
  if (searchfield.value==words['defaultsearch']) {
    searchfield.value='';
  }
}

/** Load menu's and init searchfield on window load **/
addLoadEvent(function() {
  initMenu();
  initSearchform();
});

/** Initialise mootools info **/
window.addEvent('domready', function(){
  //store titles and text   
  $$('.Tips2').each(function(element,index) {   
    var content = element.get('title').split('::');
    element.store('tip:title', content[0]);   
    element.store('tip:text', '');   
  });  
  var Tips2 = new Tips($$('.Tips2'), {
    onShow: function(toolTip) {
      toolTip.fade('in');
    },
    onHide: function(toolTip) {
      toolTip.fade('out');
    }
  });
});

/** show information div whith dealer info **/
function showDealerInfo(motorId,autoId,autoId2) {
  var divTemplateObj=document.getElementById('country_info_template');
	if (motorId>0) {
	  var divMotorObj=document.getElementById('country_info_motor');
	  var html=divTemplateObj.innerHTML;
	  html=html.replace('{info}',dealerInformation['motor'][motorId]['info']);
	  html=html.replace('{image}','<img src="'+dealerInformation['motor'][motorId]['src']+'" width="76" height="103" align="left"/>');
	  html=html.replace('{name}',dealerInformation['motor'][motorId]['name']);
	  html=html.replace('{title}',words['motorBranche']);
	  divMotorObj.innerHTML=html;
	  divMotorObj.style.visibility='visible';
	}
	if (autoId>0) {
	  var divAutoObj=document.getElementById('country_info_auto');
	  var html=divTemplateObj.innerHTML;
	  html=html.replace('{info}',dealerInformation['auto'][autoId]['info']);
	  html=html.replace('{image}','<img src="'+dealerInformation['auto'][autoId]['src']+'" width="76" height="103" align="left"/>');
	  html=html.replace('{name}',dealerInformation['auto'][autoId]['name']);
		if (motorId > 0) {
		  html=html.replace('{title}', words['autoBranche']);
	  } else {
			html=html.replace('{title}', '');
		}
		divAutoObj.innerHTML=html;
	  divAutoObj.style.visibility='visible';
	}
  if (autoId2>0) {
    var divAutoObj=document.getElementById('country_info_auto2');
    var html=divTemplateObj.innerHTML;
    html=html.replace('{info}',dealerInformation['auto'][autoId2]['info']);
    html=html.replace('{image}','<img src="'+dealerInformation['auto'][autoId2]['src']+'" width="76" height="103" align="left"/>');
    html=html.replace('{name}',dealerInformation['auto'][autoId2]['name']);
    if (motorId > 0) {
      html=html.replace('{title}', words['autoBranche']);
    } else {
      html=html.replace('{title}', '');
    }
    divAutoObj.innerHTML=html;
    divAutoObj.style.visibility='visible';
  }
}

/** hide information div whith dealer info **/
function hideDealerInfo() {
  var divMotorObj=document.getElementById('country_info_motor');
  divMotorObj.style.visibility='hidden';
  var divAutoObj=document.getElementById('country_info_auto');
  divAutoObj.style.visibility='hidden';
  var divAuto2Obj=document.getElementById('country_info_auto2');
  divAuto2Obj.style.visibility='hidden';
}

/** dealer information **/
var dealerInformation = { 'motor': { '1': { 'name': 'Minne de Vries',
                                            'info': '06-51 602 686<br/>minne.de.vries@forte-nwe.com',
                                            'src' : '/images/people/benelux/MinnedeVries.jpg' 
                                          },
                                     '2': { 'name': 'Guus Rijken',
                                            'info': '06-54 927 741<br/>guus.rijken@forte-nwe.com',
                                            'src' : '/images/people/benelux/GuusRijken.jpg' 
                                          }
                                   },
                          'auto':  { '1' :{ 'name': 'Bert Visser',
                                            'info': '0627 446 422<br/>bert.visser@forte-nwe.com',
                                            'src' : '/images/people/benelux/bert-visser.jpg' 
                                          },
																	   '2' :{ 'name': 'Nico Griffijn',
                                            'info': '06-50 504 650<br/>nico.griffijn@forte-nwe.com',
                                            'src' : '/images/people/benelux/NicoGriffijn.jpg' 
                                          },
                                     '3' :{ 'name': 'Jan Pieter de Jong',
                                            'info': '06-22 514 156<br/>jan.de.jongforte-nwe.com',
                                            'src' : '/images/people/benelux/JanPieterDeJong.jpg' 
                                          },
                                     '4' :{ 'name': 'Anton Diender',
                                            'info': '06-55 181 965<br/>anton.diender@forte-nwe.com',
                                            'src' : '/images/people/benelux/AntonDiender.jpg' 
                                          },
                                     '5' :{ 'name': 'Willy van Sambeek',
                                            'info': '06-25 107 997<br/>willy.van.sambeek@forte-nwe.com',
                                            'src' : '/images/people/benelux/WillyvanSambeek.jpg' 
                                          },
                                     '6' :{ 'name': 'Ton Pol',
                                            'info': '06-51 237 251<br/>ton.pol@forte-nwe.com',
                                            'src' : '/images/people/benelux/TonPol.jpg' 
                                          },
                                     '7' :{ 'name': 'Egbert van Duursen',
                                            'info': '06-54 657 007<br/>egbert.van.duursen@forte-nwe.com',
                                            'src' : '/images/people/benelux/Egbert.jpg' 
                                          },
                                     '8' :{ 'name': 'Koos Stoop',
                                            'info': '06-53 804 306<br/>koos.stoop@forte-nwe.com',
                                            'src' : '/images/people/benelux/KoosStoop.jpg' 
                                          },
                                     '9' :{ 'name': 'Nico vd Water',
                                            'info': '06-55 834 838<br/>nico.van.de.water@forte-nwe.com',
                                            'src' : '/images/no_person.gif' 
                                          },
                                     '10':{ 'name': 'Cor De Gans',
                                            'info': '06-54 280 009<br/>cor.de.gans@forte-nwe.com',
                                            'src' : '/images/no_person.gif' 
                                          },
                                     '11':{ 'name': 'Fort&eacute; Noord-West Europa BV',
                                            'info': '0478 537555<br/>jan.cuijpers@forte-nwe.com',
                                            'src' : '/images/no_person.gif' 
                                          },
                                     '12':{ 'name': 'Peter van der Hoogt',
                                            'info': '06-54 224 189<br/>peter.van.der.hoogt@forte-nwe.com',
                                            'src' : '/images/people/benelux/PetervanderHoogt.jpg' 
                                          },
                                     '13':{ 'name': 'John vd Lans',
                                            'info': '06-18 559 719<br/>john.van.der.lans@forte-nwe.com',
                                            'src' : '/images/people/benelux/JohnvanderLans.jpg' 
                                          },
                                     '14':{ 'name': 'Joost Waleson',
                                            'info': '06-54 284 812<br/>joost.waleson@forte-nwe.com',
                                            'src' : '/images/people/benelux/JoostWaleson.jpg' 
                                          },
                                     '16':{ 'name': 'Marco Duinhoven',
                                            'info': '06-53 659 444<br/>marco.duinhoven@forte-nwe.com',
                                            'src' : '/images/people/benelux/MarcoDuinhoven.jpg' 
                                          },
                                     '17':{ 'name': 'Boy Claassen',
                                            'info': '06-21 815 170<br/>boy.claassen@forte-nwe.com',
                                            'src' : '/images/people/benelux/BoyClaassen.jpg' 
                                          },
                                     '18':{ 'name': 'Rob Hessing',
                                            'info': '06-13 703 137<br/>rob.hessing@forte-nwe.com',
                                            'src' : '/images/people/benelux/RobHessing.jpg' 
                                          },
                                     '19':{ 'name': 'Ruud van Helvoort',
                                            'info': '06-51 171 930<br/>ruud.van.helvoort@forte-nwe.com',
                                            'src' : '/images/people/benelux/RuudVanHelvoort.jpg' 
                                          },
                                     '20':{ 'name': 'Fort&eacute; Noord-West Europa BV ',
                                            'info': '+31 (0)478 - 537 555<br/>contact@forte-nwe.com',
                                            'src' : '/images/no_person.gif' 
                                          },
                                     '21':{ 'name': 'Fort&eacute; Noord-West Europa BV ',
                                            'info': '+31 (0)478 - 537 555<br/>contact@forte-nwe.com',
                                            'src' : '/images/no_person.gif' 
                                          },
                                     '22':{ 'name': 'Henny Manderveld',
                                            'info': '06-12 605 573<br/>henny.manderveld@forte-nwe.com',
                                            'src' : '/images/people/benelux/HennyManderveld.jpg' 
                                          },
                                     '23':{ 'name': 'Ren&eacute; Brands',
                                            'info': '06-42 000 515<br/>contact@forte-nwe.com',
                                            'src' : '/images/people/benelux/ReneBrands.jpg' 
                                          }
                                   }
                        };
