//*********************************
//
// drop down variables
//
//*********************************
//timezones
var timezones = [["Eniwetok (GMT-12)", "-12"], ["Samoa (GMT-11)", "-11"], ["Hawaii (GMT-10)", "-10"], ["Alaska (GMT-9)", "-9"], ["PST, Pacific US (GMT-8)", "-8"], ["MST, Mountain US (GMT-7)", "-7"], ["CST, Central US (GMT-6)", "-6"], ["EST, Eastern US (GMT-5)", "-5"], ["Atlantic, Canada (GMT-4)", "-4"], ["Brazilia, Buenos Aries (GMT-3)", "-3"], ["Mid-Atlantic (GMT-2)", "-2"], ["Cape Verdes (GMT-1)", "-1"], ["Greenwich (GMT)", "0"], ["Berlin, Rome (GMT+1)", "1"], ["Israel, Cairo (GMT+2)", "2"], ["Moscow, Kuwait (GMT+3)", "3"], ["Abu Dhhabi, Muscat (GMT+4)", "4"], ["Islamabad, Karachi (GMT+5)", "5"], ["Almaty, Dhaka (GMT+6)", "6"], ["Banngkok, Jakarta (GMT+7)", "7"], ["Hong Kong, Beijing (GMT+8)", "8"], ["Tokyo, Osaka (GMT+9)", "9"], ["Sydney, Melbourne, Guam (GMT+10)", "10"], ["Magadan, Solomon Is. (GMT+11)", "11"], ["Fiji, Wellington, Auckland (GMT+12)", "12"]];
//permission levels
var permissions = [["Admin", "admin"], ["Creator", "creator"], ["Updater", "updater"], ["Viewer", "viewer"]];
//months
var months = [["January (01)", 1], ["February (02)", 2], ["March (03)", 3], ["April (04)", 4], ["May (05)", 5], ["June (06)", 6], ["July (07)", 7], ["August (08)", 8], ["September (09)", 9], ["October (10)", 10], ["November (11)", 11], ["December (12)", 12]];
//status
var statuses = [["active", "ACTIVE"], ["paused", "PAUSED"], ["deleted", "DELETED"]];
//adult content
var adultContent = [["No", "0"], ["Yes", "1"]];
//credit card years
var y = new Date();
var creditYears = new Array();
for (var i = 0; i < 15; i++) {
    var e = new Array();
    var tempYear = y.getFullYear();
    e[0] = tempYear + i;
    e[1] = tempYear + i;
    creditYears.push(e);
}
//credit card types
var cardType = [["Visa", "visa"], ["MasterCard", "master"], ["Discover", "discover"], ["American Express", "american_express"]/*, ["Test Card", "bogus"]*/];
//media types
var mediaType = [["Image", "IMAGE"], ["Video", "VIDEO"]];
//keyword match tpe
var keywordMT = [["Broad", "BROAD"], ["Phrase", "PHRASE"], ["Exact", "EXACT"], ["Negative", "NEGATIVE"]];
//states
var states = [["Alabama", "AL"], ["Alaska", "AK"], ["Arizona", "AZ"], ["Arkansas", "AR"], ["California", "CA"], ["Colorado", "CO"], ["Connecticut", "CT"], ["Delaware", "DE"], ["District of Columbia", "DC"], ["Florida", "FL"], ["Georgia", "GA"], ["Hawaii", "HI"], ["Idaho", "ID"], ["Illinois", "IL"], ["Indiana", "IN"], ["Iowa", "IA"], ["Kansas", "KS"], ["Kentucky", "KY"], ["Louisiana", "LA"], ["Maine", "ME"], ["Maryland", "MD"], ["Massachusetts", "MA"], ["Michigan", "MI"], ["Minnesota", "MN"], ["Mississippi", "MS"], ["Missouri", "MO"], ["Montana", "MT"], ["Nebraska", "NE"], ["Nevada", "NV"], ["New Hampshire", "NH"], ["New Jersey", "NJ"], ["New Mexico", "NM"], ["New York", "NY"], ["North Carolina", "NC"], ["North Dakota", "ND"], ["Ohio", "OH"], ["Oklahoma", "OK"], ["Oregon", "OR"], ["Pennsylvania", "PA"], ["Rhode Island", "RI"], ["South Carolina", "SC"], ["South Dakota", "SD"], ["Tennessee", "TN"], ["Texas", "TX"], ["Utah", "UT"], ["Vermont", "VT"], ["Virginia", "VA"], ["Washington", "WA"], ["West Virginia", "WV"], ["Wisconsin", "WI"], ["Wyoming", "WY"]/*,["Alberta","AB"],["British Columbia","BC"],["Manitoba","MB"],["New Brunswick","NB"],["Newfoundland Labrdor","NL"],["Northwest Territories","NT"],["Nova Scotia","NS"],["Nunavut","NU"],["Ontario","ON"],["Prince Edward Island","PE"],["Quebec","QC"],["Saskatchewan","SK"],["Yukon","YT"],["American Samoa","AS"],["Federated States of Micronesia","FM"],["Guam","GU"],["Marshall Islands","MH"],["Northern Mariana Islands","MP"],["Palau","PW"],["Puerto Rico","PR"],["Virgin Islands","VI"],["Carlow","CARLO"],["CAVAN","CAVAN"],["Clare","CLARE"],["Cork","CORK"],["Donegal","DONEG"],["Dublin","DUBLI"],["Galway","GALWA"],["Kerry","KERRY"],["Kildore","KILDA"],["Kilkenny","KILKE"],["Laois","LAOIS"],["Leitrim","LEITR"],["Limerick","LIMER"],["Longford","LONGF"],["Louth","LOUTH"],["Mayo","MAYO"],["Meath","MEATH"],["Monaghan","MONAG"],["Offaly","OFFAL"],["Roscommon","ROSCO"],["Sligo","SLIGO"],["Tipperary","TIPPE"],["Waterford","WATER"],["Westmeath","WESTM"],["Wexford","WEXFO"],["Wicklow","WICKL"],["Other","OTHER"]*/];
//time
var timeStamps = [["12 am", "0"], ["1 am", "1"], ["2 am", "2"], ["3 am", "3"], ["4 am", "4"], ["5 am", "5"], ["6 am", "6"], ["7 am", "7"], ["8 am", "8"], ["9 am", "9"], ["10 am", "10"], ["11 am", "11"], ["12 pm", "12"], ["1 pm", "13"], ["2 pm", "14"], ["3 pm", "15"], ["4 pm", "16"], ["5 pm", "17"], ["6 pm", "18"], ["7 pm", "19"], ["8 pm", "20"], ["9 pm", "21"], ["10 pm", "22"], ["11 pm", "23"]];
//accounts to export to
var externalAccounts = [["Google", "google"], ["Yahoo!", "yahoo"]];
//types of site
var sitePrefixType = [["http://", "http://"], ["https://", "https://"]];
//types of date ranges
var dateRangeType = [["Summary", "summary"], ["Daily", "daily"], //["Day of Week - Sun to Mon","dayofweek-sm"],
//["Day of Week - Mon to Tues","dayofweek-mt"],
//["Day of Week - Tues to Wed","dayofweek-tw"],
//["Day of Week - Wed to Thur","dayofweek-wt"],
//["Day of Week - Thur to Fri","dayofweek-tf"],
//["Day of Week - Fri to Sat","dayofweek-fs"],
//["Day of Week - Sat to Sun","dayofweek-ss"],
["Weekly", "weekly"], ["Monthly", "monthly"], ["Quarterly", "quarterly"], ["Yearly", "yearly"]];
//report scheduling
var reportScheduling = [["every day", "everyday"], ["every monday", "everymonday"], ["first day of the month", "firstdayofthemonth"]];
//chart choices
var chartChoicesArray = [["Impressions", "IMP"], ["Clicks", "CLK"], ["CTR", "CTR"], ["Average CPC", "aCPC"], ["CPC Cost", "pCST"], ["CPM Cost", "mCST"], ["Total Cost", "tCST"], ["Average Position", "aPOS"]];
//*********************************
//
// list of used campaigns
// -this function is called in the "createAccountTree" function in the account_tab.js
// -this function receives information on the current set of campaings. Whenever there
// is an update to the tree the campaigns sitewide are updated through this function
//
//*********************************
function updateAccountTreeList(obj){
    //write other functions
    //mediaFilterCreate(obj);
    //contactFilterCreate(obj);
    //billingChartOption(obj);
    //writeExternalAccountsFilter(obj);
    createCampaignArray(obj);
    //createAdgroupArray(obj);
    createReportTemplate();
}

