/** edit_photo.js BEGIN **/
var waitFlagUpload = false;

function sendPhoto(){
	if (waitFlagUpload){
		alert('Por favor, espere a terminar la &uacute;ltima acci&oacute;n.');
		return;
	}
	if (!trim(getValue('file'))){
		alert('Haga click en examinar para seleccionar una imagen.');
		return;
	}
	waitFlagUpload = true;
	$('upform').submit();
	$('upload_confirmation').innerHTML = 'Subiendo archivo...';
}

function displayUploadStatus(html,photoLink){
	$('upload_confirmation').innerHTML = html;
	$('user_photo').style.width = '150px';
	if (photoLink){
		photoLink = photoLink+'?random='+Math.random();
		try{$('user_photo').src = photoLink}catch(e){};
		try{$('havatar').src = photoLink;}catch(e){};
		try{$('pic_details').src = photoLink;}catch(e){};
		show($('prev_photo'));
		hide($('edit_photo'));
	}
	waitFlagUpload = false;
}
/** edit_photo.js END **/
/** edit_contact.js BEGIN **/
function checkContactForm(){
	if (isNaN(getValue('contact_cp'))){
		alert('El código postal debe ser un n&uacute;mero');
		return false;
	}
	return true;
}

function openConfirmPass(){
	openNode('confirm_password_div');
	closeNode('confirm_pass_link');
	closeNode('confirm_password_result');
}

function passwordConfirm(){
	var email = $('contact_alt_email').value;
	if(!validateEmail(email)){
		alert('Por favor, escriba correctamente el correo electronico');
		return;
	}
	password = $('confirmation_password').value;
	var params = {'password':password,'email':email};
	closeNode('confirm_password_div');
	$('confirm_password_result').innerHTML = 'Verificando contraseña...';
	openNode('confirm_password_result');
	ajaxRequest(MEMBERS,'password_confirmation',params,displayPasswordConfirmation);
}

function displayPasswordConfirmation(html){
	if(!(html.status))
		closeNode('confirm_password_div');
	$('contact_alt_email').value = '';
	$('confirmation_password').value = '';
	openNode('confirm_pass_link');
	$('confirm_password_result').innerHTML = html.message
}

function updateContactProfile(userId){
	var email = $('contact_pred_email_select').value;
	if (waitFlagEdit){
		alert('Por favor, espere a terminar la última acción.');
		return;
	}
	waitFlagEdit = true;
	if (!checkContactForm()){
		waitFlagEdit = false;
		return;
	}
	var im = getValue('contact_im');
	var address = getValue('contact_address');
	var website = getValue('contact_website');
	var gamertag_psn = getValue('gamertag_psn');
	var gamertag_xbox = getValue('gamertag_xbox');
	var cp = getValue('contact_cp');
	var params = {'edit_section':'contact','email':email,'im':im,'address':address,'website':website,'cp':cp,'user_id':userId,'gamertag_xbox':gamertag_xbox,'gamertag_psn':gamertag_psn};
	var twitterSync = $('contact_twitter_sync');
	if(twitterSync != null)
		params.twitter_sync = twitterSync.checked ? 1 : 0;
	$('confirmation_message_contact_edit').innerHTML = 'Actualizando datos. Por favor espere...';
	ajaxRequest(MEMBERS,'edit_members',params,displayContactEditConfirmation);
}

function displayContactEditConfirmation(html){
	if(html.msj)
		alert(html.msj);
	$('confirmation_message_contact_edit').innerHTML = html.display;
	waitFlagEdit = false;
}

function updatePersonalProfile(userId){
	if (waitFlagEdit){
		alert('Por favor, espere a terminar la &uacute;ltima acci&oacute;n.');
		return;
	}
	waitFlagEdit = true;
	if (!checkContactForm()){
		waitFlagEdit = false;
		return;
	}
	interests = getValue('edit_interest');
	fav_music = getValue('edit_fav_music');
	fav_tv = getValue('edit_fav_tv');
	fav_movies = getValue('edit_fav_movies');
	fav_games = getValue('edit_fav_games');
	about = getValue('edit_about_me');
	params = {'edit_section':'personal','interests':interests,'fav_music':fav_music,'fav_tv':fav_tv,'fav_movies':fav_movies,'fav_games':fav_games, 'user_id': userId, 'about':about};
	$('confirmation_message_personal_edit').innerHTML = 'Actualizando datos. Por favor espere...';
	ajaxRequest(MEMBERS,'edit_members',params,displayContactEditConfirmationMessages);
}

