/*
 * @revision: April 15, 2010
**/

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(/'/g, "\'");
            sTxt = sTxt.replace(/"/g, "\"");
            sTxt = sTxt.replace(/&/g, "&");
            sTxt = sTxt.replace(/</g, "\<");
            sTxt = sTxt.replace(/>/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 (typeof(oKExp) != "undefined" && typeof(oKExp.kit) != "undefined" && typeof(oKExp.kit.pageURL) != "undefined") this.thisPageUrl = oKExp.kit.pageURL;

        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 ) {
    try { console.log("FlashMsgr.sendIM");    } catch (e) { }
    this.byAIM(sMessage, sLinkUrl, sLinkTxt, bConfirm, sThisPageName , deepLinkURL);
}

FlashMsgr.sendEmail = function( sMailId, sMessage, sSubject, sLinkUrl, sThisPageName, deepLinkURL) {
    try { console.log("FlashMsgr.sendEmail");    } catch (e) { }
    this.byEMAIL(sMailId, sMessage, sSubject, sLinkUrl, sThisPageName, deepLinkURL);
}

//---------------------------------------------------------------------------------------------------
//  KE FUNCTIONS
function ke_sentEmail( sMailId, sMessage, sSubject, sLinkUrl, sThisPageName, deepLinkURL ) {
    FlashMsgr.sendEmail(sMailId, sMessage, sSubject, sLinkUrl, "", deepLinkURL);
}

function ke_sendIM( sMessage, sLinkUrl, sLinkTxt, bConfirm, sThisPageName, deepLinkURL ) {
    FlashMsgr.sendIM(sMessage, sLinkUrl, sLinkTxt, true, "", deepLinkURL);
}
//---------------------------------------------------------------------------------------------------

if(typeof(oKE) == "undefined") var oKE = new Object();

//if (typeof(addthis_pub) == "undefined") var addthis_pub = "rishi112002";

oKE.shareThis = function(galleryId, image, title, body, linkLabel, channelLogo, mqid, mqpid, addThisType) {

    //try { console.log("rev: 1  \ngalleryId = '"+galleryId.replace(/\'/g,"")+"';\nimage = '"+image+"';\ntitle = '"+title.replace(/\'/g,"")+"';\nbody = '"+body.replace(/\'/g,"")+"';\nlinkLabel = '"+linkLabel.replace(/\'/g,"")+"';\nchannelLogo = '"+channelLogo.replace(/\'/g,"")+"';");    } catch (e) { }

    var isPopUp = (typeof(oKE) != "undefined" && typeof(oKE.kit) != "undefined" && typeof(oKE.kit.pageURL) != "undefined");
    var garr = galleryId.split("-");
    var channel = garr[0];
    var pageTitle = (title != "") ? title : "Click here";
    var href = (isPopUp) ? oKE.kit.pageURL : location.href;
    var pageURL = href.split("?")[0] + escape("?dlid=" + mqid + "&dlpid=" + mqpid);
    var pageDescription = body;

    try { console.log("addThisType = "+addThisType+"\npageTitle = "+pageTitle+";\npageURL = "+unescape(pageURL)); } catch (e) { }
    /*
    addthis_open(document.getElementById('shareButton'), '', unescape(pageURL), pageTitle);
    addthis_sendto(addThisType);
    addthis_close();
    */

    if (isPopUp) {
        addthis.update("share", "title", pageTitle);
        addthis.update("share", "url", unescape(pageURL));
        addthis.update("share", "description", body);
    }
    addthis_sendto(addThisType);

    try { console.log("addthis_sendto('"+addThisType+"') called"); } catch (e) { }
}

function omniHPClk(){
    var global_list = ['aolsvc','aolukjunglobal','aolfrglobal','aoldegermanytotal','aolcaglobal','aolind','aoljp','aolanz','aolmx','aolitl','aolgchina','aolesp','aolse','aolnl','aolpl','aolclo','aoldk','aolnzl','aolno','aolbr','aolarg','aolbe','aolsg','aolfi','aolch','aolchile','aoltk','aolru','aolirl','aolat','aolvzl','aolmy','aolkr','aolth','aolcz','aolph','aolxpromo','aolleadaolsvc','devaolsvc'],
    acct_array = s_account.split(','),
    numGlobalAccts=global_list.length,
    numAccts=acct_array.length,
    global_match,
    oLoop,
    iLoop;
    
    if (acct_array){
        Loop1:
        for(oLoop=0; oLoop<numAccts; oLoop++) {
            Loop2:
            for(iLoop=0; iLoop<numGlobalAccts; iLoop++) {
                if (acct_array[oLoop]==global_list[iLoop]){
                    //temp fix for aolxpromo, remove when xpromo is updated
                    if (global_list[iLoop]='aolxpromo'){
                        iLoop=0;
                    }

                    global_match=iLoop+1;
                    break Loop1;
                }
            }
        }

        if(global_match){
            var s=s_gi(global_list[global_match-1],0,1);
            s_265.linkTrackVars='None';
            s_265.linkTrackEvents='None';
            s_265.tl(true,'o','KE - HP Print - ' + s_265.channel + '|' + s_265.prop1 + '|' + s_265.prop2);
            s.sa(s_account);
        }
    }
}

//---------------------------------------------------------------------------------------------------
//  FACEBOOK CONNECT FUNCTIONS - rishisharma08
//---------------------------------------------------------------------------------------------------
var jsfFB = new ShareThis();
jsfFB.resultBody = "You know what you want out of a relationship and you're not afraid to keep moving until you get it. Wit and charm are your biggest turn-ons, and you like guys who appreciate you for your mind as much as your body. You have fun playing the dating game, but secretly you just can't wait to find the guy who sweeps you off your feet and carries you into the sunset.";
jsfFB.quizTitle = "Which Sex and the City character are you?";
jsfFB.resultTitle = '"You are Carrie"';
jsfFB.href = "http://www.aol.com";
jsfFB.mediaType = "image";
jsfFB.mediaSrc = "http://www.keyexperiences.com/_test/fb_connect/Carrie.jpg";
jsfFB.mediaHref = "http://www.keyexperiences.com/_test/fb_connect/Carrie.jpg";
jsfFB.imageArray = new Array();
jsfFB.publishToFB = function(targetAds,_quizTitle,_resultsTitle,_body,_imageArray,_id,_pid)
{
    this.resultBody = _body;
    this.quizTitle = _quizTitle;
    this.resultTitle = _resultsTitle;
    this.imageArray=[];
    var isPopUp = (typeof(oKE) != "undefined" && typeof(oKE.kit) != "undefined" && typeof(oKE.kit.pageURL) != "undefined");
    var dochref = (isPopUp) ? oKE.kit.pageURL : location.href;
    this.href = dochref.split("?")[0] + escape("?dlid=" + _id + "&dlpid=" + _pid);
    for(var i=0;i<_imageArray.length;i++)
    {
        this.imageArray.push({'type':'image','src':_imageArray[i],'href':_imageArray[i]});
    }
    this.fbOnFlashTimer();
}
jsfFB.fbOnFlashTimer = function()
{
    var me=this;
    FB.init("0cbd26b486ae36e7465a53f09b854795", "", {"ifUserConnected":me.fbOnInitLoggedIn});
    setTimeout(function(){jsfFB.doSomething();},2000);
}
jsfFB.doSomething = function()
{
    var me=this;
    FB.Connect.get_status().waitUntilReady( function( status ) { switch ( status ) { case FB.ConnectState.connected: loggedIn = true; jsfFB.doThis();break; case FB.ConnectState.appNotAuthorized: FB.Connect.requireSession(); case FB.ConnectState.userNotLoggedIn: FB.Connect.requireSession(); loggedIn = false; }}); 
}
jsfFB.doThis = function()
{
    var attachment = {name:this.quizTitle,href:unescape(this.href),caption:"{*actor*} took the quiz and got the result "+this.resultTitle,description:this.resultBody,'media':this.imageArray};
    var actionLinks = [];//[{ "text": "Watch Video", "href": "http://www.myvideosite/videopage.html"}];
    FB.Connect.streamPublish('',attachment,actionLinks,null,"Write something...",function(){},false);
}
jsfFB.fbOnInitLoggedIn = function(){jsfFB.doThis();}

function publishToFB(targetAds,_quizTitle,_resultsTitle,_body,_imageArray,id,pid)    //called by Flash
{
    jsfFB.publishToFB(targetAds,_quizTitle,_resultsTitle,_body,_imageArray,id,pid);
}
function loadFacebook()
{
    if(!document.getElementById('facebookScript')){var d=document,s=d.createElement('script');s.type="text/javascript";s.id="facebookScript";s.src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php";d.getElementsByTagName('head')[0].appendChild(s);}
}