   var authenticationWidgetTest = {
   createSignInWidget: function() {
    Flux.createWidget('Authentication', { fluxHosted: true },
     function(authenticationWidget) {
      authenticationWidget.showSignInForm();
     });
   },
   createSignUpWidget: function() {
    Flux.createWidget('Authentication', { fluxHosted: true },
     function(authenticationWidget) {
      authenticationWidget.showSignUpForm();
     });
   },
   createInterimWidget: function() {
    Flux.createWidget('Authentication', { fluxHosted: true },
     function(authenticationWidget) {
      authenticationWidget.showInterimForm();
     });
   }
  }

   var authenticationWidgetNav = {
   createSignInWidget: function(donde) {
    Flux.createWidget('Authentication', { fluxHosted: true, customSignupPage: donde },
     function(authenticationWidget) {
      authenticationWidget.showSignInForm();
     });
   },	   
   createInterimWidget: function(donde) {
    Flux.createWidget('Authentication', { fluxHosted: true, customSignupPage: donde },
     function(authenticationWidget) {
      authenticationWidget.showInterimForm();
     });
   }
  }



/*Navegación*/
function _navIrA_(donde){
	Flux.loadContext(function(context) {
	  if (context.user) {
			if( parseInt(context.user.age,10) <= 0 ){
				authenticationWidgetNav.createInterimWidget( donde );	
			}else{
				location.href = donde;
			}
	  }else{
		  authenticationWidgetNav.createSignInWidget( donde );	
	  }	  
	});
}


function login(){
	Flux.loadContext(function(context) {
		context.onSignOut = loginLoggedOut;
		context.onSignIn = loginLoggedInLive;
		//alert(context.user.age);
		if (context.user) {
			loginLoggedIn(context.user);
		}else{
			loginLoggedOut()
		}
	});
}

function loginLoggedInLive(){
	var userfluxid = context.user.ucid;
	//alert('in:'+userfluxid);
	if( parseInt(context.user.age,10) <= 0 ){
		//authenticationWidgetTest.createInterimWidget();
	}else{
		$.ajax({
				type: "POST",
				url: "save_session.php",
				cache: false,
				async: false,
				data: { flux_id : userfluxid, age: context.user.age },
				success: function(data){
					//alert('a-'+data)
					if( data == 'recargarPagina=1') location.reload();
			   }
			});
	}
}
function loginLoggedIn(user){
	var userfluxid = user.ucid;
	//alert(	"flux_id="+userfluxid+"&age="+user.age );
	$.ajax({
			type: "POST",
			url: "save_session.php",
			cache: false,
			async: false,
			data: { flux_id : userfluxid, age: user.age },
			success: function(data){
				//alert('a-'+data)
				if( data == 'recargarPagina=1') location.reload();
		   }
		});
}
function loginLoggedOut(){
	//alert('out');
		$.ajax({
			type: "POST",
			url: "save_session.php",
			cache: false,
			async: false,
			data: { flux_id : '', age: '' },
			success: function(data){
				//alert('b-'+data)
				if( data == 'recargarPagina=1') location.reload();
			}
		});
}




function permiso_requerido(){
	if( login() != true){
		authenticationWidgetTest.createSignInWidget();
	}
}

$(window).load(function(){
	//login();	En _header_flux.php
});

function preload(){
	$('#preload').slideToggle('fast',function(){
		/*$("#contenidos").animate({ left: 0 }, 1000, function(){ });*/
		$(".contenidos").slideToggle('slow');
	});
}
function mostrar_msj_error(obj_id){
	$('#'+obj_id).show(); 
}
function ocultar_msj_error(obj_id){
	$('#'+obj_id).hide(); 
}
function ocultar_msjs_error(){
	$('.label_mensajes_errores').hide(); 
}
function limitarTextarea(campo, indicadorBajada, maxlimit) {
	lenghActual =  campo.value.length;
	//Si es ie, éste cuenta los enters como dos caracteres, así que por cada uno que encuentre descuento 1 de la suma total
	if($.browser.msie){
		var patron = /\r\n/gi;	
		var encontrados = campo.value.match(patron);
		if( encontrados ){
			//lenghActual = lenghActual - (encontrados.length*2);
			lenghActual = lenghActual - encontrados.length;
		}
	}/*else{ 	//Y para FF  le saco los enters de la cuenta total:
		var patron = /\n/gi;	
		var encontrados = campo.value.match(patron);
		if( encontrados ){
			lenghActual = lenghActual - encontrados.length;
		}
	} Eliminado por ahora ya que desde php se limita tambien, habría que buscar en todos los lugares donde se corta y aplicar lo mismo que aca*/

	if ( lenghActual > maxlimit ){
		out_value = campo.value.substring(0, maxlimit);
	    campo.value = out_value;
	}else if( lenghActual == 0 ){
		$('#'+indicadorBajada).html('');
	}else{
		strTextoIndicadorComentariosTemp = strTextoIndicadorComentarios.replace('%total%',parseInt(maxlimit - lenghActual));
		$('#'+indicadorBajada).html( strTextoIndicadorComentariosTemp);
	}
}
strTextoIndicadorComentarios = 'Le restan %total% de caracteres';




function popup(url,ancho,alto,id,extras){
	if(navigator.userAgent.indexOf("Mac")>0){ancho=parseInt(ancho)+15;alto=parseInt(alto)+15;}
	var left = (screen.availWidth-ancho)/2;
	var top = (screen.availHeight-alto)/2;
	if(extras!=""){extras=","+extras;};
	var ventana = window.open(url,id,'width='+ancho+',height='+alto+',left='+left+',top='+top+',screenX='+left+',screenY='+top+extras);
	var bloqueado = "AVISO:\n\nPara ver este contenido es necesario que desactive\nel Bloqueo de Ventanas para este Sitio."
	//var bloqueado = "WARNING:\n\nIn order to use this functionality, you need\nto deactivate Popup Blocking."
	if(ventana==null || typeof(ventana.document)=="undefined"){ alert(bloqueado) }else{ ventana.focus(); return ventana; };
}

function alertInputFile(){
	texto = 'Before you send in your pic, make sure it´s ready for MMG!\n';
	texto += 'To have a chance of making it on the show, your PHOTOS must be:\n';
	texto += 'FULL-BODY OR TORSO SHOT in COLOR (No headshots)\n';
	texto += 'BEST QUALITY AVAILABLE (No small or blurry images!)\n'; 
	texto += 'AVOID THE FLASH REFLECTING ON MIRRORS\n';
	alert(texto)
}

/*Modal error box*/
function setErrorBox(str,append){
	if( append == 1 ){
		$('#errorBoxCenterStr').append('<br>'+str);
	}else{
		$('#errorBoxCenterStr').html(''+str);
		if( str != '' ) mostrarErrorBox();
	}
	return false;
}
function mostrarErrorBox(){
	$('.overlay').fadeIn('fast',function(){
		$('#errorBoxLayer').animate({'top':'100px'},500);
	});
}
$(window).load(function(){
	$('.errorBoxClose').click(function(){
		$('.box').animate({'top':'-600px'},500,function(){
			$('.overlay').fadeOut('fast');
		});
	});	
});