function displayContactEditConfirmationMessages(html){
	if(html.msj)
		alert(html.msj);
	$('confirmation_message_personal_edit').innerHTML = html.display;
	waitFlagEdit = false;
}
/** edit_contact.js END **/

/** activate.js BEGIN **/
function activateBasicProfile(){
	name = $('edit_name').value;
	if (name==''){
		alert('Ingrese un nombre válido');
		return;
	}
	lname = getValue('edit_lastname');
	nick = getValue('edit_nickname');
	email = getValue('activate_email');
	key = getValue('activate_key');
	params = {'email': email, 'key': key, 'name': name,'lastname': lname,'nickname':nick};
	$('confirmation_message_basic_edit').innerHTML = 'Actualizando datos. Por favor espere...';
	ajaxRequest(MEMBERS,'activar_cuenta',params,displayActivation);
}

function displayActivation(html){
	if(html.status){
		window.location.href = html.link;
	}else{
		alert(html.message);
	}
}
/** activate.js END **/

/** edit_basic.js BEGIN**/
var flagCountry;
var flagHomeCountry;

windowOnloadAdd(function(){
	if($('selected_country')){
		var autoComp =  new autoCompleteDrop 
		(
			{
				input_id		:	'selected_country',
				section			: 	MEMBERS,
				action			:	'members_get_locations',
				autoInsert		: 	true,
				dropDownClick	:	setCountry,
				autoSelectFirst :	true
			}
		);		
		var autoComp =  new autoCompleteDrop 
		(
			{
				input_id		:	'selected_home_country',
				section			: 	MEMBERS,
				action			:	'members_get_locations',
				autoInsert		: 	true,
				dropDownClick 	:	setHomeCountry,
				autoSelectFirst :	true
			}
		);	
		if($('selected_country').value!='')
			flagCountry = true;
		else
			flagCountry = false;
			
		if($('selected_country').value!='')	
			flagHomeCountry = true;
		else
			flagHomeCountry = false;
			
		closeNode('country_selector');
		closeNode('country_home_selector');
	}
});

function setCountry(){
	flagCountry = true;
	$('country_div').innerHTML = getValue('selected_country');
	toggleCountryInput();
}

function toggleCountryInput(){
	var countryDiv = $('country_div_container');
	if (countryDiv.style.display == 'none'){
		show($('country_div_container'));
		hide($('selected_country'));
	}else{
		hide($('country_div_container'));
		show($('selected_country'));
		$('selected_country').value = '';
		$('selected_country').focus();
	}
}

function setHomeCountry(){
	flagHomeCountry = true;
	$('country_home_div').innerHTML = getValue('selected_home_country');
	toggleCountryHomeInput();
}

function toggleCountryHomeInput(){
	var homeDiv = $('country_home_div_container');
	if (homeDiv.style.display == 'none'){
		show($('country_home_div_container'));
		hide($('selected_home_country'));
	}else{
		hide($('country_home_div_container'));
		show($('selected_home_country'));
		$('selected_home_country').value = '';
		$('selected_home_country').focus();
	}
}

function removeCountry(e){
	var key = getPressedKey(e);
	if(key!=9&&key!=16)
		flagCountry = false;
}

function removeHomeCountry(e){
	var key = getPressedKey(e);
	if(key!=9&&key!=16)
		flagHomeCountry = false;
}

function clearCountry(){
	if(!flagCountry)
		$('selected_country').value='';
}

function clearHomeCountry(){
	if(!flagHomeCountry)
		$('selected_home_country').value='';
}
	
function checkNick(){
	nick = $('edit_nickname').value;
	messageDiv = $('confirmation_message_email');
	
	if (trim(nick)==''){
		messageDiv.innerHTML = 'Escriba un nickname antes de presionar el bot&oacute;n verificar.';
		waitFlagEmail = false;
		return;
	}
	
	messageDiv.innerHTML = 'Verificando...';
	
	ajaxRequest(MEMBERS,'members_check_nick',nick,displayEmailConfirmation);
}

