// JavaScript Document
function activar_cuenta_mc()
{
	if (document.frm_alta.chk_cuenta_mc.checked)
	{
		document.frm_alta.correo_mc.disabled       = false;
		document.frm_alta.pass_mc.disabled         = false;
		document.frm_alta.repetir_pass_mc.disabled = false;
	}
	else
	{
		document.frm_alta.correo_mc.disabled       = true;
		document.frm_alta.pass_mc.disabled         = true;
		document.frm_alta.repetir_pass_mc.disabled = true;
	
	}
}

function activar_cuenta_mc_modificacion_datos()
{
	if (document.frm_datosEmpresa.chk_cuenta_mc.checked)
	{
		document.frm_datosEmpresa.correo_mc.disabled       = false;
		document.frm_datosEmpresa.pass_mc.disabled         = false;
		document.frm_datosEmpresa.repetir_pass_mc.disabled = false;
	}
	else
	{
		document.frm_datosEmpresa.correo_mc.disabled       = true;
		document.frm_datosEmpresa.pass_mc.disabled         = true;
		document.frm_datosEmpresa.repetir_pass_mc.disabled = true;
	
	}
}


function comprobar_mail(texto){
    var mailres = true;            
    var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";
    
    var arroba = texto.indexOf("@",0);
    if ((texto.lastIndexOf("@")) != arroba) arroba = -1;
    
    var punto = texto.lastIndexOf(".");
                
     for (var contador = 0 ; contador < texto.length ; contador++){
        if (cadena.indexOf(texto.substr(contador, 1),0) == -1){
            mailres = false;
            break;
     }
    }

    if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1))
     mailres = true;
    else
     mailres = false;
                
    return mailres;
} 



<!--  **********************************************


function envia_datos(){
 var error="";
 var bien=true;

 if (document.frm_alta.empresas_forma_juridica.value.length==0){
   bien=false;
   error +="\nError: Introducir forma juridica de la empresa.";
  }

if (document.frm_alta.empresas_cif.value.length==0){
   bien=false;
   error+="\nError: Introducir CIF/NIF de la empresa.";
  }else{
    // Comprobar que esta bien formado
	  if (Es_NIF(document.frm_alta.empresas_cif.value)==0) {
	      if (Es_CIF(document.frm_alta.empresas_cif.value)==0)  {
		   bien=false;
		   error+="\nError: Formato CIF/NIF es incorrecto.";
	   }
	 }
  }
  

 if (document.frm_alta.empresas_nombre.value.length==0){
   bien=false;
   error +="\nError: Introducir nombre comercial de la empresa.";
  }
  
 if (document.frm_alta.empresas_rubro.value.length==0){
   bien=false;
   error +="\nError: Introducir actividad comercial de la empresa.";
  }

 if (document.frm_alta.empresas_cp.value.length==0){
   bien=false;
   error +="\nError: Introducir código postal de la empresa.";
  }

 if (document.frm_alta.empresas_localidad.value.length==0){
   bien=false;
   error +="\nError: Introducir localidad de la empresa.";
  }
  

 if (document.frm_alta.empresas_provincia.options[document.frm_alta.empresas_provincia.selectedIndex].value != 52){
   bien=false;
   error +="\nError: Seleccionar provincia Melilla.";
  }
  

 if (document.frm_alta.empresas_telefono_contacto.value.length==0){
   bien=false;
   error +="\nError: Introducir teléfono de contacto de la empresa.";
  }


 if (document.frm_alta.empresas_email.value!=""){
  if (comprobar_mail(document.frm_alta.empresas_email.value)==false){
   bien=false;
   error +="\nError: E-mail no correcto. Introducir un e-mail correcto.";
  }
} 
  
 if (document.frm_alta.empresas_persona_contacto.value.length==0){
   bien=false;
   error +="\nError: Introducir persona de contacto de la empresa.";
  }



 if (document.frm_alta.empresas_cargo_persona_contacto.value.length==0){
   bien=false;
   error +="\nError: Introducir cargo persona de contacto de la empresa.";
  }

 if (document.frm_alta.empresas_email_contacto.value.length==0){
   bien=false;
   error +="\nError: Introducir e-mail de contacto de la empresa.";
  }

  
 if (comprobar_mail(document.frm_alta.empresas_email_contacto.value)==false){
   bien=false;
   error +="\nError: E-mail no correcto. Introducir un e-mail correcto.";
  }
  

 if (document.frm_alta.empresas_descripcion.value.length==0){
   bien=false;
   error +="\nError: Introducir descripción de la empresa.";
  }

  
  if (document.frm_alta.chk_cuenta_mc.checked)
  {
  	if (document.frm_alta.correo_mc.value.length == 0)
	{
		bien = false;
		error += "\nError: debes especificar una cuenta para el correo de Melilla Comercio";
	}
	if ((document.frm_alta.pass_mc.value.length == 0) || (document.frm_alta.repetir_pass_mc.value != document.frm_alta.pass_mc.value))
	{
		bien = false;
		error += "\nError: las contraseñas del correo no coinciden o son vacías";
	}
  }

  if (bien==false){
   alert(error);
  }
  else
  {
  	document.frm_alta.submit();
  }
 
}


/////////////////////////////////
//
/////////////////////////////////
function IsUnsignedInteger(YourNumber)
{
	var RegExPattern = /^(?:\+|-)?\d+$/; 
    return YourNumber.match(RegExPattern);
}

function IsChar(YourChar)
{
	var Template = /^[a-z]$/i //Formato de letra
	return (Template.test(YourChar)) ? 1 : 0 //Compara \"YourChar\" con el formato \"Template\" y si coincidevuelve verdadero si no devuelve falso
}

///////////////////////
///// CONPROBACION DEL NIF
//////////////////////

function Es_NIF(YourNIF)
{
	
	if (YourNIF.length != 10) return 0 //Si la longitud de \"YourNIF\" es menor que 9 devuelve falso
	if (!IsUnsignedInteger(YourNIF.substring(0, 8))) return 0 //Si los ocho primeros digitos no forman un numero entero sin signo valido devuelve falso
	if (!IsChar(YourNIF.substring(9, 10))) return 0 //Si el ultimo digito no es una letra valida devuelve falso
	
	if (YourNIF.substring(8, 9)!='-') return 0 	
	
    return 1
}

///////////////////////
///// CONPROBACION DEL CIF
//////////////////////

function Es_CIF(YourCIF)
{
	if (YourCIF.length != 10) return 0 //Si la longitud  es menor que 9 devuelve falso
	if (!IsUnsignedInteger(YourCIF.substring(1, 10))) return 0 //Si los ocho ultimos digitos no forman un numero entero sin signo valido devuelve falso
	if (!IsChar(YourCIF.substring(0, 1))) return 0 //Si el primer digito no es una letra valida devuelve falso
	
	if (YourCIF.substring(1, 2)!='-') return 0 
	
	return 1
}
