//shows/hides headers and footers for design mode
var lastdesignbackground;
function design(el, sh) {
    if (sh) {
        lastdesignbackground = el.parentNode.style.background;
        el.parentNode.style.background = 'lightyellow';
    } else {
        el.parentNode.style.background = lastdesignbackground;
    }

}
//Requires Mozilla or Phoenix post 8-Jan-03
function showHideElement(id) {
    var d = document.getElementById(id);
    if (d) {
        if (d.style.display == 'none')
            d.style.display = 'block';
        else
            d.style.display = 'none';
    }
}
function showFileInput(el) {
    document.getElementById(el).name = '__name' + el;
    document.getElementById(el + 'imagebodydata').style.display = 'block';
    document.getElementById(el + 'imagebodydata').innerHTML = '<input type=file name=' + el + ' id=' + el + '>';
    document.getElementById('current' + el + 'image').style.display = 'none';
    document.getElementById(el + 'imagepicker').style.display = 'block';
    return false;
}
function showImagePicker(el, t, id) {

    try {
        document.getElmentById('__name' + el).name = el;
    } catch (e) { }

    document.getElementById(el + 'imagebodydata').style.display = 'block';
    document.getElementById(el + 'imagebodydata').innerHTML = '';
    document.getElementById('current' + el + 'image').style.display = 'none';
    document.getElementById(el + 'imagepicker').style.display = 'block';
    //document.getElementById(el + 'imagepager').style.display='block';
    getContent('db.aspx?t=attachments&tableid=' + t + '&itemid=' + id + '&filetypeop=in&filetypequery=jpg,jpeg,png,gif&noheader=true&nofooter=true&vid=imagechooser&updatefield=' + el + '&ajaxdiv=' + el + 'imagebodydata', el + 'imagebodydata');
    return false;
}
function validateEmail(val, el, required) {
    var passed = true;
    if (required != undefined && required) {
        passed = validateRequired(val, el);
    }

    if (passed) {
        var emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
        if (val != '' && !emailRe.test(val)) {
            document.getElementById(el + 'invalidmsg').innerHTML = "&nbsp;<img src=/icons/crystal_project/32x32/actions/stop.png height=16 width=16 align=absmiddle alt='You entered an invalid email address.' title='You entered an invalid email address.'>";
        } else {
            document.getElementById(el + 'invalidmsg').innerHTML = "";
        }
    }
}
function validateRequired(val, el) {
    if (val == '') {
        document.getElementById(el + 'invalidmsg').innerHTML = "&nbsp;<img src=/icons/crystal_project/32x32/actions/stop.png height=16 width=16 align=absmiddle alt='You must enter a value.' title='You must enter a value.'>";
        return false;
    } else {
        document.getElementById(el + 'invalidmsg').innerHTML = "";
        return true;
    }
}
function validatePhone(val, el, required) {
    var passed = true;
    if (required != undefined && required) {
        passed = validateRequired(val, el);
    }

    if (passed) {
        var phoneRe = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/;
        if (val != "" && !phoneRe.test(val)) {
            document.getElementById(el + 'invalidmsg').innerHTML = "&nbsp;<img src=/icons/crystal_project/32x32/actions/stop.png height=16 width=16 align=absmiddle alt='You entered an invalid phone number.' title='You entered an invalid phone number.'>";
        } else {
            document.getElementById(el + 'invalidmsg').innerHTML = "";
        }
    }
}
function validateDateTime(val, el, required) {
    var passed = true;
    if (required) {
        passed = validateRequired(val, el);
    }

    if (passed) {
        var dateRe1 = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})$/;
        var dateRe2 = /^(([1-9])|(0[1-9])|(1[0-2]))\/(([0-9])|([0-2][0-9])|(3[0-1]))\/(([0-9][0-9])|([1-2][0,9][0-9][0-9]))$/;
        var dateRe3 = /^(3[0-1]|2[0-9]|1[0-9]|0[1-9]|[1-9])[\s{1}|\/|-](Jan|JAN|jan|Feb|FEB|feb|Mar|MAR|mar|Apr|APR|apr|May|MAY|may|Jun|JUN|jun|Jul|JUL|jul|aug|Aug|AUG|sep|Sep|SEP|oct|Oct|OCT|nov|Nov|NOV|dec|Dec|DEC)[\s{1}|\/|-]\d{4}$/;
        //alert(dateRe1.test(val));
        //alert(dateRe2.test(val));
        //alert(dateRe3.test(val));
        if (!dateRe1.test(val) && !dateRe2.test(val) && !dateRe3.test(val)) {
            document.getElementById(el + 'invalidmsg').innerHTML = "&nbsp;<img src=/icons/crystal_project/32x32/actions/stop.png height=16 width=16 align=absmiddle alt='You entered an invalid date/time.' title='You entered an invalid date/time.'>";
        } else {
            document.getElementById(el + 'invalidmsg').innerHTML = "";
        }
    }
}
function validateSSN(val, el) {
    var isValid = true;
    var re = /^([0-6]\d{2}|7[0-6]\d|77[0-2])([ \-]?)(\d{2})\2(\d{4})$/;
    if (!re.test(val)) { isValid = false; }
    var temp = val;
    if (val.indexOf("-") != -1) { temp = (val.split("-")).join(""); }
    if (val.indexOf(" ") != -1) { temp = (val.split(" ")).join(""); }
    if (temp.substring(0, 3) == "000") { isValid = false; }
    if (temp.substring(3, 5) == "00") { isValid = false; }
    if (temp.substring(5, 9) == "0000") { isValid = false; }
    if (val != "" && !isValid) {
        document.getElementById(el + 'invalidmsg').innerHTML = "&nbsp;<img src=/icons/crystal_project/32x32/actions/stop.png height=16 width=16 align=absmiddle alt='You entered an invalid SSN.' title='You entered an invalid SSN.'>";
    } else {
        document.getElementById(el + 'invalidmsg').innerHTML = "";
    }
}
function validateZIP(val, el, required) {
    var passed;
    if (required) {
        passed = validateRequired(val, el);
    }

    if (passed) {
        var valid = "0123456789-";
        var hyphencount = 0;
        document.getElementById(el + 'invalidmsg').innerHTML = "";
        if (val.length == 0)
            return;

        if (val.length != 5 && val.length != 10) {
            document.getElementById(el + 'invalidmsg').innerHTML = "&nbsp;<img src=/icons/crystal_project/32x32/actions/stop.png height=16 width=16 align=absmiddle alt='You entered an invalid Zip Code. Use 5 or 5-4 format.' title='You entered an invalid Zip Code. Use 5 or 5-4 format.'>";
        }

        for (var i = 0; i < val.length; i++) {
            temp = "" + val.substring(i, i + 1);
            if (temp == "-") hyphencount++;
            if (valid.indexOf(temp) == "-1") {
                document.getElementById(el + 'invalidmsg').innerHTML = "&nbsp;<img src=/icons/crystal_project/32x32/actions/stop.png height=16 width=16 align=absmiddle alt='There are invalid characters in your Zip Code.' title='There are invalid characters in your Zip Code.'>";
            }
            if ((hyphencount > 1) || ((val.length == 10) && "" + val.charAt(5) != "-")) {
                document.getElementById(el + 'invalidmsg').innerHTML = "&nbsp;<img src=/icons/crystal_project/32x32/actions/stop.png height=16 width=16 align=absmiddle alt='The proper format is 12345-1234 when using a ZIP+4.' title='The proper format is 12345-1234 when using a ZIP+4.'>";
            }
        }
    }
}

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: David Leppek :: https://www.azcode.com/Mod10

