/**
 * Display a warning message to the user if one (or more objects) will be erased by this action.
 * Return true when the user agreed or when it's no use to warn him. Else return false.
 */
function getUserConfirmation() {
	if (lock('blackMarketLockButton', 30000) === false) {
		return false;
	}
	retour = true;
	// If a horse is pre-selected to use this object there's no radio buttons on the page but a hidden field.
	hiddenFieldTab = $$('input[type=hidden][name=cheval]');
	if(hiddenFieldTab.length > 0){
		hiddenField = hiddenFieldTab[0];
		if(hiddenField != null) {
			messageHidden = $('message'+hiddenField.value);
			// if a message exists
			if(messageHidden != null && messageHidden.value != ''){
				retour = confirm(messageHidden.value);
			}
		} 
	}
	// Check the radio buttons
	else {
		radioButtons = $$('[name=cheval]');
		for (var i=0;i<radioButtons.length;i++){
			if(radioButtons[i].checked == true){
				// get the message to display
				messageHidden = $('message'+radioButtons[i].value);
				// if a message exists
				if(messageHidden != null && messageHidden.value != ''){
					retour = confirm(messageHidden.value);
				}
			}
		}
	}
	if (retour === false) {
		unlock('blackMarketLockButton');
	}
	return retour;
}

BlackMarketHorseAjax = Class.create();
BlackMarketHorseAjax.prototype = {
	page: projectUrl +'/marche/noir/searchHorse',
	execute: function(object) {
		if(object.SearchHorseBox != null) {
			$('SearchHorseBox').innerHTML = object.SearchHorseBox;
		}
		if (object.RefreshCoat !== undefined) {
			selectCheval(object.RefreshCoat);
			changerTri(0);
			changerRobes(null);
		}
	}
}
Object.extend(BlackMarketHorseAjax.prototype, CommonAjax);

BlackMarketFriendAjax = Class.create();
BlackMarketFriendAjax.prototype = {
	page: projectUrl +'/marche/noir/searchFriend',
	execute: function(object) {
		if(object.SearchHorseBox != null) {
			$('SearchHorseBox').innerHTML = object.SearchHorseBox;
		}
		$('SearchHorseBox').show();
	}
}
Object.extend(BlackMarketFriendAjax.prototype, CommonAjax);

BlackMarketCoatAjax = Class.create();
BlackMarketCoatAjax.prototype = {
	page: projectUrl +'/marche/noir/searchCoat',
	execute: function(object) {
		if(object.coat != null) {
			$('robes').innerHTML = object.coat;
		}
	}
}
Object.extend(BlackMarketCoatAjax.prototype, CommonAjax);

function PommeOrRobes(display) {
	if(display != true) {
		document.getElementById('etapeRobeDisplay').style.display = 'none';
	} else {
		document.getElementById('etapeRobeDisplay').style.display = 'block';
	}
}

function CorneDabondanceFriend(display) {
	if(display != true) {
		$('SearchHorseBoxFields').style.display = 'none';
		$('SearchHorseBox').innerHTML = '';
	} else {
		$('SearchHorseBoxFields').style.display = 'block';
		Ajax.JSON(new BlackMarketFriendAjax({ params: 'friendName='+$('receiverName').value+'&productId='+$('productId').value }));
	}
}
