﻿
var ajax = null, ajVote = null, ajVisit, ajGoods, ajaxWant, ajLogin;

(function()
{
    showTips();
    ajVisit = CreateAjax();
    Send(ajVisit, "/Visit.jsp?id=" + Id, "GET", null, _ShowVisit, true, true);
})();

function _ShowVisit()
{
    if (null == ajVisit) return;
    if (4 != ajVisit.readyState) return;
    if (200 == ajVisit.status) ShowVisit(eval(ajVisit.responseText));
    ajVisit = null;
}

function ShowVisit(arr)
{
    var tbl = GetE('_visit_log');
    var shtml = '';
    if (null == tbl) return;
    if (null == arr) return;
    if (1 == arr.length) return;
    
    shtml = '<table border="0" cellpadding="4" cellspacing="1" width="100%">';
    
    for (var i = 0, l = arr.length, k = 0; i < l && k < 10; i++)
    {
        if (null == arr[i]) continue;
        if (i % 5 == 0) shtml += '<tr bgcolor="#ffffff" align="center" valign="bottom">';
        shtml += '<td><a href="' + arr[i].Url + '#related" target="_blank"><img vspace="2" hspace="2" width="92" onload="if(height>92){width*=(92/height);heigit=92;}" onerror="src=\'http://www.artxun.com/images/nophoto.jpg\';onerror=null;" src="' + arr[i].Photo + '" border="0" alt="' + decodeURI(arr[i].Name).replace(/\+/g, " ").replace(/\"/g, "&quot;") + '" /></a><br/><a href="' + arr[i].Url + '#related" target="_blank">' + decodeURI(arr[i].Name).replace(/\+/g, " ") + '</a></td>';
        if (i % 5 == 4) shtml += '</tr>';
        k += 1;
    }
    shtml += '</table>';
    GetE('_visit_body').innerHTML = shtml;
    tbl.style.display = '';
}

function showTips()
{
    var ly = GetE('_drop_tips');
    var img = GetE('main_photo');
    if (img == null) return;
    var pos = GetAbsPos(img);
    if (null == pos || null == ly) return;
    ly.style.top = (pos.Top + img.height + 2) + 'px';
    ly.style.left = (pos.Left + img.width / 2 - 142 / 2) + 'px';
    ly.style.display = '';
}

(function()
{
    var key = "";
    var els = document.getElementsByTagName("META");
    for (var i = 0, l = els.length; i < l; i++)
    {
        if (els[i].getAttribute("name") == 'keywords') key = els[i].getAttribute("content").replace(/^(\S+).*$/gi, "$1");
    }
    ajGoods = CreateAjax();
    Send(ajGoods, "/Goods.jsp?k=" + encodeURI(key), "GET", null, _ShowGoods, true, true);
})();

function _ShowGoods()
{
    if (null == ajGoods) return;
    if (4 != ajGoods.readyState) return;
    if (200 == ajGoods.status) ShowGoods(eval(ajGoods.responseText));
    ajGoods = null;
}

function ShowGoods(arr)
{
    var tbl = GetE('_goods');
    var shtml = '';
    if (null == tbl) return;
    if (null == arr) return;
    if (1 == arr.length) return;
    
    shtml = '<table border="0" cellpadding="4" cellspacing="1" width="100%">';
    
    for (var i = 0, l = arr.length, k = 0; i < l && k < 5; i++)
    {
        if (null == arr[i]) continue;
        if (i % 5 == 0) shtml += '<tr bgcolor="#ffffff" align="center" valign="bottom">';
        shtml += '<td width="20%"><a target="_blank" href="' + arr[i].Url + '?from_auction"><img vspace="2" hspace="2" width="92" height="92" onerror="src=\'http://www.artxun.com/images/nophoto.jpg\';onerror=null;" src="' + arr[i].Photo + '" border="0" alt="' + unescape(arr[i].Name).replace(/\+/g, " ").replace(/\"/g, "&quot;") + '" /></a><br/><a href="' + arr[i].Url + '?from_auction" target="_blank">' + unescape(arr[i].Name).replace(/\+/g, " ") + '</a></td>';
        if (i % 5 == 4) shtml += '</tr>';
        k += 1;
    }
    shtml += '</table>';
    GetE('_goods_body').innerHTML = shtml;
    tbl.style.display = '';
}

function InsertEmotion(imgObj){    if (null == imgObj) return;    var src = imgObj.src;    src = src.replace(/^.*?\/face\/(\w+)\.gif$/gi, "[$1]");    if (src.match(/^\[\w+\]$/gi) == null) return;    var txtObj = GetE("content");    if (null == txtObj) return;    txtObj.focus();    if (document.selection)    {        document.selection.createRange().text = src;    }    else if(typeof(txtObj.selectionStart) != "undefined")    {        txtObj.value = txtObj.value.replace(new RegExp("^([\\s\\S]{" + txtObj.selectionStart + "})([\\s\\S]{" + (txtObj.selectionEnd - txtObj.selectionStart) + "})([\\s\\S]*)$", "gi"), "$1" + src + "$3");    }    txtObj.focus();}
