﻿/* dialogbox.js */

function DialogBox(title, content) {
    DialogBox.idCount += 1;

    title = title || 'Please correct the following:';

    this.frame = document.createElement('div');
    this.frame.setAttribute('id', 'dialogbox_frame_' + DialogBox.idCount);
    this.frame.setAttribute('class', 'dialogbox_frame');
    //this.frame.style.position = 'relative';
    //this.frame.style.top = '520px';
    this.frame.style.left = '-50px';
    this.frame.style.width = '180px';
    //this.frame.style.height = '200px';
    this.frame.style.border = '1px solid #880011';
    this.frame.style.zIndex = '110';
    this.frame.style.background = '#ff3300';
    this.frame.style.overflow = 'hidden';
    this.frame.style.fontFamily = 'Verdana, sans-serif';
    this.titlebar = document.createElement('div');
    this.titlebar.setAttribute('class', 'dialogbox_titlebar');
    this.titlebar.setAttribute('title', title);
    this.titlebar.style.height = '15px';
    this.titlebar.style.width = '100%';
    this.titlebar.style.color = 'white';
    this.titlebar.style.fontWeight = 'bold';
    this.titlebar.style.fontSize = '10px';
    this.titlebar.style.backgroundColor = '#880011';
    this.titlebar.style.padding = '5px 10px';
    this.titlebar.appendChild(document.createElement('p'))
                 .innerHTML = title;
    this.contentArea = document.createElement('div');
    this.contentArea.setAttribute('class', 'dialogbox_contentArea');
    this.contentArea.style.marginTop = '0px';
    this.contentArea.style.zIndex = '120';
    this.contentArea.style.padding = '5px';
    this.contentArea.style.width = '100%';
    this.contentArea.style.height = '100%';
    this.contentArea.style.textAlign = 'left';
    this.contentArea.style.verticalAlign = 'top';
    this.contentArea.style.color = 'white';
    this.contentArea.style.fontSize = '10px';
    this.contentArea.appendChild(document.createElement('p')).innerHTML = content;
    this.frame.appendChild(this.titlebar);
    this.frame.appendChild(this.contentArea);
}


DialogBox.prototype.show = function(x, y, width, height) {
    var submitbtn = document.getElementById('submitButton');
    document.getElementById('col1').insertBefore(this.frame, submitbtn);
    submitbtn.style.marginTop = '5px';
    submitbtn.style.padding = '0px';
}


DialogBox.prototype.hide = function() {
    this.frame.style.display = 'none';
}

DialogBox.prototype.close = function() {
    this.frame = null;
    this.titlebar = null;
    this.contentArea = null;
}


// class method
DialogBox.getStyleValue = function(styleValue) {
    return styleValue.slice(1, -2);
}


DialogBox.prototype.init = function() {

}


// from http://www.quirksmode.org/js/findpos.html
// gets absolute position of an element
function getAbsPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft, curtop];
}



