﻿var windowHeight = 500;

function shareFacebook(url, text, thumbnail, title) {
	
	var domain = document.location.hostname;
	
	urlParam = url;
	urlShare = 'http://www.facebook.com/sharer.php?u='+urlParam;
	windowWidth = 500;
	openWindow();
}

function shareOrkut(URL, text, thumbnail, title) {
	urlShare = 'http://promote.orkut.com/preview?nt=orkut.com&du='+URL+'&tt='+title+'&cn='+text+'&tn='+thumbnail;
	windowWidth = 700;
	openWindow();
}

function shareTwitter(URL, text, hashtag) {
	
	text = text+' ';
	urlShare = 'http://twitter.com/intent/tweet?url='+URL+'&text='+text;
	windowWidth = 500;
	if(hashtag!=null){
		hashtag = '#'+hashtag;
		hashtag = encodeURIComponent(hashtag);
		openWindowTwitter(hashtag);
	} else {
		openWindowTwitter();
	} 
}

function openWindow(hashtag) {
		
    var finalUrl = encodeURI(urlShare) + (hashtag ? hashtag : '');
	
	var posX  = (window.screen.width/2) - (windowWidth/2);		
	var posY  =  (window.screen.height/2)- (windowHeight/2);
		
	window.open(finalUrl,'','left='+posX+',top='+posY+',width='+windowWidth+',height='+windowHeight+',toolbar=no,resizable=0,scrollbars=yes');
}

function openWindowTwitter(hashtag) {
	
	urlShare = urlShare.replace("%hash_tag%", "hash_tag");
	
    var finalUrl = encodeURI(urlShare);
    var tag = (hashtag ? hashtag : '');
	if(tag != '') {
		finalUrl = finalUrl.replace("hash_tag", tag);
	} else {
		finalUrl = finalUrl.replace("hash_tag", "");
	}
	var posX  = (window.screen.width/2) - (windowWidth/2);		
	var posY  =  (window.screen.height/2)- (windowHeight/2);
		
	window.open(finalUrl,'','left='+posX+',top='+posY+',width='+windowWidth+',height='+windowHeight+',toolbar=no,resizable=0,scrollbars=yes');
}

