﻿//new_element = document.createElement("script");
//new_element.setAttribute("type", "text/javascript");
//new_element.setAttribute("src", "/src/common.js");
var xmlHttp;

var title;
var type;  //0 browsing,1 estimate
var ctype;//1:support,2:opponse
function createXMLHttpRequest() {

    if (window.ActiveXObject) {

        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

    }

    else if (window.XMLHttpRequest) {

        xmlHttp = new XMLHttpRequest();

    }

}
function registerrequest(name, email,type) {
    createXMLHttpRequest();
    var queryString = "/Asy/Registercheck.aspx?name=" + escape(name) + "&email=" + escape(email) + "&type=" + escape(type) + "&timeStamp=" + new Date().getTime();
    xmlHttp.onreadystatechange = registerStateChange;

    xmlHttp.open("GET", queryString, false);

    xmlHttp.send(null);
}
function registerStateChange() {
    if (xmlHttp.readyState == 4) {

        if (xmlHttp.status == 200) {

            var html = xmlHttp.responseText;
         
            if (html.indexOf("name") >= 0) {
                document.getElementById("UserName_error").innerHTML = html;
                
            }
            if (html.indexOf("email") >= 0) {
                document.getElementById("Email_error").innerHTML = html;
            }
           


        }

    }

}

function judgepricerequest(AvgPriceId, MemberId, PlaceId, ProductId, JudgePrice) {
    createXMLHttpRequest();
    var queryString = "/Asy/judgepricerequest.aspx?AvgPriceId=" + escape(AvgPriceId) + "&MemberId=" + escape(MemberId) + "&PlaceId=" + escape(PlaceId) + "&ProductId=" + escape(ProductId) + "&JudgePrice=" + escape(JudgePrice) + "&JudgeTime=" + new Date().getTime();
    xmlHttp.onreadystatechange = judgeStateChange;
    xmlHttp.open("GET", queryString, true);

    xmlHttp.send(null);
}
function judgeStateChange() {
    if (xmlHttp.readyState == 4) {

        if (xmlHttp.status == 200) {
        }
    }

}

function exitrequest() {
    createXMLHttpRequest();

    var queryString = "/exit.aspx?timeStamp=" + new Date().getTime();
    xmlHttp.onreadystatechange = exitStateChange;

    xmlHttp.open("GET", queryString, false);

    xmlHttp.send(null);
}
function exitStateChange() {
    if (xmlHttp.readyState == 4) {

        if (xmlHttp.status == 200) {
        } 
    }
}

function request(name, pwd,index) {

    createXMLHttpRequest();

    var queryString = "/landmanage.aspx?UserName=" + escape(name) + "&Pwd=" + escape(pwd) + "&index=" + index + "&timeStamp=" + new Date().getTime();
    xmlHttp.onreadystatechange = landStateChange;

    xmlHttp.open("GET", queryString, false);

    xmlHttp.send(null);
}
function landStateChange() {

    if (xmlHttp.readyState == 4) {

        if (xmlHttp.status == 200) {

            var html = xmlHttp.responseText;

            if (html == "0") {
                alert("用户名或密码错误");
               
            }
           
            else {
                landdiv.innerHTML = html;
            }
               
            
        }

    }

}

//拼url参数
function createQueryString(objectid) 
{
    

    title = escape(document.title);
    
    rawurl = escape(window.location.href);

    var referrerurl = escape(document.referrer);

    var tablefrom = getTableForm();

    var queryString = "tablefrom=" + tablefrom + "&rawurl=" + rawurl

        + "&referrerurl=" + referrerurl + "&objectid=" + objectid;
   return queryString;

}


//clicktype:1 support 2 opponse
function startRequest(edittype, clicktype, objectid) {

    type = edittype;
    ctype = clicktype;
    createXMLHttpRequest();
    var queryString = "/BrowsingHistoryManage.aspx?";

    queryString = queryString + createQueryString(objectid)

       + "&type=" + type + "&clicktype="+clicktype+"&timeStamp=" + new Date().getTime();


    xmlHttp.onreadystatechange = handleStateChange;

    xmlHttp.open("GET", queryString, true);

    xmlHttp.send(null);

}


