//
//	Customer PASSWORD handling.
//
function customer_password_xmit( action ) {
	//
	//	What kind of password-action is required?
	//
	if( action != 'change' && action != 'forgotten' ) {
		alert('Action [change|forgotten] is not correct ...');
		return;
	}
	var thisAction				= action;
	//
	//	Collect all form data
	//
	var POSTthis				= '&action=' + action;
	//
	if( thisAction == 'change' ) {
		//
		var inputID					= 'cust_id';
		var objElem					= document.getElementById(inputID);
		if( objElem == null ) {
			alert('<INPUT> -' + inputID + '- not found ...');
			return;
		}
		POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
		//
		var inputID					= 'wachtwoordoud';
		var objElem					= document.getElementById(inputID);
		if( objElem == null ) {
			alert('<INPUT> -' + inputID + '- not found ...');
			return;
		}
		POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
		//
		var inputID					= 'wachtwoord';
		var objElem					= document.getElementById(inputID);
		if( objElem == null ) {
			alert('<INPUT> -' + inputID + '- not found ...');
			return;
		}
		POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
		//
		var inputID					= 'wachtwoord2';
		var objElem					= document.getElementById(inputID);
		if( objElem == null ) {
			alert('<INPUT> -' + inputID + '- not found ...');
			return;
		}
		POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
		//
	} else {
		//
		var inputID					= 'email';
		var objElem					= document.getElementById(inputID);
		if( objElem == null ) {
			alert('<INPUT> -' + inputID + '- not found ...');
			return;
		}
		POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	}
	//
	//	Show we're going to do some AJAX
	var ajax_busy				= document.getElementById('ajax_busy');
	ajax_busy.style.display		= 'inline';
	//
	//	AJAX the request & POST the data with it
	var url						=	'/functions/customer/customer_password.php';
	var myAjax					=	new Ajax.Request(
										url,
										{
											method: 'post',
											parameters: POSTthis,
											onSuccess: customer_password_receive
										}
									);
}

function customer_password_receive( response ) {
	var customer_data			= response.responseText;
	var customer_check			= customer_data.substr(0,2);
	//
	//	Show we're done with AJAX
	//
	var ajax_busy				= document.getElementById('ajax_busy');
	ajax_busy.style.display		= 'none';		// Fast(er) disappear !
	//
	//	Any errors or not?
	//
	if( customer_check != 'ok' ) {
		var error_text				= 'During filling the form, the following is detected:' + "\n" + customer_data.substr(2);
		alert(error_text);
		return;
	}
	//
	var customer_action			= customer_data.substr(2,6);
	if( customer_action == 'change' ) {
		alert("\nYour password is changed.");
	} else {
		alert("\nA new password is sent to you by e-mail.");
	}
	location.href				= '/';
}



//
//	Customer FORM handling.
//
function customer_form_xmit( type, action ) {
	//
	//	What kind of customer-form is setup?
	//
	if( type != 'customer' && type != 'reseller' ) {
		alert('Type [customer|reseller] is not correct ...');
		return;
	}
	var thisType				= type;
	//
	//	Does the visitor want to change to type op customer?
	//
	if( thisType == 'customer' ) {
		var account_choice			= '';
		var account					= document.getElementById('account_customer');
		if( account == null ) {
			alert('<INPUT> -account_customer- not found ...');
			return;
		}
//		if( account.checked ) {
			account_choice		= account.value;
//		}
//		var account					= document.getElementById('account_reseller');
//		if( account == null ) {
//			alert('<INPUT> -account_reseller- not found ...');
//			return;
//		}
//		if( account.checked ) {
//			account_choice				= account.value;
//		}
		if( account_choice == '' ) {
			alert('Make first a choice for which kind of account you want ...');
			return;
		}
		if( account_choice != 'customer' && account_choice != 'reseller' ) {
			alert('Account keuze [customer|reseller] is not correct ...');
			return;
		}
		thisType					= account_choice;
	}
	//
	//	What kind of customer-form is setup?
	//
	if( action != 'add' && action != 'change' ) {
		alert('Action [add|change] is not correct ...');
		return;
	}
	//
	//	Collect all form data
	//
	var POSTthis				= '&type=' + thisType;
	POSTthis					+= '&action=' + action;
	//
	var inputID					= 'bedrijf';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'voornaam';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'tussenvoegsel';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'achternaam';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'adres';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'huisnummer';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'postcode';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'woonplaats';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'land';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'telefoon';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'email';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'btwnummer';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'kvknummer';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'opmerking';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'gebruikersnaam';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	if( action == 'change' ) {
		var inputID					= 'cust_id';
		var objElem					= document.getElementById(inputID);
		if( objElem == null ) {
			alert('<INPUT> -' + inputID + '- not found ...');
			return;
		}
		POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
		//
		var inputID					= 'wachtwoordoud';
		var objElem					= document.getElementById(inputID);
		if( objElem == null ) {
			alert('<INPUT> -' + inputID + '- not found ...');
			return;
		}
		POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	}
	//
	var inputID					= 'wachtwoord';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'wachtwoord2';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	//	Show we're going to do some AJAX
	var ajax_busy				= document.getElementById('ajax_busy');
	ajax_busy.style.display		= 'inline';
	//
	//	AJAX the request & POST the data with it
	var url						=	'/functions/customer/customer_form.php';
	var myAjax					=	new Ajax.Request(
										url,
										{
											method: 'post',
											parameters: POSTthis,
											onSuccess: customer_form_receive
										}
									);
}

