function createAlbum() {

	if ( ! Validation.validate($('album_name'))) {
		return;
	}

	Effect.BlindUp('div_create_album');
	AppObj.Ajax.sendForm($('form_create_album'),'div_album_edit',{loading:false,asynchronous:false});
	$('album_name').value='';
	$('album_desc').value='';
	Effect.BlindDown('div_album_edit'); 

}
function cancelCreateAlbum() {

	Effect.BlindUp('div_create_album');
	$('album_name').value='';
	$('album_desc').value='';
	Effect.BlindDown('div_create_album_link'); 

}

function startEdit(intRowId) {
	$('div_desc_edit_' + intRowId).show();
	$('div_desc_' + intRowId).hide();
	$('desc_' + intRowId).focus();
}

function doEdit(intRowId) {
	var oldvalue = $('div_desc_' + intRowId).innerHTML;
	var newvalue = $('desc_' + intRowId).value;
	if (oldvalue != newvalue) {
		$('div_desc_' + intRowId).innerHTML = newvalue;
		$('dirty_' + intRowId).value = 'true';
		AppObj.Ajax.sendForm($('form_edit_photo_desc_' + intRowId),'',{loading:false,asynchronous:false});
	}
	$('div_desc_photo_edit_count_' + intRowId).hide();
	Effect.BlindDown('div_desc_' + intRowId);
	Effect.BlindUp('div_desc_edit_' + intRowId);

}

function doEditVideoDesc(intRowId) {
	var oldvalue = $('div_video_desc_' + intRowId).innerHTML;
	var newvalue = $('video_desc_' + intRowId).value;
	if (oldvalue != newvalue) {
		$('div_video_desc_' + intRowId).innerHTML = newvalue;
		AppObj.Ajax.sendForm($('form_edit_video_desc_' + intRowId),'');
	}
	$('div_desc_video_edit_count_' + intRowId).hide();
	Effect.BlindDown('div_video_desc_' + intRowId);
	Effect.BlindUp('div_video_desc_edit_' + intRowId);

}
function removePhoto(intRowId) {
	var hidden = $('editingAlbum');
	if (! confirm('Esta seguro que desea eliminar la foto del álbum ?')) {
		return;
	}
	$('removed_' + intRowId).value = 'true';
	$('tr_photo_' + intRowId).hide();
	$('tr_photo_' + intRowId + '_space').hide();
	$('editingAlbumDirty').value = '1';
	if ($('intRowCount').value == 0) {
		Effect.BlindUp('div_photo_list');
	}
	$('intRowCount').value = $('intRowCount').value  - 1;
	AppObj.Ajax.updaterAjax('/modules/microsites/upload/ajax_remove_image.php?idimage=' + $('imgid_' + intRowId).value + '&albumid=' + hidden.value,'');
}

function setAvatar(intRowId) {
	var hidden = $('editingAlbum');

	$('div_notice_avatar').value='';
	$('div_notice_avatar').show();
	AppObj.Ajax.updaterAjax('/modules/microsites/upload/ajax_setavatar.php?idimage=' + $('imgid_' + intRowId).value + '&albumid=' + hidden.value,'div_notice_avatar',{loading:false});
	AppObj.Ajax.updaterAjax('/modules/microsites/upload/ajax_update_image_list.php?albumid=' + hidden.value,'div_photo_list',{loading:true});
//	$('div_photo_list').hide();
//	Effect.BlindDown('div_photo_list');
}

function editAlbum() {
	var name = $V('album_name_edit'); 
	name = name.trim();
	if (name.length == 0 ) {
		alert('El nombre del álbum es requerido');
		$('album_name_edit').focus();
		return;
	}
	Effect.BlindDown('div_create_album_link');
	Effect.BlindUp('div_album_edit');
	if ($V('editingAlbumDirty') == '1') {
		AppObj.Ajax.updaterAjax('/modules/microsites/upload/ajax_album_list.php','div_album_list');
		$('div_album_list').hide();
		Effect.BlindDown('div_album_list');	
	}
}
function editAlbumList(intRowId) {
	var hidden = $('album_id_' + intRowId);
	var options = {
		onComplete: function() {
								myLightbox.updateImageList()
							  }
		
	};
	AppObj.Ajax.updaterAjax('/modules/microsites/upload/ajax_edit_created_album.php?albumid=' + hidden.value,'div_album_edit', options);
	Effect.BlindDown('div_album_edit'); 
	Effect.BlindUp('div_create_album_link');
	Effect.BlindUp('form_create_album');
	Effect.BlindUp('div_expand_album_' + intRowId);

}

function editAlbumName() {
	$('div_edit_album_name_edition' ).show();
	$('div_edit_album_name').hide();
	$('album_name_edit').focus();

}

function editAlbumDesc() {
	$('div_edit_album_desc_edition' ).show();
	$('div_edit_album_desc').hide();
	$('album_desc_edit').focus();

}
function doEditAlbumName() {
	if ($('hidden_album_name').value != $('album_name_edit').value) {
		$('div_album_name' ).innerHTML = $('album_name_edit').value;
		$('hidden_album_name').value = $('album_name_edit').value;
		AppObj.Ajax.sendForm($('form_edit_album_name'),'',{loading:false,asynchronous:false});
		$('editingAlbumDirty').value = '1';
	}
	Effect.BlindDown('div_edit_album_name');
	Effect.BlindUp('div_edit_album_name_edition');

}
function doEditAlbumDesc() {
	if ($('hidden_album_desc').value != $('album_desc_edit').value) {
		$('div_album_desc' ).innerHTML = $('album_desc_edit').value;
		$('hidden_album_desc').value = $('album_desc_edit').value;
		AppObj.Ajax.sendForm($('form_edit_album_desc'),'div_create_album_link',{loading:false,asynchronous:false});
		$('editingAlbumDirty').value = '1';
	}
	Effect.BlindDown('div_edit_album_desc');
	Effect.BlindUp('div_edit_album_desc_edition');
}

