
var error = null; 
var contador = 1000;


function seleccionado(obj)
{

   if(obj.checked==true)
    contador++;
        else
            contador--;

}

function changeHTML()
{
   div = document.getElementById("conHTML");
   div2 =  document.getElementById("sinHTML");
   
   if(div.className == "titleText3")
    {
    div2.className =  "titleText3";
    div.className =  "text"; 
    }
    else
        {
         div2.className =  "text"; 
         div.className =  "titleText3"; 
        }

}

function compararPassword()
{

p1 = document.formulario.passwordLogueado;

alert(p1);

}

function activarBloque(total,inicial,obj)
{

var bucle = 0;

if(obj.checked==true)
   { opcion = true;
     suma = 1;
    }
        else
     {       opcion = false;
     		 suma = -1;
		}

while(bucle < total)
	{	
	
		if(document.getElementById("check"+inicial).checked != opcion)
			contador += suma;
		
		document.getElementById("check"+inicial).checked = opcion;
		
		inicial++;
		bucle++;
	}

}

function activarTodas(obj)
{

var continuar = true;
var bucle = 0;
var opcion = "";
var suma = 0; 


if(obj.checked==true)
   { opcion = true;
     suma = 1;
    }
        else
     {       opcion = false;
     		 suma = -1;
		}

if(document.getElementById("portada").alt!="1")
{ 

if(document.getElementById("portada").checked != opcion)
	contador += suma;

document.getElementById("portada").checked = opcion;

}


while(continuar&&(bucle < 200))
	{
	
		try{
				
		document.getElementById("bloqueCk"+bucle).checked = opcion;
		
		}
		catch(error)
		{
			continuar = false;
		}
		
	
	
		bucle++;
	}

	
continuar = true;
bucle = 0;

while(continuar&&(bucle < 200))
	{
		try{
		
		if(document.getElementById("check"+bucle).checked != opcion)
			contador += suma;
		
		document.getElementById("check"+bucle).checked = opcion;
		
		}
		catch(error)
		{
			continuar = false;
		}
		
		bucle++;
		
	
	}
	

}


function sendLoguear()
{
		errorText = document.getElementById('error3');
        errorText.innerHTML = ''; 

		var email= /^[^@ ]+@[^@ ]+.[^@ .]+$/; 
		
		var t1=email.test(document.formularioLoguear.email3.value); 
		
		var retorno = true;
         
		if( document.formularioLoguear.email3.value.length<1 || !t1 )
		{
			document.getElementById('error3').style.display = '';
			
			document.getElementById('email3text').className = 'text error';
			document.getElementById('email3').className = 'fieldFormError';
			
			errorText = document.getElementById('error3');
			
			if(retorno == false)
				errorText.innerHTML += '<div style="height:10px;"></div>'; 
			
			errorText.innerHTML += error2; 
			
			retorno = false;
		}
 
		if(document.formularioLoguear.password.value.length<1)
		{
			document.getElementById('error3').style.display = '';
			
			document.getElementById('passwordText').className = 'text error';
			document.getElementById('password').className = 'fieldFormError';
			errorText = document.getElementById('error3');
			
			if(retorno == false)
				errorText.innerHTML += '<div style="height:10px;"></div>'; 
			
			errorText.innerHTML += error14; 
			retorno = false;
		}
		
		if(document.getElementById('recordar').checked)
		{
			setYearCookie("front_email",document.formularioLoguear.email3.value);
			setYearCookie("front_password",document.formularioLoguear.password.value);
			setYearCookie("front_recordar","checked");
		}
		else
		{
			delCookie("front_email");
			delCookie("front_password");
			delCookie("front_recordar");
		}
 
    	return retorno;
}

function sendAnular(){


		errorText = document.getElementById('error2');
        errorText.innerHTML = ''; 

         var email= /^[^@ ]+@[^@ ]+.[^@ .]+$/; 
         
         var t1=email.test(document.formularioAnular.email2.value); 
         
         var retorno = true;
 
         if(error13 != null)
         {
         
         	if(document.formularioAnular.textoBaja.value.length<1)
         	{
         	
         
           	document.getElementById('error2').style.display = '';
        
          	document.getElementById('textoBajaText').className = 'text error';
         	errorText = document.getElementById('error2');
         	errorText.innerHTML = error13; 
         	retorno = false;
         	
         	}
         
         }
         
         if( document.formularioAnular.email2.value.length<1 || !t1 ){
         
          document.getElementById('error2').style.display = '';
            
          document.getElementById('email2text').className = 'text error';
          document.getElementById('email2').className = 'fieldFormError';
          
          errorText = document.getElementById('error2');
                     
          if(retorno == false)
         	errorText.innerHTML += '<div style="height:10px;"></div>'; 
                 
          errorText.innerHTML += error2; 
         

         
         	retorno = false;
         
            }
    
    
    	return retorno;
    
}





