(function($) {
	//Main Method
	$.fn.reportprogress = function(val,maxVal) {
		var max=100;
		if(maxVal)
			max=maxVal;
		return this.each(
			function(){
				var div=$(this);
				var innerdiv=div.find(".progress");

				if(innerdiv.length!=1){
					innerdiv=$("<div class='progress_new'></div>");
					div.append("<div class='text'>&nbsp;</div>");
					$("<span class='text_new' style='z-index:100;'>&nbsp;</span>").css("width",div.width()).appendTo(innerdiv);
					div.append(innerdiv);
				}
				var width=Math.round(val/max*100);
				innerdiv.css("width",width+"%");
				div.find(".text").html(width+" %");
			}
		);
	};
})(jQuery);
var pct=0;
var handle=0;
function update(){
        $("#progressbar").reportprogress(++pct);
        if(pct==100){
                clearInterval(handle);
                //$("#run").val("start");
                pct=0;
        }
}

function count_visitor(){
	var uri = window.location.href;
	//alert(idioma_general);
	$.ajax({
		type:'post',
		url:'/' + idioma_general + '/image/countgateway',
		data:"page="+uri,
		dataType:'json',
		success: function(data){
			return;
		}
	});
}

//========Selecciona checks=======
function ChequearTodos(chkbox){
	//alert(document.forms["formchk"].elements.length)
	$('.chequear').attr('checked',chkbox.checked)

}
function ChequearTodosup(chkbox){
	//alert(document.forms["formchk"].elements.length)
	$('.chequearup').attr('checked',chkbox.checked)

}

function undoFav() {
	var idwall = $('#idoculto').val();
		$.getJSON(ajax_domain + '/' + idioma_general + '/image/removefav/?id=' + idwall + "&callback=?", function(data){
			$('.favourite2').show();
			$('#pa_mostra_mensaje').html(data.msj);
			$('.flag2').hide();
			$('.comments2, .send-friend2, .your-resolutions2, #issendrep, #issendwall, .flag21, .send-friend21').hide();
			$('.cono6').show();
			$('.cono2, .cono3, .cono4, .cono5, .cono1').hide();
			$('.ico-view1, .ico-view2_active, .ico-view3_active, .ico-view4_active, .ico-view5_active, .ico-view6').css({});
			return;
		})
	}



