function eliminabanner(bancod, tipo, nombre){
  if (confirm("Esta Seguro de Eliminar este Archivo: " + nombre + "?")) {
      location.href="eliminalo.php?bancod=" + bancod + "&tipo=" + tipo + "&nombre=" + nombre;
  }
}

function eliminaarchivo(arccod){
  if (confirm("Esta Seguro de Eliminar este Archivo:" + arccod + "?")) {
      location.href="elimina_archivo.php?arccod=" + arccod;
  }
}

function submitNav(num){
  document.navigation.navigTo.value = num;
  document.navigation.submit();
}

function validaparam(){

	var nomarchivo = document.f.archivo.value;
	var largo      = nomarchivo.length;
	var desde      = largo - 4;
	var extension  = nomarchivo.substring(desde,largo);

    if(desde > 0){
    	if (extension.toUpperCase() != ".JPG") { // &&  extension != ".JPG" && extension != ".jpeg" &&  extension != ".JPEG" && extension != ".gif" &&  extension != ".GIF") {
            alert("No es un archivo válido. Solo jpg")
           return;
    	}
    }
  	document.f.submit();
}

function borrarusuario(usu){
  if (confirm("Esta Seguro de Eliminar este Usuario:" + usu + "?")) {
      location.href="regrabar_usuario.php?kill=ok&rut=" + usu;
  }
}

function validausuRG() {
	if (document.frmusu.txtnomusu.value == "" || document.frmusu.txtnomusu.value == " "){
    		alert("Debe ingresar Nombre de Usuario");
		    return false;
	}

	if (document.frmusu.txtclausu.value == "" || document.frmusu.txtclausu.value == " "){
    		alert("Debe ingresar Clave");
    		return false;
	}

	if (document.frmusu.txtcla2usu.value == "" || document.frmusu.txtcla2usu.value == " "){
    		alert("Debe ingresar nuevamente la Clave");
    		return false;
	}

	if (document.frmusu.txtclausu.value == document.frmusu.txtcla2usu.value){
	}else{
    		alert("Claves ingresadas no coinciden, revise");
    		return false;
	}

	document.frmusu.submit();
}

function isNumeric(value){
  if (value == "")  { return false }
  if (value.charAt(0) == "-")
    start = 1;
  else
    start = 0;
  for (i=start; i<value.length; i++) {
    if (value.charAt(i) < "0") { return false; }
    if (value.charAt(i) > "9") { return false; }
    
    if (value.charAt(i) == ".") { return false; }
  }
  return true;
}

function validausu() {
	if (document.frmusu.txtrutusu.value == "" || document.frmusu.txtrutusu.value == " "){
    		alert("Debe ingresar Rut de Usuario");
    		return false;
	}

	if(!isNumeric(document.frmusu.txtrutusu.value)){
	   alert("Rut debe ser numérico");
	   return;
	}

	if (document.frmusu.txtnomusu.value == "" || document.frmusu.txtnomusu.value == " "){
    		alert("Debe ingresar Nombre de Usuario");
		return false;
	}

	if (document.frmusu.txtclausu.value == "" || document.frmusu.txtclausu.value == " "){
    		alert("Debe ingresar Clave");
    		return false;
	}

	if (document.frmusu.txtcla2usu.value == "" || document.frmusu.txtcla2usu.value == " "){
    		alert("Debe ingresar nuevamente la Clave");
    		return false;
	}

	if (document.frmusu.txtclausu.value == document.frmusu.txtcla2usu.value){
	}else{
    		alert("Claves ingresadas no coinciden, revise");
    		return false;
	}

	document.frmusu.submit();
}

function validapoll() {
	var marcado = "no";
	with (document.frmpoll){
		for ( var i = 0; i < radpol.length; i++ ) {
			if ( radpol[i].checked ) {
				document.frmpoll.submit();
				return true;
			}
		}
		if ( marcado == "no" ){
			window.alert("Debe Seleccionar una Alternativa." ) ;
		}
	}
}

function columna(codigo){

  xposition = 120;
  yposition = 200;

   if (confirm("Esta Seguro de poner este documento destacado en la columna del sitio web?\n\nRecuerde si ya existe un documento que se esté mostrando, será reemplazado por el que está seleccionado en este momento.")) {
      switch(navigator.appName) {
        case "Netscape":
          options="toolbar=0,status=0,menubar=0,scrollbars=0,resizable=1,location=0,directories=0,width=" + 5 + ",height=" + 2 + ",screenx=" + xposition + ",screeny=" + yposition;
          break;
        case "Microsoft Internet Explorer":
          options="toolbar=0,status=0,menubar=0,scrollbars=0,resizable=1,location=0,directories=0,width=" + 5 + ",height=" + 2 + ",left=" + xposition + ",top=" + yposition;
          break;
      }
      ventanita = "ponecolumna.php?codigo=" + codigo;
      subvent=window.open(ventanita, "", options);
   }

}

