	function MM_openBrWindow(theURL,winName,features) { //v2.0
  		window.open(theURL,winName,features);
	}

	function MM_swapImgRestore() { //v3.0
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
	
	function MM_swapImage() { //v3.0
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}
	
	function MM_findObj(n, d) { //v4.0
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && document.getElementById) x=document.getElementById(n); return x;
	}
	
	function MM_showHideLayers() { //v3.0
	  var i,p,v,obj,args=MM_showHideLayers.arguments;
	  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
	    obj.visibility=v; }
	}
		
		
		function changeIn(campo) {
			campo.value = campo.value.toUpperCase();
		}
		
		function onKeyPress () {
		
		  	var keycode;
		  	if (window.event) keycode = window.event.keyCode;
		  	else return true;
		
		 	if (keycode == 13){
			    validaFrm(document.frm);
			    return false;
			}
		
			return true;
		}
		
		function f_digvercnt(cVar) {
			var nVar1=0;
			var nVar2=0;
			var i=0;
			var j=0;
			var z=0;
			
			var cVar1=cVar.toUpperCase();
			var cRet="?";
			
			cVar2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
			cVar3 = "1012131415161718192021232425262728293031323435363738";
			
			for(i=1; i<=4; i++) {
				for(j=1; j<=26; j++) {
					if (cVar1.substring(i-1,i)==cVar2.substring(j-1,j)) {	
						nVar1=nVar1+(parseInt(cVar3.substring((j*2)-2,(j*2)))*Math.pow(2,i-1));
						break;
					}
				}
			}
			
			for(i=5; i<=10; i++) {
				nVar1=nVar1+(parseInt(cVar1.substring(i-1,i))*Math.pow(2,i-1));
			}
			
			nVar2 = nVar1%11;
			if (nVar2==10) {
			   nVar2=0;
			}
			
			return nVar2;
		}
		
		function Trim(TRIM_VALUE){
			if(TRIM_VALUE.length < 1){
				return"";
			}
			TRIM_VALUE = RTrim(TRIM_VALUE);
			TRIM_VALUE = LTrim(TRIM_VALUE);
			if(TRIM_VALUE==""){
				return "";
			} else{
				return TRIM_VALUE;
			}
		} //End Function
		
		function RTrim(VALUE){
			var w_space = String.fromCharCode(32);
			var v_length = VALUE.length;
			var strTemp = "";
			if(v_length < 0){
				return"";
			}
			var iTemp = v_length -1;
			
			while(iTemp > -1){
				if(VALUE.charAt(iTemp) == w_space){
				} else{
					strTemp = VALUE.substring(0,iTemp +1);
					break;
				}
				iTemp = iTemp-1;
			
			} //End While
			return strTemp;
		
		} //End Function
		
		function LTrim(VALUE){
			var w_space = String.fromCharCode(32);
			if(v_length < 1){
				return"";
			}
			var v_length = VALUE.length;
			var strTemp = "";
			
			var iTemp = 0;
			
			while(iTemp < v_length){
				if(VALUE.charAt(iTemp) == w_space){
				} else{
					strTemp = VALUE.substring(iTemp,v_length);
					break;
				}
				iTemp = iTemp + 1;
			} //End While
			return strTemp;
		} //End Function
		
		function imprimirPagina() {
		  if (window.print)
		    window.print();
		  else
		    alert("Lo siento, pero a tu navegador no se le puede ordenar imprimir" +
		      " desde la web. Actualizate o hazlo desde los men£s");
		}
		

	    /** definimos las variables que almacenaran los componentes de la fecha actual */
	    ahora          = new Date();
	    ahoraDay    = ahora.getDate();
	    ahoraMonth = ahora.getMonth();
	    ahoraYear   = ahora.getYear();
	
	    /** Nestcape Navigator 4x cuenta el anyo a partir de 1900, por lo que es necesario
	 	sumarle esa cantidad para obtener el anyo actual adecuadamente **/
	 
	    if (ahoraYear < 2000) ahoraYear += 1900;
	
	    /** funcion para saber cuantos dias tiene cada mes */
	    
	    function cuantosDias(mes, anyo)
	    {
	        var cuantosDias = 31;
	        if (mes == "Abril" || mes == "Junio" || mes == "Septiembre" || mes == "Noviembre")
	      cuantosDias = 30;
	        if (mes == "Febrero" && (anyo/4) != Math.floor(anyo/4))
	      cuantosDias = 28;
	        if (mes == "Febrero" && (anyo/4) == Math.floor(anyo/4))
	      cuantosDias = 29;
	        return cuantosDias;
	    }
	
	    /** una vez que sabemos cuantos dias tiene cada mes
	 	a asignamos dinamicamente este numero al combo de los dias dependiendo 
	 	del mes que aparezca en el combo de los meses */
	 	
	    function asignaDias()
	    {
	        comboDias = document.form1.seleccionaDia;
	        comboMeses = document.form1.seleccionaMes;
	        comboAnyos = document.form1.seleccionaAno;
	
	        Month = comboMeses[comboMeses.selectedIndex].text;
	        Year = comboAnyos[comboAnyos.selectedIndex].text;
	
	        diasEnMes = cuantosDias(Month, Year);
	        diasAhora = comboDias.length;
	
	        if (diasAhora > diasEnMes)
	        {
	            for (i=0; i<(diasAhora-diasEnMes); i++)
	            {
	                comboDias.options[comboDias.options.length - 1] = null
	            }
	        }
	        if (diasEnMes > diasAhora)
	        {
	            for (i=0; i<(diasEnMes-diasAhora); i++)
	            {
	                sumaOpcion = new Option(comboDias.options.length + 1);
	                comboDias.options[comboDias.options.length]=sumaOpcion;
	            }
	        }
	        if (comboDias.selectedIndex < 0) 
	          comboDias.selectedIndex = 0;
	     }
	
	    /** ahora selecionamos en los combos los valores correspondientes 
	 	a la fecha actual del sistema */
	 	
	    function ponDia()
	    {
	        comboDias = eval("document.form1.seleccionaDia");
	        comboMeses = eval("document.form1.seleccionaMes");
	        comboAnyos = eval("document.form1.seleccionaAno");
	
	        comboAnyos[0].selected = true;
	        comboMeses[ahoraMonth].selected = true;
	  
	        asignaDias();
	
	        comboDias[ahoraDay-1].selected = true;
	    }
	    
		
	function cambiarHojaEstilos (idh,estilo) {
		if (document.getElementById && document.getElementById(idh) != null)
		node = document.getElementById(idh).className=estilo;
		else if (document.layers && document.layers[idh] != null)
		document.layers[idh].className=estilo;
		else if (document.all)
		document.all[idh].className=estilo;
	}
	
	
	