$(document).ready(function(){
	try {
		//UP.add('lalala','/en/user/uploadfile','/en/user/progres.php');
		//toggle del footer
		$(".botonFooter").click(function(){
			$(".foot12").toggle("slow");
		});
		// Report
		$(document).keypress(function(e){
			if(e.keyCode==27 && popupStatus==1){
				disablePopup();
			}
		});
		$("#reason_mycopy").change(function(){
			$("#mycopy, #tbsubmit").fadeIn(500);
			$("#mytitle, #mycategory").fadeOut(500);
		});
		$("#reason_mytitle").change(function(){
			$("#mytitle, #tbsubmit").fadeIn(500);
			$("#mycopy, #mycategory").fadeOut(500);
		});
		$("#reason_mycategory").change(function(){
			$("#mycategory, #tbsubmit").fadeIn(500);
			$("#mytitle, #mycopy").fadeOut(500);
		});
		$("#reason_porno, #reason_other").change(function(){
			$("#tbsubmit").fadeIn(500);
			$("#mytitle, #mycopy, #mycategory").fadeOut(500);
		});
		// Interceptamos el evento submit
		$('#formReport').submit(function() {
			document.getElementById('formReport').disablereport.disabled=true;
			ajaxPost(this,'resultReport');
			document.getElementById('formReport').disablereport.disabled=false;
			return false;
		});

		//  ---------------------------------
		//  esto de del NEWSLLETTER
		// ---------------------------------
		$("#formNewsletter").submit(function() {
			ajaxPost(this,'resultNews');
			return false;
		});
		$("#flecha_der").click(function(){
			valor = document.getElementById("galeria").scrollLeft-460;
			$("#galeria").animate({
				scrollLeft: valor
			}, "slow");
		});
		$("#flecha_izq").click(function(){
			valor = document.getElementById("galeria").scrollLeft;
			$("#galeria").animate({
				scrollLeft: 460+valor
			}, "slow");
		});
		$("ul.menu_body li:even").addClass("alt");
		$('img.menu_head').click(function () {
			$('ul.menu_body').slideToggle('medium');
		});
		$('ul.menu_body li a').mouseover(function () {
			$(this).animate({
				fontSize: "11px",
				paddingLeft: "10px"
			}, 50 );
		});
		$('ul.menu_body li a').mouseout(function () {
			$(this).animate({
				fontSize: "11px",
				paddingLeft: "10px"
			}, 50 );
		});
		$("ul.menu_body2 li:even").addClass("alt");
		$('img.menu_head2').click(function () {
			$('ul.menu_body2').slideToggle('medium');
		});
		$('ul.menu_body2 li a').mouseover(function () {
			$(this).animate({
				fontSize: "11px",
				paddingLeft: "10px"
			}, 50 );
		});
		$('ul.menu_body2 li a').mouseout(function () {
			$(this).animate({
				fontSize: "11px",
				paddingLeft: "10px"
			}, 50 );
		});
		//  ---------------------------------
		//  LOGIN
		// ---------------------------------
		$('#menuLogin').click(function () {
			$('#content_login').fadeIn(10);
			$("#category1").css({
				'visibility':"hidden"
			});
			$("#resolution1").css({
				'visibility':"hidden"
			});

		});
		$('#closePopup').click(function() {
			$('#content_login').fadeOut(10);
			$("#category1").css({
				'visibility':"visible"
			});
			$("#resolution1").css({
				'visibility':"visible"
			});
		});
/*
		$('#formLogin').submit(function() {
			ajaxPostAjax(this,'resultLogin');
			return false;
		});
*/
		$('#remember-button').click(function() {
			// No quiere el toggle
			// $('#formRemember').fadeIn(10);
			});
		$('#formRemember').submit(function() {
			ajaxPost(this,'resultRemember');
			return false;
		});
		//-------Duplica------------
		$('#formLogin2').submit(function() {
			ajaxPost(this,'resultLogin2');
			return false;
		});
		$('#remember-button2').click(function() {
			$('#formRemember2').fadeIn(10);
		});
		$('#formRemember2').submit(function() {
			ajaxPost(this,'resultRemember2');
			return false;
		});
		//-------Triplica------------
		$('#formLogin3').submit(function() {
			ajaxPostAjax(this,'resultLogin3');
			return false;
		});
		$('#remember-button3').click(function() {
			$('#formRemember3').fadeIn(10);
		});
		$('#formRemember3').submit(function() {
			ajaxPost(this,'resultRemember3');
			return false;
		});

		// ---------------------------------
		//  Busqueda
		// ---------------------------------
		$('.s-input').click(function() {
			$('.busqueda1').fadeIn(500);
		});
		// ---------------------------------
		//  PREVIEW
		// ---------------------------------
		$(".sendViewAll").click(function () {
			$(".postViewAll").toggle(500);
		});
		//$('#mycarousel').jcarousel();
		$('#formSentFriend').submit(function() {
			ajaxPost(this,'resultSentFriend');
			return false;
		});
		//$('#formComment').submit(function() {
		//	ajaxPostAlert(this,'resultComment');
		//alert($('#resultComment').text()); //va comentado
		//	return false;
		//});
		$('#formComment2').submit(function() {
			ajaxPostAjax(this,'notienenombre');
			return false;
		});
		$('.closemenu').click(function() {
			//alert($('#closemenu').length);
			//alert($('.flag2').length);
			$('.favourite2, .flag2, .comments2, .send-friend2, .your-resolutions2, #issendrep, #issendwall').hide();
			$('.flag21, .send-friend21').hide();
			$('.cono1, .cono2, .cono3, .cono4, .cono5, .cono6').hide();
		})
		$('#favourite').click(function () {
			if($('.cono6').is(':visible')){
				return;
			}
			var idwall = $('#idoculto').val();
				$.getJSON(ajax_domain + '/' + idioma_general + '/image/favourite/?id=' + idwall + "&callback=?", function(data){
					$('.comments2, .send-friend2, .your-resolutions2, .nofavourite2, .favourite2, #issendrep, #issendwall, .send-friend21, .flag21, .flag2').hide();
					$('.cono2, .cono3, .cono4, .cono5, .cono1').hide();
					$('.cono6').show();
					$('.favourite2').show();
					$('#pa_mostra_mensaje').html(data.msj);
					$('.ico-view1_active, .ico-view2_active, .ico-view3_active, .ico-view4_active, .ico-view5_active, .ico-view6,').css({});
					//$('#favourite').unbind('click');
					return;
				})
/*
			$.ajax({
				type:'POST',
				url: '/' + idioma_general + '/image/favourite/',
				data: "id="+idwall,
				dataType:'json',
				success: function(data) {
					$('.comments2, .send-friend2, .your-resolutions2, .nofavourite2, .favourite2, #issendrep, #issendwall, .send-friend21, .flag21, .flag2').hide();
					$('.cono2, .cono3, .cono4, .cono5, .cono1').hide();
					$('.cono6').show();
					$('.favourite2').show();
					$('#pa_mostra_mensaje').html(data.msj);
					$('.ico-view1_active, .ico-view2_active, .ico-view3_active, .ico-view4_active, .ico-view5_active, .ico-view6,').css({});
					//$('#favourite').unbind('click');
					return;
				}

			});
*/

		});
		$('#flag').click(function () {
			$('.comments2, .send-friend2, .your-resolutions2, .nofavourite2, .favourite2, #issendrep, #issendwall, .send-friend21, .flag21').hide();
			//$('.comments21').hide();
			$('.cono2, .cono3, .cono4, .cono5, .cono6').hide();
			$('.flag2, .cono1').show();
		//$('.ico-view1, .ico-view2_active, .ico-view3_active, .ico-view4_active, .ico-view5_active, .ico-view6_active').css({});
		});
		$('#comments').click(function () {
			$('.send-friend2, .your-resolutions2, .nofavourite2, .favourite2, #issendrep, #issendwall, .send-friend21, .flag21, .flag2').hide();
			$('.cono1,.cono3, .cono4, .cono5, .cono6').hide();
			$('.comments2, .cono2').show();
		//$('.ico-view1_active, .ico-view2, .ico-view3_active, .ico-view4_active, .ico-view5_active, .ico-view6_active').css({});
		});
		$('#send-friend').click(function () {
			$('.comments2, .your-resolutions2, .nofavourite2, .favourite2, #issendrep, #issendwall, .send-friend21, .flag21, .flag2').hide();
			$('.cono1, .cono2, .cono4, .cono5, .cono6').hide();

			$('.cono3').show();
			$('.send-friend2').show();
		//$('.ico-view1_active, .ico-view2_active, .ico-view3, .ico-view4_active, .ico-view5_active, .ico-view6_active').css({});
		});
		$('#your-resolution').click(function () {
			$('.comments2, .send-friend2, .your-resolutions2, .nofavourite2, .favourite2, #issendrep, #issendwall, .send-friend21, .flag21, .flag2').hide();
			$('.cono1, .cono2, .cono3, .cono5, .cono6').hide();
			$('.cono4').show();
			$('.your-resolutions2').show();
		//$('.ico-view1_active, .ico-view2_active, .ico-view3_active, .ico-view4, .ico-view5_active, .ico-view6_active').css({});
		});
		$('#send-mobile').click(function () {
			$('.comments2, .send-friend2, .your-resolutions2, .nofavourite2, .favourite2, #issendrep, #issendwall, .send-friend21, .flag21, .flag2').hide();
			$('.cono1, .cono2, .cono3, .cono4, .cono6').hide();
		//$('.cono5').show();
		//$('.ico-view1_active, .ico-view2_active, .ico-view3_active, .ico-view4_active, .ico-view5, .ico-view6_active').css({});
		});
		$('#formsendwallpeper').submit(function () {
			ajaxPost(this,'resultsend');
			return false
		});
		$('#prevUploader').mouseover(function () {
			$('#contenedor_prevUploader').fadeIn(300);
		});
		$('#prevUploader').mouseout(function () {
			$('#contenedor_prevUploader').fadeOut(300);
		});

		$('#nextUploader').mouseover(function () {
			$('#contenedor_nextUploader').fadeIn(300);
		});
		$('#nextUploader').mouseout(function () {
			$('#contenedor_nextUploader').fadeOut(300);
		});
		$('#viewAllComments').click(function () {
			$('#allComments').toggle('open');
			$('#viewAllComments').fadeOut(10);
			$('#closeComments').fadeIn(500);
		});
		$('#closeComments').click(function () {
			$('#allComments').hide();
			$('#viewAllComments').fadeIn(10);
			$('#closeComments').fadeOut(500);
		});
		// ---------------------------------
		//  FEEDBACK
		// ---------------------------------
		$('#formfeedback').submit(function() {
			ajaxPost(this,'resultfeedback');
			return false;
		});
		//$('#formRegister').submit(function() {
		//	ajaxPost(this,'resultRegister');
		//	return false;
		//});
		//  ---------------------------------
		//  REGISTER
		// ---------------------------------
		//$.validator().setDefaults({messages: {required: "This field is required..."}});
		//$("#formRegister").validate();
		jQuery.validator.messages.required = "This field is required..."
		jQuery.validator.messages.email = "Please enter a valid email address"
		$('#formComment').submit(function() {
			if($(this).valid() == true){
				ajaxPostAjax(this,'resultadoComment');
			}
			return false;
		});
		$('#formComment').validate({
			showErrors: function(errorMap, errorList) {
				var error = errorMap;
				if (error){
					for ( var name in errorMap ) {
						$(this.findByName(name)[0]).val(errorMap[name]);
					}
				}
			//console.log(errorList);
			//$("#warning").html("Tu formulario contiene " + this.numberOfInvalids() + " errores.");
			//this.defaultShowErrors();
			}
		});
		//=========================Validacion Mail==================
		/*$('#formsendwallpeper').submit(function() {
			if($(this).valid() == true){
				ajaxPost(this,'resultsend');
			}
			console.log($(this).valid());
			return false;
		});
		$('#formsendwallpeper').validate({
			showErrors: function(errorMap, errorList) {
				var error = errorMap;
				if (error){
					for ( var name in errorMap ) {
						$(this.findByName(name)[0]).val(errorMap[name]);
					}
				}
		}});*/

		//====Esta Validaba====
		/*$("#formsendwallpeper").validate({
			showErrors: function(errorMap, errorList) {
				for ( var name in errorMap ) {
					$(this.findByName(name)[0]).val(errorMap[name]);
				}
			}
		});*/
		$('#inputMail').click(function () {
			$('#resultMail').fadeOut(500);
		});
		$('#formRegister').submit(function() {
			$('#formRegister').find('.notice').remove();
			$('#formRegister').find('.notice_verde').remove();
			$('.notice_arriba').remove();
			$('#error_arriba').remove();
			ajaxPostvalidateAjax(this,'formRegister');
			return false;
		});
		// ---------------------------------
		//  Borra cache
		// ---------------------------------
		$('#borrachache').submit(function() {
			ajaxPost(this,'cacheborrada');
			return false;
		});

		// ---------------------------------
		//  FORGOT PASSWORD
		// ---------------------------------
		$('#formForgot').submit(function() {
			ajaxPost(this,'resultForgot');
			return false;
		});
		$('#formRenew').submit(function() {
			ajaxPostAjax(this,'resultRenew');
			return false;
		});
		// ---------------------------------
		// MY ACCOUNT
		// ---------------------------------
		$('#ChangePassword').click(function() {
			$('#formulariopass').fadeIn(500);
			$('#ChangePassword').fadeOut(500);
		});
		$('#formUpdateProfile').submit(function() {
			//$('#formRegister').find('.notice').remove();
			//$('#formRegister').find('.notice_verde').remove();
			$('.notice_arriba').remove();
			$('#error_arriba_form').remove();
			$('#error_arriba_form_verde').remove();
			ajaxPostvalidateaccount(this,'formUpdateProfile');
			return false;
		});
		$('#formUpdateMail').submit(function() {
			$('.notice_arriba').remove();
			$('#error_arriba_form').remove();
			$('#error_arriba_form_verde').remove();
			ajaxPostvalidateaccount(this,'formUpdateMail');
			return false;
		});
		$('#formUpdatePassword').submit(function() {
			$('.notice_arriba').remove();
			$('#error_arriba_form').remove();
			$('#error_arriba_form_verde').remove();
			ajaxPostvalidateaccount(this,'formUpdatePassword');
			return false;
		});
		$('#formUpload').submit(function() {
			ajaxPost(this,'resultUploadwallpaper');
			return false;
		});
		$('#formContinue').submit(function() {
			$('#resultContinue').fadeOut(10);
			ajaxPost(this,'resultContinue');
			return false;
		});
		$("#changePass").click(function () {
			$("#newPassword").toggle('slow');
		});
		$("#buscara").click(function () {
			var cat			= '';
			$('#category1 option').each(function(){
				if($(this).attr('value') == $(this).parent().val()){
					cat = $(this).html();
				}

			});
			var res			= '';
			$('#resolution1 option').each(function(){
				if($(this).attr('value') == $(this).parent().val()){
					res = $(this).html();
				}

			});
			var	url			= $("#url").val();
			var cx			= $("#cx").val();
			var cof			= $("#cof").val();
			var ie			= $("#ie").val();
			var wallpaper	= $("#wallpaper").val();
			var sa			= $("#sa").val();
			location.href= url+'?cx='+cx+'&cof='+cof+'&ie='+ie+'&q='+cat+'+'+res+'+'+wallpaper+'&sa='+sa;
			return false;
		})
		$("#rmfav").click(function(){
			var cant = new Array;
			var i = 0;
			//var	cant = $('.chequear').find('checked',chkbox.checked);

			$(".chequear[type='checkbox']").each(function(){
				if($(this).attr('checked') == true){
					cant[i] = $(this).attr('name').match(/.*\[(.*)\]/)[1];
					i++;
				}
			});
			if(i > 0){
				//alert(cant)
				$.ajax({
					type: 'POST',
					url:'/' + idioma_general + '/image/removefavorites',
					data: 'ids=' + cant.toString(),
					dataType:'json',
					success: function(data) {
						$('#respuesta').html(data.html);
					}

				});
			}
		});
		$("#rmup").click(function(){
			var cant = new Array;
			var i = 0;
			//var	cant = $('.chequear').find('checked',chkbox.checked);

			$(".chequearup[type='checkbox']").each(function(){
				if($(this).attr('checked') == true){
					cant[i] = $(this).attr('name').match(/.*\[(.*)\]/)[1];
					i++;
				}
			});
			if(i > 0){
				//alert(cant)
				$.ajax({
					type: 'POST',
					url:'/' + idioma_general + '/image/removeupuser',
					data: 'ids=' + cant.toString(),
					dataType:'json',
					success: function(data) {
						$('#respuesta').html(data.html);
					}

				});
			}
		});
		$(".favboton_delete").click(function(){
			var cant = new Array;
			var i = 0;
			cant[i] = $(this).attr('name').match(/.*\[(.*)\]/)[1];
			$.ajax({
				type: 'POST',
				url:'/' + idioma_general + '/image/removefavorites',
				data: 'ids=' + cant.toString(),
				dataType:'json',
				success: function(data) {
					$('#respuesta').html(data.html);
				}

			});

		});
		$(".upboton_delete").click(function(){
			var cant = new Array;
			var i = 0;
			cant[i] = $(this).attr('name').match(/.*\[(.*)\]/)[1];
			$.ajax({
				type: 'POST',
				url:'/' + idioma_general + '/image/removeupuser',
				data: 'ids=' + cant.toString(),
				dataType:'json',
				success: function(data) {
					$('#respuesta').html(data.html);
				}

			});

		});

		//=====RECARGA RES========

		$("#category1").change(function () {
			$.ajax({
				type:'POST',
				url:'/en/image/getresolution/',
				data: "id="+this.value,
				dataType:'json',
				success: function(data) {
					//alert(data.msj)
					var res = $('#resolution1');
					res.html('');
					for(var i=0;i<data.msj.length;i++){
						var option = '<option value="' + data.msj[i].id_resolution + '">' + data.msj[i].resolution  + '</option>';
						res.html(res.html() + option);
					}
					return;
				}

			});
		});

		var button = $('#button1');
		var interval;
		if(typeof Ajax_upload != 'undefined'){
			new Ajax_upload(button,{
				action: '/en/user/uploadfile',
				name: 'file',
				responseType:'json',
				onSubmit : function(file, ext){
					$("#content_progress").fadeIn(1);
					document.getElementById('formUpload').stp2.disabled=true;
					this.disable();
					interval = window.setInterval(function(){
						if (pct < 100){
							$("#progressbar").reportprogress(++pct);
						} else {
							$("#progressbar").reportprogress(100);
						}
					}, 100);
				},
				onComplete: function(file, response){
					$("#progressbar").reportprogress(100);
					setTimeout("$('#stepuno').hide()",2000);
					setTimeout("$('#stepdos').show()",2000);
					//button.text('Upload');
					window.clearInterval(interval);
					this.disable();
					document.getElementById('formUpload').stp2.disabled=false;
					$("[name='uploaded']").val(1);
					$('<span></span>').appendTo('.files').text(file);
					$('<span></span>').appendTo('.filesresponse').text(response.msj);
					$("#resultContinue").hide();
					if(response.error){
						$('.files, .filesresponse').hide();
						$('.files_error, .filesresponse_error').show();
						$('<span></span>').appendTo('.files_error').text(file);
						$('<span></span>').appendTo('.filesresponse_error').text(response.msj);
						document.getElementById('formUpload').stp2.disabled=true;
						this.enable();
						$('.save_wp').fadeOut(500);
					}else{
						$('.save_wp').fadeIn(500);
					}
				}
			});
		}
	} catch (e){
		if(typeof console != 'undefined'){
			console.log(e.message);
		}
	}
});
/**
 *	*********** FUNCIONES ***********
 */
