//// begin script ////

//// local debug vars ////
var debug = false;

// check browser ///////////////////////
agent = navigator.userAgent.toLowerCase(); 
mac = (agent.indexOf("mac")!=-1);
win = (!this.mac) ?true:false;
w3c = (document.getElementById) ?true:false;
iex = (document.all) ?true:false;
ns4 = (document.layers) ?true:false;
curr_item = '';

if(debug) {
	if(w3c) alert("w3c");
	if (iex) alert("iex");
	if (ns4) alert("ns4");
}

//// verplaats achtergrond image script //////////////
function move_col_bg(margin,h,m,t,f,mnb,right_margin,hf,ff,mf,padding_top,f1,f2,col1,col2,pos1) {
	var boxHeight = 0;
	var windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
	if (h) boxHeight += document.getElementById('header').offsetHeight;
	if (m) boxHeight += document.getElementById('menu').offsetHeight;
	if (t) boxHeight += document.getElementById('thumbs').offsetHeight;
	if (f1) boxHeight += f1;
	if (f2) boxHeight += f2;
	if (col1) document.getElementById(col1).style.top=boxHeight-margin;
	if (col2) document.getElementById(col2).style.backgroundPosition=pos1 + (boxHeight-margin);
	move_notes_box(margin,h,m,t,f,mnb,right_margin,hf,ff,mf,padding_top,f1,f2);
}

function move_fixed_boxes(hf,ff,mf) {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	//alert(containerHeight);
	if (hf) set_left('header_fixed','header');
	if (mf) set_both('menu-fixed','menu');
	if (ff) set_cond('footer-fixed-box','footer-box',myHeight);
}

function move_notes_box(margin,h,m,t,f,mnb,right_margin,hf,ff,mf,padding_top,f1,f2) {
	//alert('hoi');
	var boxHeight = 0, footerHeight = 0, maxHeight = 0;
	var containerLeft = 0, containerHeight = 0, myWidth = 0, myHeight = 0;
	//alert('hoi2');
	if (h) boxHeight += document.getElementById('header').offsetHeight;
	if (hf) set_top("header",margin);
	if (m) boxHeight += document.getElementById('menu').offsetHeight;
	if (t) boxHeight += document.getElementById('thumbs').offsetHeight;
	if (f) footerHeight = document.getElementById('footer-box').offsetHeight;
	//alert('hoi3');
	maxHeight = document.getElementById('container').offsetHeight - boxHeight - footerHeight - padding_top;
	if (f1) boxHeight += f1;
	if (f2) boxHeight += f2;
	//alert(boxHeight);
	//alert('hoi4');
	containerLeft = document.getElementById("container").offsetLeft + document.getElementById("container").offsetWidth - right_margin;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	//alert(document.getElementById("container").offsetLeft);
	//alert(containerLeft);
	if (mnb) {
		containerHeight = Math.min(myHeight - (boxHeight+footerHeight+padding_top+margin),maxHeight);
	} else {
		containerHeight = 0;
	}
	//document.getElementById("notes_box").style.top=(boxHeight-margin) + 'px';
	document.getElementById("notes_box").style.left=containerLeft + 'px';
	document.getElementById("notes_box").style.height=containerHeight + 'px';
	document.getElementById("notes_float").style.height=containerHeight + 'px';
	//alert(containerHeight);
	if (hf) set_left('header_fixed','header');
	if (mf) set_both('menu-fixed','menu');
	if (ff) set_cond('footer-fixed-box','footer-box',myHeight);
}