//*********************************
//
// write notices
//
//*********************************
function pagingFooter(start, count, total, f, id){
    var div = document.createElement("div");
    var table = document.createElement("table");
    var tbody = document.createElement("tbody");
    var tr = document.createElement("tr");
    var td1 = document.createElement("td");
    var td2 = document.createElement("td");
    var td3 = document.createElement("td");
    var td4 = document.createElement("td");
    div.appendChild(table);
    table.appendChild(tbody);
    tbody.appendChild(tr);
    tr.appendChild(td1);
    tr.appendChild(td2);
    tr.appendChild(td3);
    tr.appendChild(td4);
    if (start > 0) {
        var a = document.createElement("a");
        a.href = "javascript:" + f + "(" + id + "," + 0 + "," + count + ");";
        a.appendChild(document.createTextNode("First"));
        td1.appendChild(a);
    }
    else {
        td1.appendChild(document.createTextNode(" "));
    }
    if (start > 0) {
        var a = document.createElement("a");
        a.href = "javascript:" + f + "(" + id + "," + (start - count) + "," + count + ");";
        a.appendChild(document.createTextNode("Prev"));
        td2.appendChild(a);
    }
    else {
        td2.appendChild(document.createTextNode(" "));
    }
    if (start < total) {
        var a = document.createElement("a");
        a.href = "javascript:" + f + "(" + id + "," + (start + count) + "," + count + ");";
        a.appendChild(document.createTextNode("Next"));
        td3.appendChild(a);
    }
    else {
        td3.appendChild(document.createTextNode(" "));
    }
    if ((start - count) < total) {
        var a = document.createElement("a");
        a.href = "javascript:" + f + "(" + id + "," + (total - count) + "," + count + ");";
        a.appendChild(document.createTextNode("Last"));
        td4.appendChild(a);
    }
    else {
        td4.appendChild(document.createTextNode(" "));
    }
    return div;
}

//*********************************
//
// write notices
//
//*********************************
function writeNotices(obj){
    var mainDiv = removeElement("account_notifications", "account_notifications_content");
    var div = document.createElement("div");
    div.id = "account_notifications_content";
    var loop = obj.data.length;
    for (var i = 0; i < loop; i++) {
        var newDiv = document.createElement("div");
        if (obj.data[i].header) {
            var newHeader = document.createElement("h1");
            newHeader.appendChild(document.createTextNode(obj.data[i].header));
            newDiv.appendChild(newHeader);
        }
        if (obj.data[i].paragraph) {
            var newParagraph = document.createElement("p");
            newParagraph.appendChild(document.createTextNode(obj.data[i].paragraph));
            newDiv.appendChild(newParagraph);
        }
        if (obj.data[i].url) {
            var newLink = document.createElement("a");
            newLink.href = obj.data[i].url;
            newLink.target = "_blank";
            newLink.appendChild(document.createTextNode("More Information At: " + obj.data[i].url));
            newDiv.appendChild(newLink);
        }
        div.appendChild(newDiv);
    }
    mainDiv.appendChild(div);
}

//*********************************
//
// add tool tip
//
//*********************************
function addToolTip(divID, attach, e){
    var contentDiv = document.createElement("div");
    var tooltipspan = document.createElement("span");
    tooltipspan.className = "tooltip_div";
    tooltipspan.id = divID;
    var e = (e) ? e : 10;
    tooltipspan.style.right = e + "px";
    var tooltipicon = document.createElement("img");
    tooltipicon.src = "/images/icons/questionmark.gif";
    tooltipspan.appendChild(tooltipicon);
    contentDiv.appendChild(tooltipspan);
    contentDiv.appendChild(attach);
    return contentDiv;
}

//*********************************
//
// show error from server
//
//*********************************
function serverError(message){
    switch (message) {
        case "You are logged out":
            window.location = "/";
            break;
        case "You are logged out.":
            window.location = "/";
            break;
    }
    alert(message);
    
}

//*********************************
//
// create campaign array
//
//*********************************
function createCampaignArray(obj){
    var loop = obj.account.campaigns.length;
    generalCampaignArray = new Array();
    for (var i = 0; i < loop; i++) {
        var e = new Array();
        e[0] = obj.account.campaigns[i].name;
        e[1] = obj.account.campaigns[i].id;
        generalCampaignArray.push(e);
    }
}

