/**
 * Client information loader AJAX call.
 *
 * @return void
 */
function save($a_blnSendNow) {
	//Element.update('spnStatus', '');
	Element.update('spnAjaxStatus', '<img src="/img/ajax-loader.gif" height="16" width="16" align="top" alt="Loading ..." />');

	$('frmMain').request({
		onSuccess: function(a_objResponse) {
			resetUI();

			var objJSON = eval('(' + a_objResponse.responseText + ')');

			if (typeof objJSON[0] == 'undefined' || objJSON[0] == '') {
				window.location.href = ($a_blnSendNow)? '/EN/send' : '/EN/preview-mycard';
			}

			else {
				var strInnerHTML = '';

				// show message
				for (i=0; i<objJSON[0].length; i++) {
					strInnerHTML += objJSON[0][i] + '<br />';
				}

				// highlite form feilds
				for (j=0; j<objJSON[1].length; j++) {
					$(objJSON[1][j]).style.backgroundColor = '#FFB3B3';
				}

				Element.update('spnStatus', '<p class="error">' + strInnerHTML + '</p>');
			}

			Element.update('spnAjaxStatus', '');
		}
	});
}

function save_fr($a_blnSendNow) {
	//Element.update('spnStatus', '');
	Element.update('spnAjaxStatus', '<img src="/img/ajax-loader.gif" height="16" width="16" align="top" alt="Loading ..." />');

	$('frmMain').request({
		onSuccess: function(a_objResponse) {
			resetUI();

			var objJSON = eval('(' + a_objResponse.responseText + ')');

			if (typeof objJSON[0] == 'undefined' || objJSON[0] == '') {
				window.location.href = ($a_blnSendNow)? '/FR/envoyer' : '/FR/previsualiser-ma-carte';
			}

			else {
				var strInnerHTML = '';

				// show message
				for (i=0; i<objJSON[0].length; i++) {
					strInnerHTML += objJSON[0][i] + '<br />';
				}

				// highlite form feilds
				for (j=0; j<objJSON[1].length; j++) {
					$(objJSON[1][j]).style.backgroundColor = '#FFB3B3';
				}

				Element.update('spnStatus', '<p class="error">' + strInnerHTML + '</p>');
			}

			Element.update('spnAjaxStatus', '');
		}
	});
}

/**
 * Resets the different UI elements.
 *
 * @return void
 */
function resetUI() {
	Element.update('spnStatus', '');

	$('txtCustomMessage').style.backgroundColor = '#FFFFFF';
	$('txtYourName').style.backgroundColor = '#FFFFFF';
	$('txtYourEmail').style.backgroundColor = '#FFFFFF';
	$('txtFriendName').style.backgroundColor = '#FFFFFF';
	$('txtFriendEmail').style.backgroundColor = '#FFFFFF';
}

/**
 * Counts the available characters
 *
 * @return void
 */
function charCount(a_objFeild, a_objTarget, a_intCharLimit) {
	if (a_objFeild.value.length > a_intCharLimit)
		a_objFeild.value = a_objFeild.value.substring(0, a_intCharLimit);
	else
		a_objTarget.innerHTML = a_intCharLimit - a_objFeild.value.length;
}

function msgFieldFormat(a_objFeild) {
	if (a_objFeild.value == 'CM') {
		$('spnRequired').innerHTML = '*';
		$('txtCustomMessage').disabled = false;
	}

	else {
		$('spnRequired').innerHTML = '';
		$('txtCustomMessage').disabled = true;
	}
}