function displayEmailConfirmation(html){
	$('confirmation_message_email').innerHTML = html;
	waitFlagEmail = false;
}

function checkBasicForm(){
	if ($('edit_name').value==''){
		alert('Ingrese nombre.');
		return false;
	}
	if($('edit_sex')){
		if ($('edit_sex').value==-1){
			alert('Ingrese sexo.');
			return false;
		}
		if (getValue('edit_month')==-1||getValue('edit_day')==-1||getValue('edit_year')==-1){
			alert('Verifique su fecha de nacimiento');
			return false;
		}
	}	
	if($('selected_country')){
		if ($('selected_country').value==''){
			alert('Ingrese su ciudad de nacimiento.');
			return false;
		}
		if ($('selected_home_country').value==''){
			alert('Ingrese su ciudad de residencia.');
			return false;
		}
	}
	return true;
}

var waitFlagEdit = false;

function updateBasicProfile(userId){
	if (!checkBasicForm())
		return false;
	
	basic_name = getValue('edit_name');
	basic_lastname = getValue('edit_lastname');
	basic_nick = getValue('edit_nickname');
	
	if (basic_nick.length>15){
		alert('Su nick debe contener máximo 15 caracteres');
		return false;
	}
	if($('edit_sex')){
		basic_sex = getValue('edit_sex');
		basic_month = getValue('edit_month');
		basic_year = getValue('edit_year');
		basic_day = getValue('edit_day');
		basic_country = getValue('selected_country');
		basic_country_home = getValue('selected_home_country');
		edit_section = 'basic';
	}else
		edit_section = 'email_confirmation';
		
	if(edit_section=='basic')
		params = { 'edit_section': 'basic','name': basic_name,'lastname': basic_lastname,'nickname':basic_nick,'sex': basic_sex,'month':basic_month,'year':basic_year,'day':basic_day,'country':basic_country,'home_country':basic_country_home, 'user_id': userId };
	else
		params = { 'edit_section': 'email_confirmation','name': basic_name,'lastname': basic_lastname,'nickname':basic_nick,'user_id': userId };
		
	$('confirmation_message_basic_edit').innerHTML = 'Actualizando datos. Por favor espere...';
	
	if(edit_section=='basic')
		ajaxRequest(MEMBERS,'edit_members',params,displayBasicEditConfirmation);
	else
		ajaxRequest(MEMBERS,'edit_members',params,redirectLogin);
}

function displayBasicEditConfirmation(html){
	$('confirmation_message_basic_edit').innerHTML = html.display;
}

function redirectLogin(html){
	window.location.href = html;
}
/** edit_basic.js END**/

/** edit_signature.js BEGIN **/
var limitSignature = 155;

function countSignatureSize(){
	signatureTxt = $('txta_signature').value;
	if(signatureTxt.length > limitSignature)
		$('txta_signature').value = signatureTxt.substring(0,limitSignature);
	else{
		counter = limitSignature-signatureTxt.length;
		$('signatureCounter').innerHTML = 'Faltan <b>'+counter+'</b> caractéres';
	}
}

function classicUploadSuccessSign(obj){
	if (obj.status){
		$('previewSignature').innerHTML = '<img width="260" src="'+obj.image+'"/>';
		show('delSignLink');
	}else{
		alert(obj.message);
	}
	hide('progressContSign');
	$('messageSign').innerHTML = '';
}

function delSignature(){
	ajaxRequest(MEMBERS,'delete_own_signature','',doneDeleteSignature);
}

function doneDeleteSignature(res){
	if(res.status){
		hide('delSignLink');
		$('previewSignature').innerHTML = '';
	}
	$('messageSign').innerHTML = res.message;
}

function clasicSignForm(){
	hide('swfSignFrm');
	show('classic_upload_signature');
}

function doneEditPassword(obj){
	if (obj.status)
		$('confirmation_message_password_edit').innerHTML = obj.message;
	else
		alert(obj.message);
}
/** edit_signature.js BEGIN **/

/** friends.js BEGIN **/
tmpFriendId = 0;

