var debug = false;

function openWin(gt) {
		url = '/flashupload.php?goto=' + gt;
		wi = '400';
		he = '265';
		window.open(url, 'MEN_at_WORK', 'toolbar=0,location=0,directories=0,menubar=0,scrollbars=0,resizable=no,width=' + wi + ',height=' + he);
}

function openBDD() {
		url = '/bdd.php';
		wi = '640';
		he = '480';
		window.open(url, 'MEN_at_WORK', 'toolbar=0,location=0,directories=0,menubar=0,scrollbars=0,resizable=no,width=' + wi + ',height=' + he);
}

function openLookbook() {
		
		url = '/lookbook';
		wi = '1024';
		he = '768';
		window.open(url, 'MEN_at_WORK', 'toolbar=0,location=0,directories=0,menubar=0,scrollbars=0,resizable=no,width=' + wi + ',height=' + he);
	
	/*
		url = '/index.php?goto=lookbook';
		wi = '1024';
		he = '768';
		window.open(url, 'MEN_at_WORK', 'toolbar=0,location=0,directories=0,menubar=0,scrollbars=0,resizable=no,width=' + wi + ',height=' + he);
	*/
}

function closeWindow() {
	window.open('','_parent','');
	window.close();
}

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 callMusic() {
	var url = '/ajax.php';
	var pars = 'update=call&goto=music&musicstart=true';
	var myAjax = new Ajax.Request(url, {method: 'get', parameters: pars, onComplete: loadMusic});
}

function loadMusic(call) {
	elm_music = MM_findObj('music');
	
	tmpsplit = call.responseText.split('&');
	tmpmain = tmpsplit[3];
	tmpmain = tmpmain.replace('main=', '');
	tmpquery = tmpsplit[4];
	tmpquery = tmpquery.replace('querystring=', '');
	
	var url = '/ajax.php';
	var pars = 'update=music&main=' + tmpmain + '&querystring=' + tmpquery;
	var myAjax = new Ajax.Updater(elm_music, url, {method: 'get', parameters: pars});
}

function setContent(gt, elm) {
	var url = '/ajax.php';
	var pars = 'update=' + gt;
	var myAjax = new Ajax.Updater(elm, url, {method: 'get', parameters: pars});
}

function callPage(gt) {
	// Debug
	if (debug == true) {
		//alert(gt);
	}
	// -
	
	// Google Analytics
	urchinTracker('/pages/' + gt); 
	//
	
	elm_main = MM_findObj('main');
	elm_music = MM_findObj('music');
	
	if (gt == 'music') {
		elm_music.style.width = '980px';
		elm_music.style.height = '583px';
		hideMain();
		
		var url = '/ajax.php';
		var pars = 'update=call&goto=' + gt;
		var myAjax = new Ajax.Request(url, {method: 'get', parameters: pars, onComplete: loadMusicNext});
	} else {
		elm_music.style.width = '1px';
		elm_music.style.height = '1px';
		
		var url = '/ajax.php';
		var pars = 'update=call&goto=' + gt;
		var myAjax = new Ajax.Request(url, {method: 'get', parameters: pars, onComplete: loadPage});
	}
}

function loadMusicNext(call) {
	is_music = 1;
	
	tmpsplit = call.responseText.split('&');
	tmpmenu = tmpsplit[0];
	tmpmenu = tmpmenu.replace('menu=', '');
	tmplogo = tmpsplit[1];
	tmplogo = tmplogo.replace('logo=', '');
	tmpanimatie = tmpsplit[2];
	tmpanimatie = tmpanimatie.replace('animatie=', '');
	
	buildPageMusic(tmpmenu, tmplogo, tmpanimatie)
}

function loadPage(call) {
	// Debug
	if (debug == true) {
		//alert(call.responseText);
	}
	// -
	
	is_music = 0;
	
	tmpsplit = call.responseText.split('&');
	tmpmenu = tmpsplit[0];
	tmpmenu = tmpmenu.replace('menu=', '');
	tmplogo = tmpsplit[1];
	tmplogo = tmplogo.replace('logo=', '');
	tmpanimatie = tmpsplit[2];
	tmpanimatie = tmpanimatie.replace('animatie=', '');
	tmpmain = tmpsplit[3];
	tmpmain = tmpmain.replace('main=', '');
	tmpquery = tmpsplit[4];
	tmpquery = tmpquery.replace('querystring=', '');
	
	buildPage(tmpmenu, tmplogo, tmpanimatie, tmpmain, tmpquery)
}

