function changeMoney(version)
{
	document.forms['form_commande'].method = "POST";
	document.forms['form_commande'].action = "/order/ts" + version + "_server";
	document.forms['form_commande'].submit();
}

function sliderTS3()
{
	window.addEvent('domready', function(){
		var el = $('transfert');
		var res = $('result_transfert');
		
		new Slider(el, el.getElement('.knob_transfert'), {
			steps: 5001,
			range: [300],
			wheel: true,
			onChange: function(value)
			{
				res.innerHTML = value + ' Kb/s';
			}
		}).set(10);
		
		
		var elSpace = $('space');
		var resSpace = $('result_space');
		
		new Slider(elSpace, elSpace.getElement('.knob_space'), {
			steps: 10000,
			range: [100],
			wheel: true,
			onChange: function(value)
			{
				resSpace.innerHTML = value + ' Mo';
			}
		}).set(10);
	});
}


function delUserSec(user)
{
	if(confirm("Do you really want to delete this user ?"))
	{
		window.location.replace('/customer_area/my_users?action=delete&user=' + user);
	}
}


function showWoman()
{
	if(document.getElementById('woman').style.display == "none")
	{
		document.getElementById('woman').style.display = "block";
	}
	else
	{
		document.getElementById('woman').style.display = "none";
	}
}

function effectuerVirement(id)
{
	var pseudo = document.getElementById('loginDestinataire').value;
	var montant_gbp = document.getElementById('montant_gbp').value;
	var montant_usd = document.getElementById('montant_usd').value;
	var montant_eur = document.getElementById('montant_eur').value;
	var montant_cad = document.getElementById('montant_cad').value;
	var montant_chf = document.getElementById('montant_chf').value;
	
	if(pseudo == '')
	{
		alert("Please inform the recipient.");
	}
	else
	{	
		if(confirm(('Are you sure to do a tokens transfert to ' + pseudo + ' ?')))
		{
			var xhr;
	
			try
			{
				xhr = new ActiveXObject('Msxml2.XMLHTTP');
			}
			catch (e)
			{
				try
				{
					xhr = new ActiveXObject('Microsoft.XMLHTTP');
				}
				catch (e2)
				{
					try
					{
						xhr = new XMLHttpRequest();
					}
					catch (e3)
					{
						xhr = false;
					}
				}
			}
		
			xhr.onreadystatechange = function ()
			{
				if (xhr.readyState == 4 && xhr.status == 200)
				{
					alert(xhr.responseText);
					window.location.replace('/customer_area/my_tokens');
				}
			}
			;
			
			
			var data = "id=" + id + "&pseudo=" + encodeURIComponent(pseudo) + "&montant_gbp=" + montant_gbp + "&montant_usd=" + montant_usd + "&montant_eur=" + montant_eur + "&montant_cad=" + montant_cad + "&montant_chf=" + montant_chf;
			xhr.open("POST", "/ajax/virement.php", true);
			xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			xhr.send(data);
		}
	}
}



function womanInfo(action)
{
	if(action == 'bic')
	{
		document.getElementById('informations').innerHTML = '<p>All the transferts from your account are immediately transferred to the recipient account</p><p>Form more informations about the transfert, <a href="/page/faq_teamspeak">consult our Frequently Asked Questions here</a></p>';
	}
	else if(action == 'histo')
	{
		document.getElementById('informations').innerHTML = '<p>All your orders are listing here.</p><p>You can cancel or change the mean of payment while the server is not delivered in the tab <a href="/customer_area/my_orders">"my orders"</a>.</p>';
	}
}

function moreDetails(action)
{
	if(action == 'standby')
	{
		document.getElementById('bulle').style.display = "block";
		document.getElementById('woman').innerHTML = '<p>Your order is validated.</p><p>We await reception of your payment.</p>';
		window.scroll(0, 0);
	}
	else if(action == 'finish')
	{
		document.getElementById('bulle').style.display = "block";
		document.getElementById('woman').innerHTML = '<p>Your order is delivered.</p><p>You can manage your server.</p>';
		window.scroll(0, 0);
	}
}


/**
 * Annule une commande
 */
