﻿var adUrl = "http://ad.yabao365.com/";
var currentUrl = location.href;
var isMoscowServer = currentUrl.indexOf("www") > 0;

function show_special_ad(curr_ad_info, content_id) {

    var tmp_ad_url = curr_ad_info[0];
    var tmp_ad_click_url = curr_ad_info[1];
    var tmp_ad_content = curr_ad_info[2];
    var tmp_ad_width = curr_ad_info[3];
    var tmp_ad_height = curr_ad_info[4];
    var tmp_ad_adtype = curr_ad_info[5];
    var tmp_ad_opentype = curr_ad_info[6];
    var tmp_ad_url1 = curr_ad_info[7];
    var tmp_ad_showtype = curr_ad_info[8];
    var pos_id = curr_ad_info[9];
    var ad_content = $("#ad_pos_" + content_id);
    if (isMoscowServer) {
        tmp_ad_url = tmp_ad_url.replace("img2.yabao365", "img2.yabao365");
        tmp_ad_url1 = tmp_ad_url1.replace("img2.yabao365", "img2.yabao365");
    }
    switch (tmp_ad_adtype) {
        case "0":
            ad_content.html("<a href = \"" + tmp_ad_click_url + "\" target = \"" + tmp_ad_opentype + "\"><img src = \"" + tmp_ad_url + "\" width = \"" + tmp_ad_width + "\" height = \"" + tmp_ad_height + "\" border = \"0\"></a>");
            break;
        case "1":
            ad_content.html("<embed quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" scale=\"exactfit\" src=\"" + tmp_ad_url + "\" height= \"" + tmp_ad_height + "\" width= \"" + tmp_ad_width + "\" wmode=\"Transparent\"></embed>");
            break;
        case "2":
            ad_content.html("<iframe src='" + adUrl + "/code/" + pos_id + ".html' name='" + pos_id + "' width='" + tmp_ad_width + "' height='" + tmp_ad_height + "' frameborder='no' border='0' marginwidth='0' marginheight='0' scrolling='no' allowtransparency='yes' ></iframe>");
            break;
        case "3":
            document.write("<a href = '" + tmp_ad_click_url + "' target = \"+ tmp_ad_opentype +\">" + tmp_ad_content + "</a>");
            break;
        default:
            break;
    }
}

function show_yb_ad(pos_id) {
    document.write("<div id = 'ad_pos_" + pos_id + "' ></div>");
    $.getScript(adUrl + "/js/" + pos_id + ".js",
		function() {
		    try {
		        eval("default_ad_info = default_ad_info_" + pos_id);
		        show_special_ad(default_ad_info, pos_id);
		    }
		    catch (err) {

		    }
		}
	);
}
function show_yb_sc_ad(pageID, sysclassID) {
    document.write("<div id = 'ad_pos_" + sysclassID + "' ></div>");
    $.getScript(adUrl + "/scjs/" + pageID + "/" + sysclassID + ".js",
		function() {
		    try {
		        eval("default_ad_info = default_ad_info_" + sysclassID);
		        show_special_ad(default_ad_info, sysclassID)
		    } catch (err) {

		    }
		}
	);
}
//交换显示
function show_yb_sw_ad(adList) {
    if (!adList || adList.length <= 0) {
        return;
    }
    var ad_switch1 = getCookie('ad_switch1');
    if (ad_switch1 == undefined || ad_switch1 == null) {
        ad_switch1 = 0;
        saveCookie("ad_switch1", ad_switch1);
    }
    if (ad_switch1 == 0) {
        saveCookie("ad_switch1", 1);
    }
    else {
        saveCookie("ad_switch1", 0);
    }
    show_yb_ad(adList[ad_switch1]);
}

function saveCookie(objName, objValue) {//添加cookie
    var str = objName + "=" + escape(objValue);

    document.cookie = str;
}

function getCookie(objName) {//获取指定名称的cookie的值
    var arrStr = document.cookie.split("; ");
    for (var i = 0; i < arrStr.length; i++) {
        var temp = arrStr[i].split("=");
        if (temp[0] == objName) return unescape(temp[1]);
    }
}
  