﻿function OpenGlobalPopup(url,width,height,name,fullscreen)
{
    //trato de llamar al constructor
    try
    {
        var ObjPopup = new top.GlobalPopUpHandler(name,openPopUp(url,width,height,name,fullscreen)) ;
        ObjPopup.setHandler()
        
        objHand = ObjPopup.getHandler();
        objHand.focus();
        return  ObjPopup;    
         
    }
    catch(ex)
    {
        try
        {
            var ObjPopup = new GlobalPopUpHandler(name,openPopUp(url,width,height,name,fullscreen)) ;
            objHand = ObjPopup.getHandler();
            objHand.focus();
            return  ObjPopup;    
         }
         catch(ex){openPopUp(url,width,height,name,fullscreen)}
        
    }
}

function CloseGlobalPopup(name)
{
    
    var ObjPopup = new top.GlobalPopUpHandler(name,null) ;
    ObjPopup.closePopUp()
    return ;     
    
}

/*
    CREATED BY:     Agustín SERRA
    CREATION DATE:  07/09/2007
    DESCRIPTION:    Permite la apertura de PopUps con parámetros opcionales.
*/
function openPopUp (url)
{
    
    var arg1 = openPopUp.arguments[1] || 800;
    var arg2 = openPopUp.arguments[2] || 520;
    var arg3 = openPopUp.arguments[3] || null;
    var arg4 = openPopUp.arguments[4] || 0;

    var width           = (arg1 != 0    && arg1 != null && arg1 != '')  ? arg1 : 800; //530;
    var height          = (arg2 != 0    && arg2 != null && arg2 != '')  ? arg2 : 520; //300;
    var title           = (arg3 != 0    && arg3 != '')                  ? arg3 : null;
    var fullscreen      = (arg4 != null && arg4 != '')                  ? arg4 : 0;

    var leftposition    = 0;
    var topposition     = 0;

    if (fullscreen == 1) {
        width = screen.width;
        height = screen.height;
    } else {
        leftposition = (screen.width) ? (screen.width - width) / 2 : 0;
        topposition = (screen.height) ? (screen.height - height) / 2 : 0;
    }

    var style = 'width = ' + width + ', height = ' + height + ', ' +
                'top = ' + topposition + ' , left = ' + leftposition + ', ' +
                'menubar = no, toolbar = no, ' +
                'status = yes, location = no, ' +
                'scrollbars = yes, resizable = yes';

    
   
    
    return window.open(url, title, style);
     
}

/*
    CREATED BY:     Agustín SERRA
    CREATION DATE:  30/10/2007
    DESCRIPTION:    Permite cancelar las teclas que se oprimen en un control por medio de su código.
                    Por ejemplo: cancelPressEnter(event, 13) no permite que se oprima Enter.
*/
function cancelKeysPress(e)
{
    var keynum;
    var resp = true;

    if(window.event) // IE
    {
        keynum = e.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which;
    }

    
    for (var key = 1 ; key < cancelKeysPress.arguments.length ; key++)
    {
        if(keynum == cancelKeysPress.arguments[key]) resp = false;
    }
    
    return resp;
}

function validateAmount(source, arguments)
{
	var numAux;
	var decimales=new Array();
	
	//separa decimales
	decimales=arguments.Value.split(dec);
	
	//si tiene mas de un separador decimal, entonces es incorrecto
	if (decimales.length>2)
	{
		arguments.IsValid = false;
		return;
	}
	else
	{
		if (decimales.length==2)
		{
			//verifica que la parte decimal sea numérica
			numAux=parseInt(decimales[1]);
			if (numAux=='NaN' || numAux!=decimales[1])
			{
				arguments.IsValid =  false;
				return;
			}
		}
	}
	
	var miles=new Array();
	miles=decimales[0].split(thousand);
	
	switch (miles.length)
	{
		case 0:
			arguments.IsValid =  false;
			return;
		case 1:
			numAux=parseInt(miles[0]);
			if (numAux=='NaN' || numAux!=miles[0])
			{
				arguments.IsValid =  false;
				return;
			}
			break;
		default:
			for (i=0; i<miles.length;i++)
			{
				numAux=parseInt(miles[i]);
				if (numAux=='NaN' || numAux!=miles[i])
				{
					//no es número
					arguments.IsValid =  false;
					return;
				}
				else
				{
					if (miles[i].length!=3)
					{
						if (i==0)
						{
							if (miles[i].length>3)
							{
								arguments.IsValid =  false;
								return;
							}
						}
						else
						{
							arguments.IsValid =  false;
							return;
						}
					}
				}
			}
			break;
	}

	arguments.IsValid =  true;
}
/*
Asignado Por: Patricio Milan
Realizado Por: Javier Borrás
Fecha: 11/02/2008
Funcionalidad del tooltip personalizable
-> para implementar se debe agregar el siguiente código en
el body de la página:
<span id="toolTipBox" width="200"></span> 
Y en el control que se quiera utilizar el tooltip:
onMouseOver="toolTip('Texto en Formato HTML que se va a mostrar',this)"
*/

