  /***************************************\
  *                                       *
  *        DualDevelopment Project        *
  *          DualDevelopment.com          *
  *                                       *
  \***************************************/

  /***************************************\
  *                                       *
  *                OBJECT                 *
  *                                       *
  \***************************************/

  function XMLHttp_request()
  {

          this.isIE               = false;
          this.allow_use          = false;
          this.xmlhandler         = null;
          this.error_string       = null;
          this.nocache            = true;
          this.do_request_functon = function() {}
          this.loading_fired      = 0;
          this.centerdiv          = null;

  }

  /***************************************\
  *                                       *
  *           OBJECT FUNCTIONS            *
  *                                       *
  \***************************************/

  XMLHttp_request.prototype.xml_init = function()
  {

          try
          {

                  /* Moz, Opera, Safari */

                  this.xmlhandler = new XMLHttpRequest();
                  this.ie        = false;
                  this.allow_use = true;

                  return true;

          }
          catch(e)
          {

                  try
                  {

                          /* Internet Explorer 5.1 + */

                          this.xmlhandler = new ActiveXObject('Microsoft.XMLHTTP');
                          this.ie        = true;
                          this.allow_use = true;

                          return true;

                  }
                  catch(e)
                  {

                          /* Internet Explorer 5.0 - */

                          this.ie        = true;
                          this.allow_use = false;

                          return false;

                  }

          }

  }

  XMLHttp_request.prototype.process = function( url, type, post )
  {

          type = type == "POST" ? "POST" : "GET";


          if ( this.nocache == true  && type == 'GET' )
          {

                  url = this.nocache_url( url );

          }

          if ( ! this.xmlhandler )
          {

                  this.xml_init();

          }

          if ( ! this.readystate_not_ready() )
          {

                  this.xmlhandler.open(type, url, true);

                  if ( type == "GET" )
                  {

                          this.xmlhandler.send(null);

                  }
                  else
                  {

                          if ( typeof( this.xmlhandler.setRequestHeader ) != "undefined" )
                          {

                                  this.xmlhandler.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                                  this.xmlhandler.setRequestHeader('Connection', 'close');

                          }

                          this.xmlhandler.send( post );

                  }

                  if ( this.xmlhandler.readyState == 4 && this.xmlhandler.status == 200 )
                  {

                          return true;

                  }

          }

          return false;

  }

  XMLHttp_request.prototype.get_element_text_ns = function(prefix, local, parentElem, index)
  {

          var result = null;

          if ( prefix && this.isIE )
          {

                  /* Internet Explorer */

                  result = parentElem.getElementsByTagName(prefix + ":" + local)[index];

          }
          else
          {

                  /* Safari, Moz */

                  result = parentElem.getElementsByTagName(local)[index];

          }

          if ( result )
          {

                  if (result.childNodes.length > 1)
                  {

                          return result.childNodes[1].nodeValue;

                  }
                  else
                  {

                          return result.firstChild.nodeValue;

                  }

          }
          else
          {

                  return "n/a";

          }

  }

  XMLHttp_request.prototype.replacearray = function (array)
  {

          var repl = new Array( "Array\n", "(\n", ")\n" );
          for( var i in repl )
          {

                  array = array.replace( repl[i], '' );

          }

          return array;

  }

  XMLHttp_request.prototype.requestarray = function (array)
  {

          var isarray = new Array( );
          array       = this.replacearray(array);
          var iscount = array.split( "\n" );
          for( var i in iscount )
          {

                  if( iscount[i] != '' && iscount[i] != "\n" )
                  {

                          var newdef = iscount[i].split( '[' );
                          var isdef  = newdef[1].split( ']' );
                          var newval = array.split( '[' + isdef[0] + '] => ' );
                          var isval  = newval[1].split( "\n    [" );

                          isarray[isdef[0]] = isval[0];

                  }

          }

          return isarray;

  }

  XMLHttp_request.prototype.nocache_url = function (url)
  {

          var sep    = ( -1 < url.indexOf("?") ) ? "&" : "?";
          var mydate = new Date();
          var newurl = url + sep + "__=" + mydate.getTime();

          return newurl;

  }

  XMLHttp_request.prototype.format_for_post = function( arrayfields )
  {

          var str = '';

          try
          {

                  for( var i in arrayfields )
                  {

                          str += i + '=' + this.encodeurl(arrayfields[i]) + '&';

                  }

          }
          catch(e)
          {

          }

          return str;

  }

  XMLHttp_request.prototype.encodeurl = function( url )
  {

          url = url.toString();

          var regcheck = url.match(/[\x90-\xFF]/g);

          if ( regcheck )
          {

                  for (var i = 0; i < i.length; i++)
                  {

                          url = url.replace(regcheck[i], '%u00' + (regcheck[i].charCodeAt(0) & 0xFF).toString(16).toUpperCase());

                  }

          }

          return escape(url).replace(/\+/g, "%2B");

  }

  XMLHttp_request.prototype.readystate_not_ready = function()
  {

          return ( this.xmlhandler.readyState && ( this.xmlhandler.readyState < 4 ) );

  }

  XMLHttp_request.prototype.readystate_ready_and_ok = function()
  {

          return ( this.xmlhandler.readyState == 4 && this.xmlhandler.status == 200 ) ? true : false;

  }

  XMLHttp_request.prototype.onreadystatechange = function( event )
  {

          if ( ! this.xmlhandler )
          {

                  this.xml_init();

          }

          if ( typeof(event) == 'function' )
          {

                  this.xmlhandler.onreadystatechange = event;

          }

  }


