function ir_pagina( pagina ) {
	location.href = pagina;
}

function validar_eliminar( mensaje, pagina ) {
    if ( confirm( mensaje ) ) {
        location.href = pagina;
    }
}

function validar_obligatorio( objeto, mensaje ) {
	if( objeto.value == '' ) {
		alert( mensaje );
		objeto.focus();
		return true;
	}
}
function validar_numero( objeto, mensaje ) {
	if( isNaN(objeto.value) ) {
		alert( mensaje );
		objeto.focus();
		objeto.select();
		return true;
	}
}

function cambiar_color_on( id ){
	id.style.background = '#FFCC33';
}
function cambiar_color_off( id ){
	id.style.background = '#F0F0F0';
}

function cambiar_color_fila_on( id ){
	id.style.background = '#FFCC33';
}
function cambiar_color_fila_off( id ){
	id.style.background = '#F0F0F0';
}

function cambiar_color_txt_on( id, color ){
	id.style.background = color;
}
function cambiar_color_txt_off( id, color ){
	id.style.background = color;
}

function makeOptionList(objeto, name,value, sel) {
	var o=new Option( name,value);
	objeto.options[objeto.length]=o;
	if( sel == 1 )
		objeto.selectedIndex = objeto.length-1;
}

function cerrar_caja( obj ) {
	obj.style.visibility = "hidden";
}

function generar_caja( x, y, contenido, obj, obj_txt ) {
	obj.style.left = x;
	obj.style.top = y;
	obj.style.visibility = "visible";

	aux_contenido = "<div align=right><A HREF='#' onclick=\"cerrar_caja("+obj_txt+");\" title='Cerrar Ventana' class='link02'>X</A></div>" + contenido;

	obj.innerHTML = aux_contenido;
}

////////////////////////////////////////////////
function KeyIsLetra(evt)
{
var isNav = (navigator.appName.indexOf("Netscape") != -1)
var isIE = (navigator.appName.indexOf("Microsoft") != -1)

	if (isNav) {
		//if ( evt.which == 13 || evt.which == 8 || (evt.which >= 65 &&  evt.which <=90) || (evt.which >= 97 &&  evt.which <=122) || evt.which == 225 || evt.which == 233 || evt.which == 237 || evt.which == 243 || evt.which == 250 || evt.which == 193 || evt.which == 201 || evt.which == 205 || evt.which == 211 || evt.which == 218 )
		if ( evt.which == 209 || evt.which == 241 || evt.which == 13 || evt.which == 8 || (evt.which >= 65 &&  evt.which <=90) || (evt.which >= 97 &&  evt.which <=122) || evt.which == 32)
		return true;
	return false;
	}
	else if (isIE)
		{evt = window.event;
		//if ( evt.keyCode == 13 || evt.keyCode == 8 || (evt.keyCode >= 65 && evt.keyCode <= 90) || (evt.keyCode >= 97 && evt.keyCode <= 122) || evt.keyCode == 225 || evt.keyCode == 233 || evt.keyCode == 237 || evt.keyCode == 243 || evt.keyCode == 250 || evt.keyCode == 193 || evt.keyCode == 201 || evt.keyCode == 205 || evt.keyCode == 211 || evt.keyCode == 218 )
		if ( evt.keyCode == 209 || evt.keyCode == 241 || evt.keyCode == 13 || evt.keyCode == 8 || (evt.keyCode >= 65 && evt.keyCode <= 90) || (evt.keyCode >= 97 && evt.keyCode <= 122) || evt.keyCode == 32 )
			return true;
		return false;
		}
	else {
		alert("Su browser no es soportado por esta aplicación")
	}
	return false
}

////////////////////////////////////////////////
function KeyIsNumber(evt)
{
var isNav = (navigator.appName.indexOf("Netscape") != -1)
var isIE = (navigator.appName.indexOf("Microsoft") != -1)

	if (isNav) {
		if ( evt.which == 13 || evt.which == 44 || evt.which == 8 || (evt.which >= 48 &&  evt.which <=57) )
		return true;
	return false;
	}
	else if (isIE)
		{evt = window.event;
		if ( evt.keyCode == 13 || evt.keyCode == 44 || evt.keyCode == 8 || (evt.keyCode >= 48 && evt.keyCode <= 57) )
			return true;
		return false;
		}
	else {
		alert("Su browser no es soportado por esta aplicación")
	}
	return false
}

////////////////////////////////////////////////
function KeyIsRut(evt)
{
var isNav = (navigator.appName.indexOf("Netscape") != -1)
var isIE = (navigator.appName.indexOf("Microsoft") != -1)

	if (isNav) {
		if ( evt.which == 13 || evt.which == 44 || 
		evt.which == 8 || evt.which == 75 || evt.which == 107 || 
		(evt.which >= 48 &&  evt.which <=57))
		return true
	
	return false
	}
	else if (isIE)
		{evt = window.event
		if ( evt.keyCode == 13 || evt.keyCode == 44 || 
			evt.keyCode == 75 || evt.keyCode == 107 || 
			evt.keyCode == 8 || (evt.keyCode >= 48 && evt.keyCode <= 57) )
			return true
			
		return false
		}
	else {
		alert("Su browser no es soportado por esta aplicación")
	}
	return false
}