Basically, the alorithum takes each digit, from right to left and muliplies each second
digit by two. If the multiple is two-digits long (i.e.: 6 * 2 = 12) the two digits of
the multiple are then added together for a new number (1 + 2 = 3). You then add up the 
string of numbers, both unaltered and new values and get a total sum. This sum is then
divided by 10 and the remainder should be zero if it is a valid credit card. Hense the
name Mod 10 or Modulus 10. */
function isValidCreditCardNumber(ccNumb) {  // v2.0
    var valid = "0123456789"  // Valid digits in a credit card number
    var len = ccNumb.length;  // The length of the submitted cc number
    var iCCN = parseInt(ccNumb);  // integer of ccNumb
    var sCCN = ccNumb.toString();  // string of ccNumb
    sCCN = sCCN.replace(/^\s+|\s+$/g, '');  // strip spaces
    var iTotal = 0;  // integer total set at zero
    var bNum = true;  // by default assume it is a number
    var bResult = false;  // by default assume it is NOT a valid cc
    var temp;  // temp variable for parsing string
    var calc;  // used for calculation of each digit

    // Determine if the ccNumb is in fact all numbers
    for (var j = 0; j < len; j++) {
        temp = "" + sCCN.substring(j, j + 1);
        if (valid.indexOf(temp) == "-1") { bNum = false; }
    }

    // if it is NOT a number, you can either alert to the fact, or just pass a failure
    if (!bNum) {
        /*alert("Not a Number");*/bResult = false;
    }

    // Determine if it is the proper length 
    if ((len == 0) && (bResult)) {  // nothing, field is blank AND passed above # check
        bResult = false;
    } else {  // ccNumb is a number and the proper length - let's see if it is a valid card number
        if (len >= 15) {  // 15 or 16 for Amex or V/MC
            for (var i = len; i > 0; i--) {  // LOOP throught the digits of the card
                calc = parseInt(iCCN) % 10;  // right most digit
                calc = parseInt(calc);  // assure it is an integer
                iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
                i--;  // decrement the count - move to the next digit in the card
                iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
                calc = parseInt(iCCN) % 10;    // NEXT right most digit
                calc = calc * 2;                                 // multiply the digit by two
                // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
                // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
                switch (calc) {
                    case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
                    case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
                    case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
                    case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
                    case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
                    default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
                }
                iCCN = iCCN / 10;  // subtracts right most digit from ccNum
                iTotal += calc;  // running total of the card number as we loop
            }  // END OF LOOP
            if ((iTotal % 10) == 0) {  // check to see if the sum Mod 10 is zero
                bResult = true;  // This IS (or could be) a valid credit card number.
            } else {
                bResult = false;  // This could NOT be a valid credit card number
            }
        }
    }
    return bResult; // Return the results
}



