﻿
function showHideShareTool (id1, id2) {

	if (document.getElementById) {
		if (document.getElementById(id1).className == 'hide') {
			document.getElementById(id1).className = 'show';
			document.getElementById(id2).className = 'sharebox';
		} else {
	     	document.getElementById(id1).className = 'hide';
    		document.getElementById(id2).className = 'share';
		}
	}
	return false;
}

function blogPostShare(site, keywords, pubdate,pg, theID) {

	var title;
	var description;
	var popUpUrl;
	var byline;
	var formCtl;
	var formID;
	var section;

	title = '';
	description = '';
	popUpUrl = '';
	byline = '';
	section = '';
    if(pubdate=='')
    {
      var currentTime = new Date();
      var month = currentTime.getMonth() + 1;
      var day = currentTime.getDate();
      var year = currentTime.getFullYear();
      pubdate= month + "/" + day + "/" + year;
      
    }
	formID = 'emailThis_' + theID;

	/*if(document.getElementById) {
		formCtl = document.getElementById(formID);
		if(formCtl) {
			description = formCtl.description.value;
			title = formCtl.title.value;
			popUpUrl = formCtl.url.value;
			byline = 'By ' + formCtl.author.value;
			section = formCtl.section.value;
		}
	}*/

popUpUrl = document.location.href;
title= document.title;
if(pg=='cat')
{
	description=document.getElementById('lbl_DescriptionShort').innerHTML;
}
else if(pg=='mcat')
{
	description=document.getElementById('lblDesc').innerHTML;
}


	switch (site) {
	case "newsvine":
		postPopUp('http://www.newsvine.com/_wine/save?ver=2&popoff=0&aff=nytimes&t=' + keywords + '&e=' + description + '&h=' + title + '&u=' + popUpUrl, 'newsvine', 'toolbar=0,status=0,height=445,width=650,scrollbars=yes,resizable=yes');
		s_code_linktrack('Article-Tool-Share-Newsvine');
		break;
	case "facebook":
		postPopUp('http://www.facebook.com/sharer.php?u=' + popUpUrl + '&t=' + title, 'facebook', 'toolbar=0,status=0,height=436,width=646,scrollbars=yes,resizable=yes');
		s_code_linktrack('Article-Tool-Share-Facebook');
		break;
    case "twitter":
		postPopUp('http://twitter.com/home?status=' + title + ' ' + popUpUrl , 'twitter', 'toolbar=0,status=0,height=436,width=646,scrollbars=yes,resizable=yes');
		s_code_linktrack('Article-Tool-Share-Twitter');
		break;
	case "digg":
		postPopUp('http://digg.com/remote-submit?phase=2&url=' + popUpUrl + '&title=' + title + '&bodytext=' + description, 'digg', 'toolbar=0,status=0,height=450,width=650,scrollbars=yes,resizable=yes');
		s_code_linktrack('Article-Tool-Share-Digg');
		break;
	case "permalink":
/*		postPopUp('http://www.nytimes.com/export_html/common/new_article_post.html?url=' + popUpUrl + '&title=' + title+ '&summary=' + description + '&section=' + section + '&pubdate=' + pubdate + '&byline=' + byline, 'permalink', 'toolbar=0,status=0,height=410,width=490,scrollbars=yes,resizable=no');
		s_code_linktrack('Article-Tool-Share-Permalink');*/
		break;
	case "delicious":
		postPopUp('http://del.icio.us/post?v=4&partner=nyt&noui&jump=close&url=' + popUpUrl + '&title=' + title + '&bodytext=' + description, 'delicious', 'toolbar=0,status=0,height=400,width=700,scrollbars=yes,resizable=no');
		s_code_linktrack('Article-Tool-Share-Delicious');
		break;
	case "myspace":
		postPopUp('http://www.myspace.com/index.cfm?fuseaction=postto&u=' + popUpUrl + '&t=' + title + '&c=' + description, 'myspace', 'toolbar=0,status=0,height=400,width=700,scrollbars=yes,resizable=no');
		s_code_linktrack('Article-Tool-Share-Delicious');
		break;

	case "yahoobuzz":
		// fall-back behavior.  At least it'll just open the page in a new window/tab, but not downsized.
    		postPopUp( 'http://buzz.yahoo.com/article/new_york_times/'
			    + encodeURIComponent(popUpUrl),
			    'yahoobuzz',
                'scrollbars=yes,resizable=yes'
		);
		s_code_linktrack('Article-Tool-Share-YahooBuzz');
		break;

	case "mixx":
		try {
		    var otherParams =
			     '&title='       + title
			   + '&description=' + description
			   + '&tags='        + keywords
			   + '&partner='     + 'NYT';
		    postPopUp(
			   'http://mini.mixx.com/submit/story'
			   + '?page_url='    + popUpUrl
			   + otherParams,
			   'mixx',
			   'toolbar=0,status=0,height=550,width=700,scrollbars=yes,resizable=no'
		    );
		} catch(e) {
		    postPopUp(
			   'http://mini.mixx.com/submit/story'
			   + '?page_url='    + popUpUrl
			   + '&title='       + title
			   + '&partner='     + 'NYT'
			   ,
			   'mixx',
			   'toolbar=0,status=0,height=550,width=700,scrollbars=yes,resizable=no'
		    );
		}
		s_code_linktrack('Article-Tool-Share-Mixx');
		break;

	case "linkedin":
		  //http://www.linkedin.com/shareArticle?mini=true&url={articleUrl}&title={articleTitle}&summary={articleSummary}&source={articleSource}
		  postPopUp(
		     'http://www.linkedin.com/shareArticle?mini=true'
			   + '&url='         + popUpUrl
			   + '&title='       + title
			   + '&summary='     + description
			   + '&source='      + 'The New York Times'
			   ,
			   'Linkedin',
			   'toolbar=0,status=0,height=550,width=700,scrollbars=yes,resizable=no'
		  );
		s_code_linktrack('Article-Tool-Share-LinkedIn');
		break;
	}
}

