var xmlHttp;
function prepAJAX()
{
	try
  {
	    // Firefox, Opera 8.0+, Safari
	    xmlHttp = new XMLHttpRequest();
  }
  catch (e)
    {
	    // Internet Explorer
	    try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
	    catch (e)
	    {
	    	try
	        {
	        	xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	        }
	      	catch (e)
	        {
	        	alert("Uw browser ondersteunt niet de nodige technieken om te checken of deze domeinnaam al bestaat.");
	        }
	    }
	}
}


function begin()
{
	if(document.getElementById)
	{
		//try {
			oMenu = document.getElementById('menu');
			for (var i=0;i < oMenu.childNodes.length; i++) {
				var ver = navigator.appVersion;
				if (ver.indexOf("MSIE") < 0)
				{
					i += 1;
				}
				if (i < oMenu.childNodes.length)
				{
					oMenu.childNodes[i].onmouseover = new Function("arrow(" + i + ",'over')");
					oMenu.childNodes[i].onmouseout = new Function("arrow(" + i + ",'out')");
					oMenu.childNodes[i].style.cursor = 'pointer';
				}
				
			}
		//}
		//catch (e)
		//{
		//	alert(e.description);	
		//}
	}
	else
	{
		alert('probleem');
	}
}

function arrow(id, action)
{
	document.getElementById('menu').childNodes[id].childNodes[0].src = '/templates/new/images/menu_arrow_'+action+'.gif';
}



// 		Price calculating scripts


function gameserver()
{
	fps = document.getElementById('fps');
	sum = document.getElementById('sum');
	spel = document.getElementById('spel');
	type = document.getElementById('type');
	slots = document.getElementById('slots');
	period = document.getElementById('period');
	totaal = document.getElementById('totaal');
	voorwaarden = document.getElementById('voorwaarden');
	bestellen = document.getElementById('bestellen');
	if (voorwaarden.checked)
	{
		bestellen.disabled = false;
	}
	else
	{
		bestellen.disabled = true;
	}
	if (spel.value != 0)
	{
		currslot = slots.value;
		base = price[spel.value][type.value];
		result = base + (((slots.value - 10) / 2) * price[spel.value][type.value+'plus']);
		if (period.value == 3)
		{
			total = result*3*0.9;
		}
		else {
			total = result*period.value;
		}
		sum.value = result;
		totaal.value = total;
		document.forms['prod'].slots.options.length = 0;
		s = 8;
		for (i = 0;i <= 8; i++)
		{
			s = s + 2;
			document.forms['prod'].slots.options[i] = new Option(s+' slots',s);
			if (s == currslot)
			{
				document.forms['prod'].slots.options[i].selected = true
			}
		}
	}
	else {
		sum.value = 0;
	}
}


// Webhosting function:
function webhosting()
{
	iCurrPrice = parseFloat(document.getElementById('prijs').value);
	price = Array();
	price['1'] = 30;
	price['2'] = 42;
	price['3'] = 78;
	price['4'] = 138;
	
	tlds = Array();
	tlds['BE'] = 13.00;
					tlds['NL'] = 9.99;
					tlds['COM'] = 13.50;
					tlds['ORG'] = 13.50;
					tlds['INFO'] = 13.50;
					tlds['biz'] = 13.50;
					tlds['name'] = 30.00;
					tlds['mobi'] = 40.00;
					tlds['NET'] = 13.50;
					tlds['EU'] = 17.50;
					tlds['de'] = 22.50;
					tlds['nu'] = 60.00;
					tlds['co.uk'] = 30.00;
					tlds['org.uk'] = 30.00;
					tlds['me.uk'] = 30.00;
					tlds['es'] = 22.50;
					tlds['us'] = 13.50;
					tlds['tk'] = 20.00;
					tlds['cc'] = 20.00;
					tlds['ws'] = 20.00;
					tlds['tv'] = 30.00;
					tlds['ac'] = 80.00;
					tlds['ag'] = 10.00;
					tlds['am'] = 75.00;
					tlds['bz'] = 30.00;
					tlds['cn'] = 30.00;
					tlds['gs'] = 22.50;
					tlds['in'] = 20.00;
					tlds['co.in'] = 20.00;
					tlds['io'] = 70.00;
					tlds['jp'] = 80.00;
					tlds['la'] = 40.00;
					tlds['ms'] = 22.50;
					tlds['ru'] = 40.00;
					tlds['sc'] = 40.00;
					tlds['sg'] = 55.00;
					tlds['sh'] = 70.00;
					tlds['tc'] = 22.50;
					tlds['tw'] = 40.00;
					tlds['com.tw'] = 40.00;
					tlds['vg'] = 22.50;
					
	iPrice = 0;
	if (document.getElementById('tld').value != 0)
	{
		iPrice = parseFloat(tlds[document.getElementById('tld').value]);
	}
	
	
	if (document.getElementById('pakket').value > 0)
	{
		iPrice += parseFloat(price[document.getElementById('pakket').value]);
	}
	
	document.getElementById('prijs').value = iPrice;
	
	
	voorwaarden = document.getElementById('voorwaarden');
	bestellen = document.getElementById('bestellen');
	if (voorwaarden.checked)
	{
		bestellen.disabled = false;
	}
	else
	{
		bestellen.disabled = true;
	}
}

