var tmpimg = new Array();

function init() {
	//preloadImages();
}

document.observe('lightview:opened', function(event) {
  $('submenu').hide();
});

document.observe('lightview:hidden', function(event) {
  $('submenu').show();
});

function preloadImages() {
	tel = 0;
	for(i = 0; i < document.all.length; i++){
		if (document.all[i].tagName == 'IMG') {
			tmpimg[tel] = new Image();
			tmpimg[tel].src = document.all[i].src;
			tel = tel + 1;
		}
		if (document.all[i].tagName == 'TD' || document.all[i].tagName == 'TABLE') {
			if (document.all[i].background) {
				tmpimg[tel] = new Image;
				tmpimg[tel].src = document.all[i].background;
				tel = tel + 1;
			}
		}
	}
}

function CMSPopUp(url, wi, he, winm) {
	if (winm == 0) {
		window.open(url, 'OC', 'toolbar=0,location=0,directories=0,menubar=0,scrollbars=0,resizable=no,width=' + wi + ',height=' + he);
	} else {
		window.open(url, 'OC', 'toolbar=1,location=1,directories=1,menubar=1,scrollbars=1,resizable=yes,width=' + (wi + 16) + ',height=' + he);
	}
}

function startScroll(element, dir) {
	elementobj = document.getElementById(element);
	if (elementobj) {
		scroll_loop = true;
		if (scroll_loop == true) {
			if (element == 'fotoscroll') {
				if (dir == "up") {
					frames(element).scrollBy(0,-3);
				}
				if (dir == "down") {
					frames(element).scrollBy(0,3);
				}
				if (dir == "left") {
					frames(element).scrollBy(-3,0);
				}
				if (dir == "right") {
					frames(element).scrollBy(3,0);
				}
			} else {
				if (dir == "up") {
					frames(element).scrollBy(0,-1);
				}
				if (dir == "down") {
					frames(element).scrollBy(0,1);
				}
				if (dir == "left") {
					frames(element).scrollBy(-1,0);
				}
				if (dir == "right") {
					frames(element).scrollBy(1,0);
				}
			}
			scroll_timer = setTimeout("startScroll('" + element + "', '" + dir + "')", 1);
		}
	}
}

function stopScroll() {
  scroll_loop = false;
	clearTimeout(scroll_timer);
}

function isEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		if (string.search(/.com/) != -1 | string.search(/.nl/) != -1 | string.search(/.net/) != -1 | string.search(/.org/) != -1 | string.search(/.nu/) != -1 | string.search(/.biz/) != -1 | string.search(/.info/) != -1 | string.search(/.be/) != -1) {
			return true;
		}
	else
		return false;
}

function checkForm(formname) {
	elems = document.all(formname).elements;
	tel= 0;
	document.all(formname).fields.value = '';
	for(i = 0; i < elems.length; i++) {
		element = null;
		element = document.getElementById(elems[i].name + '_');
		document.all(formname).fields.value = document.all(formname).fields.value + elems[i].name + ',';
		if (element) {
			element.style.display = 'none';
			if (elems[i].value == '') {
				tel = tel + 1;
				element.style.display = '';
			} else {
				if (elems[i].type == 'checkbox') {
					if (elems[i].checked == false) {
						tel = tel + 1;
						element.style.display = '';
						element.style.color = '#FF0000';
					} else {
						element.style.display = '';
						element.style.color = '#000000';
					}
				}
				if (elems[i].name.substr(0,5) == 'email') {
					if (!isEmail(elems[i].value)) {
						tel = tel + 1;
						elems[i].value = 'geen geldige e-mail';
						element.style.display = '';
					}
				}
			}
		}
	}
	passerror = 0;
	if (document.all(formname).wachtwoord) {
		if (document.all(formname).wachtwoord.value != document.all(formname).herhaalwachtwoord.value) {
			passerror = 1;
			tel = tel + 1;
			document.all('wachtwoord_').style.display = '';
			document.all('herhaalwachtwoord_').style.display = '';
		}
	}
	element = document.getElementById('showcheck');
	if (tel == 0) {
		document.all(formname).submit();
	} else {
		if (passerror == 0) {
			element.innerHTML = '<font color="#FAD043"><b>* Vul alle verplichte velden in [' + tel + ']</b></font>';
		} else {
			element.innerHTML = '<font color="#FAD043"><b>* Herhaal je wachtwoord correct</b></font>';
		}
	}
}

function checkFoto() {
	if (fotofrm.all('foto').value == '') {
		element = document.getElementById('foto_');
		element.style.display = '';
		element = document.getElementById('showcheck');
		element.innerHTML = '<font color="#FAD043"><b>* Vul alle verplichte velden in [1]</b></font>';
	} else {
		tmpcheck =  fotofrm.all('foto').value.split('.');
		if (tmpcheck[(tmpcheck.length - 1)] == 'jpg' || tmpcheck[(tmpcheck.length - 1)] == 'JPG' || tmpcheck[(tmpcheck.length - 1)] == 'gif' || tmpcheck[(tmpcheck.length - 1)] == 'GIF') {
			document.all('fotofrm').submit();
		} else {
			element = document.getElementById('foto_');
			element.style.display = '';
			element = document.getElementById('showcheck');
			element.innerHTML = '<font color="#FAD043"><b>* Vul alle verplichte velden in [1]</b></font>';
		}
	}
}



function showFoto() {
		element = document.getElementById('showfoto');
		CMSPopUp('previousnext.php?img=' + element.src.replace('_t',''), 172, 129, 0)
}

function addFoto() {
		element = document.getElementById('fotourl');
		location = 'page.php?p_id=30&addfoto=' + element.value;
}

function delFoto() {
		element = document.getElementById('fotourl');
		location = 'page.php?p_id=30&delfoto=' + element.value;
}

var scrolling = false;

function scroll(by) { 
  if (scrolling) stopscroll(); 
  scrolling = setInterval('doscroll('+by+')', 100); 

} 

function stopscroll(by) { 
  if (scrolling) clearInterval(scrolling); 
  scrolling = false; 

} 

function doscroll(by) {
  var curtop = parseInt(document.getElementById('scroller').style.left, 10); 
  curtop += by;
  
  minvalue = 0 - document.getElementById('scroller').offsetWidth;
  minvalue += parseInt(document.getElementById('fotoscroll').style.width) - 10;

  if(curtop < minvalue) {
  	curtop = minvalue;
  }
  if(curtop > 0) {
  	curtop = 0;
  }
  document.getElementById('scroller').style.left = curtop + 'px'; 
}