// JavaScript Document



var ajax;







function registraUsuario(typeuser){



	



	var email 	  = document.getElementById('email').value;



	var nick 	  = document.getElementById('nick').value;



	var pass      = document.getElementById('password').value;



	var cpass     = document.getElementById('cpassword').value;



	var nombre 	  = document.getElementById('nombre').value;



	var apellido  = document.getElementById('apellidos').value;



	



	var codigoPostal = document.getElementById('codigoPostal').value;



	



	//var pais = document.getElementById('pais').value;



	var provincia = document.getElementById('provincia').value;



	var dia       		= document.form1.Day.value;



	var mes       		= document.form1.Month.value;



	var year      		= document.form1.Year.value;





	var fechaNac  = year+'-'+mes+'-'+dia;



	try{



		var cuentaPaypal 	= document.getElementById('cuentaPaypal').value;



		var numero;



		for(i=1;i<=5;i++)



		{



			if(document.getElementById("propiedad"+i).checked == true)



				numero = i;



		}



	



	}catch(error){



		



		}







 	



	pass2=pass;



		 pass=hex_md5(pass);



		 ajax=Ajax();



		 url='';



		 switch(typeuser){



		 	 case 1: url='procesos/reg_artista.php';



			 break;



			 case 2: url='procesos/reg_label.php';



			 break;



			 case 3: url='procesos/reg_nuevo_usuario.php'



			 }



		 ajax.onreadystatechange = procesarEventoRegistro;



		 ajax.open("POST", url, true);



		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");



		 send="nick="+nick+"&email="+email+"&pass="+pass+"&nombre="+nombre+"&apellido="+apellido+"&codigoPostal="+codigoPostal;



		 send+="&fechan="+fechaNac+"&provincia="+provincia+"&fec="+fechaNac+pass2+"&propiedad="+numero+"&cuentaPaypal="+cuentaPaypal;



		 ajax.send(send);



		 



	



	



}







function ModificaUsuario(){



	



	



	            var coduser   = document.getElementById('coduser').value;



				var nombre 	  = document.getElementById('nombre').value;



				var apellido  = document.getElementById('apellidos').value;



				var localidad = document.getElementById('localidad').value;



				//var pais 	  = document.getElementById('pais').value;



				var provincia 	  = document.getElementById('provincia').value;



				



				var codigoPostal = document.getElementById('codigoPostal').value;



				



				alert(codigoPostal);



				



				var dia       = document.form1.Day.value;



				var mes       = document.form1.Month.value;



				var year      = document.form1.Year.value;



				var fechaNac  = year+'-'+mes+'-'+dia;



				var cuentaPaypal = document.getElementById('cuentaPaypal').value;



				var numero;



				for(i=1;i<=5;i++)



				{



					if(document.getElementById("propiedad"+i).checked == true)



						numero = i;



				}



	



	



		



         var loader = document.getElementById("loader");



		 ajax=Ajax();



		



		 ajax.onreadystatechange = function(){



			 



			  if(ajax.readyState == 4)



  				{  



				//arrMensaje[0] The basic data have been updated



                 alert(arrMensaje[0]);



	 			loader.innerHTML='';



				}



  



  



 



			 



		 };



		 ajax.open("POST",'procesos/upd_datos_basicos.php', true);



		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");



		 send="coduser="+coduser+"&nombre="+nombre+"&apellido="+apellido+"&codigoPostal="+codigoPostal;



		 send+="&localidad="+localidad+"&fechan="+fechaNac+"&provincia="+provincia+"&propiedad="+numero+"&cuentaPaypal="+cuentaPaypal;



		 ajax.send(send);



		 



	



	



}







