var OBJECT_TYPE_SHAPE           = "http://www.bab-tec.de/eibPort:objects:Shape";
var OBJECT_TYPE_COLORCHOOSER    = "http://www.bab-tec.de/eibPort:objects:ColorChooser";
var OBJECT_TYPE_BG_IMAGE        = "http://www.bab-tec.de/eibPort:objects:v2:BgImage";
var OBJECT_TYPE_PAGE_LINK       = "http://www.bab-tec.de/eibPort:objects:v2:PageLink";
var OBJECT_TYPE_LAMP            = "http://www.bab-tec.de/eibPort:objects:v2:Lamp";
var OBJECT_TYPE_SWITCH_ON_OFF   = "http://www.bab-tec.de/eibPort:objects:v2:SwitchOnOff";
var OBJECT_TYPE_SWITCH_DIM      = "http://www.bab-tec.de/eibPort:objects:v2:SwitchDim";
var OBJECT_TYPE_SLIDER          = "http://www.bab-tec.de/eibPort:objects:v2:Slider";
var OBJECT_TYPE_BUTTON          = "http://www.bab-tec.de/eibPort:objects:v2:Button";
var OBJECT_TYPE_BUTTON_EIS14    = "http://www.bab-tec.de/eibPort:objects:v2:ButtonEis14";
var OBJECT_TYPE_STATIC_TEXT     = "http://www.bab-tec.de/eibPort:objects:v2:StaticText";
var OBJECT_TYPE_DYNAMIC_TEXT    = "http://www.bab-tec.de/eibPort:objects:v2:DynamicText";
var OBJECT_TYPE_EIS15_TEXT      = "http://www.bab-tec.de/eibPort:objects:v2:Eis15Text";
var OBJECT_TYPE_EIS15_DISPLAY   = "http://www.bab-tec.de/eibPort:objects:v2:Eis15Display";
var OBJECT_TYPE_TELEGRAM_TIME   = "http://www.bab-tec.de/eibPort:objects:v2:TelegramTime";
var OBJECT_TYPE_DATE_TIME       = "http://www.bab-tec.de/eibPort:objects:v2:DateTime";
var OBJECT_TYPE_ANALOG_TIME     = "http://www.bab-tec.de/eibPort:objects:v2:AnalogTime";
var OBJECT_TYPE_TEMP_DISPLAY    = "http://www.bab-tec.de/eibPort:objects:v2:TempDisplay";
var OBJECT_TYPE_TEMP_CONTROL    = "http://www.bab-tec.de/eibPort:objects:v2:TempControl";
var OBJECT_TYPE_VALUE_DISPLAY   = "http://www.bab-tec.de/eibPort:objects:v2:ValueDisplay";
var OBJECT_TYPE_TOP_CONSUMER    = "http://www.bab-tec.de/eibPort:objects:TopConsumer";
var OBJECT_TYPE_SEQ_BUTTON      = "http://www.bab-tec.de/eibPort:objects:SeqButton";
var OBJECT_TYPE_JALOUSIE        = "http://www.bab-tec.de/eibPort:objects:v2:Jalousie";
var OBJECT_TYPE_DYN_JALOUSIE    = "http://www.bab-tec.de/eibPort:objects:DynJalousie";
var OBJECT_TYPE_WINDOWCONTACT   = "http://www.bab-tec.de/eibPort:objects:WindowContact";
var OBJECT_TYPE_RTRDISPLAY      = "http://www.bab-tec.de/eibPort:objects:RTRDisplay";
var OBJECT_TYPE_CAMERA          = "http://www.bab-tec.de/eibPort:objects:v2:Camera";
var OBJECT_TYPE_RSS_FEED        = "http://www.bab-tec.de/eibPort:objects:v2:RssFeed";
var OBJECT_TYPE_GRAPH           = "http://www.bab-tec.de/eibPort:objects:v2:Graph";
var OBJECT_TYPE_CONTAINER       = "http://www.bab-tec.de/eibPort:objects:Container";
var OBJECT_TYPE_WEBCONTAINER    = "http://www.bab-tec.de/eibPort:objects:WebContainer";

function VisuObject() {
  var visuPage;
  
  this.visible = false;
  this.disposed = true;
  
  this.id;
  this.type;
  this.version;
  
  this.layer;
  this.posX;
  this.posY;
  this.width;
  this.height;
  
  this.alpha;

  this.keepImageAspectRatio = true;
  
  this.shadowPainted = false;
  this.shadowHeight = "0.7";
  this.shadowScaled = false;

  this.setParent = function(parent) {
    visuPage = parent;
  };

  this.getParent = function() {
    return visuPage;
  };
}

