var re_email = /^.*?((?:[\w.-])+\@(?:(?:[\w-])+\.)+(?:[\w]{2,4})).*?$/;

/*
Bepaald de onload, functie toevoegen aan body onload d.m.v.: window.onload.actions.push(function_naam);
*/
window.onload = function () {
    for (var i=0;arguments.callee.actions.length>i;i++)
        arguments.callee.actions[i]();
};
window.onload.actions = [];

function ClearInputEvents(id,str) {
	obj = document.getElementById(id);
	val = obj.value;
	
	obj.startvalue = val;
	obj.value = val;
	
	obj.onfocus = function() { if(this.value == this.startvalue) { this.value = '';}}
	obj.onblur =  function() { if(this.value == '') { this.value = this.startvalue; }}

}

/* POPUP SCRIPT 
----------------------------------------------------------------*/
function calc_position(popWidth, popHeight) {
	popLeft = (screen.width/2)-(popWidth/2);
	popTop = (screen.height/2)-(popHeight/2);
	var returnRay = new Array(popWidth, popHeight, popLeft, popTop);
	return returnRay;
}

function open_popup(type, w, h) {
	popProps = calc_position(w, h);
	popup = window.open('/popup/' + type + '.php', 'popup_window', 'scrollbars=yes, width='+popProps[0]+', height='+popProps[1]+', left='+popProps[2]+', top='+popProps[3]);
}

/* BIEDEN SCRIPT 
----------------------------------------------------------------*/
function valid_offer(minimum, titel) {
	var frm = document.getElementById('frm-bieden');
	var current=frm.elements['i_bod'].value;

	if(confirm("Weet u zeker dat u een bod van " + current + " euro wilt uitbrengen op " + titel + "?")) {
		if(parseFloat(current.replace (",",".")) < parseFloat(minimum.replace(",","."))) {
			alert('Uw bod van ' + current + 'euro is te laag. U moet minstens ' + minimum + 'euro bieden.');
			return false;
		} else {
			return true;
		}
	} else {
		return false;
	}
}

function eurofield_keypress(evt) {
	// 48 = 0   57 = 9
	// 46 = .   44 = ,
	
	if(evt.keyCode==0 && evt.charCode>0) { // Firefox methode
		var kc=evt.charCode;
		if((kc<48 || kc>57) && kc!=44 && kc!=46) { return false; } else { return true; }
	} else if(evt.keyCode>0 && typeof evt.charCode=='undefined') { // Internet Explorer methode
		var retval=evt.keyCode;
		if(retval==46) { retval=44; }
		if((retval<48 || retval>57) && retval!=44) { retval=false; }
		evt.keyCode=retval;
		return true;
	} else { // Onbekende browser of systeemkarakter (backspace, etc.), alles wordt doorgelaten en alsnog server-side gecheckt
		return true;
	}
}
function eurofield_keyup(what) {
	// Omdat Firefox geen tekens kan replacen bij de onkeypress
	if(what.value.indexOf(".")>=0) { what.value=what.value.replace(".",","); }
}
function eurofield_blur(what) {
	var p=what.value.split(",");
	var euro=p[0];
	if(p[1]) { var centen=p[1]; } else { var centen=''; }
	if(centen.length==0) { centen="00"; }
	else if(centen.length=="1") { centen=centen+"0"; }
	else if(centen.length>2) { centen=centen.substr(0,2); }
	if(!euro) { euro="0"; }
	what.value=euro+","+centen;
}

function display_currency(nr) {
	var q=new String(nr).split(".");
	if(typeof q[1]=='undefined') { q[1]="00"; }
	else if(q[1].length==1) { q[1]=q[1]+"0"; }
	return q[0]+","+q[1];
}

/* STAF SCRIPT 
----------------------------------------------------------------*/
function init_staf() {
	doc = document
	if(doc.getElementById('staf_preview')) {
		var staf_fields = Form.getElements('frm-staf');
		for(i = 0; i < staf_fields.length; i++) {
			if(staf_fields[i].type != 'hidden' && staf_fields[i].type != 'button' && staf_fields[i].type != 'image') {
				staf_fields[i].onkeyup = staf_fields[i].onblur = function() { update_staf_preview(); return false; }
			}
		}
		update_staf_preview();		
	}
}

function update_staf_preview() {
	var submit_body = Form.serialize('frm-staf');
	new Ajax.Updater('staf_preview', '/ajax/staf_preview.php', { method:'post', postBody:submit_body, asynchronous:true, evalScripts:true } );
}

/* PRINT SCRIPT
----------------------------------------------------------------*/
function init_Print() {
	if(window.print && document.getElementById("print-btn")) { 
		document.getElementById("print-btn").style.display = 'block';
		document.getElementById("print-btn").onclick  = function () { window.print(); return false; }
	}
}

/* FAQ SCRIPT
----------------------------------------------------------------*/
/*
function toggle_display(obj) {
	if(obj.style.display == 'none') {
		obj.style.display = 'block';
	} else {
		obj.style.display = 'none'; 
	}
}
*/
function show(target) {
	blok=document.getElementById(target);
	if(blok.style.display!="block") {
		blok.style.display="block";
	} else {
		blok.style.display="none";
	}
}

function toggle_display(obj) {
	if(obj.style.display == 'none') {
		obj.style.display = 'block';
	} else {
		obj.style.display = 'none'; 
	}
}

/* ONLOAD
----------------------------------------------------------------*/
function init() {
	detect_flash();
    load_flash('add_120x600', '/swf/Sauna_Peize_120x600.swf', 120, 600, 6);
	load_flash('add_728x90', '/swf/Sauna_Peize_728x90.swf', 728, 90, 6);
	if(document.getElementById('populaireartikelen')) load_flash('populaireartikelen', '/swf/flashfile_new.swf', 239, 365, 6);
	
	ClearInputEvents('keyword');
	if(window.alphaPNG) alphaPNG(); 
	init_Print();
	init_staf();
	
	obj=document.getElementById('page');
	menu=document.getElementById('mn');
	stuur=document.getElementById('stuurdoor');
	subnav=document.getElementById('subnavigatie');
	inh=document.getElementById('inhoud');
	if(!inh) inh=document.getElementById('faq');
	
	if((subnav && stuur) && ((subnav.offsetHeight + stuur.offsetHeight)>inh.offsetHeight)) {
		inh.style.height=subnav.offsetHeight + stuur.offsetHeight;
	} else if (subnav && (subnav.offsetHeight>inh.offsetHeight)) {
		inh.style.height=subnav.offsetHeight;
	}
	
	if(stuur) {
		stuur.style.top=obj.offsetHeight-stuur.offsetHeight-menu.offsetHeight-135+'px';
		stuur.style.visibility='visible';
	}
	
	/*
	url=document.location.href.split('&');
	var lastparam=url[url.length-1];
	if(lastparam=='IDEALStatus=SUCCESS') {	
		oklnk=document.forms[1].action;
		window.setTimeout('window.location="'+oklnk+'"; ',0);
	}
	*/
}

window.onload.actions.push(init);