////////////////////////////////////////////////



function checkCDV( dvr, objeto )
{
  dv = dvr + "";
  if ( dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k'  && dv != 'K')
  {
     alert("Debe ingresar un digito verificador valido.");
     objeto.focus();
     objeto.select();
     return false;
  }
  return true;
}

function checkDV( crut, objeto)
{
  largo = crut.length;
  if ( largo < 2 )
  {
    alert("Debe ingresar el rut completo.");
    objeto.focus();
    objeto.select();
    return false;
  }

  if ( largo > 2 )
    rut = crut.substring(0, largo - 1);
  else
    rut = crut.charAt(0);
  dv = crut.charAt(largo-1);
  checkCDV( dv, objeto );

  if ( rut == null || dv == null )
      return 0;

  var dvr = '0';

  suma = 0;
  mul  = 2;

  for (i= rut.length -1 ; i >= 0; i--)
  {
    suma = suma + rut.charAt(i) * mul;
    if (mul == 7)
      mul = 2;
    else
      mul++;
  }


  res = suma % 11;
  if (res==1)
    dvr = 'k';
  else if (res==0)
    dvr = '0';
  else
  {
    dvi = 11-res;
    dvr = dvi + "";
  }

//  alert("rut: [" + rut + "]" );
//  alert("dvr=[" + dvr + "] dv=[" + dv + "]" );

  if ( dvr != dv.toLowerCase() )
  {
    alert("EL rut es incorrecto.");
    objeto.focus();
    objeto.value = "";
    return false;
  }

//      document.form1.c4.value = rut + "-" + dv;

      return true;

}

function checkRutField(texto, objeto){
      var tmpstr = "";
      for ( i=0; i < texto.length ; i++ )    {
        if ( texto.charAt(i) != ' ' && texto.charAt(i) != '.' && texto.charAt(i) != '-' && texto.charAt(i) != 'k') tmpstr = tmpstr + texto.charAt(i);
        if ( texto.charAt(i) == "k")
          tmpstr = tmpstr + "K";
      }
      texto = tmpstr;
      largo = texto.length;

      if ( largo < 2 )
      {
        alert("Debe ingresar el rut completo.");
        objeto.focus();
        objeto.select();
        return false;
      }


      for (i=0; i < largo ; i++ )
      {
        if ( texto.charAt(i) !="0" && texto.charAt(i) != "1" && texto.charAt(i) !="2" && texto.charAt(i) != "3" && texto.charAt(i) != "4" && texto.charAt(i) !="5" && texto.charAt(i) != "6" && texto.charAt(i) != "7" && texto.charAt(i) !="8" && texto.charAt(i) != "9" && texto.charAt(i) !="k" && texto.charAt(i) != "K" )
        {
          alert("El valor ingresado no corresponde a un R.U.T valido.");
          objeto.focus();
          objeto.select();
          return false;
        }
      }

      var invertido = "";

      for ( i=(largo-1),j=0; i>=0; i--,j++ )
        invertido = invertido + texto.charAt(i);


      var dtexto = "";

      dtexto = dtexto + invertido.charAt(0);
      //dtexto = dtexto + '-';
      cnt = 0;

      for ( i=1,j=2; i<largo; i++,j++ )
      {
        //alert("i=[" + i + "] j=[" + j +"]" );
        if ( cnt == 3 )
        {
         // dtexto = dtexto + '.';
          j++;
          dtexto = dtexto + invertido.charAt(i);
          cnt = 1;
        }
        else
        {
          dtexto = dtexto + invertido.charAt(i);
          cnt++;
        }
      }

      invertido = "";

      for ( i=(dtexto.length-1),j=0; i>=0; i--,j++ )
        invertido = invertido + dtexto.charAt(i);
      
      objeto.value = invertido;

      if ( checkDV(texto, objeto) )
        return true;
      return false;
}

if(navigator.appName == "Microsoft Internet Explorer") { 
function printURL(sHref) { 
  if(document.getElementById && document.all && sHref){ 
    if(!self.oPrintElm){ 
      var aHeads = document.getElementsByTagName('HEAD'); 
      if(!aHeads || !aHeads.length) 
        return false; 
      if(!self.oPrintElm) 
        self.oPrintElm = document.createElement('LINK'); 
      self.oPrintElm.rel = 'alternate'; 
      self.oPrintElm.media = 'print'; 
      aHeads[0].appendChild(self.oPrintElm); 
      } 
      self.oPrintElm.href = sHref; 
      self.focus(); 
      self.print(); 
      return true; 
    } 
  else 
	return false; 
  } 
} 

function imprimir(id, fecha){
	var url = "adm_cam.php?action=print&id="+id+"&fecha="+fecha;
	if(navigator.appName == "Microsoft Internet Explorer")
		printURL(url)
	else {
		var url = "OrderPrint?tm="+d.getTime();
		window.open( url, 'imprimr', "width=800, height=600, menubar=0, scrollbars=yes, location=0, resizable=1, status=1" );
	}
}

function validarEmail(valor){
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	strEmail = valor.value;
	
	if (strEmail.search(validRegExp) == -1) {
	    alert("La dirección de email es incorrecta o está mal escrita. Ingrésala nuevamente");
	    valor.focus();
	    return (false);
	}else
		return (true);
} 
