function centerLayer( id, halfWidth, halfHeight )
{
	o = document.getElementById(id)
	if( o )
	{
		//la mitad de los tamannos para los calculos
		hw = document.body.clientWidth/2
		hh = document.body.clientHeight/2
		o.style.top = hh-halfHeight
		o.style.left = hw-halfWidth
	}
}

function setParagraph(id, text)
{
	if( document.all )
	{
		document.all(id).innerText = text
	}
	else if( document.getElementById )
	{
		document.getElementById(id).firstChild.nodeValue = text
	}
}

if (document.layers) 
{ // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all || document.getElementById)
{ // Internet Explorer o mozilla
    document.onmousemove = captureMousePosition;
}

// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {//Netscape
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) { //IE
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {//Mozilla
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

function moveLayerMouse(id,offsetX,offsetY)
{
	if( document.all )
	{
		document.all(id).style.left = xMousePos + offsetX
		document.all(id).style.top = yMousePos + offsetY
	}
	else if( document.getElementById )
	{
		document.getElementById(id).style.left = xMousePos + offsetX
		document.getElementById(id).style.top = yMousePos + offsetY
	}
}


function doBlink()
{
}

function startBlink()
{
}

function richText(field)
{
	popup('../include/richText.jsp?pField='+ field,'richTextEditor',600,400)
}

function formula( field )
{
	popup('../include/formula/formula.html','formula',680,250)
}

function maximizeWindow( win )
{
	win.window.moveTo(0,0);
	if (document.all)
	{
		win.window.resizeTo( screen.availWidth, screen.availHeight )
	}
	else if( document.layers || document.getElementById )
	{
		if( win.window.outerHeight<screen.availHeight || win.window.outerWidth<screen.availWidth )
		{
			win.window.outerHeight = screen.availHeight
			win.window.outerWidth = screen.availWidth
		}
	}
}


function sendEmail( email, type )
{
	path = '../Users/sendEmail.jsp?pEmail='+ email
	if( type )
		path += '&pType='+ type
	popup( path, 'email', 500, 400 );
}

function selectAll( form, name, field )
{
	for( i=0; i<form.elements.length ; i++ )
	{
		element = form.elements[i]
		if( element.name == name )
		{
			element.checked = field.checked
		}
	}
	allSelected = !allSelected
}

function showLayer( id, pos )
{
	if( document.getElementById(id) )
	{
		if( pos )
			document.getElementById(id).style.position = 'relative'
		document.getElementById(id).style.visibility = 'visible'
	}
}

function hideLayer( id, pos )
{
	if( document.getElementById(id) )
	{
		if( pos )
			document.getElementById(id).style.position = 'absolute'
		document.getElementById(id).style.visibility = 'hidden'
	}
}

function doClock(){ // By Paul Davis - www.kaosweaver.com
  var t=new Date(),a=doClock.arguments,str="",i,a1,lang="5";
  var month=new Array('Enero','En.', 'Febrero','Feb.', 'Marzo','Mar.', 'Abril','Abr.', 'Mayo','May.', 'Junio','Jun.', 'Julio','Jul.', 'Agosto','Ago.', 'Septiembre','Sep.', 'Octubre','Oct.', 'Noviembre','Nov.', 'Diciembre','Dic.');
  var tday= new Array('domingo','dom','lunes','lun', 'martes','mar', 'mi�rcoles','mi�','jueves','jue','viernes','vie','s�bado','s�b');
  for(i=0;i<a.length;i++) {a1=a[i].charAt(1);switch (a[i].charAt(0)) {
  case "M":if  ((Number(a1)==3) && ((t.getMonth()+1)<10)) str+="0";
  str+=(Number(a1)>1)?t.getMonth()+1:month[t.getMonth()*2+Number(a1)];break;
  case "D": if ((Number(a1)==1) && (t.getDate()<10)) str+="0";str+=t.getDate();break;
  case "Y": str+=(a1=='0')?t.getFullYear():t.getFullYear().toString().substring(2);break;
  case "W":str+=tday[t.getDay()*2+Number(a1)];break; default: str+=unescape(a[i]);}}return str;
}

function clock(campo, deep )
{	
	path = ''
	if( deep )
		for( i=0 ; i<deep ; i++ )	
			path += '../'
	else
		path = '../'
	path += 'include/'
	win = open(path +'clock.jsp?pField='+campo,'clock','location=no,scrollbars=yes,width=100,height=160,left=100,top=100');
	win.focus()
}

function setIndexByText(field,texto)
{
	size = field.length
	if( texto == '' || texto == null )
		return
	for( i=0 ; i<size ; i++ )
		if( field.options[i].text == texto )
		{
			field.selectedIndex = i
			return
		}
}

function setIndexByValue(field,val)
{
	size = field.length
	if( val == '' || val == null )
		return
	for( i=0 ; i<size ; i++ )
		if( field.options[i].value == val )
		{
			field.selectedIndex = i
			return
		}
}

function setSelectIndex( field, value, type )
{
  for( i=0 ; i<field.length ; i++ )
  {
    if( type==1 && field.options[i].value==value )
    {
      field.selectedIndex = i
      return
    }
    else if( field.options[i].text==value )
    {
      field.selectedIndex = i
      return
    }
  }
}

function setRadio( field, value )
{
  for( i=0 ; i<field.length ; i++ )
  {
    if( field[i].value==value )
    {
      field[i].checked = true
      return
    }
  }
}

function popup( page, name, width, height, clean, properties )
{
  if( !properties )
    properties = ',location=no,scrollbars=yes,top=100,left=100'
  win = window.open(page,name,'width='+width+',height='+ height +properties)
  if( win )
  	win.focus()
  return win
}

function setStatus(mensaje)
{
	status = mensaje;
	return true;
}

function endStatus()
{
	status = '';
}

<!-- Original:  Chu Alan -->
<!-- Web Site:  http://www.methylated-spirit.com -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

function replace(str, original, replacement) {
	var result;
	result = "";
	while(str.indexOf(original) != -1) {
		if (str.indexOf(original) > 0)
			result = result + str.substring(0, str.indexOf(original)) + replacement;
		else
			result = result + replacement;
		str = str.substring(str.indexOf(original) + original.length, str.length);
	}
	return result + str;
}
<!-- 			End			 -->

function calendar(campo, deep )
{	path = ''
	if( deep )
		for( i=0 ; i<deep ; i++ )	
			path += '../'
	path += 'include/'
	win = open(path +'calendar.jsp?pField='+campo,'calendar','location=no,scrollbars=yes,width=300,height=250,left=100,top=100');
	win.focus()
}

function downloadFile(realFile,type,fileName)
{
	open('../include/download.jsp?pFile='+realFile+'&pType='+type+'&pFileName='+fileName,'download','location=no,scrollbars=no,width=220,height=160,left=100,top=100');
}

function viewText(res)
{
	open('resource_view.jsp?pResource='+res,'view','location=no,scrollbars=no,width=600,height=500,left=100,top=100');
}

function userInfo(user)
{
	open('../Users/user_info.jsp?pUser='+user,'usinfo','location=no,scrollbars=yes,width=510,height=500,left=100,top=100');
}

function sendForm(form,action)
{
	form.action = action;
	form.submit();
}

function message(mensaje)
{
	//mensaje = replace(mensaje,' ','%20');
	//x = (screen.availWidth/2)-110;
	//y = (screen.availHeight/2)-55;
	//window.open('../include/message.jsp?pMessage='+mensaje,'window','left='+x+',top='+y+',width=220,height=110,scrollbars=no,location=no,modal=yes');	
	alert(mensaje);
}

function equals(campo1,campo2,mensaje)
{
	if( campo1.value != campo2.value )
	{
		campo2.focus();
		message(mensaje);
		return false;
	}
	return true;
}

function isEmpty(campo,mensaje,focus)
{
//alert("campo=" + campo.name + ":valor campo=" + campo.value);
	if( campo.value == "" )
	{
		if(focus=='true')
			campo.focus();
		message(mensaje);
		return true;
	}
	else
	{
		return false;
	}
}
//--------------
/*
author: David Blackledge
see: http://javascript.internet.com/forms/radio-question-validator.html#source
desc: checks if for every radio buttons group in a form one has been choosen; if so, returns true
*/
function checkRadios(form,message) {
  var el = form.elements;
  for(var i = 0 ; i < el.length ; ++i) {
    if(el[i].type == "radio") {
      var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
      var itemchecked = false;
      for(var j = 0 ; j < radiogroup.length ; ++j) {
        if(radiogroup[j].checked) {
	        itemchecked = true;
	        break;
	      }
      }
      if(!itemchecked) { 
        alert(message);
          if(el[i].focus)
            el[i].focus();
	      return false;
      }
    }
  }
  return true;
}
//--------------
/*
this function checks if there is some repeated element in an array
*/
function repeatedElements(arr){
	var repeated, length = arr.length;
  for(i=0; i<length;i++){
	  repeated = false;
	  temp = arr[i];
		for(j=0; j<length; j++){		  
		  if(j!=i && arr[j]==temp){
        repeated = true;     
			  break;
			}
		}
		if(repeated){
		  break;
		}
	}
	if(i+1 < arr.length){
	  return true;
	}
	else{
	  return false;
	}
}	

//--------------
function isNumber( numero,mensaje)
{
	largo = numero.length;
	
	for( i=0 ; i<largo ; i++ )
	{
		if( numero.charAt(i)<'0' || numero.charAt(i)>'9')
		{
			message(mensaje);
			return false;
		}
	}
	if( i == 0 )
	{
		message(mensaje);
		return false;
	}
	return true;
}

function isMoneyNumber( campo,mensaje )
{
	if(esEntero(campo.value) )
	{
		return true;
	}
	for( $i=campo.value.length,$j=$i-3 ; $i>=0 ; $i-=4,$j=$i-3 )
	{
		if( $j>0 && campo.value.charAt($j-1) != "." && campo.value.charAt($j-1) != "," )
		{
			message(mensaje);
			campo.focus();
			return false;
		}
		if(!esEntero(campo.value.substring($j,$i)))
		{
			message(mensaje);
			campo.focus();
			return false;
		}
	}
	return true;
	
}

function isFloatNumber( campo ,mensaje )
{
	punto = campo.value.indexOf(".");
	
	if( punto == -1)
	{
		punto = campo.value.indexOf(",");
	}
	
	if( punto>0 )
	{
		entera = campo.value.substring(0,punto);
		decimal = campo.value.substring(punto+1,campo.value.length);
	}
	else
	{
		entera = campo.value;
		decimal = '0';
	}
	
	if( !esEntero(entera) || !esEntero(decimal) )
	{
		message(mensaje);
		campo.focus();
		return false;
	}
	return true;
}

function longIsBetween( campo , min , max , mensaje)
{
	if( campo.value.length<min || campo.value.length>max )
	{
		message(mensaje);
		campo.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function notSelected(select,mensaje)
{
	if( select.selectedIndex==0 )
	{
		message(mensaje);
		select.focus();
		return true;
	}
	return false;
}

function isEmptyMultiSelect(select,mensaje)
{
	if( select.options[0].value == -1 )
	{
		message(mensaje);
		select.focus();
		return true;
	}
	return false;
}

function isValidDate(field,mensaje)
{
	year = field.value.substring(6,10);
	sep1 = field.value.charAt(2);
	month = field.value.substring(3,5);
	sep2 = field.value.charAt(5);
	day = field.value.substring(0,2);
	
	if( !isNumber(year,mensaje) /*|| !isNumber(month,mensaje) || !isNumber(day,mensaje)*/ )
	{
		field.focus();
		return false;
	}
	if( year<1900 || month<1 || month>12 || day<1 || day>31 || sep1!='-' || sep2!='-' )
	{
		message(mensaje);
		field.focus();
		return false;
	}	
	return true;
}

function isValidTime(campo,mensaje)
{
	hour = campo.value.substring(0,2);
	points = campo.value.substring(2,3);
	seconds = campo.value.substring(3,5);

	if( !isNumber(hour,mensaje) || !isNumber(seconds,mensaje))
	{
		return false;
	}
	else if(hour>23 || seconds>59 || points!=':')
	{
		message(mensaje);
		campo.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function isTimeBefore(time1,time2,mensaje)
{
	hour1 = time1.value.substring(0,2);
	hour2 = time2.value.substring(0,2);
	min1 = time1.value.substring(3,5);
	min2 = time2.value.substring(3,5);
	
	if( hour2<hour1 || (hour2==hour1 && min2<min1) )
	{
		message(mensaje);
		time1.focus();
		return false;
	}
	return true;
}

function minutesBetween(time1,time2)
{
	hour1 = time1.value.substring(0,2);
	hour2 = time2.value.substring(0,2);
	min1 = time1.value.substring(3,5);
	min2 = time2.value.substring(3,5);
	
	duration = (hour2 - hour1)*60;
	duration += (min2-min1);
	return duration;
}

function isBefore(date1,date2,mensaje)
{
	year1 = date1.value.substring(6,10);
	month1 = date1.value.substring(3,5);
	day1 = date1.value.substring(0,2);

	year2 = date2.value.substring(6,10);
	month2 = date2.value.substring(3,5);
	day2 = date2.value.substring(0,2);

	if( year1 > year2 || ( year1==year2 && (month1>month2 || (month1==month2 && day1>day2) ) ) )
	{
		message(mensaje);
		return false;
	}
	else
		return true;
}

/*
	Estas dos funciones manejan dos selects multiples para permitir intercambiar 
	campos entre ellos.
*/

function reorganiza(campo,borrar,texto)
{
        largo=campo.length;
        
        if(largo == 1)
        {
                campo.options[0].text = texto;
                campo.options[0].value= -1;
        }
        else
        {
                for(i=borrar;i<largo-1;i++)
                {
                        campo.options[i].text=campo.options[i+1].text;
                        campo.options[i].value=campo.options[i+1].value;
                }
                campo.options[i].text  = "";
                campo.options[i].value = "";
                campo.length=largo-1;
        }
        return;
}

function order(campo,borrar)
{
        largo=campo.length;
        
        for(i=borrar;i<largo-1;i++)
	{
		campo.options[i].text=campo.options[i+1].text;
        	campo.options[i].value=campo.options[i+1].value;
        }
        campo.options[i].text  = "";
        campo.options[i].value = "";
        campo.length=largo-1;
                
        return;
}

function order2(campo,borrar,textovacio,valorvacio)
{
        largo=campo.length;
        
        for(i=borrar;i<largo-1;i++)
	{
		campo.options[i].text=campo.options[i+1].text;
        	campo.options[i].value=campo.options[i+1].value;
        }
        campo.options[i].text  = "";
        campo.options[i].value = "";
        campo.length=largo-1;

	if( campo.length == 0 )
	{
		campo.length = 1
        	campo.options[i].text  = textovacio
	        campo.options[i].value = valorvacio
	}
	
        return;
}

function quita(campoQuita,campoPone,tipo,texto)
{
	cual = campoQuita.selectedIndex;
	
        if(campoQuita.options[0].value == -1)
        {
                message("No hay nada para "+tipo);
                return;
        }
        if(cual==-1)
        {
                message("Debe seleccionar primero cual "+tipo);
                return;
        }
        
        ultimo=campoPone.length;
        
        if(campoPone.options[0].value == -1)
        {
                ultimo=0;
        }

        campoPone.length = ultimo + 1;
        campoPone.options[ultimo].value = campoQuita.options[cual].value;
        campoPone.options[ultimo].text  = campoQuita.options[cual].text;

        reorganiza(campoQuita,cual,texto);
}

function isAlready(selectField,text,mensaje)
{
	for( i=0 ; i<selectField.length ; i++)
	{
		if( selectField.options[i].text == text )
		{
			message(mensaje);
			return true;
		}
	}
	return false;
}

function isAlreadyValue(selectField,text,mensaje)
{
	for( i=0 ; i<selectField.length ; i++)
	{
		if( selectField.options[i].value == text )
		{
			message(mensaje);
			return true;
		}
	}
	return false;
}

function mueveTexto(campoTexto,campoSelect,tipo,texto,textoEmpty,textoAlready,counter)
{
	//Mueve el texto del campo de texto al final del select
	if( tipo == 1 )
	{
		if( isEmpty(campoTexto,textoEmpty) )
		{
			return false;
		}
		if( isAlready(campoSelect,campoTexto.value,textoAlready) )
		{
			return false;
		}
        	ultimo=campoSelect.length;
        
        	if(campoSelect.options[0].value == -1)
        	{
                	ultimo=0;
        	}

	        campoSelect.length = ultimo + 1;
        	campoSelect.options[ultimo].value = campoTexto.value;
	        campoSelect.options[ultimo].text  = campoTexto.value;
	        campoTexto.focus();
	        campoTexto.select();
	}
	//Elimina el campo seleccionado del select
	else if( tipo == 2 )
	{
		cual = campoSelect.selectedIndex;

	        if(campoSelect.options[0].value == -1)
        	{
                	message("No hay nada para eliminar");
	                return false;
        	}
	        if(cual==-1)
        	{
                	message("Debe seleccionar primero cual eliminar");
	                return false;
        	}		
	        reorganiza(campoSelect,cual,texto);
	}
	return true;
}


function mueveTexto2(campoTexto,campoValue,campoSelect,tipo,texto,textoEmpty,textoEmpty2,textoAlready)
{
	//Mueve el texto del campo de texto al final del select
	if( tipo == 1 )
	{
		if( isEmpty(campoTexto,textoEmpty) )
		{
			return;
		}
		if( isEmpty(campoValue,textoEmpty2) )
		{
			return;
		}
		if( isAlreadyValue(campoSelect,campoValue.value,textoAlready) )
		{
			return;
		}
        	ultimo=campoSelect.length;
        
        	if(campoSelect.options[0].value == -1)
        	{
                	ultimo=0;
        	}

	        campoSelect.length = ultimo + 1;
        	campoSelect.options[ultimo].value = campoValue.value;
	        campoSelect.options[ultimo].text  = campoTexto.value;
	        campoTexto.focus();
	        campoTexto.select();
	}
	//Elimina el campo seleccionado del select
	else if( tipo == 2 )
	{
		cual = campoSelect.selectedIndex;

	        if(campoSelect.options[0].value == -1)
        	{
                	message("No hay nada para eliminar");
	                return;
        	}
	        if(cual==-1)
        	{
                	message("Debe seleccionar primero cual eliminar");
	                return;
        	}		
	        reorganiza(campoSelect,cual,texto);
	}
}


//fin de funciones para dos selects

function isEmail(campo,mensaje) {
  str = campo.value;
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  if(!r1.test(str) && r2.test(str))
  {
  	return true;
  }
  else
  {
  	message(mensaje);
  	campo.focus();
	return false;
  }
}

function help(accion) {	
	window.open(accion, "help", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes, width=450, height=500, top=50, left=300");	
}

function esEntero( numero )
{
	largo = numero.length;
	
	for( i=0 ; i<largo ; i++ )
	{
		if( numero.charAt(i)<'0' || numero.charAt(i)>'9')
		{
			return false;
		}
	}
	if( i == 0 )
	{
		return false;
	}
	return true;
}
