//Agrega varios transportistas al grupo
function trans_add() {
  var veri = 0;
  for (var i=0; i < document.form1.elements.length; i++) {
       if (document.form1.elements[i].type == 'checkbox') {
           if (document.form1.elements[i].checked == true)
             veri++;
     }
   }
  // if (veri != 0) {
       var agree=confirm("Si das click en ACEPTAR, los transportistas seleccionados se agregaran/quitaran al grupo.");
       if (agree) {
	       document.form1.method = "post";
	       document.form1.action = "trans_add.php";
		   document.form1.submit(); //return true ;
	  } else {
	     return false ;
	  }
   /*
   } else {
     alert("Selecciona un transportista");
   }
   */
}
//MARCA TODOS LOS REGISTROS A MOVER O A ELIMINAR
function marca_todos() {
  with (document.form1) {
    for (var i=0; i < elements.length; i++) {
     if (elements[i].type == 'checkbox') {
         if (selCheck.checked == true)
             elements[i].checked = true;
         else 
             elements[i].checked = false;
     }
    }
  }
}

//~~~~~~~Completar campos select en busca_fletes.php
function com_busca_fletes() {
  var success1 = -1;
  var success2 = -1;
  var success5 = -1;
  var success6 = -1;
  
  document.form1.tipo.value            = document.form1.tipoB.value;
  document.form1.detalle.value         = document.form1.detalleB.value;
  document.form1.estadoO.value         = document.form1.estadoOB.value;
  document.form1.estadoD.value         = document.form1.estadoDB.value;
  
  for (var i = 0; i < document.form1.tipo.length; i++) {
    if (document.form1.tipo.options[i].value == document.form1.tipoB.value)
      success1 = [i];
  } 
  for (var i = 0; i < document.form1.detalle.length; i++) {
    if (document.form1.detalle.options[i].value == document.form1.detalleB.value)
      success2 = [i];
  } 
  for (var i = 0; i < document.form1.estadoO.length; i++) {
    if (document.form1.estadoO.options[i].value == document.form1.estadoOB.value)
      success5 = [i];
  } 
  for (var i = 0; i < document.form1.estadoD.length; i++) {
    if (document.form1.estadoD.options[i].value == document.form1.estadoDB.value)
      success6 = [i];
  } 
 
  document.form1.tipo.selectedIndex            = success1;
  document.form1.detalle.selectedIndex         = success2;
  document.form1.estadoO.selectedIndex         = success5;
  document.form1.estadoD.selectedIndex         = success6;
  //
}
//~~~~~~~Completar campos select en busca_carga.php
function com_busca_carga() {
  var success1 = -1;
  var success2 = -1;
  var success5 = -1;
  var success6 = -1;
  
  document.form1.tipo.value            = document.form1.tipoB.value;
  document.form1.detalle.value         = document.form1.detalleB.value;
  document.form1.estadoO.value         = document.form1.estadoOB.value;
  document.form1.estadoD.value         = document.form1.estadoDB.value;
  
  for (var i = 0; i < document.form1.tipo.length; i++) {
    if (document.form1.tipo.options[i].value == document.form1.tipoB.value)
      success1 = [i];
  } 
  for (var i = 0; i < document.form1.detalle.length; i++) {
    if (document.form1.detalle.options[i].value == document.form1.detalleB.value)
      success2 = [i];
  } 
  for (var i = 0; i < document.form1.estadoO.length; i++) {
    if (document.form1.estadoO.options[i].value == document.form1.estadoOB.value)
      success5 = [i];
  } 
  for (var i = 0; i < document.form1.estadoD.length; i++) {
    if (document.form1.estadoD.options[i].value == document.form1.estadoDB.value)
      success6 = [i];
  } 
 
  document.form1.tipo.selectedIndex            = success1;
  document.form1.detalle.selectedIndex         = success2;
  document.form1.estadoO.selectedIndex         = success5;
  document.form1.estadoD.selectedIndex         = success6;
  //
}
//~~~~~~~Completar campos select en Flete_edit.php
function com_flete() {
  var success1 = -1;
  var success2 = -1;
  var success3 = -1;
  var success4 = -1;
  var success5 = -1;
  var success6 = -1;
  
  document.form1.tipo.value            = document.form1.tipoB.value;
  document.form1.detalle.value         = document.form1.detalleB.value;
  //document.form1.status.value          = document.form1.statusB.value;
  document.form1.precio_concepto.value = document.form1.precio_conceptoB.value;
  document.form1.estadoO.value         = document.form1.estadoOB.value;
  document.form1.estadoD.value         = document.form1.estadoDB.value;
  
  for (var i = 0; i < document.form1.tipo.length; i++) {
    if (document.form1.tipo.options[i].value == document.form1.tipoB.value)
      success1 = [i];
  } 
  /*
  for (var i = 0; i < document.form1.status.length; i++) {
    if (document.form1.status.options[i].value == document.form1.statusB.value)
      success3 = [i];
  }
  */
  for (var i = 0; i < document.form1.detalle.length; i++) {
    if (document.form1.detalle.options[i].value == document.form1.detalleB.value)
      success2 = [i];
  } 
  for (var i = 0; i < document.form1.precio_concepto.length; i++) {
    if (document.form1.precio_concepto.options[i].value == document.form1.precio_conceptoB.value)
      success4 = [i];
  } 
  for (var i = 0; i < document.form1.estadoO.length; i++) {
    if (document.form1.estadoO.options[i].value == document.form1.estadoOB.value)
      success5 = [i];
  } 
  for (var i = 0; i < document.form1.estadoD.length; i++) {
    if (document.form1.estadoD.options[i].value == document.form1.estadoDB.value)
      success6 = [i];
  } 
  //
  if (document.form1.cap_dispB.value == 0)
      document.form1.cap_dispo[0].checked = true;
  else 
      document.form1.cap_dispo[1].checked = true;
  //
 
  document.form1.tipo.selectedIndex            = success1;
  document.form1.detalle.selectedIndex         = success2;
  //document.form1.status.selectedIndex          = success3;
  document.form1.precio_concepto.selectedIndex = success4;
  document.form1.estadoO.selectedIndex         = success5;
  document.form1.estadoD.selectedIndex         = success6;
  //Si existe viaje. llena componente de puntualidad
 if (document.form1.idv.value) {
	  var success7 = -1;
	  document.form1.puntualidad.value = document.form1.puntualidadB.value;
      
	  for (var i = 0; i < document.form1.puntualidad.length; i++) {
		   if (document.form1.puntualidad.options[i].value == document.form1.puntualidadB.value)
		       success7 = [i];
      } 
	  
	  document.form1.puntualidad.selectedIndex = success1;
  }

}
//~~~~~~~Completar campos select en user_edit.php
function com_user() {
  var success1 = -1;
  var success2 = -1;
  var success3 = -1;
  var success4 = -1;
  
  document.form1.diac.value   = document.form1.diacB.value;
  document.form1.mesc.value   = document.form1.mescB.value;
  document.form1.anioc.value  = document.form1.aniocB.value;
  document.form1.estado.value = document.form1.estadoB.value;
  
  for (var i = 0; i < document.form1.diac.length; i++) {
    if (document.form1.diac.options[i].value == document.form1.diacB.value)
      success1 = [i];
  } 
  for (var i = 0; i < document.form1.mesc.length; i++) {
    if (document.form1.mesc.options[i].value == document.form1.mescB.value)
      success2 = [i];
  } 
  for (var i = 0; i < document.form1.anioc.length; i++) {
    if (document.form1.anioc.options[i].value == document.form1.aniocB.value)
      success3 = [i];
  } 
  for (var i = 0; i < document.form1.estado.length; i++) {
    if (document.form1.estado.options[i].value == document.form1.estadoB.value)
      success4 = [i];
  } 
 
  document.form1.diac.selectedIndex   = success1;
  document.form1.mesc.selectedIndex   = success2;
  document.form1.anioc.selectedIndex  = success3;
  document.form1.estado.selectedIndex = success4;
  //
}
//~~~~~~~Completar campos select en carga_edit.php
function com_carga() {
  var success1 = -1;
  var success2 = -1;
  var success3 = -1;
  var success4 = -1;
  var success5 = -1;
  var success6 = -1;
  
  document.form1.tipo.value            = document.form1.tipoB.value;
  document.form1.detalle.value         = document.form1.detalleB.value;
  document.form1.estadoO.value         = document.form1.estadoOB.value;
  document.form1.estadoD.value         = document.form1.estadoDB.value;
  
  for (var i = 0; i < document.form1.tipo.length; i++) {
    if (document.form1.tipo.options[i].value == document.form1.tipoB.value)
      success1 = [i];
  } 
  /*
  for (var i = 0; i < document.form1.status.length; i++) {
    if (document.form1.status.options[i].value == document.form1.statusB.value)
      success3 = [i];
  } 
  */
  for (var i = 0; i < document.form1.detalle.length; i++) {
    if (document.form1.detalle.options[i].value == document.form1.detalleB.value)
      success2 = [i];
  } 
  for (var i = 0; i < document.form1.estadoO.length; i++) {
    if (document.form1.estadoO.options[i].value == document.form1.estadoOB.value)
      success5 = [i];
  } 
  for (var i = 0; i < document.form1.estadoD.length; i++) {
    if (document.form1.estadoD.options[i].value == document.form1.estadoDB.value)
      success6 = [i];
  } 
 
  document.form1.tipo.selectedIndex            = success1;
  document.form1.detalle.selectedIndex         = success2;
 //document.form1.status.selectedIndex          = success3;
  document.form1.estadoO.selectedIndex         = success5;
  document.form1.estadoD.selectedIndex         = success6;
  //
 //Si existe viaje. llena componente de puntualidad
 if (document.form1.idv.value) {
	  var success7 = -1;
	  document.form1.puntualidad.value = document.form1.puntualidadB.value;
      
	  for (var i = 0; i < document.form1.puntualidad.length; i++) {
		   if (document.form1.puntualidad.options[i].value == document.form1.puntualidadB.value)
		       success7 = [i];
      } 
	  
	  document.form1.puntualidad.selectedIndex = success1;
  }
}