function sendFriendRequest(idFriend){
	try{$('f'+idFriend+'_sub_div').innerHTML  = 'Enviando solicitud...';}catch(e){}
	tmpFriendId = idFriend;
	ajaxRequest(MEMBERS,'send_friend_request',idFriend,displayFriendRequestResult);
}

function displayFriendRequestResult(html){
	$('f'+tmpFriendId+'_sub_div').innerHTML = html;//friend_2_request_result
}

function deleteFriend(idFriend,element){
	nick = $('f'+idFriend+'nick').innerHTML;
	if (confirm('¿Realmente desea eliminar de sus amigos a '+nick+'?'))
		ajaxRequest(MEMBERS,'deleteFriend',idFriend,function(obj){deleteFriendResult(obj,element);});
}

function deleteFriendResult(obj,element){
	if (obj.status){
		removeEl(element);
		removeNode('f'+obj.id+'div');
		
	}else
		alert(obj.message);
}
/** friends.js END **/

/** Inbox_outbox.js BEGIN**/
function deleteConversation(idOriginal)
{
	if (confirm('¿Realmente desea eliminar esta conversación?'))
		ajaxRequest(MEMBERS,'deleteConversation',idOriginal,doneDelConversation,idOriginal);
}

function doneDelConversation(obj){
	if (obj.status){
		if ($('in_'+obj.localdata+'_id'))
			removeNode('in_'+obj.localdata+'_id');
		else
			window.location.href = obj.redirect;
	}else
		alert(obj.message);
}
/** Inbox_outbox.js END**/

/** invite.js BEGIN **/
windowOnloadAdd(function(){
	if($('searchCont'))
	{
		disable('searchCont','sendInvite');
		closeNode('mailDiv');
	}
});

function validateForm(){
	if ((getValue('userMail')=='')||(getValue('memberPwd')==''))
		disable('searchCont');
	else
		enable('searchCont');
}

function showContactForm(mail){
	openNode('mailDiv');
	$('headerMail').innerHTML = 'Invitar a mis contactos de <b>'+mail+'</b>';
	$('searchCont').mail = mail;
	$('searchCont').onclick = function (){searchContacts(this.mail)};
	if((mail=='MSN')||(mail=='outlook')){
		closeNode('atLbl');
		$('mail_advert').innerHTML = '';
		$('userDomain').value = 'msn';
		closeNode('mail_advert');
		$('img_msn').src = TEMPLATES_URL+'/images/logo_msn.jpg';
		$('img_yahoo').src = TEMPLATES_URL+'/images/logo_yahoo_bw.jpg';
		//$('img_gmail').src = TEMPLATES_URL+'/images/logo_gmail_bw.jpg';
	}else{
		if(mail=='Gmail'){
			closeNode('mail','atLbl');
			//$('mail').innerHTML = '<option>'+mail+'.com</option><option>googlemail.com</option>';
			$('userDomain').value = 'gmail';
			closeNode('mail_advert');
			$('img_msn').src = TEMPLATES_URL+'/images/logo_msn_bw.jpg';
			$('img_yahoo').src = TEMPLATES_URL+'/images/logo_yahoo_bw.jpg';
			//$('img_gmail').src = TEMPLATES_URL+'/images/logo_gmail.jpg';
		}else if(mail=='Yahoo'){
			closeNode('mail','atLbl');
			//$('mail').innerHTML = '<option>'+mail+'.com</option>';
			$('mail_advert').innerHTML = ' (Escriba solo el nombre de usuario) ';
			openNode('mail_advert'); 
			$('userDomain').value = 'yahoo';
			$('img_msn').src = TEMPLATES_URL+'/images/logo_msn_bw.jpg';
			$('img_yahoo').src = TEMPLATES_URL+'/images/logo_yahoo.jpg';
			//$('img_gmail').src = TEMPLATES_URL+'/images/logo_gmail_bw.jpg';
		}
	}
}
	
function searchContacts(mail){
	pwd = getValue('memberPwd');
	domain = getValue('userDomain');
	email = trim(getValue('userMail'));
	$('invite_confirm').innerHTML = 'Buscando contactos...';
	params = {'email':email,'password':pwd,'domain':domain};
	ajaxRequest(CONTACT_SECTION,'search_member_invite_contacts',params,displayContacts);
}