function cancelOrder(id_commande, id_client)
{
	if(confirm('Are you sure you want to cancel your order ?'))
	{
		var xhr;
	
		try
		{
			xhr = new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch (e)
		{
			try
			{
				xhr = new ActiveXObject('Microsoft.XMLHTTP');
			}
			catch (e2)
			{
				try
				{
					xhr = new XMLHttpRequest();
				}
				catch (e3)
				{
					xhr = false;
				}
			}
		}
	
		xhr.onreadystatechange = function ()
		{
			if (xhr.readyState == 4 && xhr.status == 200)
			{
				alert(xhr.responseText);
				window.location.replace('/customer_area/my_orders');
			}
		}
		;
		
		var data = "id_commande=" + id_commande + "&id_client=" + id_client;
		xhr.open("POST", "/ajax/annuler_commande.php", true);
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xhr.send(data);
	}
}





/**
 * Ajouter un email pour la newsletter
 */
function addEmailToNewsletter()
{
	var xhr;

	try
	{
		xhr = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (e)
	{
		try
		{
			xhr = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (e2)
		{
			try
			{
				xhr = new XMLHttpRequest();
			}
			catch (e3)
			{
				xhr = false;
			}
		}
	}

	xhr.onreadystatechange = function ()
	{
		if (xhr.readyState == 4 && xhr.status == 200)
		{
			document.getElementById('newsletter_msg').innerHTML = xhr.responseText;
		}
	}
	;
	
	var data = "email=" + document.getElementById('emailNewsletter').value;
	xhr.open("POST", "/ajax/ajouter_email_newsletter.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(data);
}


function changeAutomaticRenewOfServer(id, id2)
{
	var xhr;

	try
	{
		xhr = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (e)
	{
		try
		{
			xhr = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (e2)
		{
			try
			{
				xhr = new XMLHttpRequest();
			}
			catch (e3)
			{
				xhr = false;
			}
		}
	}
 
	xhr.onreadystatechange = function ()
	{
		if (xhr.readyState == 4 && xhr.status == 200)
		{
			document.getElementById('automaticrenew_state_'+id).innerHTML = xhr.responseText;
		}
	}
	;
	
	if(document.getElementById('automaticrenew_'+id).checked)
	{
		renew = 'yes';	
	}
	else
	{
		renew = 'no';
	}
	
	
	var data = "id=" + id + "&renew=" + encodeURIComponent(renew) + "&id2=" + id2;
	xhr.open("POST", "/ajax/changer_renew_serveur_ts.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(data);
}

/**
 * Changer le mot de passe d'un serveur TS
 * @param id
 */
function changePasswordOfServer(id, id2)
{
	var xhr;

	try
	{
		xhr = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (e)
	{
		try
		{
			xhr = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (e2)
		{
			try
			{
				xhr = new XMLHttpRequest();
			}
			catch (e3)
			{
				xhr = false;
			}
		}
	}
 
	xhr.onreadystatechange = function ()
	{
		if (xhr.readyState == 4 && xhr.status == 200)
		{
			document.getElementById('buttonsetpassword').value = "Execute (OK)";
			document.getElementById('buttonsetpassword').disabled = false;
		}
	}
	;
	
	var pass = document.getElementById('ts_password').value;
	
	var data = "id=" + id + "&pass=" + encodeURIComponent(pass) + "&id2=" + id2;
	xhr.open("POST", "/ajax/changer_pass_serveur_ts.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(data);
}

function changeSuperUserPasswordOfServer(id, id2)
{
	var xhr;

	try
	{
		xhr = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (e)
	{
		try
		{
			xhr = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (e2)
		{
			try
			{
				xhr = new XMLHttpRequest();
			}
			catch (e3)
			{
				xhr = false;
			}
		}
	}

	xhr.onreadystatechange = function ()
	{
		if (xhr.readyState == 4 && xhr.status == 200)
		{
			alert(xhr.responseText);
		}
	}
	;
	
	var pass = document.getElementById('superuser').value;
	
	var data = "id=" + id + "&superuser=" + encodeURIComponent(pass) + "&id2=" + id2;
	xhr.open("POST", "/ajax/changer_pass_serveur_mumble.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(data);
}



function sendCommand(id, id2)
{
	var xhr;

	try
	{
		xhr = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (e)
	{
		try
		{
			xhr = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (e2)
		{
			try
			{
				xhr = new XMLHttpRequest();
			}
			catch (e3)
			{
				xhr = false;
			}
		}
	}

	xhr.onreadystatechange = function ()
	{
		if (xhr.readyState == 4 && xhr.status == 200)
		{
			document.getElementById('buttonsendcommand').value = "Execute (OK)";
			document.getElementById('buttonsendcommand').disabled = false;

			if(command=="newtoken")
			{
				document.getElementById('tokens').value = xhr.responseText;
			}
			/* alert(xhr.responseText);*/
		}
	}
	;
	
	var command = document.getElementById('command').value;
	
	var data = "id=" + id + "&command=" + encodeURIComponent(command) + "&id2=" + id2;
	xhr.open("POST", "/ajax/sendCommand.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(data);
}


/**
 * Executor
 * @param param
 * @param ts
 * @param id
 */
function server(param, ts, id)
{
	var xhr;

	try
	{
		xhr = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (e)
	{
		try
		{
			xhr = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (e2)
		{
			try
			{
				xhr = new XMLHttpRequest();
			}
			catch (e3)
			{
				xhr = false;
			}
		}
	}
	document.getElementById('serverStatus').src = '/img/espace_client/serveurs/btn_restart.gif';
	
	xhr.onreadystatechange = function ()
	{
		if (xhr.readyState == 4 && xhr.status == 200)
		{
			if(xhr.responseText == 1)
			{				
				window.location.replace('/customer_area/my_servers?id=' + ts);
			}
			else
			{
				alert(xhr.responseText);
			}
		}
	}
	;
	
	var data = "p=" + param + "&ts=" + ts + "&id=" + id;
	xhr.open("POST", "/ajax/server.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(data);
}

/**
 * Confirme l'ajout du sous-domaine
 */
function verifAjouterHerbergement()
{
	var ssDomaine = document.getElementById('ssDomaine').value;
	var exp = /\W|_/gi; 
	
	ssDomaine = ssDomaine.replace(exp,"");
	
	if(ssDomaine != "")
	{	
		if(confirm("Do you really want the subdomain : http://" + ssDomaine + ".teamspeak.net"))
		{
			document.forms['form'].submit();
		}
	}
	else
	{
		alert("Fill the field.");
	}
}




/**
 * Gère l'ajout de tokens par un code secret
 * @param int idClient
 */
function tokensCodeSecret(idClient)
{
	if(document.getElementById('codeSecret').value == "")
	{
		alert("Indicate your secret code.");
	}
	else
	{
		var codeSecret = document.getElementById('codeSecret').value;
		var exp = /\W|_/gi; 
		codeSecret = codeSecret.replace(exp,"");
		
		var xhr;

		try
		{
			xhr = new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch (e)
		{
			try
			{
				xhr = new ActiveXObject('Microsoft.XMLHTTP');
			}
			catch (e2)
			{
				try
				{
					xhr = new XMLHttpRequest();
				}
				catch (e3)
				{
					xhr = false;
				}
			}
		}
		
		xhr.onreadystatechange = function ()
		{
			if (xhr.readyState == 4 && xhr.status == 200)
			{
				alert(xhr.responseText);
				window.location.replace('/customer_area/my_tokens');
			}
		}
		;
		
		var data = "code=" + codeSecret + "&id=" + idClient;
		xhr.open("POST", "/ajax/tokenCodeSecrets.php", true);
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xhr.send(data);
	}
}

function effectuerReglement(id_r, id_u)
{
	var xhr;

	try
	{
		xhr = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (e)
	{
		try
		{
			xhr = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (e2)
		{
			try
			{
				xhr = new XMLHttpRequest();
			}
			catch (e3)
			{
				xhr = false;
			}
		}
	}
	
	xhr.onreadystatechange = function ()
	{
		if (xhr.readyState == 4 && xhr.status == 200)
		{
			alert(xhr.responseText);
			window.location.replace('/customer_area/my_clan_contribution');
		}
	}
	;
	
	var data = "r=" + id_r + "&u=" + id_u;
	xhr.open("POST", "/ajax/reglerCotisation.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(data);
	
}