//~~Elimina un flete
function del_flete(id) {
   var agree=confirm("Si das click en ACEPTAR, el flete se eliminará permanentemente.");
   if (agree) {
	   this.location = 'flete_del.php?id='+id;
	   /*
	   document.form1.action = 'flete_del.php?id='+id;
	   document.form1.method = "get";
	   document.form1.submit(); //return true ;
	   */
   } else {
	   return false ;
   }
}
//Confirma borrar
function confirmDel(rname,url) {
   var agree=confirm("¿Borrar Registro: " + rname +"?");
   if (agree) {
	   window.location = url;
   } else {
	   return false ;
   }
}
//Confirma contratar
function contrata(url) {
   var agree=confirm("¿Contratar Flete?");
   if (agree) {
	   window.location = url;
   } else {
	   return false ;
   }
}
//Carga los SWF dinamicamente
function printmovie(swf,w,h) {
document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"                    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+w+'" height="'+h+'">');
document.write('<param name="movie" value="'+swf+'">');
document.write('<param name="quality" value="high">');
document.write('<param name="wmode" value="transparent">');
document.write('<embed src="'+swf+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"></embed></object>');
}
//~~VERIFICAR CAMPOS LLENOS: Nuevos user
function verifica_user() {
 var cad = '';
 var ban = 0;
 if (document.form1.servicio.value == 0) {
     cad += "Selecciona tipo de servicio.\n";
	 ban++;
 }
 if (document.form1.nombre.value == "") {
     cad += "Escribe tu nombre.\n";
	 ban++;
 }
 if (document.form1.apellidos.value == "") {
     cad += "Escribe tus apellidos.\n";
	 ban++;
 }
 /*
 if (document.form1.email.value == "") {
     cad += "Escribe tu correo electrónico.\n";
	 ban++;
 }
 */
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.form1.email.value)){
   //alert("La dirección de email " + valor    + " es correcta.") 
   //return (true)
  } else {
     cad += "Escribe tu correo electrónico.\n";
	 ban++;
  } 
  if (document.form1.actividad[4].checked == true && document.form1.actividadO.value == '') {
     cad += "Escribe la actividad de tu empresa.\n";
	 ban++;
 }
 if (document.form1.calle.value == "") {
     cad += "Escribe tu dirección.\n";
	 ban++;
 }
 if (document.form1.colonia.value == "") {
     cad += "Escribe tu coloniao.\n";
	 ban++;
 }
 if (document.form1.cp.value == "") {
     cad += "Escribe tu código postal.\n";
	 ban++;
 }
 if (document.form1.ciudad.value == "") {
     cad += "Escribe tu ciudad.\n";
	 ban++;
 }
 if (document.form1.estado.value == "") {
     cad += "Escribe tu estado.\n";
	 ban++;
 }
 if (document.form1.tel.value == "") {
     cad += "Escribe tu teléfono.\n";
	 ban++;
 }
 /*
 if (document.form1.tipoT[4].checked == true && document.form1.tipoTO.value == '') {
     cad += "Escribe el tipo de transporte.\n";
	 ban++;
 }
 if (document.form1.propios.value == "") {
     cad += "Escribe número de camiones propios.\n";
	 ban++;
 }
 if (document.form1.manejan.value == "") {
     cad += "Escribe número de camiones manejan.\n";
	 ban++;
 }
 if (document.form1.empleados.value == "") {
     cad += "Escribe nñumero de empleados.\n";
	 ban++;
 }
 if (document.form1.ventas.value == "") {
     cad += "Escribe tus ventas anuales.\n";
	 ban++;
 }
 */
 if (ban != 0) {
    alert(cad);
    return(false);
 } else {
   document.form1.method = 'POST'; 
   document.form1.action = 'user_save.php'; 
   document.form1.submit();
 }
}
//~~VERIFICAR CAMPOS LLENOS: editar user
function verifica_user_edit() {
 var cad = '';
 var ban = 0;
 if (document.form1.nombre.value == "") {
     cad += "Escribe tu nombre.\n";
	 ban++;
 }
 if (document.form1.apellidos.value == "") {
     cad += "Escribe tus apellidos.\n";
	 ban++;
 }
 /*
 if (document.form1.email.value == "") {
     cad += "Escribe tu correo electrónico.\n";
	 ban++;
 }
 */
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.form1.email.value)){
   //alert("La dirección de email " + valor    + " es correcta.") 
   //return (true)
  } else {
     cad += "Escribe tu correo electrónico.\n";
	 ban++;
  } if (document.form1.actividad[4].checked == true && document.form1.actividadO.value == '') {
     cad += "Escribe la actividad de tu empresa.\n";
	 ban++;
 }
 if (document.form1.calle.value == "") {
     cad += "Escribe tu dirección.\n";
	 ban++;
 }
 if (document.form1.colonia.value == "") {
     cad += "Escribe tu coloniao.\n";
	 ban++;
 }
 if (document.form1.cp.value == "") {
     cad += "Escribe tu código postal.\n";
	 ban++;
 }
 if (document.form1.ciudad.value == "") {
     cad += "Escribe tu ciudad.\n";
	 ban++;
 }
 if (document.form1.estado.value == "") {
     cad += "Escribe tu estado.\n";
	 ban++;
 }
 if (document.form1.tel.value == "") {
     cad += "Escribe tu teléfono.\n";
	 ban++;
 }
 
 /*
 if (document.form1.tipoT[4].checked == true && document.form1.tipoTO.value == '') {
     cad += "Escribe el tipo de transporte.\n";
	 ban++;
 }
 if (document.form1.propios.value == "") {
     cad += "Escribe número de camiones propios.\n";
	 ban++;
 }
 if (document.form1.manejan.value == "") {
     cad += "Escribe número de camiones manejan.\n";
	 ban++;
 }
 if (document.form1.empleados.value == "") {
     cad += "Escribe nñumero de empleados.\n";
	 ban++;
 }
 if (document.form1.ventas.value == "") {
     cad += "Escribe tus ventas anuales.\n";
	 ban++;
 }
  */
 if (ban != 0) {
    alert(cad);
    return(false);
 } else {
   document.form1.method = 'POST'; 
   document.form1.action = 'user_update.php'; 
   document.form1.submit();
 }
}
//~~VERIFICAR CAMPOS LLENOS: olvidaste paswawrd
function verifica_recu() {
 var cad = '';
 var ban = 0;
 if (document.form1.email.value == "") {
     cad += "Escribe tu correo electrónico.\n";
	 ban++;
 }
 if (ban != 0) {
    alert(cad);
    return(false);
 } else {
   document.form1.method = 'POST'; 
   document.form1.action = 'rec_pass2.php'; 
   document.form1.submit();
 }
}
//~~VERIFICAR CAMPOS LLENOS: nuevo grupo
function verifica_grupo() {
 var cad = '';
 var ban = 0;
  if (document.form1.nombre.value == "") {
     cad += "Escribe el nombre del grupo.\n";
	 ban++;
 } 
 if (ban != 0) {
    alert(cad);
    return(false);
 } else {
   //document.form1.method = 'POST'; 
   //document.form1.action = 'flete_save.php'; 
   document.form1.submit();
 }
}
//~~VERIFICAR CAMPOS LLENOS: nueva carga
function verifica_carga() {
 var cad = '';
 var ban = 0;
  if (document.form1.carga.value == "") {
     cad += "Escribe la carga.\n";
	 ban++;
 } 
 if (document.form1.tipo.value == 0) {
     cad += "Selecciona tipo de camion.\n";
	 ban++;
 }
 if (document.form1.detalle.value == 0) {
     cad += "Selecciona la caracteristica del camion.\n";
	 ban++;
 }
 if (document.form1.fec1.value == "doble click") {
     cad += "Escribe la fecha del viaje.\n";
	 ban++;
 } 
 if (document.form1.ciudadO.value == "") {
     cad += "Escribe la ciudad de origen.\n";
	 ban++;
 } 
 if (document.form1.ciudadD.value == "") {
     cad += "Escribe la ciudad de destino.\n";
	 ban++;
 } 
 if (ban != 0) {
    alert(cad);
    return(false);
 } else {
   //document.form1.method = 'POST'; 
   //document.form1.action = 'flete_save.php'; 
   document.form1.submit();
 }
}
//~~VERIFICAR CAMPOS LLENOS: nuevo flete
function verifica_flete() {
 var cad = '';
 var ban = 0;
 if (document.form1.tipo.value == 0) {
     cad += "Selecciona tipo de camion.\n";
	 ban++;
 }
 if (document.form1.detalle.value == 0) {
     cad += "Selecciona la caracteristica del camion.\n";
	 ban++;
 }
 if (document.form1.fec1.value == "doble click") {
     cad += "Escribe la fecha del viaje.\n";
	 ban++;
 } 
 if (document.form1.ciudadO.value == "") {
     cad += "Escribe la ciudad de origen.\n";
	 ban++;
 } 
 if (document.form1.ciudadD.value == "") {
     cad += "Escribe la ciudad de destino.\n";
	 ban++;
 } 
 if (document.form1.no_camiones.value == "") {
     cad += "Escribe el numero de camiones.\n";
	 ban++;
 } 
 if (document.form1.precio_concepto.value == 0) {
     cad += "Selecciona concepto de cobro.\n";
	 ban++;
 }
 //verifica si hay viaje
 var cont = 0;
 if (document.form1.idv.value != '') {
	 //Fecha de entrega carga
	 if (document.form1.entrega_carga.value != '') {
	     cont = valida_fecha(document.form1.entrega_carga.value);
	     if (cont != 0) {
		     cad += "Fecha de entrega de carga incorrecta.\n";
		     ban++;
	     }
     }
	 //Fecha de entrega evidencia
	 if (document.form1.entrega_evidencias.value != '') {
	     cont = valida_fecha(document.form1.entrega_evidencias.value);
	     if (cont != 0) {
		     cad += "Fecha de entrega de evidencia incorrecta.\n";
		     ban++;
	     }
     }
	 //Fecha de entrega revision factura
	 if (document.form1.revision_factura.value != '') {
	     cont = valida_fecha(document.form1.revision_factura.value);
	     if (cont != 0) {
		     cad += "Fecha de entrega de revision de factura incorrecta.\n";
		     ban++;
	     }
     }
	 //Fecha de entrega de pago
	 if (document.form1.recibe_pago.value != '') {
	     cont = valida_fecha(document.form1.recibe_pago.value);
	     if (cont != 0) {
		     cad += "Fecha de entrega pago incorrecta.\n";
		     ban++;
	     }
     }
 }
 
 
 if (ban != 0) {
    alert(cad);
    return(false);
 } else {
   //document.form1.method = 'POST'; 
   //document.form1.action = 'flete_save.php'; 
   document.form1.submit();
 }
}
//Bloquea campos y solo escribe numeros
function onlyNumbers() {
	keyChar = window.event.keyCode;
	if ((keyChar < 46 || keyChar > 57)) {
		window.event.keyCode = 0;
	}
}
//valida fecha
function valida_fecha(Cadena){
	var cad = 0;
	var Fecha= new String(Cadena)	// Crea un string
	var RealFecha= new Date()	// Para sacar la fecha de hoy
	// Cadena Año
	var Ano= new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length))
	// Cadena Mes
	var Mes= new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")))
	// Cadena Día
	var Dia= new String(Fecha.substring(0,Fecha.indexOf("/")))

	// Valido el año
	if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){
        cad++;
	}
	// Valido el Mes
	if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12 || Mes.length < 2){
        cad++;
	}
	// Valido el Dia
	if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31 || Dia.length < 2){
        cad++;
	}
	if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {
		if (Mes==2 && Dia > 28 || Dia>30) {
        cad++;
		}
	}
  //para que envie los datos, quitar las  2 lineas siguientes
  //alert("Fecha correcta.")
  //return false	
  return cad;
}

