﻿// JScript 文件
var divID="rbbox";
var srcUrl="http://www.yaoliwang.com";

function ref_Request(strName)
{
    var strHref=document.referrer;
    var intPos = strHref.indexOf("?");
    var strRight = strHref.substr(intPos + 1);

    var arrTmp = strRight.split("&");
    for(var i = 0; i < arrTmp.length; i++)
    {
        var arrTemp = arrTmp[i].split("=");
        if(arrTemp[0].toUpperCase() == strName.toUpperCase()) return arrTemp[1];
    }
    return "";
}

function ref_getKeyword()
{
    //baidu
    if (ref_Request("wd")!="")
        return "gb2312|"+ref_replace(ref_Request("wd"));
    //google
    //youdao
    //bing
    if (ref_Request("q")!="")
        return "utf-8|"+ref_replace(ref_Request("q"));
    //sogou
    if (ref_Request("query")!="")
        return "gb2312|"+ref_replace(ref_Request("query"));
    //yahoo
    if (ref_Request("p")!="")
        return "gb2312|"+ref_replace(ref_Request("p"));
    //soso
    if (ref_Request("w")!="")
        return "gb2312|"+ref_replace(ref_Request("w"));
    return "";
}

function ref_replace(str)
{
    var localString = '';   
    for(var index = 0; index<str.length; index++)   
    if(str.charAt(index)!= '%'){   
        localString += str.charAt(index);  
    }
    else{
        localString+="$";
        };   
    return localString; 
}
   
function ref_showBox(o)
{ 
    if (o==undefined) o=document.getElementById(divID); 
    o.style.height=o.clientHeight+2+"px"; 
    if (o.clientHeight<252) setTimeout(function(){ref_showBox(o)},5); 
} 

function ref_hideBox(o)
{ 
    if (o==undefined) o=document.getElementById(divID); 
    o.style.height=o.clientHeight-2+"px"; 
    if (o.clientHeight>32) setTimeout(function(){ref_hideBox(o)},5); 
}

function ref_closeBox(){
    document.getElementById(divID).style.display="none";
    ref_SetCookie("rbbox","true","/","yaoliwang.com");
}

function ref_changeBox(o)
{
    if (o.src.indexOf("hide.gif")>-1)
    {
        ref_hideBox();
        o.src=srcUrl+"/images_book/show.gif";
    }
    else
    {
        ref_showBox();
        o.src=srcUrl+"/images_book/hide.gif";
    }
}

//createDIV
function ref_createDiv()
{
    var div=document.createElement("div");
    div.id=divID;
    div.style.position="absolute";
    div.style.right="10";
    div.style.bottom="0";
    div.style.width="285px";
    div.style.height="0px";
    div.style.overflow="hidden";
    var content="<div style='position:absolute; top:8px; right:0px;' ><img src='"+srcUrl+"/images_book/hide.gif' onclick=\"ref_changeBox(this)\" style='cursor:pointer;' />&nbsp;<img src='"+srcUrl+"/images_book/close.gif' onclick=\"ref_closeBox()\" style='cursor:pointer; margin-right:15px;' /></div>";
    content+="<div><iframe src=\""+srcUrl+"/referrer.aspx?keyword="+ref_getKeyword()+"\" frameborder=\"0\" height=\"270\" width=\"285\" scrolling=\"no\"></iframe></div>";
    div.innerHTML=content;
    document.body.appendChild(div);
    var divDisplay=document.createElement("div");
    divDisplay.id="d";
    divDisplay.style.display="none";
    document.body.appendChild(divDisplay);
}

function ref_scroll()
{
    var isie6 = window.XMLHttpRequest?false:true;
    var a = document.getElementById(divID);
    var d = document.getElementById('d');
    if(isie6){
            a.style.position = 'absolute';
            window.onscroll = function(){
                d.innerHTML = '';
        }
    }else{
        a.style.position = 'fixed';
    }
    a.style.right = '0';
    a.style.bottom = '0';
}


function ref_GetCookieVal(offset) 
{
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}
function ref_SetCookie(name,value,path,domain) 
{ 
    var Days = 1;
    var exp = new Date(); 
    var argv = ref_SetCookie.arguments;
    var argc = ref_SetCookie.arguments.length;  
    //var expires = (argc > 2) ? argv[2] : null;
    //var path = (argc > 3) ? argv[3] : null;
    //var domain = (argc > 4) ? argv[4] : null;
    //var secure = (argc > 5) ? argv[5] : false;
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    //document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString()+";path="+path+";domain="+domain;
    document.cookie = name + "="+ escape (value) + ";path="+path+";domain="+domain;

}
function ref_DelCookie(name)
{ 
    var exp = new Date();
    exp.setTime (exp.getTime() - 1);
    var cval = ref_GetCookie (name);
    document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}
function ref_GetCookie(name) 
{  
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
        return ref_GetCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}

if (ref_GetCookie("rbbox")==null)
{
    ref_createDiv();
    ref_showBox();
    ref_scroll(); 
}
