//Title of current page/Article
function getShareHeadline() {
	return encodeURIComponent(document.title);
}

//Description about current page/Article
function getShareDescription() { 

	return encodeURIComponent('Online survey software for employee satisfaction surveys, employee evaluation surveys, sample surveys. Web surveys for non profits, event registration and online survey best practices');
}

function getShareSection() {
	return encodeURIComponent('Zarca Static Web Information');
}

function getShareSubSection() {
	return encodeURIComponent('tech');
}

function getShareKeywords() {
	return encodeURIComponent('Product and Solutions');
}

//URL of Current Page/Article
function getShareURL() {
	return encodeURIComponent(document.location.href);
}

function getSharePasskey() { return '99439f762eb07323be79c2215d9c64e2';}



function articleShare(site) {
	var popUpUrl;
    var title = getShareHeadline();
    var description = getShareDescription();
	switch (site) {
	
	//case "facebook":
	//	popUpUrl = generatePasskeyURL('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');
	
	//	break;
	case "digg":
		var topic = getShareSection();	
		postPopUp('http://digg.com/submit?url=' + getShareURL() + '&title=' + title + '&bodytext=' + description, 'digg', 'toolbar=0,status=0,height=450,width=650,scrollbars=yes,resizable=yes');
		
		break;	
	//case "digg":
	//	popUpUrl = generatePasskeyURL('digg');
	//	var topic = getShareSection();	
	//	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');
	
	//	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/'
			    + encodeURIComponent(getShareURL()),
			    'yahoobuzz',
                         'scrollbars=yes,resizable=yes'
		);
	
		break;			

	case "mixx":
		try {
		    var popUpUrl = getShareURL();
		    var passKey  = encodeURIComponent( '?' + getSharePasskey() );
		    var otherParams = 
			     '&title='       + getShareHeadline()
			   + '&description=' + getShareDescription()
			   + '&tags='        + getShareKeywords()
			   + '&partner='     + 'Zarca.com';
		    postPopUp( 
			   'http://mini.mixx.com/submit/story'
			   + '?page_url='    + getShareURL()
			   + passKey 
			   + 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='    + getShareURL()
			   + '&title='       + getShareHeadline()
			   + '&partner='     + 'Zarca.com'
			   ,
			   'mixx',
			   'toolbar=0,status=0,height=550,width=700,scrollbars=yes,resizable=no'
		    );
		}
		
		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='         + getShareURL()
		   + '&title='       + getShareHeadline()
		   + '&summary='     + description
		   + '&source='      + 'Zarca.com'
		   ,
		   'Linkedin',
		   'toolbar=0,status=0,height=550,width=700,scrollbars=yes,resizable=no'
	  )
	 
		break;
	}
}


function postPopUp(url, name, params) {
	var win = window.open(url, name, params);
}

function addPostItem(parentElement, style, post_link, text) {
	if( document.createElement ){
		if( typeof(window.shareToolsExcludeList)!='undefined'
		    && typeof(window.shareToolsExcludeList[style])!='undefined' ) {
		    return;
		}
		var postItem = document.createElement("LI");
		postItem.className = style;
		
		var itemLink = document.createElement("A");
		itemLink.setAttribute("href", post_link);
		itemLink.innerHTML = text;

		postItem.appendChild(itemLink);
		parentElement.appendChild(postItem);
	}
}


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.
			
		};
		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 instrumentYahooBuzzBadge() {
	
	if ( document.getElementById('yahooBuzzBadge') ) {
		// already instrumented. Abort.
		return;
	}
	
	var list = document.getElementById('postList');
	if ( !list ) {
		// haven't created the list yet. Abort.
		return;
	}
	
	createYahooBuzzOnLoad();
	
	var postLinks = list.getElementsByTagName('a');
	for ( var i = 0, l = postLinks.length; i < l; i ++ ) {
		var href = postLinks[i].href;
		href = href.toLowerCase();
		if ( href.indexOf('buzz') !== -1 && href.indexOf('yahoo') !== -1 ) {
			// works whether it's the real URL or the javascript: with yahoobuzz in the call.
			var badge = postLinks[i];
			badge.id = 'yahooBuzzBadge';
		}
	}
	
	// Y! Buzz requires its own script be included dynamically like this ...
	//path need to be change according to condition.
	var artUriYahoo = decodeURIComponent(getShareURL());
	document.write(
	        '<script badgetype="text" src="../js/badge.js">zarca:'
		 + artUriYahoo
		 + '</script>'
	);
}

function addPosts(shareList) {	

		if(document.getElementById) {	
			var sList;
				
			if(typeof(shareList)=='string') {
				sList = document.getElementById(shareList); 
				}
			
			else if(typeof(shareList)=='object') { 
				sList = shareList;
			}
			
			else {
				return false;
			}

                     // Note: delicious and newsvine deleted intentionally, per Marko.
			addPostItem(sList, "linkedin", "javascript:articleShare('linkedin');", "Linkedin");
			addPostItem(sList, "digg", "javascript:articleShare('digg');", "Digg");
			addPostItem(sList, "facebook", "javascript:articleShare('facebook');", "Facebook");
			addPostItem(sList, "mixx", "javascript:articleShare('mixx');", "Mixx");
			addPostItem(sList, "yahoobuzz", "javascript:articleShare('yahoobuzz');", "Yahoo! Buzz");
			//addPostItem(sList, "permalink", "javascript:articleShare('permalink');", "Permalink");
		}
}




