﻿function ItmeSubmit(tmp_Gameid, value_id, tmp_Gamename, value_Items, value_Deliverytime, tmp_gamesx, tmp_totalpirc) {

    try {
        var Datejson = "{\"gameid\":\"" + tmp_Gameid + "\",";
        Datejson += "\"itemid\":\"" + value_id + ",\",";
        Datejson += "\"gamename\":\"" + tmp_Gamename + "\",";
        Datejson += "\"itemname\":\"" + value_Items + "|#\",";
        Datejson += "\"itemstatus\":\"" + 0 + "\",";
        Datejson += "\"itemquantity\":\"" + 1 + ",\",";
        Datejson += "\"deliverytime\":\"" + value_Deliverytime + ",\",";
        Datejson += "\"gamesx\":\"" + tmp_gamesx + "\",";
        Datejson += "\"totalPirc\":\"" + tmp_totalpirc + "\",";
        Datejson += "\"danPirc\":\"" + tmp_totalpirc + "\"}";
        Setcookies(CookiesKey.ItmeInfo, Datejson, 2);
        document.location = "../items-checkout.html";
    }
    catch (e) {

    }

}


//将时间换算成秒
function getSec(datatime) {
    var dt = new Date(datatime);
    return Math.floor(dt.getHours()) * 3600 + Math.floor(dt.getMinutes()) * 60 + Math.floor(dt.getSeconds());
}
//将秒换算成时间格式
function getNowTime(secs) {

    var hour = parseInt(secs / 3600);

    var min = parseInt((secs % 3600) / 60);

    var sec = parseInt(secs % 60);

    var result =(hour > 9 ? hour : ("0" + hour))+ "H:" +(min > 9 ? min : ("0" + min))+ "M:" +(sec > 9 ? sec : ("0" + sec))+"S";
    return result;


}
//两日期之间相隔秒数
function CalculateTime(date1, date2) {
    var dt1 = date1.replace("amp;","").split('&');
    var dt2 = date2.replace("amp;", "").split('&');
    var a = new Date(dt1[0].replace(/-/g, '/'));  //因为js默认只认“/”的日期格式
    var b = new Date(dt2[0].replace(/-/g, '/'));
    a = a.valueOf();
    b = b.valueOf();
    var c =  ((b - a) / (24 * 60 * 60 * 1000) + 1) * 24 * 60*60;  //间隔天数秒
    var d = parseInt(dt1[1].split(':')[0]) * 3600 + parseInt(dt1[1].split(':')[1]) * 60 + parseInt(dt1[1].split(':')[2]);
    
    var e = parseInt(dt2[1].split(':')[0]) * 3600 + parseInt(dt2[1].split(':')[1]) * 60 + parseInt(dt2[1].split(':')[2]);

    return (c+d-e);
}
//获取服务器
function GetServertime() {

    jQuery.ajax({
        url: '../ashx/HostTime.ashx',
        type: 'get',
        data: new Date(),
        dataType: 'text',
        error: function() { alert("NetWork Error!"); },
        success: function(str) {

        host_Time = str.split('|')[0];
        Host_away = str.split('|')[1];
        Timingload();
        }
    });
    
}
var host_Time;
var Host_away;
var arr = new Array(); //加载初试时间
var arrdat = new Array();
var Time_fet = true;


function Timingload() {

    var Start_time,Tmp_time;

    jQuery("#itmelistlang li").each(function(i) {
        //物品是否存在
        if (jQuery("#time_" + i) != null) {


            Start_time = jQuery("#time_" + i).html();
            
            Tmp_time = CalculateTime(Start_time,host_Time);
            arrdat[i] = Tmp_time - parseInt((Tmp_time / (parseInt(Host_away) * 3600)) )* Host_away*3600;

            if (arrdat[i] < 0) {
                arrdat[i] = (parseInt(Host_away) * 3600) *Host_away* 3600;
            }
        }

    });
         if (arrdat.length > 0) {
           TimingGo();
       }

}
//function Timingload() {
//    var startDate = new Date();
//    var timesec = 0; //相差秒数
//    
//    //是否第一次访问
//    if (Getcookies("#Nowtime") != null) {
//    
//        //是否是同一天
//        if (startDate.toLocaleDateString().toString() == Getcookies("#Nowtime")) {

//            timesec = getSec(startDate) - parseInt(Getcookies("#NowtimeSec"));
//  
//            Time_fet = true;

//        } else {
//            Time_fet = false;

//        }
//    }
//    else {
//       
//        Time_fet = false;
//    } 
//    
//    Setcookies("#Nowtime", startDate.toLocaleDateString().toString(), 24);
//     Setcookies("#NowtimeSec", getSec(startDate), 24); 
//   //循环所有展示物品
//     jQuery("#itmelistlang li").each(function(i) {

//         //物品是否存在
//         if (jQuery("#time_" + i) != null) {
//             //确定是否有历史记录
//             if (Getcookies("#time_" + i) != null && Time_fet && Getcookies("#time_" + i)!="NaN") {

//                 arrdat[i] = Math.abs(parseInt(Getcookies("#time_" + i)) - timesec);
//             }
//             else {
//                 arrdat[i] = 3600 * 24 - (Math.floor(Math.random() * 10 + 1) * 1000);
//             }
//             
//             Setcookies("#time_" + i, arrdat[i], 24);
//         }
//     });
//     if (arrdat.length > 0) {
//         TimingGo();
//     }
//}

function TimingGo()
{

    for(var n=0;n<arrdat.length;n++)
    {
        jQuery("#time_" + n).html(getNowTime(arrdat[n]));
        arrdat[n] = (arrdat[n] - 1);
    }

setTimeout("TimingGo()", 1000);
}

var fet_show = true;

//创建说明图层
function showOrderInfo(e) {

    if (fet_show) {

        fet_show = false
        e = e || window.event;
        var x = mouseX(e);
        var y = mouseY(e);

        var h = jQuery("#showitem").height();
        document.getElementById("showitem").style.position = "absolute";
        document.getElementById("showitem").style.left = (x + 10) + "px";
        document.getElementById("showitem").style.top = (y - h) + "px"
        document.getElementById("showitem").style.display = "";
        fet_show = true
    }
}

function descriptionshow(index, img, tile, description) {
    jQuery("#descriptions").html(jQuery("#" + description).html());
    document.getElementById("itemimgshow").style.backgroundImage = "url(" + img + ")";
    jQuery("#itemstile").html(uescapeChr(tile));
}

function CloseShow() {
    document.getElementById("showitem").style.display = "none";
}
//效果
function mouseX(evt) {
    if (evt.pageX) return evt.pageX;
    else if (evt.clientX)
        return evt.clientX + (document.documentElement.scrollLeft ?
document.documentElement.scrollLeft :
document.body.scrollLeft);
    else return null;
}
function mouseY(evt) {
    if (evt.pageY) return evt.pageY;
    else if (evt.clientY)
        return evt.clientY + (document.documentElement.scrollTop ?
document.documentElement.scrollTop :
document.body.scrollTop);
    else return null;
} 