function customer_form_receive( response ) {
	var customer_data			= response.responseText;
	var customer_check			= customer_data.substr(0,2);
	//
	//	Show we're done with AJAX
	//
	var ajax_busy				= document.getElementById('ajax_busy');
	ajax_busy.style.display		= 'none';		// Fast(er) disappear !
	//
	//	Any errors or not?
	//
	if( customer_check != 'ok' ) {
		var error_text				= 'During filling the form, the following is detected:' + "\n" + customer_data.substr(2);
		alert(error_text);
		return;
	}
	//
	var customer_action			= customer_data.substr(2,3);
	if( customer_action == 'add' ) {
		alert("\nRegistration is completed.");
	} else {
		alert("\nRegistration is changed.");
	}
	location.href				= '/';
}



//
//	Anonymous FORM handling.
//
var	next_page		= '/';
function anonymous_xmit( type ) {
	//
	//	What kind of customer-form is setup?
	//
	if( type != 'address' && type != 'delivery' ) {
		alert('Type [address|delivery] is not correct ...');
		return;
	}
	var thisType				= type;
	//
	var inputID					= 'next_page';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	next_page					= objElem.value;
	//
	//	Collect all form data
	//
	var POSTthis				= '&type=' + thisType;
	//
	var inputID					= 'orderid';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'voornaam';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'tussenvoegsel';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'achternaam';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'adres';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'huisnummer';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'postcode';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'woonplaats';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	var inputID					= 'land';
	var objElem					= document.getElementById(inputID);
	if( objElem == null ) {
		alert('<INPUT> -' + inputID + '- not found ...');
		return;
	}
	POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
	//
	if( type == 'address' ) {
		//
		var inputID					= 'telefoon';
		var objElem					= document.getElementById(inputID);
		if( objElem == null ) {
			alert('<INPUT> -' + inputID + '- not found ...');
			return;
		}
		POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
		//
		var inputID					= 'email';
		var objElem					= document.getElementById(inputID);
		if( objElem == null ) {
			alert('<INPUT> -' + inputID + '- not found ...');
			return;
		}
		POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
		//
	} else {
		//
		var inputID					= 'bericht';
		var objElem					= document.getElementById(inputID);
		if( objElem == null ) {
			alert('<INPUT> -' + inputID + '- not found ...');
			return;
		}
		POSTthis					+= '&' + inputID + '=' + myEscape(objElem.value);
		//
	}
	//
	//	Show we're going to do some AJAX
	var ajax_busy				= document.getElementById('ajax_busy');
	ajax_busy.style.display		= 'inline';
	//
	//	AJAX the request & POST the data with it
	var url						=	'/functions/customer/anonymous_form.php';
	var myAjax					=	new Ajax.Request(
										url,
										{
											method: 'post',
											parameters: POSTthis,
											onSuccess: anonymous_receive
										}
									);
}

function anonymous_receive( response ) {
	var customer_data			= response.responseText;
	var customer_check			= customer_data.substr(0,2);
	//
	//	Show we're done with AJAX
	//
	var ajax_busy				= document.getElementById('ajax_busy');
	ajax_busy.style.display		= 'none';		// Fast(er) disappear !
	//
	//	Any errors or not?
	//
	if( customer_check != 'ok' ) {
		var error_text				= 'During filling the form, the following is detected:' + "\n" + customer_data.substr(2);
		alert(error_text);
		return;
	}
	//
	location.href				= next_page;
}


function myEscape( str ) {
	str		= escape(str);
	return str;
}