function postPopUp(url, name, params) {
	var win = window.open(url, name, params);
	if(win) {
		win.focus();
	}
}

/* sharetool functions end */

function blogPostPrint(keywords, pubdate, theID, printPostURL, blogImageURL) {

	var title;
	var description;
	var popUpUrl;
	var byline;
	var formCtl;
	var formID;
	var section;
	var full_text;

	title = '';
	description = '';
	popUpUrl = '';
	byline = '';
	section = '';
	full_text = '';

	formID = 'emailThis_' + theID;

	if(document.getElementById) {
		formCtl = document.getElementById(formID);
		if(formCtl) {
			description = formCtl.description.value;
			title = formCtl.title.value;
			popUpUrl = formCtl.url.value;
			byline = 'By ' + formCtl.author.value;
			section = formCtl.section.value;
			full_text = formCtl.full_text.value;
		}
	}

	postPopUp(printPostURL + '?ID=' + theID + '&full_text=parent_form_text', 'printthis', 'menubar=1,toolbar=0,status=0,height=445,width=650,scrollbars=yes,resizable=yes');

}

function createYahooBuzzOnLoad() {

	// An event listener is attached once the badge is loaded so that
	// function itself is separated from the dom ref via a closure to prevent IE 6 memory leakage.
	window.yahooBuzzOnLoad = function () {
		var onclick = function () {
			// this is the onclick handler that gets attached to the badge.
			s_code_linktrack('Article-Tool-Share-YahooBuzz');
		};
		return function () {
		    if(typeof(window['yahooBuzzOnLoad'])!='function') {
			    window.yahooBuzzOnLoad=null; // clean up the global.
		    }
			var badge = document.getElementById('yahooBuzzBadge-form');
			if ( badge ) {
				if ( badge.addEventListener ) {
					badge.addEventListener('click', onclick, true);
				} else if ( badge.attachEvent ) {
					badge.attachEvent('click', onclick);
				} else {
					// can't put an onclick directly, or it'll break the badge.
					// This is an edge case, so losing non-mousers is not very significant.
					badge.onmousedown = onclick;
				}
			}
		}
	}();

};

function sortTagArchive(val) {
	javascript:window.location.href='?orderby=' + val;
}