//~~CALCULADORA
function calculador() {
var cad = '';
 var ban = 0;
 var path = document.form1;
 /*
 if (document.form1.cate.value == 0) {
     cad += "Selecciona categoría.\n";
	 ban++;
 }
 if (document.form1.nombre.value == '') {
     cad += "Escribe el nombre.\n";
	 ban++;
 }
 */
  
 if (ban != 0) {
    alert(cad);
    return(false);
 } else {
	//haz calculos
	var costo        = path.costo.value;
	var km           = path.km.value;
	var valor        = path.valor.value;
	var seguro       = path.seguro.value;
	var diesel       = path.diesel.value;
	var rendimiento  = path.rendimiento.value;
	var aceite_costo = path.aceite_costo.value;
	var aceite_km    = path.aceite_km.value;
	var repara_costo = path.repara_costo.value;
	var repara_km    = path.repara_km.value;
	var llanta_costo = path.llanta_costo.value;
	var llantas      = path.llantas.value;
	var llanta_km    = path.llanta_km.value;
	var dias_viaje   = path.dias_viaje.value;
	var comision     = path.comision.value;
	var dias_anio    = path.dias_anio.value;
	var carga_vacia  = path.carga_vacia.value;
	
	document.form1.km_vacios.value        = (carga_vacia/100) * km;
	document.form1.km_cargados.value      = km;
	document.form1.km_totales.value       = eval(document.form1.km_vacios.value) + eval(document.form1.km_cargados.value);
	//
	document.form1.depreciacion.value     = (valor/(dias_anio*5))*dias_viaje;
	document.form1.seguro_unidad.value    = (seguro/dias_anio)*dias_viaje;//redondear
	document.form1.costos_fijos.value     = eval(document.form1.depreciacion.value) + eval(document.form1.seguro_unidad.value);
    //
	document.form1.lubricacion.value      = (aceite_costo/aceite_km) * document.form1.km_totales.value;
	document.form1.mantenimiento.value    = (repara_costo/repara_km) * document.form1.km_totales.value;
	document.form1.llantas_total.value    = ((llanta_costo*llantas)/llanta_km) * document.form1.km_totales.value;
	document.form1.diesel_total.value     = (diesel/rendimiento) * document.form1.km_totales.value;
	document.form1.sueldo.value           = costo * (comision/100);
	document.form1.costos_variables.value = eval(document.form1.lubricacion.value) + 
	                                        eval(document.form1.mantenimiento.value) +
	                                        eval(document.form1.llantas_total.value) +
	                                        eval(document.form1.diesel_total.value) +
	                                        eval(document.form1.sueldo.value);
	document.form1.total_costo.value      = eval(document.form1.costos_fijos.value) + eval(document.form1.costos_variables.value);
	document.form1.utilidad.value         = costo - eval(document.form1.total_costo.value);
 }
}
//~~~~~~~ ABRE POP UP CENTRADO ~~~~~~~
function open_wins(url,w,h) { 
 var x     = (screen.width)?(screen.width-w)/2:100;
 var y     = (screen.height)?(screen.height-h)/2:100;
 var a = url;
ventana = window.open(a,"","menubar=no,location=no,toolbar=no,status=yes,scrollbars=yes,resizable=no,left="+x+", top="+y+", width="+w+",height="+h);
}
//POPUP CENTRADO
function open_wins_center(url,w,h) { 
 var x     = (screen.width)?(screen.width-w)/2:100;
 var y     = (screen.height)?(screen.height-h)/2:100;
 var a = url;
ventana = window.open(a,"Nueva","menubar=no,location=no,toolbar=no,status=yes,scrollbars=no,resizable=yes,left="+x+", top="+y+", width="+w+",height="+h);
}

