function eliminarcombo(codigo){
   if (confirm("Esta Seguro de Eliminar este Combo?")) {
    location.href="eliminacombo.php?cod=" + codigo;
   }

}

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

   if (confirm("Esta Seguro de Eliminar este Usuario?")) {
      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 = "borrarusuario.php?codigo=" + codigo;
      subvent=window.open(ventanita, "", options);
   }

}

function traduce(){
    location.href="http://translate.google.com/translate?u=http://www.psikis.cl/&langpair=es|en&ie=UTF8";
}

function top10(){
  xposition = 180;
  yposition = 100;

  switch(navigator.appName) {
    case "Netscape":
          options="toolbar=0,status=0,menubar=0,scrollbars=1,resizable=1,location=0,directories=0,width=" + 500 + ",height=" + 550 + ",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=" + 500 + ",height=" + 550 + ",left=" + xposition + ",top=" + yposition;
          break;
  }
     ventanita = "top.php";
     subvent=window.open(ventanita, "", options);
}

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;
 }

   if (document.ingcontacto.txtcod.value == ""){
       alert("Por Favor Ingrese Código de 4 caracteres\nRespete Mayúsculas y Minúsculas");
       exit;
   }

 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;
 }


   if (document.frming.txtcod.value == ""){
       alert("Por Favor Ingrese Código de 4 caracteres\nRespete Mayúsculas y Minúsculas");
       exit;
   }

 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();
}