function displayContacts(contacts){
	if(contacts.anyContacts){
		$('cont_list').innerHTML = contacts.html;
		$('invite_confirm').innerHTML = '';
		closeNode('searchCont');
		openNode('cont_list');
	}else{
		$('invite_confirm').innerHTML = 'No se encontraron contactos';
		$('cont_list').innerHTML = '';
	}
}
	
function displayInvite(message){
	$('invite_confirm').innerHTML = '<br/>'+message;
	closeNode('cont_list');
	openNode('searchCont');
	$('contactsTable').innerHTML = '';
	$('registeredTable').innerHTML = '';
}
/** invite.js END **/

/** shoutbox.js BEGIN **/
function sendWall(userId){
	comment = getValue('comment_box_message');
	if (trim(comment)==''){
		alert('Por favor escriba un mensaje');
		return;
	}
	if (comment.length > 800){
		alert('Se excedió la longitud máxima permitida del comentario. Por favor reduce el tamaño.');
		return;
	}
	$('comment_ajax_message').innerHTML = '<center>Enviando comentario...</center><br/>';
	ajaxRequest(MEMBERS,SEND_MEMBERS_SHOUTBOX_MESSAGE,{ 'user_id': userId, 'comment': comment },refreshCommentBox);
}

function refreshCommentBox(arr){
	if (arr.status)
		$('shoutbox').innerHTML = arr.html;
	else
		alert(arr.message);
	$('comment_ajax_message').innerHTML = '';
}

function validateWall(){
	if(getValue('comment_box_message')!='')
		enable('sendWallBtn');
	else
		disable('sendWallBtn');
}

function deleteShoutbox(idMessage,idMember){
	if (confirm('¿Realmente desea eliminar este mensaje?')){
		$('sh_'+idMessage+'_id').innerHTML = 'Eliminando...';
		ajaxRequest(MEMBERS,'deleteShoutbox',{ 'user_id': idMember, 'comment': idMessage },doneDeleteShoutbox,idMessage);
	}
}

function doneDeleteShoutbox(obj){
	if (obj.status)
		removeNode('sh_'+obj.localdata+'_id');
	else
		alert(obj.message);
}
/** shoutbox.js END **/

/** ban.js BEGIN **/
function reportAvatar(idUser, domain){
	if (confirm('¿Realmente desea reportar este avatar?')){
		$('report'+idUser).href = '#';
		$('report'+idUser).innerHTML = 'Enviando...';
		ajaxRequest(MEMBERS,'reportAvatar',{'id':idUser,'domain':domain},reportAvatarResult);
	}
}
function reportAvatarResult(obj){
	if (obj.status){
		$('report'+obj.id).innerHTML = 'Reportado';
		return;
	}
	alert(obj.message);
	$('report'+obj.id).href = "javascript:reportAvatar("+obj.id+",'"+CURRENT_DOMAIN+"');";
	$('report'+obj.id).innerHTML = 'Reportar';
}

function banAvatar(url, idUser){
	if (confirm('¿Realmente desea eliminar este avatar?'))
		httpRequest(url,{'idUser':idUser});
}
function banAvatarResult(obj){
	if (obj.status)
		$('avatar_pic').src = obj.avatar;
	else
		alert(obj.message);
}

function banStatus(idUser){
	if (confirm('¿Realmente desea eliminar el estatus de este usuario?'))
		ajaxRequest(MEMBERS,'banStatus',{'idUser':idUser},banStatusResult);
}
function banStatusResult(obj){
	if (obj.status){
		$('status_message').className = 'block cred';
		$('status_message').innerHTML = obj.html;
		$('moderate_status_message').innerHTML = '';
	}else
		alert(obj.message);
}
/** ban.js END **/

var openedNode;
function memebers_editor_Onload(){
	openedNode = 'members_basic';
	closeNode('members_contact');
	closeNode('members_personal');
	closeNode('members_picture');
	closeNode('members_signature');
	closeNode('members_password');
	if(window.location.hash == '#preferencias'){
		showEditor('members_preferences');
		active(this,'edit_container',405);
	}
}