function generatePasskeyURL(tracker) {

	if(document.getElementById) {

		var passkey = getSharePasskey();

	

		// make sure passkey exists

		if(passkey != '') {

			if (decodeURIComponent(getShareURL()).indexOf('?') > 0) {

				return getShareURL() + encodeURIComponent('&' + passkey + '&partner=' + tracker + '&exprod=' + tracker);

			} else {

				return getShareURL() + encodeURIComponent('?' + passkey + '&partner=' + tracker + '&exprod=' + tracker);

			}

		} else {

			if (decodeURIComponent(getShareURL()).indexOf('?') > 0) {

				return getShareURL() + encodeURIComponent('&partner=' + tracker + '&exprod=' + tracker);

			} else {

				return getShareURL() + encodeURIComponent('?partner=' + tracker + '&exprod=' + tracker);

			}

		}

	}

}



function dcsMultiTrack(){
	if (arguments.length%2==0){
		for (var i=0;i<arguments.length;i+=2){
			if (arguments[i].indexOf('WT.')==0){
				WT[arguments[i].substring(3)]=arguments[i+1];
			}
			else if (arguments[i].indexOf('DCS.')==0){
				DCS[arguments[i].substring(4)]=arguments[i+1];
			}
			else if (arguments[i].indexOf('DCSext.')==0){
				DCSext[arguments[i].substring(7)]=arguments[i+1];
			}
		}
		var dCurrent=new Date();
		DCS.dcsdat=dCurrent.getTime();
		dcsFunc("dcsCookie");
		dcsTag();
	}
}

function dcsFunc(func){
	if (typeof(window[func])=="function"){
		window[func]();
	}
}


function dcsTag(){
	if (document.cookie.indexOf("WTLOPTOUT=")!=-1){
		return;
	}
	var P="http"+(window.location.protocol.indexOf('https:')==0?'s':'')+"://"+dcsInit.domain+(dcsInit.dcsid==""?'':'/'+dcsInit.dcsid)+"/dcs.gif?";
	for (var N in DCS){
		if ((typeof DCS[N]!="function")&&DCS[N]){
			P+=dcsA(N,DCS[N]);
		}
	}
	var keys=["co_f","vt_sid","vt_f_tlv"];
	for (var i=0;i<keys.length;i++){
		var key=keys[i];
		if (WT[key]){
			P+=dcsA("WT."+key,WT[key]);
			delete WT[key];
		}
	}
	for (N in WT){
		if ((typeof WT[N]!="function")&&WT[N]){
			P+=dcsA("WT."+N,WT[N]);
		}
	}
	for (N in DCSext){
		if ((typeof DCSext[N]!="function")&&DCSext[N]){
			P+=dcsA(N,DCSext[N]);
		}
	}
	if (P.length>2048&&navigator.userAgent.indexOf('MSIE')>=0){
		P=P.substring(0,2040)+"&WT.tu=1";
	}
	dcsCreateImage(P);
	WT.ad="";
}


function dcsA(N,V){
	if (dcsInit.i18n&&(dcsInit.exre!="")&&!dcsInit.exre.test(N)){
		if (N=="dcsqry"){
			var newV="";
			var params=V.substring(1).split("&");
			for (var i=0;i<params.length;i++){
				var pair=params[i];
				var pos=pair.indexOf("=");
				if (pos!=-1){
					var key=pair.substring(0,pos);
					var val=pair.substring(pos+1);
					if (i!=0){
						newV+="&";
					}
					newV+=key+"="+dcsEncode(val);
				}
			}
			V=V.substring(0,1)+newV;
		}
		else{
			V=dcsEncode(V);
		}
	}
	return "&"+N+"="+dcsEscape(V, dcsInit.re);
}

function dcsCreateImage(dcsSrc){
	if (document.images){
		dcsInit.images[dcsInit.index]=new Image;
		dcsInit.images[dcsInit.index].src=dcsSrc;
		dcsInit.index++;
	}
	else{
		document.write('<IMG ALT="" BORDER="0" NAME="DCSIMG" WIDTH="1" HEIGHT="1" SRC="'+dcsSrc+'">');
	}
}

function dcsEncode(S){
	return (typeof(encodeURIComponent)=="function")?encodeURIComponent(S):escape(S);
}


function dcsEscape(S, REL){
	if (REL!=""){
		var retStr = new String(S);
		for (var R in REL){
			if (typeof(REL[R])!="function"){
				retStr = retStr.replace(REL[R],R);
			}
		}
		return retStr;
	}
	else{
		return escape(S);
	}
}






