
/***
 * 			THIS SCRIPT IS INCLUDED ON EVERY PAGE FROM FRONT-END
 **/


// ========= 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();
	}	

// ================================================	


// ===== 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();
	
});

// =========================================




//===== HOME PAGE ROUNDED BORDERS SCRIPT ============

window.addEvent('load', function(){ 

	var homeBorderTop    = RUZEE.ShadedBorder.create({ corner:10, edges:"tlr", border:1 });
	var homeBorderBottom = RUZEE.ShadedBorder.create({ corner:10, edges:"blr", border:1 });	
	var homeRounded = RUZEE.ShadedBorder.create({ corner:10, border:1 });

	$$('.home-box:not(.normal)').each(function(item, index) {

		var box_heading = item.getElement('h3');
		var box_content = item.getElement('div.content');
		var box_content2 = item.getElement('div.content2');

		// we have to render the bottom first because we need to exist JUST ONE DIV
		// for getElementsByTagName and rendering top will insert loads of them ...		
		if (box_content) homeBorderBottom.render(box_content);		
		if (box_heading) homeBorderTop.render(box_heading);
		if (box_content2) homeRounded.render(box_content2); 
		
	}); // END foreach

}); // END function

//====================================================



//===== VERIFY CONTACT ============
function VerifyContact()
{	
	if(document.contact.last_name.value=="")
	{
		alert("Va rugam sa introduceti numele dumneavoastra");
		document.contact.last_name.focus();
		return false;
	}	
	
	if(document.contact.first_name.value=="")
	{
		alert("Va rugam sa introduceti prenumele dumneavoastra");
		document.contact.first_name.focus();
		return false;
	}	
	
	if(document.contact.email.value=="")
	{
		alert("Va rugam sa introduceti e-mail-ul dumneavoastra");
		document.contact.email.focus();
		return false;
	}	
	
	var emailRegxp =/^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{1,}){1,}$/;
	if(emailRegxp.test(document.contact.email.value)!=true)
	{
		alert("Va rugam sa introduceti o adresa de e-mail valida");
		document.contact.email.focus();
		return false;
	}

    if ( document.contact.tip.selectedIndex == '' )
    {
        alert ( "Va rugam sa selectati tipul de contact" );
        return false;
    }
	
	if(document.contact.mesaj.value=="")
	{
		alert("Va rugam sa introduceti mesajul dumneavoastra");
		document.contact.mesaj.focus();
		return false;
	}	
	
	return true;
}
//====================================================





//==============================================================================
//								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











/*************************************************
 *  				ONLOAD
 *************************************************/

// on inner pages, content column must have same height with right-column  
window.addEvent('load', function(){
	
	if (!$('right-column'))
		return;
	
	var  h = $('right-column').getStyle('height').toInt();
	
	$('content').setStyle('min-height', h-15);
	
});