function showEditor(editorId){
	openNode(editorId);
	if(editorId!=openedNode)
		closeNode(openedNode);
	openedNode = editorId;
}

function active(element,parent,sizeHeight){
	var parent = $(parent);
	var spans = parent.getElementsByTagName('span');
	var length = spans.length;
	for(var i=0; i<length; i++){
		if(spans[i] != element)
			spans[i].className = spans[i].className.replace('active',''); 
	}
	if(!/active/.test(element.className))
		addClass(element,'active');
	$('left-side-menu').style.height = sizeHeight+'px';
}

function changeImage(){
	hide($('prev_photo'));
	show($('edit_photo'));
}

function changeTab(num){
	if(num == 1){
		hide($('visits'));
		show($('friends'));
	}else{
		hide($('friends'));
		show($('visits'));
	}
}

function actualizar(){
	show($('new_status'));
	show($('actualizar'));
	hide($('status_message'));
	hide($('status_date'));
	hide($('status_error'));
}

function saveStatus(){
	var status;
	status = $('new_status').value;
	resultSpan = $('status_message');
	resultSpan.innerHTML = 'Guardando...';
	ajaxRequest(MEMBERS,'save_member_status',status,displayStatusConfirmation);
}

function displayStatusConfirmation(html){
	$('new_status').value = '';		
	errorSpan = $('status_error');
	resultSpan = $('status_message');
	dateSpan = $('status_date');
	if(!html['result']){
		errorSpan.innerHTML = html['error'];
		resultSpan.innerHTML = html['message'];
		show($('status_message'));
		show($('status_error'));			
		hide($('new_status'));
		hide($('actualizar'));
	}
	else{
		show($('status_message'));
		show($('status_date'));
		resultSpan.innerHTML = html['message'];
		errorSpan.innerHTML = '';
		dateSpan.innerHTML = html['date'];
		hide($('new_status'));
		hide($('actualizar'));
	}
}
/** members_editor.tpl END **/

/**/
var SEND_FRIEND_REQUEST;
var MEMBER_FRIEND_LINK;
var MEMBER_ID;
var AVANCED_SEARCH_WINDOW = false;
/******************************************/
//ajax pagination data for friends
var ACTUAL_LETTER = 'all';
var ACTUAL_SEARCH_BY_FIELD = 'nickname';
var ACTUAL_PAGE = 1;
var ACTUAL_PAGINATION = 'SHOW_MEMBERS'
var MORE_ELEMENTS = true;
/*****************************************/

windowOnloadAdd(
	function(){
		if($('alphabar'))
			$('alphabar').lastSelectedLink = 'link_all';
	}
);

function hoverFriendBox(element){
	if(!isDefined(element.over))
		element.over = true;
	if(element.over){
		element.style.backgroundColor = '#EFEFEF';
		element.style.border = '1px solid #B3DBEF';
		try{show($(element.id+'_delete'));}catch(e){}
		try{show($(element.id+'_message'));}catch(e){}
		element.over = false;
	}
	else{
		element.style.backgroundColor = '#FFFFFF';
		element.style.border = '1px solid #DFDFDF';
		try{hide($(element.id+'_delete'));}catch(e){}
		try{hide($(element.id+'_message'));}catch(e){}
		element.over = true;
	}
}

function GoToAlpha(by){
	var params = new Object();
	params.alpha = by;
	params.field = $('filterBy').value;
	params.usuario = MEMBER_ID;
	loading(true);
	$($('alphabar').lastSelectedLink).className = 'alphabarLink';
	var idSelectedLink = 'link_' + by;
	$('alphabar').lastSelectedLink = idSelectedLink;
	$(idSelectedLink).className = 'alphabarLinkSelected';
	if(by != 'all'){
		startAjaxPagination(true);
	}else{
		window.location = MEMBER_FRIEND_LINK;
		startAjaxPagination(false);
	}
	ajaxRequest(
		CURRENT_SECTION,
		'filter_friends',
		params,
		function (dat){
			if(dat.data){				
				$('users_list').innerHTML = dat.data;
				$('box_ajax_pagination').innerHTML = dat.pagination;
			}else{					
				$('users_list').innerHTML = dat.message;
				hide($('box_ajax_pagination'));
			}
			loading(false);
		}
	);
}