function enviarCambioClave(){



	



	



	          



				var email_send = document.getElementById('email_send').value;



				



	



		



         var loader = document.getElementById("loader");



		 ajax=Ajax();



		



		 ajax.onreadystatechange = function(){



			 



			  if(ajax.readyState == 4)



  				{    



				 //arrMensaje[0] Los datos basicos fueron actualizados



                 alert(arrMensaje[0]);



	 			//loader.innerHTML='';



				document.getElementById('image').src = 'includes/securimage/securimage_show.php?sid=' + Math.random();



			    document.getElementById('codesecure').value='';



				document.getElementById('email_send').value='';



				}



  



  



 



			 



		 };



		 ajax.open("POST",'procesos/upd_olvide_clave.php', true);



		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");



		 send="email="+email_send;



		 ajax.send(send);



		 



	



	



}







function verificaCodigoCambioClave(){   	



		 ajax=Ajax();



		 var valor=0;



		 var codesecure= document.getElementById('codesecure').value;



		 var msjContent= document.getElementById('msjcontent');



		  ajax.open("POST", 'procesos/verifica_code.php', true);



		 



		 ajax.onreadystatechange = function(){



		    if(ajax.readyState == 4 )



				{				  



				  valor = ajax.responseText;



				  



				  if(valor == 1){	



				  	 msjContent.innerHTML= ''; 		



					 verificaEmailCambioClave();



				   				 



				  }else{



					  msj='<span style="color:#FF0000; font:Verdana, Arial, Helvetica, sans-serif x-small italic bold">';



		              msj +='[ '+'El codigo no es correcto'+' ]</span>';	



	                  msjContent.innerHTML= msj; 



					  document.getElementById('image').src = 'includes/securimage/securimage_show.php?sid=' + Math.random();



					  document.getElementById('codesecure').value='';



				  }



			}



			



		



				



	     }



		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	 



		 send="codesecure="+codesecure;



		 ajax.send(send);	



		



		 



}







function verificaEmailCambioClave(){   	



		 ajax=Ajax();



		 var valor=0;



		 var email_send= document.getElementById('email_send').value;



		 var msjContent= document.getElementById('msjcontent');



		  ajax.open("POST", 'procesos/check_user.php', true);



		 



		 ajax.onreadystatechange = function(){



		    if(ajax.readyState == 4 )



				{				  



				  valor = ajax.responseText;



				  



				  if(valor == 1){		



					enviarCambioClave();



				   	msjContent.innerHTML= ''; 			 



				  }else{



					  msj='<span style="color:#FF0000; font:Verdana, Arial, Helvetica, sans-serif x-small italic bold">';



					 //arrMensaje[3]='La cuenta de email no existe';



					  msj +='[ '+'El usuario no existe'+' ]</span>';



					   document.getElementById('image').src = 'includes/securimage/securimage_show.php?sid=' + Math.random();



					  document.getElementById('codesecure').value='';



	                  msjContent.innerHTML= msj; 



					 



					 



				  }



			}



			



		



				



	     }



		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	 



		 send="nick="+email_send;



		 ajax.send(send);	



		



		 



}











function procesarEventos()



{



	try{



  var contenedor = document.getElementById("response_principal");



//  var loader = document.getElementById("loader");



//  loader.innerHTML='<img src="img/loader.gif"  style="margin-left:230px; margin-top:2px" onClick="ajax.abort()" />';



  



  if(ajax.readyState == 4)



  {    



    contenedor.innerHTML = ajax.responseText;



	 loader.innerHTML='';



  }



  }catch(__e__){}



}







function procesarEventoRegistro()



{



	try{



  var contenedor = document.getElementById("response_principal");



//  var loader = document.getElementById("loader");



//  loader.innerHTML='<img src="img/loader.gif"  style="margin-left:230px; margin-top:2px" onClick="ajax.abort()" />';



  



  if(ajax.readyState == 4)



  {    



     responseRegistroBd(); 



	 loader.innerHTML='';



  }



	}catch(__e__){}



  



}















