var map;
var Settings = new Array();;
var headerfotos = new Array;
var headernr = 0;
var editor = null;
var x      = 0;
var home_cat_actief = 0;
var sluitTimers = new Array();
var currentNumber = 4;
var totaalAantal = 0;
var l_verborgen = 1;
var r_verborgen = 0;
var sloganteller = 0;
var slogans = new Array();

var nu_links = 0;

var huidig_nr = 1;

var fader = new Array();
var hash = new Array();
var lijst = new Array();

function popUp(URL, breed, hoog) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=" + breed + ",height=" + hoog + ",left=150,top=150');");
}

function popUpcontent(name, inhoud, breed, hoog) {
  var generator=window.open(name,'popup','height=' + hoog + ',width=' + breed + 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,left=150,top=150');
  generator.document.write('<html><head><title>' + name + '</title><link rel="stylesheet" href="/css/site_popup.css" type="text/css"/></head><body>');
  generator.document.write(inhoud);
  generator.document.write('</body></html>');
  generator.document.close();
}

function htmlarealaden () {
	if (typeof (velden) == "object") {
		for (x=0; x < velden.length; x++) { 
        var oFCKeditor = new FCKeditor( velden[x] ) ;
        oFCKeditor.BasePath = webadres + "jsf/fckeditor/" ;
        oFCKeditor.Height	= 550;
				oFCKeditor.Width = 620;
				oFCKeditor.ToolbarSet = 'Default';
        //oFCKeditor.Config['ToolbarStartExpanded'] = false ;								
        oFCKeditor.ReplaceTextarea();		
		}
	}
}

function putfocus (formInst, elementInst) {
	if (document.forms.length > 0) {
		document.forms[formInst].elements[elementInst].focus();
		document.forms[formInst].elements[elementInst].select();
	}
}

function isset(variable_name)
{
try
{
if (typeof(eval(variable_name)) != 'undefined')
if (eval(variable_name) != null)
return true;
} catch(e) { }

return false;
}

function volgendeSlogan() {
  document.getElementById('slogan').innerHTML = slogans[sloganteller];
	sloganteller++;
	if (sloganteller >= slogans.length) {
	  sloganteller = 0;
	}
}


function parsepagina () {
	htmlarealaden();
	
	if (slogans.length) {
	  volgendeSlogan();
		
		if(slogans.length > 1) {
	    setInterval(function() { volgendeSlogan(); }, 5000);
		}
	}
}

window.onload = parsepagina;

function in_array(my_array,my_value){
	caseSensitive = in_array.arguments.length<3?0:in_array.arguments[2];

	for(i=0;i<my_array.length;i++){
		if((caseSensitive==0?my_array[i]:my_array[i].toUpperCase())==(caseSensitive==0?my_value:my_value.toUpperCase())){
			return true;
		}
	}

	return false;
}

function hasOptions(obj) {if (obj!=null && obj.options!=null) { return true; }	return false;}
function swapOptions(obj,i,j) {	var o = obj.options;	var i_selected = o[i].selected;	var j_selected = o[j].selected;	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);	o[i] = temp2;o[j] = temp;o[i].selected = j_selected;o[j].selected = i_selected;}
function moveOptionUp(obj) {if (!hasOptions(obj)) { return; }	for (i=0; i<obj.options.length; i++) {if (obj.options[i].selected) {if (i != 0 && !obj.options[i-1].selected) { swapOptions(obj,i,i-1);	obj.options[i-1].selected = true;}}} volgordeclasses ();}
function moveOptionDown(obj) {if (!hasOptions(obj)) { return; }	for (i=obj.options.length-1; i>=0; i--) {if (obj.options[i].selected) {if (i != (obj.options.length-1) && ! obj.options[i+1].selected) { swapOptions(obj,i,i+1);	obj.options[i+1].selected = true; }}} volgordeclasses ();}
function submitForm(url, veld) { var	list = document.getElementById(veld); 	var velden = '';	for (i = 0; i <= list.options.length - 1; i++) { 	velden = velden + '_SPLIT_' + list.options[i].value;}	window.location.href = url + velden; }
function volgordeclasses () {
	list		= document.getElementById('volgorde');
	var	kleur	= 'nee';

	for (i = 0; i <= list.options.length - 1; i++) {
		if (kleur == 'ja') {
			list.options[i].className = 'een';
			kleur = 'nee';
		} else {
			list.options[i].className = 'twee';
			kleur = 'ja';
		}

		if (typeof(volgordetitel) == "object") {
			for (a=0;a < volgordetitel.length;a++) {
				if (volgordetitel[a] == list.options[i].value) {
						list.options[i].style.color = 'red';
				}
			}
		}
	}
}

