
//首页人气商品js代码  
//创建人：刘标才 2008-12-19
var nowDiff="";//客户端与服务器时间差
var postDateDiff="";//传输时间
var clientNowDate="";//客户端当前时间
var timeTicks=0;//时间的变化量

var hot1=null;//1-1999积分的商品
var hot2=null;//2000-5000积分的商品
var hot3=null;//5000-10000积分的商品
var hot4=null;//10000-1000000积分的商品
var n=null;
//------------------------以上变量用来保存客户端代码减少访问服务器次数----------------------------------

function initHot(min,max)
{
    var obj=document.getElementById('hotProduct');
    if(min==null||min=='')
        min='0';
    if(max==null||max=='')
        max='1999';
    if(min==0&&max==1999){
        n=1;
        if(hot1!=null&&hot1!=''){
            obj.innerHTML=hot1;
            return;
        }
    }
    if(min==2000&&max==5000){
        n=2;
        if(hot2!=null&&hot2!=''){
            obj.innerHTML=hot2;
            return;
        }
    }
    if(min==5000&&max==10000){
        n=3;
        if(hot3!=null&&hot3!=''){
            obj.innerHTML=hot3;
            return;
        }
    }
    if(min==10000&&max==100000000){
        n=4;
        if(hot4!=null&&hot4!=''){
            obj.innerHTML=hot4;
            return;
        }
    }
    getAjaxByMethod("checkUser.aspx?minPoint="+min+"&maxPoint="+max,initstatechange); 
}


function initstatechange(xmlHttp){
    if (xmlHttp.readyState == 4&&xmlHttp.status==200){
        if(n==1){hot1=unescape(xmlHttp.responseText);}
        if(n==2){hot2=unescape(xmlHttp.responseText);}
        if(n==3){hot3=unescape(xmlHttp.responseText);}
        if(n==4){hot4=unescape(xmlHttp.responseText);}
        document.getElementById("hotProduct").innerHTML=xmlHttp.responseText;
    }
    if(xmlHttp.readyState == 1 || xmlHttp.readyState == 3){
        var html="<div class='resear'><div style='background:url(webTheme/images/loader.gif) no-repeat 15px center;padding:50px;text-indent:25px;color:#000000;font-size:14px; font-weight:bold;'>数据加载中,请稍候...</div></div>";
        document.getElementById('hotProduct').innerHTML=html;
    }
}
 
 //人气商品按钮鼠标按下事件
//function mouseDown(n)
//{
//   for(var i=1;i<=4;i++){
//       if(i==n){
//             switch(i){
//                 case 1:document.getElementById("hotBtn_1").className='divB_button1_down divB_button1_hasRight';break;
//                 case 2:document.getElementById("hotBtn_2").className='divB_button2_down divB_button1_hasRight';break;
//                 case 3:document.getElementById("hotBtn_3").className='divB_button3_down divB_button1_hasRight';break;
//                 case 4:document.getElementById("hotBtn_4").className="divB_button4_down";break;
//                 default:break;
//             }
//       }
//       else{
//            switch(i){
//                 case 1:document.getElementById("hotBtn_1").className='divB_button1_normal divB_button1_hasRight';break;
//                 case 2:document.getElementById("hotBtn_2").className='divB_button2_normal divB_button1_hasRight';break;
//                 case 3:document.getElementById("hotBtn_3").className='divB_button3_normal divB_button1_hasRight';break;
//                 case 4:document.getElementById("hotBtn_4").className="divB_button4_normal";break;
//                 default:break;
//           }
//       }
//   }
//}


function mouseDown(n)
{
   for(var i=1;i<=4;i++)
   {
       if(i==n)
       {   
           document.getElementById("dt_"+n).className="play";
           document.getElementById("dd_"+n).className="divB_button"+ i +"_down";
       }
       else
       {
           document.getElementById("dt_"+i).className="clear";
           document.getElementById("dd_"+i).className="divB_button"+ i +"_normal";
       }
   }
}

function mouseHover(n,obj)
{
   if(obj.className!="divB_button"+ n +"_down"){
       obj.className="divB_button"+ n +"_hover";
   }
   for(var i=1;i<=4;i++)
   {
       if(n==i)
       {
           document.getElementById("dt_"+i).className="play";
       }
       else
       {
           if(document.getElementById("dd_"+i).className!="divB_button"+ i +"_down"){
              document.getElementById("dt_"+i).className="clear";
           }
       }
   }
}

function mouseOut(n,obj)
{
   if(obj.className!="divB_button"+ n +"_down"){
       obj.className="divB_button"+ n +"_normal";
   }
}

function setClear(n,obj)
{
    if(document.getElementById('dd_'+n).className!="divB_button"+n+"_down"){
        obj.className="clear";
    }
}

