﻿    
    
    onerror=handleErr
var txt=""

function handleErr(msg,url,l)
{
txt="There was an error on this page.\n\n"
txt+="Error: " + msg + "\n"
txt+="URL: " + url + "\n"
txt+="Line: " + l + "\n\n"
txt+="Click OK to continue.\n\n"
alert(txt)
return true
}

    var request = false;
   
   
   var spon = 0;
   var redLight = 0;
   var iInterval=1000;

     function getXMLHttpRequest() 
{
    if (window.XMLHttpRequest) {
    
        return new window.XMLHttpRequest;
    }
    else {
        try {
       
            return new ActiveXObject("MSXML2.XMLHTTP.3.0");
        }
        catch(ex) {
            return null;
        }
    }
}
     
   function getAuctionStatus() {
     if(redLight==0)redLight==1
     else
     return;    
     try
     {
     request = null;
        request = getXMLHttpRequest();
        
         
           
  if (request==null)
     alert("Error initializing XMLHttpRequest!");
     
     var url = "getAuctionStatus.aspx";
     request.open("GET", url, true);
     request.onreadystatechange = updateCountDownArea;
     request.send(null);
     redLight = 0;
     
     
     }catch(e)
     {
       alert(e.description );
     }
     finally{    
     
     }
   }
   
   function clearAllNode(parentNode){
    while (parentNode.firstChild) {
      var oldNode = parentNode.removeChild(parentNode.firstChild);
       oldNode = null;
     }
   } 
   function updateCountDownArea() {
   if(request==null)return;
   if(spon==0)
    spon =1;
    else
    return;
    try{
     if (request.readyState == 4) {
     if (request.status == 200) {
     
       var xmlDoc = request.responseXML;
       if(xmlDoc==undefined)
       {
        alert("null xmlDoc");
        return;
       }
      
       
       var asElement = xmlDoc.getElementsByTagName("AuctionStatus")[0];
       var asTextNode = asElement.firstChild;

       var auctionStatus = parseInt(asTextNode.nodeValue );
       
       var countdownArea = document.getElementById("countdownToLatest");
       if(countdownArea==undefined)
       {
       alert("no countdownArea found");
       return;
       }
       var welcLable = document.createTextNode("欢迎光临拍卖徐忆邮社网站!!")
       var inAuctionLink = document.createElement("a");
       inAuctionLink.setAttribute("href", "auction_room.aspx");
       inAuctionLink.appendChild(document.createTextNode("现场拍卖已经开始，请点击进入..."));

       switch(auctionStatus)
       {
       case -1:
       clearAllNode(countdownArea);
       countdownArea.appendChild(welcLable);
        break;
        case 0:
        var leftSecondsElement = xmlDoc.getElementsByTagName("LeftSeconds")[0];
        var lsTextNode = leftSecondsElement.firstChild;
        
        var leftSeconds = parseInt(lsTextNode.nodeValue);
         
        if(leftSeconds<=0)
        {
        clearAllNode(countdownArea);
       countdownArea.appendChild(inAuctionLink);
        }
        if(leftSeconds<=360)
        {
        
         var countDownLabel = document.createTextNode(leftSeconds+"秒后将进入现场拍卖");
         clearAllNode(countdownArea);
       countdownArea.appendChild(countDownLabel);
                
        }
        else
        {
        var auctionTime = xmlDoc.getElementsByTagName("NextAuctionTime")[0];
        var auctionTimeNode = auctionTime.firstChild;
        var auctionTime  = auctionTimeNode.nodeValue;
        
           clearAllNode(countdownArea);
       countdownArea.appendChild(document.createTextNode("欢迎光临，现场拍卖将于 " + auctionTime+" 开始,请大家关注！"));
                        }
                        leftSeconds = null;
        break;
       case 1:
       case 2:
       case 4:
       clearAllNode(countdownArea);
       countdownArea.appendChild(inAuctionLink);
        break;
        case 3:        
        break;
        default:
          clearAllNode(countdownArea);
         countdownArea.appendChild(welcLable);
        break;
       }
       
       xmlDoc = null;
       response = null;
     } 
   }
   }
   catch(e)
   {
   alert(e.description );
   }
   finally
   {
      
   }
   spon =0;
   
   
   }
   
 
setInterval("getAuctionStatus()",1000);