var BG_IMAGE_VISIBLE_ALWAYS = 0;
var BG_IMAGE_VISIBLE_ON     = 1;
var BG_IMAGE_VISIBLE_OFF    = 2;
function BgImageObject() {
  this.imageKey;
  this.useExternalImage;
  this.externalUrl;
  this.externalRefresh;
  
  this.imgVisible = BG_IMAGE_VISIBLE_ALWAYS;

  this.address = new AddressObject(DATATYPE_EIS1);
}
BgImageObject.prototype = new VisuObject();

function PageLinkObject() {
  this.bgStyle = new BgStyle();
  this.objectFgStyle = new ObjectFgStyle();
  
  this.text;
  this.targetId;
}
PageLinkObject.prototype = new VisuObject();

var SHAPE_TYPE_RECTANGLE  = 0;
var SHAPE_TYPE_ROUNDRECT  = 1;
var SHAPE_TYPE_OVAL       = 2;
function ShapeObject() {
  
  this.bgStyle = new BgStyle();
  
  this.shapeType = SHAPE_TYPE_RECTANGLE;
  this.cornerRadius = 10;
  
  this.actionOnPress = new Array();
  this.actionOnRelease = new Array();
}
ShapeObject.prototype = new VisuObject();

function ColorChooser() {
  this.bgStyle = new BgStyle();
  
  this.addressRed = new AddressObject(DATATYPE_EIS14u);
  this.addressGreen = new AddressObject(DATATYPE_EIS14u);
  this.addressBlue = new AddressObject(DATATYPE_EIS14u);
  this.addressSubmit = new AddressObject(DATATYPE_EIS1);
}
ColorChooser.prototype = new VisuObject();

function LampObject() {
  this.bgStyle = new BgStyle();
  
  this.themeSetKey = 0;
  
  this.address = new AddressObject(DATATYPE_EIS1);
}
LampObject.prototype = new VisuObject();

function SwitchOnOffObject() {
  this.bgStyle = new BgStyle();
  
  this.themeSetKey = 0;
  
  this.address = new AddressObject(DATATYPE_EIS1);
}
SwitchOnOffObject.prototype = new VisuObject();

function SwitchDimObject() {
  this.bgStyle = new BgStyle();
  
  this.themeSetKey = 0;
  
  this.addressSwitch = new AddressObject(DATATYPE_EIS1);
  this.addressDim = new AddressObject(DATATYPE_EIS2);
}
SwitchDimObject.prototype = new VisuObject();

var SLIDER_ORIENTATION_VERTICAL = 0;
var SLIDER_ORIENTATION_HORIZONTAL = 1;
var SLIDER_UI_IMAGE = 0;
var SLIDER_UI_LINES = 1;
function SliderObject() {
  this.bgStyle = new BgStyle();
  
  this.themeSetKey = 0;
  
  this.address = new AddressObject(DATATYPE_EIS6);
  this.minValue = 0;
  this.maxValue = 100;
  this.orientation = 0;
  this.uiStyle = 0;
  this.colorMin = "#fff";
  this.colorMax = "#ff0";
  this.sliderColor = "#000";
  this.sliderWidth = 8;
}
SliderObject.prototype = new VisuObject();

var BUTTON_METHOD_TOGGLE = -1;
var BUTTON_METHOD_OFF = 0;
var BUTTON_METHOD_ON = 1;
var BUTTON_METHOD_PUSH_BUTTON_1 = 2;
var BUTTON_METHOD_PUSH_BUTTON_0 = 3;
function ButtonObject() {
  this.bgStyle = new BgStyle();
  
  this.themeSetKey = 0;
  
  this.address = new AddressObject(DATATYPE_EIS1);
  
  this.method = BUTTON_METHOD_TOGGLE;
}
ButtonObject.prototype = new VisuObject();

function ButtonEis14Object() {
  this.bgStyle = new BgStyle();
  
  this.themeSetKey = 0;
  
  this.address = new AddressObject(DATATYPE_EIS14u, -1);
  this.values = 0;
}
ButtonEis14Object.prototype = new VisuObject();

var STATIC_TEXT_HALIGN_LEFT = 0;
var STATIC_TEXT_HALIGN_CENTER = 1;
var STATIC_TEXT_HALIGN_RIGHT = 2;
function StaticTextObject() {
  this.objectFgStyle = new ObjectFgStyle();
  this.text;
  this.halign = STATIC_TEXT_HALIGN_LEFT;
}
StaticTextObject.prototype = new VisuObject();

function DynamicTextObject() {
  this.objectFgStyle0 = new ObjectFgStyle();
  this.text0;
  
  this.objectFgStyle1 = new ObjectFgStyle();
  this.text1;
  
  this.address = new AddressObject(DATATYPE_EIS1);
}
DynamicTextObject.prototype = new VisuObject();

function Eis15TextObject() {
  this.objectFgStyle = new ObjectFgStyle();
  
  this.text;
  this.address = new AddressObject(DATATYPE_EIS15);
}
Eis15TextObject.prototype = new VisuObject();