//*********************************
//
// update flash
//
//*********************************
function updateFlash(){
    var div = document.createElement("div");
    var p = document.createElement("p");
    p.appendChild(document.createTextNode("This content requires the Adobe Flash Player."));
    var a = document.createElement("a");
    a.href = "http://www.adobe.com/go/getflash/";
    a.appendChild(document.createTextNode(" Download Here."));
    a.target = "_blank";
    p.appendChild(a);
    div.appendChild(p);
    ;
    return div;
}

//*********************************
//
// get url parameter
//
//*********************************
function getURLParam(name){
    var name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null) 
        return "";
    else 
        return results[1];
}

//*********************************
//
// removes a child element from the parent
//
//*********************************
function removeElement(parent, child){
    if (dojo.byId(parent)) {
        var parentDiv = dojo.byId(parent);
        if (dojo.byId(child)) {
            purge(dojo.byId(child));
            parentDiv.removeChild(dojo.byId(child));
        }
        return parentDiv;
    }
    else {
        var div = document.createElement("div");
        div.id = parent;
        return div;
    }
}

function removeWidget(widget){
    if (dojo.widget.byId(widget)) {
        dojo.widget.byId(widget).destroyChildren();
        dojo.widget.byId(widget).destroy();
    }
}

function purge(d){
    var a = d.attributes, i, l, n;
    if (a) {
        l = a.length;
        for (i = 0; i < l; i += 1) {
            n = a[i].name;
            if (typeof d[n] === 'function') {
                d[n] = null;
            }
        }
    }
    a = d.childNodes;
    if (a) {
        l = a.length;
        for (i = 0; i < l; i += 1) {
            purge(d.childNodes[i]);
        }
    }
}

//*********************************
//
// adds a script call for the callback features
//
//*********************************
function addScript(url){
    var script = document.createElement('script');
    script.src = url;
    document.body.appendChild(script);
}

//*********************************
//
// for html and inner htmls. Adds the divs needed to make the pretty wrapper box (2 parts)
//
//*********************************
function addBoxTop(){
    var output = "<div class='box_left'><div class='box_right'><div class='box_top'><div class='box_top_left'></div><div class='box_top_right'></div></div><div class='box_middle'><div class='content'>";
    return output;
}

function addBoxBottom(){
    var output = "</div></div></div><div class='box_bottom'><div class='box_bottom_left'></div><div class='box_bottom_right'></div></div></div>";
    return output;
}

//*********************************
//
// For dynamically created pieces. Attaches the element 'toAttach'
// to the content area of the div, and then attaches the box and
// it's contents to the 'attachTo' element choosen.
//
//*********************************
function addBoxDynamic(attach, id){
    //find div
    var mainDiv = document.createElement("div");
    if (id) {
        mainDiv.id = id;
    }
    //create divs
    var div1 = document.createElement("div");
    div1.className = "box_left";
    var div2 = document.createElement("div");
    div2.className = "box_right";
    var div3 = document.createElement("div");
    div3.className = "box_top";
    var div4 = document.createElement("div");
    div4.className = "box_top_left";
    var div5 = document.createElement("div");
    div5.className = "box_top_right";
    var div6 = document.createElement("div");
    div6.className = "box_middle";
    var div7 = document.createElement("div");
    div7.className = "box_content";
    var div8 = document.createElement("div");
    div8.className = "box_bottom";
    var div9 = document.createElement("div");
    div9.className = "box_bottom_left";
    var div10 = document.createElement("div");
    div10.className = "box_bottom_right";
    //attach divs
    div1.appendChild(div2);
    div2.appendChild(div3);
    div3.appendChild(div4);
    div3.appendChild(div5);
    div2.appendChild(div6);
    div6.appendChild(div7);
    div1.appendChild(div8);
    div8.appendChild(div9);
    div8.appendChild(div10);
    div7.appendChild(attach);
    mainDiv.appendChild(div1);
    return mainDiv;
}

//*********************************
//
// hidden field
//
//*********************************
function hiddenField(name, val){
    var input = document.createElement("input");
    input.type = "hidden";
    input.name = name;
    input.id = name;
    input.value = val;
    return input;
}

//*********************************
//
// text counter
//
//*********************************
function textCounter(field, countfield, maxlimit){
    if (field.value.length > maxlimit) 
        field.value = field.value.substring(0, maxlimit);
    else 
        countfield.value = maxlimit - field.value.length;
}

//*********************************
//
// show message
//
//*********************************
function showMessage(msg, t){
    dojo.event.topic.publish("alert", {
        message: "<span class='alert'>" + msg + '</span>',
        type: t,
        duration: 32000
    })
}

//*********************************
//
// form verification scripts
//
//*********************************
function MM_findObj(n, d){ //v4.01
    var p, i, x;
    if (!d) 
        d = document;
    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) 
        x = d.all[n];
		if (d.forms) {
			for (i = 0; !x && i < d.forms.length; i++) 
				x = d.forms[i][n];
		}
		if (d.layers) {
			for (i = 0; !x && d.layers && i < d.layers.length; i++) 
				x = MM_findObj(n, d.layers[i].document);
		}
    if (!x && d.getElementById) 
        x = d.getElementById(n);
    return x;
}

function MM_validateForm(array) {
    var elm = document.getElementById(formObj);
    elm = elm ? elm : dojo.byId(formObj);
    var i, p, q, nm, test, num, min, max, errors = "", args = array;
    for (i = 0; i < args.length - 2; i += 3) {
        test = args[i + 2];
        var valo = MM_findObj(args[i], elm);
        var val = "";
        if (valo) {
            nm = valo.name;
            if ((val = valo.value) != "") {
                if (test.indexOf("isEmail") != -1) {
                    regex = new RegExp("^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$");
                    p = regex.exec(val);
                    if (p == null) {
                        errors += "- " + nm + " must contain an e-mail address.<br />";
                    }
                } else if (test != "R") {
                    num = parseFloat(val);
                    if (isNaN(val)) {
                        errors += "- " + nm + " must contain a number.<br />";
                    }
                    if (test.indexOf("inRange") != -1) {
                        p = test.indexOf(":");
                        min = test.substring(8, p);
                        max = test.substring(p + 1);
                        if (num < min || max < num) {
                            errors += "- " + nm + " must contain a number between " + min + " and " + max + ".<br />";
                        }
                    }
                } else if (valo.type=="select-one" && val == "0") {
                    errors += "- " + nm + " is required.<br />";
                }
            } else if (test.charAt(0) == "R") {
                errors += "- " + nm + " is required.<br />";
            }
        }
    }
    if (errors) {
        showMessage("The following error(s) occurred:<br />" + errors, "ERROR");
    }
    return errors == "";
}

