/***********************************************************
   AOL IM Javascript Tool v1.9.2005-2006
   Juan F. Sarria (JuanFerManNY@aol.com)
   Publishing Tech Dev Web Svc
   Documentation: http://www.aolexd.com/AIMThis/AIMThis.htm
************************************************************/

    function ShareThis() {
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        //        DEFAULT VALUES
        //
        this.setDefault = function () {
            //    Could be modified by the user
            this.message = "A Friend Wants You to See This";    // Default Message
            this.subject = "Hey, check this out from AOL";      // 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 AIM confirmation
            this.thisPageName = "";

            //    Used internally
            this.msgBody     = "";
            this.linkTo      = "";
            this.pageTo      = ""
            this.thisPageUrl = document.URL.split("?")[0];
        }
		
		
		this.checkOS = function () {
			
			var OSName="Unknown OS";
			if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
			if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
			if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
			if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
			
			this.thisOpSys = OSName;

		}

		this.checkOS();

		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, "+");
				sTxt = isIE?sTxt.replace(/&/g, "%2526"):sTxt.replace(/&/g, "%26");
				sTxt = sTxt.replace(/;/g, "%3B");
				sTxt = sTxt.replace(/#/g, "%23");
            }
            return sTxt;
        }

        this.decodeEntities    = function (sTxt) {
            if ( typeof(sTxt) != "undefined" ) { 
                sTxt = sTxt.replace(/&apos;/g, "\'");
                sTxt = sTxt.replace(/&quot;/g, "\"");
                sTxt = sTxt.replace(/&amp;/g, "&");
                sTxt = sTxt.replace(/&lt;/g, "\<");
                sTxt = sTxt.replace(/&gt;/g, "\>");
				sTxt = sTxt.replace(/&hash;/g, "\#");
            }
            return sTxt;
        }

        //        Replace defaults with custom values
        this.setValues = function (sMailId, sMessage, sSubject, sLinkUrl, sLinkTxt, bConfirm, sThisPageName ) {
            this.setDefault();

            sLinkTxt = this.decodeEntities(sLinkTxt);
            sSubject = this.decodeEntities(sSubject);

            if ( typeof(sMailId) != "undefined" && sMailId != "" ) this.mailId = sMailId;
			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 ( typeof(sThisPageName) != "undefined" && sThisPageName != "" ) this.thisPageName = sThisPageName;
            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, sThisPageName, deepLinkURL) {

			this.setValues('', sMessage, '', sLinkUrl, sLinkTxt, bConfirm, sThisPageName );

            //    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, "+");
                this.thisPageName = this.thisPageName.replace(/ /g, "+").replace(/\&/g, "%2526");
            }

            //    Build the complete link
            if ( this.thisOpSys == "MacOS" ) {
				this.linkTo = this.thisPageUrl+deepLinkURL;
                this.pageTo = this.thisPageUrl;
            } else {
				this.linkTo = this.encode('<a href="') + this.thisPageUrl+deepLinkURL + this.encode('">') + this.linkTxt + this.encode("</a>");
                this.pageTo = this.encode('<a href="') + this.thisPageUrl + this.encode('">') + this.thisPageName + this.encode("</a>");
            }
            
            //    Build the body of the message, which is; message plus link

			this.msgBody = this.message.replace(/\-LINK\-/g, this.linkTo);
            this.msgBody = this.msgBody.replace(/\-THISPAGE\-/g, this.pageTo);

			this.msgBody = this.decodeEntities(this.msgBody)
			this.msgBody = this.encode(this.msgBody);


            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/_media/channels/jfs_msgr_aimthisconfwin.html?msg=" + this.msgBody, "confirmWindow", 350, 100);
                } else {
                    this.OpenPopUp('aim:GoIm?message=' + this.msgBody, "IM", 1,1).close();
                }
            }
        }

        //        Launch Email
        this.byEMAIL = function (sMailId, sMessage, sSubject, sLinkUrl, sThisPageName, deepLinkURL ) {
            this.setValues(sMailId, sMessage, sSubject, sLinkUrl, sThisPageName );
			this.linkUrl = escape(this.thisPageUrl+deepLinkURL);
			this.msgBody = this.message + this.linkUrl;
            document.location = "mailto:"+this.mailId+"?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, sThisPageName, deepLinkURL) {
	this.byAIM( sMessage, sLinkUrl, sLinkTxt, bConfirm, sThisPageName , deepLinkURL);
}

FlashMsgr.sendEmail = function(sMailId, sMessage, sSubject, sLinkUrl, sThisPageName, deepLinkURL) {
	this.byEMAIL(sMailId, sMessage, sSubject, sLinkUrl, sThisPageName, deepLinkURL );
}
