var scriptArray = new Array();
var DocumentUpdater = Class.create();
DocumentUpdater.prototype = {
    initialize: function() {
        this.isActive = false;
        this.responseTimeout = null;
    },
    executeScript: function(aScript){
        eval(aScript);
    },
    ajaxUpdate: function(ajaxResponse) {
        
        var styleDataNodes = ajaxResponse.getElementsByTagName("style_data");
        var renderDataNodes = ajaxResponse.getElementsByTagName("render_data");
        var scriptDataNodes = ajaxResponse.getElementsByTagName("script_data");
               
        if(renderDataNodes != null && renderDataNodes.length >= 0){
            for(i=0;i<renderDataNodes.length;i++){
                var target = renderDataNodes[i].getAttribute("target");
                var newHTML = renderDataNodes[i].lastChild.nodeValue;
                if(target == null || target == ""){
                    target = document.getElementsByTagName("body").item(0);
                }
                if($(target)){
                 
			Element.update(target, newHTML);
                }
                else{
                   
                    Element.update("exceptionArea", "Taget "+target+" does not exsist");
                    setViewState("showExceptionArea"); 
                }
            }
            
        }
        if(scriptDataNodes != null && scriptDataNodes.length >= 0){
            for(i=0;i<scriptDataNodes.length;i++){
                
                this.executeScript(scriptDataNodes[i].lastChild.nodeValue);
            }
        }
        this.isActive = false; 
    },
    setResponseTimeout: function(){
        this.isActive = true;
      
        this.responseTimeout = setTimeout(this.clearResponseTimeout,10000);
    },
    clearResponseTimeout: function(){
        clearTimeout(this.responseTimeout);
    }
};


var documentUpdater = new DocumentUpdater();
ajaxEngine.registerAjaxObject('documentUpdater',documentUpdater);





