/*
 * Copyright 2006 OST-SYSTEMS. All rights reserved.
 */

function WidgetContext(id) {
  this.id = id;
  this.showErrors = true;
}

WidgetContext.prototype.addError= function(error) {
  var errors = document.getElementById("Errors");
  if (this.showErrors) {
    errors.style.display = "block";
  }  
  errors.style.backgroundColor = "white";
  var textnode = document.getElementById("ErrorsContent");
  var text = textnode.firstChild;
  var from = "";
  if (addError.caller) {
    from = "[" + addError.caller.name + "]: ";
  }
  text.nodeValue = text.nodeValue + from + error + "\r\n";
}

WidgetContext.prototype.clearError = function() {
  var errors = document.getElementById("Errors");
  errors.style.display = "none";
  var textnode = document.getElementById("ErrorsContent");
  var text = textnode.firstChild;
  text.nodeValue = "\n";
}

WidgetContext.prototype.showErrorPage = function(show) {
  this.showErrors = show;
  var errors = document.getElementById("Errors");
  if (show) {
    errors.style.display = "block";
  }
  else {
    errors.style.display = "none";
  }
}  

WidgetContext.prototype.setBackgroundAttribute = function(attribute, value) {
  var body = document.getElementsByTagName("body")[0];
  if (body != null) {
    body.style["background" + attribute] = value;
    keyStorage.store("background", this.id, attribute, value);
  }  
}

WidgetContext.prototype.getBackgroundAttribute = function(attribute) {
  var body = document.getElementsByTagName("body")[0];
  if (body != null) {
    if (document.defaultView) {
      var style = document.defaultView.getComputedStyle(body, "");
      return style["background" + attribute];
    }
    else {
      eval("value = body.currentStyle.background" + attribute + ";");
      return value;
    }  
  }
  return null;  
}

WidgetContext.prototype.getBackground = function() {
  var body = document.getElementsByTagName("body")[0];
  if (body != null) {
    return body.style.background;
  }
  return null;  
}

WidgetContext.prototype.restoreBackground = function() {
  var body = document.getElementsByTagName("body")[0];
  if (body != null) {
    background = keyStorage.getAll("background", this.id);
    for (var attribute in background) {
      body.style["background" + attribute] = background[attribute];
    }  
  }
  return null;  
}