//*********************************
//
// 	create DOM form
//	createDOMForm(id/name, method, action);
//
//*********************************
function setFormFocus(f){
    formObj = f;
}

function createDOMForm(id, method, action, a, extraArg){
    var form = document.createElement("form");
    form.id = id;
    form.name = id;
    if (method != "") 
        form.method = method;
    if (action != "") 
        form.action = action;
    switch (extraArg) {
        case 'upload':
            form.enctype = "multipart/form-data";
            break;
        default:
            break;
    }
    form.onclick = function(){
        setFormFocus(id);
        //setFormFocus(form);
    }
    form.onmouseover = function(){
        setFormFocus(id);
        //setFormFocus(form);
    }
    var validationArray = new Array();
    if (a) {
        var a_length = a.length;
        for (var i = 0; i < a_length; i++) {
            if (a[i][3] != '') {
                validationArray.push(a[i][1]);
                validationArray.push("");
                validationArray.push(a[i][3]);
            }
        }
    }
    if (validationArray.length > 0) {
        form.onsubmit = function(){
            return MM_validateForm(validationArray);
        }
    }
    return form;
}

function createDOMFormObject(id, method, action, a, extraArg){
    var form = document.createElement("form");
    form.id = id;
    form.name = id;
    if (method != "") 
        form.method = method;
    if (action != "") 
        form.action = action;
    switch (extraArg) {
        case 'upload':
            form.enctype = "multipart/form-data";
            break;
        default:
            break;
    }
    form.onclick = function(){
        setFormFocus(id);
        //setFormFocus(form);
    }
    form.onmouseover = function(){
        setFormFocus(id);
        //setFormFocus(form);
    }
    var validationArray = new Array();
    if (a) {
        var a_length = a.length;
        for (var i = 0; i < a_length; i++) {
            if (a[i].validation) {
                validationArray.push(a[i].id);
                validationArray.push("");
                validationArray.push(a[i].validation);
            }
        }
    }
    if (validationArray.length > 0) {
        form.onsubmit = function(){
            return MM_validateForm(validationArray);
        }
    }
    return form;
}

