var WerkplekMakeover = new function() {}

WerkplekMakeover.load = function() {
	window.onresize = WerkplekMakeover.stretch;
	this.stretch();
}


WerkplekMakeover.stretch = function() {
	var p = document.getElementById("page");
	
	if(window.innerHeight) {
		h = window.innerHeight;
	} 	
	else {
		h = document.body.clientHeight;
	}
	if(p.offsetHeight < h) {
		
		p.style.height = (h-20) + "px";
	}
}

WerkplekMakeover.getReport = function() {
	var url = "/index.php?c=test&m=report";
	var ajax = new Ajax.Updater(
	{success: 'report'},
		url,
		{method: 'get', onFailure: reportError, onComplete:WerkplekMakeover.stretch});
}

WerkplekMakeover.setColumnsEpisode = function(oSelect) {
	window.location.href= "/index.php/columns/page/0/" + oSelect.options[oSelect.selectedIndex].value;
}

WerkplekMakeover.setEpisode = function(oSelect) {
	window.location.href= "/index.php/week/page/" + oSelect.options[oSelect.selectedIndex].value;
}

WerkplekMakeover.setGezienEpisode = function(oSelect) {
	window.location.href= "/index.php/gezien/partners/" + oSelect.options[oSelect.selectedIndex].value;
}


function reportError(request) {
	$F('report') = "Error";
}

WerkplekMakeover.viewPhoto = function(company, photo) {
	pop = window.open("/index.php/photo/view/" + photo + "/" + company, "photo", "width=640,height=480");
	pop.focus();
	pop.moveTo(screen.availWidth/2 - 320 , screen.availHeight/2 -240);
}

WerkplekMakeover.algemenevoorwaarden = function() {
	var url = "/index.php/algemenevoorwaarden";
	var w = 300;
	var h = 200;
	var popje = window.open( url, "",'width='+w+',height='+h+',toolbar=0,status=0,scrollbars=no, resizable=1');
	window.focus();
	popje.focus();
}

WerkplekMakeover.voorwaardenmakeover = function() {
	var url = "/index.php/voorwaardenmakeover";
	var w = 400;
	var h = 400;
	var popje = window.open( url, "",'width='+w+',height='+h+',toolbar=0,status=0,scrollbars=no, resizable=1');
	//window.focus();
	pop.moveTo(screen.availWidth/2 - w , screen.availHeight/2 -h);
	popje.focus();
}

// deprecated 
WerkplekMakeover.clickout = function(href) {
	var hostname = href.replace(/(http:\/\/)([^/]*)\/.*/, "$2");
	new Ajax.Request('/index.php/clickout/to/' + hostname, {asynchronous:true, method:'get'});
	window.open(href);
}

WerkplekMakeover.hit = function(oAnchor) {
	var hostname = oAnchor.href.replace(/(http:\/\/)([^/]*)\/.*/, "$2");
	new Ajax.Request('/index.php/clickout/to/' + hostname, {asynchronous:true, method:'get'});
}

WerkplekMakeover.flashInstall = function() {
	oReport = document.getElementById('report');
	oReport.innerHTML = "<div class='box threethird'><h2>Flash versie te laag!</h2><p>De versie van Flash op je computer is te laag om de test te kunnen doen. Volg de instructies hierboven om de nieuwste versie te installeren. <b>Let op dat er gevraagd kan worden om je browser af te sluiten tijdens de installatie!</b>. Als de installatie is voltooid kom je automatisch weer terug op deze pagina.</p><p>Wil het allemaal nog steeds niet lukken, ga dan gewoon naar <a href='http://www.macromedia.com/go/getflashplayer'><b>deze pagina</b></a> om de Flash Player handmatig te installeren. Succes!</p><p></p><p></p><div class='threethirdbottom'></div></div>";
}

WerkplekMakeover.gispenMiniSite = function() {
	new Ajax.Request('/index.php/clickout/to/http://www.gispen.nl', {asynchronous:true, method:'get'});
	newWindow = window.open('http://www.gispen.nl/werkplekmakeover/gispen/popup.html','Gispen','width=965,height=682,scrollbars=no, resizable=no,');
	newWindow.focus();
}

WerkplekMakeover.commitMiniSite = function() {
	new Ajax.Request('/index.php/clickout/to/http://www.gispen.nl/commit', {asynchronous:true, method:'get'});
	newWindow = window.open('http://www.gispen.nl/werkplekmakeover/commit/popup.html','Commit','width=965,height=682,scrollbars=no, resizable=no,');
	newWindow.focus();
}


WerkplekMakeover.sendEcard = function () {
	oForm 	   = document.getElementById("sendform");
	aInputs    = oForm.getElementsByTagName("input");
	aValues	   = new Array();
	for(var i = 0; i < aInputs.length; i ++) {
		oInput = aInputs[i];
		if(oInput.type == "text" || oInput.type == "hidden") {
			aValues[aValues.length] = { name: oInput.name, value: oInput.value }
		}
		else if(oInput.type == "radio" && oInput.checked == true) {
			aValues[aValues.length] = { name: oInput.name, value: oInput.value }
		}
		else if(oInput.type == "submit") {
			oInput.value = "Bezig met versturen...";
			oInput.style.cursor = "wait";
		}
	}
		
	aSelects   = oForm.getElementsByTagName("select");
	if(aSelects.length == 1) {
		oSelect = aSelects[0];
		aValues[aValues.length] = { name: oSelect.name, value: oSelect.value }
	}
	
	aTextareas = oForm.getElementsByTagName("textarea");
	if(aSelects.length == 1) {
		oTextarea = aTextareas[0];
		aValues[aValues.length] = { name: oTextarea.name, value: oTextarea.value }
	}
	
	var params = "";
	for(var i = 0; i < aValues.length; i++) {
		params += aValues[i].name+"="+aValues[i].value;
		if(i!=aValues.length-1) params += "&";	
	}
	
	var url = oForm.action;
	var ajax = new Ajax.Updater('sendbox', url, {method:'post', postBody:params});	
	return false;
}

WerkplekMakeover.viewImage = function(oDiv) {
	aImg = oDiv.getElementsByTagName("IMG"); 
	if(aImg.length == 1) {
		sImg = aImg[0].src.replace(/(afl[0-9])|(rentokil)/, "$1$2/large");
		url 	   = "/image.html?" + sImg;
		viewWindow = window.open(url, "image", "width=64,height=64,scrollbars=auto,toolbar=no,location=no,resizable=yes");	
		viewWindow.focus();
	}
}