
function QuickContact()
{
	this.x = 0;
	this.y = 0;
	
	this.elem = null;
	this.formElem = null;
	
	this.intervalId = -1;
	this.counter;
	
	this.init = function()
	{
		var hold = document.getElementById('loginbox');	
		this.x = getAbsoluteX( hold, null ) + hold.offsetWidth / 2;
		this.y = getAbsoluteY( hold, null ) + hold.offsetHeight / 2;
		
		this.elem = document.createElement('div');
		this.elem.style.display = 'block';
		this.elem.style.position = 'absolute';
		this.elem.style.backgroundColor = 'black';
		this.elem.style.border = '1px solid red';
		this.elem.style.backgroundImage = 'url(assets/templates/cp2/watermerk2.png)';
		this.elem.style.zIndex = 99999999;
		
		var dark = document.createElement('div');
		dark.style.display = 'block';
		dark.style.position = 'absolute';
		dark.style.backgroundColor = 'black';
		dark.style.width = '100%';
		dark.style.height = '100%';
		setElementAlpha(dark, 0.75);
		this.elem.appendChild(dark);
		
		this.formElem = document.createElement('div');
		this.formElem.style.display = 'block';
		this.formElem.style.position = 'absolute';
		this.formElem.style.width = '100%';
		this.formElem.style.height = '100%';
		this.elem.appendChild(this.formElem);		
		
		document.body.appendChild(this.elem);
	
		this.counter = 0;
		var _this_ = this;
		this.intervalId = setInterval(function(){ _this_.grow(); }, 10);
	};
	
	this.grow = function()
	{
		var lerp = this.counter / 100.0;
		
		var last =false;
		if(lerp >= 1.0)
		{
			lerp = 1.0;
			last = true;
		}
		
		lerp = 1.0 - lerp;
		lerp *= lerp;
		lerp = 1.0 - lerp;
	
	
		var w = Math.floor(lerp * 240);
		var h = Math.floor((lerp*lerp*lerp*lerp*lerp) * 280);
		var x = Math.floor(this.x - w/2);
		var y = Math.floor(this.y - h/2);		
		setElementBounds(this.elem, x, y, w, h);
		this.elem.style.backgroundPosition = Math.floor(-w/2)+'px '+Math.floor(-h/2)+'px';
		
		this.counter++;
		
		if(last)
		{
			clearInterval(this.intervalId);
			this.intervalId = -1;
		
			this.createForm();
			
			this.counter = 0;
			var _this_ = this;
			this.intervalId = setInterval(function(){ _this_.revealForm(); }, 10);
		}
	};
	
	this.createForm = function()
	{
		var fieldName = '<h3 style="color:#FFFFFF; font-size: 8pt;">Uw naam</h3><input id="field_name" type="name" size="20" style="border: 1px solid #800000; background-color: #202020; color: #FFFFFF; height: 20px">';
		var fieldMail = '<h3 style="color:#FFFFFF; font-size: 8pt;">Emailadres</h3><input id="field_mail" type="mail" size="20" style="border: 1px solid #800000; background-color: #202020; color: #FFFFFF; height: 20px">';
		var fieldText = '<h3 style="color:#FFFFFF; font-size: 8pt;">Stel uw vraag</h3><textarea id="field_text" cols="30" rows="5" style="border: 1px solid #800000; background-color: #202020; color: #FFFFFF;"></textarea>';
		
		var html = '';
		html += '<center><form><br>';
		html += fieldName;
		html += fieldMail;
		html += fieldText;
		html += '<br><br>';
		html += '<input type="button" name="submit" value="Versturen" style="background-color: #660000; border: 1px solid #800000; color: #FFFFFF;" onClick="quickContact.submitForm()">';
		html += '&nbsp;&nbsp;';
		html += '<input type="button" name="cancel" value="Annuleren" style="background-color: #660000; border: 1px solid #800000; color: #FFFFFF;" onClick="quickContact.cancelForm()">';
		html += '</form></center>';
		
		setElementAlpha(this.formElem, 0.0);
		this.formElem.innerHTML = html;
	};
	
	this.revealForm = function()
	{
		var lerp = this.counter / 100.0;
		
		var last =false;
		if(lerp >= 1.0)
		{
			lerp = 1.0;
			last = true;
		}
		
		lerp = 1.0 - lerp;
		lerp *= lerp;
		lerp = 1.0 - lerp;
		
		
		setElementAlpha(this.formElem, lerp);
		
		this.counter++;
		
		if(last)
		{
			clearInterval(this.intervalId);
			this.intervalId = -1;
		}
	};
	
	this.shroudForm = function()
	{
		var lerp = this.counter / 100.0;
		
		var last =false;
		if(lerp >= 1.0)
		{
			lerp = 1.0;
			last = true;
		}
		
		lerp = 1.0 - lerp;
		lerp *= lerp;
		lerp = 1.0 - lerp;
		
		
		setElementAlpha(this.formElem, 1.0 - lerp);
		
		this.counter++;
		
		if(last)
		{
			clearInterval(this.intervalId);
			this.intervalId = -1;

			this.counter = 0;
			var _this_ = this;
			this.intervalId = setInterval(function(){ _this_.shrink(); }, 10);
		}
	};
	
	this.shrink = function()
	{
		var lerp = this.counter / 50.0;
		
		var last =false;
		if(lerp >= 1.0)
		{
			lerp = 1.0;
			last = true;
		}
		
	
	
		var w = Math.floor((1.0-(lerp*lerp*lerp*lerp)) * 240);
		var h = Math.floor((1.0-(lerp)) * 280);
		var x = Math.floor(this.x - w/2);
		var y = Math.floor(this.y - h/2);		
		setElementBounds(this.elem, x, y, w, h);
		this.elem.style.backgroundPosition = Math.floor(-w/2)+'px '+Math.floor(-h/2)+'px';
		
		this.counter++;
		
		if(last)
		{
			clearInterval(this.intervalId);
			this.intervalId = -1;
			
			this.elem.parentNode.removeChild(this.elem);
		}
	};
	
	this.submitForm = function()
	{
		var nameVal = document.getElementById('field_name').value;
		var mailVal = document.getElementById('field_mail').value;
		var textVal = document.getElementById('field_text').value;
		
		if(nameVal == "") {	window.alert("Vult u alstublieft uw naam in.");	return;	}
		if(mailVal == "")	{	window.alert("Vult u alstublieft uw emailadres in.");	return;	}
		if(textVal == "")	{	window.alert("U hebt nog geen vraag gesteld.");	return;	}
		
		var query = '';
		query += 'name='+strToHex(nameVal);
		query += '&';
		query += 'mail='+strToHex(mailVal);
		query += '&';
		query += 'text='+strToHex(textVal);
		
		var _this_ = this;
		ajax( "POST", "/quick_contact.php", "", query, function() { _this_.onForumSubmitted(); } );
	};
	
	this.onForumSubmitted = function()
	{
		window.alert('Uw bericht is zojuist verzonden naar CP2.\nU hoort zo snel mogelijk van ons.');
		
		this.counter = 0;
		var _this_ = this;
		this.intervalId = setInterval(function(){ _this_.shroudForm(); }, 10);
	};
	
	this.cancelForm = function()
	{
		this.counter = 0;
		var _this_ = this;
		this.intervalId = setInterval(function(){ _this_.shroudForm(); }, 10);
	};
}

var quickContact = null;

function showQuickContactForm()
{
	quickContact = new QuickContact();
	quickContact.init();
}
