// JavaScript Document

// js handling profile data

// constants
var NORMAL_STATE = 4;
var GEGEVENS_PREFIX = '/core/gegevens.php?';

// variables
var http = getHTTPObject(); // We create the HTTP Object
var hasSeed = false;
var loggedIn = false;
var seed_id = 0;
var seed = 0;
var fullname = '';
var messages = '';

// getSeed method:  gets a seed from the server for this transaction
function getSeed() 
{		// only get a seed if we're not logged in and we don't already have one
	if (!loggedIn && !hasSeed) {
		// open up the path
		http.open('GET', GEGEVENS_PREFIX + 'task=getseed', true);
		http.onreadystatechange = handleHttpGetSeed;
		http.send(null);
		
	}
}

// handleHttpGetSeed method: called when the seed is returned from the server
function handleHttpGetSeed()
{
	// if there hasn't been any errors
	if (http.readyState == NORMAL_STATE) {
		// split by the divider |
		results = http.responseText.split('|');
		
		// id is the first element
		seed_id = results[0];
		
		// seed is the second element
		seed = results[1];
		
		// now we have the seed
		hasSeed = true;
	}
}


function validateGegevens()
{
	passwordString = "";
	email = document.getElementById('email').value;
	mobile = document.getElementById('cellphone').value;
	license = document.getElementById('plate').value;
	if(document.getElementById('password').value != "" && document.getElementById('confirm_password').value != "")
		passwordString = "&password="+document.getElementById('password').value+"&confirm="+document.getElementById('confirm_password').value;
	// open the http connection
	http.open('GET', GEGEVENS_PREFIX + 'task=checkgegevens&email='+email+'&id='+seed_id+'&mobile='+mobile+'&license='+license+passwordString, true);
	
	// where to go
	http.onreadystatechange = handleHttpValidateGegevens;
	http.send(null);

}



function handleHttpValidateGegevens()
{
	
	
	// did the connection work?
	if (http.readyState == NORMAL_STATE) {
		// split by the pipe
		results = http.responseText.split('$$');
		document.getElementById('password').value = "";
		document.getElementById('confirm_password').value = "";
		document.getElementById("summary").innerHTML = results[1];
		document.getElementById("summary").style.display = 'block';
	}
}
