function tienda_virtual (){
	if (document.getElementById('presupuesto').value!='550 €'){
        document.getElementById('presupuesto').options[3].selected="selected";
		alert ("El precio mínimo de una tienda virtual es de 550 €.\r\n\El presupuesto ha sido ajustado automáticamente");
	}
}

function PopWindow()
{
window.open("http://www.introtiendas.com/caracteristicas_trabajos.html",null,"width=300,height=450,menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=no,top=40,left=40");
}


/*
 * Valida direcciones ip
 */
function validar_ip() {

newip=new String(document.getElementById('ip_denegar').value);

var regexIP = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;

valid=newip.search(regexIP);

  if (valid==0) document.getElementById('denegar_ip').submit();
  else { alert ("La direccion IP no es valida");}

} 
/*
 * Oculta y despliega la capa pasada como parametro
 */
function ocultacapa(capa){
  var menu = document.getElementById(capa);
  menu.style.display = "none";
}
function despliegacapa(capa){
  var menu = document.getElementById(capa);
  
    if(menu.style.display == "none" || menu.style.diplay==""){
      menu.style.display = "block";
    }
    else{
      menu.style.display = "none";
    }
}


/* Pop up */
function popup(pagina){
	alert (pagina);
 window.open (pagina,"Historial de pedido", 'width=450px, scrollbars=1,top=50%; left=50%');
}

/* Pop up */
function popup_manual(pagina){
  window.open (pagina,"manual", 'width=480px, toolbar=yes, scrollbars=1,top=50%; left=50%');
}
/* Pop up */
function popup_visor(pagina){
  window.open (pagina,"visor", 'width=510px, toolbar=no, scrollbars=1,top=50%; left=50%');
}

/*
 Forma no intrusiva de llamar al pop up
<!--<a href="pagina.html" onclick="popup(this.href);return false">Lorem</a>-->

*/

// Vuelve a la página anterior del historial.
function atras (){
  window.history.back();
}

// Imprimir una página
function imprimirPagina() {
  if (window.print){
    window.print();

 }
  else {
      alert("Su navegador no le permite ordenar imprimir\n" +
      "Imprima desde el menú Archivos->Imprimir, o pulse CTRL+P simultaneamente.\n"+
      "Si sigue sin funcionar actualice su navegador\n");
      }
}
/**
  * Valida los datos de los formularios en el cliente.
  *
  * Tambíen son validados en el servidor
  * en el archivo pedido.cliente.hpp
  */
function validar_datos_pedido (){

  if (document.getElementById('nombre').value=='' ||
      document.getElementById('apellidos').value=='' ||
      document.getElementById('direccion').value=='' ||
      document.getElementById('cp').value=='' ||
      document.getElementById('ciudad').value=='' ||
      document.getElementById('provincia').value=='' ||
      document.getElementById('pais').value=='' ||
      document.getElementById('telefono').value=='' ||
      document.getElementById('nif').value=='') {

  alert  (
   "Debe rellenar al menos los campos de la dirección de facturación\n"+
   "Nombre: "+document.getElementById('nombre').value+"\n"+
   "Apellidos: "+document.getElementById('apellidos').value+"\n"+
   "Dirección: "+document.getElementById('direccion').value+"\n"+
   "Código Postal: "+document.getElementById('cp').value+"\n"+
   "Ciudad: "+document.getElementById('ciudad').value+"\n"+
   "Provincia: "+document.getElementById('provincia').value+"\n"+
   "País: "+document.getElementById('pais').value+"\n"+
   "Teléfono: "+document.getElementById('telefono').value+"\n"+
   "CIF/NIF: "+document.getElementById('nif').value+"\n"
   );
    window.location.href='pedido.php?error=true'
  // window.location.href='pedido.php';
   }
   else {
    window.location.href='pedido_cliente.php';
   }

}
//
function marcar_todos(field) {
  for (i = 0; i < field.length; i++)

  if (field[i].checked==false)
    field[i].checked = true;
  else
    field[i].checked = false;

}

// Borra el boletín
function confirmar_borrar_boletin ()
{
   resultado=confirm ("¿Quiere borrar el boletín?");
              if (resultado==false){
                 window.history.back();
              }
 }


// Valida la búsqueda del pedido.
function validar_busqueda_pedido(){

var campos_no_rellenos=0;
if ( document.getElementById('year_from').value=='' ) campos_no_rellenos++;
if ( document.getElementById('month_from').value=='' ) campos_no_rellenos++;
if ( document.getElementById('day_from').value=='' ) campos_no_rellenos++;

if ( document.getElementById('year_still').value=='' ) campos_no_rellenos++;
if ( document.getElementById('month_still').value=='' ) campos_no_rellenos++;
if ( document.getElementById('day_still').value=='' ) campos_no_rellenos++;


// Si no es correcto mostramos cartel de advertencia.
if ( campos_no_rellenos>=1 && campos_no_rellenos <6) {
        alert ("Si rellena una fecha debe todos los campos");
   }
else
  {
   document.getElementById('busqueda_pedido').submit();
  }
}






