/*
Page:           rating.js
Created:        Aug 2006
Last Mod:       Mar 11 2007
Handles actions and requests for rating bars.	
--------------------------------------------------------- 
ryan masuga, masugadesign.com
ryan@masugadesign.com 
--------------------------------------------------------- */

var xmlhttp
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	  try {
	  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	   xmlhttp=false
	  }
	 }
	@else
	 xmlhttp=false
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	 try {
	  xmlhttp = new XMLHttpRequest();
	 } catch (e) {
	  xmlhttp=false
	 }
	}
	function myXMLHttpRequest() {
	  var xmlhttplocal;
	  try {
	    xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	    xmlhttplocal=false;
	  }
	 }

	if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
	 try {
	  var xmlhttplocal = new XMLHttpRequest();
	 } catch (e) {
	  var xmlhttplocal=false;
	  alert('couldn\'t create xmlhttp object');
	 }
	}
	return(xmlhttplocal);
}

function toggle(id_usuario,id_foto) {
  sndReq(id_usuario,id_foto);
}


function eliminar_comentario(id_comentario) {
 if (confirm("¿Quieres borrar el comentario?")) {
  sndReq_eliminar_comentario(id_comentario);
}
}

function informa_desnudo(id_foto,tipo) {
  sndReq_informa_desnudo(id_foto,tipo);
}

function toggle_desnudo(id_foto) {
  sndReq_desnudo(id_foto);
}
function toggle_oculta(id_foto) {
  sndReq_oculta(id_foto);
}
function sndReq(id_usuario,id_foto) {
    xmlhttp.open('get', '/rpc.php?id_usuario='+id_usuario+'&id_foto='+id_foto);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);	
}

function sndReq_desnudo(id_foto) {
    xmlhttp.open('get', '/rpc_des.php?id_foto='+id_foto);
    xmlhttp.onreadystatechange = handleResponse_desnudo;
    xmlhttp.send(null);	
}

function sndReq_eliminar_comentario(id_comentario) {
	
	document.getElementById("comentario_"+id_comentario).style.display = 'none';
	//Effect.BlindUp('comentario_'+id_comentario);
	
    xmlhttp.open('get', '/rpc_comentario.php?id_comentario='+id_comentario);
	
    xmlhttp.onreadystatechange = handleResponse_comentario;
    xmlhttp.send(null);	
}

function sndReq_informa_desnudo(id_foto,tipo) {
    xmlhttp.open('get', '/rpc_informa_des.php?id_foto='+id_foto+'&tipo='+tipo);
    xmlhttp.onreadystatechange = handleResponse_informa_desnudo;
    xmlhttp.send(null);	
}

function sndReq_oculta(id_foto) {
    xmlhttp.open('get', '/rpc_ocu.php?id_foto='+id_foto);
    xmlhttp.onreadystatechange = handleResponse_oculta;
    xmlhttp.send(null);	
}

function sndReq_sin_leer() {
    xmlhttp.open('get', '/rpc_sin_leer.php');
    xmlhttp.onreadystatechange = handleResponse_sin_leer;
    xmlhttp.send(null);	
}


function handleResponse() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
       	
        var response = xmlhttp.responseText;
        var update = new Array();

        if(response.indexOf('|') != -1) {
            update = response.split('|');
			var imagen = document.getElementById(update[1]);
			//var contador = document.getElementById('favoritas');
			imagen.src = update[2];
			//contador.innerHTML= "["+update[3]+"]";
            
        }
		}
    }
}
function handleResponse_desnudo() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
       	
        var response = xmlhttp.responseText;
        var update = new Array();

        if(response.indexOf('|') != -1) {
            update = response.split('|');
			var imagen = document.getElementById(update[1]);
			imagen.src = update[2];           
        }
		}
    }

}
function handleResponse_comentario() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
       	
        var response = xmlhttp.responseText;
        var update = new Array();
		
		

       // if(response.indexOf('|') != -1) {
      //      update = response.split('|');
	//		var imagen = document.getElementById(update[1]);
	//		imagen.src = update[2];           
     //   }
		}
    }

}
function handleResponse_informa_desnudo() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
       	
        var response = xmlhttp.responseText;
        id_foto = response;
		

			var mensaje = document.getElementById('ina_'+id_foto);
			mensaje.innerHTML= '<div style="font-size:14px">Gracias por informar</span>';
		
		}
    }

}