function validateCC(val, el) {
    if (val != "" && !isValidCreditCardNumber(val)) {
        document.getElementById(el + 'invalidmsg').innerHTML = "&nbsp;<img src=/icons/crystal_project/32x32/actions/stop.png height=16 width=16 align=absmiddle alt='You entered an invalid date/time.' title='You entered an invalid credit card number.'>";
    } else {
        document.getElementById(el + 'invalidmsg').innerHTML = "";
    }
}

function formatCurrency(strValue) {
    strValue = strValue.toString().replace(/\$|\,/g, '');
    dblValue = parseFloat(strValue);

    blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
    dblValue = Math.floor(dblValue * 100 + 0.50000000001);
    intCents = dblValue % 100;
    strCents = intCents.toString();
    dblValue = Math.floor(dblValue / 100).toString();
    if (intCents < 10)
        strCents = "0" + strCents;
    for (var i = 0; i < Math.floor((dblValue.length - (1 + i)) / 3); i++)
        dblValue = dblValue.substring(0, dblValue.length - (4 * i + 3)) + ',' +
		dblValue.substring(dblValue.length - (4 * i + 3));
    return (((blnSign) ? '' : '-') + '$' + dblValue + '.' + strCents);
}
function validateInteger(val, el) {
    if (val != "" && !isNumeric(val, false)) {
        document.getElementById(el + 'invalidmsg').innerHTML = "&nbsp;<img src=/icons/crystal_project/32x32/actions/stop.png height=16 width=16 align=absmiddle alt='You must enter a number with no decimals.' title='You must enter a number with no decimals.'>";
    } else {
        document.getElementById(el + 'invalidmsg').innerHTML = "";
    }

}