// ---------------------------------------------------------------------- //
//                                VARIABLES                               //
// ---------------------------------------------------------------------- //

// Esta variable indica si está bien dejar las casillas
// en blanco como regla general
var defaultEmptyOK = false

// listas de caracteres
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyzáéíóúñü"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZÁÉÍÓÚÑ"
var whitespace = " \t\n\r";

// caracteres admitidos en nos de telefono
var phoneChars = "()-+ ";

// ---------------------------------------------------------------------- //
//                     TEXTOS PARA LOS MENSAJES                           //
// ---------------------------------------------------------------------- //

// m abrevia "missing" (faltante)
var mMessage = "Error: no puede dejar este espacio vacio"

// p abrevia "prompt"
var pPrompt = "Error: ";
var pAlphanumeric = "ingrese un texto que contenga solo letras y/o numeros";
var pAlphabetic   = "ingrese un texto que contenga solo letras";
var pInteger = "ingrese un numero entero";
var pNumber = "ingrese un numero";
var pPhoneNumber = "ingrese un número de teléfono";
var pEmail = "ingrese una dirección de correo electrónico válida";
var pName = "ingrese un texto que contenga solo letras, numeros o espacios";
var pRut = "ingrese un rut valido";

// ---------------------------------------------------------------------- //
//                FUNCIONES PARA MANEJO DE ARREGLOS                       //
// ---------------------------------------------------------------------- //

// JavaScript 1.0 (Netscape 2.0) no tenia un constructor para arreglos,
// asi que ellos tenian que ser hechos a mano. Desde JavaScript 1.1 
// (Netscape 3.0) en adelante, las funciones de manejo de arreglos no
// son necesarias.

function makeArray(n) {
//*** BUG: If I put this line in, I get two error messages:
//(1) Window.length can't be set by assignment
//(2) daysInMonth has no property indexed by 4
//If I leave it out, the code works fine.
//   this.length = n;
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}

// ---------------------------------------------------------------------- //
//                  CODIGO PARA FUNCIONES BASICAS                         //
// ---------------------------------------------------------------------- //


// s es vacio
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

