function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' is geen geldig e-mail adres.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is verplicht.\n'; }
  } if (errors) alert('Gelieve volgende velden na te kijken:\n'+errors);
  document.MM_returnValue = (errors == '');
}// JavaScript Document
function MM_validateForm_extra() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_extra.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name;  if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' is geen geldig e-mail adres.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is verplicht.\n'; }
  } 
  
  if( !document.getElementById("akkoord").checked ) errors+='- Je moet de privacy voorwaarden aanvaarden.\n';
  
  if (errors) alert('Gelieve volgende velden na te kijken:\n'+errors);
  document.MM_returnValue = (errors == '');
}
function MM_validateForm_extra_nl() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_extra_nl.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name;  if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' is geen geldig e-mail adres.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is verplicht.\n'; }
  } 
  
  if( !document.getElementById("akkoord").checked ) errors+='- Je moet de privacy voorwaarden aanvaarden.\n';
  
  if (errors) alert('Gelieve volgende velden na te kijken:\n'+errors);
  document.MM_returnValue = (errors == '');
}
function MM_validateForm_extra_fr() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_extra_fr.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.id;  if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' is geen geldig e-mail adres.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' est obligatoire.\n'; }
  } 
  
  if( !document.getElementById("akkoord").checked ) errors+='- Il faut accepter les termes de protection de vie privée.\n';
  
  if (errors) alert('Veuillez s.v.p. vérifier les champs suivants::\n'+errors);
  document.MM_returnValue = (errors == '');
}
function set_class(what,Sclass){ 			
	var currTabElem = document.getElementById(what);
	currTabElem.setAttribute("class", Sclass);
	currTabElem.setAttribute("className", Sclass); 
}
function get_map(street){
		  google.load("maps", "2");
		  function initialize() {
			var map = new google.maps.Map2(document.getElementById("map"));
			//map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);
			map.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5, 5))); 
			map.addControl(new GLargeMapControl()); 
			
			var geocoder = new GClientGeocoder();
			geocoder.getLatLng(street,
			  function(point){
				 if(point){
					 var marker = new GMarker(point);
					 map.setCenter(point, 13);
					 map.addOverlay(marker);
				  }
				  else{
					 //not found, hide the GoogleMaps div
					 element.style.visibility = 'hidden';
				  }
			   }
			); 
		  }
		  google.setOnLoadCallback(initialize);
}
function addEvent( obj, type, fn )
{	
	try {
		if (obj.addEventListener) 
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) 
		{
			obj["e" + type + fn] = fn;
			obj[type + fn] = function(){
				obj["e" + type + fn](window.event);
			}
			obj.attachEvent("on" + type, obj[type + fn]);
		}
	}
	catch(e) {
		//console.log(obj)
		//console.log(e.message)
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

function stopEvent(e)
{
	if(e.preventDefault)
		e.preventDefault();
	else
		e.returnValue = false
}

function getEvent(e)
{
	if (!e)
		return window.event;
	return e;
}

function maintabs(activetab) {
    if(this != window)
    {
        var activetab = this.getAttribute('rel');
    }
    
    for (i=1; i <= 4; i++)
    {
        document.getElementById("tablink"+i).className='tab'+i;
        document.getElementById("submenu"+i).style.display = 'none';
    }
    
    if(document.getElementById("tablink"+ activetab))
    {
		document.getElementById("tablink" + activetab).className = 'tabactive';
		document.getElementById("submenu" + activetab).style.display = 'block';
    }
}

function changeTabCases()
{
    $('#tabspanel_cases > ul').tabs('rotate', null);
    $('#tabspanel_cases > ul').tabs('select', this.getAttribute('rel'));
    if(document.getElementById('activeCaseTab'))
    {
        document.getElementById('activeCaseTab').id = '';
    }
    this.id = 'activeCaseTab';
    return false;
}

addEvent(window,'load', function(){
    if(document.getElementById('tabspanel_cases2'))
    {
        var nodes = document.getElementById('tabspanel_cases2').getElementsByTagName('a');
        for(var i=0; i < nodes.length; i++)
        {
            nodes[i].onclick = changeTabCases;
        }
    }
})

function opacity(id, inout) {
    //speed for each frame
    millisec=500;
    var speed = Math.round(millisec / 100);
    var timer = 0;
    if(inout=="out") {
        for(i = 100; i >= 0; i--){
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(inout=="in") {
        for(i = 0; i <= 100; i++){
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;    
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}


function toggleElement(oldElement, newElement)
{
    document.getElementById(oldElement).style.display='none';
    changeOpac(0,newElement);
    document.getElementById(newElement).style.display='block';
    opacity(newElement, "in");
}

function switchTab(container_id, obj)
{
    toggleElement(document.getElementById("active_" + container_id).getAttribute('rel'), obj.getAttribute('rel'));
    document.getElementById("active_" + container_id).id = '';
    obj.id = "active_" + container_id;
    
	//alert(obj.id)
	
    clearInterval(intervallist[container_id])
}


function opentab(newref)
	{
	var oldref = document.getElementById("active_box_services_content").getAttribute('rel');
	toggleElement(oldref, newref);
	document.getElementById("active_box_services_content").id = "";
	$("a[rel='" + newref + "']").attr('id','active_box_services_content');
	return false;
	}


function rotate(container_id)
{
    try { //voor IE
        var obj = document.getElementById("active_" + container_id).parentNode.nextSibling.getElementsByTagName('a')[0];
    }
    catch(err)
    {
        try { // voor FF
            var obj = document.getElementById("active_" + container_id).parentNode.nextSibling.nextSibling.getElementsByTagName('a')[0];
        }
        catch(err) { 
            var obj = document.getElementById(container_id).getElementsByTagName('a')[0];
        }
    }
    
    document.getElementById("active_" + container_id).id = '';
    obj.id = "active_" + container_id;
    
    toggleElement(obj.getAttribute('previous'), obj.getAttribute('rel'))
}

var intervallist = new Object;
function initTabs(container_id, time)
{    
    var nodes = document.getElementById(container_id).getElementsByTagName('a');
    var previousID = nodes[nodes.length-1].getAttribute('rel');
        
    for(var i=0; i < nodes.length; i++)
    {
        nodes[i].setAttribute('previous',previousID);
        var previousID = nodes[i].getAttribute('rel');
        
		if (previousID != null) {  //added by Tom, javascript Master
			addEvent(nodes[i], 'click', function(e){
				stopEvent(getEvent(e))
				switchTab(container_id, this)
			});
		}
    }

    intervallist[container_id] = setInterval("rotate('"+ container_id +"')",time)
}