function agenda_kies () {
  select1 = document.getElementById('agenda_jaar');
	
	document.location.href = webadres + 'agenda/' + select1.value;
}

function agenda_kies2 () {
  select1 = document.getElementById('agenda_jaar');
	select2 = document.getElementById('agenda_maand');
	
	document.location.href = webadres + 'agenda/' + select1.value + '/' + select2.value;
}

function weergeefSWF(src, width, height, id, flashvars) {
   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="' + width + '" height="' + height + '" id="' + id + '" align="middle">');
   document.write('<param name="wmode" value="transparent"><param name="flashvars" value="' + flashvars + '"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + webadres + 'swf/' + src + '" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />');
   document.write('<embed src="' + webadres + 'swf/' + src + '" flashvars="' + flashvars + '" quality="high" bgcolor="#ffffff" width="' + width + '" height="' + height + '" name="' + id + '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
   document.write('</object>');
}

function api (movie) {
  document.write('<object type="application/x-shockwave-flash" data="' + webadres + 'flv/flvplayer.swf" width="450" height="337"><param name="movie" value="' + webadres + 'flv/flvplayer.swf"><param name="flashvars" value="file=' + movie + '"></object>');
}

function scroll_down () {
  box = document.getElementById('fotothumbs');
	
	box.scrollTop = box.scrollTop + 2;
}

function scroll_up () {
  box = document.getElementById('fotothumbs');
	
	box.scrollTop = box.scrollTop - 2;
}

function set_scroll_down (type) {
  if (type) {
	 down_timer = setInterval('scroll_down()', 5); 
	} else {
	 clearInterval(down_timer);
	}
}

function set_scroll_up (type) {
  if (type) {
	 up_timer = setInterval('scroll_up()', 5); 
	} else {
	 clearInterval(up_timer);
	}
}

function selecteerSubCategorieVan(id, checked) {
  box = document.getElementById('cat' + id);
	
	if (checked) {
	  box.checked = false;
	}
}

function neemContactOp(advertentie_id) {
  box1 = document.getElementById('contact_naam');
  box2 = document.getElementById('contact_email');
  box3 = document.getElementById('contact_bericht');	
	box4 = document.getElementById('contact_box');
	
	if (!box1.value || !box2.value || !box3.value || box1.value == 'naam..' || box2.value == 'email..' || box3.value == 'Bericht..') {
	  alert('Vul eerst uw gegevens in');
	} else {
    var req = new XMLHttpRequest();
    if (req) {
      req.onreadystatechange = function() {
        if (req.readyState == 4 && (req.status == 200 || req.status == 304)) {
          //alert(req.responseText + 'test' + box1.value);
					box4.innerHTML = '<strong>Uw bericht is verzonden.</strong>';
        }
      };

      req.open('POST', webadres + 'php/verwerk/contact.php?advertentie=' + advertentie_id + '&naam=' + box1.value + '&email=' + box2.value + '&bericht=' + box3.value);
      req.send(null);
    }	
	}
}

function fadeObject(id, c1, c2, s1, s2) {
  var self = this;
  this.id      = id;
  this.elem    = false;
  this.colour  = {
    stt: [parseInt(c1.substr(0, 2), 16), parseInt(c1.substr(2, 2), 16), parseInt(c1.substr(4, 2), 16)],
    end: [parseInt(c2.substr(0, 2), 16), parseInt(c2.substr(2, 2), 16), parseInt(c2.substr(4, 2), 16)],
    now: [parseInt(c1.substr(0, 2), 16), parseInt(c1.substr(2, 2), 16), parseInt(c1.substr(4, 2), 16)]
  };
  this.steps   = [s1, s2];
  this.dir     = false;
  this.active  = false;
  this.queue   = [];
  this.msg     = [];
  this.message = 0;
  function d2h(num) {
    num = Math.round(num);
    return ((num < 16) ? "0" : "") + num.toString(16);
  }
  this.fade = function(message, direction) {
    this.elem = this.elem || document.getElementById(this.id);
    this.queue.push([message, direction]);
    for (var x = 0; x < this.queue.length; x++) {
      for (var y = x + 1; y < this.queue.length; y++) {
        if (this.queue[x][0] == this.queue[y][0] && this.queue[x][1] != this.queue[y][1]) {
          this.queue.splice(x, 1);
          this.queue.splice(y - 1, 1);
        }
      }
    }
    if (!this.active) setTimeout(function() { self.fadeLoop(); }, 10);
  };
  this.fadeLoop = function() {
    if (!this.active && this.queue.length) {
      if (this.dir && this.message != this.queue[0][0]) this.queue.unshift([this.message, false]);
      var msg = this.queue.shift();
      if (this.msg[msg[0]]) {
        this.active = true;
        this.elem.innerHTML = this.msg[this.message = msg[0]];
        this.dir = msg[1];
      }
    }
    if (this.dir) {
      var c1 = this.colour.stt, c2 = this.colour.end, s = this.steps[0];
    } else var c1 = this.colour.end, c2 = this.colour.stt, s = this.steps[1];
    for (var x = 0, cnow = "", inc = 0; x < 3; x++) {
      this.colour.now[x] += inc = (c2[x] - c1[x]) / s;
      cnow += this.colour.now[x] = (inc < 0) ? Math.max(this.colour.now[x], c2[x]) : Math.min(this.colour.now[x], c2[x]);
    } this.elem.style.color = "#" + d2h(this.colour.now[0]) + d2h(this.colour.now[1]) + d2h(this.colour.now[2]);
    if (cnow == c2.join("")) {
      this.active = false;
      if (!this.queue.length) {
        if (!this.dir) {
          if (this.msg[0]) {
            this.queue.push([0, true]);
            setTimeout(function() { self.fadeLoop(); }, 10);
          } else this.elem.innerHTML = "&nbsp;";
        }
      } else setTimeout(function() { self.fadeLoop(); }, 10);
    } else setTimeout(function() { self.fadeLoop(); }, 10);
  };
  if (window.addEventListener) {
    window.addEventListener('load', function() { self.fade(0, true); }, false); 
  } else if (window.attachEvent)
    window.attachEvent('onload', function() { self.fade(0, true); });
}


function throb(item) {

  // If the hash array does not have an entry for this item, initialise it at 2
  if (!hash[item]) hash[item] = 2;

  // Send a fade command using the hash array to tell us what parameters we should use
  fader[item].fade(Math.floor(hash[item] / 2), !(hash[item] % 2));

  // Call this function again for this same item after a certain amount of time
  setTimeout(function() { throb(item); }, (hash[item] % 2) ? 100 : 5000);

  // If we have exceeded the number of messages in this fader, start over again at 2
  if (++hash[item] > fader[item].msg.length * 2 - 1) hash[item] = 2;
}

function controleerDoorsturen() {
  box1 = document.getElementById('doorsturenemail1');
  box2 = document.getElementById('doorsturenemail2');
	
	if (!box1.value || !box2.value || box1.value == 'Vul een e-mailadres in' || box2.value == 'Vul een e-mailadres in') {
	  alert('Vul eerst beide e-mail adressen in.');
		return false;
	}
	
	return true;
}

function headerFoto() {
  headernr++;

	if (headernr >= headerfotos.length) {
	  headernr = 0;
	}
	
  //blendimage('headerfoto', 'headerfotoIMG', '/php/verwerk/org.php?code=' + headerfotos[headernr], 1000);
	document.getElementById('headerfotoIMG').src = '/php/verwerk/org.php?code=' + headerfotos[headernr];
}

function blendimage(divid, imageid, imagefile, millisec) { 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
     
    //set the current image as background 
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")"; 
     
    //make image transparent 
    changeOpac(0, imageid); 
     
    //make new image 
    document.getElementById(imageid).src = imagefile; 

    //fade in image 
    for(i = 0; i <= 100; i++) { 
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(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 vergrootFoto(product, foto) {
  box1 = document.getElementById('container1');
  box2 = document.getElementById('container2');
	box3 = document.getElementById('container3');
	
	box1.style.display = 'block';
	box1.style.height = height();
	box2.style.display = 'block';
	
	//box2.innerHTML = '<iframe src="' + webadres + 'php/verwerk/gallerij.php?pagina=' + pagina + '&foto=' + foto + '" width="612" height="540"></iframe>';
	box3.src = webadres + 'php/verwerk/gallerij.php?product=' + product + '&foto=' + foto;
}

function containerSluiten() {
  box1 = document.getElementById('container1');
  box2 = document.getElementById('container2');
	box3 = document.getElementById('container3');
	
	box1.style.display = 'none';
	box2.style.display = 'none';
}

function height() {
  //  if (document.all) 
  //      return document.body.offsetHeight;
  //  else if (document.layers)
  //      return document.body.document.height;
	return document.body.clientHeight;
}

function height() {
var theHeight;

if (window.innerHeight) {
theHeight=window.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight) {
theHeight=document.documentElement.clientHeight;
}
else if (document.body) {
theHeight=document.body.clientHeight;
}

return theHeight;
}