//	Check domein
function checkDomein()
{
	
	sDomein = document.getElementById('domein').value;
	sTLD = document.getElementById('tld').value;
	if (sDomein.length > 0 && sTLD.length > 0)
	{
		  prepAJAX();
			
			var sUrl = "domeinCheck.php?domein=" + sDomein + '&tld='+ sTLD;
			var sVolledigeDomein = sDomein + '.' + sTLD;
			xmlHttp.onreadystatechange = function() 
			{
				if (xmlHttp.readyState == 4)
				{
					sResponse = xmlHttp.responseText;
					document.getElementById('domeinresult').innerHTML = '';
					if (sResponse == 'OK')
					{						
						document.getElementById('domeinresult').innerHTML += 'De domeinnaam (' + sVolledigeDomein + ') is verkrijgbaar!';
					}
					else if (sResponse == 'OK1' || sResponse == 'OK2')
					{
						document.getElementById('domeinresult').innerHTML += 'De domeinnaam (' + sVolledigeDomein + ') is (misschien) verkrijgbaar, er zijn geen whois records gevonden.';
					}
					else if (sResponse == 'U')
					{
						document.getElementById('domeinresult').innerHTML += 'Geen data verkrijgbaar voor dit domein (' + sVolledigeDomein + '), als u zeker bent dat dit domein vrij is gelieve verder te gaan.';
					}
					else if (sResponse == 'T')
					{
						document.getElementById('domeinresult').innerHTML += 'De domeinnaam (' + sVolledigeDomein + ') is al geregistreerd.';
					}
					else if (sResponse == 'E1')
					{
						document.getElementById('domeinresult').innerHTML += 'Gelieve een geldige domeinnaam  op te geven.';
					}
					else if (sResponse == 'E0')
					{
						document.getElementById('domeinresult').innerHTML += 'Er is iets misgelopen met het opzoeken van data, gelieve een admin te contacteren.';
					}
					else
					{
						document.getElementById('domeinresult').innerHTML += sResponse;
					}
				}
			};
			xmlHttp.open("GET",sUrl,true);
			xmlHttp.send(null);
	}
}


// Bouncers function:
function bouncers()
{
	aantal = document.getElementById('aantal');
	//maanden = document.getElementById('maanden');
	totaal = document.getElementById('totaal');
	voorwaarden = document.getElementById('voorwaarden');
	bestellen = document.getElementById('bestellen');
	if (voorwaarden.checked)
	{
		bestellen.disabled = false;
	}
	else
	{
		bestellen.disabled = true;
	}
	if (aantal.value == 0)
	{
		totaal.value = 0;
	}
	else
	{
		//totaal.value = aantal.value*1.5*maanden.value;
		totaal.value = aantal.value*12
	}
}


// Co locations:
function colocation(ch)
{
	/*
		price = Array();
		price['gb'] = Array();
		price['gb'][100] = 25;
		price['gb'][200] = 35;
		price['gb'][250] = 40;
		price['gb'][500] = 65;
		price['gb'][1000] = 125;
		price['gb'][2000] = 250;
		price['gb'][5000] = 500;
		price['gb'][10000] = 1000;
		
		price['mbit'] = Array();
		price['mbit'][1] = 32.50;
		price['mbit'][2] = 65;
		price['mbit'][5] = 162.50;
		price['mbit'][10] = 300;
		price['mbit'][15] = 450;
		price['mbit'][20] = 550;
		price['mbit'][30] = 750;
		price['mbit'][40] = 900;
		price['mbit'][50] = 1000;
	*/
	rackruimte = document.getElementById('rackruimte');
	bandbreedte = document.getElementById('bandbreedte');
	rpb = document.getElementById('rpb');
	backup = document.getElementById('backup');
	prijs = document.getElementById('prijs');
	
	var iPrijs = 0;

	
	iPrijs = rackruimte.value * 12.50;
	iPrijs += rpb.value * 10;
	iPrijs += backup.value * 2;
	
	if (bandbreedte.value != 0) {
		iPrijs += price['mbit'][bandbreedte.value];
		
	}

	
	
	prijs.value = iPrijs;
	
	
	voorwaarden = document.getElementById('voorwaarden');
	bestellen = document.getElementById('bestellen');
	if (voorwaarden.checked)
	{
		bestellen.disabled = false;
	}
	else
	{
		bestellen.disabled = true;
	}
}

