/**
 * Archivo General de JavaScrip para el PORTAL de la DEM
 * http://dem.tsj.gov.ve
 */
 
/**
 * FUNCIONES
 * function enviarConfirmacion(nombreVentana, nombreClase, donde, w, h) Abre una ventana para la confirmación de datos
 * function newWindow(file,window,w,h)				Abre un pop-up con unas dimensiones especificas en el centro de la pantalla.
 * function doSubmit 								Funcion para controlar el submit de la página donde es llamada
 * function validarIngresoRetencionIVA(forma)		Valida los datos de entrada de la página de Declaración de Retención del IVA
 * function esNulo(obj)								Determina si un objecto de HTML es nulo o no.
 * function esNuloCombo(obj)						Determina si un combo de HTML es nulo o no tiene ninguna opción.
 * function esNumero(num)							Determina si num es o no un número.
 * function esInteger(num)							Determina si num es o no un número entero o no.
 * function evaluarError(error)						Genera un mensaje de alerta con el valor de error.
 * function isDate(Day, Month, Year)				Verifica si es una fecha valida o no.
 * function newWindow(file,window,w,h)				Abre un pop-up con unas dimensiones especificas en el centro de la pantalla.
 * function round(numero, decimales)				Redondea un número decimal. Si no tiene '.' se lo coloca.
 */
 
defaultStatus = "© Dirección Ejecutiva de la Magistratura.";

var FECHA_TIPO_YYYY_MM_DD = 1;
var FECHA_TIPO_DD_MM_YYYY = 2;
var FECHA_TIPO_MM_DD_YYYY = 3;

/**
 * Abre una ventana para la confirmación de datos
 */
function enviarConfirmacion(nombreVentana, nombreClase, donde, w, h) {
		//newWindow('about:blank',nombreVentana, w, h);
		doSubmit(nombreClase,'',donde);
}

/**
 * Funcion para controlar el sumit de la página donde es llamada
 * accion = el action de la forma.
 * objectivo = el target de la forma.
 * control = variale de control. Esta dee estar definida dentro
 *           del form como un campo oculto.
 */
function doSubmit(accion, objectivo, control, e){
	var vAction = accion;
	var vTarget = objectivo;
	var vControl= control;	

	document.forms[e].control.value = vControl;
	document.forms[e].action = vAction;
	document.forms[e].target = vTarget;
	document.forms[e].method = "post";
	document.forms[e].submit();
	return false;
}

/**
 * Redondea un número decimal. Si no tiene '.' se lo coloca.
 * Redondea a dos digitos decimales solamente.
 * 25/07/02
 */
function round(numero, decimales) {

	var s = "" + Math.round(numero * 100) / 100;
  	var i = s.indexOf('.');
  	if (i < 0) return s + ".00";
  	var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3);
  	if (i + 2 == s.length) t += "0";
  	return t;
}


/**
 * Abre un pop-up con unas dimensiones especificas en el centro de la pantalla.
 */
function newWindow(file, window, w, h) {
	if (document.all || document.layers || document.getElementById) {
		wCenter = screen.availWidth;
		hCenter = screen.availHeight;
	}
	
	var popW = w, popH = h;
	var leftPos = (wCenter-popW)/2, topPos = (hCenter-popH)/2;

	msgWindow=open(file,window,"menubar=no,status=no,scrollbars=yes,resizable=no,width=" + w + ",height=" + h +",top="+topPos+",left="+leftPos);
	msgWindow.location.href = file;
	if (msgWindow.opener == null) {
		msgWindow.opener = self;
	}
//		msgWindow.opener.name = "opener";
}
function popSticker(file) {
	if (document.all || document.layers || document.getElementById) {
		wCenter = screen.availWidth;
		hCenter = screen.availHeight;
	}
	
	var popW = 45, popH = 45;
	var leftPos = (wCenter-popW)/2, topPos = (hCenter-popH)/2;

	msgWindow=open(file,'Sticker','menubar=no,status=no,scrollbars=yes,resizable=no,width=' + 380 + ',height=' + 450 +',top='+topPos+',left='+leftPos);
	msgWindow.location.href = file;
	if (msgWindow.opener == null) {
		msgWindow.opener = self;
	}
//		msgWindow.opener.name = "opener";
}
/**
 * Abre un pop-up con unas dimensiones especificas en el centro de la pantalla.
 * isScroll [yes][no]
 * isStatus [yes][no]
 * isResizable [yes][no]
 * isMenuBar [yes][no]
 */