function esFecha(formu)
{
	var elDia=formu.txt_dia.value
	var elMes=formu.txt_mes.value-1
	var elAnio=formu.txt_anio.value
	var ff = new Date(elAnio, elMes, elDia)
	if ( ff.getDate() != elDia ) return false
	if ( ff.getMonth() != elMes ) return false
	if ( ff.getFullYear() != elAnio ) return false
	return true
}


function ajaxPost(obj,callback){//iria el id para el if()
	$.ajax({
		type: 'POST',
		url: $(obj).attr('action'),
		data: $(obj).serialize(),
		dataType: 'json',
		// Mostramos un mensaje con la respuesta de PHP
		success: function(data) {
			//console.log(data);
			//if(id){
			//	$('#'+id).insertAfter(data.msj);
			//}
			$('#' + callback).html(data.msj);
			$('#' + callback).fadeIn(500);
			if(data.ret){
				$(obj).fadeOut(500);
			}
			if(data.pagina){
				$("#colum2").html(data.pagina);
			}
		}
	//beforeSend: function(){
	//    $('#' + callback).html('<img src="/resources/img/ajax-loader.gif">');
	//	$('#' + callback).fadeIn(500);
	//}

	})
}
function ajaxPostAjax(obj,callback){
	var values = $(obj).serialize();
		$.getJSON(($(obj).attr('action')) + '?' + values + "&callback=?", function(data){
			$('#' + callback).html(data.msj);
			$('#' + callback).fadeIn(500);
			if(data.ret){
				$(obj).fadeOut(500);
			}
			if(data.pagina){
				$("#colum2").html(data.pagina);
			}
		}
 )}