function userbroswingRequest(){
    var rawurl = escape(window.location.href);

    var referrerurl = escape(document.referrer);
    createXMLHttpRequest();
    var queryString = "/BrowsingHistoryManage.aspx?rawurl=" + rawurl

        + "&referrerurl=" + referrerurl + "&timeStamp=" + new Date().getTime();
    var id = GetCookie(COOKIE_Id);
    
    if (id != null) {
        xmlHttp.onreadystatechange = browsingStateChange;

        xmlHttp.open("GET", queryString, true);

        xmlHttp.send(null);
    }


}

function browsingStateChange() {
    if (xmlHttp.readyState == 4) {

        if (xmlHttp.status == 200) {
        }
    }
}

function leavewordRequest(title, relation, content, revicemember) {
    createXMLHttpRequest();
    var queryString = "/Asy/LeavewordRequest.aspx?title=" + escape(title)

        + "&realtion=" + escape(relation) + "&content=" + escape(content) + "&revicemember=" + revicemember + "&timeStamp=" + new Date().getTime();
 
        xmlHttp.onreadystatechange = leavewordState;

        xmlHttp.open("GET", queryString, true);

        xmlHttp.send(null);


    }
    function leavewordState() {

        if (xmlHttp.readyState == 4) {

            if (xmlHttp.status == 200) {
                var result = xmlHttp.responseText;
                if (result == "1") { 
                    alert("留言发布成功")
                }
            }
        }
    }

userbroswingRequest();
function handleStateChange()
 {

    if (xmlHttp.readyState == 4) 
    {

        if (xmlHttp.status == 200) 
        {
            if (type == 1) {
              
                var estimatecount = xmlHttp.responseText;
                var estimate = estimatecount.split("|");
                if (estimate[0] == "no") {
                    if (ctype == 1) {

                        document.getElementById("support").innerHTML = estimate[1];
                    }
                    else if (ctype == 2) {

                    document.getElementById("opponse").innerHTML = estimate[2];

                    }
                    alert("该视频同一天只能顶踩一次");
                }
                else {


                    document.getElementById("support").innerHTML = estimate[0];
                    document.getElementById("opponse").innerHTML = estimate[1];
                }
            }
            
        }

    }

}



//读取原有cookies，判断重复，只保留近十条
function readcookies(name,values) 
{
    var cookiesvalues = GetCookie(name);
    
    if (cookiesvalues == null) {
        return values.substring(1);
    }
    if (cookiesvalues.indexOf(objectid) >= 0) {
        return null;
    }
    var cookiesvalue = cookiesvalues.split("|");
 
    if (cookiesvalue.length > 10) {
        cookiesvalue.shift();
        cookiesvalues=cookiesvalue;
    }
    else {
        cookiesvalues += values;
       
    }
   return cookiesvalues;
}



//action 