function validateForm()
{
	oErrors = document.getElementById('errors');
	oErrors.innerHTML = '';
	sOkColor = '#000000';
	sErrorColor = '#CC0000';
	bOk = true;
	//	Aanhef
	oAanhef = document.getElementById('aanhef');
	oAanhef.style.backgroundColor = sOkColor;
	if (oAanhef.selectedIndex == 0)
	{
		oErrors.innerHTML += 'Gelieve een aanhef op te geven. <br />';
		oAanhef.style.backgroundColor = sErrorColor;
		bOk = false;
	}
	
	//	Voorletter
	oVoorletter = document.getElementById('voorletter');
	oVoorletter.style.backgroundColor = sOkColor;
	if (oVoorletter.value.length == 0)
	{
		oErrors.innerHTML += 'Gelieve een voorletter op te geven. <br />';
		oVoorletter.style.backgroundColor = sErrorColor;
	}
	
	//	Familienaam
	oFamilieNaam = document.getElementById('familienaam');
	oFamilieNaam.style.backgroundColor = sOkColor;
	if (oFamilieNaam.value.length == 0)
	{
		oErrors.innerHTML += 'Gelieve een familienaam op te geven. <br />';
		oFamilieNaam.style.backgroundColor = sErrorColor;
	}
	
	//	Geboortedatum
	oGebDag = document.getElementById('gebDag');
	oGebDag.style.backgroundColor = sOkColor;
	if (oGebDag.selectedIndex == 0)
	{
		oErrors.innerHTML += 'Gelieve een geboortedag op te geven. <br />';
		oGebDag.style.backgroundColor = sErrorColor;
		bOk = false;
	}
	oGebMaand = document.getElementById('gebMaand');
	oGebMaand.style.backgroundColor = sOkColor;
	if (oGebMaand.selectedIndex == 0)
	{
		oErrors.innerHTML += 'Gelieve een geboortemaand op te geven. <br />';
		oGebMaand.style.backgroundColor = sErrorColor;
		bOk = false;
	}
	oGebJaar = document.getElementById('gebJaar');
	oGebJaar.style.backgroundColor = sOkColor;
	if (oGebJaar.selectedIndex == 0)
	{
		oErrors.innerHTML += 'Gelieve een geboortejaar op te geven. <br />';
		oGebJaar.style.backgroundColor = sErrorColor;
		bOk = false;
	}
	oMail = document.getElementById('email');
	if (!validMail(oMail.value))
	{
		oErrors.innerHTML += 'Gelieve een correct email adres op tegeven. <br />';
		oMail.style.backgroundColor = sErrorColor;
		bOk = false;
	}
	
	arrsInputs = new Array('voorletter','familienaam','straat','postcode','gemeente','land','tel','email','username','pass','pass2');
	
	for (i = 0; i < arrsInputs.length;i++)
	{
		oInput = document.getElementById(arrsInputs[i]);
		oInput.style.backgroundColor = sOkColor;
		if (oInput.value.length == 0)
		{
			oErrors.innerHTML += 'Gelieve een ' + arrsInputs[i] + ' op te geven. <br />';
			oInput.style.backgroundColor = sErrorColor;
			bOk = false;
		}
	}
	
	oPass = document.getElementById('pass');
	oPass2 = document.getElementById('pass2');
	oPass.style.backgroundColor = sOkColor;
	oPass2.style.backgroundColor = sOkColor;
	if (oPass.value != oPass2.value)
	{
		oErrors.innerHTML += 'De passwoorden komen niet overeen. <br />';
		oPass.style.backgroundColor = sErrorColor;
		oPass2.style.backgroundColor = sErrorColor;
		bOk = false;
	}
	
	if (bOk)
	{
		return true;
	}
	else
	{
		return false;
	}
}