function loading(bool){
	try{
		if(bool){
			show($('ajax_loader'));
			show($('ajax_loader_global'));
		}
		else{
			hide($('ajax_loader'));
			hide($('ajax_loader_global'));
		}
	}catch(e){} 
}

function advancedSearch(bool){
	try{
		if(bool){
			show($('global_users_list'));
			hide($('users_list'));
		}
		else{
			hide($('global_users_list'));
			show($('users_list'));
			disabledDiv($('alphabar'),false);
			disabledDiv($('box_pagination'),false);
			disabledDiv($('box_ajax_pagination'),false);
		}
	}catch(e){}
}

function startAjaxPagination(bool){
	try{
		if(bool){
			var ACTUAL_LETTER = $('alphabar').lastSelectedLink.replace('link_','');
			var ACTUAL_SEARCH_BY_FIELD = $('filterBy').value;
			var ACTUAL_PAGE = 1;
			var ACTUAL_PAGINATION = 'SHOW_MEMBERS';
			hide($('box_pagination'));
			show($('box_ajax_pagination'));
		}
		else{
			var ACTUAL_LETTER = $('alphabar').lastSelectedLink.replace('link_','');
			var ACTUAL_SEARCH_BY_FIELD = $('filterBy').value;
			var ACTUAL_PAGE = 1;
			var ACTUAL_PAGINATION = 'SHOW_MEMBERS';
			show($('box_pagination'));
			hide($('box_ajax_pagination'));	
		}
	}catch(e){}
}

function paginationGo(bool){
	var params = new Object();
	params.alpha = $('alphabar').lastSelectedLink.replace('link_','');
	params.field = $('filterBy').value;
	if(bool)
 		ACTUAL_PAGE ++;
 	else if(ACTUAL_PAGE>0)
 		ACTUAL_PAGE --;
 	else
 		return;
	params.page = ACTUAL_PAGE;
	loading(true);
 	ajaxRequest(
 		CURRENT_SECTION,
 		'filter_friends',
 		params,
 		function (res){
 			if(res.data != ''&& res.data){
 				$('users_list').innerHTML =  res.data;
 			}
 			else{
 				if(bool)
 					ACTUAL_PAGE --;		
 			}
 			loading(false);
 		}
 	);
}

/******************************************/
//ajax pagination data for friends
var globalsearch_ACTUAL_PAGE = 1;
var globalsearch_ACTUAL_PAGINATION = 'SHOW_GLOBAL_MEMBERS'
var globalsearch_MORE_ELEMENTS = true;
var specificSearch  = false;
/*****************************************/

function initGlobalSearch(bool){
	specificSearch =  bool;
	globalsearch_ACTUAL_PAGE = 0;
}

function paginationGoGlobalSearch(bool){
	var params = new Object();
	if(bool)
 		globalsearch_ACTUAL_PAGE ++;
 	else if(globalsearch_ACTUAL_PAGE>0)
 		globalsearch_ACTUAL_PAGE --;
 	else
 		return;
	params.page = globalsearch_ACTUAL_PAGE;
	loading(true);
	if(specificSearch)
		search(params.page);
	else
		search_users (params.page);
}

function ajaxPaginationVisits(obj){
	loading(true);
	disabledDiv($('box_ajax_pagination_visits'),true); 	
	ajaxRequest(
		CURRENT_SECTION,
 		'filter_visits',
 		obj,
 		function (res){
 			if(res.data){	
 				$('visits_list').innerHTML =  res.data;
 				$('box_ajax_pagination_visits').innerHTML = res.pagination;
 			}
 			disabledDiv($('box_ajax_pagination_visits'),false); 
 			show($('box_ajax_pagination_visits'));	 			
 			loading(false);
 		}
	);		
}

function ajaxPagination(obj){
	loading(true);
	disabledDiv($('box_ajax_pagination'),true); 
	obj.field = $('filterBy').value; 
	if(obj.global_specific_search == '1'){
		search(obj);
		return;
	}
	else if(obj.global_search == '1'){
		 search_users (obj);
		 return;
	}
	else{ 
		ajaxRequest(
			CURRENT_SECTION,
	 		'filter_friends',
	 		obj,
	 		function (res){
	 			if(res.data != ''&& res.data){
	 				$('users_list').innerHTML =  res.data;
	 				$('box_ajax_pagination').innerHTML = res.pagination;
	 			}
	 			disabledDiv($('box_ajax_pagination'),false); 
	 			loading(false);
	 		}
		);
	}
}