function getBrowsingList(tablefrom) 
{
    var cookiesvalues = GetCookie(tablefrom);

    if (cookiesvalues == "null" || cookiesvalues == null || cookiesvalues == "") 
    {
        return null;
    }
    if (tablefrom == "offer")    //供求
    {

        var offerlist = new Array();
        if (cookiesvalues == null)
            return null;
        var values = cookiesvalues.split("|");
        for (var i = 0; i < values.length; i++) {
            var value = values[i].split("#");
            var myoffer = new offerEntity();
            myoffer.id = value[0];
            myoffer.title = value[1];
            myoffer.offerclass = value[2];
            myoffer.price = value[3];
            myoffer.url = value[4];
            offerlist.push(myoffer);

        }
        return offerlist.reverse();
    }
    else if (tablefrom == "enterprise")//企业 
    {
        var enterpriseList = new Array();
        cookiesvalues = GetCookie(tablefrom);
        var values = cookiesvalues.split("|");

        for (var i = 0; i < values.length; i++) {
            var value = values[i].split("#");
            var ent = new enterprise();
            ent.id = value[0];
            ent.title = value[1];
            ent.logo = value[2];
            ent.url = value[3];
            enterpriseList.push(ent);
        }
        return enterpriseList.reverse();
    }
    else if (tablefrom == "video")//视频 
    {
        var videolist = new Array();
        cookiesvalues = GetCookie(tablefrom);
        var values = cookiesvalues.split("|");
        for (var i = 0; i < values.length; i++) {
            var value = values[i].split("#");
            var vid = new video();
            vid.id = value[0];
            vid.title = value[1];
            vid.imgurl = value[2];
            vid.url = value[3];
            videolist.push(vid);
        }
        return videolist.reverse();

    }
    else if (tablefrom == "article")//文章
    {
        var articleList = new Array();
        cookiesvalues = GetCookie(tablefrom);
        var values = cookiesvalues.split("|");

        for (var i = 0; i < values.length; i++) {
            var value = values[i].split("#");
            var artic = new article();
            artic.id = value[0];
            artic.title = value[1];
            artic.url = value[2];
            articleList.push(artic);
        }
        return articleList.reverse();
    }
    else if (tablefrom == "eproduct") {
        var eproductList = new Array();
        cookiesvalues = GetCookie(tablefrom);
        var values = cookiesvalues.split("|");

        for (var i = 0; i < values.length; i++) {
            var value = values[i].split("#");
            var ep = new eproduct();
            ep.id = value[0];
            ep.name = value[1];
            ep.img = value[2];
            ep.url = value[3];
            eproductList.push(ep);
        }
        return eproductList.reverse();
    }
}

function subBrowsingList(list,maxCount) {

    var resultCookieValues="";
    if(list.length>=maxCount)
    {
        var startIndex = list.length - maxCount + 1;
        for (var i = 0; i < startIndex; i++) {
            list[i] = null;
        }
    }
    for (var i = 0; i < list.length; i++) {
        if (list[i] != null && list[i] != "") 
        {
            if (i == (list.length - 1))
                resultCookieValues += list[i];
            else
                resultCookieValues += list[i] + "|";
        }
    }
    return resultCookieValues;
}

function clearBrowsingCookie(tableFrom,htmlContentId) {
    SetCookie(tableFrom, null, browsingTimeOut);
    document.getElementById(htmlContentId).innerHTML = "";
}

var browsingTimeOut = 30 * 24 * 60 * 60;//guo qi shi jian 30 tian
//offer
var offerBrowsingLogCount = 10;
function offerEntity() {

    this.id;
    this.offerclass;
    this.title;
    this.price;
    this.url;
    this.writeCookie = function() {

        var tFrom = "offer"; //getTableForm();
        var oldCookiesValues = GetCookie(tFrom);
        if (oldCookiesValues == null)
            oldCookiesValues = "";
        if (oldCookiesValues.indexOf(this.id) >= 0)
            return false;

        var enterpriseList = oldCookiesValues.split("|");
        if (enterpriseList.length >= offerBrowsingLogCount) {
            //qu chu chao chu de ji lu
            oldCookiesValues = subBrowsingList(enterpriseList, offerBrowsingLogCount);
        }
        if (oldCookiesValues == null || oldCookiesValues == "")
            oldCookiesValues = this.id + "#" + this.title + "#" + this.offerclass + "#" + this.price + "#" + this.url;
        else {
            oldCookiesValues += "|" + this.id + "#" + this.title + "#" + this.offerclass + "#" + this.price + "#" + this.url;
        }

        SetCookie(tFrom, oldCookiesValues, browsingTimeOut);
    }
}

