
var intMessagePage = 0;
function goSettings() {
	AppObj.Ajax.updaterAjax('/modules/microsites/settings/index.php','div_microsite_content');
}
function goUpload() {
	AppObj.Ajax.updaterAjax('/modules/microsites/upload/index.php','div_microsite_content');
}
function goHome() {
	AppObj.Ajax.updaterAjax('/modules/microsites/home/index.php','div_microsite_content');
}
function goProfile() {
	AppObj.Ajax.updaterAjax('/modules/microsites/profile/index.php','div_microsite_content');
}
var clsMicrosite = {};

clsMicrosite.TabFriends = function(){ return 'friends'; };
clsMicrosite.TabTopten = function(){ return 'topten'; };

clsMicrosite.changeTabMicrositesList = function(strTab){
	AppObj.Ajax.updaterAjax('/modules/microsites/ajax_micrositeslist.php?mstab='+strTab, $('div_micrositeslist'));	
};
clsMicrosite.changeTabBookmarks = function(strTab){
	var options = {};
	if(strTab != 'news'){
		options = {
			onComplete: function() {
				myLightbox.updateImageList()
			  }
		};
	}
	if ( $V('microsite_id') != null) {
		AppObj.Ajax.updaterAjax('/modules/microsites/ajax_bookmarks.php?idmicrosite=' + $V('microsite_id') + '&mstab='+strTab, $('div_bookmarks'), options);	
	} else {
		AppObj.Ajax.updaterAjax('/modules/microsites/ajax_bookmarks.php?mstab='+strTab, $('div_bookmarks'), options);	
	}
};

function postMessage() {
	if ( ! Validation.validate($('txt_message'))) {
		return;
	}
	AppObj.Ajax.sendForm($('form_post_message'),'');
	$('div_MessageForm').hide();
	$('div_MessageAdded').show();
}
function cancelPostMessage() {
	Validation.reset($('txt_message'))
	Effect.BlindUp('div_send_message');
	$('txt_message').value='';
}

function closePostMessage(){
	cancelPostMessage();
}

function formMessage() {
	if($('div_MessageForm')){
		$('div_MessageForm').show();
		$('div_MessageAdded').hide();
	}
	
	if(!$('form_post_message')){
		doLogin({leavemsg:true});
	}else{
		if ($('div_send_message').visible()) {
			cancelPostMessage();
		} else {
			Effect.BlindDown('div_send_message');
			Effect.ScrollTo('div_send_message');
		}
	}

}

function doLogin(objParam) {
	var user = $('microsite_owner').value;
	var strParam = '';
	if(typeof objParam != 'undefined'){
		strParam = '&' + Object.toQueryString(objParam);
	}
	window.location.href = '/modules/microsites/show/dologin.php?user=' + user + strParam;
}

function doLoginAddAsFriend() {
	var idmicrosite = $('microsite_id').value;
	var strMicrosite = '&redirect=true';	
	window.location.href = '/modules/microsites/show/dologin_addasfriend.php?idmicrosite=' + idmicrosite + strMicrosite;
}