var arr_animatie;
var current_animatie;
var is_music;

function buildPageMusic(menu, logo, animatie) {
	elm_menu = MM_findObj('menu');
	elm_logo = MM_findObj('logo');
	
	hideMain();
	
	// Menu
	if (menu != '') {
		elm_menu.style.width = '305px';
		elm_menu.style.height = '325px';
		var url = '/ajax.php';
		var pars = 'update=menu&menu=' + menu;
		var myAjax = new Ajax.Updater(elm_menu, url, {method: 'get', parameters: pars});
	} else {
		elm_menu.style.width = '1px';
		elm_menu.style.height = '1px';
		elm_menu.innerHTML = '&nbsp;';
	}
	// -
	
	// Logo
	if (logo != '') {
		var url = '/ajax.php';
		var pars = 'update=logo&logo=' + logo;
		var myAjax = new Ajax.Updater(elm_logo, url, {method: 'get', parameters: pars});
	} else {
		elm_logo.innerHTML = '&nbsp;';
	}
	// -
	
	// Animatie
	if (animatie != '') {
		arr_animatie = animatie;
		current_animatie = 0;
		theTimer = setTimeout("setFlash()", 1000);
	}
	// -
}

function buildPage(menu, logo, animatie, main, query) {
	elm_menu = MM_findObj('menu');
	elm_logo = MM_findObj('logo');
	elm_main = MM_findObj('main');
	
	// Menu
	if (menu != '') {
		elm_menu.style.width = '305px';
		elm_menu.style.height = '325px';
		var url = '/ajax.php';
		var pars = 'update=menu&menu=' + menu;
		var myAjax = new Ajax.Updater(elm_menu, url, {method: 'get', parameters: pars});
	} else {
		elm_menu.style.width = '1px';
		elm_menu.style.height = '1px';
		elm_menu.innerHTML = '&nbsp;';
	}
	// -
	
	// Logo
	if (logo != '') {
		var url = '/ajax.php';
		var pars = 'update=logo&logo=' + logo;
		var myAjax = new Ajax.Updater(elm_logo, url, {method: 'get', parameters: pars});
	} else {
		elm_logo.innerHTML = '&nbsp;';
	}
	// -
	
	// Main
	if (main != '' || animatie != '') {
		var url = '/ajax.php';
		var pars = 'update=main&main=' + main + '&querystring=' + query;
		var myAjax = new Ajax.Updater(elm_main, url, {method: 'get', parameters: pars});
		// Debug
		//MM_findObj('showurl').innerHTML = url + '?' + pars;
		// -
	} else {
		elm_main.innerHTML = '&nbsp;';
	}
	// -
	
	// Animatie
	if (animatie != '') {
		// Debug
		//alert(animatie);
		// -
		arr_animatie = animatie;
		current_animatie = 0;
		theTimer = setTimeout("setFlash()", 1000);
	}
	// -
}

function hideMain() {
	elm_main = MM_findObj('main');
	elm_main.innerHTML = '&nbsp;';
	elm_main.style.width = '1px';
}

function showMain() {
	elm_main = MM_findObj('main');
	elm_main.style.width = '980px';
}

function setFlash() {
	if (is_music == 0) {
		elm_animatie = MM_findObj('flashmain');
	} else {
		elm_animatie = MM_findObj('flashmusic');
	}
	
	if (elm_animatie) {
		tmp_split = arr_animatie.split('%2C');
		tmp_animatie = tmp_split[current_animatie];
		// Debug
		//MM_findObj('showurl').innerHTML = arr_animatie + ' - ' + current_animatie + ' - ' + tmp_split[0] + ' | ' + tmp_split[1] +  ' | ' + tmp_split[2];
		// -
		
		current_animatie++;
		if (current_animatie > (tmp_split.length - 2)) {
			current_animatie = 0;
		}
			
		elm_animatie.SetVariable('eenvar', tmp_animatie);
	} else {
		theTimer = setTimeout("setFlash()", 1000);
	}
}
function actie_checkEmail() {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('emailid').value)){
		return true;
	}
		return false;
}
function actie_doSubmit(){
  var valid = actie_checkEmail();
	if(valid){
		var url = 'actieAjax.php';
		var pars = 'email='+escape($F('emailid'));
		var target = 'action';
		var myAjax = new Ajax.Updater(target, url, {	method: 'get',	parameters: pars});
	}else{
		$('emailid').value = "E-mailadres is ongeldig.";
		return false;
	}
}