<!--
 
/**
 * ************************************************************************************
 * Fecha de Modificacion: 01/09/2009
 * Modificado por: Angel Narvaez Fow
 * Nro. Orden de Trabajo: 2553
 * Descripción de la modificación: Se creó nuevo método "NumDecSinRastroCero"
 *								   basado en el método "NumDec". Pero agrega condicionales
 * 								   para los siguientes casos:		 
 * 								  - Si obtiene un "0", entonces devuelve "".
 *								  - Si obtiene un "", entonces devuelve "".
 *													
 * ************************************************************************************
*/

/*	(!(isNaN(eval("document."+fname+"."+nommes+".value"))) && 
	(!(isNaN(eval("document."+fname+"."+nomdia+".value"))) && 
	(!(IsNaN(eval("document."+fname+"."+nom+".value"))) && 
*/

//Funcion que se encarga de filtrar caracteres extraños de una cadena.
//Se debe utilizar para cada parámetro que se envíe hacia el servidor.
function filtraParametroRequest(parametro){
	var expreg = /[_:;<>°!"#$%=?¡¿'*\~{}\()[\]{\\^`|¬´¨]/g;
	parametro = parametro.replace(expreg,"");
	return parametro;
}

function ValClaveSeguridad(valor,nomb,fname) {
	if(valor != "" && valor.length < 8) {
		alert("Ingrese correctamente los 8 digitos de la clave de seguridad");
        aux = eval("document." + fname + "." + nomb);
        aux.focus();
        return false;
    }
	return true;
}





error=0;
function BorCarEsp(num)
	{
        expreg=/[@_:;<>°!"#$%=?¡¿'*\~{}\[\]{\\^`|¬´¨]/g;
	this.num=num.replace(expreg,"");
	return this.num;
	}

//Validacion para nombre, direcciones, documentos de identidad
//Parametros: (this.value,this.name,this.form.name)
function LimpiaCar(num,nom,fname)
	{
        num=num.toUpperCase();
        this.num=Trim(num);
	this.num=BorCarEsp(this.num)
	eval("document."+fname+"[nom].value=this.num");
	}
function Trim(num)
	{
	this.num=num.replace(/^\s*/,"");
	this.num=this.num.replace(/\s*$/,"");
	return this.num
        }

//Verifica Montos
//Parametros: (this.value,this.name,this.form.name)
function NumDec(num,nom,fname)
	{
        this.num=Trim(num);
	this.num=BorCarEsp(this.num)
	if(isNaN(this.num))
		{
		alert("Ingrese una cantidad sin utilizar coma (,)");
		eval("document."+fname+"[nom].focus()");
		}
	else
		{
		//this.num=Math.round(this.num*100)/100;
		this.numero=""+(this.num*100)/100;
		//alert(this.numero);
		eval("document."+fname+"[nom].value=this.numero");
		}
	}

//Verifica Montos
//Parametros: (this.value,this.name,this.form.name)
function NumDecSinRastroCero(num,nom,fname){
    this.num=Trim(num);
	this.num=BorCarEsp(this.num)
	
	if(isNaN(this.num)){
		alert("Ingrese una cantidad sin utilizar coma (,)");
		eval("document."+fname+"[nom].focus()");
	}else{
	    if(this.num==""){			
			eval("document."+fname+"[nom].value=\"\"");	    
	    }else{ 
		    this.numero=""+(this.num*100)/100;
			if(this.numero=="0"){		
				eval("document."+fname+"[nom].value=\"\"");	 
			}else{
				eval("document."+fname+"[nom].value=this.numero"); 
			}			  	    
	    }
	}
}

//Verifica fechas desde el año 
//Parametros:
//CheckDate(this.value,this.name,this.form.name,'nombre del campo dias','nombre del campo meses')
function CheckDate(num,nom,fname,nomdia,nommes)
	{
	date=new Date();
	dias=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	anoref=1900;
	modulo=(num-anoref)%4;
	if(modulo==0)
		{
		dias[1]=29;
		}
	
	if(!((eval("document."+fname+"."+nomdia+".value")<=dias[eval("document."+fname+"."+nommes+".value")-1]) && 
	(eval("document."+fname+"."+nomdia+".value")>0) && 
	(eval("document."+fname+"."+nommes+".value")>0) && 
	(eval("document."+fname+"."+nommes+".value")<13) && 
	(eval("document."+fname+"."+nom+".value")>1900)))
		{
		alert(" verifique la fecha");
		return false;
		}
	}

//Verifica Numero Telefonico y Numeros de Cuenta
function EsNum(num,nom,fname)
	{
        this.num=Trim(num);
	this.num=BorCarEsp(this.num)
	expreg=/[()\-\+\s]/g;
	num1=this.num.replace(expreg,"");
	if(isNaN(num1))
		{
		alert("Ingrese un número válido");
		//eval("document."+fname+"[nom].focus()");
		eval("document."+fname+"[nom].value=\"\"");
		eval("document."+fname+"[nom].focus()");
		}
	else
		{
		eval("document."+fname+"[nom].value=this.num");
		}
	}


//Valida Correos Electronicos
//Parametros: (this.value,this.name,this.form.name)

function ValMail(num,nom,fname){

    switch(validamail(num,nom,fname))
     {
       case 0 :
//      document.frmdata.action="actdatos.jsp?asaccion=1"
//      document.frmdata.submit();
        return;
        break;

     /* case 1 :
	alert("....");
  	eval("document."+fname+"."+nom+".focus()");
	error=1;
	return;
	break;*/

      case 2 :
	alert("Mail incorrecto. Por favor verifique.");
  	eval("document."+fname+"."+nom+".focus()");
	error=1;
	return;
	break;

      case 3 :
	alert("Mail incorrecto. No puede existir espacios en blanco.");
  	eval("document."+fname+"."+nom+".focus()");
	error=1;
	return;
	break;

      case 4 :
	alert("Mail incorrecto. Verifique el uso del @.");
  	eval("document."+fname+"."+nom+".focus()");
	error=1;
	return;
	break;

      case 5 :
	alert("Mail incorrecto. No puede haber . despues del @.");
  	eval("document."+fname+"."+nom+".focus()");
	error=1;
	return;
	break;

      case 6 :
	alert("Mail incorrecto. Mail no puede terminar en . ");
  	eval("document."+fname+"."+nom+".focus()");
	error=1;
	return;
	break;
    }
}

function validamail(mail,nom,fname)
{
//verificamos si la cadena enviada no esta vacia
if (mail =="")  {return 1} //Llene su mail.

//Quitamos los espacios en blanco a la derecha y a la izquierda y validamos
//que no haya espacios o caracteres extraños en blanco dentro de la cadena.

num=mail.length
cadena=""

x=0
inicio= 0 // variable para definir inicio y fin de cadena  0 inicialmente 
	  // 1 cuando comienzan los caracteres, 2 cuando terminan.

for(i=0;i<=num;i++)
	//{ if ((eval("document."+fname+"."+nom+".value.substring(i,i+1)==\" \""))||(eval("document."+fname+"."+nom+".value.substring(i,i+1)==\"\"")))
	{ if ((mail.substring(i,i+1)==" ")||(mail.substring(i,i+1)==""))
	   {x=x+1;
	    if (inicio==1)
		{inicio=2}
	   }
     else
	   {if (inicio!=2)
		{inicio=1;
		 //car=eval("document."+fname+"."+nom+".value.substring(i,i+1)");
		 car=mail.substring(i,i+1);
		 //caracteres especiales
		 if ((car=="á")||(car=="é")||(car=="í")||(car=="ó")||
		     (car=="ú")||(car=="Á")||(car=="É")||(car=="Í")||
		     (car=="Ó")||(car=="Ú")||(car==",")||(car==";")||
	             (car=="*")||(car=="#")||(car=="%")||(car=="[")||
	             (car==":")||(car=="}")||(car=="{")||(car=="]")||
	             (car=="^")||(car=="$")||(car=="|")||(car=="<")||(car==">"))
		 	{return 2} //caracteres no permitidos
		else	
	        	 {cadena=cadena+car}
		 }
	    else
		{return 3} //No puede haber espacios en blanco
	   }
   }

//validamos caracter en blanco
if (num==x) {return 1} //Mail en blanco

//validamos la presencia del @ y del punto despues de él.

x=0;
pos=0;
pos1=0;
num=cadena.length;

for(i=0;i<=num;i++){
	//if (eval("document."+fname+"."+nom+".value.substring(i,i+1)==\"@\""))
	if (mail.substring(i,i+1)=="@")
		{x=x+1;
		 pos=i+1}
	}
if (x!=1) {return 4} //Verifique el uso del @
else   
     {  x=0;
	if (pos==1) {return 2 } //No puede comenzar con @
       	for (i=pos;i<=num;i++) {
 	//if (eval("document."+fname+"."+nom+".value.substring(i,i+1)==\".\""))
 	if (mail.substring(i,i+1)==".")
	   {x=x+1;
	    pos1=i-pos+1}
	}
       if (x==0) {return 2} //Mail invalido

       if (pos1==1) {return 5} //No puede haber un punto despues de @
       if (num==pos1+pos) {return 6}  //No puede terminar en punto	  	 

     } 	 	 

{return 0}
}

//Valida input en blanco 
//nomb=document.NombreFormulario.NombreInput
//mensaje="mensaje de error"
function blanco(nomb,mensaje){
    if(Trim(nomb.value)==""){
        alert(""+mensaje);
        nomb.focus();
        return false;
    }else{
        return true;
    }
}
function blancoSM(nomb){
    if(Trim(nomb.value)==""){
        return false;
    }else{
        return true;
    }
}
function ValCombo(nomb,mensaje){
    if(Trim(nomb.options[nomb.selectedIndex].value)=="0" || Trim(nomb.options[nomb.selectedIndex].value)=="00" || Trim(nomb.options[nomb.selectedIndex].value)==""){
        alert(""+mensaje);
        nomb.focus();
        return false;
    }else{
        return true;
    }
}
function ValComboSM(nomb){
    if(Trim(nomb.options[nomb.selectedIndex].value)=="0" || Trim(nomb.options[nomb.selectedIndex].value)=="00" || Trim(nomb.options[nomb.selectedIndex].value)==""){
        return false;
    }else{
        return true;
    }
}
function ValRUC(valor,nomb,fname){
if(isNaN(valor) && valor!=""){
        alert("Ingrese correctamente los once(11) dígitos del RUC de su empresa.");
        aux=eval("document."+fname+"."+nomb);
        aux.value="";
        aux.focus();
        return false;
}else{
        if(valor.length < 11 && valor != ""){
            alert("Ingrese correctamente los once(11) dígitos del RUC de su empresa.");
            aux=eval("document."+fname+"."+nomb);            
            aux.focus();
        }else{
        return true;
       }
}
}

function ValidaDNI(valor,nomb,fname) {
	if(isNaN(valor) && valor!="") {
        alert("Ingrese correctamente los ocho(8) dígitos del DNI.");
        aux=eval("document."+fname+"."+nomb);
        aux.value="";
        aux.focus();
        return false;
	}
	else {
        if(valor.length < 8 && valor != "") {
            alert("Ingrese correctamente los ocho(8) dígitos del DNI.");
            aux=eval("document."+fname+"."+nomb);
            aux.focus();
        }
        else {
	        return true;
	    }
    }
}

function ValidaTelefono(valor,nomb,fname) {
	if(isNaN(valor) && valor!="") {
        alert("Ingrese correctamente los seis(6), siete(7), ocho(8), once(11) o doce(12) dígitos del teléfono.");
        aux=eval("document."+fname+"."+nomb);
        aux.value="";
        aux.focus();
        return false;
	}
	else {
        if((valor.length != 6 && valor.length != 7 && valor.length != 8 && valor.length != 11 && valor.length != 12)
        	&& valor != "") {
            alert("Ingrese correctamente los seis(6), siete(7), ocho(8), once(11) o doce(12) dígitos del teléfono.");
            aux=eval("document."+fname+"."+nomb);
            aux.focus();
        }
        else {
	        return true;
	    }
    }
}

function esVacio(cad) {
  var i;
  var blanco = " \n\t" + String.fromCharCode(13);
  var es_vacio;
  if((cad == null) || (cad.length == 0))
    return true;
  for(i = 0, es_vacio = true; (i < cad.length) && es_vacio; i++)
    es_vacio = blanco.indexOf(cad.charAt(i)) != - 1;
  return (es_vacio);
}

function daysInFebruary(year) {
  return (((year%4 == 0) && ((!(year%100 == 0)) || (year%400 == 0))) ? 29 : 28);
}

function isDate(year, month, day) {
  var daysInMonth = new Array();
  daysInMonth[1] = 31;
  daysInMonth[2] = 29;
  daysInMonth[3] = 31;
  daysInMonth[4] = 30;
  daysInMonth[5] = 31;
  daysInMonth[6] = 30;
  daysInMonth[7] = 31;
  daysInMonth[8] = 31;
  daysInMonth[9] = 30;
  daysInMonth[10] = 31;
  daysInMonth[11] = 30;
  daysInMonth[12] = 31;
  if(day > daysInMonth[month])
    return false;
  if((month == 2) && (day > daysInFebruary(year)))
    return false;
  return true;
}

function evaluaFecha(objCaja, formato) {
  var er_date;
  var dateValue = objCaja.value;
  if(!esVacio(dateValue)) {
    switch(formato) {
      case "dd/mm/yyyy":
        er_date = /((\d{2})[\/](\d{2})[\/](\d{4}))+$/
        break;
      default:
        er_date = /((\d{2})[\-](\d{2})[\-](\d{4}))+$/
    }
    if(!er_date.test(dateValue)) {
      alert('Campo fecha con formato inválido.');
      objCaja.value = "";
      return false;
    }
    var intday = parseInt(dateValue.substr(0, 2), 10);
    var intmonth = parseInt(dateValue.substr(3, 2), 10);
    var intyear = parseInt(dateValue.substr(6, 4), 10);
    if((intday > 31) || (intday == 0)) {
      alert("Error en el día");
      objCaja.value = "";
      return false;
    }
    if((intmonth > 12) || (intmonth == 0)) {
      alert ("Error en el mes");
      objCaja.value = "";
      return false;
    }
    if(!isDate(intyear, intmonth, intday)) {
      alert("fecha inválida");
      objCaja.value = "";
      return false;
    }
    return true;
  }
  else {
    return false;
  }
}

function estaSeleccionado(obj) {
  check = false;
  if(isNaN(obj.length)) {
    check = obj.checked && !obj.disabled;
  }
  else {
    longitud = obj.length;
    for(i = 0; i < longitud; i++) {
      if(obj[i].checked == true && !obj[i].disabled) {
        check = true;
        break;
      }
    }
  }
  return check;
}

function moveUp(element) {
  for(i = 0; i < element.options.length; i++) {
    if(element.options[i].selected == true) {
      if(i != 0) {
        var temp = new Option(element.options[i-1].text,element.options[i-1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i-1] = temp2;
        element.options[i-1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}

function moveDown(element) {
  for(i = (element.options.length - 1); i >= 0; i--) {
    if(element.options[i].selected == true) {
      if(i != (element.options.length - 1)) {
        var temp = new Option(element.options[i+1].text,element.options[i+1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i+1] = temp2;
        element.options[i+1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}

function SelectAllList(control){
	for(var i = 0; i < control.length; i++) {
		control.options[i].selected = true;
	}
}

function esTeclaTextoNumero() {
  var valid = "abcdefghijklmñnopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZóáíúé1234567890 ";
  var key = String.fromCharCode(event.keyCode);
  if(valid.indexOf("" + key) == "-1")
    return false;
}


function cantidadObjetosFormulario(forma, nombreObjeto) {
	var conta = 0;
	for (var i = 0; i < forma.elements.length; i++) {
		if (forma.elements[i].name == nombreObjeto) {
			conta++;
		}
	}
	return conta;
}

//Funcion que calcula el tamaño del jsp que sera llamado desde un iframe del Web 
//Content Managament
function calcularTamanoContenedor() {
	
		//alert(" document.body.scrollHeight "+document.body.scrollHeight);		
 	/*if (this.parent.objIframe!=null){
		//le asigna automáticamente altura del body del iframe a el iframe
		alert(" document.body.scrollHeight "+document.body.scrollHeight);		
		parent.objIframe.height=document.body.scrollHeight; 
		alert(" parent.objIframe.document.body.height "+parent.objIframe.height);			
	

		alert("document.parent "+document.parent);
		alert("window.location"+window.location);
	}
	/*if (parent.objIframe!=null){
		parent.objIframe.height = document.getElementById("cuerpo").height;
		alert(" document.getElementById('cuerpo').height "+document.getElementById("cuerpo").height);		
		alert(" parent.objIframe.height "+parent.objIframe.height);		
	}*/
}


function replaceChars(entry, out, add) {
	
	temp = "" + entry; // temporary holder

	while (temp.indexOf(out)>-1) {	
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length));
	}
	return temp;
}
function restaPeriodo(mesInicial, anioInicial, mesFinal, anioFinal){
		var diferenciaMes, diferenciaAnio, resultado;

		if (mesFinal < mesInicial) {
				diferenciaMes = mesFinal + 12 - mesInicial;
				anioFinal = anioFinal - 1;
		}
		else {
				diferenciaMes = mesFinal - mesInicial;
		}
		diferenciaAnio = anioFinal - anioInicial;
		resultado = (diferenciaAnio * 12) + diferenciaMes + 1;
		return resultado;
}
function validarNumeroEntero(){
  var keycode;
  if (window.event) 
  	keycode = window.event.keyCode;
  else 
  	return true;
  if ((keycode >=	48) && (keycode	<=	57)){
  	return true;
  	}
  else{
  	return false;
  	}
}

function validarNumeroDecimal(obj){
	var cadena 	= obj.value;
	var keycode;
  if (window.event) 
  	keycode = window.event.keyCode;
  else 
  	return true;
  	
	if ((cadena.split('.').length>1) & (keycode==46)){
		return false;	
	}
	
  if (((keycode >=	48) && (keycode	<=	57)) || (keycode ==	46)){
  	return true;
  	}
  else{
  	return false;
  	}

}
function rdz_validarInput(tipval){
  var xkey=event.keyCode;
  if(tipval=="int")
    if ((xkey < 48) || (xkey > 57)) event.returnValue = false;
  if(tipval=="dec")
    if ((xkey < 46) || (xkey > 57)) event.returnValue = false;
  if(tipval=="str")
    if (((xkey != 32) && (xkey < 65)) || ((xkey > 90) && (xkey < 97))) event.returnValue = false;
  if(tipval=="tlf")
    if (((xkey != 32) && (xkey < 45)) ||(xkey > 57)) event.returnValue = false;
  if(tipval=="mon")
    if (((xkey < 48) && xkey!=46) || (xkey > 57)) event.returnValue = false;
}

function rdz_keyToUpperCase(field, evt) {
	var c = event.keyCode;
	var C = String.fromCharCode(c).toUpperCase().charCodeAt();
	evt.keyCode = C;
	return true;
}

function ValClaveSeguridad(valor,nomb,fname) {
	if(valor != "" && valor.length < 8) {
		alert("Ingrese correctamente los 8 digitos de la clave de seguridad");
        aux = eval("document." + fname + "." + nomb);
        aux.focus();
        return false;
    }
	return true;
}
function ValClaveSeguridad(valor,nomb,fname) {
	if(valor != "" && valor.length < 8) {
		alert("Ingrese correctamente los 8 digitos de la clave de seguridad");
        aux = eval("document." + fname + "." + nomb);
        aux.focus();
        return false;
    }
	return true;
}
function ValidaTelefono(valor,nomb,fname) {
	if(isNaN(valor) && valor!="") {
        alert("Ingrese correctamente los seis(6), siete(7), once(11) o doce(12) dígitos del teléfono.");
        aux=eval("document."+fname+"."+nomb);
        aux.value="";
        aux.focus();
        return false;
	}
	else {
        if((valor.length != 6 && valor.length != 7 && valor.length != 8 && valor.length != 11 && valor.length != 12)
        	&& valor != "") {
            alert("Ingrese correctamente los seis(6), siete(7), siete(8), once(11) o doce(12) dígitos del teléfono.");
            aux=eval("document."+fname+"."+nomb);
            aux.focus();
        }
        else {
	        return true;
	    }
    }
}

function esTeclaTextoNumero() {
  var valid = "abcdefghijklmñnopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZóáíúé1234567890 ";
  var key = String.fromCharCode(event.keyCode);
  if(valid.indexOf("" + key) == "-1")
    return false;
}

//Verifica fechas desde el año 
//Parametros:
//CheckDate(this.value,this.name,this.form.name,'nombre del campo dias','nombre del campo meses')
function CheckDate(num,nom,fname,nomdia,nommes)
	{
	date=new Date();
	dias=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	anoref=1900;
	modulo=(num-anoref)%4;
	if(modulo==0)
		{
		dias[1]=29;
		}
	
	if(!((eval("document."+fname+"."+nomdia+".value")<=dias[eval("document."+fname+"."+nommes+".value")-1]) && 
	(eval("document."+fname+"."+nomdia+".value")>0) && 
	(eval("document."+fname+"."+nommes+".value")>0) && 
	(eval("document."+fname+"."+nommes+".value")<13) && 
	(eval("document."+fname+"."+nom+".value")>1900)))
		{
		alert(" verifique la fecha");
		return false;
		}
	}

//Verifica Numero Telefonico y Numeros de Cuenta
function EsNum(num,nom,fname)
	{
        this.num=Trim(num);
	this.num=BorCarEsp(this.num)
	expreg=/[()\-\+\s]/g;
	num1=this.num.replace(expreg,"");
	if(isNaN(num1))
		{
		alert("Ingrese un número válido");
		//eval("document."+fname+"[nom].focus()");
		eval("document."+fname+"[nom].value=\"\"");
		eval("document."+fname+"[nom].focus()");
		}
	else
		{
		eval("document."+fname+"[nom].value=this.num");
		}
	}


//Valida Correos Electronicos
//Parametros: (this.value,this.name,this.form.name)

function ValMail(num,nom,fname){

    switch(validamail(num,nom,fname))
     {
       case 0 :
//      document.frmdata.action="actdatos.jsp?asaccion=1"
//      document.frmdata.submit();
        return;
        break;

     /* case 1 :
	alert("....");
  	eval("document."+fname+"."+nom+".focus()");
	error=1;
	return;
	break;*/

      case 2 :
	alert("Mail incorrecto. Por favor verifique.");
  	eval("document."+fname+"."+nom+".focus()");
	error=1;
	return;
	break;

      case 3 :
	alert("Mail incorrecto. No puede existir espacios en blanco.");
  	eval("document."+fname+"."+nom+".focus()");
	error=1;
	return;
	break;

      case 4 :
	alert("Mail incorrecto. Verifique el uso del @.");
  	eval("document."+fname+"."+nom+".focus()");
	error=1;
	return;
	break;

      case 5 :
	alert("Mail incorrecto. No puede haber . despues del @.");
  	eval("document."+fname+"."+nom+".focus()");
	error=1;
	return;
	break;

      case 6 :
	alert("Mail incorrecto. Mail no puede terminar en . ");
  	eval("document."+fname+"."+nom+".focus()");
	error=1;
	return;
	break;
    }
}

function validamail(mail,nom,fname)
{
//verificamos si la cadena enviada no esta vacia
if (mail =="")  {return 1} //Llene su mail.

//Quitamos los espacios en blanco a la derecha y a la izquierda y validamos
//que no haya espacios o caracteres extraños en blanco dentro de la cadena.

num=mail.length
cadena=""

x=0
inicio= 0 // variable para definir inicio y fin de cadena  0 inicialmente 
	  // 1 cuando comienzan los caracteres, 2 cuando terminan.

for(i=0;i<=num;i++)
	//{ if ((eval("document."+fname+"."+nom+".value.substring(i,i+1)==\" \""))||(eval("document."+fname+"."+nom+".value.substring(i,i+1)==\"\"")))
	{ if ((mail.substring(i,i+1)==" ")||(mail.substring(i,i+1)==""))
	   {x=x+1;
	    if (inicio==1)
		{inicio=2}
	   }
     else
	   {if (inicio!=2)
		{inicio=1;
		 //car=eval("document."+fname+"."+nom+".value.substring(i,i+1)");
		 car=mail.substring(i,i+1);
		 //caracteres especiales
		 if ((car=="á")||(car=="é")||(car=="í")||(car=="ó")||
		     (car=="ú")||(car=="Á")||(car=="É")||(car=="Í")||
		     (car=="Ó")||(car=="Ú")||(car==",")||(car==";")||
	             (car=="*")||(car=="#")||(car=="%")||(car=="[")||
	             (car==":")||(car=="}")||(car=="{")||(car=="]")||
	             (car=="^")||(car=="$")||(car=="|"))
		 	{return 2} //caracteres no permitidos
		else	
	        	 {cadena=cadena+car}
		 }
	    else
		{return 3} //No puede haber espacios en blanco
	   }
   }

//validamos caracter en blanco
if (num==x) {return 1} //Mail en blanco

//validamos la presencia del @ y del punto despues de él.

x=0;
pos=0;
pos1=0;
num=cadena.length;

for(i=0;i<=num;i++){
	//if (eval("document."+fname+"."+nom+".value.substring(i,i+1)==\"@\""))
	if (mail.substring(i,i+1)=="@")
		{x=x+1;
		 pos=i+1}
	}
if (x!=1) {return 4} //Verifique el uso del @
else   
     {  x=0;
	if (pos==1) {return 2 } //No puede comenzar con @
       	for (i=pos;i<=num;i++) {
 	//if (eval("document."+fname+"."+nom+".value.substring(i,i+1)==\".\""))
 	if (mail.substring(i,i+1)==".")
	   {x=x+1;
	    pos1=i-pos+1}
	}
       if (x==0) {return 2} //Mail invalido

       if (pos1==1) {return 5} //No puede haber un punto despues de @
       if (num==pos1+pos) {return 6}  //No puede terminar en punto	  	 

     } 	 	 

{return 0}
}

//Valida input en blanco 
//nomb=document.NombreFormulario.NombreInput
//mensaje="mensaje de error"
function blanco(nomb,mensaje){
    if(Trim(nomb.value)==""){
        alert(""+mensaje);
        nomb.focus();
        return false;
    }else{
        return true;
    }
}
function blancoSM(nomb){
    if(Trim(nomb.value)==""){
        return false;
    }else{
        return true;
    }
}
function ValCombo(nomb,mensaje){
    if(Trim(nomb.options[nomb.selectedIndex].value)=="0" || Trim(nomb.options[nomb.selectedIndex].value)=="00" || Trim(nomb.options[nomb.selectedIndex].value)==""){
        alert(""+mensaje);
        nomb.focus();
        return false;
    }else{
        return true;
    }
}
function ValComboSM(nomb){
    if(Trim(nomb.options[nomb.selectedIndex].value)=="0" || Trim(nomb.options[nomb.selectedIndex].value)=="00" || Trim(nomb.options[nomb.selectedIndex].value)==""){
        return false;
    }else{
        return true;
    }
}
function ValRUC(valor,nomb,fname){
if(isNaN(valor) && valor!=""){
        alert("Ingrese correctamente los once(11) dígitos del RUC de su empresa.");
        aux=eval("document."+fname+"."+nomb);
        aux.value="";
        aux.focus();
        return false;
}else{
        if(valor.length < 11 && valor != ""){
            alert("Ingrese correctamente los once(11) dígitos del RUC de su empresa.");
            aux=eval("document."+fname+"."+nomb);            
            aux.focus();
        }else{
        return true;
       }
}
}

function ValidaDNI(valor,nomb,fname) {
	if(isNaN(valor) && valor!="") {
        alert("Ingrese los 8 dígitos del Documento de Identidad. En caso su Documento de Identidad tenga menos de 8 dígitos, completarlo con ceros a la izquierda.");
        aux=eval("document."+fname+"."+nomb);
        aux.value="";
        aux.focus();
        return false;
	}
	else {
        if(valor.length < 8 && valor != "") {
            alert("Ingrese los 8 dígitos del Documento de Identidad. En caso su Documento de Identidad tenga menos de 8 dígitos, completarlo con ceros a la izquierda.");
            aux=eval("document."+fname+"."+nomb);
            aux.focus();
        }
        else {
	        return true;
	    }
    }
}

function ValidaTelefono(valor,nomb,fname) {
	if(isNaN(valor) && valor!="") {
        alert("Ingrese correctamente los seis(6), siete(7), ocho(8), once(11) o doce(12) dígitos del teléfono.");
        aux=eval("document."+fname+"."+nomb);
        aux.value="";
        aux.focus();
        return false;
	}
	else {
        if((valor.length != 6 && valor.length != 7 && valor.length != 8 && valor.length != 11 && valor.length != 12)
        	&& valor != "") {
            alert("Ingrese correctamente los seis(6), siete(7), ocho(8), once(11) o doce(12) dígitos del teléfono.");
            aux=eval("document."+fname+"."+nomb);
            aux.focus();
        }
        else {
	        return true;
	    }
    }
}

function esVacio(cad) {
  var i;
  var blanco = " \n\t" + String.fromCharCode(13);
  var es_vacio;
  if((cad == null) || (cad.length == 0))
    return true;
  for(i = 0, es_vacio = true; (i < cad.length) && es_vacio; i++)
    es_vacio = blanco.indexOf(cad.charAt(i)) != - 1;
  return (es_vacio);
}

function daysInFebruary(year) {
  return (((year%4 == 0) && ((!(year%100 == 0)) || (year%400 == 0))) ? 29 : 28);
}

function isDate(year, month, day) {
  var daysInMonth = new Array();
  daysInMonth[1] = 31;
  daysInMonth[2] = 29;
  daysInMonth[3] = 31;
  daysInMonth[4] = 30;
  daysInMonth[5] = 31;
  daysInMonth[6] = 30;
  daysInMonth[7] = 31;
  daysInMonth[8] = 31;
  daysInMonth[9] = 30;
  daysInMonth[10] = 31;
  daysInMonth[11] = 30;
  daysInMonth[12] = 31;
  if(day > daysInMonth[month])
    return false;
  if((month == 2) && (day > daysInFebruary(year)))
    return false;
  return true;
}

function evaluaFecha(objCaja, formato) {
  var er_date;
  var dateValue = objCaja.value;
  if(!esVacio(dateValue)) {
    switch(formato) {
      case "dd/mm/yyyy":
        er_date = /((\d{2})[\/](\d{2})[\/](\d{4}))+$/
        break;
      default:
        er_date = /((\d{2})[\-](\d{2})[\-](\d{4}))+$/
    }
    if(!er_date.test(dateValue)) {
      alert('Campo fecha con formato inválido.');
      objCaja.value = "";
      return false;
    }
    var intday = parseInt(dateValue.substr(0, 2), 10);
    var intmonth = parseInt(dateValue.substr(3, 2), 10);
    var intyear = parseInt(dateValue.substr(6, 4), 10);
    if((intday > 31) || (intday == 0)) {
      alert("Error en el día");
      objCaja.value = "";
      return false;
    }
    if((intmonth > 12) || (intmonth == 0)) {
      alert ("Error en el mes");
      objCaja.value = "";
      return false;
    }
    if(!isDate(intyear, intmonth, intday)) {
      alert("fecha inválida");
      objCaja.value = "";
      return false;
    }
    return true;
  }
  else {
    return false;
  }
}

function estaSeleccionado(obj) {
  check = false;
  if(isNaN(obj.length)) {
    check = obj.checked && !obj.disabled;
  }
  else {
    longitud = obj.length;
    for(i = 0; i < longitud; i++) {
      if(obj[i].checked == true && !obj[i].disabled) {
        check = true;
        break;
      }
    }
  }
  return check;
}

function moveUp(element) {
  for(i = 0; i < element.options.length; i++) {
    if(element.options[i].selected == true) {
      if(i != 0) {
        var temp = new Option(element.options[i-1].text,element.options[i-1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i-1] = temp2;
        element.options[i-1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}

function moveDown(element) {
  for(i = (element.options.length - 1); i >= 0; i--) {
    if(element.options[i].selected == true) {
      if(i != (element.options.length - 1)) {
        var temp = new Option(element.options[i+1].text,element.options[i+1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i+1] = temp2;
        element.options[i+1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}

function SelectAllList(control){
	for(var i = 0; i < control.length; i++) {
		control.options[i].selected = true;
	}
}

function esTeclaTextoNumero() {
  var valid = "abcdefghijklmñnopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZóáíúé1234567890 ";
  var key = String.fromCharCode(event.keyCode);
  if(valid.indexOf("" + key) == "-1")
    return false;
}


function cantidadObjetosFormulario(forma, nombreObjeto) {
	var conta = 0;
	for (var i = 0; i < forma.elements.length; i++) {
		if (forma.elements[i].name == nombreObjeto) {
			conta++;
		}
	}
	return conta;
}
function evaluaFechaPPO(dia,mes,anio, formato) {
  var er_date;
  
  if(dia.lenght == 1 && eval(dia.value) < 10)
 	 dia.value = "0"+dia.value;
  if(mes.lenght == 1 && eval(mes.value) < 10)
 	 mes.value = "0"+mes.value;
  
  var dateValue =  dia.value+"/"+mes.value+"/"+anio.value;
  if(!esVacio(dateValue)) {
    switch(formato) {
      case "dd/mm/yyyy":
        er_date = /((\d{2})[\/](\d{2})[\/](\d{4}))+$/
        break;
      default:
        er_date = /((\d{2})[\-](\d{2})[\-](\d{4}))+$/
    }
    if(!er_date.test(dateValue)) {
      alert('Campo fecha con formato inválido.');
     
      return false;
    }
    var intday = parseInt(dateValue.substr(0, 2), 10);
    var intmonth = parseInt(dateValue.substr(3, 2), 10);
    var intyear = parseInt(dateValue.substr(6, 4), 10);
    if((intday > 31) || (intday == 0)) {
      alert("Error en el día de nacimiento");
      dia.select();
      return false;
    }
    if((intmonth > 12) || (intmonth == 0)) {
      alert ("Error en el mes de nacimiento");
      mes.select();
      return false;
    }
    if(!isDate(intyear, intmonth, intday)) {
      alert("fecha inválida");
      return false;
    }
    return true;
  }
  else {
    return false;
  }
}

function agregarOpcion(objetoSelect, newOptionValue, newOptionText) {
	var newIndex = objetoSelect.options.length;
	objetoSelect.options[newIndex] = new Option(newOptionText, newOptionValue);
    return newIndex;
}

function ValCodigoPromotorVentas(valor,nomb,fname) {
	if(valor != "" && valor.length < 5) {
		alert("Ingrese correctamente los 5 digitos del código de promotor de ventas");
        aux = eval("document." + fname + "." + nomb);
        aux.focus();
        return false;
    }
	return true;
}
function removerOpciones(objetoSelect) {
	if (objetoSelect.length != 0) {
		for (var i = 0; i < objetoSelect.options.length; ++i) {
			objetoSelect.options[i] = null;
			--i;
		}
	}
}

function seleccionarOpcionPorIndice(objetoSelect, optionIndex) {
	objetoSelect.selectedIndex = optionIndex;
}

function rellenarConCero(cadena) {
	if (cadena < 10) {
		cadena = "0" + cadena;
	}
	return cadena;
}


function BorCarEsp1(num)
	{
        expreg=/[@_:;,<>°!"#$%=?¡¿'*\~{}\[\]{\\^`|¬´¨]/g;
	this.num=num.replace(expreg,"");
	return this.num;
	}
function numeroObjetos(name) {
	var ctd_items=0;

    for(i=0;i<document.all.length;i++) {
      if(document.all[i].name == name)
      	seleccionado = ctd_items = ctd_items + 1;
    }
  
    return ctd_items;
}
//-->