function validateDecimal(val, el) {
    if (val != "" && !isNumeric(val, false)) {
        document.getElementById(el + 'invalidmsg').innerHTML = "&nbsp;<img src=/icons/crystal_project/32x32/actions/stop.png height=16 width=16 align=absmiddle alt='You did not enter a valid number.' title='You did not enter a valid number.'>";
    } else {
        document.getElementById(el + 'invalidmsg').innerHTML = "";
    }

}
function validateCurrency(val, el) {
    if (val != "" && !isNumeric(val, false)) {
        document.getElementById(el + 'invalidmsg').innerHTML = "&nbsp;<img src=/icons/crystal_project/32x32/actions/stop.png height=16 width=16 align=absmiddle alt='You did not enter a valid currency amount.' title='You did not enter a valid currency amount.'>";
    } else {
        document.getElementById(el + 'invalidmsg').innerHTML = "";
    }

}
function validateAlphaNumeric(val, el, strExtraChars, required) {

    var passed;
    if (required) {
        passed = validateRequired(val, el)
    }

    if (passed) {
        if (!IsAlphaNumeric(val, strExtraChars, required)) {
            document.getElementById(el + 'invalidmsg').innerHTML = "&nbsp;<img src=/icons/crystal_project/32x32/actions/stop.png height=16 width=16 align=absmiddle alt='You did not enter a valid currency amount.' title='You entered a value with invalid characters.'>";
        } else {
            document.getElementById(el + 'invalidmsg').innerHTML = "";
        }
    }
}
function IsNumeric(strString, bAllowDecimals)
//  check for valid numeric strings 
{
    var strValidChars = "0123456789-";
    if (bAllowDecimals)
        strValidChars += '.';
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}

function IsAlphaNumeric(strString, strExtraLegalChars)
//  check for valid numeric strings 
{
    var strValidChars = "0123456789.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    if (strExtraLegalChars != null) {
        strValidChars = strValidChars + strExtraLegalChars;
    }
    var strChar;
    var blnResult = true;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}

function countChars(t, max) {
    if (max > 0) {
        if (document.getElementById(t.id + 'Count'))
            document.getElementById(t.id + 'Count').innerHTML = t.value.length + " / " + max;
    } else {
        if (document.getElementById(t.id + 'Count'))
            document.getElementById(t.id + 'Count').innerHTML = t.value.length;
    }
}
function clearTabOrder(tagname) {
    var imgs, i;
    imgs = document.getElementsByTagName(tagname);
    for (i = 0; i < imgs.length; i++) {
        imgs[i].tabIndex = -1;
    }
}
function updateField(el, val) {
    document.getElementById(el).value = val;
    return false;
}
function updateImage(el, val) {
    document.getElementById('current' + el + 'image').src = val;
    document.getElementById(el).value = val;
    showHideElement('current' + el + 'image');
    showHideElement(el + 'imagepicker');
    showHideElement(el + 'imagepager');
    return false;
}

