﻿var ready = false;
var mouse_start = true;
var baseurl = "http://www.smpk.cn";
var scripturl = "http://www.smpk.cn/script";
var json, user, site, contentId;
var url = document.URL;
var isShow = true;
var m = 0;
var maxads=10;
var KeysImg = [];

if(typeof(user)=="undefined")
	user=3;
if(typeof(site)=="undefined")
	site="www.zjol.com.cn";
if(typeof(contentId) == "undefined")
	contentId="ArticleCnt";

String.prototype.replaceAll = function(s1, s2) {
    return this.replace(new RegExp(s1, "gm"), s2);
}
String.prototype.startsWith = function(str) {
    return (this.match("^" + str) == str);
}
String.prototype.endsWith = function(str) {
    return (this.match(str + "$") == str);
}
String.prototype.trim = function() {
    return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""));
}
function replace() {
	var __total = json.length;
	var __time=maxads/__total;
    for (var i = 0; i < __total; i++) {
        var code = json[i].Code;
        var keys = json[i].Keysword;
        var imgkeys = json[i].ImgKeys;
        var imgurl = baseurl + json[i].ImgUrl;
        url = baseurl + "/jump.aspx?code=" + code;
        var uid = "0";
        var nextPost;
        var frontPos = 0;
        var endPos = 0;
        var tmpString;
        var tmpNodeString = "";
        var findFlag = 0;
        for (var j = 0; j < nodeList.length && findFlag < __time; j++) {
            var kwAnchor = "<span name='cncsj_gemsy_adv' class='cncsj_adv_class' id='span_" + m + "'><a id='" + m + "' onmouseover='create_Div(this.id)' onmouseout='isShow=false;hrefmoveover(this.id)' code='" + code + "' rel='" + imgurl + "' href='" + url + "' target='_blank'>" + keys + "</a></span>";
	    KeysImg[m] = imgkeys;
            tmpNodeString = "";
            var words = keys;
            if (typeof(dataList[j]) == "undefined") {
                tmpString = nodeList[j].data;
            } else {
                tmpString = dataList[j];
            }
            if (tmpString.indexOf(words) > 0) {
                var pos = tmpString.indexOf(words);
                var perWord = tmpString.substring(0, pos) + kwAnchor + tmpString.substring(pos + words.length, tmpString.length);
                frontPos = pos + words.length;
                endPos = nodeList[j].length;
                tmpString = tmpString.substring(frontPos, endPos);
                if (nodeList[j].parentNode && nodeList[j].parentNode != null && FilterNode(nodeList[j].parentNode)) {
                    tmpNodeString += perWord;
                    findFlag++;
                    dataList[j] = tmpNodeString;
                }
            }
            m++;
        }
    }
    for (var n = 0; n < nodeList.length; n++) {
        try {
            if (dataList[n].innerHTML != "") {
                var tmpNode = document.createElement("span");
                tmpNode.id = "ad";
                tmpNode.innerHTML = dataList[n];
                nodeList[n].parentNode.replaceChild(tmpNode, nodeList[n]);
            }
        } catch(e) {}
    }
}
function FilterNode(Node) {
    if (Node.tagName == "IMG" || Node.tagName == "A" || Node.tagName == "SCRIPT" || Node.tagName == "OBJECT" || Node.tagName == "h1" || Node.tagName == "H1") {
        return false;
    }
    var pNode = Node.parentNode;
    while (pNode.tagName != "BODY") {
        if (pNode.tagName == "IMG" || pNode.tagName == "A" || pNode.tagName == "SCRIPT" || pNode.tagName == "OBJECT" || pNode.tagName == "h1" || pNode.tagName == "H1") {
            return false;
        }
        pNode = pNode.parentNode;
    }
    return true;
}
var osMac = false;
if (navigator.platform.toLowerCase().indexOf("mac") != -1) {
    osMac = true;
}
var bIE = (navigator.appName.indexOf("Microsoft") != -1);
var bOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
function include_script(url, doWrite) {
    if (doWrite) {
        document.writeln("<script type='text/javascript'  src='" + url + "'></script>");
    } else {
        if (bIE) {
            var s = document.createElement("script");
            s.setAttribute("type", "text/javascript");
            s.setAttribute("src", url);
            document.body.appendChild(s);
        } else {
            var s = document.createElement("SPAN");
            s.innerHTML = "<script type='text/javascript' src='" + url + "'></script>";
            document.body.appendChild(s);
        }
    }
}
function flash(ur, w, h) {
    var shtml = '<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="obj1" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" border="0" width="' + w + '" height="' + h + '"><param name="movie" value="' + ur + '"><param name="quality" value="high"><param name="wmode" value="transparent"><param name="menu" value="false"> <embed src="' + ur + '" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="obj1" width="' + w + '" height="' + h + '" quality="High" wmode="transparent"></embed></object>';
    return shtml;
}
function newsUL(imgkeys) {
    var sul = '<iframe allowTransparency="true" border="0" SCROLLING="no" FRAMEBORDER="0" src="http://ads.cncsj.net/show.aspx?keys=' + encodeURI(imgkeys) + '" width="238" height="77"></iframe>';
if(user=="3"){
	sul='<iframe allowTransparency="true" border="0" SCROLLING="no" FRAMEBORDER="0" src="http://www.smpk.cn/show.aspx?keys=' + encodeURI(imgkeys) + '" width="238" height="77"></iframe>';
}
    return sul;
}
function init() {
    if (!ready) {
        setTimeout("init()", 1000);
        return;
    }
    var d = document.getElementById(contentId) ? document.getElementById(contentId) : document.body;
    var tempNodeList = new Array();
    function parse_node(node, nodeList) {
        for (var tempI = 0; tempI < node.length; tempI++) {
            if (node[tempI].nodeType == 3 && (node[tempI].parentNode.tagName == "P" || node[tempI].parentNode.tagName == "DIV" || node[tempI].parentNode.tagName == "LI" || node[tempI].parentNode.tagName == "FONT")) {
                if (node[tempI].data.length > 1) {
                    nodeList[nodeList.length] = node[tempI];
                }
            }
            var childrens = node[tempI].childNodes;
            for (var i = 0; i < childrens.length; i++) {
                node[node.length] = childrens[i];
            }
        }
    }
    nodeList = [];
    tempNodeList[0] = d;
    parse_node(tempNodeList, nodeList);
    dataList = [];
    replace();
}
function hrefmoveover(obj) {
    setTimeout("divremove('" + obj + "')", 1000);
}
function divremove(obj) {
    try {
        if (!isShow) {
            var div = document.getElementById("div_" + obj);
            div.parentNode.removeChild(div);
        }
    } catch(e) {}
}
var show_total = 0;
createEl = function(p, t, a, y) {
    for (var i = 0; i < m; i++) {
        try {
            var div = document.getElementById("div_" + i);
            div.parentNode.removeChild(div);
        } catch (e) { }
    }
    var em = document.createElement(t);
    document.getElementById("span_" + p).appendChild(em); 
    if (a) {
        for (var k in a) {
            if (k == 'class') em.className = a[k];
            else if (k == 'id') em.id = a[k];
            else em.setAttribute(k, a[k]);
        }
    }
    if (y) {
        for (var k in y) em.style[k] = y[k];
    }

    var swf = jQuery("#" + em.id.split('_')[1]).attr("rel");
    var code = jQuery("#" + em.id.split('_')[1]).attr("code");
    var imgkeys = jQuery("#" + em.id.split('_')[1]).attr("imgkeys");
    url = baseurl + "/jump.aspx?code=" + code;
    var eNum = parseInt(swf.length);
    var sNum = parseInt(swf.lastIndexOf(".")) + 1;
    var gStr = swf.substring(sNum, eNum);
    var fla = null;
    if (gNum = 'swf') {
        fla = flash(swf, 240, 142);
    } else {
        fla = '<img src=' + swf + ' />';
    }
    var sul = newsUL(KeysImg[em.aid]);

    var html = '<a href=" ' + url + '" target="_blank" style="display:block; width:250px; background:#e5e5e5;filter: Alpha(Opacity=0);opacity:0; height:120px; position:absolute;"></a>'
	+ '<div  style=" padding:0px; text-indent:0em; margin:0px;background:#e9e9e9; border:none; text-align:center; padding-top:3px">' + fla + '</div>'
	+ '<div style="padding:0px; text-indent:0em; margin:0px;background:#e9e9e9 url(' + baseurl + '/img/hbackground.gif) 3px 0px no-repeat; height:22px;">'
	+ '<div style="padding:0px; text-indent:0em; margin:0px;text-align:left; margin:0px; padding:0px; height:22px;overflow:hidden; line-height:22px;"><span style=" float:right; padding:4px 5px 0 0;"><a href="http://www.smkk.cn/adsreg.aspx" target="_blank"><img border="0" src="' + baseurl + '/img/btn.gif" /></a></span><span style="color:#333; border-bottom:none;text-decoration:none;font-size:12px; font-weight:normal; padding:4px 0 0 15px;">延伸阅读</span></div>'
	+ '<div style=" height:87px padding:0px; text-indent:0em; margin:0px;line-height:25px;background:#e4e4e4" >' + sul + '</div>'
	+ '</div>'
	+'<iframe src=' + baseurl + '/ajaxhelper.aspx?action=v_keys&code=' + code + '&url=' + document.URL+' width=0 height=0></iframe>';
    $("#" + em.id).html(html);
    em.onmouseover = function() {
        isShow = true;
    };
    em.onmouseout = function() {
        isShow = false;
        hrefmoveover(em.id.split('_')[1]);
    };
    return em;
}
function create_Div(obj) {
    var newElement = createEl(obj, 'div', {
        'class': 'newDivClass',
        id: "div_" + obj,
        name: 'newDivName',
        aid: obj
    },
    {
		width: '250px',
        height: '248px'
    });
}
include_script(scripturl + "/css.js", false);
include_script(scripturl + "/jquery.js", false);
//document.writeln("<style>.newDivClass{position:absolute;z-index:9999; margin-top:-250px;border:#c40000 1px solid; background:#fff;padding:1px; overflow:hidden;text-indent:0em}</style>");
document.writeln("<style>.newDivClass{position:absolute;z-index:9999; margin-top:-250px;border:#c40000 1px solid; background:#fff;padding:1px; overflow:hidden;text-indent:0em;}.cncsj_adv_class{ border-bottom:1px #ff6600 solid;}.cncsj_adv_class a{ color:#ff6600; text-decoration:none;}.cncsj_adv_class a:hover{ color:#ff6600; text-decoration:none;}</style>");
include_script(baseurl + "/ajaxhelper.aspx?action=s_keys&url=" + url + "&infoid=" + user + "&web=" + site + "", true);
//document.writeln(baseurl + "/ajaxhelper.aspx?action=s_keys&url=" + url + "&infoid=" + user + "&web=" + site + "");
init();