function popupWindow(url, name, attributes){
	var newWindow = window.open(url, name.replace(/[a-z]/ig, ''), attributes);
	newWindow.focus();
}

function trimSlash(url) {
    return url.replace(/\//, '');
}

/* ### Start Twitter related publishing ### */

function publishToTwitter(title, pageAddress) {
    var pageUrl = basehref + trimSlash(pageAddress);
    var message = title + ' ' + pageUrl;
    var twitterUrl = 'http://twitter.com/home?status=' + encodeURI(message);
    popupWindow(twitterUrl, 'Twitter','width=900, height=500, scrollbars');
    if (pageTracker) { pageTracker._trackPageview(pageAddress + '/TwitterPost'); }
}

/* ### End Twitter related publishing ### */

/* ### Start Facebook related publishing ### */
function callPublish(msg, attachment, action_link) {
	FB.ui({
		method: 'stream.publish',
		message: msg,
		attachment: attachment
     }
	);
	if (pageTracker) { pageTracker._trackPageview('/FacebookPost'); }
}

function publishToFacebook(title, description, pageAddress) {
	var imageUri = basehref+'/uploads/facebook.jpg';
	callPublish(
		'',
		{
			'name': title,
			'href': basehref + trimSlash(pageAddress),
			'description': description,
			'media':[{
				'type': 'image',
				'src': imageUri,
				'href': basehref
			}]
		}/*,
		[{
			'text':'Global Volunteering',
			'href':'http://www.facebook.com/pages/Lattitude-Global-Volunteering/355106402993'
		}]*/
	);
	return false;
}


/* ### End Facebook related publishing ### */

/* ### End Email related sharing ### */

function shareEmail(senderName, senderEmail, recipientName, recipientEmail, message, address) {
	//alert(senderName +":"+ senderEmail +":"+ recipientName +":"+ recipientEmail +":"+ message +":"+ address);
	
    var formData = {
        'senderName': senderName,
        'senderEmailAddress': senderEmail,
        'recipientName': recipientName,
        'recipientEmailAddress': recipientEmail,
        'message': message,
        'address': trimSlash(address)
    };
    $.get('index.php?do=restShare', formData);
}
/* ### End Email related sharing ### */


function displayWrapper() {
    var wrapper = document.getElementById('wrapper');
    if(wrapper != undefined) wrapper.style.display = 'block';
}

$(document).ready(function() { 
	window.fbAsyncInit = function() {
		FB.init(
			{
				appId  : fbAppKey,
				status : true, // check login status
				cookie : true, // enable cookies to allow the server to access the session
				xfbml  : false // parse XFBML - false stops issue where entire site would reload in a hidden iFrame
			});
	};
	(function() {
		var e = document.createElement('script');
		e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
		e.async = true;
		document.getElementById('fb-root').appendChild(e);
	}());
})