function send(){

      
    var my_array = new Array;

    var email= /^[^@ ]+@[^@ ]+.[^@ .]+$/;
       
    var error="";
     
    var t1=email.test(document.formulario.email.value);
     
    if( document.formulario.nombre.value.length<1 ){//|| !t1){
        error+=error1+"\n"; //"El campo nombre está vacío. \n";
        my_array['nombre']=false;
    }
    else
        my_array['nombre']=true;

    if( document.formulario.email.value.length<1 || !t1 ){
        error+=error2; //"El campo email está vacío o es incorrecto. \n";
        my_array['email']=false;
    }
    else
        my_array['email']=true;   
      
    
    if(contador <= 0)
        error+=error4; //seleccione alguna seccion
        
	if (error5 != null) {
		if (document.formulario.nombre2.value.length < 1 ) {
			error += error5; //"El campo nombre2 está vacío o es incorrecto. \n";
			my_array['nombre2'] = false;
		}
		else 
			my_array['nombre2'] = true;
	}

	if (error6 != null) {
		if (document.formulario.apellidos.value.length < 1 ) {
			error += error6; //"El campo apellidos está vacío o es incorrecto. \n";
			my_array['apellidos'] = false;
		}
		else 
			my_array['apellidos'] = true;
	}
	
	if (error7 != null) {
		if (document.formulario.pais.value < 0 ) {
			error += error7; //"El campo pais está vacío o es incorrecto. \n";
			my_array['pais'] = false;
		}
		else 
			my_array['pais'] = true;
	}
	
	if (error8 != null) {
		if (document.formulario.provincia.value < 0 && document.formulario.provinciaTexto.value == "") {
			error += error8; //"El campo provincia está vacío o es incorrecto. \n";
			my_array['provincia'] = false;
		}
		else 
			my_array['provincia'] = true;
	}
	
	if (error9 != null) {
		if (document.formulario.ciudad.value.length < 1 ) {
			error += error9; //"El campo ciudad está vacío o es incorrecto. \n";
			my_array['ciudad'] = false;
		}
		else 
			my_array['ciudad'] = true;
	}
	
	if (error10 != null) {
		if (document.formulario.cp.value.length < 1 ) {
			error += error10; //"El campo cp está vacío o es incorrecto. \n";
			my_array['cp'] = false;
		}
		else 
			my_array['cp'] = true;
	}
	
	if (error11 != null) {
		if (document.formulario.conocio.value < 0 ) {
			error += error11; //"El campo conocio está vacío o es incorrecto. \n";
			my_array['conocio'] = false;
		}
		else 
			my_array['conocio'] = true;
	}

	if (error12 != null) {
		if (document.formulario.sugerencia.value.length < 1 ) {
			error += error12; //"El campo sugerencia está vacío o es incorrecto. \n";
			my_array['sugerencia'] = false;
		}
		else 
			my_array['sugerencia'] = true;
	}

	if (error16 != null) {
		if (document.formulario.passwordLogeado.value.length < 6 ) {
			error += error16; //"El campo password tiene menos de 6 digitos. \n";
			my_array['passwordLogeado'] = false;
		}
		else 
			my_array['passwordLogeado'] = true;
	}

	if (error17 != null) {
		if (document.formulario.passwordLogeado.value !=  document.formulario.passwordLogeado2.value  ) {
			error += error17; //"Los campos de password no coinciden \n";
			my_array['passwordLogeado2'] = false;
		}
		else 
			my_array['passwordLogeado2'] = true;
	}
			

    if(error!=""){
        
        document.getElementById('error').style.display = '';  
        showErrors(error,my_array);
        return false;
    }
 
    return true;


}

function showErrors(s,a){
    
    primero = true;
    for (var i in a) {
		if (i == 'nombre' || i == 'email' || i == 'nombre2' || i == 'apellidos' ||
		i == 'ciudad' || i == 'cp') {
			if (!a[i]) {
				eval("document.getElementById('" + i + "Text').className = 'text error'");
				eval("document.getElementById('" + i + "').className = 'fieldFormError'");
				if (primero) {
					eval("document.getElementById('" + i + "').focus();");
					primero = false;
				}
			}
			else {
				eval("document.getElementById('" + i + "Text').className = 'text'");
				eval("document.getElementById('" + i + "').className = 'fieldForm'");
			}
		}
		else {
				if (i == 'sugerencia') {
					if (!a[i]) {
						eval("document.getElementById('" + i + "Text').className = 'text error'");
						eval("document.getElementById('" + i + "').className = 'textoFormularioError'");
						if (primero) {
							eval("document.getElementById('" + i + "').focus();");
							primero = false;
						}
					}
					else {
						eval("document.getElementById('" + i + "Text').className = 'text'");
						eval("document.getElementById('" + i + "').className = 'textoFormulario'");
					}
				}else{
					if (i == 'pais' || i == 'provincia' || i == 'conocio') {
						primero = false;
						if (!a[i]) {
							eval("document.getElementById('" + i + "Text').className = 'text error'");
				}
						else {
							eval("document.getElementById('" + i + "Text').className = 'text'");
						}
					}
				}
			}
	}
      
        
    if(error!=null)
        while(error.firstChild != undefined)
            error.removeChild(error.firstChild);
     
   
            
    error = document.getElementById('error');
    
    var oo= s.split("\n");
    
    for(i=0;i<oo.length;i++){
    
        var mySpan = document.createElement('p');
    
        mySpan.setAttribute('class','datosUsuarioError');
    
        var texto=document.createTextNode(oo[i]);
    
        mySpan.appendChild(texto);
        
        error.appendChild(mySpan);
       
    }
      

}