//*********************************
//	create DOM table
//	createDOMTableObject(tableObjects, submit, style, matchObject);
//      - tableObjects: array of objects for table info
//      - submit: Submit Button Value(if "" then there is no submit line)
//      - styleObject: style object
//      - matchObject: data object to match
//  options
//  table has the options for:
//  - style
//      -'cssClass':'class reference'=''
//      - 'border':'number'=0
//      - 'cellspacing':'number'=1
//      - 'cellpadding':'number'=1
//      - 'width':'number'=100%
//      - 'layout', which includes 'sidebyside' and 'stacked', default 'stacked'
//      - 'validationText':'string', string used to show if an item is required, default '*'
//  each line has the ability for:
//  - icon:'string path' (creates an icon at the beginning of the line)
//  - tooltip (requires either a 'tooltipicon' or 'tooltiptext') - uses dojo's tooltip facility
//      - tooltipicon:'string path'
//      - tooltiptext:'string'
//      - tooltiplink:'string link'
//      - tooltipcap:'string caption'
//  - validation:'string', validation rules include
//      - 'R': required, automatically adds the '*'
//      - ' ':not required
//      - 'isEmail':has to be an email (put R infront to make it also required, RisEmail)
//      - 'isNum': has to be a number (put R infront to make it also required, RisNum)
//      - 'isRange(startingNum:endingNum)':has to be a number within a range (put R infront to make it also required, RisNum)
//  - validate:'string', if validate='immediate', a flag will be sent immediately onblur
//  - css:sets the css class for the input field, default='inputfield'
//  - type: types and sub parameters include:
//      - 'hidden':creates a hidden field not in a table row, always put hidden objects at the end of your arrays
//      - 'header': creates a bold header line without a form field, good to seperate sections of input fields
//      - 'text':creates a text input field
//          - 'size':'number', sets the size (width) of the field, default=20
//          - 'value':'string', sets the value of the field,default="" **note if you include a match object with a matching id the value will be set to that id's value
//          - 'length':'number', creates a length counter field, removes the ability to add additional onkeydown and onkeyup fields, informs the user how many characters they can and cannot use
//          - 'maxlength':'number', sets the max length of the text field to stop overflow, also tells the user the max amount of characters
//          - 'id':'string', sets the name and id fields, also used to match back to the matchObject values
//          - 'onChangeEvent':function
//          - 'onKeyUpEvent':function
//          - 'onKeyDownEvent':function
//          - 'onSubmitEvent':function
//          - 'onClickEvent':function
//          - 'label':'string', text field label
//      - 'password':creates a password input field
//          - 'size':'number', sets the size (width) of the field, default=20
//          - 'value':'string', sets the value of the field,default="" **note if you include a match object with a matching id the value will be set to that id's value
//          - 'length':'number', creates a length counter field, removes the ability to add additional onkeydown and onkeyup fields, informs the user how many characters they can and cannot use
//          - 'maxlength':'number', sets the max length of the text field to stop overflow, also tells the user the max amount of characters
//          - 'id':'string',  sets the name and id fields, also used to match back to the matchObject values
//          - 'onChangeEvent':function
//          - 'onKeyUpEvent':function
//          - 'onKeyDownEvent':function
//          - 'onSubmitEvent':function
//          - 'onClickEvent':function
//          - 'label':text field label
//      - 'textArea': creates a text area
//          - 'size':'number', sets the size (width) of the field, default=20
//          - 'rows':'number', sets the amount of lines (height) of the field, default=8
//          - 'value':'string', sets the value of the field,default="" **note if you include a match object with a matching id the value will be set to that id's value
//          - 'length':'number', creates a length counter field, removes the ability to add additional onkeydown and onkeyup fields, informs the user how many characters they can and cannot use
//          - 'maxlength':'number', sets the max length of the text field to stop overflow
//          - 'id':'string', sets the name and id fields, also used to match back to the matchObject values
//          - 'onChangeEvent':function
//          - 'onKeyUpEvent':function
//          - 'onKeyDownEvent':function
//          - 'onSubmitEvent':function
//          - 'onClickEvent':function
//          - 'label':'string', text field label
//      - 'radio':creates a singular radio button, grouped radio buttons all need the same id
//          - 'value':'string', sets the value of the field,default="" **note if you include a match object with a matching id if the values of the matchingObject id and the radio button match, the button will be checked
//          - 'id':'string' sets the name and id fields, also used to match back to the matchObject values
//          - 'checked':boolean, sets the radio button to being initially checked
//          - 'onChangeEvent':function
//          - 'onKeyUpEvent':function
//          - 'onKeyDownEvent':function
//          - 'onSubmitEvent':function
//          - 'onClickEvent':function
//          - 'label':'string', text field label
//      - 'select': creates a select drop down list
//          - 'id':'string' sets the name and id fields, also used to match back to the matchObject values
//          - 'values':'array', an array of arrays, with the [0] element used as the label, and the [1] element used as the data, values will be matched to the matchObject if one exists
//          - 'start':'number', an offset, if you don't want to use a specific amount of leading array items from 'values'
//          - 'value':'string', sets the value of the select field, matches back to a data value in 'values'
//          - 'multiple':'string'='multiple', makes it so you can select multiple values
//          - 'size':'number', sets the line quantity (height) of the drop down select
//          - 'initial':'string', sets the initial value with a data value of 0
//          - 'onChangeEvent':function
//          - 'onKeyUpEvent':function
//          - 'onKeyDownEvent':function
//          - 'onSubmitEvent':function
//          - 'onClickEvent':function
//          - 'label':'string', text field label
//      - 'match': creates a text field that matches back to a value in the 'values' array, displays the [0] value
//          - 'id':'string' sets the name and id fields, also used to match back to the matchObject values
//          - 'values':'array', an array of arrays, with the [0] element used as the label, and the [1] element used as the data, values will be matched to the matchObject if one exists
//          - 'value':'string', sets the value of the select field, matches back to a data value in 'values'
//          - 'label':'string', text field label
//      - 'checkbox': creates a checkbox
//          - 'id':'string' sets the name and id fields, also used to match back to the matchObject values
//          - 'value':'string', sets the value of the field,default="" **note if you include a match object with a matching id if the values of the matchingObject id and the radio button match, the button will be checked
//          - 'checked':boolean, sets the checkbox to being initially checked
//          - 'onChangeEvent':function
//          - 'onKeyUpEvent':function
//          - 'onKeyDownEvent':function
//          - 'onSubmitEvent':function
//          - 'onClickEvent':function
//          - 'label':'string', text field label
//      - 'label': creates text field where the input field usually is, great for instructions
//          - 'text':'string', text shown where the input field usually is
//          - 'label':'string', text field label
//      - 'file': creates text field where the input field usually is, great for instructions
//          - 'size':'number', sets the size (width) of the field, default=13
//          - 'label':'string', text field label
//          - 'id':'string' sets the name and id fields, also used to match back to the matchObject values
//      - 'button': creates a button
//          - 'id':'string' sets the name and id fields
//          - 'value':'string', sets the value of the field(text shown in the button),default="Submit"
//          - 'onChangeEvent':function
//          - 'onKeyUpEvent':function
//          - 'onKeyDownEvent':function
//          - 'onSubmitEvent':function
//          - 'onClickEvent':function
//          - 'label':'string', text field label
//      - 'image': creates an image
//          - 'source':'string', link path to the image
//          - 'height':'number', height of the image
//          - 'width':'number', width of the image
//          - 'vspace':'number', vspace of the image
//          - 'hspace':'number', hspace of the image
//          - 'border':'number', border of the image
//          - 'alt':'string', alt text for the image
//*********************************
function createDOMTableObject(a, style, s, obj){
    var checkVar = "";
    var validationArray = new Array();
    var a_length = a.length;
    var table = document.createElement("table");
    if (style.border) {
        table.border = style.border;
    }
    else {
        table.border = 0;
    }
    if (style.cssClass) {
        table.className = style.cssClass;
    }
    if (style.cellspacing) {
        table.cellSpacing = style.cellspacing;
    }
    else {
        table.cellSpacing = 1;
    }
    if (style.cellpadding) {
        table.cellPadding = style.cellpadding;
    }
    else {
        table.cellPadding = 1;
    }
    if (style.width) {
        table.style.width = style.width;
    }
    else {
        table.style.width = "100%";
    }
    var vT = "*";
    if (style.validationText) {
        vT = style.validationText;
    }
    var tbody = document.createElement("tbody");
    table.appendChild(tbody);
    for (var i = 0; i < a_length; i++) {
        //if hidden
        if (a[i].type != 'hidden') {
            //if header element, create it's own row and make it bold
            if (a[i].type == "header") {
                var label = document.createElement("strong");
                label.appendChild(document.createTextNode(a[i].label));
            }
            else {
                //if not header, add text field
                if (a[i].label) {
                    var label = document.createTextNode(a[i].label);
                }
                else {
                    var label = document.createTextNode(" ");
                }
            }
            if (a[i].icon) {
                var icon = document.createElement("img");
                icon.src = a[i].icon;
            }
            switch (a[i].type) {
                case "text":
                    var input = document.createElement("input");
                    if (a[i].size) {
                        input.size = a[i].size;
                    }
                    else {
                        input.size = 20;
                    }
                    var val = "";
                    val = (a[i].value) ? a[i].value : "";
                    val = (obj) ? obj[a[i].id] : val;
                    input.value = val;
                    if (a[i].length) {
                        input.onkeydown = textCounter(this.form.a[i].id, this.form.a[i].id + "_remLen", a[i].length);
                        input.onkeyup = textCounter(this.form.a[i].id, this.form.a[i].id + "_remLen", a[i].length);
                    }
                    if (a[i].maxlength) {
                        input.maxLength = a[i].maxlength;
                    }
                    break;
                case "password":
                    var input = document.createElement("input");
                    if (a[i].size) {
                        input.size = a[i].size;
                    }
                    else {
                        input.size = 20;
                    }
                    var val = "";
                    val = (a[i].value) ? a[i].value : "";
                    val = (obj) ? obj[a[i].id] : val;
                    input.value = val;
                    if (a[i].length) {
                        input.onkeydown = textCounter(this.form.a[i].id, this.form.a[i].id + "_remLen", a[i].length);
                        input.onkeyup = textCounter(this.form.a[i].id, this.form.a[i].id + "_remLen", a[i].length);
                    }
                    if (a[i].maxlength) {
                        input.maxLength = a[i].maxlength;
                    }
                    break;
                case "textarea":
                    var input = document.createElement("textarea");
                    if (a[i].rows) {
                        input.rows = a[i].rows;
                    }
                    else {
                        input.rows = 8;
                    }
                    if (a[i].size) {
                        input.cols = a[i].cols;
                    }
                    else {
                        input.cols = 20;
                    }
                    var val = (obj) ? obj[a[i].id] : "";
                    input.appendChild(document.createTextNode(val));
                    if (a[i].length) {
                        input.onkeydown = textCounter(this.form.a[i].id, this.form.a[i].id + "_remLen", a[i].length);
                        input.onkeyup = textCounter(this.form.a[i].id, this.form.a[i].id + "_remLen", a[i].length);
                    }
                    if (a[i].maxlength) {
                        input.maxLength = a[i].maxlength;
                    }
                    break;
                case "radio":
                    var input = document.createElement("input");
                    if (a[i].value) {
                        input.value = a[i].value;
                    }
                    if ((a[i].checked) && (a[i].checked == true)) {
                        input.defaultChecked = true;
                    }
                    if (obj) {
                        if ((a[i].value) && (a[i].value == obj[a[i].id])) {
                            input.defaultChecked = true;
                        }
                    }
                    break;
                case "select":
                    var input = document.createElement("select");
                    var t_length = a[i].values.length;
                    var start = 0;
                    if (a[i].start) {
                        start = a[i].start;
                    }
                    if ((a[i].initial != "") && (a[i].initial != null)) {
                        var optionSelect = document.createElement("option");
                        optionSelect.value = 0;
                        optionSelect.appendChild(document.createTextNode(a[i].initial));
                        if (obj) {
                            for (var j = start; j < t_length; j++) {
                                if (a[i].values[j][1] == 0) {
                                    optionSelect.selected = true;
                                }
                            }
                        }
                        input.appendChild(optionSelect);
                    }
                    for (var j = start; j < t_length; j++) {
                        var optionSelect = document.createElement("option");
                        optionSelect.value = a[i].values[j][1];
                        optionSelect.appendChild(document.createTextNode(a[i].values[j][0]));
                        if (obj) {
                            if (a[i].values[j][1] == obj[a[i].id]) {
                                optionSelect.selected = true;
                            }
                        }
                        else 
                            if (a[i].value) {
                                if (a[i].values[j][1] == a[i].value) {
                                    optionSelect.selected = true;
                                }
                            }
                        input.appendChild(optionSelect);
                    }
                    if ((a[i].multiple) || (a[i].multiple == "multiple")) {
                        input.multiple = true;
                        if (a[i].size) {
                            input.size = a[i].size;
                        }
                        else {
                            input.size = 8;
                        }
                    }
                    break;
                case "match":
                    var matchSelect = "";
                    var t_length = a[i].values.length;
                    for (var j = 0; j < t_length; j++) {
                        if (obj) {
                            if (a[i].values[j][1] == obj[a[i].id]) {
                                matchSelect += a[i].values[j][0];
                            }
                        }
                        else 
                            if (a[i].value) {
                                if (a[i].values[j][1] == a[i].value) {
                                    matchSelect += a[i].values[j][0];
                                }
                            }
                    }
                    var input = document.createTextNode(matchSelect);
                    break;
                case "checkbox":
                    var input = document.createElement("input");
                    if (a[i].value) {
                        input.value = a[i].value;
                    }
                    else {
                        input.value = 1;
                    }
                    if (obj) {
                        if (a[i].value == obj[a[i].id]) {
                            input.defaultChecked = "checked";
                        }
                    }
                    else 
                        if (a[i].checked) {
                            input.defaultChecked = "checked";
                        }
                    break;
                case "file":
                    var input = document.createElement("input");
                    if (a[i].size) {
                        input.size = a[i].size;
                    }
                    else {
                        input.size = 13;
                    }
                    break;
                case "label":
                    if (a[i].text) {
                        var val = a[i].text;
                    }
                    else {
                        var val = "";
                    }
                    var input = document.createTextNode(val);
                    break;
                case "button":
                    var input = document.createElement("input");
                    if (a[i].value) {
                        input.value = a[i].value;
                    }
                    else {
                        input.value = "Submit";
                    }
                    break;
                case "image":
                    var input = document.createElement("img");
                    if (a[i].source) {
                        input.src = a[i].source;
                    }
                    else {
                        input.src = "";
                    }
                    if (a[i].height) {
                        input.height = a[i].height;
                    }
                    if (a[i].width) {
                        input.width = a[i].width;
                    }
                    if (a[i].vspace) {
                        input.vSpace = a[i].vspace;
                    }
                    else {
                        input.vSpace = 0;
                    }
                    if (a[i].hspace) {
                        input.hSpace = a[i].hspace;
                    }
                    else {
                        input.hSpace = 0;
                    }
                    if (a[i].border) {
                        input.border = a[i].border;
                    }
                    else {
                        input.border = 0;
                    }
                    if (a[i].alt) {
                        input.alt = a[i].alt;
                    }
                    else {
                        input.alt = "";
                    }
                    break;
                case "validbox":
                    input = document.createElement("div");
                    vregex = new RegExp("^[a-zA-Z0-9]+$");
                    if ( a[i].regex ) {
                      vregex = new RegExp(a[i].regex);
                    }
                    vsize = 20;
                    if ( a[i].size ) {
                      vsize = a[i].size;
                    }
                    vid = a[i].id;
                    if ( a[i].vid ) {
                      vid = a[i].vid;
                    }
                    vmaxlength = a[i].maxlength;
                    vrequired = ((a[i].validation) && (a[i].validation.charAt(0) == "R"));
                    vmissingMessage = "&nbsp;";
                    if ( vrequired ) {
                      vmissingMessage = "*";
                    }
                    val = (a[i].value) ? a[i].value : "";
                    val = (obj) ? obj[a[i].id] : val;
                    a[i].validation = null;
                    vinvalidMessage = a[i].invalidMessage;
                    vbox = dojo.widget.createWidget("ValidationTextbox",
                                                    {id: vid,
                                                     name: a[i].id,
                                                     size: vsize, 
                                                     maxlength: vmaxlength, 
                                                     required: vrequired,
                                                     missingMessage: vmissingMessage,
                                                     invalidMessage: "&nbsp;"});
                    vbox.isValid = new isValidFunc(vid, vregex, vrequired);
                    if ( a[i].validArray ) {
                      validArray = a[i].validArray;
                      validArray.push(vbox);
                    }
                    vbox.setValue(val);
                    dojo.event.connect(vbox, "update", new warnNotValid(vid, vinvalidMessage));
                    input.appendChild(vbox.domNode);
                    break;
                default:
                    if (obj) {
                        var val = obj[a[i].id];
                        if ( a[i].value ) {
                          val = a[i].value;
                        }
                    }
                    else {
                        if (a[i].text) {
                            var val = a[i].text;
                        }
                        else {
                            var val = "";
                        }
                    }
                    var input = document.createTextNode(val);
                    break;
            }
            //common attributes
            if ((a[i].type != "match") && (a[i].type != "header") && (a[i].type != "validbox") && (a[i].type != "label") && (a[i].type != null) && (a[i].type != undefined) && (a[i].type != "")) {
                if (a[i].id) {
                    input.name = a[i].id;
                    input.id = a[i].id;
                }
                if ((a[i].type) && ((a[i].type != "select") && (a[i].type != "password") && (a[i].type != "textarea") && (a[i].type != "list") && (a[i].type != "text") && (a[i].type != "image"))) {
                    input.type = a[i].type;
                }
                if (a[i].validate == 'immediate') {
                    input.onblur = function(){
                        var immediateValidate = new Array();
                        validationArray.push(a[i].id);
                        validationArray.push("");
                        validationArray.push(a[i].validation);
                        return MM_validateForm(immediateValidate);
                    }
                }
                if (a[i].css) {
                    input.className = a[i].css;
                }
                else {
                    input.className = "inputField";
                }
            }
            //additional functions
            if (a[i].onChangeEvent) {
                input.onchange = a[i].onChangeEvent;
            }
            if (a[i].onKeyUpEvent) {
                input.onkeyup = a[i].onKeyUpEvent;
            }
            if (a[i].onKeyDownEvent) {
                input.onkeydown = a[i].onKeyDownEvent;
            }
            if (a[i].onSubmitEvent) {
                input.onsubmit = a[i].onSubmitEvent;
            }
            if (a[i].onClickEvent) {
                input.onclick = a[i].onClickEvent;
            }
            //add counter component if necessary        
            if (((a[i].type == 'text') && (a[i].length)) || ((a[i].type == 'textarea') && (a[i].length)) || ((a[i].type == 'password') && (a[i].length))) {
                var input_counter = document.createElement("input");
                input_counter.type = "text";
                input_counter.id = a[i].id + "_remLen";
                input_counter.name = a[i].id + "_remLen";
                input_counter.size = 3;
                input_counter.maxLength = 3;
                input_counter.readOnly = true;
                input_counter.value = a[i].length;
                if (a[i].css) {
                    input_counter.className = a[i].css;
                }
                else {
                    input_counter.className = "inputField";
                }
                var inputCounterDiv = document.createElement("div");
                inputCounterDiv.appendChild(input_counter);
                inputCounterDiv.appendChild(document.createTextNode(" characters remaining"));
            }
            else {
                var inputCounterDiv = document.createElement("div");
            }
            //add max length as necessary
            if (((a[i].type == 'text') && (a[i].maxlength)) || ((a[i].type == 'textarea') && (a[i].maxlength)) || ((a[i].type == 'password') && (a[i].maxlength))) {
                var inputCounterDiv = document.createElement("div");
                inputCounterDiv.appendChild(document.createTextNode("Max " + a[i].maxlength + " characters"));
            }
            //add * if required
            if ((a[i].validation) && (a[i].validation.charAt(0) == "R")) {
                var validationSymbol = document.createTextNode(vT);
            }
            //tooltip
            if ((a[i].tooltipicon) || (a[i].tooltiptext)) {
                var ttS = document.createElement("span");
                if (a[i].tooltipclass) {
                    ttS.className = a[i].tooltipclass;
                }
                ttS.id = "ttspan_" + a[i].id;
                if (a[i].tooltipicon) {
                    var ttI = document.createElement("img");
                    ttI.src = a[i].tooltipicon;
                    ttS.appendChild(ttI);
                }
                if (a[i].tooltiptext) {
                    ttS.appendChild(document.createTextNode(a[i].tooltiptext));
                }
            }
            //layout section
            switch (style.layout) {
                case "sidebyside":
                    var row1 = document.createElement("tr");
                    if (a[i].type == "header") {
                        var label_col = document.createElement("td");
                        label_col.vAlign = "top";
                        label_col.colSpan = 2;
                        row1.appendChild(label_col);
                        if (a[i].icon) {
                            label_col.appendChild(icon);
                        }
                        label_col.appendChild(label);
                        label_col.appendChild(input);
                        if ((a[i].validation) && (a[i].validation.charAt(0) == "R")) {
                            label_col.appendChild(validationSymbol);
                        }
                        if (a[i].length) {
                            label_col.appendChild(inputCounterDiv);
                        }
                        if ((a[i].tooltipicon) || (a[i].tooltiptext)) {
                            label_col.appendChild(ttS);
                        }
                    }
                    else {
                        var label_col = document.createElement("td");
                        label_col.vAlign = "top";
                        var input_col = document.createElement("td");
                        if (style.inputPlacement) {
                            if (style.inputPlacement == "infront") {
                                row1.appendChild(input_col);
                                row1.appendChild(label_col);
                            }
                            else {
                                row1.appendChild(label_col);
                                row1.appendChild(input_col);
                            }
                        }
                        else {
                            row1.appendChild(label_col);
                            row1.appendChild(input_col);
                        }
                        if (a[i].icon) {
                            label_col.appendChild(icon);
                        }
                        label_col.appendChild(label);
                        input_col.appendChild(input);
                        if ((a[i].validation) && (a[i].validation.charAt(0) == "R")) {
                            input_col.appendChild(validationSymbol);
                        }
                        if (a[i].length) {
                            input_col.appendChild(inputCounterDiv);
                        }
                        if ((a[i].tooltipicon) || (a[i].tooltiptext)) {
                            input_col.appendChild(ttS);
                        }
                    }
                    tbody.appendChild(row1);
                    break;
                case "stacked":
                    var row1 = document.createElement("tr");
                    var row2 = document.createElement("tr");
                    var label_col = document.createElement("td");
                    label_col.vAlign = "top";
                    var input_col = document.createElement("td");
                    row1.appendChild(label_col);
                    row2.appendChild(input_col);
                    if (a[i].icon) {
                        label_col.appendChild(icon);
                    }
                    label_col.appendChild(label);
                    input_col.appendChild(input);
                    if ((a[i].validation) && (a[i].validation.charAt(0) == "R")) {
                        input_col.appendChild(validationSymbol);
                    }
                    if (a[i].length) {
                        input_col.appendChild(inputCounterDiv);
                    }
                    if ((a[i].tooltipicon) || (a[i].tooltiptext)) {
                        input_col.appendChild(ttS);
                    }
                    tbody.appendChild(row1);
                    tbody.appendChild(row2);
                    break;
                default:
                    var row1 = document.createElement("tr");
                    var row2 = document.createElement("tr");
                    var label_col = document.createElement("td");
                    label_col.vAlign = "top";
                    var input_col = document.createElement("td");
                    row1.appendChild(label_col);
                    row2.appendChild(input_col);
                    if (a[i].icon) {
                        label_col.appendChild(icon);
                    }
                    label_col.appendChild(label);
                    input_col.appendChild(input);
                    if ((a[i].validation) && (a[i].validation.charAt(0) == "R")) {
                        input_col.appendChild(validationSymbol);
                    }
                    if (a[i].length) {
                        input_col.appendChild(inputCounterDiv);
                    }
                    if ((a[i].tooltipicon) || (a[i].tooltiptext)) {
                        input_col.appendChild(ttS);
                    }
                    tbody.appendChild(row1);
                    tbody.appendChild(row2);
                    break;
            }
            //add validation information
            if (a[i].validation) {
                validationArray.push(a[i].id);
                validationArray.push("");
                validationArray.push(a[i].validation);
            }
            //if type hidden just attach it to the table without it's own row
        }
        else {
            var input = document.createElement("input");
            input.name = a[i].name?a[i].name:a[i].id;
            input.id = a[i].id;
            input.type = a[i].type;

            var val = (obj) ? obj[a[i].id] : "";
            val = (val) ? val : a[i].value;
            input.value = val;
            tbody.appendChild(input); //attach to table
            //end if hidden element  
        }
        //end iterating through array, for statement	
    }
    //if there is a submit buttom requested
    if ((s) && (s != "")) {
        //create submit btn
        var submitRow = document.createElement("tr");
        var submitCol1 = document.createElement("td");
        if (style.layout == "sidebyside") {
            submitCol1.colSpan = 2;
        }
        var submitBtn = document.createElement("input");
        submitBtn.id = "submit";
        submitBtn.type = "submit";
        submitBtn.name = "submit";
        submitBtn.value = s;
        submitBtn.className = "inputField";
        /*
         if(validationArray.length>0){
         alert(validationArray);
         submitBtn.onclick = function(){
         return MM_validateForm(validationArray);
         }
         }
         */
        submitCol1.appendChild(submitBtn);
        submitRow.appendChild(submitCol1);
        tbody.appendChild(submitRow);
    }
    //output table to dom
    return table;
}

