/* ------------------------------------------------------------------ */
/* - Actualizacion el Lunes, 22 de Mayo de 2006 a las 01:07:55 p.m. - */
/* ------------------------------------------------------------------ */

function popup(pagina,nombre,ancho,alto,opcscroll)
{		
	screen_height = window.screen.availHeight;
	screen_width = 	window.screen.availWidth; 
	left_point = parseInt(screen_width/2)-(ancho/2); 
	top_point = parseInt(screen_height/2)-(alto/2);
	pop = window.open(pagina,nombre,"status=no,resizable=no,toolbar=no,scrollbars="+opcscroll+",left="+left_point+",top="+top_point+",width="+ancho+",height="+alto+"");
}


/**
 * Sets/unsets the pointer in browse mode
 *
 * @param   object   the table row
 * @param   object   the color to use for this row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, thePointerColor)
{
    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
        return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
        var theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        var theCells = theRow.cells;
    }
    else {
        return false;
    }

    var rowCellsCnt  = theCells.length;
    for (var c = 0; c < rowCellsCnt; c++) {
        theCells[c].style.backgroundColor = thePointerColor;
    }

    return true;
} // end of the 'setPointer()' function



function mayusculas(obj)
{	obj.value = obj.value.toUpperCase();	}


// Funcion que cuenta las letras introducidas en el texto
function contadorLetras(campo, campoCuenta, limite)
{	if (campo.value.length > limite) 
	{	campo.value = campo.value.substring(0, limite);
	}else 
	{	campoCuenta.value = limite - campo.value.length;	}
}

// Funcion que valida si es un email valido o no
function esMail(_email)
{	var emailReg = /^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/i
	return emailReg.test(_email);
}

// Funcion que verifica si hay al menos un espacio en blanco dentro de la cadena
function isThereSpace( str )
{	var i = len = 0;
	if ( str + "" == "undefined" || str == null)	
	{	return false;	}
	str += "";
	str = trim(str);
	if ( str.length == 0 ) 
	{	return false;
	}else
	{	len = str.length;
  		while ( i <= len )
		{	if ( str.charAt(i) == " " )
			{	return true;	}
			i++;	}
  	}
  	return false;
}

// Funcion que quita los espacios en blanco de la izquierda
function trimLeft( str )
{	var resultStr = "";
	var i = len = 0;
	if (str+"" == "undefined" || str == null)	
	{	return "";	}
	str += "";
	if (str.length == 0) 
	{	resultStr = "";
	}else
	{	len = str.length;
  		while ((i <= len) && (str.charAt(i) == " "))
		{	i++;	}
  		resultStr = str.substring(i, len);
  	}
  	return resultStr;
}

function trimRight( str )
{	var resultStr = "";
	var i = 0;
	if (str+"" == "undefined" || str == null)	
	{	return "";	}

	// Make sure the argument is a string
	str += "";
	
	if (str.length == 0) 
	{	resultStr = "";
	}else
	{	i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " "))
 		{	i--;	}
  		resultStr = str.substring(0, i + 1);
  	}
  	return resultStr;  	
}

function trim( str )
{	var resultStr = "";
	resultStr = trimLeft(str);
	resultStr = trimRight(resultStr);
	return resultStr;
}



function saveValuesFromTo( selOrigen, txtDestino, splitChar )
{	var length = selOrigen.length;
	txtDestino.value = '';
	for ( i = 0; i < length; i++ )
	{	if ( i > 0 )
		{	txtDestino.value = txtDestino.value + splitChar;	}
		txtDestino.value = txtDestino.value + selOrigen.options[i].value;
	}
}


function addValueFromTo( selOrigen , selDestino )
{	var length = selOrigen.length;
	if ( length <= 0 )
	{	return false;	}
	var selected = selOrigen.selectedIndex;
	if ( selected < 0 )
	{	return false;	}
	var codigo = selOrigen.options[selected].value;
	if ( trim(codigo) == '' )
	{	return false;	}
	var descripcion = selOrigen.options[selected].text;
	if ( trim(descripcion) == '' )
	{	return false;	}
	newoption = new Option( descripcion , codigo , false, false);
	selDestino.options[selDestino.length] = newoption;
	selOrigen.options[selected] = null;
}


function addAllValueFromTo( selOrigen , selDestino )
{	var length = selOrigen.length;
	if ( length <= 0 )
	{	return false;	}
	var i = 0;
	while ( length > 0 )
	{	var codigo = selOrigen.options[0].value;
		if ( trim(codigo) == '' )
		{	continue;	}
		var descripcion = selOrigen.options[0].text;
		if ( trim(descripcion) == '' )
		{	continue;	}
		newoption = new Option( descripcion , codigo , false, false);
		selDestino.options[selDestino.length] = newoption;
		selOrigen.options[0] = null;
		length = selOrigen.length;
	}
}



function checkFecha( idOpe, idMax, idPan )
{	var value = idOpe[idOpe.selectedIndex].value;
	if ( value == '<>' )
	{	document.all[ '' + idPan + '' ].style.visibility  = 'visible';
	}else
	{	document.all[ '' + idPan + '' ].style.visibility  = 'hidden';
		idMax.value = '';	}
}




function fechaActual()
{	fecha = new Date();
	dia = fecha.getDate();
	mes = parseInt( fecha.getMonth() ) + 1;
	anio = fecha.getFullYear();
	hora = fecha.getHours();
	minuto = fecha.getMinutes(); 
	segundo = fecha.getSeconds();

	if ( mes < 10 )
	{	mes = "0" + mes;	}
	if ( dia < 10 )
	{	dia = "0" + dia;	}

	if ( hora == 0 )
	{	hora = 12;
		ampm = " AM";
	} else if ( hora <= 11 )
	{	ampm = " AM";
		if ( hora <= 9 )
		{	hora = "0" + hora;	}
	} else if ( hora == 12 )
	{	ampm = " PM";
	} else if ( hora >= 13 )
	{	hora = ( hora - 12 );
		ampm = " PM";
		if ( hora <= 9 )
		{	hora = "0" + hora;	}
	}
	if ( minuto <= 9 )
	{	minuto = "0" + minuto;	}
	if ( segundo <= 9)
	{	segundo = "0" + segundo;	}

	valor = dia + "/" + mes + "/" + anio + " " + hora + ":" + minuto + ":" + segundo + " " + ampm;
	return valor;
}



function seleccionarProvincia( theForm, theDepartament, theProvince, theDistrit, newForm )
{	var Departamento;
	Departamento = theDepartament[theDepartament.selectedIndex].value;
	theProvince.length = 1;
	theProvince.options[0].value = 'ALL';
	theProvince.options[0].text = 'TODAS LAS PROVINCIAS';
	if (Departamento != 'ALL')
	{	newForm.txtFormulario.value = theForm.name;
		newForm.txtControl.value = theProvince.name;
		newForm.txtTipo.value = 'provincia';
		newForm.txtCodigo.value = Departamento;
		newForm.submit();
	}
	theProvince.options[0].selected = true;
	seleccionarDistrito( theForm, theProvince, theDistrit, newForm );	}

function seleccionarDistrito( theForm, theProvince, theDistrit, newForm )
{	var Provincia;
	Provincia = theProvince[theProvince.selectedIndex].value;
	theDistrit.length = 1;
	theDistrit.options[0].value = 'ALL';
	theDistrit.options[0].text = 'TODOS LOS DISTRITOS';
	if (Provincia != 'ALL')
	{	newForm.txtFormulario.value = theForm.name;
		newForm.txtControl.value = theDistrit.name;
		newForm.txtTipo.value = 'distrito';
		newForm.txtCodigo.value = Provincia;
		newForm.submit();
	}
	theDistrit.options[0].selected = true;		}




function seleccionarUbicacion( theForm, theDepartament, theProvince, theDistrit, newForm, theValue )
{	theProvince.length = 1;
	theProvince.options[0].value = 'ALL';
	theProvince.options[0].text = 'TODAS LAS PROVINCIAS';
	theDistrit.length = 1;
	theDistrit.options[0].value = 'ALL';
	theDistrit.options[0].text = 'TODOS LOS DISTRITOS';

	if ( (theValue != '000000') && (theValue != '') )
	{	newForm.txtFormulario.value = theForm.name;
		newForm.txtDepControl.value = theDepartament.name;
		newForm.txtProControl.value = theProvince.name;
		newForm.txtDisControl.value = theDistrit.name;
		newForm.txtTipo.value = 'todos';
		newForm.txtCodigo.value = theValue;
		newForm.submit();
	}
}