function validMail(sMail)
{
	sReg = /([A-Za-z0-9]|-|_|\.)*@([A-Za-z0-9]|-|_|\.)*\.([A-Za-z0-9]|-|_|\.)*/
	if (sMail.match(sReg))
	{
		return true;
	}
	else
	{
		return false;
	}
}
function showErvaring(iId)
{
	oErvaring = document.getElementById('ervaring' + iId);
	if (oErvaring.style.display != 'none')
	{
		oErvaring.style.display = 'none';
	}
	else
	{
		oErvaring.style.display = 'block';
	}
}

function approvedErvaring(iId)
{
	oErvaring = document.getElementById('approved' + iId);
	oTD = document.getElementById('select' + iId);
	if (oErvaring.selectedIndex == 0)
	{
		sApproved = 'Y';
	}
	else
	{
		sApproved = 'N';
	}
	prepAJAX();
	var sUrl = "?p=admin&content=ervaringen&do=approved&id=" + iId + "&approved=" + sApproved;
	xmlHttp.onreadystatechange = function() 
	{
		if (xmlHttp.readyState == 4)
		{
			if (xmlHttp.responseText != "error")
			{
				oTD.innerHTML = xmlHttp.responseText;
				alert('Gewijzigd!');
			}
			else
			{
				alert('Error, contacteer Disa.');
			}
		}
	};
	xmlHttp.open("GET",sUrl,true);
	xmlHttp.send(null);
}

function deleteErvaring(iId)
{
	oErvaring = document.getElementById('approved' + iId);
	oTR = document.getElementById('mainErvaring' + iId)	
	prepAJAX();
	
	var sUrl = "?p=admin&content=ervaringen&do=delete&id=" + iId;
	xmlHttp.onreadystatechange = function() 
	{
		if (xmlHttp.readyState == 4)
		{
			if (xmlHttp.responseText != "error")
			{
				oTR.style.display = 'none';
				oErvaring.style.display = 'none';
			}
			else
			{
				alert('Error, contacteer Disa.');
			}
		}
	};
	xmlHttp.open("GET",sUrl,true);
	xmlHttp.send(null);
}

function editErvaring(iId)
{
	sErvaring = document.getElementById('message' + iId).innerHTML;
	oTD = document.getElementById('tdErvaring' + iId);
	oTxt = document.createElement('textarea');
	oBtn = document.createElement('input');
	
	oTxt.setAttribute('id','txtErvaring' + iId);
	oTxt.id = 'txtErvaring' + iId;
	oTxt.setAttribute('rows','15');
	oTxt.setAttribute('cols','50');
	oTxt.innerHTML = sErvaring;
	
	oBtn.setAttribute('id','btnErvaring' + iId);	
	oBtn.setAttribute('type','button')
	oBtn.setAttribute('value','Edit');
	oBtn.onmousedown = new Function("sendErvaring(" + iId + ")");
	oBtn.className = 'input';
	
	oTD.innerHTML = '';
	
	oTD.appendChild(oTxt);
	oTD.appendChild(oBtn);
	
	tinyMCE.execCommand('mceAddControl', false, 'txtErvaring' + iId );
	
}

function sendErvaring(iId)
{
	oTXT = document.getElementById('txtErvaring' + iId);
	sTXT = oTXT.value;
	prepAJAX();
	
	var sUrl = "?p=admin&content=ervaringen";
	sParameters = 'do=edit&id=' + iId + "&message=" + encodeURI(sTXT);
	xmlHttp.overrideMimeType('text/html');
	xmlHttp.onreadystatechange = function() 
	{
		if (xmlHttp.readyState == 4)
		{
			if (xmlHttp.responseText != "error")
			{
				document.getElementById('tdErvaring' + iId).innerHTML = '';
				//onmousedown="editErvaring({ERVARINGEN.id})" style="margin:0px;margin-left:15px;"
				oP = document.createElement('p');
				oP.onmousedown = new Function("editErvaring(" + iId + ")");
				oP.style.margin = '0px';
				oP.style.marginLeft = '15px';
				oP.innerHTML = sTXT;
				document.getElementById('tdErvaring' + iId).appendChild(oP);
				alert(xmlHttp.responseText);		
				
				alert('Gewijzigd')
			}
			else
			{
				alert('Error, contacteer Disa.');
			}
		}
	};
	
    xmlHttp.open('POST', sUrl, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", sParameters.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(sParameters);
	
}
