/**
 * Top scripts
 * 
 * This file contains all the javascripts used on the site
 *
 * @author Antoine Morcos
 * @version 1.0
 */
 
/**
 * Some global variables
 *
 * @global gallery_filter : user can choose a filter (image, video or none) for the media gallery
 * @global gallery_current_page : user current gallery page his watching
 * @global gallery_current_category : user current gallery category his watching
 * @global feeds_background_color : feeds background color variable is used to switch between white and gray background for a list of html
 items
 * @global requests_background_color : my requests background color variable is used to switch between white and gray background for a list of html
 * @global add_group_blogger_form_background_color : add-group-blogger-form background color variable is used to switch between white and gray background for a list of html
 * @global article_comment_background_color : article comment background color variable is used to switch between white and gray background for a list of html
 *
 * @author : Antoine Morcos
 * @date : 09/03/2007 18:28
 */

var gallery_filter = null;

var gallery_current_page = 1;

var gallery_current_category = null;
                           
var feed_background_color = 'white-background';

var request_background_color = 'white-background';

var management_background_color = 'white-background';

var comment_background_color = 'white-background';

var field_number = 5;

var frequency_action = 60;
var pars_updater = 'frequency_action='+frequency_action;

/**
 * Scriptaculous Ajax.InPlaceEditor two colors for high light
 *
 * @global high_light_color
 * @global high_light_end_color
 */

var high_light_color = '#FFF6D0';
var high_light_end_color = '#FFFFFF';

/**
 * date setup in the world
 *
 * @author : Antoine Morcos
 * @date : 12/02/2007 18:28
 */

var date_time = new Date();
var date_time_zone = date_time.getTimezoneOffset();
document.cookie = "date_time_zone=" + date_time_zone + "; path=/;";

/**
 * hide_status function is used to hide the status of the bowser
 *
 * @author : Antoine Morcos
 * @date : 01/03/2007 00:28
 */

function hide_status(){
window.status=''
return true
}
if (document.layers)
document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT | Event.MOUSEDOWN)
document.onmouseover=hide_status
document.onmouseout=hide_status
document.onmousedown=hide_status

/**
 * set_checkbox function is used to hide the status of the bowser
 *
 * @param form_name : form name
 * @param field_name : field name
 * @param check_value : check value
 *
 * @author : Antoine Morcos
 * @date : 17/04/2008 00:28
 */

function set_checkbox(form_name,field_name,check_value,countCheckBoxes)
{
	if(!document.forms[form_name])
		return;

	//var objCheckBoxes = document.forms[form_name].elements[field_name];
	//if(!objCheckBoxes)
	//	return;
	//var countCheckBoxes = objCheckBoxes.length;
	//if(!countCheckBoxes)
	//	objCheckBoxes.checked = check_value;
	//else
		// set the check value for all check boxes

	var objCheckBoxes;
	var box_name;

	for(var i = 0; i < countCheckBoxes; i++)
	{
		box_name = field_name+''+i;   
        objCheckBoxes = document.forms[form_name].elements[box_name];
        objCheckBoxes.checked = check_value;
	}
}

/**
 * start_updater function is used to start an Ajax.PeriodicalUpdater updater on an element 
 *
 * @param updater : updater
 *
 * @author : Antoine Morcos
 * @date : 12/02/2007 18:28
 */

function start_updater(updater)
{
	if (updater != null)
	{
		updater.start();
	}
}

/**
 * stop_updater function is used to stop an Ajax.PeriodicalUpdater updater on an element 
 *
 * @param updater : updater
 *
 * @author : Antoine Morcos
 * @date : 12/02/2007 18:28
 */

function stop_updater(updater)
{
	if (updater != null)
	{
		updater.stop();
	}
}
 
/**
 * edit_color function is used to change element's color to customise the page
 *
 * @param element_id : html element id
 * @param element_type : element type (group, profile, etc.)
 * @param element : html element to be change on the page
 * @param style_element : css attribute to be change
 * @param color : color html code
 * @param type : id or class
 *
 * @author : Antoine Morcos
 * @date : 27/02/2007 18:28
 */

