﻿function fptClick(flag, url, title) {
    url = url.replace("http://dev", "http://www");
    var combol = (url.indexOf('?') != -1)? "&" : "?";
    url = url + combol + "rnd=" + getRadom(99999)
    var wname = "";
    title = ReplaceAll(title, "　", " ");  //加上這行是因為怕 title 會有全形空白，記得好像會出錯，加上以防萬一。

    if(flag == "fClick"){

        url = "http://www.facebook.com/sharer.php?u=" + encodeURIComponent(url) + "&t=" + encodeURIComponent(title);

        wname = "sharer";

    }else if(flag == "pClick"){

        url = "http://www.plurk.com/?qualifier=shares&status=" + encodeURIComponent(url) + " (" + encodeURIComponent(title) + ")";

        wname = "plurk";

    }else if(flag == "tClick"){

        url = "http://twitter.com/?qualifier=shares&status=(" + encodeURIComponent(title) + ") " + encodeURIComponent(url);

        wname = "twitter";

    }


    window.open(url, wname);
    return false;
}
function getFPT(flag, nid){
    try{
        if(!isNaN(nid.substring(0,1))){
            obj = document.getElementById('n' + nid);
        }
        else{
            obj = document.getElementById(nid);
        }
        fptClick(flag, obj.href, obj.title);
    }catch(e){alert(e);}
}
function FBVideo(vid) {
    if (window.location.href.indexOf("FlvPlayer01.htm") != -1) {
        fptClick('fClick', document.referrer + '&fbmvid=' + getParameter(queryString, 'id'), parent.document.title);
    }
    else {
        var indexfbmvid = window.location.href.indexOf("fbmvid=");
        if (indexfbmvid != -1) {
            fptClick('fClick', window.location.href.substring(0, indexfbmvid + 7) + vid.toString(), document.title);
        }
        else {
            fptClick('fClick', document.location + "&fbmvid=" + vid, document.title);
       }
        ImagePlay();       
    }
}
function ImagePlay() {
    var imgs = document.getElementsByTagName('img');
    for (var i = 0; i < imgs.length; i++) {
        if (imgs[i].src.indexOf(".gif") != -1 && document.all)
            imgs[i].src = imgs[i].src;
    }
}

function getRadom(intMax) {
    var intR = Math.floor(Math.random() * (intMax + 1));
    if (intR == 0)
        intR = 1;
    return intR;
}


function ReplaceAll(sString, strSource, strObject){

       while(sString.indexOf(strSource) != -1){

               sString = sString.replace(strSource, strObject);

       }

       return sString;

}


