/**
 *  Ajax Request zum Einloggen eines Users
 */

function login( mail, password ) {
	
	function response() {
				
		if ( client.status == 200 && client.readyState == 4 ) {
						
			document.getElementById('holder').innerHTML = client.responseText;
								
		}
		
	}	
	
	var param = 'mail=' + mail + '&password=' + password;
		
	client = new XMLHttpRequest();
	client.onreadystatechange = function() { response(); };
	
	client.open( "POST", "/shop/wp-content/themes/featurepitch/shop/login.php", true);
	client.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	client.setRequestHeader("Content-Length", param.length );
	client.setRequestHeader("Connection", "close");	
	client.send(param);

}

function listorders() {
	
		function response() {
			
			if (client.readyState == 1) {
				
				document.getElementById('orderdata').innerHTML = "<img src='/shop/wp-content/themes/featurepitch/shop/images/loading.gif' title='Suche Toner' alt='Suche l&auml;ft' style='text-align:center; display:block;margin:auto;border:none' />";
				
			}
			
			if ( client.status == 200 && client.readyState == 4 ) {
				
				document.getElementById('orderdata').innerHTML = client.responseText;
							
			}
			
		}	
		
		var param = 'action=listorders';
		
		client = new XMLHttpRequest();
		client.onreadystatechange = function() { response(); };
		
		client.open( "POST", "/shop/wp-content/themes/featurepitch/shop/login.php", true);
		client.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		client.setRequestHeader("Content-Length", param.length );
		client.setRequestHeader("Connection", "close");	
		client.send(param);
		
}

function listcustomer() {
	
	function response() {
		
		if  (client.readyState == 1) {
			
			document.getElementById('customerdata').innerHTML = "<img src='/shop/wp-content/themes/featurepitch/shop/images/loading.gif' title='Suche Toner' alt='Suche l&auml;ft' style='text-align:center; display:block;margin:auto;border:none' />";
			
		}
		
		if ( client.status == 200 && client.readyState == 4 ) {
			
			document.getElementById('customerdata').innerHTML = client.responseText;
						
		}
		
	}	
	
	var param = 'action=listcustomer';
	
	client = new XMLHttpRequest();
	client.onreadystatechange = function() { response(); };
	
	client.open( "POST", "/shop/wp-content/themes/featurepitch/shop/login.php", true);
	client.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	client.setRequestHeader("Content-Length", param.length );
	client.setRequestHeader("Connection", "close");	
	client.send(param);
		
}

function setcustomer(title, firstname, lastname, email, phone, street, streetnumber, postcode, city, company) {
	
	function response() {
		
		if ( client.status == 200 && client.readyState == 4 ) {
			
			document.getElementById('change').innerHTML = client.responseText;
						
		}
		
	}	
	
	var param = "Title=" + title + "&FirstName=" + firstname + "&LastName=" + lastname;
	param += "&Telephone=" + phone + "&Email=" + email + "&Street=" + street + "&StreetNumber=" + streetnumber + "&Postcode=" + postcode;
	param += "&City=" + city + '&Company=' + company + '&action=setcustomer';	
	
	client = new XMLHttpRequest();
	client.onreadystatechange = function() { response(); };
	
	client.open( "POST", "/shop/wp-content/themes/featurepitch/shop/login.php", true);
	client.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	client.setRequestHeader("Content-Length", param.length );
	client.setRequestHeader("Connection", "close");	
	client.send(param);
		
}

function logout( mail ) {
	
	function response() {
		
		if ( client.status == 200 && client.readyState == 4 ) {
			
			document.getElementById('holder').innerHTML = client.responseText;
						
		}
		
	}	
	
	var param = 'action=logout&email=' + mail;
	
	client = new XMLHttpRequest();
	client.onreadystatechange = function() { response(); };
	
	client.open( "POST", "/shop/wp-content/themes/featurepitch/shop/login.php", true);
	client.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	client.setRequestHeader("Content-Length", param.length );
	client.setRequestHeader("Connection", "close");	
	client.send(param);
	
}