function newWindow2(file,window,w,h, isScroll, isStatus, isResizable, isMenuBar) {
	if (document.all || document.layers || document.getElementById) {
		wCenter = screen.availWidth;
		hCenter = screen.availHeight;
	}
	
	var popW = w, popH = h;
	var leftPos = (wCenter-popW)/2, topPos = (hCenter-popH)/2;

	msgWindow=open(file,window,"menubar=" + isMenuBar + ",status=" + isStatus + ",scrollbars=" + isScroll + ",resizable=" + isResizable + ",width=" + w + ",height=" + h +",top="+topPos+",left="+leftPos);
	msgWindow.location.href = file;
	if (msgWindow.opener == null) {
		msgWindow.opener = self;
	}
//		msgWindow.opener.name = "opener";
}
function newWindow3(file,window2,w,h, isScroll, isStatus, isResizable, isMenuBar) {
	if (document.all || document.layers || document.getElementById) {
		wCenter = screen.availWidth;
		hCenter = screen.availHeight;
	}
	
	var popW = w, popH = h;
	var leftPos = (wCenter-popW)/2, topPos = (hCenter-popH)/2;

	window.open(file,window2,"menubar=" + isMenuBar + ",status=" + isStatus + ",scrollbars=" + isScroll + ",resizable=" + isResizable + ",width=" + w + ",height=" + h +",top="+topPos+",left="+leftPos);
   return false;
}


/**
 * Abre un pop-up con unas dimensiones especificas en el centro de la pantalla sin scroll.
 */

function newWindowSinScroll(file,window,w,h) {
	if (document.all || document.layers || document.getElementById) {
		wCenter = screen.availWidth;
		hCenter = screen.availHeight;
	}
	
	var popW = w, popH = h;
	var leftPos = (wCenter-popW)/2, topPos = (hCenter-popH)/2;

	msgWindow=open(file,window,"menubar=no,status=no,scrollbars=no,resizable=no,width=" + w + ",height=" + h +",top="+topPos+",left="+leftPos);
	msgWindow.location.href = file;
	if (msgWindow.opener == null) {
		msgWindow.opener = self;
	}
//		msgWindow.opener.name = "opener";
}


/**
 * Para deshabilitar el boton derecho del Browser
 */
 
function botonEnIE() {
	if (document.all) {
		return false;
	}
} 

function botonEnNetscape(e) {
	if (document.layers || (document.getElementById && !document.all)) { 
		if (e.which==2 || e.which==3) {
			return false;
		}
	}
} 

if (document.layers) {
//	document.captureEvents(Event.MOUSEDOWN);
//	document.onmousedown	= botonEnNetscape;
} else{
//	document.onmouseup		= botonEnNetscape;
//	document.oncontextmenu	= botonEnIE;
}


/**
 * Verifica si es una fecha valida o no
 * Parametros de entrada es DIA, MES, ANO
 * DIA es un SELET->HTML
 * MES es un SELET->HTML
 * ANO es un SELET->HTML
 * Retorna true si es una fecha valida, de lo contrario retorna False
 */
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function isDate(Day, Month, Year) {
	var day = Day-0;
	var month = Month-0;
	var year = Year-0;
	var today = new Date();
	
	year = ((!year) ? y2k(today.getYear()):year);
	month = ((!month) ? today.getMonth():month-1);
	if (!day) return false
	var test = new Date(year,month,day);
	if ( (y2k(test.getYear()) == year) && (month == test.getMonth()) && (day == test.getDate()) )
		return true;
	else
		return false
}

/**
 * Determina si num es o no un número.
 * Retorna true si se número o false si no lo es.
 * 21/1/02
 */
function esNumero(num){
	return !isNaN(num);
	
}

/**
 * Determina si num es o no un número entero o no.
 */
function esInteger(num) {
  return (parseInt(num) == num);
}

/**
 * Determina si un objecto de HTML es nulo o no.
 */
function esNulo(obj){
	if ((obj==null) || (obj.value==null)){
		return true;
	}
	var objString = new String(obj.value);

	if (objString.replace(/^\s*/, '').replace(/\s*$/, '').length==0){
		return true;
	}

	return false;
}

/**
 * Determina si un combo de HTML es nulo o no tiene ninguna opción.
 */