function set_left(div_fixed,div) {
	//alert(div);
	var divLeft = 0;
	//alert(div_fixed);
	divId = document.getElementById(div);
	pos_div = findPos(divId);
	//headerLeft = document.getElementById("header").offsetLeft;
	//alert(pos_div[0]);
	//alert(headerLeft);
	document.getElementById(div_fixed).style.left=pos_div[0] + 'px';
}
function set_top(div,margin) {
	divId = document.getElementById(div);
	divId.style.top=margin + 'px';
}
function set_both(div_fixed,div,screenHeight) {
	//alert(div);
	var divLeft = divHeight = 0;
	//alert(div_fixed);
	divId = document.getElementById(div);
	div_fixedId = document.getElementById(div_fixed);
	pos_div = findPos(divId);
	//pos_div_fixed = findPos(div_fixedId);
	//headerLeft = document.getElementById("header").offsetLeft;
	//alert(pos_div[0]);
	//alert(pos_div[1]);
	//alert(pos_div_fixed[0] + '>' + pos_div[1]);
	div_fixedId.style.left=pos_div[0] + 'px';
	div_fixedId.style.top=pos_div[1] + 'px';
	divHeight = divId.offsetHeight - 8;
	div_fixedId.style.height=divHeight + 'px';
}
function set_cond(div_fixed,div,screenHeight) {
	//alert(div);
	var divLeft = divHeight = 0;
	//alert(div_fixed);
	divId = document.getElementById(div);
	div_fixedId = document.getElementById(div_fixed);
	pos_div = findPos(divId);
	//pos_div_fixed = findPos(div_fixedId);
	//headerLeft = document.getElementById("header").offsetLeft;
	//alert(pos_div[0]);
	//alert(pos_div[1]);
	//alert(divId.offsetHeight);
	div_fixedId.style.left=pos_div[0] + 'px';
	if (screenHeight > pos_div[1] + divId.offsetHeight) {
		//divHeight = divId.offsetHeight;
		//alert(divHeight);
		//div_fixedId.style.bottom='auto';
		div_fixedId.style.height=divId.offsetHeight + 'px';
		div_fixedId.style.top=pos_div[1] + 'px';
	}
}

function fill_notes_box(text) {
	document.getElementById("notes_box").innerHTML=text;
}

function move_col_hmt_bg(margin) {
	var boxHeight = document.getElementById('header').offsetHeight;
	boxHeight += document.getElementById('menu').offsetHeight;
	boxHeight += document.getElementById('thumbs').offsetHeight;
	document.getElementById('abs_cols_box_id').style.top=boxHeight-margin;
}

function move_col_hm_bg(margin) {
	var boxHeight = document.getElementById('header').offsetHeight;
	boxHeight += document.getElementById('menu').offsetHeight;
	document.getElementById('abs_cols_box_id').style.top=boxHeight-margin;
}

function move_col_h_bg(margin) {
	var boxHeight = document.getElementById('header').offsetHeight;
	document.getElementById('abs_cols_box_id').style.top=boxHeight-margin;
}

function move_col_mt_bg(margin) {
	var boxHeight = document.getElementById('menu').offsetHeight;
	boxHeight += document.getElementById('thumbs').offsetHeight;
	document.getElementById('abs_cols_box_id').style.top=boxHeight-margin;
}

function move_col_m_bg(margin) {
	var boxHeight = document.getElementById('menu').offsetHeight;
	document.getElementById('abs_cols_box_id').style.top=boxHeight-margin;
}

function move_col_hmtff_bg(margin,fade) {
	var boxHeight = document.getElementById('header').offsetHeight;
	boxHeight += document.getElementById('menu').offsetHeight;
	boxHeight += document.getElementById('thumbs').offsetHeight;
	boxHeight += 2*fade;
	document.getElementById('abs_cols_box_id').style.top=boxHeight-margin;
}

function move_col_hmf_bg(margin,fade) {
	var boxHeight = document.getElementById('header').offsetHeight;
	boxHeight += document.getElementById('menu').offsetHeight;
	boxHeight += fade;
	document.getElementById('abs_cols_box_id').style.top=boxHeight-margin;
}

function move_col_hmff_bg(margin,fade) {
	var boxHeight = document.getElementById('header').offsetHeight;
	boxHeight += document.getElementById('menu').offsetHeight;
	boxHeight += 2*fade;
	document.getElementById('abs_cols_box_id').style.top=boxHeight-margin;
}

