﻿
/// <summary>
/// 添加事件
/// </summary>
/// <param name="target">载体</param>
/// <param name="type">事件类型</param>
/// <param name="func">事件函数</param>
function addEventHandler(target, type, func) {
    if (target.addEventListener)
        target.addEventListener(type, func, false);
    else if (target.attachEvent)
        target.attachEvent("on" + type, func);
    else target["on" + type] = func;
}

/// <summary>
/// 移除事件
/// </summary>
/// <param name="target">载体</param>
/// <param name="type">事件类型</param>
/// <param name="func">事件函数</param>
function removeEventHandler(target, type, func) {
    if (target.removeEventListener)
        target.removeEventListener(type, func, false);
    else if (target.detachEvent)
        target.detachEvent("on" + type, func);
    else delete target["on" + type];
}

/// <summary>
/// 获得元素的绝对坐标
/// </summary>
/// <param name="element">HTML元素</param>
function absolutePoint(element) {
    var result = { x: element.offsetLeft, y: element.offsetTop };
    element = element.offsetParent;
    while (element) {
        result.x += element.offsetLeft;
        result.y += element.offsetTop;
        element = element.offsetParent;
    }
    return result;
}


//--------------------------------- 商家报价 促销活动 (首页) -----------------------------------

function CznetActiveCard() {

    this.div_card = document.createElement("div");
    with (this.div_card.style) {
        borderStyle = "none";
        borderWidth = "0";
        display = "none";
        width = "357px";
        height = "194px";
        position = "absolute";
        textAlign = "left";
        background = "transparent url(/Content/Home/images/bg_ActiveCard.gif) no-repeat scroll 0 0";
        fontFamily = "Verdana,Arial,Helvetica,sans-serif";
    }
    document.body.appendChild(this.div_card);

    this.table_card = document.createElement("table");
    with (this.table_card.style) {
        top = "12px";
        left = "56px";
        position = "relative";
        width = "290px";
    }
    this.table_card.cellSpacing = "0";
    this.table_card.cellPadding = "0";
    this.table_card.border = "0";
    this.div_card.appendChild(this.table_card);

    this.tr_card = this.table_card.insertRow(-1);
    this.td_card = this.tr_card.insertCell(-1);
    with (this.td_card.style) {
        lineHeight = "170%";
        textAlign = "left";
        verticalAlign = "top";
    }

    this.brand_tip = document.createElement("span");
    with (this.brand_tip.style) {
        color = "#828282";
        fontSize = "13px";
    }
    this.brand_tip.innerHTML = "品牌：";
    this.td_card.appendChild(this.brand_tip);

    this.brand = document.createElement("span");
    with (this.brand.style) {
        color = "#01359D";
        fontSize = "15px";
    }
    this.td_card.appendChild(this.brand);

    this.br_1 = document.createElement("br");
    this.td_card.appendChild(this.br_1);

    this.types_tip = document.createElement("span");
    with (this.types_tip.style) {
        color = "#828282";
        fontSize = "13px";
    }
    this.types_tip.innerHTML = "车型：";
    this.td_card.appendChild(this.types_tip);

    this.types = document.createElement("span");
    with (this.types.style) {
        color = "#01359D";
        fontSize = "15px";
    }
    this.td_card.appendChild(this.types);

    this.br_2 = document.createElement("br");
    this.td_card.appendChild(this.br_2);

    this.customer_tip = document.createElement("span");
    with (this.customer_tip.style) {
        color = "#828282";
        fontSize = "13px";
    }
    this.customer_tip.innerHTML = "经销商：";
    this.td_card.appendChild(this.customer_tip);

    this.customer = document.createElement("span");
    with (this.customer.style) {
        color = "#01359D";
        fontSize = "15px";
    }
    this.td_card.appendChild(this.customer);


    this.br_3 = document.createElement("br");
    this.td_card.appendChild(this.br_3);

    this.active_tip = document.createElement("span");
    with (this.active_tip.style) {
        color = "#828282";
        fontSize = "13px";
    }
    this.active_tip.innerHTML = "活动内容：";
    this.td_card.appendChild(this.active_tip);

    this.active = document.createElement("span");
    with (this.active.style) {
        color = "#01359D";
        fontSize = "15px";
    }
    this.td_card.appendChild(this.active);
}

CznetActiveCard.prototype.close = function() {
    this.div_card.style.display = "none";
    if (typeof this.onclose == "function") this.onclose(this);
}

CznetActiveCard.prototype.show = function(left, top, brand, types, customer, active) {
    this.brand.innerHTML = brand;
    this.types.innerHTML = types;
    this.customer.innerHTML = customer;
    this.active.innerHTML = active;

    this.div_card.style.left = left + "px";
    this.div_card.style.top = top + "px";
    this.div_card.style.display = "block";

}


var currentActiveCard = null;