function ajaxPostvalidate(obj,callback){
	$.ajax({
		type: 'POST',
		url: $(obj).attr('action'),
		data: $(obj).serialize(),
		dataType: 'json',
		// Mostramos un mensaje con la respuesta de PHP
		success: function(data) {
			//alert(datmsj);
			var mensajes = '';
			if(data.register){
				location.href=data.register;
				return;
			}
			for(var i=0;i<data.msj.length;i++){
				var obj = $('#'+callback).find('#'+data.msj[i].id);
				var html = '<p class="notice">'+data.msj[i].msj+'</p>';
				obj.after(html);
				mensajes += '<p class="notice_arriba">'+data.msj[i].msj+'</p>';
			}
			$('#form_registro').before('<div id="error_arriba">'+mensajes+'</div>');
			$('#notice_verde').show();
			//alert(mensajes)
			return;
		}

	//beforeSend: function(){
	//    $('#' + callback).html('<img src="/resources/img/ajax-loader.gif">');
	//	$('#' + callback).fadeIn(500);
	//}

	})
}

function ajaxPostvalidateAjax(obj,callback){
		var values = $(obj).serialize();
		$.getJSON(($(obj).attr('action')) + '?' + values + "&callback=?", function(data){
			var mensajes = '';
			if(data.register){
				location.href=ajax_domain + data.register;
				return;
			}
			for(var i=0;i<data.msj.length;i++){
				var obj = $('#'+callback).find('#'+data.msj[i].id);
				var html = '<p class="notice">'+data.msj[i].msj+'</p>';
				obj.after(html);
				mensajes += '<p class="notice_arriba">'+data.msj[i].msj+'</p>';
			}
			$('#form_registro').before('<div id="error_arriba">'+mensajes+'</div>');
			$('#notice_verde').show();
			//alert(mensajes)
			return;
		}
	)}