function move_col_hf_bg(margin,fade) {
	var boxHeight = document.getElementById('header').offsetHeight;
	boxHeight += fade;
	document.getElementById('abs_cols_box_id').style.top=boxHeight-margin;
}

function move_col_mtff_bg(margin,fade) {
	var boxHeight = document.getElementById('menu').offsetHeight;
	boxHeight += document.getElementById('thumbs').offsetHeight;
	boxHeight += 2*fade;
	document.getElementById('abs_cols_box_id').style.top=boxHeight-margin;
}

function move_col_mf_bg(margin,fade) {
	var boxHeight = document.getElementById('menu').offsetHeight;
	boxHeight += fade;
	document.getElementById('abs_cols_box_id').style.top=boxHeight-margin;
}

function move_col_mff_bg(margin,fade) {
	var boxHeight = document.getElementById('menu').offsetHeight;
	boxHeight += 2*fade;
	document.getElementById('abs_cols_box_id').style.top=boxHeight-margin;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		return [curleft,curtop];
	} else {
		return [obj.screenLeft,obj.screenLeft];
	}
}

//// anti-spam script //////////////
function safemail(name, domain, display) {
    displayed=(typeof(display)=="undefined") ? name+"@"+domain : display
    document.write('<a class="sub" href=mailto:' + name + '@' + domain + '>' + displayed + '</a>');
}

//// opens a window ////////////////
function openWin(url, name, width, height, kind) {
	var my_win;
	if (kind == "ws") {
	 	w = ((screen.width - 40) - 10);
	 	h = ((screen.height - 40) - 75);
	 	l = 20;
	 	t = 20;
	 	full = 0;
	 } else if (kind == "fs") {
	 	if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
   && (navigator.appVersion.indexOf("Win") != -1)) {
   			w = screen.width;
   			h = screen.height;
   			l = 0;
   			t = 0
	 		full = 1;
	 	} else {
	 		h = screen.height - 40;
	 		w = screen.width;
	 		l = 0;
	 		t = 0;
	 		full = 0;
	 	}
	 } else {
	 	h = height;
	 	w = width;
	 	l = ((screen.width - w) / 2);
	 	t = ((screen.height - h) / 2 - 40);
	 	full = 0;
	 }
	my_win = open(url, name, "width="+ w +",height="+ h 
		+",left=" + l + ",top=" + t 
		+ ",directories=0,location=0,menubar=0,scrollbars=0"
		+ ",status=0,toolbar=0,fullscreen=" + full 
		+ ",resizable=1");
	my_win.focus();
}

//// move and resize window /////			
function moveAndResize(w,h) {
	if (w == null) {
    	w = 600;
    	h = 450;
	}
    l = ((screen.width - w) / 2);
    t = ((screen.height - h) / 2 - 40);
    window.moveTo(l,60);
    window.resizeTo(w,h);
}

//// set kleur menu items /////			
function set_menu_item_kleur(el,sel_kleur,item,kleur) {
	el.style.color= sel_kleur;
	if (curr_item && (curr_item != item)) {
		document.getElementById('menuitem'+curr_item).style.color=kleur;
	}
	curr_item = item;
}

//// controle scripts ////
function checkForm(form, question, answer, questionError, email, emailError) {
	var ret = true;

	if (question) {

		ret = checkQuestion( form.sec_answer.value, answer, questionError);
	}
	if ( ret && email) {
		ret = checkEmail( form.from.value, emailError);
	}
	return ret;
}
function checkQuestion(guess, answer, error) {
	if (guess.toUpperCase() != answer.toUpperCase()) {
		alert(error);
		return false;
	}
	return true;
}
function checkEmail(mail,error) {
	if (mail.match('^[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,6}$')) {
		return true;
	}
	alert(error);
	return false;
}


//// end script ////
