//Caracteres Documentos DNI-CIF-...
function Validar_Caracteres(evento,objeto)
{
	if(evento.keyCode) 
	{
		if(evento.keyCode != 20 && evento.keyCode != 144 && evento.keyCode != 16 && evento.keyCode != 192 && evento.keyCode != 8 && evento.keyCode != 37 && evento.keyCode != 38 && evento.keyCode != 39 && evento.keyCode != 40 && evento.keyCode != 13 && evento.keyCode != 9)
		{
			if(evento.keyCode < 96 || evento.keyCode > 105)
			{
				
				if(evento.keyCode < 48 || evento.keyCode > 90)
				{
					objeto.value = objeto.value.substring(0,(objeto.value.length)-1);
				}
				else
					if(evento.keyCode < 65 && evento.keyCode > 57 )
					{
						if(evento.keyCode > 31 )objeto.value = objeto.value.substring(0,(objeto.value.length)-1);
					}
			}
		}
	}
}

//Solo Texto
function esTexto(evento,objeto)
{
	if(evento.keyCode) 
	{
			if((evento.keyCode < 65 || evento.keyCode > 90) && (evento.keyCode != 16 && evento.keyCode != 222 && evento.keyCode != 219 && evento.keyCode != 32 && evento.keyCode != 8 && evento.keyCode != 46 && evento.keyCode != 192 && evento.keyCode != 9))
			{
					objeto.value = objeto.value.substring(0,(objeto.value.length)-1);
			}
	}
	
	
}


//Formato númerico 1.000,00
function number_format (number, decimals, dec_point, thousands_sep)
{
	var exponent = "";
	var numberstr = number.toString ();
	var eindex = numberstr.indexOf ("e");
	if (eindex > -1)
	{
		exponent = numberstr.substring (eindex);
		number = parseFloat (numberstr.substring (0, eindex));
	}
	
	if (decimals != null)
	{
		var temp = Math.pow (10, decimals);
		number = Math.round (number * temp) / temp;
	}
	var sign = number < 0 ? "-" : "";
	var integer = (number > 0 ? 
	  Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
	
	var fractional = number.toString ().substring (integer.length + sign.length);
	dec_point = dec_point != null ? dec_point : ".";
	fractional = decimals != null && decimals > 0 || fractional.length > 1 ? 
			   (dec_point + fractional.substring (1)) : "";
	if (decimals != null && decimals > 0)
	{
		for (i = fractional.length - 1, z = decimals; i < z; ++i)
		  fractional += "0";
	}
	
	thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? 
				  thousands_sep : null;
	if (thousands_sep != null && thousands_sep != "")
	{
		for (i = integer.length - 3; i > 0; i -= 3)
		  integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
	}
	
	return sign + integer + fractional + exponent;
}

//Fomarto frances 1.000,00
function formato_frances($num)
{
	return number_format($num,2,',','.')
}

//Solo acepta caracteres numéricos 
function Numerico(texto)
{
	var i=0;
	var caracter = texto.charAt((texto.length)-1);
	
	if( caracter != '0' && caracter != '1' && caracter != '2' && caracter != '3' && caracter != '4' && caracter != '5' && caracter != '6' && caracter != '7' && caracter != '8' && caracter != '9' )
		texto=texto.substring(0,(texto.length)-1);
	
	while(i < texto.length)
	{
		if( texto.charAt(i) != '0' && texto.charAt(i) != '1' && texto.charAt(i) != '2' && texto.charAt(i) != '3' && texto.charAt(i) != '4' && texto.charAt(i) != '5' && texto.charAt(i) != '6' && texto.charAt(i) != '7' && texto.charAt(i) != '8' && texto.charAt(i) != '9' )
			texto=texto.replace(texto.charAt(i),'');
		i++;
	}

	return texto;
}



function esMovil(valor)
{

	if(valor.value.length==9 && valor.value.substr(0,1)==6)
		return true;
	else
	{
		alert('El Movil de contacto debe tener 9 dígitos y comenzar por 6');
		return false;
	}
}



function esFijo(valor)
{

	if(valor.value.substr(0,1)==9 || valor.value.substr(0,1)==6)
		return true;
	else
	{
		alert('El Telefono de contacto debe comenzar por 9 o por 6.');
		return false;
	}
}



//Verificar Email
function esMail(campo,obligatorio){
  //var patron1=/&#91;^\w\-@\.&#93;/;
  var patron1=new RegExp(String.fromCharCode(91) + '^\\w\\-@\\.' +  String.fromCharCode(93));
   //var patron2=/&#91;@.&#93;{2}/;
  var patron2=new RegExp(String.fromCharCode(91) + '@.'  +String.fromCharCode(93) + '{2}');
  //var patron3=/^&#91;.@&#93;|&#91;.@&#93;$/;
  var patron3=new RegExp('^' + String.fromCharCode(91) + '.@' +  String.fromCharCode(93) + '|' + String.fromCharCode(91) + '.@' +  String.fromCharCode(93) + '$');
  //var patron4=/@&#91;\w\-&#93;*\.&#91;\w\-&#93;*/;
   var patron4=new RegExp('@' + String.fromCharCode(91) + '\\w\\-' +  String.fromCharCode(93) + '*\\.' + String.fromCharCode(91) + '\\w\\-'  + String.fromCharCode(93) + '*');
  var patron5=/@.*@/;
  //var patron6=/\.&#91;a-z&#93;*\-&#91;a-z&#93;*$/;
  var patron6=new RegExp('\\.' + String.fromCharCode(91) + 'a-z' +  String.fromCharCode(93) + '*\\-' + String.fromCharCode(91) + 'a-z' +  String.fromCharCode(93) + '*$');
  //var patron7=/\.&#91;a-z&#93;*\_&#91;a-z&#93;*$/;
  var patron7=new RegExp('\\.' + String.fromCharCode(91) + 'a-z' +  String.fromCharCode(93) + '*\\_' + String.fromCharCode(91) + 'a-z' +  String.fromCharCode(93) + '*$');
   if(obligatorio && campo.value.length == 0){alert("Formato de correo electronico incorrecto.");return false;}
   if(campo.value.length > 0)  {if(!(!campo.value.match(patron1)&&!campo.value.match(patron2)&&! campo.value.match(patron3)&&campo.value.match(patron4)&&! campo.value.match(patron5)&&!campo.value.match(patron6)&&! campo.value.match(patron7))){ alert("Formato de correo electronico incorrecto.");    return false;  } }  
   
   return true;
}