function ajaxPostvalidateaccount(obj,callback){
	$.ajax({
		type: 'POST',
		url: $(obj).attr('action'),
		data: $(obj).serialize(),
		dataType: 'json',
		// Mostramos un mensaje con la respuesta de PHP
		success: function(data) {
			var mensajes = '';
			if(data.re){
				mensajes += '<p class="notice_arriba">'+data.re+'</p>';
				$('#form_registro').before('<div id="error_arriba_form_verde">'+mensajes+'</div>');
				setTimeout('location.href = "' + data.href + '"',2000);
				return;
			}
			//alert(data.msj);
			mensajes = '';
			for(var i=0;i<data.msj.length;i++){
				mensajes += '<p class="notice_arriba">'+data.msj[i].msj+'</p>';
			}
			$('#form_registro').before('<div id="error_arriba_form">'+mensajes+'</div>');
			$('#notice_verde').show();
			//alert(mensajes)
			return;
		}
	})
}

function ajaxPostAlert(obj){
	$.ajax({
		type: 'POST',
		url: $(obj).attr('action'),
		data: $(obj).serialize(),
		dataType: 'json',
		// Mostramos un mensaje con la respuesta de PHP
		success: function(data) {
			alert(data.msj);
		//console.log(data);
		}


	})
}
// ---- | ----
function show(id){
	try{
		var i   = 1;
		var obj = document.getElementById('link'+i)
		while(obj!=null){
			obj.style.display = i==id ?'block' :'none';
			++i;
			var obj = document.getElementById('link'+i);
		}
	}catch(e){
		alert(e.message);
	}
}
function vote(id,star){
	try{
		$.ajax({
			type: 'POST',
			url: '/image/vote/id/'+id+'/average/'+star,
			dataType: 'json',
			success: function(data) {
				$('#resultVote').html(data.msj);
				$('#resultVote').fadeIn(500);
			}
		})
	}catch(e){
		alert(e.message);
	}
}