function $ ( Target )
{
	return document.getElementById(Target);  
}


function doLoading ( Target, Bericht )
{
	var Img = '<img src="Assets/Afbeeldingen/Loading.gif" alt="Loading..." />';	
			
	$( Target ).innerHTML = Img + ' ' + Bericht;
}


function LogIn( LocationNew )
{
	
	if ( $('Gebruikersnaam').value == '' )
	{
		
		$('Status').style.color = '#c9302d';
		$('Status').innerHTML	= 'U vulde uw gebruikersnaam niet in.';
		
	}
	else if ( $('Wachtwoord').value == '' )
	{
	
		$('Status').style.color = '#c9302d';
		$('Status').innerHTML	= 'U vulde uw wachtwoord niet in.';
	
	}
	else
	{
		
		doLoading('Status', 'Een ogenblik geduld... Uw gegevens worden gecontroleerd.')
		
		var Handler		  = null;
		var Post		  = new Array();
			Post['User']  = $('Gebruikersnaam').value;
			Post['Pass']  = $('Wachtwoord').value;
			
		if ( $('Onthoud').checked )
		{
			Post['Remember'] = '_saveCurrent';	
		}
			
		Request = function ()
				  {
					
					if ( Handler.xmlhandler.readyState == 4 && Handler.xmlhandler.status == 200 )
					{
						
						if ( Handler.xmlhandler.responseText )
						{
							
							var Response = Handler.xmlhandler.responseText;
							
							if ( Response == 'Ingelogd' )
							{
								
								window.location = LocationNew;
								
							}
							else
							{
								
								$('Status').style.color = '#c9302d';
								$('Status').innerHTML	= 'De gegevens die u invulde bleken niet juist te zijn.';
								
							}
							
							
						}
						
					}
					
				  }
		Handler = new XMLHttp_request();
		Handler.process('Assets/Scripts/Inloggen.ajax.php', 'POST', Handler.format_for_post ( Post ) );
		Handler.onreadystatechange ( Request );
	
	}

}