function isValidFunc(vid, vregex, vrequired){
  return ( function() {
             fieldValue = dojo.widget.byId(vid).getValue();
             if (!fieldValue || fieldValue == "") {
               if ( vrequired ) {
                 return ( false );
               }
               else {
                 return ( true );
               }
             }
              
             m = vregex.exec(fieldValue);
             return ( m != null );
           } 
         );
}

function warnNotValid(vid, vinvalidMessage){
  return ( function() {
             if ( !dojo.widget.byId(vid).isValid() && !dojo.widget.byId(vid).isEmpty() ) { 
               showMessage(vinvalidMessage, "FATAL");
             }
           }
          );
}

function checkValid(validArray, callback, message) {
  if ( validArray.length == 0 ) {
    callback();
  }
  else {
    allValid = true;
    for ( loop = 0; loop < validArray.length; loop++ ) {
      if ( !validArray[loop].isValid() ) {
        allValid = false;
        break;
      }
    }
    if ( allValid ) {
      callback();
    }
    else {
      showMessage ( message.body, message.style );
    }
  }
}

//*********************************
//	attach tooltips in a table
//  this function can't be called until the table 
//  is added to the dom, or you willcuse have an error
//*********************************
function createDOMTTObject(a){
    var a_length = a.length;
    for (var i = 0; i < a_length; i++) {
        if ((a[i].tooltipicon) || (a[i].tooltiptext) || (a[i].tooltiplink)) {
            if (a[i].ttid) {
              if (a[i].tooltipcap) {
                var tooltip = dojo.widget.createWidget("tooltip", {
                    id: "tt_" + a[i].ttid,
                    connectId: "ttspan_" + a[i].ttid,
                    caption: a[i].tooltipcap
                });
              }
              else {
                var tooltip = dojo.widget.createWidget("tooltip", {
                    id: "tt_" + a[i].ttid,
                    connectId: "ttspan_" + a[i].ttid,
                    href: a[i].tooltiplink
                });
              }
            }
            else {
              if (a[i].tooltipcap) {
                var tooltip = dojo.widget.createWidget("tooltip", {
                    id: "tt_" + a[i].id,
                    connectId: "ttspan_" + a[i].id,
                    caption: a[i].tooltipcap
                });
              }
              else {
                var tooltip = dojo.widget.createWidget("tooltip", {
                    id: "tt_" + a[i].id,
                    connectId: "ttspan_" + a[i].id,
                    href: a[i].tooltiplink
                });
              }
            }
        }
    }
}