function buscar(){
	document.frmsearch.submit();
}

function validaopinion(){
  if (document.fo.txtnombre.value =="" || document.fo.txtnombre.value ==" " ){
      alert("Debe Ingresar su nombre.")
      return;
  }

  if (document.fo.txtmail.value == "" || document.fo.txtmail.value == " "){
       alert("Por favor, Debe Ingresar su Correo Electrónico")
       return;
  }

  correo = document.fo.txtmail.value;
  if (correo.indexOf("@") != -1){
      //return true;
  }else{
     alert('Debe escribir una dirección electrónica válida');
     return;
  }

  if (document.fo.txtopinion.value == "" || document.fo.txtopinion.value == " "){
      alert("Por favor, Ingresar su Opinión")
      return;
  }

  if (document.fo.txtcod.value == "" || document.fo.txtcod.value == " "){
      alert("Por favor, Ingresar Código de Seguridad")
      return;
  }

 document.fo.submit();
}

function mover(codigo){
  xposition = 120;
  yposition = 200;

  switch(navigator.appName) {
        case "Netscape":
          options="toolbar=0,status=0,menubar=0,scrollbars=0,resizable=1,location=0,directories=0,width=" + 620 + ",height=" + 310 + ",screenx=" + xposition + ",screeny=" + yposition;
          break;
        case "Microsoft Internet Explorer":
          options="toolbar=0,status=0,menubar=0,scrollbars=0,resizable=1,location=0,directories=0,width=" + 620 + ",height=" + 310 + ",left=" + xposition + ",top=" + yposition;
          break;
  }
  ventanita = "mover.php?codigo=" + codigo;
  subvent=window.open(ventanita, "", options);
}

function borrar(codigo,seccion){
  xposition = 120;
  yposition = 200;

   if (confirm("Esta Seguro de Eliminar este Item?\n\nRecuerde que puede perder información vinculada. Asegurese haciendo un respaldo antes desde Tablas Basicas - Respaldar Base de Datos")) {
      switch(navigator.appName) {
        case "Netscape":
          options="toolbar=0,status=0,menubar=0,scrollbars=0,resizable=1,location=0,directories=0,width=" + 765 + ",height=" + 260 + ",screenx=" + xposition + ",screeny=" + yposition;
          break;
        case "Microsoft Internet Explorer":
          options="toolbar=0,status=0,menubar=0,scrollbars=0,resizable=1,location=0,directories=0,width=" + 765 + ",height=" + 220 + ",left=" + xposition + ",top=" + yposition;
          break;
      }
      ventanita = "borrar.php?codigo=" + codigo + "&seccion=" + seccion;
      subvent=window.open(ventanita, "", options);
   }

}

function evaluarIngContacto(){
  if (document.ingcontacto.nombre.value =="" || document.ingcontacto.nombre.value ==" " ){
      alert("Debe Ingresar su nombre.")
      return;
  }

  if (document.ingcontacto.email.value == "" || document.ingcontacto.email.value == " "){
       alert("Por favor, Debe Ingresar su Correo Electrónico")
       return;
  }

  correo = document.ingcontacto.email.value;
  if (correo.indexOf("@") != -1){
      //return true;
  }else{
     alert('Debe escribir una dirección electrónica válida');
     return;
  }

  if (document.ingcontacto.mensaje.value == "" || document.ingcontacto.mensaje.value == " "){
      alert("Por favor, Ingresar el Mensaje de su Contacto")
      return;
 }

 document.ingcontacto.submit();
}

function deleteIt() {
   var contSearch = 1;
   var selIndex;
          
   // check to see if there is at least one item selected
   if (document.frmcombo.updownlist.selectedIndex == -1) {
       alert("Seleccione Documento a Eliminar");
       return true;
   }
   
   // loop through all selected items and delete them
   while (contSearch > 0) {
         selIndex = document.frmcombo.updownlist.selectedIndex;
         if (selIndex >= 0) {    
             document.frmcombo.updownlist.options[selIndex] = null;
             //--numItems_v2;
         }
	 else 
            contSearch = 0;
   }
   
   //cosecha mia
   var dato;
   var cadena;
   cadena = "";

   total = document.frmcombo.updownlist.length;

   for(x=0;x<total;x++){
       dato = document.frmcombo.updownlist[x].value;
       cadena = cadena + "&" + dato;
   }
   document.frmcombo.orden.value = cadena;
   return true;              
}
     