function Register( )
{
	
	if ( $('Gebruikersnaam2').value == '' )
	{
		
		$('Status').style.color = '#c9302d';
		$('Status').innerHTML	= 'U vulde geen gebruikersnaam in.';
		
	}
	else if ( $('Wachtwoord2').value == '' )
	{
	
		$('Status').style.color = '#c9302d';
		$('Status').innerHTML	= 'U vulde geen wachtwoord in.';
	
	}
	else if ( $('Wachtwoord3').value == '' )
	{
	
		$('Status').style.color = '#c9302d';
		$('Status').innerHTML	= 'U vulde geen bevestigings wachtwoord in.';
	
	}
	else if ( $('Wachtwoord3').value != $('Wachtwoord2').value )
	{
	
		$('Status').style.color = '#c9302d';
		$('Status').innerHTML	= 'De wachtwoorden die u invulde kwamen niet met elkaar overeen.';
	
	}
	else if ( $('Naam').value == '' )
	{
	
		$('Status').style.color = '#c9302d';
		$('Status').innerHTML	= 'U vulde uw naam niet in.';
	
	}
	else if ( $('Achternaam').value == '' )
	{
	
		$('Status').style.color = '#c9302d';
		$('Status').innerHTML	= 'U vulde uw achternaam niet in.';
	
	}
	else if ( $('Huisnummer').value == '' )
	{
	
		$('Status').style.color = '#c9302d';
		$('Status').innerHTML	= 'U vulde uw huisnummer niet in.';
	
	}
	else if ( $('Straat').value == '' )
	{
	
		$('Status').style.color = '#c9302d';
		$('Status').innerHTML	= 'U vulde uw straat niet in.';
	
	}
	else if ( $('Postcode').value == '' )
	{
	
		$('Status').style.color = '#c9302d';
		$('Status').innerHTML	= 'U vulde uw postcode niet in.';
	
	}
	else if ( $('Plaats').value == '' )
	{
	
		$('Status').style.color = '#c9302d';
		$('Status').innerHTML	= 'U vulde uw woonplaats niet in.';
	
	}
	else if ( $('Telefoon').value == '' )
	{
	
		$('Status').style.color = '#c9302d';
		$('Status').innerHTML	= 'U vulde uw telefoonnummer niet in.';
	
	}
	else if ( $('Email').value == '' )
	{
	
		$('Status').style.color = '#c9302d';
		$('Status').innerHTML	= 'U vulde uw e-mail adres niet in.';
	
	}
	else
	{
		
		doLoading('Status', 'Een ogenblik geduld... Uw gegevens worden verwerkt.')
		
		var Handler		  = null;
		var Post		  = new Array();
			Post['User']  = $('Gebruikersnaam2').value;
			Post['Pass']  = $('Wachtwoord2').value;
			Post['Name']  = $('Naam').value;
			Post['Last']  = $('Achternaam').value;
			Post['hNr']   = $('Huisnummer').value;
			Post['Stra']  = $('Straat').value;
			Post['Post']  = $('Postcode').value;
			Post['Plaa']  = $('Plaats').value;
			Post['Tele']  = $('Telefoon').value;
			Post['Mail']  = $('Email').value;
			Post['Tuss']  = $('Tussenvoegsels').value;
			
		Request = function ()
				  {
					
					if ( Handler.xmlhandler.readyState == 4 && Handler.xmlhandler.status == 200 )
					{
						
						if ( Handler.xmlhandler.responseText )
						{
							
							var Response = Handler.xmlhandler.responseText;
							
							if ( Response == 'userExists' )
							{
								
								$('Status').style.color = '#c9302d';
								$('Status').innerHTML	= 'De gebruikersnaam die u koos is reeds in gebruik.';
								
							}
							else if ( Response == 'emailExists' )
							{
								
								$('Status').style.color = '#c9302d';
								$('Status').innerHTML	= 'Het e-mail adres dat u opgaf is reeds in gebruik.';
								
							}
							else if ( Response == 'badMail' )
							{
								
								$('Status').style.color = '#c9302d';
								$('Status').innerHTML	= 'Het e-mail adres dat u opgaf bleek niet geldig te zijn.';
								
							}
							else if ( Response == 'badPass' )
							{
								
								$('Status').style.color = '#c9302d';
								$('Status').innerHTML	= 'Het wachtwoord dat u koos bleek onveilig te zijn. <br /> Een wachtwoord dient langer te zijn dan 6 tekens.';
								
							}
							else
							{
								
								window.location = 'index.php?Pagina=Betalen.php';
								
							}
							
							
						}
						
					}
					
				  }
		Handler = new XMLHttp_request();
		Handler.process('Assets/Scripts/Registreer.ajax.php', 'POST', Handler.format_for_post ( Post ) );
		Handler.onreadystatechange ( Request );
	
	}

}

function placeOrder( OrderId )
{
	
		
	var Handler		  		= null;
	var Post		  		= new Array();
		Post['Order']  		= OrderId;
		Post['Naam']  		= $('Naam').value;
		Post['Adres']  		= $('Straat').value;
		Post['Postcode']  	= $('Postcode').value;
		Post['Woonplaats']  = $('Woonplaats').value;
				
	Request = function ()
			  {
				
				if ( Handler.xmlhandler.readyState == 4 && Handler.xmlhandler.status == 200 )
				{
					
					if ( Handler.xmlhandler.responseText )
					{
						
						var Response = Handler.xmlhandler.responseText;
						
						if ( Response == 'Succes' )
						{
							
							alert('U verlaat nu de website om te gaan betalen. Let op: u moet terugkeren op deze website na de betaling om de bestelling succesvol af te ronden!');

							document.getElementById('payOrder').submit();
							
						}
						else
						{
							
							alert('Er ging iets mis tijdens het verwerken van de gegevens. Gelieve contact op te nemen met de webmaster wanneer deze melding herhadelijk voorkomt.');
							
						}
						
						
					}
					
				}
				
			  }
	Handler = new XMLHttp_request();
	Handler.process('Assets/Scripts/placeOrder.ajax.php', 'POST', Handler.format_for_post ( Post ) );
	Handler.onreadystatechange ( Request );

}