// El producto seleccionado para añadir ya existe.
function producto_existe(){
  alert ("El producto seleccionado para añadir ya existe")
}

function cambiar_marca(marca){
      if (marca!="-- Seleccione marca --")

      document.getElementById('marca').value=marca;
}
function cambiar_subcategoria(subcategoria){

       if (subcategoria!="-- Seleccione subcategoria --")
        document.getElementById('subcategoria').value=subcategoria;
}

/**
 *  Javascript para la edición del texto.
 *  David Ramón Yanes Fariña
 *  Falta adaptarlo para opera, konqueror.
 *  Funciona correctamente en Iexplorer 6.0, y navegadores con el motor *     Gecko.(mozilla,firefox,netscape).
 *
 */
// Captura la selección, y añade las etiquetas.
 function getSel(ini_etiqueta,fin_etiquita)
{
    // Si mozilla o firefox.
        if (window.getSelection)
        {

                editor=document.getElementById('editor');

                ini=editor.mensaje.selectionStart;
                fin=editor.mensaje.selectionEnd;
                pretext=editor.mensaje.value.substring (0,ini);
                addtext=ini_etiqueta+editor.mensaje.value.substring (ini,fin)+fin_etiqueta;
                fintext=editor.mensaje.value.substring (fin, editor.mensaje.value.length);


                final_text=pretext+addtext+fintext;
                editor.mensaje.value='';
                editor.mensaje.value=final_text;
                return final_text;
        }
    // If ¿Que navegador sería este?
    else if (document.getSelection){
                editor=document.getElementById('editor');

                if (fin_etiqueta.indexOf ('[/fr]')>=0 )
                    meter (fin_etiqueta);
                else {
                   final_text=prompt ("Introduzca texto");
                   meter (ini_etiqueta+final_text+fin_etiqueta);
                }

   }
    // Si es explorer 6.0
    else if (document.selection)
      {
      // Damos el foco al editor.
       document.editor.mensaje.focus();

      //Capturamos la seleccion hecha por el usuario.
      sel=document.selection.createRange().text;
      addtext=ini_etiqueta+sel+fin_etiqueta;
      meter(addtext);
        }
        else return;
}


function borrar_todo (){
  // Si es mozilla
  if (window.getSelection){
     editor=document.getElementById('editor');
     editor.mensaje.value='';
     
  }
  
  // Si es ie
  else if (document.selection){
             document.editor.mensaje.value='';
   }

}

// ----------------------------------------------------------------------------
// Este genial Script fue desarrollado por Tukzone, SirMatrix y Unknow,
// todos usuarios del Foro.. Gracias a ellos por su colaboración

  function storeCaret(text) {
   if (text.createTextRange) {
    text.caretPos = document.selection.createRange().duplicate();
   }
  }

  function meter(text) {

   var postopic = document.editor.mensaje;

   if (postopic.createTextRange && postopic.caretPos) {
      var caretPos = postopic.caretPos;

      caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?

     text + ' ' : text;
   }
   else postopic.value += text;

   postopic.focus(caretPos)
  }

  function codigo(accion) {
   switch(accion) {
    case "url":
     url=prompt ('Introduzca dirección','http://');
     ini_etiqueta='[a href=\"'+url+'\"]';
     fin_etiqueta='[/a]'
      break;
     case "bold":
     ini_etiqueta='[b]';
     fin_etiqueta='[/b]'
      break;
    case "italics":
     ini_etiqueta='[i]';
     fin_etiqueta='[/i]'
      break;
    case "quote":
     ini_etiqueta='[quote]';
     fin_etiqueta='[/quote]';
     break;
    case "underlayed":
     ini_etiqueta='[u]';
     fin_etiqueta='[/u]';
     break;
    case "fin_resumen":
     ini_etiqueta='';
     fin_etiqueta='[/fr]';
     break;
    default:
     break;
   }
   getSel(ini_etiqueta,fin_etiqueta);
  }
// Contador progresivo. Cuenta la cantidad de texto que hay en el campo.
  function textCounter(field, countfield, maxlimit) {
   if (field.value.length > maxlimit)
    field.value = field.value.substring(0, maxlimit);
   else
    //countfield.value = maxlimit - field.value.length;
    countfield.value = field.value.length;
  }

// Contador regresivo. Cuenta la cantidad de texto que hay en el campo la cual es restada
// de max limit.
  function reverseTextCounter(field, countfield, maxlimit) {
   if (field.value.length > maxlimit)
    field.value = field.value.substring(0, maxlimit);
   else
    countfield.value = maxlimit - field.value.length;
   }