function setDisplaySettings(elemid, x, y) {
    try {
        elem = document.getElementById(elemid + "div")
        elem.style.position = "absolute";
        elem.style.left = x + 'px';
        elem.style.top = y + 'px';
        elem = document.getElementById(elemid);
        taborder += 10;
        if (elem) {
            elem.tabIndex = taborder;
        } else {
            if (document.forms.Form1.elements[elemid].length) {
                document.forms.Form1.elements[elemid][0].tabIndex = taborder;
                document.forms.Form1.elements[elemid][1].tabIndex = taborder + 1;
            }
        }
    } catch (e) { }
}
function updateTabOrders() {
    clearTabOrder('a');
    //clearTabOrder('span');
    //clearTabOrder('div');
    try { document.getElementById("searchsubmit").tabIndex = -1; } catch (e) { }
    try { document.getElementById("query").tabIndex = -1; } catch (e) { }
    var ar = pageelements.split(",");
    var taborder = 0;
    var i = 0;
    var elemid;
    while (i < ar.length) {
        taborder++;
        elemid = ar[i++];
        elem = document.getElementById(elemid);
        taborder++;
        if (elemid != '') {
            if (elem) {
                elem.tabIndex = taborder;
            } else {
                var forme = document.forms.Form1.elements[elemid];
                if (forme) {
                    var ii = forme.length;
                    while (ii--) {
                        forme[ii].tabIndex = (++taborder);
                    }
                }
            }
        }    
    }
}
function textZoom(el) {

    if (document.getElementById(el)) {
        if (document.getElementById(el).style.zIndex != 1001) {
            document.getElementById(el).style.width = '95%';
            document.getElementById(el).style.height = '100em';
            document.getElementById(el).style.zIndex = 1001;
        } else {
            document.getElementById(el).style.width = '45em';
            document.getElementById(el).style.height = '15em';
            document.getElementById(el).style.zIndex = 1;
        }
    }
    if (document.getElementById(el + 'div')) {
        if (document.getElementById(el + 'div').style.zIndex != 1000) {
            document.getElementById(el + 'div').style.width = '100%';
            document.getElementById(el + 'div').style.height = '150em';
            document.getElementById(el + 'div').style.zIndex = 1000;
        } else {
            document.getElementById(el + 'div').style.width = '65em';
            document.getElementById(el + 'div').style.height = '19em';
            document.getElementById(el + 'div').style.zIndex = 1;
        }
    }
}
function drawToolbar(el) {

    document.write("<img align=absmiddle src=/images/buttons/boldbtn.gif  title=\"Highlight some text and click for bold\"  class=buttons  onmouseover=\"mouseover(this);\" onmouseout=\"mouseout(this);\"  onmousedown=\"mousedown(this);\" onmouseup=\"mouseup(this);\"  onclick=\"wrapTag(document.getElementById('" + el + "'), '<b>', '</b>');\"><img align=absmiddle src=\"/images/buttons/italicbtn.gif\" width=\"18\" height=\"18\"  title=\"Highlight some text and click for italic\"  class=\"buttons\"  onmouseover=\"mouseover(this);\" onmouseout=\"mouseout(this);\"  onmousedown=\"mousedown(this);\" onmouseup=\"mouseup(this);\"  onclick=\"wrapTag(document.getElementById('" + el + "'), '<i>', '</i>')\"><img align=absmiddle src=\"/images/buttons/underlinebtn.gif\" width=\"18\" height=\"18\"  title=\"Highlight some text and click for underlined\"  class=\"buttons\"  onmouseover=\"mouseover(this);\" onmouseout=\"mouseout(this);\"  onmousedown=\"mousedown(this);\" onmouseup=\"mouseup(this);\"  onclick=\"wrapTag(document.getElementById('" + el + "'), '<u>', '</u>')\"><img align=absmiddle src=\"/images/buttons/centerbtn.gif\" width=\"18\" height=\"18\"  title=\"Highlight some text and click to center\"  class=\"buttons\"  onmouseover=\"mouseover(this);\" onmouseout=\"mouseout(this);\"  onmousedown=\"mousedown(this);\" onmouseup=\"mouseup(this);\"  onclick=\"wrapTag(document.getElementById('" + el + "'), '<div align=%22center%22>', '</div>')\"><img align=absmiddle src=\"/images/buttons/rightbtn.gif\" width=\"18\" height=\"18\"  title=\"Highlight some text and click to right align\"  class=\"buttons\"  onmouseover=\"mouseover(this);\" onmouseout=\"mouseout(this);\"  onmousedown=\"mousedown(this);\" onmouseup=\"mouseup(this);\"  onclick=\"wrapTag(document.getElementById('" + el + "'), '<div align=%22right%22>', '</div>')\"><img align=absmiddle src=\"/images/buttons/blockquotebtn.gif\" width=\"18\" height=\"18\"  title=\"Highlight some text and click for a blockquote\"  class=\"buttons\"  onmouseover=\"mouseover(this);\" onmouseout=\"mouseout(this);\"  onmousedown=\"mousedown(this);\" onmouseup=\"mouseup(this);\"  onclick=\"wrapTag(document.getElementById('" + el + "'), '<blockquote>', '</blockquote>')\"><img align=absmiddle src=\"/images/buttons/blistbtn.gif\" width=\"18\" height=\"18\"  title=\"Highlight some text and click for a bulleted list\"  class=\"buttons\"  onmouseover=\"mouseover(this);\" onmouseout=\"mouseout(this);\" onmousedown=\"mousedown(this);\"  onmouseup=\"mouseup(this);\"  onclick=\"wrapTag(document.getElementById('" + el + "'), '<li>', '</li>')\"><img align=absmiddle src=\"/images/buttons/prebtn.gif\" width=\"18\" height=\"18\"  title=\"Highlight some text and click for pre\"  class=\"buttons\"  onmouseover=\"mouseover(this);\" onmouseout=\"mouseout(this);\" onmousedown=\"mousedown(this);\" onmouseup=\"mouseup(this);\"  onclick=\"wrapTag(document.getElementById('" + el + "'), '<pre>', '</pre>')\"><img align=absmiddle src=\"/images/buttons/rulebtn.gif\" width=\"18\" height=\"18\"  title=\"Insert a horizontal rule\"  class=\"buttons\"  onmouseover=\"mouseover(this);\" onmouseout=\"mouseout(this);\" onmousedown=\"mousedown(this);\" onmouseup=\"mouseup(this);\"  onclick=\"insertTag(document.getElementById('" + el + "'),'<hr />');\"><img align=absmiddle src=\"/images/buttons/picbtn.gif\" width=\"18\" height=\"18\"  title=\"Insert an image\"  class=\"buttons\" onmouseover=\"mouseover(this);\" onmouseout=\"mouseout(this);\" onmousedown=\"mousedown(this);\" onmouseup=\"mouseup(this);\"  onclick=\"insertImage(document.getElementById('" + el + "'));\"><img align=absmiddle src=\"/images/buttons/linkbtn.gif\" width=\"18\" height=\"18\"  title=\"Highlight some text and click to add a link\"  class=\"buttons\"  onmouseover=\"mouseover(this);\" onmouseout=\"mouseout(this);\"  onmousedown=\"mousedown(this);\" onmouseup=\"mouseup(this);\"  onclick=\"wrapWithLink(document.getElementById('" + el + "'));\"> <img class=buttons  src=/images/buttons/textzoom.gif   onmouseover=\"mouseover(this);\" onmouseout=\"mouseout(this);\"  onmousedown=\"mousedown(this);\" onmouseup=\"mouseup(this);\"  title='Click to expand/contract input size' onclick=\"javascript:textZoom('" + el + "');\" align=absmiddle>");


}
// You can erase getTestSelection():	It's here for debug purposes only
function getTestSelection(txtarea) {
    if (document.all) {
        return document.selection.createRange().text;
    } else if (document.getElementById) {
        var selLength = txtarea.textLength;
        var selStart = txtarea.selectionStart;
        var selEnd = txtarea.selectionEnd;
        if (selEnd == 1 || selEnd == 2) selEnd = selLength;
        return (txtarea.value).substring(selStart, selEnd);
    }
}

