//No permite Seleccionar el contenido de una Pagina
/*function disableselect(e)
{
	return false
}
function reEnable()
{
	return true
}
document.onselectstart=new Function ("return false")
if (window.sidebar)
{
	document.onmousedown=disableselect
	document.onclick=reEnable
}*/


//Validacion de Email
function valida_email(email)
{
	if (!(/[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/.test(email)))
	{
		return (0);
	}
}


//Elimina espacios a la derecha e izq
function eliminaEspacios(cadena)
{
	var x=0, y=cadena.length-1;
	while(cadena.charAt(x)==" ") x++;	
	while(cadena.charAt(y)==" ") y--;	
	return cadena.substr(x, y-x+1);
}


//Validación de ingreso manual de Calendario
//onKeyPress="{return validanumero2(this.value)}"
function validanumero2(valor)
{
      alert("Ingrese fecha utilizando el calendario");
      digitovalido = false;
      return (digitovalido);
}

//Popuc (ventana emergente)
function openwin(url, width, height) 
{
	var url = url; // popup name
    var name = ""; // popup name
    var width = width; // popup width
    var height = height; // popup height
    var left = (screen.width - width) / 2 ;
    var top = (screen.height - height) / 2;
    var windowproperties = "width="+ width +",height="+ height +",left="+ left +",top="+ top +", scrollbars=no";
    window.open(url, name, windowproperties);
}


//Valida numeros, letras, y -._ con longitud de 4 a 12
function validaIngreso(valor)
{
	var reg=/(^[a-zA-Z0-9_.-]{4,20}$)/;
	if(reg.test(valor)) return true;
	else return false;
}


// FUNCION VALIDA NUMEROS
//onKeyPress="{return validanumero(this.value)}"
function ValidaNumero(valor) 
{
    var nrodiv = valor.split(".");
    if (nrodiv.length==1) 
	{
        conta=0;
    }
	
    if (nrodiv.length==2) 
	{
        conta=1;
    }

    var key = String.fromCharCode(event.keyCode);
    var valid = new String("0123456789.");
    var ok = "no";
	
    for (var i=0; i<valid.length; i++) 
	{
        if (key == i)
		{ 
			ok = "yes";
        }
    }

    if (key == '.')
	{ 
        conta = conta + 1;
        ok = "yes";
    }

    if (ok == "no" || conta > 1) 
	{
		//alert("Solo números y un punto decimal son permitidos.");
      	digitovalido = false;
        return (digitovalido);
    }
}


//VALIDA QUE EL TEXTO NO TENGA COMILLAS
function IsComilla(x)
{ 
	for (k=0; k < x.length ; k++)
    if (x.substring(k,k+1) == "^" || x.substring(k,k+1) == "'" || x.substring(k,k+1) == '"' )
    return true;
    return false;
}


//VALIDA QUE NO INGRESE COMILLA
function ValidaTexto(SwForm,SwTxt,texto)
{
	if (IsComilla(texto))
	{
		alert('No debe poseer los caracteres ^ y/o  comilla.'); 
        eval("document." + SwForm + "." + SwTxt + ".focus();");
        return false ;
	}
}


//VALIDA QUE EL CAMPO NO SEA VACIO - USARLO EN CAMPOS REQUERIDOS       
function TextoVacio(SwForm,SwTxt,texto)
{   
	if (texto== "")
	{   
		alert('Debe ingresar dato obligatorio');
		eval("document." + SwForm + "." + SwTxt + ".focus();");
		return false;
	}
}

       
//Validar si una fecha es correcta según el formato dd/mm/aaaa
function valida_fecha(SwForm,SwTxt,fecha)
{
	var dia=fecha.substr(0,2);
	var separador1=fecha.substr(2,1);
	var mes=fecha.substr(3,2);
	var separador2=fecha.substr(5,1);
	var anho=fecha.substr(6,4);

	if(!(!(isNaN(dia)) && !(isNaN(mes)) && !(isNaN(anho)) && (separador1=="/" || separador1=="-")   && (separador2=="/" || separador2=="-")  ))
	{
		alert('Debe ingresar una fecha válida');
		eval("document." + SwForm + "." + SwTxt + ".focus();");
		return false; // Fecha no válida
	}
	else
	{
		if (!(checkdate(dia,mes,anho)))
		{
			alert('Debe ingresar una fecha válida');
			eval("document." + SwForm + "." + SwTxt + ".focus();");
			return false; // Fecha no válida
		}
		else
		{
			return true; // Fecha válida
		}
	}
}



//  Evaluar que una fecha sea correcta dia, mes, año
function checkdate(d,m,y)
{
	var yl=1900; // least year to consider
	var ym=2100; // most year to consider
	if (m<1 || m>12) return(false);
	if (d<1 || d>31) return(false);
	if (y<yl || y>ym) return(false);
	if (m==4 || m==6 || m==9 || m==11)
	if (d==31) return(false);
	if (m==2)
	{
		var b=parseInt(y/4);
		if (isNaN(b)) return(false);
		if (d>29) return(false);
		if (d==29 && ((y/4)!=parseInt(y/4))) return(false);
	}
	return true;
}


//valida numeros, letras, signos
//onKeyPress="return alpha(event,letters)"
var letters=' ABCDEFGHIJKLMNÑOPQRSTUVWXYZabcdefghijklmnñopqrstuvwxyzàáÀÁéèÈÉíìÍÌïÏóòÓÒúùÚÙüÜ' 
var numbers='1234567890' 
var signs=',.:;@-\'_'
var mathsigns='+-=()*/'
var custom='<>#$%&?¿' 
var raya='-/'
function alpha(e,allow) 
{ 
	var k; 
	k=document.all?parseInt(e.keyCode): parseInt(e.which); 
	return (allow.indexOf(String.fromCharCode(k))!=-1); 
} 


//funcion para quitar acentos
function quitaacentos(t)
{
	á="a";é="e";í="i";ó="o";ú="u";ñ="n";Á="a";É="e";Í="i";Ó="o";Ú="u";Ñ="n";
	acentos=/[áéíóúñÁÉÍÓÚÑ]/g;
	return t.replace(acentos,			 
	function($1)
	{
		return eval($1)
	}	
	);
}








