function loginfb(response) {
    if (response.session) {
      if (!response.perms) {
         window.open(url_frontend+"/_post/externalLogin.php?idSocialNetwork=1&session="+JSON.encode(response.session), "myWindow", "status = 1, height = 400, width = 600, resizable = 1" )
      }
    }
  }

function loginTwitter(urlBase,returnTo,userLogued){
  userLogued = typeof(userLogued) != "undefined" ? userLogued : 0;
  window.open(urlBase+"/cronjobs/externalLogin.php?idSocialNetwork=3&userLogued="+userLogued+"&returnTo="+returnTo,"closeExternalLogin","width=820,height=400,toolbar=0,location=0,menubar=0,directories=0,resizable=0");
}

LOGIN = {
	urlFromLogin:'',
	f:null,
	modalAuth:null,
	idContenido:0,
	related:'',

	isValid:function(){
		CMSFrontendLogin = getCookie("CMSFrontendLogin");
		return (CMSFrontendLogin)?true:false;
	},

	getIdPersona:function(){
		return getCookie("CMSFrontendIdPersona");
	},

	modal:function(position){
		position = position || '';
		//alert($type(LOGIN.f));
		LOGIN.modalAuth = new ModalIonlineLogin({
			 onComplete:function(){

				 $('usuarioModal').onkeyup 	= function(e){

					  e = e || window.event;
		        if (e.keyCode == 13) {
		            LOGIN.auth();
		            return false;
		        }
		        habilitar_login_button('usuarioModal','claveModal','enviarModal'); }

				 $('claveModal').onkeyup 		= function(e){

					 e = e || window.event;
		        if (e.keyCode == 13) {
		            LOGIN.auth();
		            return false;
		        }
					  habilitar_login_button('usuarioModal','claveModal','enviarModal'); }

				 $('enviarModal').onclick 	= function(e){ LOGIN.auth(); }
				 },
			 isAjax:true,
			 src:'../_modulos/usuariosweb/_htmls/ionline/loginModal_v2.html',
			 width:310,
			 height:160,
			 related:position
		});
	},

	auth:function(){
		clave = $('claveModal').value;
		usuario = $('usuarioModal').value;

		if(!clave || !usuario){ $('modalError').innerHTML = "Email ou palavra-chave incorrecta"; return false; }
		new Request.JSON({
			url: "../_post/ionline/loginModal.php",
			onSuccess: LOGIN.authSuccess}).get({'usuario':usuario,'clave':clave});
	},

	authSuccess:function(r){
		if(r.estado == 'ok'){
			switchLogin();
			LOGIN.modalAuth.cerrar();
			LOGIN.modalAuth = null;
		}else{

			$('modalError').innerHTML = "Email ou palavra-chave incorrecta";
			$('claveModal').value = '';
			$('usuarioModal').value = '';
			$('usuarioModal').focus();
		}
	}
}



MINHACIUDADE= {
	urlFromLogin:'',
	f:null,
	modalAuth:null,
	idContenido:0,
	related:'',

	isValid:function(){
		CMSFrontendLogin = getCookie("CMSFrontendLogin");
		return (CMSFrontendLogin)?true:false;
	},

	getIdPersona:function(){
		return getCookie("CMSFrontendIdPersona");
	},

	modal:function(position){
		position = position || '';
		MINHACIUDADE.modalAuth = new ModalIonlineLogin({
			 onComplete:function(){

				 $('inputSearchCity').onkeyup 	= function(e){

					  e = e || window.event;
		        if (e.keyCode == 13) {
		            MINHACIUDADE.auth();
		            return false;
		        }
		        //habilitar_login_button('usuarioModal','claveModal','enviarModal');
		      }

				 $('enviarModal').onclick 	= function(e){ MINHACIUDADE.auth(); }
				 },
			 isAjax:true,
			 src:'../_modulos/general/_htmls/ionline/minha_cidade.html',
			 width:310,
			 height:160,
			 related:position
		});
	},

	auth:function(){
		city = $('inputSearchCity').value;

		//if(!city){ $('modalError').innerHTML = "Email ou palavra-chave incorrecta"; return false; }
		if($('inputSearchCity').value.length < 3){
		  alert('Escreva um minimo de 3 caracteres');
		  $('inputSearchCity').focus();
	  }else{

		document.getElementById('divResultCitiesBis').innerHTML = "";
		new Request({
			url: "../_post/ionline/searchCities_v2.php",
			method: 'get',
			onSuccess: function(responseText){
			  eval(responseText);
       }
			}).send('text='+city);

    }
	}

}