function expandAlbum(intRowId, blnShowOnlyAuth){
	var strShowOnlyAuth = '';
	var strCollapseParam = '';
	if(typeof blnShowOnlyAuth != 'undefined'){
		strShowOnlyAuth = '&showonlyauth=true';
		strCollapseParam = ', ' + blnShowOnlyAuth;
	}
	var hidden = $('album_id_' + intRowId);
	
	var objTr = $('tr_data_' + intRowId);
	var objDivImages = $('div_expand_album_' + intRowId);
	
	if(!objDivImages.visible()){
		objTr.down().down().innerHTML = '<strong> - </strong>';
		var options = {
			asynchronous:false,
			onComplete: function() {
								   	myLightbox.updateImageList();
								   	Effect.BlindDown('div_expand_album_' + intRowId);		
								  }
			
		};
		AppObj.Ajax.updaterAjax('/modules/microsites/upload/ajax_expand_album.php?albumid=' + hidden.value+strShowOnlyAuth,'div_expand_album_' + intRowId, options);
	}else{
		objTr.down().down().innerHTML = '<strong> + </strong>';
		Effect.BlindUp('div_expand_album_' + intRowId);
	}
	
}

//function expandAlbum(intRowId, blnShowOnlyAuth) {
//	var strShowOnlyAuth = '';
//	var strCollapseParam = '';
//	if(typeof blnShowOnlyAuth != 'undefined'){
//		strShowOnlyAuth = '&showonlyauth=true';
//		strCollapseParam = ', ' + blnShowOnlyAuth;
//	}
//	var hidden = $('album_id_' + intRowId);
//	$('a_expand_' + intRowId).innerHTML = '<strong> - </strong>';
//	eval('var o = function () { collapseAlbum(' + intRowId + strCollapseParam + ') };');
//	$('a_expand_' + intRowId).onclick  = o;
//	var options = {
//		asynchronous:false,
//		onComplete: function() {
//							   	myLightbox.updateImageList();
//							   	Effect.BlindDown('div_expand_album_' + intRowId);		
//							  }
//		
//	};
//	AppObj.Ajax.updaterAjax('/modules/microsites/upload/ajax_expand_album.php?albumid=' + hidden.value+strShowOnlyAuth,'div_expand_album_' + intRowId, options);
//}
//function collapseAlbum(intRowId, blnShowOnlyAuth) {
//	var strShowOnlyAuth = '';
//	if(typeof blnShowOnlyAuth != 'undefined'){
//		strShowOnlyAuth = ', ' + blnShowOnlyAuth;
//	}
//	$('a_expand_' + intRowId).innerHTML = '<strong> + </strong>';
//	eval('var o = function () { expandAlbum(' + intRowId + strShowOnlyAuth +') };');
//	$('a_expand_' + intRowId).onclick  = o;
//	Effect.BlindUp('div_expand_album_' + intRowId);
//
//}
function removeAlbum(intRowId) {
	if (! confirm('Esta seguro que desea eliminar el álbum?.'+"\r\n"+'Tenga en cuenta que se eliminarán todas las imagenes que haya dentro de este album.')) {
		return;
	}
	var hidden = $('album_id_' + intRowId).value;
	Element.remove($('tr_data_' + intRowId));
	Element.remove($('tr_data_expanded_' + intRowId));
	var options = {
		onComplete: function(){
			AppObj.Ajax.updaterAjax('/modules/microsites/upload/ajax_album_list.php', 'div_album_list');
		}		
	};
	AppObj.Ajax.updaterAjax('/modules/microsites/upload/ajax_remove_album.php?albumid=' + hidden,'div_album_list', options);
	if($('table_album_list')){
		if ($('table_album_list').rows.length == 1) {
			$('div_album_list').hide();
		}
	}
	
}

function removeVideo (intRowId) {
	if (! confirm('Esta seguro que desea eliminar el video ?')) {
		return;
	}
	var hidden = $('video_id_' + intRowId).value;
	Element.remove($('tr_video_' + intRowId));
	Element.remove($('tr_video_' + intRowId + '_spacer'));
	AppObj.Ajax.updaterAjax('/modules/microsites/upload/ajax_remove_video.php?videoid=' + hidden,'');
	if ($('table_video_list').rows.length == 1) {
		Effect.BlindUp('div_videolist');
	}

}

function editVideo (intRowId) {
	$('div_video_desc_edit_' + intRowId).show();
	$('div_video_desc_' + intRowId).hide();
	$('video_desc_' + intRowId).focus();

}

function openTermsMediaFiles(){
	var strUrl = '/modules/microsites/upload/termsofmediafiles.php';
	var strWindowName = 'terminosmedia';
	var strFeatures = 'location=0,status=1,scrollbars=yes,width=580,height=600';	
	MM_openBrWindow(strUrl, strWindowName, strFeatures);
}
