Account = Class.create();

Account.prototype.initialize = function(client_id)
{
}

Account.prototype.updateClient = function(form,event)
{
	Event.stop(event);
	form.request({
		onComplete : function(xhr){
			if(xhr.responseText != "")
			{
				alert(xhr.responseText);
				return;
			}
			myAccount_mgr.update("frontoffice/ajax/account/home.php");
		}
	});
}

Account.prototype.show = function()
{
	front_mgr.update("frontoffice/ajax/account/parameters.php",{});
}

Account.prototype.editSubmitSuccess = function(json)
{
	alert("editSubmitSuccess");
}

Account.prototype.editSubmitFailure = function(json)
{
	alert("editSubmitFailure");
}

Account.prototype.toAddress = function()
{
}

Account.prototype.toParams = function()
{
	
}

Account.prototype.showParams = function()
{
	if ($("param_container") === null
		|| $("addrs_container") === null)
	return;
	$("addrs_container").hide();
	$("param_container").show();
}

Account.prototype.showAddress = function()
{
	if ($("param_container") === null
		|| $("addrs_container") === null)
	return;
	$("param_container").hide();
	$("addrs_container").show();
}

Account.prototype.showCommands = function()
{
	alert("lol");
	//update("frontoffice/ajax/account/commands.php")

}

Account.prototype.updateAddress = function(formElement, closePopin, element)
{
	formElement.request({
		evalJSON : "force",
		onSuccess : function(xhr){
			if(xhr.responseJSON === null || xhr.responseJSON.success == false)
			{
				alert("L'addresse a été mal remplie");
				return;
			}
			if(closePopin)
			{
				var newOptionName = "";
				popupAddress.hide();
				if(!Object.isUndefined(element) && $(element))
				{
					command_mgr.updateAddressDetails(element, xhr.responseJSON.id);
					newOptionName = $(element).down().innerHTML;
					var optionArray = new Array();
					$("billing_address_id","shipment_address_id").each(function(item){
						optionArray = optionArray.concat(item.select("option[value=\""+xhr.responseJSON.id+"\"]"));
					});
//					alert(optionArray.length);
					if(optionArray.length > 0)
					{
						optionArray.each(function(item){
							if(item.up(2).next().id != element && item.hasAttribute("selected") && item.selected)
								command_mgr.updateAddressDetails(item.up(2).next().id, xhr.responseJSON.id);
							item.update(newOptionName);
						});
					}else
					{
						if(element == "billing_detail")
						{
							var selectElement = $("billing_address_id");
							var unselectElement = $("shipment_address_id");
							var compElement = "shipment_detail";
						}
						else
						{
							var selectElement = $("shipment_address_id");
							var unselectElement = $("billing_address_id");
							var compElement = "billing_detail";
						}
						var optionSelected = new Element("option",{
							"onclick":"command_mgr.updateAddressDetails('"+element+"',"+xhr.responseJSON.id+");",
							"selected":"selected",
							"value" : xhr.responseJSON.id
						});
						var optionUnSelected = new Element("option",{
							"onclick":"command_mgr.updateAddressDetails('"+compElement+"',"+xhr.responseJSON.id+");",
							"value" : xhr.responseJSON.id
						});
						optionSelected.insert(newOptionName);
						optionUnSelected.insert(newOptionName);
						
						selectElement.select("option").each(function(item){
							item.selected = false;
						})
						selectElement.insert(optionSelected);
						unselectElement.insert(optionUnSelected);
						
					}
				}
			}
			else
				myAccount_mgr.update("frontoffice/ajax/account/address_book.php");
		},
		onFailure : function(){alert("Erreur");}
	});
}