var h = 0;
var w = 0;

var afrekenen = 0;

var xmlhttp;

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	if(isIE)
		return window[movieName];
	else
		return document[movieName];
}

function getDim() {
	if( typeof( window.innerWidth ) == 'number' ) 
	{
		h = window.innerHeight;
		w = window.innerWidth;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		h = document.documentElement.clientHeight;
		w = document.documentElement.clientWidth;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		h = document.body.clientHeight;
		w = document.body.clientWidth;
	}
	
	h = h - 150;	
	w = w - 150;
}

function setDim() {
	getDim();
	document.getElementById('achtergrondimg').style.width = w + "px";
	document.getElementById('achtergrondimg').style.height = (w * 863/1300) + "px";
	document.getElementById('pagina').style.height = (h + 130) + "px";
}

function swfLoaded()
{
	setDimHome();
}

function setDimHome() {
	getDim();
	//getFlashMovie('asjs').setAsDim(w,h+10);
	document.getElementById('contenthome').style.width = w + "px";
	document.getElementById('contenthome').style.height = (h+10) + "px";
	//document.getElementById('pagina').style.height = (h + 130) + "px";

}

function setDimComplete()
{
	//document.getElementById('contenthome').style.width = w + "px";
	//document.getElementById('contenthome').style.height = (h+10) + "px";
}

function trace(inn)
{
	//alert(inn);
}

function checkint(ipt, type)
{
	var t = parseInt(Math.floor(ipt.value));
	if(isNaN(t) || t == "")
		ipt.value = 0;
	else
		ipt.value = t;
	updatedivers(ipt, type);
}


//brrodjes lunch

function volgende(nummer)
{
	afrekenen = 1;
	getpopup(nummer);
}

function updateveld(ipt, check)
{
	switch(check)
	{
		case 1:
		  	var rExp = /^[0-3]{0,1}[0-9]{1}-[0-1]{0,1}[0-9]{1}-201[0-9]{1}$/;
			if (!rExp.exec(ipt.value)) {
				ipt.style.borderColor = "Red";
				return false;
			} else {
			ipt.style.borderColor = "White";
			}
		break;
		case 2:
		  	var rExp = /^[0-2]{0,1}[0-9]{1}:[0-5]{1}[0-9]{1}$/;
			if (!rExp.exec(ipt.value)) {
				ipt.style.borderColor = "Red";
				return false;
			} else {
			ipt.style.borderColor = "White";
			}
		break;
		case 3: 	
			if(ipt.value.length == 0) {			         
			   ipt.style.borderColor = "Red";
			   return false;
			} else {
			   ipt.style.borderColor = "White";
			}
		break;
		case 5:
			ipt.value = ipt.value.toUpperCase().split(' ').join('');
			var rExp = /^[1-8]{1}[0-9]{3}[A-Z]{2}$/;
			if (!rExp.exec(ipt.value)) {
				ipt.style.borderColor = "Red";
				return false;
			} else {
			ipt.style.borderColor = "White";
			}
		break;
		case 6:
			var rExp = /^[0-9]{10}|[0-9]{2}\-[0-9]{8}|[0-9]{3}\-[0-9]{7}|[0-9]{4}\-[0-9]{6}$/i;
			if (!rExp.exec(ipt.value)) {
				ipt.style.borderColor = "Red";
				return false;
			} else {
			ipt.style.borderColor = "White";
			}
		break;
		

	}
	
	
	
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="updateveld.php?waarde="+ipt.value+"&veld="+ipt.name+"&sid="+Math.random();
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
	if(check == 7)
		getpopup(-4);

	
	return true;
}


function updatepc(ipt)
{
	ipt.value = ipt.value.toUpperCase().split(' ').join('');
	var rExp = /^[1-8]{1}[0-9]{3}[A-Z]{2}$/;
	if (!rExp.exec(ipt.value)) {
		ipt.style.borderColor = "Red";
		return false;
	} else {
		ipt.style.borderColor = "White";
		http=GetXmlHttpObject();
		if (http==null)
		  {
		  alert ("Browser does not support HTTP Request");
		  return;
		  }
		var url="postcode.php";
		var params = "waarde="+ipt.value+"&veld="+ipt.name+"&sid="+Math.random();
		http.open("POST", url, true);
		http.onreadystatechange=pcantwoord;
		
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");
		
		http.send(params);
	}
	return true;

}

function pcantwoord()
{
	if (http.readyState==4)
	{
		if(http.responseText == "fout")
		{
			alert("Op deze postcode wordt niet geleverd");
			document.getElementById('pcvolgende').href = "javascript:getpopup(-1)";
		}
		else
			document.getElementById('pcvolgende').href = "javascript:getpopup(-2)";
	}
}

function updatebtw(ipt)
{
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="updateveld.php?waarde="+ipt+"&veld=betalingw&sid="+Math.random();

	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

	getpopup(-4);
}

function updatedivers(ipt, type)
{
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="updatedivers.php";
	url=url+"?aantal="+ipt.value+"&id="+ipt.name+"&type="+type+"&sid="+Math.random();
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function login()
{
	http=GetXmlHttpObject();
	if (http==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="login.php";
	var params = "login="+document.getElementById('login').value+"&wachtwoord="+document.getElementById('wachtwoord').value;

	http.open("POST", url, true);
	http.onreadystatechange=loginantwoord;

	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.send(params);
}

function loginantwoord()
{
	if (http.readyState==4)
	{
		if(http.responseText != "ok")
			document.getElementById("loginspan").innerHTML=http.responseText;
		else
			getpopup(-1);
	}
}

function getpopup(ipt, token, payerid)
{
	if(ipt == -2)
	{
		var fout = false;
		if(!updateveld(document.getElementById('gdatum'), 1))
			fout = true;
		if(!updateveld(document.getElementById('gtijd'), 2))
			fout = true;
		if(!updateveld(document.getElementById('naam'), 3))
			fout = true;
		if(!updateveld(document.getElementById('adres'), 3))
			fout = true;
		if(!updatepc(document.getElementById('postcode')))
			fout = true;
		if(!updateveld(document.getElementById('plaats'), 3))
			fout = true;
		if(!updateveld(document.getElementById('telefoon'), 6))
			fout = true;
		if(fout)
			return;
	}

	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="getpopup.php";
	
	url=url+"?id="+ipt+"&token="+token+"&payerid="+payerid+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function getpopupcatering(ipt)
{
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="getpopupcatering.php";
	url=url+"?id="+ipt+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function stateChanged()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("popup").innerHTML=xmlhttp.responseText;
		centerPopup();
		loadPopup();
	}
}

function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}
