﻿var objMessengerActiveP4;
function DeleteComment(strUrlComment)
{
    var urlThis=strUrlComment;
    urlThis=urlThis.indexOf('#',0)<0?urlThis:urlThis.substr(0,urlThis.indexOf('#',0));
    urlThis=urlThis.indexOf('?',0)<0?urlThis:urlThis.substr(0,urlThis.indexOf('?',0));
    return urlThis;
}
function IMThis()
{
    //Why don't I insert judgement?they want to improve to install messenger.
    
    SetCookie('UrlThis',DeleteComment(location.href));
    SetCookie('TitleThis',document.title);
    
    CheckMessenger();
    if( objMessengerActiveP4 != null) objMessengerActiveP4.LaunchApp('99996305', '');
    
    //if( objMessengerActiveP4 != null) objMessengerActiveP4.LaunchApp('000000004C01A05E', '');
    //if( objMessengerActiveP4 != null) objMessengerActiveP4.LaunchApp('99995624', '');
    
}

function BlogThis()
{
    var countMaxUrl=2048;//2076;
    var urlThis=DeleteComment(location.href);
    var strOverLimited=encodeURI("...");
    var strUrlThis;
    if(urlThis.charAt(0)=="/")
    {
        urlThis="http://"+window.location.host+urlThis
    }
    var envThis=new GetEnvironment();
    if(envThis.ie)
    {
        var sel=document.selection.createRange();
        sel.expand("word");
        strUrlThis="http://spaces.msn.com/BlogIt.aspx?Title="+encodeURI(document.title)+"&SourceURL="+encodeURI(urlThis)+"&description="+encodeURI(sel.text);
        if(strUrlThis.length>countMaxUrl)
        {
            strUrlThis="http://spaces.msn.com/BlogIt.aspx?Title="+encodeURI(document.title)+"&SourceURL="+encodeURI(urlThis)+"&description=";
            strUrlThis=strUrlThis+GetCutSelection(sel.text,countMaxUrl-strUrlThis.length-strOverLimited.length)+strOverLimited;
        }
        window.open(strUrlThis);
    }
    else
    {
        strUrlThis="http://spaces.msn.com/BlogIt.aspx?Title="+encodeURI(document.title)+"&SourceURL="+encodeURI(urlThis);
        window.open(strUrlThis);
    }
}
function GetCutSelection(strSelectedText,countLimited)
{
    var indexStart=Math.floor(countLimited/9);
    var i=0;
    for(i=indexStart;i++;i<strSelectedText.length)
    {
        if(encodeURI(strSelectedText.substr(0,i)).length>countLimited)
            break;
    }
    return encodeURI(strSelectedText.substr(0,i-1));
}
function EncodeMail(strEncode)
{
    strEncode=strEncode.replace(/%/g,"%25");
    strEncode=strEncode.replace(/\?/g,"%3F");
    strEncode=strEncode.replace(/&/g,"%26");
    strEncode=strEncode.replace(/\n/g,"%0D%0A");
    return strEncode
}