/*
//~~~~~~~~~~~ LLENAR COMPONENTES FECHA NEWS_EDIT
function com_model() {
  var success   = -1;
   document.form1.id_sec.value  = document.form1.id_secB.value;
   document.form1.id_news.value  = document.form1.id_newsB.value;
  for (var i = 0; i < document.form1.cate.length; i++) {
    if (document.form1.cate.options[i].value == document.form1.cateB.value)
      success = [i];
  } 
 
  document.form1.cate.selectedIndex  = success;
  //
}
//Abre editar modelos
function open_editar_models(id) {
   document.form1.id_news.value = id;
   document.form1.id_sec.value = 12;
   document.form1.method='post'; 
   document.form1.action='main.php'; 
   document.form1.submit();
}
//~~VERIFICAR CAMPOS LLENOS: MODELOS
function verifica_model(id) {
 var cad = '';
 var ban = 0;
 if (document.form1.cate.value == 0) {
     cad += "Selecciona categoría.\n";
	 ban++;
 }
 if (document.form1.nombre.value == '') {
     cad += "Escribe el nombre.\n";
	 ban++;
 }
  
 if (ban != 0) {
    alert(cad);
    return(false);
 } else {
   document.form1.method='POST'; 
   if (id == 1) document.form1.action='model_save.php'; 
   if (id == 2) document.form1.action='model_update.php'; 
   document.form1.submit();
 }
}
//Abre NuevO MODELO
function open_add_modelos () {
   document.form1.id_sec.value = 11;
   document.form1.method='post'; 
   document.form1.action='main.php'; 
   document.form1.submit();
}
//~~~~~~~~~~~ LLENAR COMPONENTES  MODELOS
function com_sec3() {
  var successA   = -1;
  document.form1.id_sec.value  = document.form1.id_secB.value;
 //document.form1.limite.value  = document.form1.limite.value;
 
  for (var i = 0; i < document.form1.cate.length; i++) {
    if (document.form1.cate.options[i].value == document.form1.cateB.value)
      successA = [i];
  } 

  document.form1.cate.selectedIndex   = successA;
}
//~~~~~~~~~~~ LLENAR COMPONENTES  MODELOS
function com_sec2() {
  var success   = -1;
  var successA   = -1;
  document.form1.id_sec.value  = document.form1.id_secB.value;
 //document.form1.limite.value  = document.form1.limite.value;
 
  for (var i = 0; i < document.form1.limite.length; i++) {
    if (document.form1.limite.options[i].value == document.form1.limiteB.value)
      success = [i];
  } 
  for (var i = 0; i < document.form1.cate.length; i++) {
    if (document.form1.cate.options[i].value == document.form1.cateB.value)
      successA = [i];
  } 
  document.form1.limite.selectedIndex = success;
  document.form1.cate.selectedIndex   = successA;
}
//ELIMINA VARIOS MODELOS
function del_models_all() {
  var veri = 0;
  for (var i=0; i < document.form1.elements.length; i++) {
       if (document.form1.elements[i].type == 'checkbox') {
           if (document.form1.elements[i].checked == true)
             veri++;
     }
   }
   if (veri != 0) {
       var agree=confirm("Si das click en ACEPTAR, los modelos seleccionados se eliminarán permanentemente.");
       if (agree) {
	       document.form1.action = "model_del_all.php";
		   document.form1.submit(); //return true ;
	  } else {
	     return false ;
	  }
   } else {
     alert("Selecciona un modelo");
   }
}

//ELIMINA UN MODELO
function del_models(id) {
   var agree=confirm("Si das click en ACEPTAR, el modelo se eliminará permanentemente.");
   if (agree) {
       //document.form1.method = 'post';
	   document.form1.action = "model_del.php?id_new="+id;
	   document.form1.submit(); //return true ;
   } else {
	   return false ;
   }
}
//~~~~~~~~~~~ LLENAR COMPONENTES FECHA NEWS_EDIT
function com_sec() {
  var success   = -1;
  document.form1.id_sec.value  = document.form1.id_secB.value;
 //document.form1.limite.value  = document.form1.limite.value;
 
  for (var i = 0; i < document.form1.limite.length; i++) {
    if (document.form1.limite.options[i].value == document.form1.limiteB.value)
      success = [i];
  } 
  document.form1.limite.selectedIndex = success;
}
//~~~~~~~~~~~ LLENAR COMPONENTES FECHA NEWS_EDIT
function com_fecha2() {
  var success   = -1;
  var successA  = -1;
  var successB  = -1;
  var successD  = -1;
  
  for (var i = 0; i < document.form1.dia.length; i++) {
    if (document.form1.dia.options[i].value == document.form1.diaB.value)
      success = [i];
  } 
  for (var i = 0; i < document.form1.mes.length; i++) {
    if (document.form1.mes.options[i].value == document.form1.mesB.value)
      successA = [i];
  } 
  for (var i = 0; i < document.form1.anio.length; i++) {
    if (document.form1.anio.options[i].value == document.form1.anioB.value)
      successB = [i];
  } 
  for (var i = 0; i < document.form1.portada.length; i++) {
    if (document.form1.portada.options[i].value == document.form1.portadaB.value)
      successC = [i];
  } 
  document.form1.dia.selectedIndex  = success;
  document.form1.mes.selectedIndex  = successA;
  document.form1.anio.selectedIndex = successB;
  document.form1.portada.selectedIndex = successC;
  //
}
//Abre editar news
function open_editar_portada (id) {
   document.form1.id_news.value = id;
   document.form1.id_sec.value = 42;
   document.form1.method='post'; 
   document.form1.action='main.php'; 
   document.form1.submit();
}
//~~~~~~~~~~~ LLENAR COMPONENTES FECHA NEWS_ADD
function com_fecha() {
  var success  = -1;
  var successA  = -1;
  var successB  = -1;
  
  for (var i = 0; i < document.form1.dia.length; i++) {
    if (document.form1.dia.options[i].value == document.form1.diaB.value)
      success = [i];
  } 
  for (var i = 0; i < document.form1.mes.length; i++) {
    if (document.form1.mes.options[i].value == document.form1.mesB.value)
      successA = [i];
  } 
  for (var i = 0; i < document.form1.anio.length; i++) {
    if (document.form1.anio.options[i].value == document.form1.anioB.value)
      successB = [i];
  } 
  document.form1.dia.selectedIndex = success;
  document.form1.mes.selectedIndex = successA;
  document.form1.anio.selectedIndex = successB;
}
//Abre Nueva Portada
function open_add_portada () {
   document.form1.id_sec.value = 41;
   document.form1.method='post'; 
   document.form1.action='main.php'; 
   document.form1.submit();
}
//ELIMINA UNA NOTICIA
function del_news(id) {
   var agree=confirm("Si das click en ACEPTAR, la noticia se eliminará permanentemente.");
   if (agree) {
       //document.form1.method = 'post';
	   document.form1.action = "portada_del.php?id_new="+id;
	   document.form1.submit(); //return true ;
   } else {
	   return false ;
   }
}
//ELIMINA VARIAS NOTICIAS
function del_news_all() {
  var veri = 0;
  for (var i=0; i < document.form1.elements.length; i++) {
       if (document.form1.elements[i].type == 'checkbox') {
           if (document.form1.elements[i].checked == true)
             veri++;
     }
   }
   if (veri != 0) {
       var agree=confirm("Si das click en ACEPTAR, las noticias seleccionadas se eliminarán permanentemente.");
       if (agree) {
	       document.form1.action = "portada_del_all.php";
		   document.form1.submit(); //return true ;
	  } else {
	     return false ;
	  }
   } else {
     alert("Selecciona una noticia");
   }
}
//ELIMINA UNA IMAGEN DE LA GALERIA
function del_img(id,limite,pos_img,tipo) {
   var agree=confirm("Si das click en ACEPTAR, la imágen se eliminará permanentemente de la galeria.");
   if (agree) {
       //document.form1.method = 'post';
	   document.form1.action = "img_del.php?id="+id+"&limite="+limite+"&pos_img="+pos_img+"&tipo="+tipo;
	   document.form1.submit(); //return true ;
   } else {
	   return false ;
   }
}
//~~VERIFICAR CAMPOS LLENOS: INFO
function verifica_info() {
 var cad = '';
 var ban = 0;
 if (document.form1.texto_sp.value == '') {
     cad += "Escribe la información en español.\n";
	 ban++;
 }
 if (document.form1.texto_en.value == '') {
     cad += "Escribe la información en ingles.\n";
	 ban++;
 }
  
 if (ban != 0) {
    alert(cad);
    return(false);
 } else {
   document.form1.method='POST'; 
   document.form1.action='info_save.php'; 
   document.form1.submit();
 }
}
//~~VERIFICAR CAMPOS LLENOS: PORTADA
function verifica_portada(id) {
 var cad = '';
 var ban = 0;
 if (document.form1.dia.value == 0 || document.form1.mes.value == 0 || document.form1.anio.value == 0) {
     cad += "Selecciona la fecha de la noticia .\n";
	 ban++;
 } 
 if (document.form1.titulo_sp.value == '') {
     cad += "Escribe el título en español.\n";
	 ban++;
 }
 if (document.form1.texto_sp.value == '') {
     cad += "Escribe la información en español.\n";
	 ban++;
 }
 if (document.form1.img1.value == '') {
     cad += "Selecciona la Imagen para la portada.\n";
	 ban++;
 }
  
 if (ban != 0) {
    alert(cad);
    return(false);
 } else {
   document.form1.method='POST'; 
   if (id == 1) document.form1.action='portada_save.php';  else document.form1.action='portada_update.php';
   document.form1.submit();
 }
}
//Pasar valor de un popup a su opener
function ponPrefijo(pref,no){ 
    var objeto = 'opener.document.form1.img'+no;
    eval(objeto).value = pref;
    //window.close() 
}
//~~~~~~~~~~~ LLENAR COMPONENTE PESTAÑA GALERIA
function com_limite() {
  var success  = -1;
  
  for (var i = 0; i < document.form1.limite.length; i++) {
    if (document.form1.limite.options[i].value == document.form1.limiteB.value)
      success = [i];
  } 
  document.form1.limite.selectedIndex = success;
}
//POPUP CENTRADO
function open_wins(url,w,h) { 
 var x     = (screen.width)?(screen.width-w)/2:100;
 var y     = (screen.height)?(screen.height-h)/2:100;
 var a = url;
ventana = window.open(a,"Nueva","menubar=no,location=no,toolbar=no,status=yes,scrollbars=yes,resizable=no,left="+x+", top="+y+", width="+w+",height="+h);
}
//Abre galeria
function open_galeria (id,tipo) {
  open_wins("gal_modelos.php?pos_img="+id+"&tipo="+tipo,618,450)
}
//Quita imagen
function quita_imagen (id) {
  document.form1["img"+id].value = '';
}
//~~VERIFICAR CAMPOS LLENOS: CONTACTO
function verifica_contacto() {
 var cad = '';
 var ban = 0;
 if (document.form1.tel01.value == '') {
     cad += "Escribe el télefono 01.\n";
	 ban++;
 }
 if (document.form1.email.value == '') {
     cad += "Escribe el correo electrónico de contacto.\n";
	 ban++;
 }
 if (document.form1.email_form.value == '') {
     cad += "Escribe el correo electrónico para la forma de contacto.\n";
	 ban++;
 }
 if (ban != 0) {
    alert(cad);
    return(false);
 } else {
   document.form1.method = 'post'; 
   document.form1.action = 'contacto_update.php'; 
   document.form1.submit();
 }
}

//ABRE MAIN
function admin (id) {
   if(id) document.form1.id_sec.value = id;
   document.form1.method='POST'; 
   document.form1.action='main.php'; 
   document.form1.submit();
}
//ABRE MAIN
function admin2(id,cate) {
   if(id) document.form1.id_sec.value = id;
   if(cate) document.form1.cate.value = cate;
   document.form1.method='POST'; 
   document.form1.action='main.php'; 
   document.form1.submit();
}
//ABRE MAIN
function admin2 (id,limite) {
   if(id) document.form1.id_sec.value = id;
   document.form1.method='POST'; 
   document.form1.action='main.php'; 
   document.form1.submit();
}



/////////////////
//  Genericas //
/////////////////
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

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_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

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





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

//~~~~~~~~~~~ LLENAR COMPONENTE STATUS EN EDITAR ADMIN
function com_status() {
  var success  = -1;
  
  for (var i = 0; i < document.form1.status.length; i++) {
    if (document.form1.status.options[i].value == document.form1.statusB.value)
      success = [i];
  } 
  document.form1.status.selectedIndex = success;
}



//




 
//No se selecciona imagene para la noticia
function put_image(estado) {
   for (i = 0; i <=5; i++) {
       document.form1["img_"+i].disabled = estado;
   }
   document.form1.pie.disabled = estado;
   document.form1.pie_en.disabled = estado;
   //deshabilitarControles(!estado);
}
//Deshabilitar galerias 
function deshabilitarControles(estado) {
    //Generamos objecto enumerator
   //arrObjeto= new Enumerator(document.all);
   arrObjeto= new Enumerator(document.all);
   //recorremos cada item en un bucle
   for(arrObjeto.moveFirst(); !arrObjeto.atEnd(); arrObjeto.moveNext()) {
      //verificamos el tipo de objeto
      if ((arrObjeto.item().id == 'go_gal'))  {   
		   //deshabilitamos los objetos requeridos
            //arrObjeto.item().disabled = "disabled";
			 arrObjeto.item().onclick= function(){return estado}
			//arrObjeto.item().onClick = "";
      }
   }
}
//
function enlaces(){
alert('a');
for(m = 0; m < document.getElementsByTagName('a'); m++){
alert('a');
    if (document.getElementsByTagName('a')[m].id == 'go_agl') {
	alert('sss');
	   // document.getElementsByTagName('a')[m].onclick= function(){return true}
	}

}
}
//~~VERIFICAR CAMPOS LLENOS: NEWS_ADD
function verifica_news() {
 var cad = '';
 var ban = 0;
 if (document.form1.estructura[0].checked == false) {
     if (document.form1.img_0.value == '') {
         cad += "Selecciona la imágen a mostrar.\n";
	     ban++;
     }
     if (document.form1.pie.value == '') {
         cad += "Escribe un pie de foto en español para la imágen.\n";
	     ban++;
     }
     if (document.form1.pie_en.value == '') {
         cad += "Escribe un pie de foto en ingles para la imágen.\n";
	     ban++;
     }
 } 
 if (document.form1.dia.value == 0 || document.form1.mes.value == 0 || document.form1.anio.value == 0) {
     cad += "Selecciona la fecha de la noticia .\n";
	 ban++;
 }
 if (document.form1.titulo.value == '') {
     cad += "Escribe el título de la noticia en español.\n";
	 ban++;
 }
 if (document.form1.titulo_en.value == '') {
     cad += "Escribe el título de la noticia en ingles.\n";
	 ban++;
 }
 if (document.form1.texto.value == '') {
     cad += "Escribe la noticia en español.\n";
	 ban++;
 }
 if (document.form1.texto_en.value == '') {
     cad += "Escribe la noticia en ingles.\n";
	 ban++;
 }
  
 if (ban != 0) {
    alert(cad);
    return(false);
 } else {
   document.form1.method='post'; 
   document.form1.action='news_save.php'; 
   document.form1.submit();
 }
}
//~~VERIFICAR CAMPOS LLENOS: NEWS_EDIT
function verifica_news_edit() {
 var cad = '';
 var ban = 0;
 if (document.form1.estructura[0].checked == false) {
     if (document.form1.img_0.value == '') {
         cad += "Selecciona la imágen a mostrar.\n";
	     ban++;
     }
     if (document.form1.pie.value == '') {
         cad += "Escribe un pie de foto en español para la imágen.\n";
	     ban++;
     }
     if (document.form1.pie_en.value == '') {
         cad += "Escribe un pie de foto en ingles para la imágen.\n";
	     ban++;
     }
 } 
 if (document.form1.dia.value == 0 || document.form1.mes.value == 0 || document.form1.anio.value == 0) {
     cad += "Selecciona la fecha de la noticia .\n";
	 ban++;
 }
 if (document.form1.titulo.value == '') {
     cad += "Escribe el título de la noticia en español.\n";
	 ban++;
 }
 if (document.form1.titulo_en.value == '') {
     cad += "Escribe el título de la noticia en ingles.\n";
	 ban++;
 }
 if (document.form1.texto.value == '') {
     cad += "Escribe la noticia en español.\n";
	 ban++;
 }
 if (document.form1.texto_en.value == '') {
     cad += "Escribe la noticia en ingles.\n";
	 ban++;
 }  
 if (ban != 0) {
    alert(cad);
    return(false);
 } else {
   document.form1.method = 'post'; 
   document.form1.action = 'news_update.php'; 
   document.form1.submit();
 }
}
///////////////////////////////////

//Abre editar news
function open_editar (id) {
   document.form1.id_news.value = id;
   document.form1.id_sec.value = 13;
   document.form1.method='post'; 
   document.form1.action='main.php'; 
   document.form1.submit();
}




///////////////////////////////////
//Abre Nueva admin
function open_add2 () {
   document.form1.id_sec.value = 22;
   document.form1.method='POST'; 
   document.form1.action='main.php'; 
   document.form1.submit();
}
//Abre editar admin
function open_editar2 (id) {
   document.form1.id_admin.value = id;
   document.form1.id_sec.value = 23;
   document.form1.method='POST'; 
   document.form1.action='main.php'; 
   document.form1.submit();
}
//ELIMINA UNA admin
function del_admin(id) {
   var agree=confirm("Si das click en ACEPTAR, el usuario se eliminarán permanentemente.");
   if (agree) {
       //document.form1.method = 'post';
	   document.form1.action = "admin_del.php?id_admin="+id;
	   document.form1.submit(); //return true ;
   } else {
	   return false ;
   }
}
//ELIMINA VARIAS admin
function del_admin_all() {
  var veri = 0;
  for (var i=0; i < document.form1.elements.length; i++) {
       if (document.form1.elements[i].type == 'checkbox') {
           if (document.form1.elements[i].checked == true)
             veri++;
     }
   }
   if (veri != 0) {
       var agree=confirm("Si das click en ACEPTAR, los usuarios seleccionados se eliminarán permanentemente.");
       if (agree) {
	       document.form1.action = "admin_del_all.php";
		   document.form1.submit(); //return true ;
	  } else {
	     return false ;
	  }
   } else {
     alert("Selecciona un usuario");
   }
}
//~~VERIFICAR CAMPOS LLENOS: admin_ADD
function verifica_admin() {
 var cad = '';
 var ban = 0;
 if (document.form1.nombre.value == '') {
     cad += "Escribe el nombre.\n";
	 ban++;
 }
 if (document.form1.apellidos.value == '') {
     cad += "Escribe los apellidos.\n";
	 ban++;
 }
 if (document.form1.email.value == '') {
     cad += "Escribe el correo.\n";
	 ban++;
 }
 if (document.form1.user.value == '') {
     cad += "Escribe el nombre de usuario.\n";
	 ban++;
 }
 if (document.form1.pass.value == '') {
     cad += "Escribe la contraseña.\n";
	 ban++;
 }
  
 if (ban != 0) {
    alert(cad);
    return(false);
 } else {
   document.form1.method='POST'; 
   document.form1.action='admin_save.php'; 
   document.form1.submit();
 }
}
//~~VERIFICAR CAMPOS LLENOS:ADMIN_EDIT
function verifica_admin_edit() {
 var cad = '';
 var ban = 0;
 if (document.form1.nombre.value == '') {
     cad += "Escribe el nombre.\n";
	 ban++;
 }
 if (document.form1.apellidos.value == '') {
     cad += "Escribe los apellidos.\n";
	 ban++;
 }
 if (document.form1.email.value == '') {
     cad += "Escribe el correo.\n";
	 ban++;
 }
 if (document.form1.pass.value == '') {
     cad += "Escribe la contraseña.\n";
	 ban++;
 }
 if (document.form1.status.value == 99) {
     cad += "Selecciona el status.\n";
	 ban++;
 }
  
 if (ban != 0) {
    alert(cad);
    return(false);
 } else {
   document.form1.method = 'POST'; 
   document.form1.action = 'admin_update.php'; 
   document.form1.submit();
 }
}
//MARCA TODOS LOS REGISTROS A MOVER O A ELIMINAR
function marca_todos() {
  with (document.form1) {
    for (var i=0; i < elements.length; i++) {
     if (elements[i].type == 'checkbox') {
         if (selCheck.checked == true)
             elements[i].checked = true;
         else 
             elements[i].checked = false;
     }
    }
  }
}



*/