function getMozSelection() {
    return document.getSelection();
}

// IE only - stores the current cursor position on any textarea activity
function storeCaret(txtarea) {
    if (txtarea.createTextRange) {
        txtarea.caretPos = document.selection.createRange().duplicate();
    }
}

// IE only - wraps selected text with lft and rgt
function WrapIE(lft, rgt) {
    strSelection = document.selection.createRange().text;
    if (strSelection != "") {
        document.selection.createRange().text = lft + strSelection + rgt;
    }
}

// Moz only - wraps selected text with lft and rgt
function wrapMoz(txtarea, lft, rgt) {
    var selLength = txtarea.textLength;
    var selStart = txtarea.selectionStart;
    var selEnd = txtarea.selectionEnd;
    if (selEnd == 1 || selEnd == 2) selEnd = selLength;
    var s1 = (txtarea.value).substring(0, selStart);
    var s2 = (txtarea.value).substring(selStart, selEnd)
    var s3 = (txtarea.value).substring(selEnd, selLength);
    txtarea.value = s1 + lft + s2 + rgt + s3;
}

// Chooses technique based on browser
function wrapTag(txtarea, lft, rgt) {
    lft = unescape(lft);
    rgt = unescape(rgt);
    if (document.all) {
        WrapIE(lft, rgt);
    }
    else if (document.getElementById) {
        wrapMoz(txtarea, lft, rgt);
    }
}

// Get a link via a prompt and wrap selected text
function wrapWithLink(txtarea) {
    var selText = "";
    if (document.all)
        selText = document.selection.createRange().text;
    else if (document.getElementById) {
        var selLength = txtarea.textLength;
        var selStart = txtarea.selectionStart;
        var selEnd = txtarea.selectionEnd;
        if (selEnd == 1 || selEnd == 2) selEnd = selLength;
        selText = (txtarea.value).substring(selStart, selEnd);
    }

    //alert(selText);

    var prompttext = "http://";
    if ((selText.indexOf("http:") == 0) || (selText.indexOf("https:") == 0)) {
        prompttext = selText;
    }
    var my_link = prompt("URL:", prompttext);
    if (my_link != null) {
        lft = "<a href=\"" + my_link + "\">";
        rgt = "</a>";
        wrapTag(txtarea, lft, rgt);
    }
    return;
}

// IE only - Insert text at caret position or at start of selected text
function insertIE(txtarea, text) {
    if (txtarea.createTextRange && txtarea.caretPos) {
        var caretPos = txtarea.caretPos;
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + caretPos.text + ' ' : text + caretPos.text;
    } else {
        txtarea.value = txtarea.value + text;
    }
    return;
}

