
/***
 * 			THIS SCRIPT IS INCLUDED ON EVERY PAGE OF THE WEBSITE
 **/


// ========= DHTML Window functions ================

	var win;
	
	function open_win(src, width, height)
	{
		win = dhtmlwindow.open("win-container", "iframe", src, 'title', "width=" + width + "px,height=" + height + "px,resize=1,scrolling=1,center=1")
	}
	
	function close_win()
	{
		parent.win.close();
	}

	// when viewing image, scrollbars should not be visible and height+width don't matter as window is resized
	
	function view_image(src)
	{
		win = dhtmlwindow.open("win-container", "iframe", src, 'title', "width=100px,height=100px,resize=1,scrolling=0,center=1")		
	}
	
	function close_image()
	{
		parent.win.close();
	}		
	
// ================================================	
	
	
	
// ========= TINYMCE INIT FUNCTION ================	
	
	
function init_simple_tinymce()
{	
	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		plugins : "safari,style",
		theme_advanced_buttons1 : "bold,italic,underline,forecolor,backcolor,separator,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,link,unlink,|,code",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "bottom",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "",
		extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
		force_p_newlines : false,
		force_br_newlines : true,
	   	forced_root_block : '',
	   	height: "15px"		
	});	
	
} // END function
	
	
	
	
function init_full_tinymce()
{
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect,forecolor,backcolor,|,fullscreen,preview",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,removeformat,cleanup,help,code,|,sub,sup,charmap,emotions,media,advhr,nonbreaking,insertdate",
		theme_advanced_buttons3 : "tablecontrols,|,hr,visualaid,|,ltr,rtl,|,insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,template",
		theme_advanced_buttons4 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
		force_p_newlines : false,
		force_br_newlines : true,
		
		// Example content CSS (should be your site CSS)
		content_css : "",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js"
		
	});
}

function init_rich_tinymce()
{
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect,forecolor,backcolor",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,removeformat,cleanup,help,code",
		theme_advanced_buttons3 : "sub,sup,charmap,emotions,media,advhr,nonbreaking,insertdate,|,fullscreen,preview",
		theme_advanced_buttons4 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
		force_p_newlines : false,
		force_br_newlines : true,
		
		// Example content CSS (should be your site CSS)
		content_css : "",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js"
	});
}


// TinyMCE initialization on Admin - NEWS Editor
function init_news_tinymce()
{
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		editor_selector : "mceEditor",
		editor_deselector : "mceNoEditor",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "forecolor,backcolor,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,removeformat,cleanup,help,code",
		theme_advanced_buttons3 : "cut,copy,paste,pastetext,pasteword,|,sub,sup,charmap,emotions,media,advhr,nonbreaking,insertdate,|,fullscreen,preview",
		theme_advanced_buttons4 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
		force_p_newlines : false,
		force_br_newlines : true		
	});	
	
} // END function




// =============================================




// ===== ROUNDED BORDERS SCRIPT ============

// perform the rendering when the document has been loaded completely
window.addEvent('domready', function(){  

	// add the border definitions
	RUZEE.Borders.add({ ".rounded" : { borderType:"simple", cornerRadius:5 } });	
	
	RUZEE.Borders.render();
	
});

// =========================================








// ==============================================================================
//								FACEBOOK FUNCTIONS
// ==============================================================================


// publish something to your Facebook account wall
function facebook_publish(msg, attachment, action_link) 
{	        
	FB.ensureInit( function () { 
		FB.Connect.streamPublish('', attachment, action_link); 
	});
	
} // END function



// this function is launched when a mentor/mentee wants to connect his Facebook account with his MO account
// i.e. sends an Ajax request to record facebook_user_id into the database
function facebook_connect()
{
			
  FB.ensureInit(function() {
      FB.Facebook.get_sessionState().waitUntilReady(function(session) {

			if (!session) return;

			var user_id = FB.Connect.get_loggedInUser();

			var req = new Request({ url: 'account_action.php', onSuccess: function(){ window.location.reload(true);} });
			req.send('caller=facebook_connect&facebook_user_id='+user_id);
    	  
        });            
    });
    
} // END function



// display facebook login button that will trigger the pop-up with Facebook login form
function facebook_display_login(container_id)
{		
	var markup = '<fb:login-button v="2" size="medium" onlogin="window.location.reload(true);">Login with Facebook</fb:login-button>';  
	var div = document.getElementById(container_id);		
	
	div.innerHTML = markup;
	
	FB.XFBML.Host.parseDomElement(div);
	
} // END function



// displays pictures with current user's friends on Facebook
function facebook_display_friends(container_id, max)
{
	FB.Facebook.get_sessionState().waitUntilReady(function() {
		
		var div = document.getElementById(container_id);
		
		FB.Facebook.apiClient.friends_get(null, function(result) {
		    var markup = '<div style="width:150px; border: 2px solid #3B5998;">';
		    var num_friends = result ? Math.min(max, result.length) : 0;
		    
		    if (num_friends > 0) 
		      for (var i=0; i<num_friends; i++) 
		        markup += '<fb:profile-pic size="square" uid="'+result[i]+'" facebook-logo="true" linked="false"></fb:profile-pic>';	     
		    
		    markup += '</div>';
		    
		    div.innerHTML = markup;
		    FB.XFBML.Host.parseDomElement(div);
	
		});
		
	});	
	
} // END function








