﻿// JScript File

//alert("Common.js");

// a class to hold all the common functions and data
function Common(){}




// additional classes
function Location(x, y){
    if(x == null) x = 0;
    if(y == null) y = 0;
    this.x = x;
    this.y = y;
}

function Size(width, height){
    if(width == null) width = 0;
    if(height == null) height = 0;
    this.width = width;
    this.height = height;
}

function Rectangle(x, y, width, height){
    if(x.x != null && y.width != null){// they are passing in location and size
        this.location = x;
        this.size = y;
    }else{
        this.location = new Location(x, y);
        this.size = new Size(width, height);        
    }
}


function DivController(element){
    this.size = new Size(0, 0);
    this.location = new Location(0, 0);
    if(element != null && element.style != null){
        this.element = element;
        this.attached = true;
    }else{
        this.attached = false;
    }
}
// Location
DivController.prototype.updateX = function(){
    if(this.attached){ this.element.style.left = this.location.x + "px"; }
}
DivController.prototype.updateY = function(){
    if(this.attached){ this.element.style.top = this.location.y + "px"; }
}
DivController.prototype.setX = function(x){
    this.location.x = x;
    this.updateX();
}
DivController.prototype.setY = function(y){
    this.location.y = y;
    this.updateY();
}
DivController.prototype.setLocation = function(x, y){
    if(x.x != null){    // they are passing a Location object
        this.location.x = x.x;
        this.location.y = x.y;
    }else{  // they are passing in x and y values
        this.location.x = x;
        this.location.y = y;
    }
    this.updateX();
    this.updateY();
}
// Size
DivController.prototype.updateWidth = function(){
    if(this.attached){ this.element.style.width = this.size.width + "px"; }
}
DivController.prototype.updateHeight = function(){
    if(this.attached){ this.element.style.height = this.size.height + "px"; }
}
DivController.prototype.setWidth = function(width){
    this.size.width = width;
    this.updateWidth();
}
DivController.prototype.setHeight = function(height){
    this.size.height = height;
    this.updateHeight();
}
DivController.prototype.setSize = function(width, height){
    if(width.width != null){    // they are passing a Size object
        this.size.width = width.width;
        this.size.height = width.height;
    }else{  // they are passing in width and height values
        this.size.width = width;
        this.size.height = height;
    }
    this.updateWidth();
    this.updateHeight();
}
DivController.prototype.getX = function(){ return this.location.x; }
DivController.prototype.getX2 = function(){ return this.location.x + this.size.width; }
DivController.prototype.getY = function(){ return this.location.y; }
DivController.prototype.getY2 = function(){ return this.location.y + this.size.height; }
DivController.prototype.getWidth = function(){ return this.size.width; }
DivController.prototype.getHeight = function(){ return this.size.height; }
DivController.prototype.hide = function(){
    if(this.attached){ this.element.style.visibility = "hidden"; }
}
DivController.prototype.show = function(){
    if(this.attached){ this.element.style.visibility = "visible"; }
}
