
function Frame(id,name,width,price,style,finish,material, src) { 
  this.id = id ? id : 0;
  this.name = name ? name : "";
  this.src = src ? src : "";
  this.width = width ? width : 0;
  this.price = price ? price : 0.0;
  this.style = style ? style : "";
  this.finish = finish ? finish : "";
  this.material = material ? material : "";
}

function Art(id,item_number,height,width,price,art_path) {
  this.id = id ? id : '';
  this.item_number = item_number ? item_number : "test art";
  this.height = height ? height : 14.5;
  this.width = width ? width : 6.25;
  this.price = price ? price : 0.0;
  this.art_path = art_path ? art_path : "images/def_img.gif";
}

function Mat(id, color, texture, name, price) {
  this.id = id ? id : 0;
  this.color = color ? color : "";
  this.texture = texture ? texture : "";
  this.name =  name ? name : "";
  this.price = price ? price : 0.0;
}

function Glass(id, name, price) {
  this.id = id ? id : 0;
  this.name =  name ? name : "";
  this.price = price ? price : 0.0;
}

function createWindowManagerInstance() {
  windowManager = new WindowManager();
  window.onunload = closeCreatedWindowManager;
}
function closeCreatedWindowManager() {
  windowManager.closeAll();
}

function WindowManager() {
  this.addWindow = wm_addWindow;
  this.focusAll = wm_focusAll;
  this.closeAll = wm_closeAll;
  this.showWindow = wm_showWindow;
  this.removeWindow = wm_removeWindow;
  this.windows = new Array();
  this.calculatePositions = wm_calculatePositions;
  // For showing position
  this.posCorner = 1;
  this.posIncrementPx = 20;
  this.left = 0;
  this.top = 0;
}
function wm_addWindow(wnd) {
  this.windows[this.windows.length]=wnd;
}
function wm_showWindow(url) {
  this.calculatePositions();
  var wnd = window.open(url + "&title=Compare&compare=1",'',"status=no,width="+CANVAS_WINDOW_W+",height="+CANVAS_WINDOW_H+",top="+this.top+",left="+this.left);
  this.addWindow(wnd);
  this.focusAll();
}
function wm_calculatePositions() {
  if(this.posCorner == 1) {
    this.left = window.screen.availWidth - CANVAS_WINDOW_W - this.posIncrementPx;
    this.top = this.posIncrementPx;
  }
  else if(this.posCorner == 2) {
    this.left = window.screen.availWidth - CANVAS_WINDOW_W - this.posIncrementPx;
    this.top = window.screen.availHeight - CANVAS_WINDOW_H - this.posIncrementPx;
  }
  else if(this.posCorner == 3) {
    this.left = this.posIncrementPx;
    this.top = window.screen.availHeight - CANVAS_WINDOW_H - this.posIncrementPx;
  }
  else if(this.posCorner == 4) {
    this.left = this.posIncrementPx;
    this.top = this.posIncrementPx;
  }
  this.posIncrementPx = this.posCorner == 4 ? this.posIncrementPx + 20 : this.posIncrementPx;
  this.posCorner = this.posCorner == 4 ? 1 : this.posCorner + 1;
  this.posIncrementPx = this.posIncrementPx == 100 ? 20 : this.posIncrementPx;
  return [this.left, this.top];
}
function wm_focusAll() {
  for(var i=0; i < this.windows.length; i++) {
    if(this.windows[i])
      this.windows[i].focus();
  }
}
function wm_closeAll() {
  for(var i=0; i < this.windows.length; i++) {
    if(this.windows[i])
      this.windows[i].close();
  }
}

function wm_removeWindow(window) {
  for(var i=0; i < this.windows.length; i++) {
    if(this.windows[i]==window) {
      this.windows[i] = null;
    } 
  }
}