function Eis15DisplayObject() {
  this.bgStyle = new BgStyle();
  this.objectFgStyle = new ObjectFgStyle();
  
  this.text;
  this.address = new AddressObject(DATATYPE_EIS15);
  
  this.historyActive = true;
  this.historySize = 10;
  this.inputActive = true;
}
Eis15DisplayObject.prototype = new VisuObject();

function TelegramTimeObject() {
  this.objectFgStyle = new ObjectFgStyle();
  
  this.format;
  this.address = new AddressObject(DATATYPE_NONE);
}
TelegramTimeObject.prototype = new VisuObject();

var DATETIME_ORDER_DATE_TIME = 0;
var DATETIME_ORDER_TIME_DATE = 1;
var DATETIME_ORDER_DATE      = 2;
var DATETIME_ORDER_TIME      = 3;
function DateTimeObject() {
  this.objectFgStyle = new ObjectFgStyle();
  
  this.format = "";
  this.addressTime = new AddressObject(DATATYPE_EIS3);
  this.addressDate = new AddressObject(DATATYPE_EIS4);
  
  this.formatOrder = DATETIME_ORDER_DATE_TIME;
}
DateTimeObject.prototype = new VisuObject();

function AnalogTimeObject() {
  this.themeSetKey = 0;
  
  this.address = new AddressObject(DATATYPE_EIS3);
  this.address.latestValue = null;
  this.offset = 0;
}
AnalogTimeObject.prototype = new VisuObject();

function TempDisplayObject() {
  this.bgStyle = new BgStyle();
  this.objectFgStyle = new ObjectFgStyle();
  
  this.addressCurrent = new AddressObject(DATATYPE_EIS5);
  this.addressSetpoint = new AddressObject(DATATYPE_EIS5);
  
  this.textCurrent = null;
  this.textSetpoint = null;
}
TempDisplayObject.prototype = new VisuObject();

function TempControlObject() {
  this.bgStyle = new BgStyle();
  
  this.themeSetKey = 0;
  
  this.address = new AddressObject();
  this.stepWidth = 0.5;
  this.minValue = -40;
  this.maxValue = 40;
}
TempControlObject.prototype = new VisuObject();

function ValueDisplayObject() {
  this.bgStyle = new BgStyle();
  this.objectFgStyle = new ObjectFgStyle();
  
  this.address = new AddressObject();
  this.format = "##.#";
  this.factor = 1;
  this.offset = 0;
  this.sendValue = true;
  this.textAlign = 0;
  this.limitsActive = false;
  this.minValue = 0.0;
  this.maxValue = 100.0;
}
ValueDisplayObject.prototype = new VisuObject();

var TOP_CONSUMER_ITEM_COUNT           = 4;
var TOP_CONSUMER_DATA_SRC_CURRENT     = 0;
var TOP_CONSUMER_DATA_SRC_HISTORICAL  = 1;
function TopConsumerObject() {
  this.bgStyle = new BgStyle();
  this.objectFgStyle = new ObjectFgStyle();
  
  this.barColor = 0xff0000;
  this.dataSrc = TOP_CONSUMER_DATA_SRC_CURRENT;
  this.timespanMinutes = 15;  
  this.valueFormat = "0.0 kWh";
  
  this.items = new Array();
}
TopConsumerObject.prototype = new VisuObject();

function SeqButtonObject() {
  this.objectFgStyle = new ObjectFgStyle();
  
  this.defaultColor = 0xdddddd;
  this.defaultTitle = "?";
  this.delay = 2000;
  
  this.functions = new Array();
}
SeqButtonObject.prototype = new VisuObject();

function JalousieObject() {
  this.bgStyle = new BgStyle();
  
  this.themeSetKey = 0;
  
  this.addressMove = new AddressObject(DATATYPE_EIS1);
  this.addressStep = new AddressObject(DATATYPE_EIS1);
  this.addressWind = new AddressObject(DATATYPE_EIS1);
  
  this.invert = false;
}
JalousieObject.prototype = new VisuObject();

function DynJalousieObject() {
  this.bgStyle = new BgStyle();
  
  this.themeSetKey = 0;
  this.showPosition = true;
  this.showStep = true;
  
  this.addressMove = new AddressObject(DATATYPE_EIS1);
  this.addressStep = new AddressObject(DATATYPE_EIS1);
  this.addressWind = new AddressObject(DATATYPE_EIS1);
  this.addressPosition  = new AddressObject(DATATYPE_EIS6);
  this.addressAngle     = new AddressObject(DATATYPE_EIS6);
  
  this.invert = false;
}
DynJalousieObject.prototype = new VisuObject();