function moveOptionUp(obj) {
  for (i=0; i<obj.options.length; i++) {
       if (obj.options[i].selected) {
           if (i != 0 && !obj.options[i-1].selected) {
               swapOptions(obj,i,i-1);
               obj.options[i-1].selected = true;
           }
       }
  }
}

function moveOptionDown(obj) {
   for (i=obj.options.length-1; i>=0; i--) {
        if (obj.options[i].selected) {
            if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
                swapOptions(obj,i,i+1);
                obj.options[i+1].selected = true;
            }
        }
   }
}

function swapOptions(obj,i,j) {
   var o = obj.options;
   var i_selected = o[i].selected;
   var j_selected = o[j].selected;
   var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
   var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
   o[i] = temp2;
   o[j] = temp;
   o[i].selected = j_selected;
   o[j].selected = i_selected;
   
   //cosecha mia
   var dato;
   var cadena;
   cadena = "";

   total = document.frmcombo.updownlist.length;

   for(x=0;x<total;x++){
       dato = document.frmcombo.updownlist[x].value;
       cadena = cadena + "&" + dato  ;
   }

   document.frmcombo.orden.value = cadena;
}

function eliminaitemcombo(codigo) {
  xposition = 120;
  yposition = 200;

   if (confirm("Esta Seguro de Eliminar este Item del Combo?")) {
      switch(navigator.appName) {
        case "Netscape":
          options="toolbar=0,status=0,menubar=0,scrollbars=0,resizable=1,location=0,directories=0,width=" + 765 + ",height=" + 260 + ",screenx=" + xposition + ",screeny=" + yposition;
          break;
        case "Microsoft Internet Explorer":
          options="toolbar=0,status=0,menubar=0,scrollbars=0,resizable=1,location=0,directories=0,width=" + 765 + ",height=" + 220 + ",left=" + xposition + ",top=" + yposition;
          break;
      }
      ventanita = "eliminaitemcombo.php?codigo=" + codigo;
      subvent=window.open(ventanita, "", options);
   }
}

function agregaritemarreglocombo(cod,tit){
  xposition = 180;
  yposition = 200;

  switch(navigator.appName) {
    case "Netscape":
          options="toolbar=0,status=0,menubar=0,scrollbars=0,resizable=1,location=0,directories=0,width=" + 500 + ",height=" + 260 + ",screenx=" + xposition + ",screeny=" + yposition;
          break;
    case "Microsoft Internet Explorer":
          options="toolbar=0,status=0,menubar=0,scrollbars=0,resizable=1,location=0,directories=0,width=" + 500 + ",height=" + 220 + ",left=" + xposition + ",top=" + yposition;
          break;
  }
     ventanita = "agregar_item_arreglocombo.php?doccod=" + cod + "&docnom=" + escape(tit);
     subvent=window.open(ventanita, "", options);
}

function evaluarIng2(){
   if (document.frming.pais.value == "" || document.frming.pais.value == " "){
       alert("Por favor, Debe Ingresar su Pais")
       return;
   }

   if (document.frming.ciudad.value == "" || document.frming.ciudad.value == " "){
       alert("Por favor, Debe Ingresar Ciudad")
       return;
   }

   if (document.frming.comuna.value == "" || document.frming.comuna.value == " "){
       alert("Por favor, Debe Ingresar Comuna")
       return;
   }

   if (document.frming.direccion.value == "" || document.frming.direccion.value == " "){
       alert("Por favor, Debe Ingresar Dirección")
       return;
   }

  if (document.frming.nombre.value =="" || document.frming.nombre.value ==" " ){
      alert("Debe Ingresar su nombre.")
      return;
  }

  if (document.frming.labor.value =="" || document.frming.labor.value ==" " ){
      alert("Debe Ingresar su Labor o Especialidad")
      return;
  }

  if (document.frming.fono1.value == "" || document.frming.fono1.value == " " || document.frming.fono1.value == "0"){
      alert("Por favor, Debe Ingresar Teléfono")
      return;
  }
  /*
  if (document.frming.clave1.value == "" || document.frming.clave1.value == " " || document.frming.clave1.value == 0) {
      alert("Atención, Contraseña no puede ser vacia.");
      return;
  }

  if (document.frming.clave2.value == "" || document.frming.clave2.value == " " || document.frming.clave2.value == 0) {
      alert("Atención, Confirmación de Contraseña no puede ser vacia. Revise.");
      return;
  }

  if (document.frming.clave1.value != document.frming.clave2.value) {
      alert("Atención, Las Contraseñas no coinciden. Revise.");
      return;
  }

  if (document.frming.recuerdo.value == "" || document.frming.recuerdo.value == " "){
      alert("Por favor, Debe Ingresar Texto Recordatorio de Contraseña")
      return;
 }
 */

 document.frming.submit();
}