// s es vacio o solo caracteres de espacio
function isWhitespace (s)
{   var i;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        // si el caracter en que estoy no aparece en whitespace,
        // entonces retornar falso
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

// Quita todos los caracteres que que estan en "bag" del string "s" s.
function stripCharsInBag (s, bag)
{   var i;
    var returnString = "";

    // Buscar por el string, si el caracter no esta en "bag", 
    // agregarlo a returnString
    
    for (i = 0; i < s.length; i++)
    {   var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

// Lo contrario, quitar todos los caracteres que no estan en "bag" de "s"
function stripCharsNotInBag (s, bag)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }

    return returnString;
}

// Quitar todos los espacios en blanco de un string
function stripWhitespace (s)
{   return stripCharsInBag (s, whitespace)
}

// La rutina siguiente es para cubrir un bug en Netscape
// 2.0.2 - seria mejor usar indexOf, pero si se hace
// asi stripInitialWhitespace() no funcionaria

function charInString (c, s)
{   for (i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;
    }
    return false
}

// Quita todos los espacios que antecedan al string
function stripInitialWhitespace (s)
{   var i = 0;
    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    return s.substring (i, s.length);
}

// c es una letra del alfabeto espanol
function isLetter (c)
{
    return( ( uppercaseLetters.indexOf( c ) != -1 ) ||
            ( lowercaseLetters.indexOf( c ) != -1 ) )
}

// c es un digito
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

// c es letra o digito
function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}

// ---------------------------------------------------------------------- //
//                          NUMEROS                                       //
// ---------------------------------------------------------------------- //

// s es un numero entero (con o sin signo)
function isInteger (s)
{   var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if (!isDigit(c)) return false;
        } else { 
            if (!isDigit(c) && (c != "-") || (c == "+")) return false;
        }
    }
    return true;
}

// s es un numero (entero o flotante, con o sin signo)
function isN (s)
{   var i;
    var dotAppeared;
    dotAppeared = false;
    if (isEmpty(s)) 
       if (isN.arguments.length == 1) return defaultEmptyOK;
       else return (isN.arguments[1] == true);
    
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if ( c == "." ) {
                if( !dotAppeared )
                    dotAppeared = true;
                else
                    return false;
            } else     
                if (!isDigit(c)) return false;
        } else { 
            if ( c == "." ) {
                if( !dotAppeared )
                    dotAppeared = true;
                else
                    return false;
            } else     
               if (!isDigit(c) && (c != "-") || (c == "+")) return false;
        }
    }
    return true;
}

// ---------------------------------------------------------------------- //
//                        STRINGS SIMPLES                                 //
// ---------------------------------------------------------------------- //

// s tiene solo letras
function isAlphabetic (s)
{   var i;

    if (isEmpty(s)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);

        if (!isLetter(c))
        return false;
    }
    return true;
}


// s tiene solo letras y numeros
function isAlphanumeric (s)
{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    return true;
}

// s tiene solo letras, numeros o espacios en blanco
function isName (s)
{
    if (isEmpty(s)) 
       if (isName.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);
    
    return( isAlphanumeric( stripCharsInBag( s, whitespace ) ) );
}

function isX (s) {
	return true;
}

// ---------------------------------------------------------------------- //
//                           FONO o EMAIL                                 //
// ---------------------------------------------------------------------- //


// s es numero de telefono valido
function isPhoneNumber (s)
{   var modString;
    if (isEmpty(s)) 
       if (isPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isPhoneNumber.arguments[1] == true);
    modString = stripCharsInBag( s, phoneChars );
    return (isInteger(modString))
}