//*********************************
//
//	no filter table data
//
//*********************************
function noFilterTableData(obj, div){
    if ((obj == null) || (obj == "")) {
        var header = document.createElement("h2");
        header.className = "titletag";
        header.align = "center";
        header.appendChild(document.createTextNode("There is currently no data to show"));
        div.appendChild(header);
    }
}

//*********************************
//
//	create total row below filter table
//
//*********************************
function createTotalTable(total, header, mainDiv){
    div = document.createElement("div");
    div.id = "totalTable";
    var table = document.createElement("table");
    table.style.width = "100%";
    table.cellSpacing = 1;
    table.border = 0;
    table.cellPadding = 1;
    var tbody = document.createElement("tbody")
    table.appendChild(tbody);
    var rowHeader = document.createElement("tr");
    var emptyCol = document.createElement("td");
    rowHeader.appendChild(emptyCol);
    for (key in header) {
        var hcol = document.createElement("td");
        hcol.appendChild(document.createTextNode(header[key]));
        rowHeader.appendChild(hcol);
    }
    var totalRow = document.createElement("tr");
    var totalTextCol = document.createElement("td");
    totalTextCol.appendChild(document.createTextNode("Totals:"));
    totalRow.appendChild(totalTextCol);
    for (key in total) {
        var col = document.createElement("td");
        col.appendChild(document.createTextNode(total[key]));
        totalRow.appendChild(col);
    }
    tbody.appendChild(rowHeader);
    tbody.appendChild(totalRow);
    div.appendChild(table);
    mainDiv.appendChild(div);
}
