var initVolume = 75;

var player;
function playerReady(obj) {
    var id = obj['id'];
    var version = obj['version'];
    var client = obj['client'];
    //alert('the videoplayer '+id+' has been instantiated');
    player = document.getElementById(id);
    //player.style.display = "none"; // Descarga el objeto... que raro...

    $("#demo").click(function(e){
        e.preventDefault();
        player.sendEvent("LOAD",this.href);
    });

    $("a.media").live("click",function(e){
        e.preventDefault();
        player.sendEvent("LOAD",this.href);
    });

};

var flashvars = {
    //file: "002.mp3",
    //image: "preview.jpg",
    type: "sound",
    autostart: "true",
    volume: initVolume,
    showfsbutton: "false",
    usefullscreen: "false"
};
var params = {
    menu: "false",
    allowfullscreen: "false",
    allowscriptaccess: "always"
};
var attributes = {
    id: "audio",
    name: "audio"
};







$(document).ready(function(){

	
	
	/*
	///MUESTRA LA VENTANA MODAL///////////////////////////
	var id = "#dialog"; //$('').attr('href');		

	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	//Set heigth and width to mask to fill up the whole screen
	$('#mask').css({'width':maskWidth,'height':maskHeight});
	
	//transition effect		
	$('#mask').fadeIn(1000);	
	$('#mask').fadeTo("slow",0.8);	

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();
      
	//Set the popup window to center
	$(id).css('top',  winH/2-$(id).height()/2);
	$(id).css('left', winW/2-$(id).width()/2);

	//transition effect
	$(id).fadeIn(2000); 
	
	//if close button is clicked
	$('#cerrar_mask, #dialog').click(function (e) {
		//Cancel the link behavior
		//e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});
	///FIN CODIGO MUESTRA LA VENTANA MODAL///////////////////////////
	*/
	
	
       swfobject.embedSWF("../com/jwplayer/jwplayer41.swf", "jwplayer", "0", "0", "9.0.0","expressInstall.swf", flashvars, params, attributes);
	function isValidEmail(email){
       	 var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	        return filter.test(email);
	}


	function isEmpty(val){
   	     if(val.match(/^s+$/) || val == "")
		 return true;
	     else
		 return false;
       }

	$("#lblligachat").click(function(){
	    window.open("/chat/client.php?language=sp","ChatiSerenata","width=690,height=400")
	    
	});
	
	$("#imgligachat").click(function(){
	    window.open("/chat/client.php?language=sp","ChatiSerenata","width=690,height=400")
	    
	});

	$("#btnCalificar").click(function(){
		var  u_pregunta = $("#hdnu_pregunta").val();
		var  u_respuesta = $("input[@name='u_respuesta']:checked").val();
		//alert('u_pregunta=' + u_pregunta + "&u_respuesta=" + u_respuesta);
		$.ajax(
		{
			url: '../insertencuestarapida.php',
			type: 'POST',
			dataType: 'json',
			data:'u_pregunta=' + u_pregunta + "&u_respuesta=" + u_respuesta,
			error: function(){
				alert('Error!!!!!! Llamar al (01-800-1473736)  Gracias');
		  	       $("#btnCalificar").attr("disabled",false);			
			},
			success: function(data){		  					
				if (data.respuesta == "exito"){
					window.location = 'index2.php';
			      }
			}
		});
			
						
		$("#btnCalificar").attr("disabled",false);
	});


	//if ($("#img_escucha_cancion").length) { 
		//$("#img_escucha_cancion").live("click",function(e){
		// $(".floatleft").parent().css({ backgroundColor:"white" });
		// $(this).parent().parent().children(".floatleft").css({ backgroundColor:"#e5f0ff" });
		//});
	//}


	if ($("#sel_cancionmain").length){
	$("#sel_cancionmain").live("click",function(e){
		//alert("fff");
		//$(".floatleft").children(".title").css({ backgroundColor:"white" });
		//$(".floatleft1").parent().children(".sel_cancion").css({ backgroundColor:"blue" });

		//$(".floatleft1").children(".title").css({ backgroundColor:"white" });
		//alert("fff");
		//alert($(this).parent().parent().children(".floatleft1").children(".title").text());
		//$(this).parent().parent().chlindren(".sel_cancion").css({ backgroundColor:"blue" });

		$(".floatleft1").css({ backgroundColor:"#ffffff" });		 
		$(".sel_cancion").css({ backgroundColor:"#ffffff" });		 
		$(this).parent().parent().children(".sel_cancion").css({ backgroundColor:"#e5f0ff" });
		$(this).parent().parent().children(".floatleft1").css({ backgroundColor:"#e5f0ff" });

		 selected = this;
		 var songId = $(selected).parent().parent().attr("id");  //obtengo el id de la cancion
		 songId = songId.substring(1,4);
		 $("#post_id_cancion").val(songId);


		if ($(selected).parent().parent().children(".floatleft1").children(".titleoculto").text() == "")
			 var songNombre = $(selected).parent().parent().children(".floatleft1").children(".title").text();  //obtengo el id de la cancion		 
		 else
			var songNombre = $(selected).parent().parent().children(".floatleft1").children(".titleoculto").text();  //obtengo el id de la cancion		 

		 $("#txt_nombrerola").val(songNombre);
		 //alert(songId  + " " + songNombre);

		

		
	});
	}


	if ($("#sel_cancionmain2").length) { 

		$("#sel_cancionmain2").live("click",function(e){

		 //$(".floatleft").children(".title").css({ backgroundColor:"white" });
		 //$(this).parent().children(".floatleft").children(".title").css({ backgroundColor:"#e5f0ff" });
		 //alert($(this).parent().parent().children(".floatleft").children(".title").text());	

		 selected = this;
		 var songId = $(selected).parent().parent().attr("id");  //obtengo el id de la cancion
		 songId = songId.substring(1,4);

		 //alert(songId);
		 //alert($(selected).parent().parent().children(".floatleft").children(".titleoculto").text());

		 if ($(selected).parent().parent().children(".floatleft1").children(".titleoculto").text() == "")
			 $("#envia input[name=txt_nombrerola]").val($(selected).parent().parent().children(".floatleft1").children(".title").text());
		else
			 $("#envia input[name=txt_nombrerola]").val($(selected).parent().parent().children(".floatleft1").children(".titleoculto").text());


		 //alert($("#envia input[name=txt_nombrerola]").val()); 

	        $("#envia input[name=post_id_cancion]").val(songId);
		 $("#btn_envia").click();		


		});
	}	 


	$("#enviar_sere").click(function(e){
		window.location = 'iserenata2.php';
	});
	

	$("#btn_invita").click(function(e){


	var txt_amigo1 = $("#txt_amigo1").val();
	var txt_amigo2 = $("#txt_amigo2").val();
	var txt_tunombre = $("#txt_tunombre").val();

	

	// Hide 'Submit' Button
	$('#btn_invita').hide();

	// Show Gif Spinning Rotator
	$('#ajax_loading').show();	



	if (txt_tunombre == "Tu nombre o nick" || txt_tunombre == ""){
		// Hide 'Submit' Button
		$('#btn_invita').show();

		// Show Gif Spinning Rotator
		$('#ajax_loading').hide();	
		return;
	}	


	if(!isValidEmail(txt_amigo1)  && txt_amigo1 != "E-mail 1" )
	{
		valid = false;
		//showError("email","Escribe un email válido");
	       //$("#btnregistrar").attr("disabled",false);
		alert("Introduzca un Email Valido....");
		$("#txt_amigo1").focus();


		// Hide 'Submit' Button
		$('#btn_invita').show();

		// Show Gif Spinning Rotator
		$('#ajax_loading').hide();	

		return;
       }



	if(!isValidEmail(txt_amigo2) && txt_amigo2 != "E-mail 2")
	{
		valid = false;
		//showError("email","Escribe un email válido");
	       //$("#btnregistrar").attr("disabled",false);
		alert("Introduzca un Email Valido....");
		$("#txt_amigo2").focus();


		// Hide 'Submit' Button
		$('#btn_invita').show();

		// Show Gif Spinning Rotator
		$('#ajax_loading').hide();	

		return;
       }
			


	
	if ( txt_amigo2 != "E-mail 2" ||  txt_amigo1 != "E-mail 1"){ //Envio del Email
		
		$("#envia").attr("value","ENVIAR");
		$.ajax(
		{
			url: 'enviaemailsrecomienda.php',
			type: 'POST',
			dataType: 'json',
			data:'nombre=' + txt_tunombre + "&amigo1=" + txt_amigo1 + "&amigo2=" + txt_amigo2,
			error: function(){
				alert('Error!!!!!! Llamar al (01-800-1473736)  Gracias');
			
			},
			success: function(data){		  					
				if (data.respuesta == "exito"){
					alert("Se ha enviado la invitacion a tus amigos...\nInvita a mas Amigos!!");
					
					$('#txt_amigo1').attr('value','E-mail 1');	
					$('#txt_amigo2').attr('value','E-mail 2');	
					$('#txt_tunombre').attr('value','Tu nombre o nick');	

					

					// Hide 'Submit' Button
					$('#btn_invita').show();

					// Show Gif Spinning Rotator
					$('#ajax_loading').hide();

					//window.location = 'index.php';
			      }
			     else
				alert("Escriba al menos un Email..");	

			}
		});

	}
	else{

					// Hide 'Submit' Button
					$('#btn_invita').show();

					// Show Gif Spinning Rotator
					$('#ajax_loading').hide();
	}


	


	});






	$("#submit").click(function(){
	
		var email = $("#email").val();
		var password = $("#password").val();
	

		// Hide 'Submit' Button
		$('#submit').hide();

		// Show Gif Spinning Rotator
		$('#ajax_loading_reg').show();	
	

		$.ajax({
		    url: '../user/verifica_login_registrate.php',
		    type: 'POST',
		    dataType: 'json',
			data:'email=' + email + "&password=" + password,
		    //timeout: 1000,
		    error: function(){
			
		        alert('Verifique su usuario o password....');
				// Hide 'Submit' Button
				$('#submit').show();

				// Show Gif Spinning Rotator
				$('#ajax_loading_reg').hide();					
			
		    },
			
		    success: function(data){		  
				if (data.respuesta == "exito")
					window.location = 'adminusuario3.php'; // Members Area												
		    }


		
		});
	
	
	});


	$("#btn_envia").click(function(e){

		var txt_de = $("#txt_de").val();
		var txt_para = $("#txt_para").val();
	
		$("#envia").attr("action","iserenata.php");
	       $("#envia").attr("method","post");			
		$("#envia input[name=hdn_de]").val(txt_de);
		$("#envia input[name=hdn_para]").val(txt_para);
		$("#envia").submit();			
    
    	});


/*

	$("#btn_envia").click(function(e){

		var txt_de = $("#txt_de").val();
		var txt_para = $("#txt_para").val();

		//if (txt_de !=  "" && txt_para != "" ) {		
		$("#envia").attr("action","iserenata.php");
              $("#envia").attr("method","post");			
		$("#envia input[name=hdn_de]").val(txt_de);
		$("#envia input[name=hdn_para]").val(txt_para);
		$("#envia").submit();			
		//}	    
    	});

*/


	$("#pleca_registrate").click(function(e){
		window.location = 'registro.php';			
	});

	


	$("#escucha_grabacion").click(function(e){

		window.location = 'evidencia.php';

	}); 



	$("#sel_cancionmain").hover(
      		function () {
        		
			$(this).attr('src','../img/escuchad.png');
      		},
	
		function () {
        		$(this).attr('src','../img/escuchaup.png');

      		}
	

    	);





	$("#img_escucha_cancion").hover(
      		function () {
			$(this).attr('src','img/play.png');
      		},
	
		function () {
        		$(this).attr('src','img/play.png');

      		}
	

    	);



	$("#sel_cancionmain").hover(
      		function () {
        		
			$(this).attr('src','../img/escuchad.png');
      		},
	
		function () {
        		$(this).attr('src','../img/escuchaup.png');

      		}
	

    	);


	$("#btn_escucha-una-demo").hover(
      		function () {
        		
			$(this).attr('src','../img/btn_escucha-una-demo_over.png');
      		},
	
		function () {
        		$(this).attr('src','../img/btn_escucha-una-demo.png');

      		}
	

    	);


	$("#btn_escucha-tu-iserenata").hover(
      		function () {
        		
			$(this).attr('src','../img/btn_escucha-tu-iserenata_over.png');
      		},
	
		function () {
        		$(this).attr('src','../img/btn_escucha-tu-iserenata.png');

      		}
	

    	);


	$("#btn_ve-como-funciona").hover(
      		function () {
        		
			$(this).attr('src','../img/btn_ve-como-funciona_over.png');
      		},
	
		function () {
        		$(this).attr('src','../img/btn_ve-como-funciona.png');

      		}
	

    	);



	$("#btn_invita").hover(
      		function () {
			$(this).attr('src','../es/img/enviardown.png');

      		},
	
		function () {
        		$(this).attr('src','../es/img/enviarup.png');

      		}
	

    	);

	$("#btn_envia").hover(
      		function () {
			$(this).attr('src','img/enviarS_dow.png');

      		},
	
		function () {
        		$(this).attr('src','img/enviarS_up.png');

      		}
	

    	);

/*
	$("#escucha_demo").hover(
      		function () {
//			alert("ddd");	
			$(this).css('background', 'url(img/demo_up.jpg)');

      		},
	
		function () {
  			$(this).css('background', 'url(img/demo_dow.jpg)');

      		}
	

    	);

*/


	



	$("#txt_de").click(function(e){
		document.getElementById("txt_de").select();
		//$(this).attr('value','');

	});

	$("#txt_para").click(function(e){
		document.getElementById("txt_para").select();
		//$(this).attr('value','');

	});

	$("#txt_tunombre").click(function(e){
		document.getElementById("txt_tunombre").select();
		//$(this).attr('value','');
	});

	$("#txt_amigo1").click(function(e){
		document.getElementById("txt_amigo1").select();
		//$(this).attr('value','');
	});

	$("#txt_amigo2").click(function(e){
		document.getElementById("txt_amigo2").select();
		//$(this).attr('value','');
	});


	$("#liga_enviar_cancion").click(function(e){
		var post_id_cancion = $("#post_id_cancion").val();
		var txt_cancion = $("#txt_nombrerola").val();
	
		//alert("entro1");
		//alert(txt_cancion + " " + post_id_cancion);
		$("#envia_cancion").attr("action","iserenata2.php");
		$("#envia_cancion").attr("method","post");			
		$("#envia_cancion input[name=txt_nombrerola]").val(txt_cancion);
		$("#envia_cancion input[name=post_id_cancion]").val(post_id_cancion);
		$("#envia_cancion").submit();	
	});


	$("#liga_enviar_cancion_top_ten").click(function(e){
		var post_id_cancion = $("#post_id_cancion").val();
		var txt_cancion = $("#txt_nombrerola").val();
	
		//alert(txt_cancion + " " + post_id_cancion);
		$("#envia_cancion").attr("action","iserenata2.php");
		$("#envia_cancion").attr("method","post");			
		$("#envia_cancion input[name=txt_nombrerola]").val(txt_cancion);
		$("#envia_cancion input[name=post_id_cancion]").val(post_id_cancion);
		$("#envia_cancion").submit();	
	});
	

	$("#liga_enviar_cancion_mananitas").click(function(e){
		var post_id_cancion = $("#post_id_cancion").val();
		var txt_cancion = $("#txt_nombrerola").val();
	
		//alert(txt_cancion + " " + post_id_cancion);
		$("#envia_cancion").attr("action","iserenata2.php");
		$("#envia_cancion").attr("method","post");			
		$("#envia_cancion input[name=txt_nombrerola]").val(txt_cancion);
		$("#envia_cancion input[name=post_id_cancion]").val(post_id_cancion);
		$("#envia_cancion").submit();	
	});


	$("#liga_enviar_cancion_jorge").click(function(e){
		var post_id_cancion = $("#post_id_cancion").val();
		var txt_cancion = $("#txt_nombrerola").val();
	
		//alert(txt_cancion + " " + post_id_cancion);
		$("#envia_cancion").attr("action","iserenata2.php");
		$("#envia_cancion").attr("method","post");			
		$("#envia_cancion input[name=txt_nombrerola]").val(txt_cancion);
		$("#envia_cancion input[name=post_id_cancion]").val(post_id_cancion);
		$("#envia_cancion").submit();	
	});	
	
	$("#enviarcancion").click(function(e){
		var post_id_cancion = $("#post_id_cancion").val();
		var txt_cancion = $("#txt_nombrerola").val();
		var post_mensaje = $("#post_mensaje").val();
	
		//alert("entro2");
		//alert(txt_cancion + " " + post_id_cancion);
		$("#envia_cancion").attr("action","iserenata2.php");
		$("#envia_cancion").attr("method","post");			
		$("#envia_cancion input[name=txt_nombrerola]").val(txt_cancion);
		$("#envia_cancion input[name=post_id_cancion]").val(post_id_cancion);
		$("#envia_cancion input[name=post_mensaje]").val(post_mensaje);
		$("#envia_cancion").submit();	
	});
	
	$("#cerrar_session").click(function(){
	
		$.ajax({
		    url: 'cierra_sesion.php',
		    type: 'POST',
		    //dataType: 'json',
			//data:'x',			    
		    error: function(){
			
			alert('Error al Cerrarse la session');
			
		    },			
		    success: function(){		  					
					alert("Su Session se ha Cerrado Correctamente");
					window.location="index2.php";					
		    }
		
		});
	
	});


	$("#b_left_content_demo").click(function(){

		//var opcion = 1;
		//logeomenus(opcion);

	});

	$("#b_left_content_grabacion").click(function(){

		//var opcion = 2;
		//logeomenus(opcion);

	});

	$("#b_left_content_chat").click(function(){

		//var opcion = 3;
		//logeomenus(opcion);

	});

	$("#b_left_content_amigo").click(function(){

		//var opcion = 4;
		//logeomenus(opcion);

	});

	
	



	function logeomenus(opcion){


		$.ajax({
		    url: 'almacenalogmenus.php',
		    type: 'POST',
		    //dataType: 'json',
		    data:'opcion=' + opcion,			    
		    error: function(){
			
			alert('Error');
			
		    },			
		    success: function(){		  					
			//alert("exito");

		    }
		
		});

	}


});



