/**********************************
   FUNCIONES GENERALES 
***********************************/

/* Validacion de E-mail
------------------------------*/
	function isMail(_email) {
		 var emailReg = /^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/i
		 return emailReg.test(_email);
	}
/* Borrar espacios en blanco
------------------------------	*/
	function RTrim(VALUE){
		var w_space = String.fromCharCode(32);
		var v_length = VALUE.length;
		var strTemp = "";		
		if(v_length < 0){
			return "";
		}		
		var iTemp = v_length -1;	
		while(iTemp > -1){
			if(VALUE.charAt(iTemp) == w_space){
			} else{
				strTemp = VALUE.substring(0,iTemp +1);
				break;
			}			
			iTemp = iTemp-1;	
		} //End While	
		return strTemp;	
	} //End Function
	
	function LTrim(VALUE){
		var w_space = String.fromCharCode(32);
		if(v_length < 1){
			return "";
		}		
		var v_length = VALUE.length;
		var strTemp = "";	
		var iTemp = 0;
	
		while(iTemp < v_length){
			if(VALUE.charAt(iTemp) == w_space){
			}else{
				strTemp = VALUE.substring(iTemp,v_length);
				break;
			}		
			iTemp = iTemp + 1;
		} //End While		
		return strTemp;
	} //End Function
	
	function Trim(TRIM_VALUE){
		if(TRIM_VALUE.length < 1){
			return"";
		}		
		TRIM_VALUE = RTrim(TRIM_VALUE);
		TRIM_VALUE = LTrim(TRIM_VALUE);
		if(TRIM_VALUE==""){
			return "";
		}else{
			return TRIM_VALUE;
		}
	} //End Function
//------------------------------	

//// ABRIR POPUPS ////////

function winpopup2 (url,titulo,ancho,alto) 
{	
var win=null; 
var ancho_new = 34 + parseInt(ancho);
var alto_new = 25 + parseInt(alto);

var opciones= 'width='+ ancho_new + ', height='+ alto_new +', toolbar=no, location=no, directories=no, status=no, menubar=no ,scrollbars=yes, resizable=no';
win=window.open('','',opciones);
	win.document.write('<html>\n');
	win.document.write('<head>\n');
	win.document.write('<title>'+titulo+'</title>\n');
	win.document.write('</head>\n'); 
	win.document.write ('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">\n');
	win.document.write ('<iframe border="0" align="top" src="'+url+'" frameBorder="0" width="100%" height="100%" scrolling="no"></iframe>');
	win.document.write ('</body>\n');
	win.document.write ('</html>\n');
}
/*----- -------------------------------
	Evalua si es un Numero Decimal (Positivo y Negativo)
-----------------------------------------*/
function IsNumDecimal( numstr ) {
	// devuelve un valor invalido deacuerdo a la evaluacion
	if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "")	
		return false;

	var isValid = true;
	var decCount = 0;		// numero de puntos decimales

	// convierte a un string para una mejor comparacion.
	numstr += "";	

	// Loop through string and test each character. If any
	// character is not a number, return a false result.
 	// Include special cases for negative numbers (first char == '-')
	// and a single decimal point (any one char in string == '.').   
	for (i = 0; i < numstr.length; i++) {
		// cuenta numero de puntos decimales
		if (numstr.charAt(i) == ".")
			decCount++;

    	if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") || 
				(numstr.charAt(i) == "-") || (numstr.charAt(i) == "."))) {
       	isValid = false;
       	break;
		} else if ((numstr.charAt(i) == "-" && i != 0) ||
				(numstr.charAt(i) == "." && numstr.length == 1) ||
			  (numstr.charAt(i) == "." && decCount > 1)) {
       	isValid = false;
       	break;
      }         	         	       
   } // END for   
   
   	return isValid;
}  // end IsNum

/*----- -------------------------------
	Evalua si es un Numero Decimal (Positivo)
-----------------------------------------*/
function IsNumDecimalPositivo( numstr ) {
	// devuelve un valor invalido deacuerdo a la evaluacion
	if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "")	
		return false;

	var isValid = true;
	var decCount = 0;		// numero de puntos decimales

	// convierte a un string para una mejor comparacion.
	numstr += "";	

	// Loop through string and test each character. If any
	// character is not a number, return a false result.
 	// Include special cases for negative numbers (first char == '-')
	// and a single decimal point (any one char in string == '.').   
	for (i = 0; i < numstr.length; i++) {
		// cuenta numero de puntos decimales
		if (numstr.charAt(i) == ".")
			decCount++;

    	if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") || 
				(numstr.charAt(i) == "."))) {
       	isValid = false;
       	break;
		} else if ((numstr.charAt(i) == "." && numstr.length == 1) ||
			  (numstr.charAt(i) == "." && decCount > 1)) {
       	isValid = false;
       	break;
      }         	         	       
   } // END for   
   
   	return isValid;
}  // end IsNum