//浏览器类型及版本检测
function getOs() {
    var OsObject = "";
    if (navigator.userAgent.indexOf("MSIE") > 0) {
        return "MSIE";
    }
    if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {
        return "Firefox";
    }
    if (isSafari = navigator.userAgent.indexOf("Safari") > 0) {
        return "Safari";
    }
    if (isCamino = navigator.userAgent.indexOf("Camino") > 0) {
        return "Camino";
    }
    if (isMozilla = navigator.userAgent.indexOf("Gecko/") > 0) {
        return "Gecko";
    }

}
function showTime()
{   
   var timeValue=document.getElementById('ctl00_hide_time').value;
   var start=timeValue.split('|')[0];//从页面的隐藏控件读取活动开始时间
   var end=timeValue.split('|')[1];//从页面的隐藏控件读取活动结束时间
   var serverNow=timeValue.split('|')[2];//从页面的隐藏控件读取服务器当前时间
   
   if(start!=null && end!=null && serverNow!=null)
   {
       var now=new Date();//客户端现在的时间
       timeTicks++;
       var serverNowDate=new Date(Date.parse(serverNow.replace(/-/g,"/")));
       if (timeTicks > 1)//第二次或者以后
       {
           var clientTimeDiff = now.getTime() - clientNowDate.getTime();
           if (Math.abs(clientTimeDiff) > 3000)//时间间隔超过3秒，可能修改了当前时间
           {
               nowDiff = nowDiff - clientTimeDiff - 1500;
           }
           nowDiff = nowDiff - postDateDiff;//第二次或者以后不存在传输时间差
       }
       else {
           nowDiff = serverNowDate.getTime() - now.getTime() + postDateDiff; //客户端与服务器时间差 
       }
       clientNowDate=now;
       var startDate = new Date(Date.parse(start.replace(/-/g,"/")));
       var endDate = new Date(Date.parse(end.replace(/-/g,"/")));
       var timeDiff=startDate.getTime()-(now.getTime()+nowDiff);//开始的时间差，加上客户端与服务器的时间差
       
       var day=Math.floor(timeDiff/(24*60*60*1000));
       var hour=Math.floor(timeDiff / (1000*3600)) - (day * 24);
       var minute=Math.floor(timeDiff / (1000*60)) - (day * 24 *60) - (hour * 60);
       var second=Math.floor(timeDiff / (1000)) - (day * 24 *60*60) - (hour * 60 * 60) - (minute*60);
       var div_time=document.getElementById('div_time');//显示时间的div控件
       if(parseInt(timeDiff)>0)
       {
           if(day<10)day="0"+day;
           if(hour<10)hour="0"+hour;
           if(minute<10)minute="0"+minute;
           if(second<10)second="0"+second;
           div_time.innerHTML="距离抢购开始还剩："+day+"天"+hour+"小时"+minute+"分钟"+second+"秒";
       }
       else if(parseInt(timeDiff)==0)
       {
           div_time.innerHTML="活动开始啦";
           location.href="/Activity/ScareBuyingShow.aspx";
       }
       else if(parseInt(timeDiff) < 0 && parseInt(now.getTime())+parseInt(nowDiff) <parseInt(endDate.getTime()))
       {
           div_time.innerHTML="活动正在进行中。。。";
       }
       else if(parseInt(now.getTime())+parseInt(nowDiff)>=parseInt(endDate.getTime()))
       {
           div_time.innerHTML="活动已经结束。。。";
       }
   }
   
   window.setTimeout("showTime()",1000);
}

function showCount()
{
    getAjaxByMethod("/checkUser.aspx?action=showcount&ran="+Math.random(),function(xmlHttp){
       if (xmlHttp.readyState == 4&&xmlHttp.status==200){
            document.getElementById('div_count').innerHTML="今日活动资格还剩："+xmlHttp.responseText+"人";
        }
        else{
            document.getElementById('div_count').innerHTML="今日活动资格还剩：0人";
        }
   }); 
    window.setTimeout("showCount()",20000);
}        

function setTime()
{
    var now=new Date();
    
    getAjaxByMethod("/checkUser.aspx?action=setTime&ran="+Math.random(),function(xmlHttp){
        if (xmlHttp.readyState == 4&&xmlHttp.status==200){
             document.getElementById('ctl00_hide_time').value=unescape(xmlHttp.responseText);
             postDateDiff=new Date().getTime()-now.getTime();
        }
        else if(xmlHttp.readyState == 4&&xmlHttp.status!=200){
            document.getElementById('ctl00_hide_time').value="2009-4-9 19:00|2009-4-16 23:59"+new Date().toString();
        }
    }); 
}
