// JavaScript Document
function dopages(p){        
        var posts = "p="+p;
        var url = ajaxurl('pages.php');
        function func(){
            getResult('dopages');
        };
        sendRequest(url,posts,func);
}
function ajaxurl(adDiv){
        var baseurl = "http://ad.nie.netease.com/" + adDiv;
        return baseurl;        
        }
function getajax(){
        var xmlhttp = false;
        if(window.ActiveXObject){
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else if(window.XMLHttpRequest){
                xmlhttp = new XMLHttpRequest();
        }
        return xmlhttp;
        }
function sendRequest(url,posts,func){
        ajax = getajax();
        ajax.onreadystatechange = func;
        ajax.open('POST', url, true);
        ajax.setRequestHeader("Content-Length",posts.length); 
        ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        ajax.send(posts);        
}
/*------------Try-------------*/
var Try = {
  these: function() {
    var returnValue;
    for (var i = 0; i < arguments.length; i++) {
      var lambda = arguments;
      try {
        returnValue = lambda();
        break;
      } catch (e) {}
    }
    return returnValue;
  }
}

function tryCollectGarbage(){
    return Try.these(
        function() {return CollectGarbage();},
        function() {return false;}
        );
}
function getResult(adDiv,num){
        if (ajax.readyState < 4) {
                document.getElementById("loading").style.visibility = "visible";
        } 
        else if (ajax.readyState == 4) {
                document.getElementById("loading").style.visibility = "hidden";
                if (ajax.status == 200){
                var result = ajax.responseText;
                if(adDiv=="dopages"){
                        document.getElementById('xpages').innerHTML = result;
                        }
        }
                else {
                        alert("³ö´í");
                        delete ajax;
                        tryCollectGarbage();//À¬»ø»ØÊÕ
                }
        }
}        