function showActiveCard(sender, brand, types, customer, active) {
    if (!currentActiveCard) {

        currentActiveCard = new CznetActiveCard();
    }
    var point = absolutePoint(sender);
    currentActiveCard.owner = sender;
    currentActiveCard.show(point.x + 30, point.y, brand, types, customer, active);
    currentActiveCard.mouseover = function(e) {
        var element = typeof event != "undefined" ? event.srcElement : e.target;
        var hotCard = false;
        while (element) {
            hotCard = element == currentActiveCard.owner || element == currentActiveCard.div_card;
            if (hotCard) break;
            element = element.parentNode;
        }
        if (!hotCard) {
            removeEventHandler(document, "mouseover", currentActiveCard.mouseover);
            currentActiveCard.close();
        }
    }
    addEventHandler(document, "mouseover", currentActiveCard.mouseover);
}


//--------------------------------- 热卖车型 促销活动 (商家详细页) -----------------------------------

function AutosActiveCard() {

    this.div_card = document.createElement("div");
    with (this.div_card.style) {
        borderStyle = "none";
        borderWidth = "0";
        display = "none";
        width = "357px";
        height = "194px";
        position = "absolute";
        textAlign = "left";
        background = "transparent url(/Content/Home/images/bg_ActiveCard.gif) no-repeat scroll 0 0";
        fontFamily = "Verdana,Arial,Helvetica,sans-serif";
    }
    document.body.appendChild(this.div_card);

    this.table_card = document.createElement("table");
    with (this.table_card.style) {
        top = "12px";
        left = "56px";
        position = "relative";
        width = "290px";
    }
    this.table_card.cellSpacing = "0";
    this.table_card.cellPadding = "0";
    this.table_card.border = "0";
    this.div_card.appendChild(this.table_card);

    this.tr_card = this.table_card.insertRow(-1);
    this.td_card = this.tr_card.insertCell(-1);
    with (this.td_card.style) {
        lineHeight = "170%";
        textAlign = "left";
        verticalAlign = "top";
    }

    this.types_tip = document.createElement("span");
    with (this.types_tip.style) {
        color = "#828282";
        fontSize = "13px";
    }
    this.types_tip.innerHTML = "车型：";
    this.td_card.appendChild(this.types_tip);

    this.types = document.createElement("span");
    with (this.types.style) {
        color = "#01359D";
        fontSize = "15px";
    }
    this.td_card.appendChild(this.types);

    this.br_1 = document.createElement("br");
    this.td_card.appendChild(this.br_1);


    this.active_tip = document.createElement("span");
    with (this.active_tip.style) {
        color = "#828282";
        fontSize = "13px";
    }
    this.active_tip.innerHTML = "活动内容：";
    this.td_card.appendChild(this.active_tip);

    this.active = document.createElement("span");
    with (this.active.style) {
        color = "#01359D";
        fontSize = "15px";
    }
    this.td_card.appendChild(this.active);
   
}

AutosActiveCard.prototype.show = function(left, top, types, active) {
    this.types.innerHTML = types;
    this.active.innerHTML = active;

    this.div_card.style.left = left + "px";
    this.div_card.style.top = top + "px";
    this.div_card.style.display = "block";

}

AutosActiveCard.prototype.close = function() {
    this.div_card.style.display = "none";
    if (typeof this.onclose == "function") this.onclose(this);
}

var currentAutosCard = null;

function showAutosCard(sender, types, active) {
    if (!currentAutosCard) {

        currentAutosCard = new AutosActiveCard();
    }
    var point = absolutePoint(sender);
    currentAutosCard.owner = sender;
    currentAutosCard.show(point.x + 30, point.y, types, active);
    currentAutosCard.mouseover = function(e) {
        var element = typeof event != "undefined" ? event.srcElement : e.target;
        var hotCard = false;
        while (element) {
            hotCard = element == currentAutosCard.owner || element == currentAutosCard.div_card;
            if (hotCard) break;
            element = element.parentNode;
        }
        if (!hotCard) {
            removeEventHandler(document, "mouseover", currentAutosCard.mouseover);
            currentAutosCard.close();
        }
    }
    addEventHandler(document, "mouseover", currentAutosCard.mouseover);
}

//--------------------------------- 经销商登录 (商家详细页) -----------------------------------

function showLogin(sender) {
    var point = absolutePoint(sender);
    var logDiv = document.getElementById("div_login");
    var left = point.x - 357;
    logDiv.style.left = left + "px";
    logDiv.style.display = "";
}

function closeLogin() {
    var logDiv = document.getElementById("div_login");
    document.getElementById('Password').value = "";
    logDiv.style.display = "none";
}


//--------------------------------- 回复 (商家详细页) -----------------------------------

function showAffirmCard(sender,id) {
    var point = absolutePoint(sender);
    var affirmDiv = document.getElementById("div_affirm");
    var a_id = document.getElementById("sp_id");
    a_id.innerHTML = id;

    var left = point.x + 40;
    var top = point.y;
    affirmDiv.style.left = left + "px";
    affirmDiv.style.top = top + "px";

    affirmDiv.style.display = "";
}

function closeAffirm() {
    var affirmDiv = document.getElementById("div_affirm");
    var affirmTxt = document.getElementById("Affirm");

    affirmTxt.value = "";
    affirmDiv.style.display = "none";
}

