//---------------------------------------------------------
// Copyright (c) 2004 to present by Bronze Inc. All rights reserved.
// 352-327-3672, Box 14303, Gainesville, FL, 32604, US
// www.programmer.bz, publish@bronz.com
//---------------------------------------------------------
function br_page_Class() {
    this.ahref_style = "";
    this.button_after = "";
    this.root_ahref = "";
    this.button_before = "";
    this.iframe_count = 0;
    this.images = [];
    this.root_domain = "";
    this.root_image = "";
    this.Ahref = br_page_Ahref;
    this.Amap = br_page_Amap;
    this.Attribute_Set = br_page_Attribute_Set;
    this.Attributes = br_page_Attributes;    
    this.Button = br_page_Button;
    this.Button_Rollover = br_page_Button_Rollover;
    this.Email = br_page_Email;
    this.Form_Attribute = br_page_Form_Attribute;
    this.Form_Checkbox_All = br_page_Form_Checkbox_All;
    this.Forms_Attribute = br_page_Forms_Attribute;
    this.Forms_Attribute_All = br_page_Forms_Attribute_All;
    this.Href = br_page_Href;
    this.Iframe = br_page_Iframe;
    this.Iframe_Fixed = br_page_Iframe_Fixed;
    this.Image_Load = br_page_Image_Load;
    this.Image_Set = br_page_Image_Set;
    this.Image_Src = br_page_Image_Src;
    this.Page_Bottom = br_page_0;
    this.Page_Top = br_page_0;
}
//---------------------------------------------------------
function br_page_0() { }
//---------------------------------------------------------
function br_page_Ahref(p, asis) {
    p = this.Href(p, asis); p = '<' + 'a ' + p; return p;
}
//---------------------------------------------------------
function br_page_Amap(c, p, t, a) {
    a = a || t;
    p = this.Href(p);
    var out = ''
    + '<' + 'area shape="rect" coords="' + c + '" ' + p
    + '" title="' + t + '" alt="' + a + '">'
    ;
    return out;
}
//---------------------------------------------------------
function br_page_Attribute_Set(item, attribute, value) {
    var newattribute = document.createAttribute(attribute);
    newattribute.value = value;
    item.attributes.setNamedItem(newattribute);
}
//---------------------------------------------------------
// Args:
//   format = 0=line; 1=table; 
// Display attributes for debugging
function br_page_Attributes(attributes, format) {
    //attributes = document.forms.item(0).attributes; // For editing in Visual Studio Intellisense
    var out = "";
    if (!attributes) return out;
    var sep1 = sep1 || "<br />"; // Or <tr><td>
    var sep2 = sep2 || ":"; // </td><td>
    var sep3 = sep3 || ""; // </td></tr>
    if (format) {
        sep1 = "<tr><td>";
        sep2 = "</td><td>";
        sep3 = "</td></tr>";        
    }
    var n = attributes.length;
    for (var i = 0; i < n; i++)
    {
        var attribute = attributes.item(i);
        var aname = attribute.nodeName;
        var atype = attribute.nodeType;
        var avalue = attribute.nodeValue;
        out += sep1 + "attribute " + i
            + sep2 + "name=" + aname
            + "; type=" + atype
            + "; value=" + avalue
            + sep3;
    }
    if (out && format) out = '<table border="1" cellpadding="3" cellspacing="0">' + out + '</table>';
    return out;
}
//---------------------------------------------------------
function br_page_Button(t, p, asis, x) {
    p = this.Ahref(p, asis); t = p + '>' + t + '<' + '/a>';
    if (this.button_before) t = this.button_before + t;
    if (this.button_after) t += this.button_after;
    return t;
}
//---------------------------------------------------------
function br_page_Button_Rollover(p, asis, i1, i2, w, h, alt) {
    if (alt) alt = ' alt="' + alt + '"'; else alt = '';
    if (h) h = ' height="' + h + '"'; else h = '';
    if (w) w = ' width="' + w + '"'; else w = '';
    p = this.Ahref(p, asis);
    p += ' onMouseOut=\'br_page.ImageSet("' + i1 + '")\''
    + ' onMouseOver=\'br_page.ImageSet("' + i1 + '","' + i2 + '")\''
    + '>';
    p += '<img name="' + i1 + '" src="' + this.images[i1].src
    + w + h + alt + '" border="0"></a>';
    if (this.button_before) p = this.button_before + p;
    if (this.button_after) p += this.button_after;
    return p;
}
//---------------------------------------------------------
// Username, Domain, Text, Class
function br_page_Email(u, d, t, c) {
  var ud=u + '@' + d; if (!t) t=ud;
  if (!c) c=""; else c=' class="' + c + '"';
  var out='<a ' + c + ' href="mai'  + 'lto' + ':' + ud + '">' + t + '</a>';
  document.write(out);
  }