function esNuloCombo(obj){
	if (obj==null)
	{
		return true;
	}

	if (obj.selectedIndex==0)
	{
		return true;
	}
	return false;
}



/**
 * Genera un mensaje de alerta con el valor de error.
 * Se utiliza para desplegar los errores de validación de una página.
 */
function evaluarError(error){
	if (error!=""){
		alert(error);
		return false
	}
	return true;
}

/**
 * Determina si un String es una fecha valida o no.
 */
function esFecha(fechaString, tipo){
	if (tipo == FECHA_TIPO_YYYY_MM_DD){
		if (fechaString.length == 10){
			return isDate(fechaString.substring(8,10), 
								fechaString.substring(5,7),
								fechaString.substring(0,4));
		} else {
			return false;
		}
	} else{
		if (tipo == FECHA_TIPO_DD_MM_YYYY){
			if (fechaString.length == 10){
				return isDate(fechaString.substring(0,2), 
								fechaString.substring(3,5),
								fechaString.substring(6,10))
			} else {
				return false;
			}
		}
	}
	return false;
}

/**
 * Determina si la argRif, es un RIF valido o no.
 * Retorna true si es valido de lo contrario retorna false.
 */
function esRIFValido(argRIF){
	if (esNulo(argRIF) || argRIF.value.length!=10){
		return false;
	}
	
	if (!esValido(argRIF.value.charAt(0)+"","JVPEG")){
		return false;
	}
	
	if (!esValido(argRIF.value.substring(1, argRIF.value.length), "0123456789")){
		return false;
	}
	return true;
}

function esValido(argString, charPermitidos) {

    for (var i=0; i< argString.length; i++) {
       if (charPermitidos.indexOf(argString.charAt(i)) == -1)
          return false;
    }
    return true;
}

/**
 * Alinea un texto en la direccion indicada y el
 * espacio sobrante lo rellena con 'relleno'
 */
function alinear(cadena, direccion, tamano, relleno){
	var longitud
	longitud = cadena.length
	if (direccion=="D"){
		for(var i=0; i<(tamano-longitud); i++){
			cadena = relleno + cadena;
		}
	} else {
		for(var i=0; i<(tamano-longitud); i++){
			cadena = cadena+relleno;
		}
	}
	
	return cadena;
}

/**
 * Elimina el item que esta seleccionado de la lista.
 */
function eliminarItemLista(lista){
	if (lista.selectedIndex>=0){
		lista.options[lista.selectedIndex] = null;
	}
}



/**
 * dado un valor y una lista, selecciona un item en la lista.
 */
function selectLista(lista, valor){
		for(var i=0; i<lista.length; i++){
			if (lista.options[i].value==valor){
				lista.selectedIndex = i;
				break;
			}
		}
}
/**
 * Funcion para aplicar un trim a los string
 */
function trim(str) {
	return str.replace(/^\s*/, '').replace(/\s*$/, '');
}

/**
 * Busca la proxima ocurrencia del caracter en la tira y
 * retorna la posición donde esta.
 */
function searchNext(tira, caracter, comienzo){
	var subString
	if (tira!=null && trim(tira)!=""){
		subString = tira.substring(comienzo+0, tira.length);
		return subString.indexOf(caracter);
	}
	//return -1;
}

/**
 * Selecciona todos los items de una lista.
 */
function selectAll(lista) {
	for ( i = 0; i <= lista.length-1; i++ )
		lista.options[i].selected = true;
	return true;
}


function enviar(argNombreVentana, w, h, accion, control ){
	newWindow('about:blank', argNombreVentana, w, h);
	doSubmit(accion,argNombreVentana,control);
}

//e = indice del formulario
function enviar2(e, argnombreVentana, w, h, accion, control, isScroll, isStatus, isResizable, isMenuBar ){
	newWindow2('about:blank', argnombreVentana, w, h, isScroll, isStatus, isResizable, isMenuBar);
	doSubmit(accion,argnombreVentana,control, e);
}

