$(document).ready(function() {
	$("a.target_blank").attr( { target: "_blank" } );
} );

function getObject(id){
	obj = document.getElementById(id);
	if(obj != undefined){
		return obj;
	}
}
function changeBackground(obj, background, left){
	backpos = "center right";
	if(left == false){
		backpos = "center left";
	}
	obj.style.backgroundImage = 'url(/assets/images/' + background + ')';
	obj.style.backgroundRepeat = 'no-repeat';
	obj.style.backgroundPosition = backpos;
	obj.onmouseout = function(){
		obj.style.backgroundImage = 'url(/assets/images/spacer.gif)';
		obj.style.backgroundRepeat = 'repeat';
		obj.style.backgroundPosition = 'center center';
	};
}
function redirect(url, target){
	if(target == "_blank"){
		window.open(url, 'new_window');
	}
	else{
		document.location.href = url;
	}
}
function hide_div(id){
	document.getElementById(id).style.display = 'none';
}
function show_div(id){
	document.getElementById(id).style.display = 'block';
}

function show_flash(f_id, f_width, f_height, f_src, f_back, flashvars){	
	var params = {};
	params.quality = "high";
	params.menu = "false";
	params.bgcolor = f_back;
	params.wmode = "opaque";
	
	var attributes = {};
	attributes.id = "uniqueID";
	attributes.name = "uniqueID";

	swfobject.embedSWF(f_src, f_id, f_width, f_height, "8.0.0", "", flashvars, params, attributes);
}

function check_flash(id){
	obj = document.getElementById(id);
	var playerVersion = swfobject.getFlashPlayerVersion();
	if(playerVersion.major < 8){
		if(playerVersion.major == 0){
			obj.innerHTML += "<br /><br /><strong>Let op!</strong> U heeft geen Adobe Flash Player geïnstalleerd.";
		}
		else{
			obj.innerHTML += "<br /><br /><strong>Let op!</strong> U heeft een oude versie van de Adobe Flash Player geïnstalleerd.";
		}
		obj.innerHTML += "<br /><a href=\"http://get.adobe.com/flashplayer/\" target=\"_blank\" alt=\"Get Adobe Flash Player\">Klik hier om de nieuwste versie van de Adobe Flash Player te downloaden en te installeren.</a>";
	}
}

function show_img(id, image){
	document.getElementById(id).src = image;
}

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

function checkInput(obj, val){
	if(obj.value == val){
		obj.value = '';
		obj.onblur = function() { blurInput(this, val); };
		obj.style.color = '#000000';
	}
}

function blurInput(obj, val){
	if(obj.value == ''){
		obj.style.color = '#d7d7d7';
		obj.value = val;
	}
}

function checkPassword(obj, val) {
	if(obj.value != val) return true;
	var parentElem = obj.parentNode;
	try {
		// For well-behaved browsers
		obj.type = "password";
		obj.value = "";
		obj.style.color = "#000000";
		obj.onblur = function() { blurPassword(this, val); };
	} catch(error) {
		// IE chokes, so catch it and swap out the elements
		var newId = obj.id;
		var newName = obj.name;
		var newStyle = obj.style;
		var textnode = document.createElement("INPUT");
		textnode.type = "password";
		textnode.onblur = function() { blurPassword(this, val); };
		parentElem.appendChild(textnode);
		parentElem.removeChild(obj);
		textnode.id = newId;
		textnode.name = newName;
		textnode.focus();
		textnode.style.color = '#000000';
	}
}

function blurPassword(obj, val) {
	if(obj.value != "") 	return true;
	var parentElem = obj.parentNode;
	try {
		// For well-behaved browsers
		obj.type = "text";
		obj.style.color = "#d7d7d7";
		obj.value = val;
	} catch(error) {
		// IE chokes, so catch it and swap out the elements
		var newId = obj.id;
		var newName = obj.name;
		var newStyle = obj.style;
		var textnode = document.createElement("INPUT");
		textnode.type = "text";
		textnode.style.color = '#d7d7d7';
		textnode.value = val;
		textnode.onfocus = function() { checkPassword(this, val); };
		parentElem.appendChild(textnode);
		parentElem.removeChild(obj);
		textnode.id = newId;
		textnode.name = newName;
		textnode.blur();
	}
}

function showPopup(id, url){
	pos = findPos(getObject(id));
	getObject('dialog').style.top = (pos[1] - 259) + 'px';
	showBackground();
	//show_div("dialog");
	$("#dialog").fadeIn(1000);
	updateDiv('dialog', url);
}

function closePopup(){
	hide_div("errorFloater");
	//hide_div("background");
	$("#background").fadeOut(800);
	//hide_div("dialog");
	$("#dialog").fadeOut(1000, function emptyPopup() { getObject('dialog').innerHTML = ''; } );
}

function updateDiv(obj, url){
	$("#" + obj).load(url);
}

function showBackground(){
	obj = getObject('background');
	//show_div('background');
	$("#background").fadeIn(800);
	var tmp_height = obj.offsetHeight;
	objs = document.getElementsByTagName('div');
	for(var i = 0; i < objs.length; i++){
		objpos = findPos(objs[i]);
		objheight = objs[i].offsetHeight;
		objtemp = objpos[1] + objheight;
		if(objtemp > tmp_height){
			tmp_height = objtemp;
		}
	}
	obj.style.height = tmp_height + 'px';
}
