// JavaScript Document
function getLetter(l) {
	return false;
}
function all(group){array=document.getElementById(group).getElementsByTagName('input');for(i=0;i<array.length;i++){array[i].checked='checked';}}
function none(group){array=document.getElementById(group).getElementsByTagName('input');for(i=0;i<array.length;i++){array[i].checked='';}}
/* newsletter suscription validation */
function validNewsletter(form) {
	var expr = /^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/;
	var validForm = true;
	var message = '';
	var elid = '';
	$('form#'+form.id+' input:text').each(
		function() {
			if (!this.value && !this.getAttribute('readonly')) {
				message += 'Complete the field : '+ '\'' + getText(this.id, form) + '\'\n';
				validForm = false;
				if (!elid) elid = 'form#'+form.id+' input#'+this.id;
			}
			if (this.id == 'email') {
				if (!expr.test(this.value)) {
					message += 'The email : '+ '\'' + this.value + '\'' + 'is invalid.\n';
					validForm = false;
				if (!elid) elid = 'form#'+form.id+' input#'+this.id;
				}
			}
		}
	);
	if (message.length > 0)	alert(message);
	if(elid) $(elid).focus();
	return validForm;
}
function getText(id, form){
	var text = "";
	$('form#'+form.id+' label').each(
		function() {
			if (this.htmlFor == id) {
				if (this.childNodes.length >= 2) {
					var node = this.childNodes[1];
					text = node.nodeValue;
				}
			}
		}
	);
	return text;
}
// check if a form element is empty
function isEmpty(el) {
	return el.value.length == 0;
}
// check for a min length
function hasMore(el,len) {
	var l = parseInt(len);
	return el.value.length > l;
}
// check a form element to validate its value as numeric
function isNum(el) {
	if (isEmpty(el)) return false;
	var str = el.value,
			chars = str.split(''),
			nums = '0123456789',
			c = 0;
	for (v in chars) if(!nums.match(chars[v])) c++;
	return c == 0;
}
// check a form element to verify email syntax
function isEmail(el) {
	var expr = /^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/;
	return expr.test(el.value);
}
// compares the values of two form elements
function fMatch(el1,el2) {
	return (!isEmpty(el1) && !isEmpty(el2) && (el1.value == el2.value));
}