/*----- -------------------------------
	Evalua si es un Numero entero Positivo
-----------------------------------------*/
function IsNumEnteroPositivo( numstr ) {
	// devuelve un valor invalido deacuerdo a la evaluacion
	if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "")	
		return false;

	var isValid = true;
	// convierte a un string para una mejor comparacion.
	numstr += "";	

	for (i = 0; i < numstr.length; i++) {
    	if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") )) {
       	isValid = false;
       	break;
		}  
   } // END for   
   
   	return isValid;
}  // end IsNumEnteroPositivo

//---- 
// Validacion FULL de Numero entero Positivo 
//--------
function validaNumEnteroPositivo(valor){
	var aux=''+valor.value;
	if(IsNumEnteroPositivo(valor.value)==false || (valor.value=="" || valor.value==null )){
		//alert('Debe ingresar solo numeros en el campo ' + valor.value.length);
		valor.value = '';	
		valor.focus(true);
	}
}

//---- 
// Validacion FULL de Numero Decimal Positivo 
//--------
function validaNumDecimalPositivo(valor){
	var aux=''+valor.value;
	if(IsNumDecimalPositivo(valor.value)==false || (valor.value=="" || valor.value==null )){
		//alert('Debe ingresar solo numeros en el campo ' + valor.value.length);
		valor.value = '';	
		valor.focus(true);
	}
}

//----------------------
// Valida Numero Decimal positivo y negativo 
//-----------------------
function validaNumDecimal(valor){
	var aux=''+valor.value;
	if(IsNumDecimal(valor.value)==false || (valor.value=="" || valor.value==null )){
		//alert('Debe ingresar solo numeros en el campo ' + valor.value.length);
		valor.value = '';	
		valor.focus(true);
	}
}
//--------------

/*----- -------------------------------
	Evalua si contiene numeros y guiones(sin importar la ubicacion; pero solo un guion) 
-----------------------------------------*/
function IsNumGuion( numstr, posicion ) {
	// devuelve un valor invalido deacuerdo a la evaluacion
	if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "")	
		return false;

	var isValid = true;
	// convierte a un string para una mejor comparacion.
	numstr += "";	
	guionCount = 0;

	for (i = 0; i < numstr.length; i++, guionCount) {
		
		if (numstr.charAt(i) == "-")
			guionCount++;

    	if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") || ((numstr.charAt(i) == "-" &&
			guionCount == 1 && i == posicion)) )) {
       	isValid = false;		
       	break;
		
		}  
   } // END for   
   
   	return isValid;
}  // end IsNumEnteroPositivo

//----------------------
// Valida Telefono Fijo
//-----------------------
function validaTefefonoFijo(valor){
	var aux=''+valor.value;
	if(IsNumGuion(valor.value, "3")==false || (valor.value=="" || valor.value==null )){		
		valor.value = '';	
		valor.focus(true);
	}else if(valor.value.length == 3){
		valor.value = Trim(valor.value) + "-";
	}
}
//--------------

//----------------------
// Valida Telefono Celular
//-----------------------
function validaTefefonoCelular(valor){
	var aux=''+valor.value;
	if(IsNumGuion(valor.value, "4")==false || (valor.value=="" || valor.value==null )){
		valor.value = '';	
		valor.focus(true);
	}else if(valor.value.length == 4){
		valor.value = Trim(valor.value) + "-";
	}
}
//--------------
/*----- -------------------------------
	Evalua si contiene numeros y guiones(sin importar la ubicacion; pero solo un guion) 
-----------------------------------------*/
function IsFecha( numstr) {
	// devuelve un valor invalido deacuerdo a la evaluacion
	if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "")	
		return false;

	var isValid = true;
	// convierte a un string para una mejor comparacion.
	numstr += "";	
	slashCount = 0;

	for (i = 0; i < numstr.length; i++, slashCount) {
		
		if (numstr.charAt(i) == "/")
			slashCount++;

    	if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") || ((numstr.charAt(i) == "/" &&
			(slashCount > 0 && slashCount < 3) && (i == 2 || i == 5) )) )) {
       	isValid = false;		
       	break;
		
		}  
   } // END for   
   
   	return isValid;
}  // end IsNumEnteroPositivo
//----------------------
// Valida Telefono Fijo
//-----------------------
function validaFecha(valor){
	var aux=''+valor.value;
	if(IsFecha(valor.value)==false || (valor.value=="" || valor.value==null )){		
		valor.value = '';	
		valor.focus(true);
	}else if(valor.value.length == 2 || valor.value.length == 5){
		valor.value = Trim(valor.value) + "/";
	}
}

/*function SoloNumeros()
{
	//Autor		:	Ruben Bermudez Varas 01/04/2006
	//Descripcion	:	Permite el ingreso unicamente de Numeros.

if(window.event.keyCode!=13)
	{
	var Tecla;
	Tecla = String.fromCharCode(window.event.keyCode);

	if ( !(Tecla>="0"&&Tecla<="9"|| Tecla==".") )
		{
		window.event.keyCode = 0;
		}
	}
}*/
//----------------