function voteHands(id,hand){
	try{
		$('#handsVote').hide();
		$.ajax({
			type: 'POST',
			url: '/image/vote/',
			dataType: 'json',
			data: "id=" + id + "&hand=" + hand,
			success: function(data) {
				$('#handsVote').addClass('resultVote');
				$('#handsVote').html(data.msj);
				$('#handsVote').fadeIn(10);
			}
		//error: function(data) { alert('Error: ' + data.msj); }
		})
	}catch(e){
		alert(e.message);
	}
}

function muestra_oculta(id){
	if (document.getElementById){
		var el = document.getElementById(id);
		el.style.display = (el.style.display == 'none') ? 'block' : 'none'; //
	}
}
/** Agrega a Favoritos **/
function bookmark(url,title){
	bookmarkurl		=	"http://" + url + "/"
	bookmarktitle	=	title
	if (document.all)
		window.external.AddFavorite(bookmarkurl,bookmarktitle)
	else if (window.sidebar) // firefox
		window.sidebar.addPanel(bookmarktitle, bookmarkurl, "");
}
function recargarCaptcha(domain,idIMG,rscr){
	var img	= $('.captcha' + idIMG);
	img.attr('src','');
	img.attr('src',domain +'/'+ rscr + '?' + Math.random());
}
function buscaVacio(obj,msj,msjError){
	var qVal = jQuery.trim(obj.value);
	if(qVal == '' || qVal == msj){
		alert(msjError)
		return false;
	}
	return true;
}
/** Recarga la imagen del Captcha 
function recargarCaptcha(idIMG){
	var img	=	document.getElementById(idIMG);
	img.src	=	"";
	img.src	=	"/captcha?"+Date();
}
var jmain = {
	overstar: function(a,hover){
		try{
			var a     = $(a);
			var div   = a.parent();
			var i = a.attr('class').split('_')[1];
			for(j=1;j<=i;j++)
			{
				var img = div.find('.star_'+j+' > img');
				if(hover)
					img.attr('src','/resources/img/star.jpg');
				else
					img.attr('src','/resources/img/star1.jpg');
			}
		}catch(e){alert(e.message);}
	},
	reload: function(){document.location.href=document.location},
	comment: function(f){
		try{
			if(!f) return;
				var s='nick='+f.nick.value;
					s+='&post='+f.post.value;
					s+='&captcha='+f.captcha.value;
					s+='&id='+f.id.value;s+='&request=ajax';
			var h=$(f);h=h.parent();h.html('Loading');
			$.post('/commentForm.php',s,function(r){
				h.html(r);if(r.indexOf('jthanks')>0){setTimeout("jmain.reload()",5000);}
			});
		}catch(e){}
	}
}
*/
