/***********************************************************
*****     Mr. Juan Ferman's AOL Message Tools v1.1 Latino Version     *****
************************************************************/
	function ShareThis() {
		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
		//		DEFAULT VALUES
		//
		this.setDefault = function () {
			//	Could be modified by the user
			this.message = "Un amigo quiere que veas esto";	// Default Message
			this.subject = "Mira lo que tiene AOL Latino";		// Default Subject.
			this.linkUrl = document.URL;						// Default URL is the current page.
			this.linkTxt = "";									// Default Empty makes the link text the same link Url
			this.confirm = true;								// Opens a pop-up window for non-AOL browsers asking for IAM confirmation

			//	Used internally
			this.msgBody = "";
			this.linkTo	 = "";
		}
		this.setDefault();

		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
		//		CONSTANTS
		//
		var uAgt	=	navigator.userAgent.toLowerCase();
		var isIE	=	uAgt.indexOf("msie")	!= -1;
		var isAOL	=	uAgt.indexOf(" aol ")	!= -1;
		var isSAFARI=	uAgt.indexOf("safari")	!= -1;

		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
		//		FEATURE FUNCTIONS
		//
		//		For non-AOL browsers the message has to be encode
		this.encode	= function (sTxt) {
			if ( !isAOL ) {
				sTxt = sTxt.replace(/\</g, "%3C");
				sTxt = sTxt.replace(/\>/g, "%3E");
				sTxt = sTxt.replace(/\//g, "%2F");
				sTxt = sTxt.replace(/\"/g, "%22");
				sTxt = sTxt.replace(/ /g, "+");
			}
			return sTxt;
		}

		//		Replace defaults with custom values
		this.setValues = function (sMessage, sSubject, sLinkUrl, sLinkTxt, bConfirm) {
			this.setDefault();
			if ( typeof(sMessage) != "undefined" && sMessage != "" ) this.message = sMessage;
			if ( typeof(sLinkTxt) != "undefined" && sLinkTxt != "" ) this.linkTxt = sLinkTxt;
			if ( typeof(sLinkUrl) != "undefined" && sLinkUrl != "" ) this.linkUrl = sLinkUrl;
			if ( typeof(sSubject) != "undefined" && sSubject != "" ) this.subject = sSubject;
			if ( typeof(bConfirm) == "undefined" || bConfirm == "" ) this.confirm = true;
			if ( this.linkTxt == "" ) this.linkTxt = this.linkUrl;	//	If the text for the link is empty then use the link url as text
		}

		//		Launch IM
		this.byAIM = function ( sMessage, sLinkUrl, sLinkTxt, bConfirm ) {
			this.setValues( sMessage, '', sLinkUrl, sLinkTxt, bConfirm );

			//	If the token LINK is not included in the message then add it at the end of it.
			if ( this.message.indexOf("-LINK-") == -1 ) this.message += " -LINK-";

			//	For non-AOL browsers the Link Url has to be escaped and the message encoded
			if (!isAOL ) {
				this.linkUrl = escape(this.linkUrl.replace(/\&/g, "%26"));
				this.linkTxt = this.linkTxt.replace(/ /g, "+").replace(/\&/g, "%2526");
				this.message = this.message.replace(/ /g, "+");
			}

			//	Build the complete link
			if ( isSAFARI ) {
				this.linkTo = this.linkUrl;
			} else {
				this.linkTo = this.encode('<a href="') + this.linkUrl + this.encode('">') + this.linkTxt + this.encode("</a>");
			}
			
			//	Build the body of the message, which is; message plus link
			this.msgBody = this.message.replace(/\-LINK\-/g, this.linkTo);

			if ( isAOL ) {
				// Launch IM from AOL browser
				document.location = 'aol://9293::' + this.msgBody;
			} else {
				// Launch IM from non-AOL browser
				if ( bConfirm && !isAOL )	{
					myWin = this.OpenPopUp("http://cdn.digitalcity.com/Shared/aimthisconfwindow?msg=" + this.msgBody, "confirmWindow", 350, 100);
				} else {
					this.OpenPopUp('aim:GoIm?message=' + this.msgBody, "IM", 1,1).close();
				}
			}

		}

		//		Launch Email
		this.byEMAIL = function ( sMessage, sSubject, sLinkUrl ) {
			this.setValues( sMessage, sSubject, sLinkUrl );
			this.msgBody = this.message + ": " + escape(this.linkUrl);
			document.location = "mailto:?subject=" + this.subject + "&body=" + this.msgBody;

		}

		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
		//		POP-UP FUNCTIONS
		//
		this.OpenPopUp = function (url, name, w, h) {
			//	Opens a centered window
			LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
			TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
			settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,resizable=no,menubar=no,toolbar=no,status=no,location=no';
			//	Assign the new window to an object and then return it
			var popWin = window.open(url,name,settings);
			popWin.focus();
			return popWin;
		}
	}


//************************************************************/

//---------------------------------------------------------------------------------------------------
//  MESSANGER ACTION FUNCTIONS
//---------------------------------------------------------------------------------------------------
//
var FlashMsgr = new ShareThis();

FlashMsgr.sendIM = function( sMessage, sLinkUrl, sLinkTxt, bConfirm ) {
	this.byAIM( sMessage, sLinkUrl, sLinkTxt, bConfirm );
}

FlashMsgr.sendEmail = function( sMessage, sSubject, sLinkUrl ) {
	this.byEMAIL(sMessage, sSubject, sLinkUrl);
}
