function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

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_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_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.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];}
}

function pop(pagina, popW, popH, scroll) //abre la página que se le pasa con la altura especificada.
{
if (document.all || document.layers || document.getElementById) 
		{
   			w = screen.availWidth;
		    h = screen.availHeight;
		}

		var leftPos = (w-popW)/2, topPos = (h-popH)/2;
		window.open(pagina,"mod","width=" + popW + ",height=" + popH + ",top=" + topPos + ",left=" + leftPos + ",scrollbars=" + scroll);
}

// ----------------------------
//    Validamos el formulario
// ----------------------------
function validacomercial(theForm)
{
  var error = 0

  if (trim(theForm.EMPRESA) == "")              //EMPRESA
  {
	  alert("Por favor, rellene el campo:\nEmpresa");
    theForm.EMPRESA.value = "";
    theForm.EMPRESA.focus();
  	error = 1;
    return false;
  }

  if (theForm.SECTOR.selectedIndex == 0)        //SECTOR
  {
  	alert("Debe seleccionar un sector");
  	theForm.SECTOR.value = "";
    theForm.SECTOR.focus();
  	error = 1;
    return false;
  }  

  if (trim(theForm.CONTACTO) == "")             //CONTACTO
  {
  	alert("Debe rellenar el campo:\nPersona de contacto");
    theForm.CONTACTO.value = "";
  	theForm.CONTACTO.focus();
  	error = 1;
    return false;
  }

  if (trim(theForm.TELEFONO) == "")             //TELEFONO
  {
  	alert("Debe rellenar el campo Teléfono")
    theForm.TELEFONO.value = "";
  	theForm.TELEFONO.focus();
  	error = 1;
    return false;
  }else if (!recoger(theForm.TELEFONO.value,1))
 	{
  	  alert ("Escriba únicamente números en el campo Teléfono.");
      theForm.TELEFONO.value = "";
  		theForm.TELEFONO.focus ();
  		error = 1;
      return false;
 	}
  
    if (trim(theForm.FAX) != "")             //FAX
  {
     if (!recoger(theForm.FAX.value,1))
    {
  	  alert ("Si desea rellenar el Fax, escriba únicamente numeros");
      theForm.FAX.value = "";
  		theForm.FAX.focus ();
  		error = 1;
      return false;
   	}
  }
    
  if (trim(theForm.CP) == "")                   //CODIGO POSTAL
  {
  	alert("Debe rellenar el campo Código Postal");
    theForm.CP.value = "";
  	theForm.CP.focus();
  	error = 1;
    return false;
  }else if (!recoger(theForm.CP.value,1))
 	{
	    alert ("Escriba únicamente numeros en el campo Codigo Postal.");
      theForm.CP.value = "";
			theForm.CP.focus ();
			error = 1;
      return false;
 	}


  if (theForm.CORREO.value != ""){
    if (!ChequeaEmail(theForm.CORREO,theForm.CORREO.value)){
      theForm.CORREO.value = "";
      theForm.CORREO.focus();
      error = 1;
      return false;
    }
  }
  
    if (theForm.TIPOINFO.selectedIndex == 0){
  	alert("Debe seleccionar la información que desea recibir");
    theForm.TIPOINFO.selectedIndex = 0;
    theForm.TIPOINFO.focus();
  	error = 1;
    return false;
  }

    if (error == 0)
	theForm.submit();
    else
	return false;
 
}

// ---------------------------------------------------
//    Funciones que comprueban los caracteres raros
// ---------------------------------------------------

function trim(e)
{
  var izq = 0
  var der = 0
  for (i=0; e.value.substr(i,1) == " " && i < e.value.length; i++)
    izq ++
  for (i = e.value.length -1; e.value.substr(i,1) == " " && i >= 0; i --)
    der++
  e.value = e.value.substr(izq, e.value.length - izq - der)
  if (izq==der && (e.value.charAt(0)==" " || e.value.charAt(0)==""))
  {
    return ""
  }
}

function recoger(campo,tipo_comprobacion)
{
  if (tipo_comprobacion == 1){
      // validamos numeros
         var checkOk = "0123456789";
     }else if( tipo_comprobacion == 2){
	      // validamos minusculas.
	         var checkOk = "abcdefghijklmnopqrstuvwxyz";
       }else if( tipo_comprobacion == 3){
		 // validamos minusculas y numeros.
			   var checkOk = "abcdefghijklmnopqrstuvwxyz0123456789";
		}else if( tipo_comprobacion == 4){
		   // validamos mayusculas.
		 	   var checkOk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";		
	         }else if( tipo_comprobacion == 5){
			  // validamos mayusculas,numeros.
					var checkOk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                 }else if( tipo_comprobacion == 6){
		         // validamos que el campo sea mayusculas,minusculas.
               	      var checkOk="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
		          }else if( tipo_comprobacion == 7){
			       // validamos mayusculas,minusculas,numeros.
			       	   var checkOk="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
		        	}else if( tipo_comprobacion == 8){
			       // validamos numeros y /.
			       	   var checkOk="0123456789/";
					   }else if( tipo_comprobacion == 9){
					   //validamos cifras(numeros con .)
					   var checkOk="0123456789.";
   					   }else if( tipo_comprobacion == 10){
					   //validamos cifras(numeros con .)
					   var checkOk="0123456789.,";
		        	}
            var checkStr = campo;
		if (checkStr == "")
		{
			return false;
		}
		for ( i = 0; i< checkStr.length; i++) 
		{
			ch=checkStr.charAt(i);
			for ( j= 0; j< checkOk.length; j++)
			{
	        	if (ch == checkOk.charAt(j))
				{
		        break;
		        }
			if(j == checkOk.length-1)
			{
				return false;		
			}
		}
	}
	return true;
}

function muestra(theForm)
{
  if (theForm.PUBLICIDAD.selectedIndex == 5){
    if (document.all){
      document.all('PBL1').innerHTML="Especifique otros medios";
      document.all('PBL2').innerHTML="<input type=TEXT name=PUBLICIDAD2 size=30 maxlength=50>";
    }
  }else{
    if (document.all){
    document.all('PBL1').innerHTML="";
    document.all('PBL2').innerHTML="";
    }
  }
}
function ChequeaEmail(campo,error) {
  var vuelve;
  vuelve = false;  
  if( (campo.value.lastIndexOf( '.') != (campo.value.length - 3)) && (campo.value.lastIndexOf( '.') != (campo.value.length - 4))) {
    alert( "Si desea rellenar el correo electrónico,\nescriba una dirección correcta");
    campo.focus();
  }else{
    if( campo.value.indexOf( '@') == -1) {
      alert( "Si desea rellenar el correo electrónico,\nescriba una dirección correcta");
			campo.focus();
    }else{
        vuelve = true;
    }
  }
   return(vuelve);
}
function desconecta() {
    if (confirm("¿Desea salir del área de clientes?"))
        document.location.href="desconectar.asp";
    else
        return false;
}