function toolTip(text,me) { 
       theObj=me; 
       theObj.onmousemove=updatePos; 
       document.getElementById('toolTipBox').innerHTML=text; 
       document.getElementById('toolTipBox').style.display="block"; 
       window.onscroll=updatePos; 
} 
function updatePos() { 
       var ev=arguments[0]?arguments[0]:event; 
       var x=ev.clientX; 
       var y=ev.clientY; 
       diffX=24; 
       diffY=0; 
       document.getElementById('toolTipBox').style.top  = y-2+diffY+document.body.scrollTop+ "px"; 
       document.getElementById('toolTipBox').style.left = x-2+diffX+document.body.scrollLeft+"px"; 
       theObj.onmouseout=hideMe; 
} 
  
function hideMe() { 
       document.getElementById('toolTipBox').style.display="none";
   }


   function jsInicio() {

       var nombre = document.forms[0].txtNombres;
       if (nombre) {
           if (nombre.addEventListener) nombre.addEventListener('keypress', jsTeclaPulsada, false);
           else if (nombre.attachEvent) nombre.attachEvent('onkeypress', jsTeclaPulsada);
           //Función que se ejecuta cuando pulsamos una tecla sobre el campo1
           else nombre.onkeypress = jsTeclaPulsada;
       }

       var apellido = document.forms[0].txtApellidos;
       if (apellido) {
           if (apellido.addEventListener) apellido.addEventListener('keypress', jsTeclaPulsada, false);
           else if (apellido.attachEvent) apellido.attachEvent('onkeypress', jsTeclaPulsada);
           else apellido.onkeypress = jsTeclaPulsada;
       }

       var rut = document.forms[0].txtRUT;
       if (rut) {
           if (rut.addEventListener) rut.addEventListener('keypress', jsTeclaPulsadaRUT, false);
           else if (rut.attachEvent) rut.attachEvent('onkeypress', jsTeclaPulsadaRUT);
           else rut.onkeypress = jsTeclaPulsadaRUT;
       }
       
       var identificador = document.forms[0].txtIdenficador;
       if (identificador) {
            if (identificador.addEventListener) identificador.addEventListener('keypress', jsTeclaPulsadaID, false);
            else if (identificador.attachEvent) identificador.attachEvent('onkeypress', jsTeclaPulsadaID);
            //Función que se ejecuta cuando pulsamos una tecla sobre el campo1
            else identificador.onkeypress = jsTeclaPulsadaID;
       }


       var rutDV = document.forms[0].txtRutDV;
       if (rutDV) {
           if (rutDV.addEventListener) rutDV.addEventListener('keypress', jsTeclaPulsadaRUTdv, false);
           else if (rutDV.attachEvent) rutDV.attachEvent('onkeypress', jsTeclaPulsadaRUTdv);
           else rutDV.onkeypress = jsTeclaPulsadaRUTdv;
       }
   }
   
   function jsTeclaPulsada(evt) {
       var keyCode = 0;
       if (evt.keyCode == 0) { keyCode = evt.which } //Para Mozilla Firefox
       else { keyCode = evt.keyCode }

       if (keyCode == 8 || keyCode == 39 || keyCode == 45) return true; //Tecla de retroceso (para poder borrar)
       patron = /[a-zA-Z ñÑ-áéíóúÁÉÍÓÚ]/;
       te = String.fromCharCode(keyCode);
       if (patron.test(te)) {
           return patron.test(te);
       }
       else {
           if (evt && evt.stopPropagation) evt.stopPropagation();
           else if (window.event) {
               window.event.cancelBubble = true;
               window.event.returnValue = false;
           }
           if (evt && evt.preventDefault) evt.preventDefault(); //Para Mozilla Firefox
           return false;
       }
   }
   function jsTeclaPulsadaID(evt) {
       var keyCode = 0;
       if (evt.keyCode == 0) { keyCode = evt.which } //Para Mozilla Firefox
       else { keyCode = evt.keyCode }

       if (keyCode == 8 ) return true; //Tecla de retroceso (para poder borrar)
       patron = /[a-zA-Z0-9]/;
       te = String.fromCharCode(keyCode);
       if (patron.test(te)) {
           return patron.test(te);
       }
       else {
           if (evt && evt.stopPropagation) evt.stopPropagation();
           else if (window.event) {
               window.event.cancelBubble = true;
               window.event.returnValue = false;
           }
           if (evt && evt.preventDefault) evt.preventDefault(); //Para Mozilla Firefox
           return false;
       }
   }
  
   function jsTeclaPulsadaRUT(evt) {
       var keyCode = 0;
       if (evt.keyCode == 0) { keyCode = evt.which } //Para Mozilla Firefox
       else { keyCode = evt.keyCode }

       if (keyCode == 8) return true; //Tecla de retroceso (para poder borrar)
       patron = /[0-9]/;
       te = String.fromCharCode(keyCode);
       if (patron.test(te)) {
           return patron.test(te);
       }
       else {
           if (evt && evt.stopPropagation) evt.stopPropagation();
           else if (window.event) {
               window.event.cancelBubble = true;
               window.event.returnValue = false;
           }
           if (evt && evt.preventDefault) evt.preventDefault(); //Para Mozilla Firefox
           return false;
       }
   }

   function jsTeclaPulsadaRUTdv(evt) {
       var keyCode = 0;
       if (evt.keyCode == 0) { keyCode = evt.which } //Para Mozilla Firefox
       else { keyCode = evt.keyCode }

       if (keyCode == 8) return true; //Tecla de retroceso (para poder borrar)
       patron = /[0-9Kk]/;
       te = String.fromCharCode(keyCode);

       if (patron.test(te)) {
           return patron.test(te);
       }
       else {
           if (evt && evt.stopPropagation) evt.stopPropagation();
           else if (window.event) {
               window.event.cancelBubble = true;
               window.event.returnValue = false;
           }
           if (evt && evt.preventDefault) evt.preventDefault(); //Para Mozilla Firefox
           return false;
       }
   }


   function crearStrAdvertencia(msg) {
       return sImagenAdvertencia + '<span class="formCamposError"" id=""error""> ' + msg + ' </span><br>'
   }

   function ocultarItem(item) {
       document.getElementById(item).innerHTML = ''
       document.getElementById(item).style.display = 'none'
   }



   function validarEmailAvisos(source, arguments) 
   {   var valor = document.forms[0].txtEmail.value;
       if (!(/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/.test(valor))) 
       { 
           arguments.IsValid = false;
       }
       else {
                arguments.IsValid = true;
            }
        }

   function validarEmailAvisos01(source, arguments) {
       var valor = document.forms[0].txtNotificaciones.value;
            if (!(/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/.test(valor))) {
                arguments.IsValid = false;
            }
            else {
                arguments.IsValid = true;
            }
        }

    function validarnombre(source, arguments) {
        var valor = document.forms[0].txtNombres.value;
        //alert((/[a-zA-Z ñÑ-áéíóúÁÉÍÓÚ´-]$/.test(valor)));
        if (!(/[a-zA-Z ñÑ-áéíóúÁÉÍÓÚ´-]$/.test(valor))) {
            //alert("1");
                arguments.IsValid = false;
            }
            else {
             //   alert("2");
                arguments.IsValid = true;
            }
        }
        
  function validarApellido(source, arguments) {
      var valor = document.forms[0].txtApellidos.value;
       // alert((/[a-zA-Z ñÑ-áéíóúÁÉÍÓÚ´-]$/.test(valor)));
        if (!(/[a-zA-Z ñÑ-áéíóúÁÉÍÓÚ´-]$/.test(valor))) {
         //   alert("1");
                arguments.IsValid = false;
            }
            else {
           //     alert("2");
                arguments.IsValid = true;
            }
        }
        
function validarIdentificador(source, arguments) {
    var valor = document.forms[0].txtIdenficador.value;
       // alert((/[a-zA-Z ñÑ-áéíóúÁÉÍÓÚ´-]$/.test(valor)));
    if (!(/[a-zA-Z0-9]$/.test(valor))) {
         //   alert("1");
                arguments.IsValid = false;
            }
            else {
           //     alert("2");
                arguments.IsValid = true;
            }
        }

        function validarRUT(source, arguments) {
            var valor = document.forms[0].txtRUT.value;
            // alert((/[a-zA-Z ñÑ-áéíóúÁÉÍÓÚ´-]$/.test(valor)));
            if (!(/[0-9]$/.test(valor))) {
                //   alert("1");
                arguments.IsValid = false;
            }
            else {
                //     alert("2");
                arguments.IsValid = true;
            }
        }