function initSelectValue(id_select){
	var options = $(id_select).getElementsByTagName('option');
	var select_value = $(id_select+'_input').value;
	for(var i in options)
		if(typeof options[i]=='object')
			if(select_value==options[i].value)
				options[i].selected="selected";
}
/**/

/*My Games*/
function changeTabMyGames(tab_number,user_id){
	if(tab_number==1){
		$('tab_1_'+user_id).className = 'selected';
		$('tab_2_'+user_id).className = '';
		$('tab_3_'+user_id).className = '';
		$('my_favorites_'+user_id).style.display = 'block';
		$('my_collection_'+user_id).style.display = 'none';
		$('my_wishlist_'+user_id).style.display = 'none';
	}else if(tab_number==2){
		$('tab_1_'+user_id).className = '';
		$('tab_2_'+user_id).className = 'selected';
		$('tab_3_'+user_id).className = '';
		$('my_favorites_'+user_id).style.display = 'none';
		$('my_collection_'+user_id).style.display = 'block';
		$('my_wishlist_'+user_id).style.display = 'none';	
	}else{
		$('tab_1_'+user_id).className = '';
		$('tab_2_'+user_id).className = '';
		$('tab_3_'+user_id).className = 'selected';
		$('my_favorites_'+user_id).style.display = 'none';
		$('my_collection_'+user_id).style.display = 'none';
		$('my_wishlist_'+user_id).style.display = 'block';
	}	
}

function changePagination(action,page,user_id){
	params = {'page':page, 'user_id':user_id};
	ajaxRequest(GAMES,action,params,applychangePagination);			
}

function applychangePagination(arr){
	if(arr.status)
	    $(arr.container).innerHTML = arr.html;
	else
		$(arr.container).innerHTML = arr.html;
}

function hoverCloseBlock(element){
	if(!isDefined(element.over))
		element.over = true;
	if(element.over){
		try{show($(element.id+'_delete'));}catch(e){}
		element.over = false;
	}else{
		try{hide($(element.id+'_delete'));}catch(e){}
		element.over = true;
	}
}

function deleteFromFavorites(user_id, filter_id, element){
	if(confirm('¿Deseas eliminar este juego de la lista de favoritos?')){	
		params = { 'user_id':user_id, 'filter_id':filter_id, 'element':element.parentNode.id, 'action':'get_my_favorites', 'page':$('page_1_'+user_id).value};
		ajaxRequest(GAMES,'delete_from_favorites',params,applyChangesDeleteFrom);	
	}
}

function deleteFromCollection(user_id, filter_id, element){
	if(confirm('¿Deseas eliminar este juego de tu coleccion?')){
		params = { 'user_id':user_id, 'filter_id':filter_id, 'element':element.parentNode.id, 'action':'get_my_collection','page':$('page_2_'+user_id).value };
		ajaxRequest(GAMES,'delete_from_collection',params,applyChangesDeleteFrom);	
	}
}

function deleteFromWishlist(user_id, filter_id, element){
	if(confirm('¿Deseas eliminar este juego de tu lista de deseos?')){	
		params = { 'user_id':user_id, 'filter_id':filter_id, 'element':element.parentNode.id, 'action':'get_my_wishlist','page':$('page_3_'+user_id).value };
		ajaxRequest(GAMES,'delete_from_wishlist',params,applyChangesDeleteFrom);	
	}
}

function applyChangesDeleteFrom(arr){
	if(arr.status){
		$(arr.container).parentNode.removeChild($(arr.container));
		changePagination(arr.action,arr.page,arr.user_id);
	}
}

function sendEmailConfirmation(email){
	if (trim(email)==''){
		alert('Por favor, escriba un correo válido');
		return;
	}
	ajaxRequest(MEMBERS,'sendEmailConfirmation',email,doneEmailConfirm);
}
function doneEmailConfirm(obj){
	alert(obj.message);
}
/**/