function edit_color(element_id,element_type,element,style_element,color,type)
{
	var pars_color = color.replace('#', '@');
	var pars = 'element_id='+element_id+'&color='+pars_color+'&style_element='+style_element+'&element_type='+element_type;

	new Ajax.Request('/edit_colors_action.php',{method:'post',parameters:pars,
	onSuccess:function(transport)
	{
		if (transport.responseText == 1)
		{
			if (type == 'id')
			{
				Element.setStyle(element,style_element+': '+color+';');
			}
			if (type == 'class')
			{
				var tab = Element.getElementsByClassName(document.body,element);
				
				for(i=0; i<tab.length; i++)
				{
					Element.setStyle(tab[i],style_element+': '+color+';');
				}
			}
		}
		else if (transport.responseText == 0 || transport.responseText == null)
		{
			alert('error');
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * blue_effect_onmouseover, blue_effect_onmouseout functions are used to change css color attributes of an element when mouve over
 *
 * @param element : html element or html element id
 *
 * @author : Antoine Morcos
 * @date : 12/02/2007 18:28
 */
  
function blue_effect_onmouseover(element)
{
	Element.setStyle(element,'background-color: #F0F6FA');
	Element.setStyle(element,'border-color: #B0CDE2');
	Element.setStyle(element,'border-width: 1px 1px 1px 1px;');
}
  
function blue_effect_onmouseout(element)
{
	Element.setStyle(element,'background-color: #F4F4F4');
	Element.setStyle(element,'border-color: #D0D0D0');
	Element.setStyle(element,'border-width: 1px 1px 1px 1px;');
}

/**
 * green_effect_onmouseover, green_effect_onmouseout functions are used to change css color attributes of an element when mouve over
 *
 * @param element : html element or html element id
 *
 * @author : Antoine Morcos
 * @date : 12/02/2007 18:28
 */
  
function green_effect_onmouseover(element)
{
	Element.setStyle(element,'background-color: #E7FFD0');
	Element.setStyle(element,'border-color: #AAD77E');
	Element.setStyle(element,'border-width: 1px 1px 1px 1px;');
}
  
function green_effect_onmouseout(element)
{
	Element.setStyle(element,'background-color: #F4F4F4');
	Element.setStyle(element,'border-color: #D0D0D0');
	Element.setStyle(element,'border-width: 1px 1px 1px 1px;');
}

/**
 * slide_box_container function is used to slide up or down the content of a main box container
 *
 * @param container_id : html container id
 * @param triangle_id : html triangle id
 * @param updater : updater
 *
 * @author : Antoine Morcos
 * @date : 08/03/2007 18:28
 */

function slide_box_container(container_id,triangle_id,updater)
{
	if (!Element.hasClassName(container_id,'hidden'))
	{
		var box_name = container_id.replace('-container', '');
		var pars = 'box_name='+box_name+'&visible=0';
		new Ajax.Request('toggle_box_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText == 1)
			{
				//new Effect.SlideUp(div_id,{queue:'front',duration:1});
				show_hide(container_id);
	 
    			Element.update(triangle_id,'<img src="images/icons/triangle_2.gif" />');
				
				if (updater != null)
				{
					stop_updater(updater);
				}				
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
	else if (Element.hasClassName(container_id,'hidden'))
	{
		var box_name = container_id.replace('-container', '');
		var pars = 'box_name='+box_name+'&visible=1';
		new Ajax.Request('/toggle_box_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText == 1)
			{
				//Element.setStyle(div_content,'display: inline');
    			//new Effect.SlideDown(div_id,{queue:'front',duration:1});
				
				show_hide(container_id);
    
    			Element.update(triangle_id,'<img src="images/icons/triangle_1.gif" />');
				
				if (updater != null)
				{
					start_updater(updater);
				}
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * active_gallery_filter function is used to show images or movies only in the media gallery
 *
 * @param media_type : media type (image or video)
 *
 * @author : Antoine Morcos
 * @date : 12/02/2007 18:28
 */
  
function active_gallery_filter(media_type)
{
	gallery_filter = media_type;

	var pars = 'media_type='+media_type+'&category_id='+gallery_current_category+'&page='+gallery_current_page+'&gallery_current_id='+gallery_current_id+'&gallery_current_type='+gallery_current_type;

	new Ajax.Request('/update_gallery_medias_action.php',{method:'post',parameters:pars,evalJS:true,
	onSuccess:function(transport)
	{
		if (transport.responseText != '')
		{
			Element.update('gallery-media-sortable-frame',transport.responseText);
		}
		else if (transport.responseText == '' || transport.responseText == null)
		{
			alert('error');
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * show_hide function is used to show or hide an element and eventually to start or stop the updater of this element
 *
 * @param element_id : html element id
 * @param updater : updater
 * @param updater_inverse : updater inverse switching
 *
 * @author : Antoine Morcos
 * @date : 12/02/2007 18:28
 */

function show_hide(element_id,updater,updater_inverse)
{
	if ((Element.getStyle(element_id,'display') == 'none') || (Element.hasClassName(element_id,'hidden')))
	{
		Element.show(element_id);
		Element.removeClassName(element_id,'hidden');
		
		if (updater != null && updater_inverse == null)
		{
			start_updater(updater);
		}
		else if  (updater != null && updater_inverse == 'inverse')
		{
			stop_updater(updater);
		}
	}
	else
	{
		Element.hide(element_id);
		Element.addClassName(element_id,'hidden');
		
		if (updater != null && updater_inverse == null)
		{
			stop_updater(updater);
		}
		else if  (updater != null && updater_inverse == 'inverse')
		{
			start_updater(updater);
		}
	}
}

/**
 * show_hide_header_image function is used to show or hide the header image of a section
 *
 * @param element_id : element id (not html)
 * @param element_type : element type (group, profile, etc.)
 * @param image_id : html element id that contains the image
 *
 * @author : Antoine Morcos
 * @date : 27/02/2007 18:28
 */

function show_hide_header_image(element_id,element_type,image_id)
{
	var pars = 'element_id='+element_id+'&element_type='+element_type;

	new Ajax.Request('/toggle_header_image_action.php',{method:'post',parameters:pars,
	onSuccess:function(transport)
	{
		if (transport.responseText == 1)
		{
			if ((Element.getStyle(image_id,'display') == 'none') || (Element.hasClassName(image_id,'hidden')))
			{
				new Effect.Appear(image_id,{
				afterFinish:function()
				{
					Element.show(image_id);
					Element.removeClassName(image_id,'hidden');
				}
				});
			}
			else
			{
				new Effect.Fade(image_id,{
				afterFinish:function()
				{
					Element.hide(image_id);
				}
				});
			}
		}
		else if (transport.responseText == 0 || transport.responseText == null)
		{
			alert('error');
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * show_hide_header_title function is used to show or hide the header title of a section
 *
 * @param element_id : group id (not html)
 * @param element_type : element type (group, profile, etc.)
 * @param title_id : html element id that contains the title
 *
 * @author : Antoine Morcos
 * @date : 29/02/2007 18:28
 */

function show_hide_header_title(element_id,element_type,title_id)
{
	var pars = 'element_id='+element_id+'&element_type='+element_type;

	new Ajax.Request('/toggle_title_action.php',{method:'post',parameters:pars,
	onSuccess:function(transport)
	{
		if (transport.responseText == 1)
		{
			if ((Element.getStyle(title_id,'display') == 'none') || (Element.hasClassName(title_id,'hidden')))
			{
				Element.setStyle(title_id,'background-color: '+high_light_color);
				
				new Effect.Appear(title_id,{
				afterFinish:function()
				{
					Element.show(title_id);
					Element.removeClassName(title_id,'hidden');
					
					Element.setStyle(title_id,'background-color: transparent');
				}
				});
			}
			else
			{
				Element.setStyle(title_id,'background-color: '+high_light_color);
				
				new Effect.Fade(title_id,{
				afterFinish:function()
				{
					Element.hide(title_id);
					Element.setStyle(title_id,'background-color: transparent');
				}
				});
			}
		}
		else if (transport.responseText == 0 || transport.responseText == null)
		{
			alert('error');
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * hide_notification function is used to hide a notification
 *
 * @param notification_id : html notification id
 * @param notification_type : notification type (event, message or request)
 *
 * @author : Antoine Morcos
 * @date : 12/02/2007 18:28
 */

function hide_notification(notification_id,notification_type)
{
	var pars_notification_id = notification_id.replace('notification-', '');
	var pars = 'notification_id='+pars_notification_id+'&notification_type='+notification_type;
	new Ajax.Request('/hide_notification_action.php',{method:'post',parameters:pars,
	onSuccess:function(transport)
	{
		if (transport.responseText == 1)
		{
			new Effect.DropOut(notification_id,{
			afterFinish:function()
			{
				Element.remove(notification_id);
			}
			});
		}
		else if (transport.responseText == 0 || transport.responseText == null)
		{
			alert('error');
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * confirm_request function is used to ignore or accept a friend or a group request
 *
 * @param request_id : html request id
 * @param request_type : type of the request (request or notification)
 * @param request_answer : accept or ignore
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 12/02/2007 18:28
 */
 
function confirm_request(request_id,request_type,request_answer,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		var pars_request_id = request_id.replace('request-', '');
		pars_request_id = pars_request_id.replace('message-', '');
		var pars = 'request_id='+pars_request_id+'&request_answer='+request_answer+'&request_type='+request_type;
		new Ajax.Request('/confirm_request_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			new Effect.DropOut(request_id,{
			afterFinish:function()
			{
				Element.remove(request_id);
						
				if (request_type == 'request' && request_answer == 'accept')
				{
					alert(transport.responseText);
				}
			}
			});
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * sign_out function is used to sign out from the account
 *
 * @author : Antoine Morcos
 * @date : 23/03/2008 18:28
 */

function sign_out()
{
	new Ajax.Request('/sign_out_action.php',{method:'post',
	onSuccess:function()
	{
          window.location.replace('/index.html');
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * delete_category function is used to delete a category of a section
 *
 * @param category_id : tab element id
 * @param element_type : tab element id
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 27/02/2007 18:28
 */
 
function delete_category(category_id,element_type,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		if (element_type == 'group')
		{
			var pars_category_id = category_id.replace('group_tab_', '');
		}
		else if (element_type == 'gallery')
		{
			var pars_category_id = category_id.replace('gallery_tab_', '');
		}
		else if (element_type == 'blog')
		{
			var pars_category_id = category_id.replace('blog_tab_', '');
		}
		
		var pars = 'category_id='+pars_category_id+'&element_type='+element_type;
		
		var url = '/delete_category_action.php'
		
		new Ajax.Request(url,{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText == 1)
			{
				Element.remove(category_id);
				
				if (element_type == 'group')
				{
					rebuild_sortable('group-tab-sortable','horizontal','group');
				}
				else if (element_type == 'gallery')
				{
					rebuild_sortable('gallery-tab-sortable','horizontal','gallery');
				
					var children = $('gallery-tab-sortable').childElements();
					
					for (var i=0; i<children.size(); i++) 
					{
						if ($(children[i].id).down(0).id != 'gallery-tab-selected')
						{
							children_id = children[i].id;
							
							Droppables.add(children_id,{hoverclass:'tab-droppable',accept:['big-thumb'],
							onDrop:function(element,droppableElement)
							{
								edit_media_category(element,droppableElement);
							}
							});
						}
					}
				}
				else if (element_type == 'blog')
				{
                                  rebuild_sortable('blog-tab-sortable','horizontal','group');
				}
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
			
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * delete_gallery_media function is used to delete a media by dragging and dropping the media over the trashcan in the page for exemple
 *
 * @param media_id : html media element
 * @param element_id : element id (not html)
 * @param element_type : element type (article, article_blogging, etc.)
 *
 * @author : Antoine Morcos
 * @date : 12/03/2008 18:28
 */
  
function delete_gallery_media(media,element_id,element_type)
{
	var pars_media_id = (media.id).replace('media_', '');
	var pars = 'element_id='+element_id+'&element_type='+element_type+'&media_id='+pars_media_id;
	
	new Ajax.Request('/delete_gallery_media_action.php',{method:'post',parameters:pars,
	onSuccess:function(transport)
	{
		if (transport.responseText == 1)
		{
			hideddrivetip();
			
			Element.remove(media);
			
			if (gallery_filter)
			{
				active_gallery_filter(gallery_filter);
			}
		}
		else if (transport.responseText == 0 || transport.responseText == null)
		{
			alert('error');
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * delete_media function is used to delete a media
 *
 * @param media_id : media id (not html)
 *
 * @author : Antoine Morcos
 * @date : 29/02/2007 18:28
 */
  
function delete_media(media_id,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		var pars_media_id = media_id.replace('media-', '');
		var pars = 'media_id='+pars_media_id;
		new Ajax.Request('/delete_media_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText != null && transport.responseText != 0)
			{
				alert(transport.responseText);
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * delete_article function is used to delete an article of a group
 *
 * @param article_id : article id (not html)
 * @param article_type : article type (group or blog)
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 12/0"/2008 18:28
 */
  
function delete_article(article_id,article_type,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		var pars = 'article_id='+article_id+'&article_type='+article_type;
		new Ajax.Request('/delete_article_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText != null && transport.responseText != 0)
			{
				alert(transport.responseText);
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * delete_comment function is used to delete a comment
 *
 * @param comment_id : element id
 * @param comment_type : type of the element (article, image, group, member, etc.)
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 26/06/2008 00:00
 */

function delete_comment(comment_id,comment_type,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		if (comment_type == 'article')
		{
			var pars_comment_id = comment_id.replace('article-comment-', '');
		}
		else if (comment_type == 'media')
		{
			var pars_comment_id = comment_id.replace('media-comment-', '');
		}
		else if (comment_type == 'member')
		{
			var pars_comment_id = comment_id.replace('member-comment-', '');
		}
		else if (comment_type == 'article_blogging')
		{
			var pars_comment_id = comment_id.replace('article-blogging-comment-', '');
		}
		else if (comment_type == 'article_blogging')
		{
			var pars_comment_id = comment_id.replace('article-blogging-comment-', '');
		}
		else if (comment_type == 'news' || comment_type == 'video' || comment_type == 'preview' || comment_type == 'feature' || comment_type == 'tip' || comment_type == 'webnews')
		{
			var pars_comment_id = comment_id.replace('article-comment-', '');
		}
		
		var pars = 'comment_id='+pars_comment_id+'&comment_type='+comment_type;
		
		new Ajax.Request('/delete_comment_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText == 1)
			{
				new Effect.DropOut(comment_id,{
				afterFinish:function()
				{
					Element.remove(comment_id);
				}
				});
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * delete_post function is used to delete a post
 *
 * @param post_id : element id
 * @param post_type : type of the element (article, image, group, member, etc.)
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 25/02/2007 20:28
 */

function delete_post(post_id,post_type,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		if (post_type == 'group_wall')
		{
			var pars_post_id = post_id.replace('group-wall-post-', '');
		}
		else if (post_type == 'member_wall')
		{
			var pars_post_id = post_id.replace('member-wall-post-', '');
		}
		else if (post_type == 'member')
		{
			var pars_post_id = post_id.replace('member-post-', '');
		}
		
		pars = 'post_id='+pars_post_id+'&post_type='+post_type;
		
		new Ajax.Request('/delete_post_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText == 1)
			{
				new Effect.DropOut(post_id,{
				afterFinish:function()
				{
					Element.remove(post_id);
				}
				});
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * delete_message function is used to delete a message
 *
 * @param message_id : html message id
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 11/03/2007 20:28
 */

function delete_message(message_id,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		var pars_message_id = message_id.replace('message-', '');
		pars = 'message_id='+pars_message_id;
		
		new Ajax.Request('/delete_message_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText == 1)
			{
				if (document.getElementById(message_id))
				{
					new Effect.DropOut(message_id,{
					afterFinish:function()
					{
						Element.remove(message_id);
					}
					});
				}
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * delete_group_blogger function is used to delete a blogger
 *
 * @param group_id : html group id
 * @param member_id : html member id
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 12/02/2007 21:28
 */
  
function delete_group_blogger(group_id,member_id,question)
{
	var confirmation = confirm(question);

	if (confirmation)
	{
		var pars_group_id = group_id.replace('group-', '');
		var pars_member_id = member_id.replace('member-', '');
		var pars = 'group_id='+pars_group_id+'&member_id='+pars_member_id;
		new Ajax.Request('/delete_group_blogger_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText == 1)
			{
				new Effect.DropOut(member_id,{
				afterFinish:function()
				{
					Element.remove(member_id);
				}
				});
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * delete_friend function is used to delete a friend
 *
 * @param member_id : html friend id
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 04/03/2007 21:28
 */
  
function delete_friend(member_id,question)
{
	var confirmation = confirm(question);

	if (confirmation)
	{
		var pars_member_id = member_id.replace('member-', '');
		var pars = 'member_id='+pars_member_id;
		new Ajax.Request('/delete_friend_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText == 1)
			{
				new Effect.DropOut(member_id,{
				afterFinish:function()
				{
					Element.remove(member_id);
				}
				});
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * delete_following function is used to delete a following member
 *
 * @param member_id : html following member id
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 01/04/2008 21:28
 */
  
function delete_following(member_id,question)
{
	var confirmation = confirm(question);

	if (confirmation)
	{
		var pars_member_id = member_id.replace('member-', '');
		var pars = 'member_id='+pars_member_id;
		new Ajax.Request('/delete_following_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText == 1)
			{
				new Effect.DropOut(member_id,{
				afterFinish:function()
				{
					Element.remove(member_id);
				}
				});
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * unsubscribe_group function is used to unsubscribe from a group
 *
 * @param group_id : html group id
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 10/03/2007 21:28
 */

function unsubscribe_group(group_id,question)
{
	var confirmation = confirm(question);

	if (confirmation)
	{
		var pars_group_id = group_id.replace('group-', '');
		var pars = 'group_id='+pars_group_id+'&subscribe=false';
		new Ajax.Request('/subscribe_group_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText != 0 && transport.responseText != null)
			{
				new Effect.DropOut(group_id,{
				afterFinish:function()
				{
					Element.remove(group_id);
					alert(transport.responseText);
				}
				});
			}
			else
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * delete_member_website function is used to delete a created website of a member
 *
 * @param website_id : html website id
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 18/02/2007 01:28
 */
  
function delete_member_website(website_id,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		var pars_website_id = website_id.replace('website-', '');
		var pars = 'website_id='+pars_website_id;
		new Ajax.Request('/delete_member_website_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText == 1)
			{
				new Effect.DropOut(website_id,{
				afterFinish:function()
				{
					Element.remove(website_id);
				}
				});
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * delete_member_email function is used to delete an email of a member
 *
 * @param email_id : html email id
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 08/03/2007 01:28
 */
  
function delete_member_email(email_id,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		var pars_email_id = email_id.replace('email-', '');
		var pars = 'email_id='+pars_email_id;
		new Ajax.Request('/delete_member_email_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText == 1)
			{
				new Effect.DropOut(email_id,{
				afterFinish:function()
				{
					Element.remove(email_id);
				}
				});
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * delete_member_favorite_website function is used to delete a favorite website of a member
 *
 * @param website_id : html website id
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 20/02/2007 01:28
 */
  
function delete_member_favorite_website(website_id,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		var pars_website_id = website_id.replace('website-', '');
		var pars = 'website_id='+pars_website_id;
		new Ajax.Request('/delete_member_favorite_website_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText == 1)
			{
				new Effect.DropOut(website_id,{
				afterFinish:function()
				{
					Element.remove(website_id);
				}
				});
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * delete_action function is used to delete a feed action in the user profile
 *
 * @param action_id : html action id
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 12/02/2007 21:28
 */

function delete_action(action_id,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		var pars_action_id = action_id.replace('action-', '');
		var pars = 'action_id='+pars_action_id;
		var url = '/delete_action_action.php';
		new Ajax.Request(url,{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText == 1)
			{
				new Effect.DropOut(action_id,{
				afterFinish:function()
				{
					Element.remove(action_id);
				}
				});
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * edit_media_category function is used to change the category of a media by dragging and dropping the media over a tab in the page
 *
 * @param media : html media element
 * @param category : html category element
 *
 * @author : Antoine Morcos
 * @date : 12/02/2007 21:28
 */
  
function edit_media_category(media,category)
{
	var media_id = (media.id).replace('media_', '');
	var category_id = (category.id).replace('gallery_tab_', '');
	var pars = 'media_id='+media_id+'&category_id='+category_id;
	new Ajax.Request('/edit_gallery_media_category_action.php',{method:'post',parameters:pars,
	onSuccess:function(transport)
	{
		if (transport.responseText == 1)
		{
			hideddrivetip();
			
			Element.remove(media);
			
			active_gallery_filter(gallery_filter);			
		}
		else if (transport.responseText == 0 || transport.responseText == null)
		{
			alert('error');
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * create_category function is used to create a new category in a section
 *
 * @param element_id : element id (not html)
 * @param element_type : type of the element (group, blog, gallery, etc.)
 *
 * @author : Antoine Morcos
 * @date : 27/02/2007 21:28
 */

function create_category(element_id,element_type)
{                         
    var pars = 'element_type='+element_type+'&element_id='+element_id;

	new Ajax.Request('/create_category_action.php',{method:'post',parameters:pars,
	onSuccess:function(transport)
	{
		if (transport.responseText != null && transport.responseText != 0)
		{
			var response_object = transport.responseText.toQueryParams('&');

			if (element_type == 'group')
			{
				var tab_id = 'group_tab_'+response_object.id;
				var url = '/group'+element_id+'_1_'+response_object.id+'.html';
			}
			else if (element_type == 'blog')
			{
				var tab_id = 'blog_tab_'+response_object.id;
				var url = '/blog'+element_id+'_1_'+response_object.id+'.html';
			}
			else if (element_type == 'gallery')
			{
				var tab_id = 'gallery_tab_'+response_object.id;
				var url = '/gallery'+element_id+'_1_'+response_object.id+'.html';
			}

			element = Builder.node('li',{id:tab_id,className:'gray-background gray-border solid-border hand-cursor'},[Builder.node('a',{href:url},response_object.name),' ',Builder.node('span',{className:'tab-cross'},[Builder.node('a',{href:'javascript:delete_category(\''+tab_id+'\',\''+element_type+'\',\''+response_object.question+'?\');'},[Builder.node('img',{src:'images/icons/cross.gif'})])])]);
			
			if (element_type == 'group')
			{
				$('group-tab-sortable').appendChild(element);
			
				rebuild_sortable('group-tab-sortable','horizontal','group');
			}
			else if (element_type == 'blog')
			{
				$('blog-tab-sortable').appendChild(element);
			
				rebuild_sortable('blog-tab-sortable','horizontal','blog');
			}
			else if (element_type == 'gallery')
			{
				$('gallery-tab-sortable').appendChild(element);
			
				rebuild_sortable('gallery-tab-sortable','horizontal','gallery');
				
				var children = $('gallery-tab-sortable').childElements();
				
				for (var i=0; i<children.size(); i++) 
				{
					if($(children[i].id).down(0).id != 'gallery-tab-selected')
					{
						var children_id = children[i].id;
							
						Droppables.add(children_id,{hoverclass:'tab-droppable',accept:['big-thumb'],
						onDrop:function(element,droppableElement)
						{
							edit_media_category(element,droppableElement);
						}
						});
					}
				}
			}
			
		}
		else if (transport.responseText == 0 || transport.responseText == null)
		{
			alert('error');
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * rebuild_sortable function is used to destroy and create the sortable again with new or less elements
 *
 * @param sortable_id : html sortable id
 * @param overlap : horizontal or vertical
 * @param type : type (group, blog, gallery, etc.)
 *
 * @author : Antoine Morcos
 * @date : 27/02/2007 21:28
 */
 
function rebuild_sortable(sortable_id,overlap,type)
{
	Sortable.destroy(sortable_id);
	
	if (type == 'group')
	{
		var position_updater_url = 'edit_group_category_position_action.html';
	}
	else if (type == 'gallery')
	{
		var position_updater_url = 'edit_gallery_category_position_action.html';
	}
	else if (type == 'blog')
	{
		var position_updater_url = 'edit_blog_category_position_action.html';
	}
			
	Sortable.create(sortable_id,{overlap:overlap,dropOnEmpty:false,constraint:false,
	onUpdate:function(sortable)
	{
		var pars = Sortable.serialize(sortable);
		new Ajax.Request(position_updater_url,{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText == 1)
			{
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
	});
}
  
/**
 * vote function is used to vote for an element
 *
 * @param element_id : element id (not html)
 * @param vote_type : vote type (article, image, group, etc.)
 * @param votes_number : votes number field id
 * @param votes_box : votes box id
 * @param voters_box : voters box id
 *
 * @author : Antoine Morcos
 * @date : 29/02/2007 14:28
 */

function vote(element_id,vote_type,votes_number_field,votes_box,voters_box)
{
    var pars = 'element_id='+element_id+'&vote_type='+vote_type;

	new Ajax.Request('/vote_action.php',{method:'post',parameters:pars,
	onSuccess:function(transport)
	{
		if (transport.responseText != '')
		{
			new Effect.Fade(votes_box,{
			afterFinish:function()
			{
				new Effect.Appear(votes_box,{
				beforeStart:function()
				{
					if (Element.hasClassName(votes_box,'voted'))
					{
						Element.setStyle(votes_box,'background-color: #FED81C;');
						Element.setStyle(votes_box,'background-image: url("images/7.gif");');
						Element.setStyle(votes_box,'border-color: #ECC101;');
						Element.removeClassName(votes_box,'voted');
					}
					else if (!Element.hasClassName(votes_box,'voted'))
					{
						Element.setStyle(votes_box,'background-color: #CAEEA9;');
						Element.setStyle(votes_box,'background-image: url("images/14.gif");');
						Element.setStyle(votes_box,'border-color: #AAD77E;');
						Element.addClassName(votes_box,'voted');
					}
					
					Element.update(votes_number_field,transport.responseText);
				},
				afterFinish:function()
				{
					if (voters_box)
					{
						update_voters(element_id,vote_type,voters_box);
					}
				}
				});
			}
			})
		}
		else if (transport.responseText == '' || transport.responseText == null)
		{
			alert('error');
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * update_voters function is used to update a box with all the voters for a specific element
 *
 * @param element_id : element id (not html)
 * @param vote_type : vote type (article, image, group, etc.)
 * @param voters_box : voters box id
 *
 * @author : Antoine Morcos
 * @date : 29/02/2007 21:28
 */

function update_voters(element_id,vote_type,voters_box)
{
	var pars = 'element_id='+element_id;

	new Ajax.Request('/update_voters_action.php',{method:'post',parameters:pars+'&vote_type='+vote_type,
	onSuccess:function(transport)
	{
		Element.update(voters_box,transport.responseText);
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}
  
/**
 * select_field_content function used to focus and select automatically the content on a field when clicked
 *
 * @param field : field
 *
 * @author : Antoine Morcos
 * @date : 12/02/2007 21:28
 */

function select_field_content(field)
{
	field.focus();
  	field.select();
}
	
/**
 * edit_combo_box function is used to edit details in a combo box
 *
 * @param form : form
 * @param form_field : form field to be used for updating the text field
 * @param text_field : text field to be updated with the form field value
 *
 * @author : Antoine Morcos
 * @date : 29/02/2007 21:28
 */

function edit_combo_box(form,form_field,text_field)
{
	var pars = Form.serialize(form);

	new Ajax.Request('/edit_category_action.php',{method:'post',parameters:pars,
	onSuccess:function(transport)
	{
		if (transport.responseText == 1)
		{
			Element.update(text_field,form[form_field].options[form[form_field].options.selectedIndex].text);
		}
		else if (transport.responseText == 0 || transport.responseText == null)
		{
			alert('error');
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * edit_member_birthday function is used to edit the birthday of a member
 *
 * @param form : form
 * @param text_field : text field to be updated with the form field value
 *
 * @author : Antoine Morcos
 * @date : 12/02/2007 21:28
 */

function edit_member_birthday(form,text_field)
{
	var pars = Form.serialize(form);
	
	var birthday_day = Form.Element.getValue('birthday_day');
	var birthday_month = Form.Element.getValue('birthday_month');
	var birthday_year = Form.Element.getValue('birthday_year');
	
	new Ajax.Request('/edit_category_action.php',{method:'post',parameters:pars,
	onSuccess:function(transport)
	{
		if (transport.responseText == 1)
		{
			Element.update(text_field,birthday_day+'/'+birthday_month+'/'+birthday_year);
		}
		else if (transport.responseText == 0 || transport.responseText == null)
		{
			alert('error');
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * edit_check_box function is used to edit details in a check box
 *
 * @param form : form
 *
 * @author : Antoine Morcos
 * @date : 29/02/2007 21:28
 */

function edit_check_box(form)
{
	var pars = Form.serialize(form);

	new Ajax.Request('/edit_check_box_action.php',{method:'post',parameters:pars,
	onSuccess:function(transport)
	{
		if (transport.responseText == 1)
		{
		}
		else //if (transport.responseText == 0 || transport.responseText == null)
		{
			alert('error'+transport.responseText);
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * edit_tags function is used to edit tags of an element
 *
 * @param form : form
 * @param text_field : form field
 *
 * @author : Antoine Morcos
 * @date : 29/02/2007 14:28
 */

function edit_tags(form,text_field)
{
	form_field = 'tags';

	if (Form.Element.getValue(form[form_field]))
	{
		var value = Form.Element.getValue(form[form_field]);
		var reg = new RegExp("[,;]+", "g");
		var tab = value.split(reg);
		var html_result = new String;
		var pars_result = new String;

		for (var i = 0; i<tab.length; i++) 
		{
			if (html_result != null)
			{
				html_result = html_result + '<a href="javascript:void(0);">'+tab[i]+'</a>';
						
				if (i<(tab.length-1))
				{
					html_result = html_result +' ';
				}
			}
		}
	}
	else
	{
		html_result = null;
	}

	var pars = Form.serialize(form);

	new Ajax.Request('/edit_tags_action.php',{method:'post',parameters:pars,
	onSuccess:function(transport)
	{
		if (transport.responseText == 1)
		{
			Element.update(text_field,html_result);
		}
		else if (transport.responseText == 0 || transport.responseText == null)
		{
			alert('error');
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * edit_group_blogger_rank function is used to change the blogger rank (admin, ect.)
 *
 * @param group_id : html group id
 * @param member_id : html member id
 * @param rank : rank id
 *
 * @author : Antoine Morcos
 * @date : 12/02/2007 21:28
 */

function edit_group_blogger_rank(group_id,member_id,rank_id)
{
	var pars_group_id = group_id.replace('group-', '');
	var pars_member_id = member_id.replace('member-', '');
	var pars_rank_id = Form.Element.getValue(rank_id);
	var pars = 'group_id='+pars_group_id+'&member_id='+pars_member_id+'&rank_id='+pars_rank_id;
	new Ajax.Request('/edit_group_blogger_rank_action.php',{method:'post',parameters:pars,
	onSuccess:function(transport)
	{
		if (transport.responseText == 1)
		{
			new Effect.Highlight(member_id,{startcolor:'#FFFF99',duration: 1});
		}
		else if (transport.responseText == 0 || transport.responseText == null)
		{
			alert('error');
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * edit_member_email_private function is used to change the privacy of an email
 *
 * @param email_id : html email id
 * @param private : private (yes or no)
 *
 * @author : Antoine Morcos
 * @date : 15/03/2008 21:28
 */

function edit_member_email_private(email_id,private)
{
	var pars_email_id = email_id.replace('email-', '');
	
	var pars_private = Form.Element.getValue(private);

	var pars = 'email_id='+pars_email_id+'&private='+pars_private;
	
	new Ajax.Request('/edit_member_email_private_action.php',{method:'post',parameters:pars,
	onSuccess:function(transport)
	{
		if (transport.responseText == 1)
		{
			new Effect.Highlight(email_id,{startcolor:'#FFFF99',duration: 1});
		}
		else if (transport.responseText == 0 || transport.responseText == null)
		{
			alert('error');
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * edit_member_service_status function is used to change the status of a service
 *
 * @param service_id : service id
 * @param status : enable (1) or disable (0)
 *
 * @author : Antoine Morcos
 * @date : 10/05/2008 21:28
 */

function edit_member_service_status(service_id,status)
{
	var pars_status = Form.Element.getValue(status);

	var pars = 'service_id='+service_id+'&status='+pars_status;
	
	new Ajax.Request('edit_member_service_status_action.html',{method:'post',parameters:pars,
	onSuccess:function(transport)
	{
		if (transport.responseText == 1)
		{
			new Effect.Highlight(status.parentNode.parentNode,{startcolor:'#FFFF99',duration: 1});
		}
		else if (transport.responseText == 0 || transport.responseText == null)
		{
			alert('error');
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}
	
/**
 * subscribe_group function is used to subscribe to a group
 *
 * @param group_id : group id (not html)
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 29/02/2007 21:28
 */

function subscribe_group(group_id,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		var pars = 'group_id='+group_id+'&subscribe=true';
		new Ajax.Request('/subscribe_group_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText != null && transport.responseText != 0)
			{
				alert(transport.responseText);
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * become_group_blogger function is used to send a request to become a blogger on a group
 *
 * @param group_id : group id (not html)
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 29/02/2007 21:28
 */

function become_group_blogger(group_id,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		var pars = 'group_id='+group_id;
		new Ajax.Request('/become_group_blogger_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText != null && transport.responseText != 0)
			{
				alert(transport.responseText);
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * withdraw_group_blogger function is used by the blogger to withdraw from a group
 *
 * @param group_id : html group id
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 21/02/2007 21:28
 */

function withdraw_group_blogger(group_id,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		var pars_group_id = group_id.replace('group-', '');
		var pars = 'group_id='+pars_group_id;
		new Ajax.Request('/withdraw_group_blogger_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText == 1)
			{
				new Effect.DropOut(group_id,{
				afterFinish:function()
				{
					Element.remove(group_id);
				}
				});			
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * become_friend function is used to send a request to become a friend of a member
 *
 * @param member_id : member id (not html)
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 29/02/2007 21:28
 */

function become_friend(member_id,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		var pars = 'member_id='+member_id;
		new Ajax.Request('/become_friend_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText != null && transport.responseText != 0)
			{
				alert(transport.responseText);
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * follow_member function is used to follow a member
 *
 * @param member_id : member id (not html)
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 29/02/2007 21:28
 */

function follow_member(member_id,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		var pars = 'member_id='+member_id;
		new Ajax.Request('/follow_member_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText != null && transport.responseText != 0)
			{
				alert(transport.responseText);
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * add_group_blogger function is used to add a blogger on a group
 *
 * @param member_id : member id (not html)
 * @param group_id : group id (not html)
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 29/02/2007 21:28
 */

function add_group_blogger(member_id,group_id,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		var pars = 'group_id='+group_id+'&member_id='+member_id;
		new Ajax.Request('/add_group_blogger_action_bis.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText != null && transport.responseText != 0)
			{
				alert(transport.responseText);
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * make_private function is used to make private an element
 *
 * @param element_id : element id (not html)
 * @param element_type : type of the element (article, image, group, etc.)
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 29/02/2007 21:28
 */

function make_private(element_id,element_type,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		if (element_type == 'media')
		{
			var pars = 'media_id='+element_id;
			var url = '/make_private_media_action.php';
		}
		
		new Ajax.Request(url,{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText != null && transport.responseText != 0)
			{
				alert(transport.responseText);
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * save_media function is used to add a media in the user's media gallery
 *
 * @param media_id : media id (not html)
 *
 * @author : Antoine Morcos
 * @date : 12/02/2007 21:28
 */

function save_media(media_id)
{
	var pars = 'media_id='+media_id;
	var url = '/save_media_action.php';
		
	new Ajax.Request(url,{method:'post',parameters:pars,
	onSuccess:function(transport)
	{
		if (transport.responseText != null && transport.responseText != 0)
		{
			alert(transport.responseText);
		}
		else if (transport.responseText == 0 || transport.responseText == null)
		{
			alert('error');
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * send_translation function is used to send a translation
 *
 * @param form : form
 * @param translation_field : translation field id
 *
 * @author : Antoine Morcos
 * @date : 05/04/2008 14:28
 */

function send_translation(form,translation_field)
{
	if (Form.Element.present(form[translation_field]))
	{
		var pars = Form.serialize(form);
			  
		form.disable();

		new Ajax.Request('/add_translation_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			alert(transport.responseText);
			form.enable();
		},
		onFailure:function()
		{
			alert('error');
			
			form.enable();
		}
		});
	}
	  
	return false;
}

/**
 * add_comment function is used to add a comment on an element
 *
 * @param form : form
 * @param comment_field : comment field id
 * @param error_field : error field id
 * @param comment_list : comment list id
 * @param error_empty : the text when there is no comment
 *
 * @author : Antoine Morcos
 * @date : 09/03/2007 14:28
 */

function add_comment(form,comment_field,error_field,comment_list,error_empty)
{
	Element.update(error_field,'');
	  
	if (!Form.Element.present(form[comment_field]))
	{
	  	Element.addClassName(form[comment_field],'yellow-textarea');
		
		Element.addClassName(error_field,'red-font');
		Insertion.Bottom(error_field,error_empty);
	}
	else
	{
		Element.removeClassName(form[comment_field],'yellow-textarea');
	}

	if (Form.Element.present(form[comment_field]))
	{
		var pars = Form.serialize(form);
		             /*
		if (comment_type == 'article')
		{
			url = 'add_article_comment_action.html';
		}
		else if (comment_type == 'article-blogging')
		{
			url = 'add_article_blogging_comment_action.html';
		}
		else if (comment_type == 'media')
		{
			url = 'add_media_comment_action.html';
		}
		else if (comment_type == 'member')
		{
			url = 'add_member_comment_action.html';
		}
			  */
			  
		form.disable();

		new Ajax.Request('/add_comment_action.php',{method:'post',parameters:pars,evalJS:true,
		onSuccess:function(transport)
		{
			if (transport.responseText != '')
			{
				Insertion.Bottom(comment_list,transport.responseText);
				//form[comment_field].clear();
			}
			else if (transport.responseText == '' || transport.responseText == null)
			{
				alert('error');
			}
			
			form.enable();
		},
		onFailure:function()
		{
			alert('error');
			
			form.enable();
		}
		});
	}
	  
	return false;
}

/**
 * add_post function is used to add a post on an element
 *
 * @param form : form id
 * @param error_field : error field id
 * @param post_field : post field id
 * @param post_list : post list id
 * @param error_text : the text when there is no post
 *
 * @author : Antoine Morcos
 * @date : 29/02/2008 20:28
 */

function add_post(form,error_field,post_field,post_list,error_text)
{
	Element.update(error_field,'');
	  
	if (!Form.Element.present(form[post_field]))
	{
	  	Element.addClassName(form[post_field],'yellow-textarea');
		
		Element.addClassName(error_field,'red-font');
		
		Insertion.Bottom(error_field,error_text);
	}
	else
	{
		Element.removeClassName(form[post_field],'yellow-textarea');
	}
	  
	if (Form.Element.present(form[post_field]))
	{
		var pars = Form.serialize(form);
		
		form.disable();
		
		new Ajax.Request('/add_post_action.php',{method:'post',parameters:pars,evalJS:true,
		onSuccess:function(transport)
		{
			if (transport.responseText != '')
			{
				Insertion.Top(post_list,transport.responseText);
				//form[post_field].clear();
			}
			else if (transport.responseText == '' || transport.responseText == null)
			{
				alert('error');
			}
			
			form.enable();
		},
		onFailure:function()
		{
			alert('error');
			
			form.enable();
		}
		});
	}
	  
	return false;
}

/**
 * delete_member_location function is used to delete a location
 *
 * @param location_id : html location id
 * @param question : question for confirmation alert box
 *
 * @author : Antoine Morcos
 * @date : 22/03/2008 18:28
 */
  
function delete_member_location(location_id,question)
{
	var confirmation = confirm(question);
	
	if (confirmation)
	{
		var pars_location_id = location_id.replace('location-', '');
		var pars = 'location_id='+pars_location_id;
		
		new Ajax.Request('delete_member_location_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText == 1)
			{
				new Effect.DropOut(location_id,{
				afterFinish:function()
				{
					Element.remove(location_id);
				}
				});
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
		},
		onFailure:function()
		{
			alert('error');
		}
		});
	}
}

/**
 * edit_member_location function is used to change the location of the member
 *
 * @param location_id : location id (the form is sent)
 * @param text_field : text field to be updated with the form field value
 *
 * @author : Antoine Morcos
 * @date : 19/03/2008 21:28
 */

function edit_member_location(location_id,text_field)
{
	var pars_location_id = Form.Element.getValue(location_id);
	var pars = 'location_id='+pars_location_id;
	new Ajax.Request('edit_member_location_action.php',{method:'post',parameters:pars,
	onSuccess:function(transport)
	{
		if (transport.responseText == 1)
		{
			Element.update(text_field,location_id.options[location_id.options.selectedIndex].text);
		}
		else if (transport.responseText == 0 || transport.responseText == null)
		{
			alert('error');
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * add_account_post function is used to add a new post from the account
 *
 * @param form : form
 * @param form_field : form field to be used for updating the text field
 * @param text_field : text field to be updated with the form field value
 */

function add_account_post(form,form_field,text_field)
{
	var pars = Form.serialize(form);
	
	var value = Form.Element.getValue(form_field);
	
	if (Form.Element.present(form_field))
	{
		form.disable();
		
		new Ajax.Request('/add_account_post_action.php',{method:'post',parameters:pars,
		onSuccess:function(transport)
		{
			if (transport.responseText == 1)
			{
				Element.update(text_field,value);
				$(form_field).clear();
			}
			else if (transport.responseText == 0 || transport.responseText == null)
			{
				alert('error');
			}
			
			form.enable();
		},
		onFailure:function()
		{
			alert('error');
			
			form.enable();
		}
		});
	}
}

/**
 * edit_in_place function is used to make an inplaceeditable field
 *
 * @param field_id : html field id
 * @param row_number : row number for the editable field
 * @param over_color : high light color
 * @param out_color : high light end color
 * @param element_id : element id
 * @param ok_button : if a submit button is shown in edit mode (true,false)
 * @param ok_button_text : the text of the submit button that submits the changed value to the server
 * @param cancel_button : if a cancel link is shown in edit mode (true,false)
 * @param cancel_button_text : the text of the link that cancels editing
 * @param over_edit_text : the text shown during mouseover the editable text
 * @param saving_text : the text shown while the text is sent to the server
 * @param form_style_id : id of the element to edit plus InPlaceForm
 * @param loading_text : If the loadText URL option is specified then this text is displayed while the text is being loaded from the server
 * @param submit_on_blur : this option if true will submit the in_place_edit form when the input tag loses focus.
 *
 * @author : Antoine Morcos
 * @date : 27/02/2007 21:28
 */

function edit_in_place(field_id,row_number,over_color,out_color,element_id,submit_on_blur,ok_button,ok_button_text,cancel_button,cancel_button_text,form_style_id,over_edit_text,saving_text,loading_text)
{
	
	if (field_id == null)
	{
		alert('error');
	}
	
	if (row_number == null)
	{
		row_number = 1;
	}
	
	if (over_color == null)
	{
		over_color = high_light_color;
	}
	
	if (out_color == null)
	{
		out_color = high_light_end_color;
	}
	
	if (element_id == null)
	{
	}
	
	if (ok_button == null)
	{
		ok_button = false;
	}
	
	if (ok_button_text == null)
	{
		ok_button_text = 'ok';
	}
	
	if (cancel_button == null)
	{
		cancel_button = false;
	}
	
	if (cancel_button_text == null)
	{
		cancel_button_text = 'cancel';
	}
	
	if (over_edit_text == null)
	{
		over_edit_text = 'click to edit';
	}

	if (saving_text == null)
	{
		saving_text = 'saving...';
	}
	
	if (form_style_id == null)
	{
		form_style_id = 'textarea-edit';
	}

	if (loading_text == null)
	{
		loading_text = 'loading...';
	}
	
	if (submit_on_blur == null)
	{
		submit_on_blur = true;
	}

	new Ajax.InPlaceEditor(field_id,'/edit_in_place_action.php',{formId:form_style_id,rows:row_number,okButton:ok_button,okText:ok_button_text,cancelButton:cancel_button,cancelText:cancel_button_text,highlightcolor:over_color,highlightendcolor:out_color,submitOnBlur:submit_on_blur,savingText:saving_text,loadingText:loading_text,clickToEditText:over_edit_text,fieldPostCreation:'focus',handleLineBreaks:true,
	/**
	 * Callback function send the value entered by the user to the php action page for treatment
	 *
	 * @param form
	 * @param value
	 */
	callback:function(form,value)
	{
          var intIndexOfMatch = value.indexOf( "&" );
          
          while (intIndexOfMatch != -1)
          {
            value = value.replace('&', '[[[@]]]');
            intIndexOfMatch = value.indexOf( "&" );
          }
          
          var intIndexOfMatch = value.indexOf( "?" );
          
          while (intIndexOfMatch != -1)
          {
            value = value.replace("?", "[[[*]]]");
            intIndexOfMatch = value.indexOf( "?" );
          }
          
          pars = 'value='+value+'&element_id='+element_id+'&field_id='+field_id;
          return pars;

	},
	onComplete:function(transport,element)
	{
	},
	onFormCustomization:function(ipe,ipeForm)
	{
		value = ipe._controls.editor.value;
		//value = value.replace("&amp;", "&");

                var intIndexOfMatch = value.indexOf( "<BR>" );
                          
                while (intIndexOfMatch != -1)
                {
                  value = value.replace("<BR>", "\n");
                  intIndexOfMatch = value.indexOf( "<BR>" );
                }
                
		//value = value.replace(/<br>/gi, "").replace(/<br\/>/gi, "").replace(/<\/p>/gi, "");
                //value = value.replace("<br>", "\n").replace("<br/>", "\n");
                value = value.unescapeHTML();
		ipe._controls.editor.value = value.stripScripts().stripTags();
	}
	});
}

/**
 * add_file_field function is used to add a new file field in a form
 *
 * @param field_list : file field list (html id)
 * @param field_text : file field text
 *
 * @author : Antoine Morcos
 * @date : 27/02/2007 21:28
 */

function add_file_field(field_list,field_text)
{
	if (field_number < 20)
	{
		Insertion.Bottom(field_list,'<div class="form-textarea"><div class="form-textarea-text">'+field_text+' '+(field_number+1)+' :</div><div class="form-textarea-field"><input type="file" id="file_'+field_number+'" name="file_'+field_number+'" class="file"/></div></div>');
		
		field_number = (field_number + 1);
	}
}

/**
 * frame_update function is used to update a frame with a content
 *
 * @param tab : html tab selected by the user
 * @param list_id : html list id with all the tabs
 * @param frame_id : html frame id to be updated
 * @param content : the frame will be updated with this content
 * @param scroll_id : html element id to scroll to
 * @param unselected_tab_color : unselected tab color
 * @param selected_tab_color : selected tab color
 *
 * @author : Antoine Morcos
 * @date : 27/02/2007 21:28
 */

function frame_update(tab,list_id,frame_id,content,scroll_id,unselected_tab_color,selected_tab_color)
{
	if(!unselected_tab_color)
	{
		unselected_tab_color = '#F4F4F4';
	}
	
	if(!selected_tab_color)
	{
		selected_tab_color = '#FFFFFF';
	}
	
	$(list_id).childElements().each(function(element){Element.setStyle(element,'background-color: '+unselected_tab_color);});
	Element.setStyle(tab,'background-color: '+selected_tab_color);
	
	Element.update(frame_id,'<div class="loading"><img src="images/1.gif" /></div>');
	
	if (content == 'opinion_latest')
	{
		var url = '/update_opinion_action.php?type=latest';
	}
	else if (content == 'opinion_team')
	{
		var url = '/update_opinion_action.php?type=team';
	}
	else if (content == 'opinion_presse')
	{
		var url = '/update_opinion_action.php?type=presse';
	}
	else if (content == 'blog_all')
	{
		var url = '/update_blog_action.php?type=all';
	}
	else if (content == 'blog_member')
	{
		var url = '/update_blog_action.php?type=blog';
	}
	else if (content == 'blog_group')
	{
		var url = '/update_blog_action.php?type=group';
	}
	else if (content == 'tip_popular')
	{
		var url = '/update_tip_action.php?type=popular';
	}
	else if (content == 'tip_latest')
	{
		var url = '/update_tip_action.php?type=latest';
	}
	else if (content == 'news')
	{
		var url = '/update_news_action.php?type=all';
	}
	else if (content == 'board_moviedvd')
	{
		var url = '/update_boards_action.php?type=moviedvd';
	}
	else if (content == 'board_tvshow')
	{
		var url = '/update_boards_action.php?type=tvshow';
	}
	else if (content == 'news_all')
	{
		var url = '/update_news_index_action.php?type=all';
	}
	else if (content == 'news_videos')
	{
		var url = '/update_news_index_action.php?type=videos';
	}
	else if (content == 'news_reviews')
	{
		var url = '/update_news_index_action.php?type=reviews';
	}
	else if (content == 'news_features')
	{
		var url = '/update_news_index_action.php?type=features';
	}
	else if (content == 'news_photos')
	{
		var url = '/update_news_index_action.php?type=photos';
	}
	else if (content == 'news_dvd')
	{
		var url = '/update_news_index_action.php?type=dvd';
	}
	else if (content == 'news_pilote')
	{
		var url = '/update_news_index_action.php?type=pilote';
	}
	
	new Ajax.Request(url,{method:'post',
	onSuccess:function(transport)
	{
		Element.update(frame_id,transport.responseText);
		
		if (scroll_id)
		{
			new Effect.ScrollTo(scroll_id,{offset: -24});
		}
	},
	onFailure:function()
	{
		alert('error');
	}
	});
}

/**
 * updater function is used to add an updater tu the page
 *
 * @param list_id : html list id to be updated
 * @param time : secondes between updates
 * @param postion : top, bottom...
 * @param pars : parameters
 *
 * @author : Antoine Morcos
 * @date : 27/02/2007 21:28
 */

function updater(list_id,time,postion,pars)
{
	var timer = time+'000';

	if (list_id.include('comment-list'))
	{
		var url = '/update_comments_action.php';
	}
	
	if (postion == 'top' || postion == 'Top')
	{
		var insertion_position = 'Insertion.Top';
	}
	if (postion == 'bottom' || postion == 'Bottom')
	{
		var insertion_position = 'Insertion.Bottom';
	}
	
	setTimeout("new Ajax.PeriodicalUpdater('"+list_id+"','"+url+"',{method:'post',parameters:'"+pars+"',evalScripts:true,insertion:"+insertion_position+",frequency:"+time+",decay:1});",timer);
}

