var hiddentiem=$("<input type=\"hidden\" id=\"hdstarttime\"/>");
$(hiddentiem).prependTo("body");
//倒数时间详细页面
function showTime(overdata, showObjId, isStart) {
    var arr = overdata.split(" ");
    var arr1 = arr[0].split("-");
    var arr2 = arr[1].split(":");
    var endData = new Date(arr1[0], (Number(arr1[1]) - 1), arr1[2], arr2[0], arr2[1], arr2[2]);
    
    // 剩余总秒
    var total = (endData - new Date()) / 1000;
    if (parseInt(total) <= 0) {
        $("#" + showObjId).text("团购已经结束，可以继续购买");
        clearInterval(showTime);
        return;
    }
    // 计算时间
    var day = parseInt(total / 86400);
    //var hour = parseInt(total / 3600);
    var hour = parseInt(total % 86400 / 3600);
    var min = parseInt((total % 3600) / 60);
    var sec = parseInt((total % 3600) % 60);

    if (hour.toString().length == 1)
        hour = "0" + hour;
    if (min.toString().length == 1)
        min = "0" + min;
    if (sec.toString().length == 1)
        sec = "0" + sec;
    var showTime ="<strong>"+day + "</strong>天<strong>" + hour + "</strong>时<strong>" + min + "</strong>分<strong>" + sec + "</strong>秒";

    // 显示
    if (isStart == "1")
        $("#" + showObjId).html(showTime);
    else
        $("#" + showObjId).html("即将开始");
}


//倒数时间列表页面
function showTimeList(overdata, showObjId, isStart,nowDate) {
    
    var arr = overdata.split(" ");
    var arr1 = arr[0].split("-");
    var arr2 = arr[1].split(":");
    var endData = new Date(arr1[0], (Number(arr1[1]) - 1), arr1[2], arr2[0], arr2[1], arr2[2]);
    var newDate=endData;
    if ($("#" + showObjId).text()==""||$("#" + showObjId).text()==null) {
        newDate = new Date(getServerTime());
    }
  
    if ($("#" + showObjId).html() != "" && $("#" + showObjId+" strong").length==4) {
        var d1 = $("#" + showObjId + " strong:eq(0)").text();
        var h = $("#" + showObjId + " strong:eq(1)").text();
        var m = $("#" + showObjId + " strong:eq(2)").text();
        var s = $("#" + showObjId + " strong:eq(3)").text();

        var sb = parseInt(d1 * 86400 +h * 3600 + m * 60)+ parseInt(s);

        newDate =endData - (sb - 1)*1000;
    }
  
    // 剩余总秒
    var total = (endData - newDate) / 1000;

    if (parseInt(total) <=0) {
        $("#" + showObjId).text("团购已经结束");
        return;
    }

    // 计算时间
    var day = parseInt(total / 86400);
    var hour = parseInt(total % 86400 / 3600);
    var min = parseInt((total % 3600) / 60);
    var sec = parseInt((total % 3600) % 60);

    if (hour.toString().length == 1)
        hour = "0" + hour;
    if (min.toString().length == 1)
        min = "0" + min;
    if (sec.toString().length == 1)
        sec = "0" + sec;
    var showTime ="<strong>"+day + "</strong>天<strong>" + hour + "</strong>时<strong>" + min + "</strong>分<strong>" + sec + "</strong>秒";
    // 显示
    if (isStart == "1")
        $("#" + showObjId).html(showTime);
    else
        $("#" + showObjId).html("团购即将开始");
}



function getServerTime() {
    var nowtime = $("#hdstarttime").val()-0;
    if(nowtime==""||nowtime==null||nowtime=="undefined"){
         var xmlHttp = false; 
        //获取服务器时间 
        try { 
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); 
        } catch (e) { 
            try { 
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
            } catch (e2) { 
                xmlHttp = false; 
            } 
        } 
         
        if (!xmlHttp && typeof XMLHttpRequest != 'undefined') { 
            xmlHttp = new XMLHttpRequest(); 
        } 
            
        xmlHttp.open("GET", "null.txt", false); 
        xmlHttp.setRequestHeader("Range", "bytes=-1"); 
        xmlHttp.send(null); 
         
        severtime=new Date(xmlHttp.getResponseHeader("Date"));
        nowtime = severtime.getTime();
        $("#hdstarttime").val(nowtime);
    }
   return nowtime;
   
}