function handleResponse_sin_leer() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
       	
        var response = xmlhttp.responseText;
        num_mensajes = response;
		
		
		if (num_mensajes==0) {
			texto_email=' ';
		}
		if (num_mensajes==1) {
			texto_email='Tienes '+num_mensajes+' mensaje nuevo. <a style=\"color: #FFFFFF;\" href=/inbox.php>Leer</a>';
		} 
		if (num_mensajes>1) {
	      texto_email='Tienes '+num_mensajes+' mensajes nuevos. <a style=\"color: #FFFFFF;\" href=/inbox.php>Leer</a>';
		}
		
    if (num_mensajes>0) {
	document.getElementById('area_mensajes').innerHTML='&nbsp;<font color=#FFFFFF><img  src="/iconos/email_error.png" align="absmiddle"> <b>'+texto_email+'</b></font>';
	document.getElementById('conta_mensajes').innerHTML='['+num_mensajes+']';
	} else {
	 document.getElementById('area_mensajes').innerHTML='';
	 document.getElementById('conta_mensajes').innerHTML='';
	}
		
		}
    }

}



function handleResponse_oculta() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
       	
        var response = xmlhttp.responseText;
        var update = new Array();

        if(response.indexOf('|') != -1) {
            update = response.split('|');
			var imagen = document.getElementById(update[1]);
			imagen.src = update[2];           
        }
		}
    }	
}

function modera_ok(id_foto,tipo) {
  $("#moderar"+id_foto).effect('blind',{mode: "hide"});
  	 $.get("/rpc_informa_des.php", {id_foto: id_foto,tipo: tipo});
}
function enable_circulo() {
  $.get("/ajax_enable_circulo.php",null, function(respuesta){
	  location.reload();
  });
}
function disable_circulo() {
  $.get("/ajax_disable_circulo.php",null, function(respuesta){
	  location.reload();
  });
}

function galeria_maxmin_todas() {
	$('.galeria_foto').click();
}
function galeria_maximiza(foto,imagen,height,width) {
	
	foto.unbind('click');
	foto.attr('onload','');
	foto.click(function() {
     	galeria_maximiza(foto,imagen,h_old,w_old);
	});

	var h_old=foto.height();
	var w_old=foto.width();
	var src_old=foto.attr('src');
		

	var nueva_imagen = $('<img />');
	nueva_imagen.attr('src', imagen);
	
	nueva_imagen.load(function() {
  		foto.attr('src', imagen);
	});


    foto.stop().animate({
        height: height, width: width
    });
	
}

function enable_mayores18(checkbox) {
  
  $.get("/ajax_enable_mayores18.php",{valor: checkbox.is(':checked')}, function(respuesta){
	  location.reload();
  });
}


function publica_comentario(id_foto,textarea) {
	var texto=textarea.val(); 
	var contenedor=textarea.parent('div').parent('div');
	$('.publicando_comentario', contenedor).show();
	$('.boton1', contenedor).hide();
	textarea.hide();
	var contenedor_num_comentarios=$('.galeria_comentarios > a', contenedor.parent('div'));
	
	 $.get("/ajax_publica_comentario.php",{comentario: texto, id_foto: id_foto}, function(respuesta){
		$('.publicando_comentario', contenedor).hide();	
		contenedor_num_comentarios.html(parseInt(contenedor_num_comentarios.html())+1);
		contenedor_num_comentarios.animate({color: '#FF0000', fontSize: '40px'},10).animate({color: '#FFFFFF', fontSize: '10px'},800)
		contenedor.fadeOut(1000);
	});
}


$(document).ready(function() {
  // Handler for .ready() called.
  $('.bubbleInfo').each(function () {

    var trigger = $('.trigger', this);
    var popup = $('.popup', this);
	var cerrar = $('.cerrar', this);


	//.attr("onmouseover", "");

    // set the mouseover and mouseout on both element
    trigger.click(function () {
		popup.show();
		 $('textarea', popup).val('Escribe aquí tu comentario...');
		 $('textarea', popup).show();
		 $('.boton1', popup).show();
		 $('.publicando_comentario', popup).hide();
    });
	
	  cerrar.click(function () {
        popup.hide();
    });
	
	
  });
});