// Moz only - Insert text at caret position or at start of selected text
function insertMoz(txtarea, lft) {
    var rgt = "";
    wrapTag(txtarea, lft, rgt);
    return;
}

// Switch function based on browser - Insert text at caret position or at start of selected text
function insertTag(txtarea, lft) {
    if (document.all) {
        insertIE(txtarea, lft);
    }
    else if (document.getElementById) {
        insertMoz(txtarea, lft);
    }
}

// prompt for image name. Insert image at caret position or at start of selected text
function insertImage(txtarea) {
    var my_link = prompt("IMG URL:", "http://");
    if (my_link != null) {
        lft = "<img src=\"" + my_link + "\" />";
        insertTag(txtarea, lft);
    }
    return;
}

// End Processing code.

/*
written by meg hourihan
http://www.megnut.com
meg@megnut.com
  
warning: it only works for IE4+/Win and Moz1.1+
feel free to take it for your site
but leave this text in place.
any problems, let meg know.
*/

function mouseover(el) {
    el.className = "raise";
}

function mouseout(el) {
    el.className = "buttons";
}

function mousedown(el) {
    el.className = "press";
}

function mouseup(el) {
    el.className = "raise";
}
/* end meg script */

var searchshowing = false;
var previouscontent = "";

var lightboxshowing = false;
var lasty = 0;
var lastcontentdiv;
var disablescroll = false;
function stopScroll() {
    if (disablescroll)
        window.scrollTo(0, 0);
}
function shLb(contentdiv) {
    if (contentdiv)
        lastcontentdiv = contentdiv;
    var el = document.getElementById("lightbox");
    var el2 = document.getElementById("lightboxcontent");
    if (lightboxshowing) {
        if (document.getElementById(lastcontentdiv)) {
            document.getElementById(lastcontentdiv).innerHTML = el2.innerHTML;
        }
        el2.innerHTML = '';
        lightboxshowing = false;
        el.className = "";
        document.getElementById('fade').style.display = 'none';
        el.style.display = 'none';
        window.scrollTo(0, lasty);
        disablescroll = false;
    } else {
        document.getElementById('fade').style.display = 'block';
        el.className = 'white_content';
        el.style.display = 'block';
        if (document.getElementById(contentdiv)) {
            el2.innerHTML = document.getElementById(contentdiv).innerHTML;
            document.getElementById(contentdiv).innerHTML = '&nbsp;';
        } else {
            el2.innerHTML = contentdiv;
        }
        lightboxshowing = true;
        lasty = getYPosition();
        window.scrollTo(0, 0);
        disablescroll = true;
        window.onscroll = stopScroll;
    }
}
var lastonclick = null;
function showSearchForm(tbl) {
    var el = document.getElementById("searchpanel");
    if (searchshowing) {
        searchshowing = false;
        el.className = "";
        document.getElementById('fade').style.display = 'none';
        el.style.display = 'none';
        el.innerHTML = previouscontent;
        try {
            document.getElementById("deletebutton").onclick = lastonclick;
        } catch (e) { }
    } else {
        previouscontent = el.innerHTML;
        document.getElementById('fade').style.display = 'block';
        el.className = 'white_content';
        el.style.display = 'block';
        document.getElementById("searchpanel").innerHTML = "<div style='text-align:right;padding-top:0'><a href='' onclick=\"return showSearchForm('" + tbl + "');\"><img width=\"16\" height=\"16\" align=\"absmiddle\" src=\"/icons/crystal_project/32x32/actions/cancel.png\"/> close</a></div><div id='searchpanel2'></div>";
        getContent('table.aspx?t=v_searchfields&pagesize=150&_tablename=' + tbl, 'searchpanel2', true, '<br /><center><img src=/images/ajax-loader.gif align=absmiddle> loading search form...<br /><br /></center>');
        try {
            lastonclick = document.getElementById("deletebutton").onclick;            
        document.getElementById("deletebutton").onclick = null;
        }catch(e){}
        searchshowing = true;
    }
    return false;
}
var lastColorUsed;
function prettyDG_changeBackColor(row, highlight) {
    if (highlight) {
        lastColorUsed = row.className;
        row.className = 'highlight';
    }
    else
        row.className = lastColorUsed;
}