function responseRegistroBd() 
{
	var tipoRegistro;
	tipoRegistro = 0;
	try
	{
		var artista  = document.getElementById('radio');
		var sello  = document.getElementById('radio2');
		if(artista.checked == true)
		{
			tipoRegistro = 1;
		}
	
		if(sello.checked == true)
		{
			tipoRegistro = 2;
		}
	}
	catch(e) {}

	if(tipoRegistro == 1 || tipoRegistro == 2)
	{
  	alert("Se te ha enviado un correo para que confirmes tu registro\nCuando inicies sesión podr\u00e1s subir tus canciones");
	}
	else
	{
		alert("Se te ha enviado un correo para que confirmes tu registro");
	}
	
  window.location.href = "index.php";
}







function cambiarImagenSeguridad() 



{



    var contenedorImg=document.getElementById('imgsecure'); 



     ajax=Ajax();



	 ajax.open("GET", 'imagen_secure.php', true);



  	 ajax.onreadystatechange = function(){



		    if(ajax.readyState == 4 )



				{			  



				 contenedorImg.innerHTML=ajax.responseText; 			 



			    }



			



	}



  



    ajax.send(null);



  



  



}















var valor;



 function submitRegisterForm(typeuser)
 {  
   var errorval = false;
   var msjContent= document.getElementById('msjcontent');
   var bandera = true;
   var email = document.getElementById('email').value;
   var pass = document.getElementById('password').value;
   var cpass = document.getElementById('cpassword').value;
   var nombre = document.getElementById('nombre').value;
   var apellido = document.getElementById('apellidos').value;
   var nick	= document.getElementById('nick').value;
   //var pais = document.getElementById('pais').value;
   var provincia = document.getElementById('provincia').value;
   var aceptt = document.getElementById('aceptt');

		if(nick.length < 3)
		{
			alert('El nombre de usuario es demasiado corto');
			bandera =false;
			return false;
		}
		
		if(!nick.match(/^[\w\-]*$/g))
		{
			alert('El nombre de usuario contiene caracteres no validos\nPuedes usar letras, n\u00Fameros, y gui\u00F3n');
			bandera =false;
			return false;
		}
		
   if(typeuser == 3)
   {
     var dia = document.form1.Day.value;
	 var mes = document.form1.Month.value;
	 var year = document.form1.Year.value;
	 var fechaNac = year+'-'+mes+'-'+dia;
   }
   else
   {
     var fechaNac = "";
   }

   var codigoPostal = document.getElementById('codigoPostal').value;

   try{
	var cuentaPaypal 	= document.getElementById('cuentaPaypal').value;
   }catch(error){
	errorval=true;
   }

   var banCheck = false;

   try{
	if(aceptt.checked != true)
	{
	  //banCheck = true;
	}
   }catch(___e___){}

   if(email.replace(/ /g, '')=='' || provincia.replace(/ /g, '')=='' || pass.replace(/ /g, '')=='' || cpass.replace(/ /g, '')=='' || nombre.replace(/ /g, '')=='' || apellido.replace(/ /g, '')=='' || nick.replace(/ /g, '')=='' || banCheck == true){
     alert(arrMensaje[3]);
     bandera =false; 	
   }
   else 
     if(!validarEmail(email)){
       alert(arrMensaje[4]);
       bandera =false;
     }
     else if(pass != cpass){
       alert(arrMensaje[5]);		
       pass.value='';
       cpass.value='';
       bandera =false;		
     }
     else if(validar_fecha(fechaNac)==false && typeuser == 3){
       alert(arrMensaje[6]);
       bandera =false;	
     }
     else bandera=true;	
	 
   if(bandera){
	 ajax=Ajax();
	 var valor=0;
	 var nick = document.getElementById('nick').value;
	 var msjContent = document.getElementById('msjcontent');
     ajax.open("POST", 'procesos/check_nick.php', true);
	 ajax.onreadystatechange = function(){
	    if(ajax.readyState == 4 )
		{				  
		  valor = ajax.responseText;
		  if(valor == 0){
		    //submitRegisterForm2(typeuser);
			//submitRegisterForm2(typeuser);
			ajax2=Ajax();
			var valor2 = 0;
			var correo = document.getElementById('email').value;
			var msjContent2 = document.getElementById('msjcontent');
			ajax2.open("POST", 'procesos/check_userMail.php', true);
			ajax2.onreadystatechange = function(){
			   if(ajax2.readyState == 4 )
			   {				  
				 valor2 = ajax2.responseText;
				 if(valor2 == 0)
				 {
				   submitRegisterForm2(typeuser);
				 }
				 else
				 {
				   alert(arrMensaje[217]);
				 }
			   }
			}
			ajax2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	 
			send2="nick="+correo;
			ajax2.send(send2);	
		  }else{
			alert(arrMensaje[7]);
		  }
		}
     }
	 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	 
	 send="nick="+nick;
	 ajax.send(send);	
   }
 }