//---------------------------------------------------------
// Change attribute on a specific form
function br_page_Form_Attribute(formname, attribute, value) {
    if (!formname) return;
    var frm = document.forms[formname];
    if (!frm) return;
    this.Attribute_Set(frm, attribute, value);
}
//---------------------------------------------------------
function br_page_Form_Checkbox_All(formname, name, what) {
    var x;
    var frm = document.forms[formname];
    if (!frm) return;
    var ele = frm.elements;
    var n = ele.length;
    for (var i = 0; i < n; i++) { x = ele[i]; if (x.name == name) x.checked = what; }
    return false;
}
//---------------------------------------------------------
// Args:
//   value - value to use or an delimited string of values to use for each form in a row
//     if there are more forms than values, stop at the last value
//   sep - for delimiter of values, defaults to comma (|)
// Change same attribute on forms
function br_page_Forms_Attribute(attribute, value, sep) {
    if (!attribute) return;
    sep = sep || "|";
    value = value || "";
    var values = value.toString().split(sep); // Get array of values to set to each form in a row
    var s = values.length; // Number of values
    var forms = document.forms;
    var n = forms.length;
    for (var i = 0; ((i < n) && (i < s)); i++)
        this.Attribute_Set(forms[i], attribute, values[i]);
}
//---------------------------------------------------------
// Args:
//   value - value to use
// Change same attribute on all forms
function br_page_Forms_Attribute_All(attribute, value) {
    if (!attribute) return;
    value = value || "";
    var forms = document.forms;
    var n = document.forms.length;
    for (var i = 0; i < n; i++)
        this.Attribute_Set(forms[i], attribute, value);
}
//---------------------------------------------------------
function br_page_Href(p, asis) {
    asis = asis || "";
    if (asis != "ASIS") {
        var p1 = "";
        if (this.root_domain) p1 += 'http://' + this.root_domain;
        p = p1 + this.root_ahref + p;
    }
    p = 'href="' + p + '"'
    if (this.ahref_style) p += ' class="' + this.ahref_style + '"';
    return p;
}
//---------------------------------------------------------
// Automatically resizes iframe to scroll height to fit contents.
// If your page and the page contained inside the iframe are on different domains,
// to allow your function to execute, add this code to the page contained in the iframe,
// where domainoriginal is the domain name of the page containing the iframe.
//
// <script type="text/javascript">
// document.domain=domainoriginal;
// </script>
function br_page_Iframe(src, iclass, istyle, id) {
    if (!id) id = 'br_iframe_' + this.iframe_count++;
    var iid = ' id="' + id + '"';
    var iname = ' name="' + id + '"';
    if (!iclass) iclass = '';
    else iclass = ' class="' + iclass + '"';
    if (!istyle) istyle = '';
    else istyle = ' style="' + istyle;
    var onload = ' onload="this.style.height=' + id + '.document.body.scrollHeight + 20;"';
    //var out = '<iframe frameborder="0" height="0" marginheight="0" marginwidth="0" scrolling="no" width="100%"'
    var out = '<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" width="100%"'
      + iid
      + iname
      + onload
      + iclass
      + istyle
      + ' src="' + src + '"'
      + '></iframe>';
    document.write(out);
}
//---------------------------------------------------------
function br_page_Iframe_Fixed(src, height, width) {
    var out = '<iframe marginheight="0"'
      + ' src="' + src + '"'
      + ' frameborder="0" marginwidth="0" scrolling="no"'
      + ' style="padding:0px; height:' + height
      + '; width:' + width
      + ';"></iframe>';
    document.write(out);
}
//---------------------------------------------------------
// name,image,name,image
function br_page_Image_Load(images) {
    var s = br_page.images.length;
    var a = images.split(','); var n = a.length + s; var i, x, y;
    for (i = s; i < n; i = i + 2) {
        x = a[i]; y = a[i + 1];
        this.images[x] = new Image();
        this.images[x].src = y;
    }
}
//---------------------------------------------------------
// name,image,name,image
function br_page_Image_Set(name, image) {
    image = image || name;
    document.images[name].src = this.images[image].src;
}
//---------------------------------------------------------
function br_page_Image_Src(v, p) {
    var out = this.root_domain + this.root_image + v;
    if (p == "FILE") return out;
    return '<img src="http://' + out + '"';
}
//---------------------------------------------------------
var br_page = new br_page_Class;
//---------------------------------------------------------