function WindowContactObject() {
  this.bgStyle          = new BgStyle();
  
  this.themeSetKey      = 0;
  this.mirrored         = false;
  this.typeEis14        = false;

  this.valueClosed      = 0;
  this.valueTilt        = 83;
  this.valueOpened      = 255;
  
  this.addressValue     = new AddressObject(DATATYPE_EIS14u);
  this.addressTilt      = new AddressObject(DATATYPE_EIS1);
  this.addressOpened    = new AddressObject(DATATYPE_EIS1);
  this.addressBroken    = new AddressObject(DATATYPE_EIS1);
  
  this.invertOpened     = false;
  this.invertTilt       = false;
  this.invertBroken     = false;
}
WindowContactObject.prototype = new VisuObject();

function RTRDisplayObject() {
  this.bgStyle          = new BgStyle();
  
  this.themeSetKey      = 0;

  this.typeEis14        = true;

  this.valueStandby     = 0;
  this.valueComfort     = 1;
  this.valueNightSetback= 2;
  this.valueAntifreeze  = 3;
  
  this.addressEis14             = new AddressObject(DATATYPE_EIS14u);
  this.addressStandbyComfort    = new AddressObject(DATATYPE_EIS1);
  this.addressNightSetback      = new AddressObject(DATATYPE_EIS1);
  this.addressAntifreeze        = new AddressObject(DATATYPE_EIS1);
}
RTRDisplayObject.prototype = new VisuObject();

function CameraObject() {
  this.bgStyle = new BgStyle();
  
  this.themeSetKey = 0;
  
  this.staticUrl;
  this.iconify;

  this.authentication = "none";
  this.authUsername = "";
  this.authPassword = "";
}
CameraObject.prototype = new VisuObject();

function RssFeedObject() {
  this.objectFgStyle = new ObjectFgStyle();
  
  this.url;
  this.speed;
  this.refresh;
}
RssFeedObject.prototype = new VisuObject();

function GraphObject() {
  this.bgStyle = new BgStyle();
  
  this.traces = new Array();
}
GraphObject.prototype = new VisuObject();

function ContainerObject(){
  this.embeddedPageId = -1;
  this.visiblePages = 1;
  this.fadeOffArea = 0;
  this.returnTime = 0;
    this.returnOnPageChange = true;
}
ContainerObject.prototype = new VisuObject();

var WEB_CONTAINER_TYPE_URL = 0;
var WEB_CONTAINER_TYPE_HTML = 1;
function WebContainerObject(){
  this.web_type = WEB_CONTAINER_TYPE_URL;
  this.url = "http://";
  this.html = "";
	this.refresh = 5;
}
WebContainerObject.prototype = new VisuObject();

function ObjectFgStyle() {
  this.key = "";
  this.autoFontScaling = true;
  this.ignoreStyle = false;
  this.color = "#fff";
}

function Action() {
  this.execute = function() {
    switch(this.type) {
      case Action.TYPE_PAGE_LINK:
        openPage(this.pageId);
        break;
      case Action.TYPE_PAGE_HISTORY:
        if(this.action == 0) {
          openPrevPage();
        } else {
          openNextPage();
        }
        break;
      case Action.TYPE_PAGE_FLIP:
        var page = currentProject.getPageById(this.targetId);
        if(page != null) {
          page.flipToSegment(this.segment, this.animated);
        }
        break;
      case Action.TYPE_PAGE_POPUP:
        var page = currentProject.getPageById(this.targetId);
        if(page != null) {
          VC.showPopupPage(page);
        }
        break;
      case Action.TYPE_OPEN_URL:
        window.open(this.url);
        break;
      case Action.TYPE_HTTP_REQUEST:
        $.ajax({
          url: "/web.visu/tools/xmlProxy.jsp",
          data: "url="+escape(this.url)
        });
        break;
      case Action.TYPE_SEND_TELEGRAM:
        //alert("sendTelegram " + this.address + " :: " + this.dataType + " :: " + this.valueEis1 + " :: " + this.value);
        if(this.dataType == DATATYPE_EIS1) {
          if(this.valueEis1 == BUTTON_METHOD_TOGGLE) {
            this.addressObject.submitNewValue(1 - this.addressObject.latestValue);
          } else {
            this.addressObject.submitNewValue(this.valueEis1);
          }
        } else {
          this.addressObject.submitNewValue(this.value);
        }
        break;
    }
  };
};
Action.TYPE_UNKNOWN       = "";
Action.TYPE_PAGE_LINK     = "page.link";
Action.TYPE_PAGE_HISTORY  = "page.history";
Action.TYPE_PAGE_FLIP     = "page.flip";
Action.TYPE_PAGE_POPUP    = "page.popup";
Action.TYPE_HTTP_REQUEST  = "http_request";
Action.TYPE_OPEN_URL      = "open.url";
Action.TYPE_SEND_TELEGRAM = "send.telegram";