function evaluarIng(){
   if (document.frming.pais.value == "" || document.frming.pais.value == " "){
       alert("Por favor, Debe Ingresar su Pais")
       return;
   }

   if (document.frming.ciudad.value == "" || document.frming.ciudad.value == " "){
       alert("Por favor, Debe Ingresar Ciudad")
       return;
   }

   if (document.frming.comuna.value == "" || document.frming.comuna.value == " "){
       alert("Por favor, Debe Ingresar Comuna")
       return;
   }

   if (document.frming.direccion.value == "" || document.frming.direccion.value == " "){
       alert("Por favor, Debe Ingresar Dirección")
       return;
   }

   if (document.frming.email.value == "" || document.frming.email.value == " "){
       alert("Por favor, Debe Ingresar su Correo Electrónico")
       return;
  }

  if (document.frming.email2.value == "" || document.frming.email2.value == " "){
      alert("Por favor, Debe Reingresar su Correo Electrónico")
      return;
  }

  correo = document.frming.email.value;
  if (correo.indexOf("@") != -1){
      //return true;
  }else{
     alert('Debe escribir una dirección electrónica válida');
     return;
  }

  correo = document.frming.email2.value;
  if (correo.indexOf("@") != -1){
      //return true;
  }else{
      alert('Debe reingresar una dirección electrónica válida');
      return;
  }

  if (document.frming.email.value !=  document.frming.email2.value){
      alert("Los Correos Electrónicos Ingresados No Coinciden. Revise por favor.")
      return;
  }

  if (document.frming.nombre.value =="" || document.frming.nombre.value ==" " ){
      alert("Debe Ingresar su nombre.")
      return;
  }

  if (document.frming.labor.value =="" || document.frming.labor.value ==" " ){
      alert("Debe Ingresar su Labor o Especialidad")
      return;
  }

  if (document.frming.fono1.value == "" || document.frming.fono1.value == " " || document.frming.fono1.value == "0"){
      alert("Por favor, Debe Ingresar Teléfono")
      return;
  }

  if (document.frming.clave1.value == "" || document.frming.clave1.value == " " || document.frming.clave1.value == 0) {
      alert("Atención, Contraseña no puede ser vacia.");
      return;
  }

  if (document.frming.clave2.value == "" || document.frming.clave2.value == " " || document.frming.clave2.value == 0) {
      alert("Atención, Confirmación de Contraseña no puede ser vacia. Revise.");
      return;
  }

  if (document.frming.clave1.value != document.frming.clave2.value) {
      alert("Atención, Las Contraseñas no coinciden. Revise.");
      return;
  }

  if (document.frming.recuerdo.value == "" || document.frming.recuerdo.value == " "){
      alert("Por favor, Debe Ingresar Texto Recordatorio de Contraseña")
      return;
 }

 document.frming.submit();
}

function validaLogin(){
  if(document.frlog.mail.value == ""){
     alert("Debe Ingresar Mail para Ingresar");
     return false;
  }

  if(document.frlog.pass.value == ""){
     alert("Debe Ingresar Contraseña para Ingresar");
     return false;
  }

  document.frlog.submit();
}

function ValidaBA(){
  if(document.frba1.search.value == ""){
     alert("Debe Ingresar Texto para Realizar la Búsqueda");
     return false;
  }
  document.frba1.submit();
}

function pidemail() {
  xposition = 180;
  yposition = 200;

  switch(navigator.appName) {
    case "Netscape":
          options="toolbar=0,status=0,menubar=0,scrollbars=0,resizable=1,location=0,directories=0,width=" + 500 + ",height=" + 260 + ",screenx=" + xposition + ",screeny=" + yposition;
          break;
    case "Microsoft Internet Explorer":
          options="toolbar=0,status=0,menubar=0,scrollbars=0,resizable=1,location=0,directories=0,width=" + 500 + ",height=" + 220 + ",left=" + xposition + ",top=" + yposition;
          break;
  }
     ventanita = "pidemail.php";
     subvent=window.open(ventanita, "", options);
}

function imprimir(docto) {
  xposition = 120;
  yposition = 200;

      switch(navigator.appName) {
        case "Netscape":
          options="toolbar=0,status=0,menubar=0,scrollbars=1,resizable=1,location=0,directories=0,width=" + 765 + ",height=" + 260 + ",screenx=" + xposition + ",screeny=" + yposition;
          break;
        case "Microsoft Internet Explorer":
          options="toolbar=0,status=0,menubar=0,scrollbars=1,resizable=1,location=0,directories=0,width=" + 765 + ",height=" + 220 + ",left=" + xposition + ",top=" + yposition;
          break;
      }
      ventanita = "imprimir.php?docto=" + escape(docto);
      subvent=window.open(ventanita, "", options);
}

function imprimirreceta(){
     window.print();
}