function haySeleccion(forma, nombreCheckbox){
	var chequeadas;
	chequeadas = 0;
	for (var i = 0; i<forma.elements.length; i++) {
        if ((forma.elements[i].name.indexOf(nombreCheckbox) > -1)) {
            if (forma.elements[i].checked) {
            	chequeadas = chequeadas + 1;
            }
        }
    }
    if (chequeadas==0) return false;
    return true;
}

	function validaFormaNoticia(forma){
		if (trim(forma.area.value)==""){
			alert("Debe seleccionar el area");
			return false; 
		}
		if (forma.seccion!=null){
			if ((forma.area.value != IDAREA_EDITORIAL)&&(forma.area.value != IDAREA_PERSONAJE)&&(forma.area.value != IDAREA_DEMOSTRACIONES)&&(forma.area.value != IDAREA_NOTAESPECIAL)){
				if (forma.seccion.value==""){
					alert("Debe seleccionar una Seccion");
					return false;
				}   
			}
		} 
		if (forma.area.value != IDAREA_NOTAESPECIAL){
			if ((trim(forma.titulo.value)=="")||(trim(forma.sub.value)=="")||(trim(forma.resumen.value)=="")||(trim(forma.texto.value)=="")){
				alert("Campos requeridos en blanco "); 
				return false;	
	  		}
		}else{
			if (trim(forma.texto.value)==""){
				alert("Campos requeridos en blanco "); 
				return false;	
			}
		}
		if  ((forma.area.value == IDAREA_EDITORIAL) || (forma.area.value == IDAREA_NOTAESPECIAL)){
			if (trim(forma.autor.value)==""){
				alert("la noticia a incluir requiere Autor");
				return false;
			}
		}

		//if((forma.area.value != IDAREA_EDITORIAL)&&(forma.area.value != IDAREA_NOTAESPECIAL)&&(forma.area.value != IDAREA_RESUMEN)&&(forma.op.value!="M")){
			//if(trim(forma.fotoP.value)==""){
			//	alert("la noticia a incluir requiere Foto Preeliminar");
			//	return false;
			//}else{
			//	if (trim(forma.descripcionP.value)==""){
			//		alert("la noticia a incluir requiere descripcion de Foto Preeliminar");
			//		return false;
			//	}
			//}
			//if (trim(forma.fotoD.value)==""){
			//	alert("la noticia a incluir requiere Foto de Desarrollo");
			//	return false;
			//}else{
			//	if (trim(forma.descripcionD.value)==""){
			//		alert("la noticia a incluir requiere descripcion de Foto Desarrollo");
			//		return false;
			//	}
			//}
		//}
  		return true;
 	}

function cuentaCaracteres(valor, CANTIDAD_CARACTERES){
//val = valor; 
 if (valor.value.length > CANTIDAD_CARACTERES) {
//  alert('excedio la cantidad de caracteres');
  valor.value = valor.value.substring(0,CANTIDAD_CARACTERES);
  valor.focus()
  }
 }
 
 function aceptaLetras(obj,evt){	
 var key = nav4 ? evt.which : evt.keyCode;	
 if (key == 13){obj.value = replace(obj.value,'\n','\n');}
 return (true);
 }
 
 function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}
function validaResumen(forma){
var valor = true;
var i=0;
 while((i<forma.elements.length)&&(valor)){
  if (forma.elements[i].name!="autor2")
  if ((forma.elements[i].value=="--")||(trim(forma.elements[i].value)=="")){
    alert("Datos Requeridos ...");
    valor = false;
   }
   i++;
  }
  return valor;
 }
function validateFormEx(forma){
var valor = true;
var i=0;
 while((i<forma.elements.length)&&(valor)){
  if ((forma.elements[i].name!="chat")&&(forma.elements[i].name!="foro")&&(forma.elements[i].name!="encuesta"))
  if ((forma.elements[i].value=="--")||(trim(forma.elements[i].value)=="")){
    alert("Datos Requeridos ...");
    valor = false;
   }
   i++;
  }
  return valor;
} 
function validateForm(forma){
var valor = true;
var i=0;
 while((i<forma.elements.length)&&(valor)){
  if ((forma.elements[i].value=="--")||(trim(forma.elements[i].value)=="")){
    alert("Datos Requeridos ...");
    valor = false;
   }
   i++;
  }
  return valor;
} 
function ocultar()
{
if(document.all){document.all["Layer1"].style.visibility="hidden";}
if(document.layers){document.layers["Layer1"].visibility="hidden";}
}


function subir(indiceForm, accion){
	document.forms[indiceForm].action=accion;
	document.forms[indiceForm].submit();
	return false;
}

/*
function trim(strText) { 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
   return strText;
}*/ 

 