function validar(e,tipo) { 
    tecla = (document.all) ? e.keyCode : e.which; 
	if (tecla==8) return true; //Tecla de retroceso (para poder borrar) 
    // dejar la lnea de patron que se necesite y borrar el resto
	if(tecla==0){
		tecla=9;
		return tecla;
	}
	if(tecla==13){
		return tecla;
	}
	if(tipo==1)
	patron =/^([a-z]|[A-Z]|||||||||||||||\')/; // Solo acepta letras 
    if(tipo==2)
	patron = /([0-9\.\-])/; // Solo acepta nmeros 
    if(tipo==3)
	patron = /^([a-z]|[A-Z]|||||||||||||||[0-9]|\-)/; // Acepta nmeros y letras 
    if(tipo==4)
	patron = /\D/; // Solo acepta letras
	if(tipo==5)
	patron =/^([a-z]|[A-Z]|||||||||||||||\s|\')+$/; // Solo acepta letras y espacio en blanco 
	if(tipo==6)
	patron =/^([a-z]|[A-Z]|[0-9]|||||||||||||||\s|\,|\.|\;|\shift|\(|\)|\#|\%|\:|\-|\ñ|\Ñ|\')+$/; // Solo acepta letras, numeros, espacio en blanco, coma y punto
    // 
    te = String.fromCharCode(tecla); 
    return patron.test(te);  
}
function conMayusculas(field) {
    field.value = field.value.toUpperCase()
}

function formatNumber(num,prefix){
	prefix = prefix || '';
	num += '';
	var splitStr = num.split('.');
	var splitLeft = splitStr[0];
	var splitRight = splitStr.length > 1 ? '.' + splitStr[1] : '';
	var regx = /(\d+)(\d{3})/;
	while (regx.test(splitLeft)) {
		splitLeft = splitLeft.replace(regx, '$1' + ',' + '$2');
	}
	return prefix+splitLeft+ splitRight;
}

function unformatNumber(num) {
	return num.replace(/([^0-9\.\-])/g,'')*1;
} 

function CompruebaMail(Campo)
{
   if (Campo.value == '') return false;
   Campo.value = Campo.value.toLowerCase();
   Campo.value = Campo.value.replace(/ /g, "");
   if (/\.\.|\.@|@\.|^\.|\.$/.test(Campo.value))
      return false;
   if (/\.([a-z]{2,3}|info|name|museum)$/.test(Campo.value))
      if (/^[_\.0-9a-z-]+@([0-9a-z-]+\.)+[a-z]*$/.test(Campo.value))
         return true;
   return false;
}