function getSuggestions(elementgroup, t) {
    //need to pass in the value of the box
    //need to add a filter on the search that has startswith	
    //add t_headerfooter for view 17 that has nothing for header or footer	
    var val = document.getElementById(elementgroup + 'box').value;
    if (val == '')
        return;
    var left = document.getElementById(elementgroup + 'box').style.left;
    var top = document.getElementById(elementgroup + 'box').style.top;
    document.getElementById(elementgroup + 'suggestions').style.border = "solid 1px black";
    document.getElementById(elementgroup + 'suggestions').style.background = "white";
    document.getElementById(elementgroup + 'suggestions').style.top = top;
    document.getElementById(elementgroup + 'suggestions').style.left = left;
    document.getElementById(elementgroup + 'suggestions').style.position = "absolute";
    document.getElementById(elementgroup + 'suggestions').style.width = "30em";
    document.getElementById(elementgroup + 'suggestions').style.overflow = "auto";
    getContent('table.aspx?t=' + t + '&vid=17&nameop=startswith&namequery=' + val + '&ELEMENT_NAME=' + elementgroup + '&orderby=name', elementgroup + 'suggestions', true);
}
function makeSelection(id, displaytext, elementgroup) {
    document.getElementById(elementgroup + 'box').value = displaytext;
    document.getElementById(elementgroup + 'suggestions').innerHTML = '';
    document.getElementById(elementgroup).value = id;
    document.getElementById(elementgroup + 'suggestions').style.border = "solid 0px black";
}
function addMenu(sc, qs, menuname, menuid) {
    try {
        document.Form1.__VIEWSTATE.value = '';
        document.Form1.__VIEWSTATE.name = '__IGNORE';
        document.Form1.__EVENTTARGET.value = '';
        document.Form1.__EVENTTARGET.name = '__IGNORE2';
        document.Form1.__EVENTARGUMENT.value = '';
        document.Form1.__EVENTARGUMENT.name = '__IGNORE3';
    } catch (e) { }
    document.Form1.action = 'addmenu.aspx?sc=' + sc + '&' + qs + '&_menuname=' + encodeURIComponent(menuname) + '&_menuid=' + menuid;
    document.Form1.method = 'post';
    document.Form1.submit();
}
function updateValues(table, field, value, valuename) {
    if (!valuename)
        valuename = value;

    if (confirm("Update the checked items " + field + " field to " + valuename + "?")) {
        for (var i = 0; i < document.Form1.id.length; i++) {
            if (document.Form1.id[i].checked) {
                getContent('savedesign.aspx?t=' + table + '&id=' + escape(document.Form1.id[i].value) + '&f=' + escape(field) + '&v=' + escape(value) + '&o=3');
                //alert('savedesign.aspx?t=' + table + '&id=' + document.Form1.id[i].value + '&f=' + field + '&v=' + value + '&o=3');
            }
        }
        document.location.href = document.location.href;
    }
}
var EXECUTE_SUCCESS = 'Changes applied successfully.'
function updateValue(table, field, id, value) {
    var test = getUrlString('savedesign.aspx?t=' + table + '&f=' + field + '&v=' + value + '&id=' + id + '&o=3');
    return test;
}
function executeUrl(url) {
    var test = getUrlString(url + '&_INDICATESUCCESS=true');
    return test;
}


function getMouse(e) {
    var scrollLeft;
    var scrollTop;
    if (typeof e == 'undefined') {
        if (document.documentElement) if (document.documentElement.scrollTop) {
            scrollLeft = document.documentElement.scrollLeft;
            scrollTop = document.documentElement.scrollTop;
        }
        else {
            scrollLeft = document.body.scrollLeft;
            scrollTop = document.body.scrollTop;
        }

        mouseX = event.clientX + scrollLeft;
        mouseY = event.clientY + scrollTop;
    }
    else {
        mouseX = e.pageX;
        mouseY = e.pageY;
    }

    return { 'x': mouseX, 'y': mouseY };
}
function mouseMove(e) {
    var m = getMouse(e);
    window.status = 'Current mouse position:  x=' + m.x + ', y=' + m.y;
}

function getYPosition() {
    var yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {
        // all other Explorers
        yScroll = document.body.scrollTop;
    }
    this.yPos = yScroll;
    return yScroll;
}