//video
var videoBrowsingLogCount = 10;
function video() {
    this.id;
    this.title;
    this.url;
    this.imgurl;
    this.writeCookie = function() {

        var tFrom = "video"; //getTableForm();
        var oldCookiesValues = GetCookie(tFrom);
        if (oldCookiesValues == null)
            oldCookiesValues = "";

        if (oldCookiesValues.indexOf(this.id) >= 0)
            return false;
        var videolist = oldCookiesValues.split("|");
        if (videolist.length >= videoBrowsingLogCount) {
            //qu chu chao chu de ji lu
            oldCookiesValues = subBrowsingList(videolist, videoBrowsingLogCount);
        }

        if (oldCookiesValues == null || oldCookiesValues == "")
            oldCookiesValues = this.id + "#" + this.title + "#" + this.imgurl + "#" + this.url;
        else {
            oldCookiesValues += "|" + this.id + "#" + this.title + "#" + this.imgurl + "#" + this.url;
        }

        SetCookie(tFrom, oldCookiesValues, browsingTimeOut);
    }
}

//article
var articleBrowsingLogCount = 10; //ji lu qi ye shu liang ;
function article() {
    this.id;
    this.title;
    this.url;
    this.writeCookie = function() {

        var tFrom = "article"; //getTableForm();
        var oldCookiesValues = GetCookie(tFrom);
        if (oldCookiesValues == null)
            return false;
        if (oldCookiesValues.indexOf(this.id) >= 0)
            oldCookiesValues = "";
        var articleList = oldCookiesValues.split("|");
        if (articleList.length >= articleBrowsingLogCount) {
            //qu chu chao chu de ji lu
            oldCookiesValues = subBrowsingList(articleList, articleBrowsingLogCount);
        }

        if (oldCookiesValues == null || oldCookiesValues == "")
            oldCookiesValues = this.id + "#" + this.title + "#" + this.url;
        else {
            oldCookiesValues += "|" + this.id + "#" + this.title + "#" + this.url;
        }

        SetCookie(tFrom, oldCookiesValues, browsingTimeOut);
    }
}

//enterprise
var enterpriseBrowsingLogCount = 10; //ji lu qi ye shu liang ;
function enterprise() 
{
    this.id;
    this.title;
    this.logo;
    this.url;
    this.writeCookie = function() 
    {

        var tFrom = "enterprise"; //getTableForm();
        var oldCookiesValues = GetCookie(tFrom);
        if (oldCookiesValues == null)
            oldCookiesValues = "";
        if (oldCookiesValues.indexOf(this.id) >= 0)
            return false;
        var enterpriseList = oldCookiesValues.split("|");
        if (enterpriseList.length >= enterpriseBrowsingLogCount) {
            //qu chu chao chu de ji lu
            oldCookiesValues = subBrowsingList(enterpriseList, enterpriseBrowsingLogCount);
        }

        if (oldCookiesValues == null || oldCookiesValues == "")
            oldCookiesValues = this.id + "#" + this.title + "#" + this.logo + "#" + this.url;
        else {
            oldCookiesValues += "|" + this.id + "#" + this.title + "#" + this.logo + "#" + this.url;
        }

        SetCookie(tFrom, oldCookiesValues, browsingTimeOut);
    }
}

//enterprise product
var eproductBrowsingLogCount = 10;
function eproduct() 
{
    this.id;
    this.name;
    this.img;
    this.url;
    this.writeCookie = function() {

        var tFrom = "eproduct"; //getTableForm();
        var oldCookiesValues = GetCookie(tFrom);
        if (oldCookiesValues == null)
            oldCookiesValues = "";
        if (oldCookiesValues.indexOf(this.id) >= 0)
            return false;
        var eproductList = oldCookiesValues.split("|");
        if (eproductList.length >= eproductBrowsingLogCount) {
            //qu chu chao chu de ji lu
            oldCookiesValues = subBrowsingList(eproductList, eproductBrowsingLogCount);
        }

        if (oldCookiesValues == null || oldCookiesValues == "") {
            oldCookiesValues = this.id + "#" + this.name + "#" + this.img + "#" + this.url;
        }
        else {
            oldCookiesValues += "|" + this.id + "#" + this.name + "#" + this.img + "#" + this.url;
        }

        SetCookie(tFrom, oldCookiesValues, browsingTimeOut);
    }
 }
    
