/*-------------------------------
validacion de password
permite paso de 
!	"	#	$	%	&	' 
(	)	*	+	,	-	.	/	0	1
2	3	4	5	6	7	8	9	:	;
<	=	>	?	@	A	B	C	D	E 
F	G	H	I	J	K	L	M	N	O
P	Q	R	S	T	U	V	W	X	Y
Z	[	\	]	^	_	`	a	b	c
d	e	f	g	h	i	j	k	l	m
n	o	p	q	r	s	t	u	v	w
x	y	z	{	|	}	?   ñ   Ñ

------------------------------*/
function validatePassword()
{
	tecla=window.event.keyCode;
	if((tecla>=33&&tecla<=125)||tecla==241||tecla==209||tecla==161||tecla==164||tecla==165||tecla==168)
		return;
	else
		window.event.keyCode=0;
}

/*-------------------------------
validacion de numero telefonico
permite paso de 0123456789 - ( )
------------------------------*/
function validateTelefono()
{
	tecla=window.event.keyCode;
	if((tecla>=48&&tecla<=57)||tecla==45||tecla==40||tecla==41)
		return;
	else
		window.event.keyCode=0;
}

/*-------------------------------
validacion de numero telefonico
permite paso de 0123456789 - ( ) .
------------------------------*/
function validateCedula()
{
	tecla=window.event.keyCode;
	if((tecla>=48&&tecla<=57)||tecla==45||tecla==40||tecla==41||tecla==46)
		return;
	else
		window.event.keyCode=0;
}

/*-------------------------------
validacion de direccion
esp "	#  &	' (	)	*	+	,	-	.	/	0	1
2	3	4	5	6	7	8	9	:	;
A	B	C	D	E 
F	G	H	I	J	K	L	M	N	O
P	Q	R	S	T	U	V	W	X	Y
Z
a	b	c
d	e	f	g	h	i	j	k	l	m
n	o	p	q	r	s	t	u	v	w
x	y	z
á é í ó ú n Ñ 
------------------------------*/
function validateDireccion()
{
	tecla=window.event.keyCode;
	if(tecla==32||tecla==34||tecla==35||(tecla>=38&&tecla<=59)||(tecla>=65&&tecla<=90)||
	   tecla==241||tecla==209||(tecla>=97&&tecla<=122)||tecla==225||tecla==233||tecla==237||
	   tecla==243||tecla==250||tecla==164||tecla==165)
		
		return;
	else
		window.event.keyCode=0;
		
}

/*-------------------------------
validacion de nombre
esp "	&	' 	,	-	.	/	0	1
2	3	4	5	6	7	8	9	:	;
A	B	C	D	E 
F	G	H	I	J	K	L	M	N	O
P	Q	R	S	T	U	V	W	X	Y
Z
a	b	c
d	e	f	g	h	i	j	k	l	m
n	o	p	q	r	s	t	u	v	w
x	y	z
á é í ó ú n Ñ 
------------------------------*/
function validateNombre()
{
	tecla=window.event.keyCode;
	if(tecla==32||tecla==34||tecla==38||tecla==39||(tecla>=44&&tecla<=59)||(tecla>=65&&tecla<=90)||
	   tecla==241||tecla==209||(tecla>=97&&tecla<=122)||tecla==225||tecla==233||tecla==237||
	   tecla==243||tecla==250||tecla==164||tecla==165)
		
		return;
	else
		window.event.keyCode=0;
		
}

/*-------------------------------
validacion de email
_ @ - .
 0 1 2 3 4 5 6 7 8 9
 A	B	C	D	E 
F	G	H	I	J	K	L	M	N	O
P	Q	R	S	T	U	V	W	X	Y
Z
a	b	c
d	e	f	g	h	i	j	k	l	m
n	o	p	q	r	s	t	u	v	w
x	y	z
------------------------------*/
function validateEmail()
{
	tecla=window.event.keyCode;
	if(tecla==95||tecla==64||tecla==45||tecla==46||(tecla>=48&&tecla<=57)||
	  (tecla>=65&&tecla<=90)||(tecla>=97&&tecla<=122))
		return;
	else
		window.event.keyCode=0;
}

/*-------------------------------
validacion de numero
0123456789
------------------------------*/
function validateNumero()
{
	tecla=window.event.keyCode;
	if(tecla>=48&&tecla<=57)
		return;
	else
		window.event.keyCode=0;
}

/*-------------------------------
validacion de Medias
0123456789 x
------------------------------*/
function validateMedidas()
{
	tecla=window.event.keyCode;
	if((tecla>=48&&tecla<=57)||tecla==120)
		return;
	else
		window.event.keyCode=0;
}

/*-------------------------------
validacion de ISBN
0123456789 -
------------------------------*/
function validateISBN()
{
	tecla=window.event.keyCode;
	if((tecla>=48&&tecla<=57)||tecla==45)
		return;
	else
		window.event.keyCode=0;

}

/*-----------------------------
valida que no se haya llenado un campo
con solo espacios
-----------------------------*/
function validateLleno(cadena)
{
	checkOk=" ";
	var contador=0;
	var i=0;
	
	if(cadena.length==0)
		return false;
	else
	{
		for(i=0;i<cadena.length;i++)
		{
			if(cadena.charAt(i)==checkOk.charAt(0))
				contador=contador+1;
		}		
		if(contador<cadena.length)
			return true;
		else
			return false;
	}	
}
/*-----------------------
valida que la direccion
de email tenga un
formato valido
nombre@sitio.dominio
------------------------*/
function validateLlenoEmail(emailstring)
{
	/*if ((cadena.indexOf ('@',0) == -1)||(cadena.length < 5))
		return false;
	else
		return true;*/
		
	var ampIndex = emailstring.indexOf("@");
	var afterAmp = emailstring.substring((ampIndex + 1), emailstring.length);
	//Encuentra un punto sólo en la porción de la cadena después del ampersand
	var dotIndex = afterAmp.indexOf(".");
	//Determina la posición del punto en toda la cadena (no sólo después del ampersand)
	dotIndex = dotIndex + ampIndex + 1;
	//afterAmp será la porción de la cadena desde el ampersand hasta el punto
	afterAmp = emailstring.substring((ampIndex + 1), dotIndex);
	//afterDot será la porción de la cadena desde el punto hasta el final de la cadena
	var afterDot = emailstring.substring((dotIndex + 1), emailstring.length);
	var beforeAmp = emailstring.substring(0,(ampIndex));
	//var email_regex = /^[\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+(\.[\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~])*\@(((\w+[\w\d\-]*[\w\d]\.)+(\w+[\w\d\-]*[\w\d]))|((\d{1,3}\.){3}\d{1,3}))$/;
	var email_regex = /^\w(?:\w|-|\.(?!\.|@))*@\w(?:\w|-|\.(?!\.))*\.\w{2,3}/ 
	//Índice de -1 significa que no se encontró
	if ((emailstring.indexOf("@") != "-1") &&
		(emailstring.length > 5) &&
		(afterAmp.length > 0) &&
		(beforeAmp.length > 1) &&
		(afterDot.length > 1) &&
		(email_regex.test(emailstring)) ) {
			  return true;
	} 
	else
		return false;
}