function EmailThis()
{
    var countLimited=320;//324;
    var strOverLimited="...";
    var emailSubject=EncodeMail(location.hostname);
    var linkUrl=location.host;
    var urlThis=DeleteComment(location.href);
    var et;
    var envThis=new GetEnvironment();
    if(envThis.ie)
    {
        var sel=document.selection.createRange();
        sel.expand("word");
        et='mailto:?subject=来自%20'+emailSubject+'%20的文章:%20'+EncodeMail(document.title)+'&body='+'文章地址'+'%0D%0A'+EncodeMail(urlThis)+'%0D%0A%0D%0A'+EncodeMail(sel.text);
        if(et.length>countLimited)
        {
            et='mailto:?subject=来自%20'+emailSubject+'%20的文章:%20'+EncodeMail(document.title)+'&body='+'文章地址'+'%0D%0A'+EncodeMail(urlThis)+'%0D%0A%0D%0A';
            et=et+EncodeMail(sel.text.substr(0,countLimited-et.length-strOverLimited.length))+strOverLimited;
        }
        location.href=et;
    }
    else
    {
        if(envThis.nt>=6)//Vista
        {
            et='mailto:?subject=来自%20'+emailSubject+'%20的文章:%20'+EncodeMail(document.title)+'&body='+'文章地址'+'%0D%0A'+EncodeMail(urlThis)+'%0D%0A';
        }
        else
            et='mailto:?subject=%C0%B4%D7%D4%20'+emailSubject+'%20%B5%C4%CE%C4%D5%C2'+'&body='+'%CE%C4%D5%C2%B5%D8%D6%B7'+'%0D%0A'+EncodeMail(urlThis)+'%0D%0A';
        location.href=et;
            
    }
}

function PrintThis()
{
    if(window.print)
    {
        window.print();
    }
    else
    {
        alert('你的浏览器不支持此功能，请按Ctrl-P或者从文件菜单选择打印功能。');
    }
}

function SetCookie(strCookieName,strCookieValue,strExpireDate)
{
    var strExpires;
    if(strExpireDate=="session")
    {
        strExpires="";
    }
    else
    {
        if(strExpireDate)
            strExpires=";expires="+strExpireDate;
        else
            strExpires=";expires="+(new Date( (new Date()).getTime() + 1000 * 60 * 60 * 24 )).toGMTString();//new Date(2021,10,4).toGMTString();
    }
    document.cookie=strCookieName+"="+escape(strCookieValue)+strExpires+";path=/";
}

function CheckMessenger(){
    this.gid=function(i){return document.getElementById(i);};
    try 
    { 
        
        objMessengerActiveP4 = new ActiveXObject("MSNMessenger.P4QuickLaunch");
    } 
    catch(e)
    {
    
        if(!gid("noMSNImDiv"))
        {
            noMSNImDiv=document.createElement("div");
            noMSNImDiv.setAttribute("id","noMSNImDiv");
            contentContainer=document.createElement("div");
            noMSNImDiv.appendChild(contentContainer);
        }
        else
        {
        gid("noMSNImDiv").style.display="block";
        };
        noMSNImDiv.className="floatBox";
        contentContainer.className="floatBoxContent";
        contentContainer.innerHTML="<div class='floatBoxHead'><span onmouseover='document.body.style.cursor=\"pointer\"' onmouseout='document.body.style.cursor=\"auto\"' onclick='document.getElementById(\"noMSNImDiv\").style.display=\"none\"'>[x]</a></div>对不起，您当前的配置不支持此功能.<br>要求安装 Messenger6.0 或以上版本及 IE5.5 或以上版本.<br><a href='http://im.live.cn' style='color:black;text-decoration:underline'  target='msnwin'>立即安装 Windows Live Messenger！</a><br><br>";
        dt=gid("P4_IMToolbar");
        dt.appendChild(noMSNImDiv);
        objMessengerActiveP4 = null;
    }
}
function GetEnvironment()
{
    var useragent=navigator.userAgent.toLowerCase();
    this.webtv=(useragent.indexOf("webtv")>-1);
    this.ie=(parseFloat(useragent.slice(useragent.indexOf("msie")+5)));
    this.nt=(parseFloat(useragent.slice(useragent.indexOf("windows nt")+11)));
    this.nn=(this.ie)?(-1):(parseFloat(useragent.slice(useragent.indexOf("mozilla/")+8)));
    this.mac=(useragent.indexOf("mac")>-1);
    this.firefox=(useragent.indexOf("firefox")>-1);
    this.safari=(useragent.indexOf("safari")>-1);
    this.systemlanguage=navigator.systemLanguage;
    this.browserlanguage=navigator.browserLanguage;
    this.userlanguage=navigator.userLanguage;
}