// s es una direccion de correo valida
function isEmail (s)
{
    if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

// ---------------------------------------------------------------------- //
//         				        DIA MES AÑO   					      	  //
// ---------------------------------------------------------------------- //
function validafecha(dd, mm, yy) {
var hoy = new Date();
var esteano = hoy.getYear();
var estemes = hoy.getMonth()+1;
var estedia = hoy.getDay();
var diames = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	
	if(((yy%4 == 0) && (yy%100 !=0) ) || (yy%400 == 0)) diames[1] = 29;
   
	if(yy > esteano){
		return "Año superior al actual(";
	} else {
		if((mm < 1) || (mm > 12)){
			return "Mes fuera de rango";
		} else {
			if(diames[mm-1] < dd){
				return "Dia incorrecto";
			}
		}
	} 
    if(yy == esteano){
	    if(mm > estemes){
			return "Mes superior al actual";
		} else { 
			if(dd<=estedia){
				return "";
			} else if(dd>estedia){
				return "Dia superior al actual";
			}
		}
	} else {
	    return ""; 
	}
}

function isFecha(dd, mm, yy) {
	var mensaje="";
	mensaje = validafecha(dd.value, mm.value, yy.value);
	if (mensaje=="") {
		return true;
	} else {
		warnInvalid(dd,mensaje);
		return false;
	}
}

// ---------------------------------------------------------------------- //
//          				        RUT         					      //
// ---------------------------------------------------------------------- //

function validarut(rut, dv) {
    var suma = 0;
    var mul = 2;
    var i = 0;
	var rutx = 0
	rutx = rut.value;
    for (i = rutx.length-1; i >= 0; i--) {
        suma = suma + rutx.charAt(i) * mul;
        mul = mul==7 ? 2 : mul+1;
    }
    var dvr = '' + (11 - suma % 11);
    if (dvr == '10')
        dvr = 'K';
    else if (dvr=='11')
        dvr = '0';
    if (dvr != UCase(dv.value)) {
        return false;
    } else {
        return true;
	}
} 

function UCase(StringToUpperCase) { 
	return StringToUpperCase.toUpperCase(); 
} 


function isRut(rut, dv) {
	if (validarut(rut, dv)) {
		return true;
	} else {
		warnInvalid(dv,pRut);
		return false;
	}
}

// ---------------------------------------------------------------------- //
//                  FUNCIONES PARA RECLAMARLE AL USUARIO                  //
// ---------------------------------------------------------------------- //

// pone el string s en la barra de estado
function statBar (s)
{   window.status = s;
}

// notificar que el campo theField esta vacio
function warnEmpty (theField)
{   theField.focus();
    alert(mMessage);
    statBar(mMessage);
    return false;
}

// notificar que el campo theField es invalido
function warnInvalid (theField, s)
{   theField.focus();
    theField.select();
    alert(s);
    statBar(pPrompt + s);
    return false;
}

// el corazon de todo: checkField
function checkField(theField, theFunction, emptyOK, s)
{   
    var msg;
    if (checkField.arguments.length < 3) emptyOK = defaultEmptyOK;
    if (checkField.arguments.length == 4 && s!="") {
        msg = s;
    } else {
        if( theFunction == isAlphabetic ) msg = pAlphabetic;
        if( theFunction == isAlphanumeric ) msg = pAlphanumeric;
        if( theFunction == isX ) msg = pAlphanumeric;
        if( theFunction == isInteger ) msg = pInteger;
        if( theFunction == isN ) msg = pNumber;
        if( theFunction == isEmail ) msg = pEmail;
        if( theFunction == isPhoneNumber ) msg = pPhoneNumber;
        if( theFunction == isName ) msg = pName;
    }
    
    if ((emptyOK == false) && (isEmpty(theField.value))) return true;

    if ((emptyOK == true) && (isEmpty(theField.value))) 
        return warnInvalid(theField,msg);
        //return warnEmpty(theField);

    if (theFunction(theField.value) == true) 
        return true;
    else
        return warnInvalid(theField,msg);

}




/* /solo digitos
function onlyDigits_antigua(e,decReq) {
		 var isIE = document.all?true:false;
		 var isNS = !document.all?true:false;
		 var key = (isIE) ? window.event.keyCode : e.which;
		 var obj = (isIE) ? event.srcElement : e.target;
		 var isN = (key > 47 && key < 58) ? true:false;
		 var menosOK = (key==45 && decReq=='menosOK' && (obj.value.indexOf("-")<0 || obj.value.length==0)) ? true:false;
		 var dotOK = (key==46 && (decReq=='decOK' || decReq=='menosOK') && (obj.value.indexOf(".")<0 || obj.value.length==0)) ? true:false;
		 e.which = (!isN && !dotOK && isNS && !menosOK) ? 0:key;
		 window.event.keyCode = (!isN && !dotOK && !menosOK && isIE) ? 0:key;
		 return (isN || dotOK);
}

function onlyDigits(e,decReq) {
		var isIE = document.all?true:false;
		var isNS = document.layers?true:false;
		var key = (isIE) ? window.event.keyCode : e.which;
		var obj = (isIE) ? event.srcElement : e.target;
		var isNum = (key > 47 && key < 58) ? true:false;
		var dotOK = (key==46 && decReq=='decOK' && (obj.value.indexOf(".")<0 || obj.value.length==0)) ? true:false;
		if(key < 32)  return true;
		return (isNum || dotOK);
}*/

function extractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}

function onlyDigits2(obj,e,decReq) {
	if (decReq=='decOK') {
		return extractNumber(obj,e, true,true);
	}
	if (decReq=='menosOK') {
		return extractNumber(obj,e, false,true);
	}
	return extractNumber(obj,e, false,false);
}