function ModificaUsuarioVal(){  







    var msjContent= document.getElementById('msjcontent');



	var bandera   		= true;



	var email 	  		= document.getElementById('email').value;



	var nombre 	  		= document.getElementById('nombre').value;



	var apellido  		= document.getElementById('apellidos').value;



	var localidad		= document.getElementById('localidad').value;



	//var pais 			= document.getElementById('pais').value;



	var provincia 			= document.getElementById('provincia').value;



	var dia       		= document.form_registro.Day.value;



	var mes       		= document.form_registro.Month.value;



	var year      		= document.form_registro.Year.value;



	var fechaNac  		= year+'-'+mes+'-'+dia;



	var cuentaPaypal 	= document.getElementById('cuentaPaypal').value;



	



	



	if(email.replace(/ /g, '')=='' || provincia.replace(/ /g, '')=='' || nombre.replace(/ /g, '')=='' || apellido.replace(/ /g, '')=='' || localidad.replace(/ /g, '')==''){



		msj='<span style="color:#FF0000; font:Verdana, Arial, Helvetica, sans-serif x-small italic bold">';



		msj +='[ '+arrMensaje[3]+' ]</span> <span class="naranja_bold" style="font: large">&#8226; </span>';



	    msjContent.innerHTML = msj;



	    bandera =false; 	



	}



	else if(!validarEmail(email)){



	    msj='<span style="color:#FF0000; font:Verdana, Arial, Helvetica, sans-serif x-small italic bold">';



		msj +='[ '+arrMensaje[4]+' ]</span>';	



	    msjContent.innerHTML= msj;



	    bandera =false;



	}



	else if(validar_fecha(fechaNac)==false){



		msj='<span style="color:#FF0000; font:Verdana, Arial, Helvetica, sans-serif x-small italic bold">';



		msj +='[ '+arrMensaje[6]+' ] </span>';		



	    msjContent.innerHTML= msj;



	    bandera =false;	



		}



	



	



	else bandera=true;	



	



    if(bandera)



		ModificaUsuario();



		 



}







var valor;



function submitRegisterForm2(typeuser){   	



		 ajax=Ajax();



		 var valor=0;



		 var codesecure= document.getElementById('codesecure').value;



		 var msjContent= document.getElementById('msjcontent');



		  ajax.open("POST", 'procesos/verifica_code.php', true);



		 



		 ajax.onreadystatechange = function(){



		    if(ajax.readyState == 4 )



				{				  



				  valor = ajax.responseText;



				  



				  if(valor == 1){



					if(document.getElementById('condiciones').checked)



					 registraUsuario(typeuser);



				    else



					  alert(arrMensaje[8]);



				 



				  }else{



					  alert(arrMensaje[1]) 



					  //cambiarImagenSeguridad() ;



					  document.getElementById('image').src = 'includes/securimage/securimage_show.php?sid=' + Math.random();



					  document.getElementById('codesecure').value='';



				  }



			}



			



		



				



	     }



		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	 



		 send="codesecure="+codesecure;



		 ajax.send(send);	



		



		 



}



