function addAsFriend(blnNotLoggued) {
	var options = {
		evalJS:true
	};
	if(typeof blnNotLoggued == 'undefined' || !blnNotLoggued){
		Object.extend(options, {
			onComplete: function(){
				Effect.BlindUp('div_add_as_friend');
				AppObj.Ajax.updaterAjax('/modules/microsites/ajax_micrositeslist.php?mstab=friends', $('div_micrositeslist'));
			}	
		});	
	}
	
	AppObj.Ajax.updaterAjax('/modules/microsites/show/ajax_addfriend.php?idmicrosite=' + $('microsite_id').value,'div_add_as_friend_temp', options);
}
function popupShareSite() {
	Effect.BlindDown('div_share_form');
	$('div_share_done').hide();
}
function readMessage(intRowId,unRead) {
	Effect.toggle('div_message_' + intRowId,'blind');
	if (unRead) {
		var newimg = $('img_message_' + intRowId).cloneNode(true);
		newimg.src='/vistas/iconos/read.gif';
		newimg.id ='newimg';
		$('img_message_' + intRowId).up().next().appendChild(newimg);
		$('img_message_' + intRowId).up().hide();
		Effect.BlindDown(newimg.up());
		var tr = $('tr_message_' + intRowId).cleanWhitespace();
		tr.firstDescendant().next().firstDescendant().style.fontWeight = 'normal';
		tr.firstDescendant().next().next().firstDescendant().style.fontWeight = 'normal';
		tr.firstDescendant().next().next().next().firstDescendant().style.fontWeight = 'normal';
		eval ('o = function () { readMessage(' + intRowId + ')};');
		tr.onclick = o;
	}
	AppObj.Ajax.updaterAjax('/modules/microsites/home/ajax_readmessage.php?idmicrosite=' + 
						$V('microsite_id')+ '&idmessage=' + $V('message_id_' + intRowId),'',{
onComplete:	function (objText) { $('btn_viewmessages').value='Ver Mensajes' + (objText.responseText!=''? ' (' + objText.responseText + ')' : '');}} );

}
function deleteMessage (intRowId) {
	if (!confirm('Esta seguro que desea eliminar este mensaje?')) {
		return;
	}
	var idmessage = $V('message_id_' + intRowId);
	Element.remove('tr_message_' + intRowId);
	Element.remove('tr_expand_message_' + intRowId);
	AppObj.Ajax.updaterAjax('/modules/microsites/home/ajax_delete_message.php?idmicrosite=' + $V('microsite_id') + '&page=' + intMessagePage + '&idmessage=' + idmessage ,'div_messages_inbox');

}
function goToMessagePage(intPage) {
	intMessagePage = intPage;
	AppObj.Ajax.updaterAjax('/modules/microsites/home/ajax_get_message.php?idmicrosite=' + $V('microsite_id') + '&page=' + intPage ,'div_messages_inbox');

}
function goToBookmarksImagePage (intPage) {
	if ($V('microsite_id')!=null) {
		AppObj.Ajax.updaterAjax('/modules/microsites/ajax_bookmarks.php?idmicrosite=' + $V('microsite_id') + '&mstab=images&page=' + intPage,'div_bookmarks',{onComplete  : function() {	myLightbox.updateImageList(); }});
	} else {
		AppObj.Ajax.updaterAjax('/modules/microsites/ajax_bookmarks.php?mstab=images&page=' + intPage,'div_bookmarks',{onComplete  : function() {	myLightbox.updateImageList(); }});
	}
}
function goToBookmarksNewsPage (intPage) {
	AppObj.Ajax.updaterAjax('/modules/microsites/ajax_bookmarks.php?mstab=news&page=' + intPage,'div_bookmarks');
}
function goToBookmarksVideoPage (intPage) {
	AppObj.Ajax.updaterAjax('/modules/microsites/ajax_bookmarks.php?mstab=video&page=' + intPage,'div_bookmarks');
}
function goToFriendsPage(intPage) {
	AppObj.Ajax.updaterAjax('/modules/microsites/ajax_micrositeslist.php?idmicrosite=' + $V('microsite_id') + '&mstab=friends&page=' + intPage,'div_micrositeslist');
}

function removeFriendMicrosite(intMicrositeId, intFriendMicrositeId){
	if (!confirm('¿Está seguro que desea remover este registro de su lista de amigos?')) {
		return;
	}
	
	var options = {
		onComplete: function(){
			clsMicrosite.changeTabMicrositesList('friends');
		}
	};
	AppObj.Ajax.updaterAjax('/modules/microsites/ajax_remove_friendmicrosites.php?microsite='+intMicrositeId+'&friend='+intFriendMicrositeId, '', options);
}

function removeBookmarkedImage(intMicrositeId, intImageId){
	if (!confirm('¿Está seguro que desea remover este elemento de sus favoritos?')) {
		return;
	}
	
	var options = {
		onComplete: function(){
			clsMicrosite.changeTabBookmarks('images');
		}
	};
	AppObj.Ajax.updaterAjax('/modules/microsites/ajax_remove_bookmarks.php?type=images&microsite='+intMicrositeId+'&element='+intImageId, '', options);
}

function removeBookmarkedVideo(intMicrositeId, intVideoId){
	if (!confirm('¿Está seguro que desea remover este elemento de sus favoritos?')) {
		return;
	}
	
	var options = {
		onComplete: function(){
			clsMicrosite.changeTabBookmarks('videos');
		}
	};
	AppObj.Ajax.updaterAjax('/modules/microsites/ajax_remove_bookmarks.php?type=videos&microsite='+intMicrositeId+'&element='+intVideoId, '', options);
}

function removeBookmarkedNews(intMicrositeId, intNewsId){
	if (!confirm('¿Está seguro que desea remover este elemento de sus favoritos?')) {
		return;
	}
	
	var options = {
		onComplete: function(){
			clsMicrosite.changeTabBookmarks('news');
		}
	};
	AppObj.Ajax.updaterAjax('/modules/microsites/ajax_remove_bookmarks.php?type=news&microsite='+intMicrositeId+'&element='+intNewsId, '', options);
}