function atrasMesProfile(mes,an,idartista){



  Calendario("calendario_profile.php?mes="+mes+"&anio="+an+"&idartista="+idartista);



}



function siguienteMesProfile(mes,an,idartista){



  Calendario("calendario_profile.php?mes="+mes+"&anio="+an+"&idartista="+idartista);



}



//	ModificaClave:	valida los datos del usuario para posteriormente solicitar 



//					el cambio de contraseña.



//



//



///////////////////////////////////////////////////////////////////////////////////



var estadoClave = false;



function validacionModificaClave()



{



	var formulario = document.getElementById('form_registro');



	var msjContent= document.getElementById('msjcontent');



	if(estadoClave == true)



	{



		if(formulario.newpass.value != '' && formulario.newpass.value == formulario.newPass2.value )



		{



			//formulario.newpass.value = hex_md5(formulario.newpass.value);



			msjContent.innerHTML= '';



			ModificaClave();



		}			



		else



		{



			msj='<span style="color:#FF0000; font:Verdana, Arial, Helvetica, sans-serif x-small italic bold">';



		    if(formulario.newpass.value != '')



				msj +='[ '+arrMensaje[9]+' ]</span>';



			else



				msj +='[ '+arrMensaje[10]+' ]</span>';



	        msjContent.innerHTML= msj;				



		}



	}		



	else



		varificarClave();



}







function varificarClave()



{



	var formulario = document.getElementById('form_registro');



	var msjContent= document.getElementById('msjcontent');



	if(formulario.oldPass.value != '')



	{



		var pass = hex_md5(formulario.oldPass.value);	



		if(pass == formulario.idUserPass.value)



		{



			estadoClave = true;



			msjContent.innerHTML= '';



		}



		else



		{



			msj='<span style="color:#FF0000; font:Verdana, Arial, Helvetica, sans-serif x-small italic bold">';



		    msj +='[ '+arrMensaje[11]+' ]</span>';	



	        msjContent.innerHTML= msj;



		}



	}



}











function ModificaClave(){



		



	   var pass	  = document.getElementById('newpass').value;



	   var passOld   = document.getElementById('oldPass').value



	   var coduser 	  = document.getElementById('coduser').value;



      //var loader = document.getElementById("loader");



		ajax=Ajax();



		



		 ajax.onreadystatechange = function(){



			 



			  if(ajax.readyState == 4)



  				{    



                 var textResponse = ajax.responseText;



				 	if(textResponse != '@@error@@' && textResponse !='')



				 	{



				 		document.getElementById('idUserPass').value = textResponse;



						alert(arrMensaje[13]);



	 					//loader.innerHTML='';



					}



					else



					{



						alert(arrMensaje[12]);	



					}



				} 



			 



		 };



		 ajax.open("POST",'procesos/upd_datos_clave.php', true);



		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");



		 send="iveg="+hex_md5(passOld)+"&contc="+passOld+"&ivag="+hex_md5(pass)+"&iart="+coduser;



		 ajax.send(send);	



	



}















function validacionModificaCuentaPaypal()



{



	var nuevaCuenta	  = document.getElementById('nuevaCuenta').value;



	var coduser 	  = document.getElementById('coduser').value;



     



		ajax=Ajax();



		



		 ajax.onreadystatechange = function(){



			 



			  if(ajax.readyState == 4)



  				{    



                 var textResponse = ajax.responseText;



				 	if(textResponse != '@@error@@' && textResponse !='')



				 	{



				 		//document.getElementById('idUserPass').value = textResponse;



						alert("Cuenta de Paypal modificada con éxito");



	 					//loader.innerHTML='';



					}



					else



					{



						alert("Error la modificar la Cuenta de Paypal");



					}



				} 



			 



		 };



		 ajax.open("POST",'procesos/upd_datos_paypal.php', true);



		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");



		 send="pp="+nuevaCuenta+"&iart="+coduser;



		 ajax.send(send);	



}