﻿/// <reference name="MicrosoftAjax.js"/>

/////////////////////////////////
//Global variable declarations//
///////////////////////////////

var regId = null,
    codeQues = null,
    attending = false,
    totalCost = 0,
    requiredItems = [],
    columnNamesUI = [],
    firstUIPosition = 13,
    hasMissingItems = false,
    missingItems = null,
    hasFileInfo = false,
    hasFileAgenda = false,
    hasFilePrintReg = false,
    emailRegConfirm = false,
    hasSetAttendance = false,
    hasRegistrants = false;
    bActivateEmail = false,
    okToSubmit = true,
    theForm = document.forms['frm1'];

//////////////////////////////
//Global variables for     // 
//Cross Browser and OnLoad//
///////////////////////////

var win = window,
    doc = document,
    nav = navigator,
    timer = null,
    isDomLoaded = false,
    domLoadFnArr = new Array();

///////////////////////////
//Cross Browser wrappers//
/////////////////////////

function getInnerText(ctrl) {
    if (document.all) { //IE only
        return ctrl.innerText;
    } else {
        return ctrl.textContent;
    }
}

function setInnerText(ctrl, value) {
    if (document.all) {
        ctrl.innerText = value;
    } else {
        ctrl.textContent = value
    }
}

function getEventSrcElement(event) {
    if (document.all) {
        return event.srcElement;
    } else {
        return event.target;
    }
}

function fireClickEvent(ctrl) {
    if (document.all) {
        ctrl.fireEvent('onclick');
    } else {
        var clickEvent = window.document.createEvent('MouseEvent');
        clickEvent.initEvent('click', false, true);
        ctrl.dispathEvent(clickEvent);
    }
}

function getWindowHeight() {
    if (document.all) {
        return document.body.offsetHeight;
    } else {
        var hgt = window.getBoundingClientRect();
        return hgt.height;
    }
}

function getWindowWidth() {
    if (document.all) {
        return document.body.offsetWidth;
    } else {
        var wdth = window.getBoundingClientRect();
        return wdth.width;
    }
}

////////////////////////////////
//Browser and DOM detection  //
//usage: ua.w3cdom ua.ie etc//
/////////////////////////////

var ua = function() {
    var w3cdom = typeof doc.getElementById != 'undefined' &&
                 typeof doc.getElementsByTagName != 'undefined' &&
                 typeof doc.createElement != 'undefined' &&
                 typeof doc.appendChild != 'undefined' &&
                 typeof doc.replaceChild != 'undefined' &&
                 typeof doc.removeChild != 'undefined' &&
                 typeof doc.cloneNode != 'undefined';

    var u = nav.userAgent.toLowerCase(),
        p = nav.platform.toLowerCase(),
        webkit = /webkit/.test(u) ? parseFloat(u.replace(/^.*webkit\/(d+(\.\d+)?).*$/, "$1")) : false,
        ie = false,
        windows = p ? /win/.test(p) : /win/.test(u),
        mac = p ? /mac/.test(p) : /mac/.test(u);

    /*@cc_on
    ie = true;
    @if (@_win32)
    windows = true;
    @elif (@ mac)
        mac = true;
        @end
    @*/
    return { w3cdom: w3cdom, webkit: webkit, ie: ie, win: windows, mac: mac };
} ();

//////////////////////////////
//Wait for DOM loaded event//
////////////////////////////

var onDomLoad = function() {
    if (!ua.w3cdom) {
        return;
    }
    ///////////////////////////////////
    //////////////////////////////////
    ////Add OnLoad Function Loader///
    ////////////////////////////////
    addDomLoadEvent(jwInit); ///////
    //////////////////////////////
    /////////////////////////////

    if (ua.ie && ua.win) {
        try  {
            doc.write('<scr' + 'ipt id=__ie_ondomload defer=true src=//:></scr' + 'ipt>');
            var s = doc.getElementById('__ie_ondomload');
            if (s) {
                s.onreadystatechange = function() {
                    if (this.readyState == 'complete') {
                        this.parentNode.removeChild(this);
                        callDomLoadFunctions();
                    }
                };
            }
        } catch (e) { }
    }

    if (ua.webkit && typeof doc.readyState != 'undefined') {
        timer = setInterval(function() {
            if (/loaded|complete/.test(doc.readyState)) {
                callDomLoadFunctions();
            }
        }, 10);
    }

    if (typeof doc.addEventListener != 'undefined') {
        doc.addEventListener('DOMContentLoaded', callDomLoadFunctions, null);
    }

    addLoadEvent(callDomLoadFunctions);
} ();

//////////////////////////
//Add OnLoad functions //
//to Event Daisy Chain// 
///////////////////////    

function callDomLoadFunctions() {
    if (isDomLoaded) {
        return;
    }
    if (ua.ie && ua.win) {
        var s = doc.createElement('span');
        try {
            var t = doc.getElementsByTagName('body')[0].appendChild(s);
            t.parentNode.removeChild(t);
        } catch (e) { 
            return;
        }
    }
    isDomLoaded = true;
    if (timer) {
        clearInterval(timer);
        timer = null;
    }
    var dl = domLoadFnArr.length;
    for (var i = 0; i < dl; i++) {
        domLoadFnArr[i]();
    }
}

///////////////////////////////////
//Add DOM OnLoad Event          //
//If DOM not ready add to array//
////////////////////////////////

function addDomLoadEvent(fn) {
    if (isDomLoaded) {
        fn();
    } else {
        domLoadFnArr[domLoadFnArr.length] = fn;
    }
}

/////////////////////////////////////////
//Cross Browser Attach to OnLoad Event//
///////////////////////////////////////

function addLoadEvent(fn) {
    if (typeof win.addEventListener != 'undefined') {
        win.addEventListener('load', fn, false);
    }
    else if (typeof doc.addEventListener != 'undefined') {
        doc.addEventListener('load', fn, false);
    }
    else if (typeof win.attachEvent != 'undefined') {
        win.attachEvent('onload', fn);
    }
    else if (typeof win.onload == 'function') {
        var fnOld = win.onload;
        win.onload = function() {
            fnOld();
            fn();
        };
    }
    else {
        win.onload = fn;
    }
}

////////////////////////////////
//JANWebs Page Initialization//
//////////////////////////////
function jwInit() {
    if (!theForm) {
        theForm = document.frm1;
    }
    focusOnFirstTextBox();
    fixTargetBlanks();
    initVars();
}

///////////////////////////////////////
//OnLoad Set Focus To First Text Box//
/////////////////////////////////////

function focusOnFirstTextBox() {
    if (document.getElementById('noFirstFocus') == null) {
        for (f = 0; f < document.forms.length; f++) {
            for (i = 0; i < document.forms[f].length; i++) {
                if (document.forms[f][i].type == 'text') {
                    if (document.forms[f][i].type.disabled != true) {
                        if (document.forms[f][i].readOnly != true) {
                            try {
                                document.forms[f][i].focus();
                                break;
                            } catch (e) { }
                        }
                    }
                }
            }
        }
    } 
}

///////////////////////////////////////////////////////////////////
//OnLoad - Initialize Xhtml1.1 Strict external links            //
//Usage: html - replace all target="_blank" with rel="external"// 
////////////////////////////////////////////////////////////////

function fixTargetBlanks() {
    if (!document.getElementsByTagName) {
        return;
    } else {
        var anchors = document.getElementsByTagName('a');
        for (var i=0; i < anchors.length; i++) {
            var anchor = anchors[i];
            if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external') {
                anchor.target = '_blank';
            }
        }
    }
}

/////////////////////////////////////////////
//OnLoad - Initialize all global variables//
///////////////////////////////////////////

function initVars() {
    hasSetAttendance = false;
    hasRegistrants = false;
    if (document.getElementById('nbrRegistrants') != null) { hasRegistrants = (parseInt(document.getElementById('nbrRegistrants').value)) > 0 ? true : false; }
    if (document.getElementById('toClient') != null) { regId = document.getElementById('toClient').value; }
    if (document.getElementById('codeQ') != null) { codeQues = document.getElementById('codeQ').value; }
    if (document.getElementById('requiredFields')) {
        var tmpReqItems = document.getElementById('requiredFields').value;
        requiredItems = tmpReqItems.split(',');
    }
    if (document.getElementById('toClientUIColumnNames') != null) {
        var tmpColNamesUI = document.getElementById('toClientUIColumnNames').value;
        columnNamesUI = tmpColNamesUI.split(',');
    }
    if (document.getElementById('chkAddEventInfo') != null) {
        if (document.getElementById('chkAddEventInfo').checked == true) {
            document.getElementById('pEventInfoDoc').style.display = '';
            hasFileInfo = true;
        } else {
            document.getElementById('pEventInfoDoc').style.display = 'none';
            hasFileInfo = false;
        }
    }
    if (document.getElementById('chkAddEventAgenda') != null) {
        if (document.getElementById('chkAddEventAgenda').checked == true) {
            document.getElementById('pEventAgendaDoc').style.display = '';
            hasFileAgenda = true;
        } else {
            document.getElementById('pEventAgendaDoc').style.display = 'none';
            hasFileAgenda = false;
        }
    }
    if (document.getElementById('chkAddEventPrintReg') != null) {
        if (document.getElementById('chkAddEventPrintReg').checked == true) {
            document.getElementById('pEventPrintRegDoc').style.display = '';
            hasFilePrintReg = true;
        } else {
            document.getElementById('pEventPrintRegDoc').style.display = 'none';
            hasFilePrintReg = false;
        }
    }
    if (document.getElementById('chkAddEventOnlineReg') != null && document.getElementById('chkAddEventOnlineReg').checked == true) { document.getElementById('pnlOnlineRegForm').style.display = ''; }
    if (document.getElementById('toClientUI') && document.getElementById('toClientUI').value.length > 0) {
        if (document.getElementById('pnlRegUserItems')) { document.getElementById('pnlRegUserItems').style.display = ''; }        
        var aryAllUI = document.getElementById('toClientUI').value.split('π');
        for (var iUI = 0; iUI < aryAllUI.length; iUI++) {
            var aryUI = aryAllUI[iUI].split('Γ');
            var order = '';
            var columnName = '';
            var receiptLabel = '';
            var prompt = '';
            var required = '';
            for (var i = 0; i < aryUI.length; i++) {
                var aryUIElem = aryUI[i].split('ß');
                switch (aryUIElem[0]) { //Left side of ß
                    case 'order':
                        order = aryUIElem[1]; //Right side of ß
                        break;
                    case 'columnName':
                        columnName = aryUIElem[1];
                        break;
                    case 'receiptLabel':
                        receiptLabel = aryUIElem[1];
                        break;
                    case 'prompt':
                        prompt = aryUIElem[1];
                        break;
                    case 'required':
                        required = aryUIElem[1];
                        break;
                    default:
                        break;
                }
            }
            onAddExistUI(order, columnName, receiptLabel, prompt, required);
        }
    }
    if (document.getElementById('toClientPI') != null && document.getElementById('toClientPI').value.length > 0) {
        if (document.getElementById('pnlRegPayItems')) { document.getElementById('pnlRegPayItems').style.display = ''; }        
        var aryAllPI = document.getElementById('toClientPI').value.split('π');
        for (var iPI = 0; iPI < aryAllPI.length; iPI++) {
            var aryPI = aryAllPI[iPI].split('Γ');
            var piOrder = '';
            var piColumnName = '';
            var piReceiptLabel = '';
            var piPrompt = '';
            var piCost = '';
            var piVisible = '';
            for (var i = 0; i < aryPI.length; i++) {
                var aryPIElem = aryPI[i].split('ß');
                switch (aryPIElem[0]) { //Left side of ß
                    case 'order':
                        piOrder = aryPIElem[1]; //Right side of ß
                        break;
                    case 'columnName':
                        piColumnName = aryPIElem[1];
                        break;
                    case 'receiptLabel':
                        piReceiptLabel = aryPIElem[1];
                        break;
                    case 'prompt':
                        piPrompt = aryPIElem[1];
                        break;
                    case 'cost':
                        piCost = aryPIElem[1];
                        break;
                    case 'visible':
                        piVisible = aryPIElem[1];
                        break;
                    default:
                        break;
                }
            }
            onAddExistPI(piOrder, piColumnName, piReceiptLabel, piPrompt, piCost, piVisible);
        }
    }
    if (document.getElementById('chkActivities') != null && document.getElementById('chkActivities').checked == true) { document.getElementById('pnlEventActivities').style.display = ''; }
    if (document.getElementById('chkAddEventContact') != null && document.getElementById('chkAddEventContact').checked == true) {
        document.getElementById('lblAddEventContact').style.display = '';
        document.getElementById('txtAddEventContact').style.display = '';
    }
    if (document.getElementById('chkRegReservations') != null && document.getElementById('chkRegReservations').checked == true) { document.getElementById('pnlRegReservations').style.display = ''; }
    if (document.getElementById('chkRegRSVP') != null && document.getElementById('chkRegRSVP').checked == true) { document.getElementById('pnlRegRSVP').style.display = ''; }
    if (document.getElementById('chkRegPayItems') != null && document.getElementById('chkRegPayItems').checked == true) { document.getElementById('pnlRegPayItems').style.display = ''; }
    if (document.getElementById('chkRegUserComments') != null && document.getElementById('chkRegUserComments').checked == true) { document.getElementById('pnlUserComments').style.display = ''; }
    
    if (document.getElementById('chkActivateEmail') != null) {
        if (document.getElementById('chkActivateEmail').checked == true) {
            document.getElementById('pnlActivateEmail').style.display = '';
            bActivateEmail = true;
        } else {
            document.getElementById('pnlActivateEmail').style.display = 'none';
            bActivateEmail = false;
        }
    }
    if (document.getElementById('rblAttend_0') != null && document.getElementById('rblAttend_1') != null) {
        if (document.getElementById('rblAttend_0').checked == true) {
            hasSetAttendance = true;
            attending = true;
        }
        if (document.getElementById('rblAttend_1').checked == true) {
            hasSetAttendance = true;
            attending = false;
        }
        if (hasSetAttendance) {
            if (document.getElementById('payTable_totalDue') != null) {
                totalCost = document.getElementById('payTable_totalDue').value;
            }
        } else {
            totalCost = 0;
        }
    }
    if (document.getElementById('toClientAmmend') != null) {
        if (document.getElementById('toClientAmmend').value == 'true') {
            alert('Please complete your changes as needed.\n\nYou will need to re-select your attendance status and event options before submitting your changes.\nEvent options are found in the lower section of the registration form and have a cost associated.');
        }
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////// MAIN PAGE PROCESSING /////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Alert Timeouts
function onAlertTimerDone() {
    if (document.getElementById("eventPDFError") != null) { setInnerText(document.getElementById('eventPDFError'), ''); }
    if (document.getElementById('eventPDFMsgInfo') != null) { setInnerText(document.getElementById('eventPDFMsgInfo'), ''); }
    if (document.getElementById('eventPDFMsgAgenda') != null) { setInnerText(document.getElementById('eventPDFMsgAgenda'), ''); }
    if (document.getElementById('eventPDFMsgPrintReg') != null) { setInnerText(document.getElementById('eventPDFMsgPrintReg'), ''); }    
}

//Timer for Alert Messages to turn off
function startAlertTimer() {
    setTimeout(onAlertTimerDone, 5000);
}

//Admin Event variables
var sendEmail = false;

function onPayItemCheckClick(checked, item) {
    var itemCost = parseFloat(getInnerText(document.getElementById('payTableCostCol_item_' + item)));        
    if (checked == true) {
        document.getElementById('payTableSelCol_item_' + item).checked = true;
        totalCost += itemCost;
    } else {
        document.getElementById('payTableSelCol_item_' + item).checked = false;
        totalCost -= itemCost;
    }
    setInnerText(document.getElementById('payTable_totalDue'), formatAsCurrency(totalCost));
}

function formatAsCurrency(amount) {
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i.toFixed(2));
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

function onRegister() {
    //ß = <alt>225, Γ = <alt>226
    if (hasSetAttendance == false) {
        alert('Your registration cannot be submitted without first selecting your attendance option. Please select either the \'Yes\' or \'No\' Option and then re-submit your registration.\n\nThank you.');
        if (document.getElementById('rblAttend_0') != null) { document.getElementById('rblAttend_0').focus(); }
        return;
    }
    var itemCount = parseInt(document.getElementById('itemCount').value);
    document.getElementById('payItems').style.display = ''
    var payItems = document.getElementById('payItems').value;
    var strBuild = '';
    var toServer = document.getElementById('fromClient');
    
    //Validate admin provided required Fields
    var itemReqText = '';
    var itemReqId = '';
    hasMissingItems = false;
    missingItems = '';
    //Test for system supplied required fields missing data
    if (document.getElementById('txtFName').value.length == 0) { missingItems += 'txtFName' + ','; }
    if (document.getElementById('txtLName').value.length == 0) { missingItems += 'txtLName' + ','; }
    if (document.getElementById('txtUserAddress').value.length == 0) { missingItems += 'txtUserAddress' + ','; }
    if (document.getElementById('txtUserCity').value.length == 0) { missingItems += 'txtUserCity' + ','; }
    if (document.getElementById('txtUserPhone').value.length == 0) { missingItems += 'txtUserPhone' + ','; }
    if (document.getElementById('txtUserEmail').value.length == 0) { missingItems += 'txtUserEmail' + ','; }
    for (intReqItem = 0; intReqItem < itemCount; intReqItem++) {
        itemReqId = 'itemText_' + (intReqItem + 1).toString();
        for (intX = 0; intX < requiredItems.length; intX++) {
            if (requiredItems[intX] == itemReqId) {
                if (document.getElementById(itemReqId).value.length == 0) {
                    missingItems += 'itemText_' + (intReqItem + 1).toString() + ',';
                    hasMissingItems = true;
                }
            }
        }
    }
    if (missingItems.substring((missingItems.length - 1)) == ',') { missingItems = missingItems.substring(0, (missingItems.length - 1)); }
    
    //Fixed Fields generated by System
    strBuild += 'eventId' + 'ß' + regId + 'Γ';  //regValue[0] eventId
    var tmpRegistrantId = document.getElementById('toClientRegistrantId');
    strBuild += 'registrantID' + 'ß';  
    strBuild += (tmpRegistrantId != null && tmpRegistrantId.value.length == 17) ? tmpRegistrantId.value : getTimeStamp();
    strBuild += 'Γ'; //regValue[1] registrantId
    strBuild += 'registrantFName' + 'ß' + document.getElementById('txtFName').value + 'Γ';  //regValue[2] regFName
    strBuild += 'registrantLName' + 'ß' + document.getElementById('txtLName').value + 'Γ';  //regValue[3] regLName
    strBuild += 'registrantAddress' + 'ß' + document.getElementById('txtUserAddress').value + 'Γ';  //regValue[4] regAddress
    strBuild += 'registrantCity' + 'ß' + document.getElementById('txtUserCity').value + 'Γ';  //regValue[5] regCity
    strBuild += 'registrantState' + 'ß' + document.getElementById('ddlUserState').options[document.getElementById('ddlUserState').selectedIndex].text + 'Γ';  //regValue[6] regState
    strBuild += 'registrantZip' + 'ß' + document.getElementById('txtUserZip').value + 'Γ';  //regValue[7] regZip
    strBuild += 'registrantPhone' + 'ß' + document.getElementById('txtUserPhone').value + 'Γ';  //regValue[8] regPhone
    strBuild += 'registrantEmail' + 'ß' + document.getElementById('txtUserEmail').value + 'Γ';  //regValue[9] regEmail    
    var tmpAttend = (attending) ? 'Yes' : 'No';
    strBuild += 'attending' + 'ß' + tmpAttend + 'Γ';  //regValue[10] Attending (true|false)
    strBuild += 'amountDue' + 'ß' + formatAsCurrency(totalCost) + 'Γ';  //regValue[11] ammountDue
    if (document.getElementById('codeQuestions') != null) {
        if (document.getElementById('codeQuestions').value.length > 0) {
            strBuild += 'codeQuestions' + 'ß' + document.getElementById('codeQuestions').value + 'Γ'; //regValue[12] Code questions comments
        } else {
            strBuild += 'codeQuestions' + 'ß' + '\u0020' + 'Γ';    //regValue[12] Code questions comments
        }
    }

    //Add user provided text starting with regValue[13] - 14th element
    var itemInText = '';
    for (intItem = (firstUIPosition - 1); intItem < itemCount + (firstUIPosition - 1); intItem++) {
        if (document.getElementById('itemText_' + (intItem + 1).toString()) != null) {
            itemInText = document.getElementById('itemText_' + (intItem + 1).toString()).value;
            itemInText = (itemInText.length == 0) ? '\u0020' : itemInText;
            strBuild += columnNamesUI[intItem - (firstUIPosition - 1)] + 'ß' + itemInText + 'Γ';
        }
    }
    //Add Pay Items Selected by user
    //Add payable item section starting with regValues[] and order= (firstUIPosition -1) + itemCount + 1]
    if (payItems != null) {
        sPayItems = payItems.split(','); //Holds columnNames for pay items
        for (var intPayItem = (firstUIPosition - 1) + itemCount; intPayItem < (firstUIPosition - 1) + itemCount + sPayItems.length; intPayItem++) {
            if (document.getElementById('payTableSelCol_item_' + (intPayItem + 1).toString()) != null) {
                if (document.getElementById('payTableSelCol_item_' + (intPayItem + 1).toString()).checked == true) {
                    strBuild += sPayItems[intPayItem - ((firstUIPosition - 1) + itemCount)] + '_state_true' + 'ß' + getInnerText(document.getElementById('payTableCostCol_item_' + (intPayItem + 1).toString())) + 'Γ';
                } else {
                    strBuild += sPayItems[intPayItem - ((firstUIPosition - 1) + itemCount)] + '_state_false' + 'ß' + getInnerText(document.getElementById('payTableCostCol_item_' + (intPayItem + 1).toString())) + 'Γ';
                }
            }
        }
    }
    strBuild = strBuild.substring(0, (strBuild.length-1));
   
    //Submit user data to server
    if (hasMissingItems == true) {
        var msngItems = missingItems.split(',');
        var labelItem = '';
        for (var i = 0; i < msngItems.length; i++) {
            var msngItem = msngItems[i];
            if (msngItem.substring(0, 3) == 'txt') {
                document.getElementById('lbl' + msngItem.substring(3)).style.color = '#ff0000';
                if (i == 0) { document.getElementById(msngItem).focus(); }
            } else {
                var msngItemParse = msngItem.substring(msngItem.lastIndexOf('_') + 1);
                labelItem = document.getElementById('itemLabel_' + msngItemParse);
                labelItem.style.color = '#ff0000';
                if (i == 0) {
                    document.getElementById('itemText_' + msngItemParse).focus();
                }
            }
        }
        alert('Registration submission was not successful.\nSome information is required before submission.\n\nPlease provide the information highlighted RED.');
    } else {
        toServer.value = strBuild;
        theForm.submit();
    }
}

function onRegCancel(urlHost) {
    if (document.getElementById('toClientAmmend') != null) {
        if (document.getElementById('toClientAmmend').value == 'true') {
            document.getElementById('fromClient').value = 'CancelMe';
            theForm.submit();
        } else {
            if (confirm('This action will clear all information provided so far. Nothing will be submitted.\n\nOK to continue?')) {
                if (location.href.indexOf("localhost") != -1) {
                    window.location.href = 'events.aspx';
                } else {
                    window.location.href = 'http://' + document.getElementById('currentHost').value + '/events.aspx';
                }
            }
        }
    }
}

function onAttendingChange(bolAttend) {
    if (hasSetAttendance) {
        if (confirm('Changing your attendance status will clear any payable items you have selected.\nPayable items are those items with a cost and are found on the lower portion of this form.\nBe sure to select your payable items again.\n\nOK to continue?')) {
            document.getElementById('payTable_totalDue').innerText = formatAsCurrency(0);
            totalCost = 0.00;
            var pItems = document.getElementById('payItems').value;
            var spItems = pItems.split(',');
            var firstPI = (firstUIPosition - 1) + parseInt(document.getElementById('itemCount').value);
            for (var iPCnt = firstPI; iPCnt < firstPI + spItems.length; iPCnt++) {
                if (document.getElementById('payTable_item_' + (iPCnt + 1).toString())) {
                    var pItem = document.getElementById('payTable_item_' + (iPCnt + 1).toString());
                    pItem.checked = false;
                }
            }
        } else {
            if (bolAttend == true) {
                bolAttend = false;
                document.getElementById('rblAttend_1').checked = true;
            } else {
                bolAttend = true;
                document.getElementById('rblAttend_0').checked = true;
            }
        }
    }
    hasSetAttendance = true;
    attending = bolAttend;
    if (document.getElementById('payItems') != null) {
        var payRadioItems = document.getElementById('payItems').value;
        var sPayRadioItems = payRadioItems.split(',');
        var firstPItem = (firstUIPosition - 1) + parseInt(document.getElementById('itemCount').value);
        for (var intPayRadioCnt = firstPItem; intPayRadioCnt < sPayRadioItems.length + firstPItem; intPayRadioCnt++) {
            if (document.getElementById('payTable_Row_' + (intPayRadioCnt + 1).toString()) != null) {
                if (document.getElementById('payTable_Row_' + (intPayRadioCnt + 1).toString()).attributes['attend'] != null) {
                    if (attending) {
                        switch (document.getElementById('payTable_Row_' + (intPayRadioCnt + 1).toString()).attributes['attend'].value) {
                            case 'true':
                                document.getElementById('payTable_Row_' + (intPayRadioCnt + 1).toString()).style.display = '';
                            case 'always':
                                document.getElementById('payTable_Row_' + (intPayRadioCnt + 1).toString()).style.display = '';
                                break;
                            case 'false':
                                document.getElementById('payTable_Row_' + (intPayRadioCnt + 1).toString()).style.display = 'none';
                                break;
                            default:
                                break;
                        }
                    } else {
                        switch (document.getElementById('payTable_Row_' + (intPayRadioCnt + 1).toString()).attributes['attend'].value) {
                            case 'false':
                                document.getElementById('payTable_Row_' + (intPayRadioCnt + 1).toString()).style.display = '';
                                break;
                            case 'always':
                                document.getElementById('payTable_Row_' + (intPayRadioCnt + 1).toString()).style.display = '';
                                break;
                            case 'true':
                                document.getElementById('payTable_Row_' + (intPayRadioCnt + 1).toString()).style.display = 'none';
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
        }
    }
}

//Add Event Info Link
function addEventInfoChg() {
    if (document.getElementById('chkAddEventInfo').checked == true) {
        document.getElementById('asyncFileUploadInfo').style.display = '';
    } else {
        if (hasFileInfo) {
            if (confirm('Removing this option will delete a file previously uploaded.\n\nAdding this option in the future will require another file to be uploaded.\n\nOK To Continue?')) {
                document.getElementById('fileAction').value += 'info.delete,';
            } else {
                document.getElementById('chkAddEventInfo').checked = true;            
            }
        }
        document.getElementById('asyncFileUploadInfo').style.display = 'none';    
    }
}

function eventPDFUploadedInfo(sender, args) {
    var fName = args.get_fileName().toLowerCase();
    var contentType = args.get_contentType();
    var text = fName + ' uploaded successfully.\n' + args.get_length() + " bytes";
    document.getElementById('eventPDFMsgInfo').style.display = '';
    if (fName.substring(fName.lastIndexOf('.') + 1) != 'pdf') {
        alert(fName + ' is not a PDF file.\nFile not saved.\nPlease upload only PDF files.');
        hasFileInfo = false;
    } else {
        if (contentType.length > 0) {
            text += " of type: '" + contentType + "'";
        }
        document.getElementById('eventPDFMsgInfo').style.color = 'black';
        hasFileInfo = true;
    }
    setInnerText(document.getElementById('eventPDFMsgInfo'), text);
    startAlertTimer();
    
}

function eventPDFUploadErrorInfo() {
    document.getElementById('eventPDFMsgInfo').style.display = '';
    setInnerText(document.getElementById('eventPDFMsgInfo'), args.get_fileName() + " " + args.get_errorMessage() + " ");
    document.getElementById('eventPDFMsgInfo').style.color = 'red';
    startAlertTimer();
}

//Add Event Agenda Link
function addEventAgendaChg() {
    if (document.getElementById('chkAddEventAgenda').checked == true)
    {
        document.getElementById('asyncFileUploadAgenda').style.display = '';
    } else {
        if (hasFileAgenda) {
            if (confirm('Removing this option will delete a file previously uploaded.\n\nAdding this option in the future will require another file to be uploaded.\n\nOK To Continue?')) {
                document.getElementById('fileAction').value += 'agenda.delete,';
            } else {
                document.getElementById('chkAddEventAgenda').checked = true;            
            }
        }
        document.getElementById('asyncFileUploadAgenda').style.display = 'none';
    }
}

function eventPDFUploadedAgenda(sender, args) {
    var fName = args.get_fileName().toLowerCase();
    var contentType = args.get_contentType();
    var text = fName + ' uploaded successfully.\n' + args.get_length() + " bytes";
    document.getElementById('eventPDFMsgAgenda').style.display = '';
    if (fName.substring(fName.lastIndexOf('.') + 1) != 'pdf')
    {
        alert(fName + ' is not a PDF file.\nFile not saved.\nPlease upload only PDF files.');
        hasFileAgenda = false;
    } else
    {
        if (contentType.length > 0)
        {
            text += " of type: '" + contentType + "'";
        }
        document.getElementById('eventPDFMsgAgenda').style.color = 'black';
        hasFileAgenda = true;
    }
    setInnerText(document.getElementById('eventPDFMsgAgenda'), text);
    startAlertTimer();
}

function eventPDFUploadErrorAgenda() {
    document.getElementById('eventPDFMsgAgenda').style.display = '';
    setInnerText(document.getElementById('eventPDFMsgAgenda'), args.get_fileName() + " " + args.get_errorMessage() + " ");
    document.getElementById('eventPDFMsgAgenda').style.color = 'red';
    startAlertTimer();
}

//Add Event Printable Registration Link
function addEventPrintRegChg() {
    if (document.getElementById('chkAddEventPrintReg').checked == true)
    {
        document.getElementById('asyncFileUploadPrintReg').style.display = '';
    } else {
        if (hasFilePrintReg) {
            if (confirm('Removing this option will delete a file previously uploaded.\n\nAdding this option in the future will require another file to be uploaded.\n\nOK To Continue?')) {
                document.getElementById('fileAction').value += 'printReg.delete,';
            } else {
                document.getElementById('chkAddEventPrintReg').checked = true;            
            }
        }
        document.getElementById('asyncFileUploadPrintReg').style.display = 'none';
    }
}

function eventPDFUploadedPrintReg(sender, args) {
    var fName = args.get_fileName().toLowerCase();
    var contentType = args.get_contentType();
    var text = fName + ' uploaded successfully.\n' + args.get_length() + " bytes";
    document.getElementById('eventPDFMsgPrintReg').style.display = '';
    if (fName.substring(fName.lastIndexOf('.') + 1) != 'pdf')
    {
        alert(fName + ' is not a PDF file.\nFile not saved.\nPlease upload only PDF files.');
        hasFilePrintReg = false;
    } else
    {
        if (contentType.length > 0)
        {
            text += " of type: '" + contentType + "'";
        }
        document.getElementById('eventPDFMsgPrintReg').style.color = 'black';
        hasfilePrintReg = true;
    }
    setInnerText(document.getElementById('eventPDFMsgPrintReg'), text);
    startAlertTimer();
}

function eventPDFUploadErrorPrintReg() {
    document.getElementById('eventPDFMsgPrintReg').style.display = '';
    setInnerText(document.getElementById('eventPDFMsgPrintReg'), args.get_fileName() + " " + args.get_errorMessage() + " ");
    document.getElementById('eventPDFMsgPrintReg').style.color = 'red';
    startAlertTimer();
}

//Link to Online Registration
function addEventOnlineRegChg() {
    if (document.getElementById('chkAddEventOnlineReg').checked == true) {
        document.getElementById('pnlOnlineRegForm').style.display = '';
        if (document.getElementById('txtAdminEmail').value == '' && document.getElementById('txtAddEventContact').value != '') { document.getElementById('txtAdminEmail').value = document.getElementById('txtAddEventContact').value; }
        if (document.getElementById('txtRegEventTitle').value == '' && document.getElementById('txtEventTitle').value != '') { document.getElementById('txtRegEventTitle').value = document.getElementById('txtEventTitle').value; }
        if (document.getElementById('txtRegFacility').value == '' && document.getElementById('txtEventFacility').value != '') { document.getElementById('txtRegFacility').value = document.getElementById('txtEventFacility').value; }
        if (document.getElementById('txtRegCity').value == '' && document.getElementById('txtEventCity').value != '') { document.getElementById('txtRegCity').value = document.getElementById('txtEventCity').value; }
        if (document.getElementById('DropDownListState2').selectedIndex.text == '' && document.getElementById('DropDownListState').selectedIndex.text != '') { document.getElementById('DropDownListState2').selectedIndex.text = document.getElementById('DropDownListState').selectedIndex.text; }
        if (document.getElementById('txtRegZip').value == '' && document.getElementById('txtEventZip').value != '') { document.getElementById('txtRegZip').value = document.getElementById('txtEventZip').value; }
    } else {
        if (confirm('Removing this option will delete the existing Online Registration Form for this event.\n\nAdding this option in the future will require another form to be created.\n\nOK To Continue?')) {
            document.getElementById('pnlOnlineRegForm').style.display = 'none';
        }
    }    
}

//Link to Online Registration Activity Details
function addEventActivitiesChg() {
    if (document.getElementById('chkActivities').checked == true) {
        document.getElementById('pnlEventActivities').style.display = '';
        document.getElementById('txtRegActivity1').focus();
    } else {
    document.getElementById('pnlEventActivities').style.display = 'none';
    }
}

//Registrant User Comments
function addRegCommentsChg() {
    if (document.getElementById('chkRegUserComments').checked == true) {
        document.getElementById('pnlUserComments').style.display = '';
        document.getElementById('txtRegComments').focus();
    } else {
        document.getElementById('pnlUserComments').style.display = 'none';
    }
}

//Registrant Reservation Information
function addRegReservationsChg() {
    if (document.getElementById('chkRegReservations').checked == true) {
        document.getElementById('pnlRegReservations').style.display = '';
        document.getElementById('txtRegReservations').focus();
    } else {
        document.getElementById('pnlRegReservations').style.display = 'none';
    }
}

//Registrant RSVP Information
function addRegRSVPChg() {
    if (document.getElementById('chkRegRSVP').checked == true) {
        document.getElementById('pnlRegRSVP').style.display = '';
        document.getElementById('txtRegRsvp').focus();
    } else {
        document.getElementById('pnlRegRSVP').style.display = 'none';
    }
}

//Registrant User Items Section
function addRegUserItemsChg() {
    if (document.getElementById('chkRegUserItems').checked == true) {
        document.getElementById('pnlRegUserItems').style.display = '';
        onAddNewUserItem('frmChkBox');
    } else {
        document.getElementById('pnlRegUserItems').style.display = 'none';
    }
}

//Registrant Payable Items Section
function addRegPayItemsChg() {
    if (document.getElementById('chkRegPayItems').checked == true) {
        document.getElementById('pnlRegPayItems').style.display = '';
        onAddNewPayItem('frmChkBox');
    } else {
        document.getElementById('pnlRegPayItems').style.display = 'none';
    }
}

//Link to Contact Administrator
function addEventContactChg() {
    if (document.getElementById('chkAddEventContact').checked == true) {
        document.getElementById('lblAddEventContact').style.display = '';
        document.getElementById('txtAddEventContact').style.display = '';
        document.getElementById('txtAddEventContact').focus();
    } else {
        document.getElementById('txtAddEventContact').value = '';
        document.getElementById('lblAddEventContact').style.display = 'none';
        document.getElementById('txtAddEventContact').style.display = 'none';
    }
}

//Activate Email Section
function onActivateEmail() {
    if (document.getElementById('chkActivateEmail').checked == true) {
        document.getElementById('pnlActivateEmail').style.display = '';
        bActivateEmail = true;
    } else {
    document.getElementById('pnlActivateEmail').style.display = 'none';
    bActivateEmail = false;
    }
}

function usersRegistered() {
    alert("This function has been disabled for this item.\n\n" +
          "Users have already registered for this event\n" +
          "Changes made to the online registration form by continuing with this function would corrupt the database.\n" +
          "Before you can make changes all existing registrant records for this event must be removed.\n\n" +
          "You can remove all the registrants by clicking on the registrants link when viewing this event and then clicking the \"remove all registrants\" button provided.\n" +
          "We strongly recommend that you export the existing registrant listing to Excel before deleting records.");
}

function onUIRemoveItem(id) {
    if (hasRegistrants == true) {
        usersRegistered();
        return;
    }
    var removeItem = document.getElementById(id);
    if (removeItem != null) {
        var allDivs = document.getElementsByTagName('div');
        if (allDivs != null) {
            var UIPanelCount = 0;
            for (var i = 0; i < allDivs.length; i++) {
                if (document.getElementsByTagName('div')[i].id.substring(0, 5) == 'pnlUI') {
                    UIPanelCount++;
                }
            }
            if (UIPanelCount > 1) {
                removeItem.parentNode.removeChild(removeItem);
            } else {
                var pItem = id.substring(id.lastIndexOf('_') + 1);
                document.getElementById('txtUIRow1_' + pItem).value = '';
                document.getElementById('txtUIRow2_' + pItem).value = '';
                document.getElementById('chkUIRequiredItemRow1_' + pItem).checked = false;
            }
        }
    }
}

function onUIMoveItemUp(id) {
    if (hasRegistrants == true) {
        usersRegistered();
        return;
    }
    var moveItemUp = document.getElementById(id);
    if (moveItemUp != null) {
        if (moveItemUp.previousSibling != null && moveItemUp.previousSibling.id.substring(0, 5) == 'pnlUI') {
            moveItemUp.parentNode.insertBefore(moveItemUp, moveItemUp.previousSibling);
        }
    }
}

function onUIMoveItemDn(id) {
    if (hasRegistrants == true) {
        usersRegistered();
        return;
    }
    var moveItemDn = document.getElementById(id);
    if (moveItemDn != null) {
        if (moveItemDn.nextSibling != null && moveItemDn.nextSibling.id.substring(0, 5) == 'pnlUI') {
            moveItemDn.parentNode.insertBefore(moveItemDn.nextSibling, moveItemDn);
        }
    }
}

function onPIRemoveItem(id) {
    if (hasRegistrants == true) {
        usersRegistered();
        return;
    }
    var removeItem = document.getElementById(id);
    if (removeItem != null) {
        var allDivs = document.getElementsByTagName('div');
        if (allDivs != null) {
            var PIPanelCount = 0;
            for (var i = 0; i < allDivs.length; i++) {
                if (document.getElementsByTagName('div')[i].id.substring(0, 5) == 'pnlPI') {
                    PIPanelCount++;
                }
            }
            if (PIPanelCount > 1) {
                removeItem.parentNode.removeChild(removeItem);
            } else {
                var pItem = id.substring(id.lastIndexOf('_') + 1);
                document.getElementById('txtPIRow1_' + pItem).value = '';
                document.getElementById('txtPIRow2_' + pItem).value = '';
                document.getElementById('txtPIRow3_' + pItem).value = '';
                document.getElementById('chkPIAttendeesItemRow1_' + pItem).checked = false;
                document.getElementById('chkPINonAttendeesItemRow2_' + pItem).checked = false;
            }
        }
    }
}

function onPIMoveItemUp(id) {
    if (hasRegistrants == true) {
        usersRegistered();
        return;
    }
    var moveItemUp = document.getElementById(id);
    if (moveItemUp != null) {
        if (moveItemUp.previousSibling != null && moveItemUp.previousSibling.id.substring(0, 5) == 'pnlPI') {
            moveItemUp.parentNode.insertBefore(moveItemUp, moveItemUp.previousSibling);
        }
    }
}

function onPIMoveItemDn(id) {
    if (hasRegistrants == true) {
        usersRegistered();
        return;
    }
    var moveItemDn = document.getElementById(id);
    if (moveItemDn != null) {
        if (moveItemDn.nextSibling != null && moveItemDn.nextSibling.id.substring(0, 5) == 'pnlPI') {
            moveItemDn.parentNode.insertBefore(moveItemDn.nextSibling, moveItemDn);
        }
    }
}

function onAddNewUserItem(init) {
    if (hasRegistrants == true) {
        usersRegistered();
        return;
    }
    var allDivs = document.getElementsByTagName('div');
    if (allDivs != null) {
        var UIPanelCount = 0;
        for (var i = 0; i < allDivs.length; i++) {
            if (document.getElementsByTagName('div')[i].id.substring(0, 5) == 'pnlUI') {
                UIPanelCount++;
            }
        }
        if (init == 'frmChkBox' && UIPanelCount > 0) { return; }
        var btnAddNewUI = document.getElementById('btnAddNewUserItem');
        if (btnAddNewUI != null) {
            var newUIDiv = document.createElement('div');
            newUIDiv.setAttribute('id', 'pnlUI_' + (UIPanelCount + 1).toString());
            newUIDiv.setAttribute('class', 'pnlAdminUserItems');
            newUIDiv.setAttribute('style', 'width:445px;');

            //New User Item - row 1 ColumnName
            var newUIRow1p = document.createElement('p');

            var newUIRow1Span = document.createElement('span');
            newUIRow1Span.setAttribute('style', 'display:inline-block;width:100px;');
            var newUIRow1SpanTxt = document.createTextNode('Column ID:');
            newUIRow1Span.appendChild(newUIRow1SpanTxt);
            newUIRow1p.appendChild(newUIRow1Span);

            var newUIRow1TxtBox = document.createElement('input');
            newUIRow1TxtBox.setAttribute('id', 'txtUIRow1_' + (UIPanelCount + 1).toString());
            newUIRow1TxtBox.setAttribute('type', 'text');
            newUIRow1TxtBox.setAttribute('class', 'txtAdminUserItems');
            newUIRow1TxtBox.setAttribute('onblur', 'onColumnNameBlur(txtUIRow1_' + (UIPanelCount + 1).toString() + ')');
            newUIRow1TxtBox.setAttribute('onfocus', 'onColumnNameFocus(txtUIRow1_' + (UIPanelCount + 1).toString() + ')');
            newUIRow1p.appendChild(newUIRow1TxtBox);

            var newUIRow1ChkSpan = document.createElement('span');
            newUIRow1ChkSpan.setAttribute('class', 'chkAdminUserItems');

            var newUIRow1Chk = document.createElement('input');
            newUIRow1Chk.setAttribute('id', 'chkUIRequiredItemRow1_' + (UIPanelCount + 1).toString());
            newUIRow1Chk.setAttribute('type', 'checkbox');
            newUIRow1ChkSpan.appendChild(newUIRow1Chk);

            var newUIRow1ChkSpanLabel = document.createElement('label');
            newUIRow1ChkSpanLabel.setAttribute('for', 'chkUIRequiredItemRow1_' + (UIPanelCount + 1).toString());
            var newUIRow1ChkTxt = document.createTextNode('Required Item');
            newUIRow1ChkSpanLabel.appendChild(newUIRow1ChkTxt);
            newUIRow1ChkSpan.appendChild(newUIRow1ChkSpanLabel);

            newUIRow1p.appendChild(newUIRow1ChkSpan);
            newUIDiv.appendChild(newUIRow1p);

            //New User Item - row 2 ReceiptLabel
            var newUIRow2p = document.createElement('p');
            newUIRow2p.setAttribute('style', 'margin-top:3px;');

            var newUIRow2Span = document.createElement('span');
            newUIRow2Span.setAttribute('style', 'display:inline-block;width:100px;');
            var newUIRow2SpanTxt = document.createTextNode('Receipt Desc:');
            newUIRow2Span.appendChild(newUIRow2SpanTxt);
            newUIRow2p.appendChild(newUIRow2Span);

            var newUIRow2TxtBox = document.createElement('input');
            newUIRow2TxtBox.setAttribute('id', 'txtUIRow2_' + (UIPanelCount + 1).toString());
            newUIRow2TxtBox.setAttribute('type', 'text');
            newUIRow2TxtBox.setAttribute('class', 'txtAdminUserItems');
            newUIRow2p.appendChild(newUIRow2TxtBox);
            newUIDiv.appendChild(newUIRow2p);

            //New User Item - row 3 UserPrompt
            var newUIRow3p = document.createElement('p');
            newUIRow3p.setAttribute('style', 'margin-top:3px;');

            var newUIRow3Span = document.createElement('span');
            newUIRow3Span.setAttribute('style', 'display:inline-block;width:100px;');
            var newUIRow3SpanTxt = document.createTextNode('User Prompt:');
            newUIRow3Span.appendChild(newUIRow3SpanTxt);
            newUIRow3p.appendChild(newUIRow3Span);

            var newUIRow3TxtBox = document.createElement('input');
            newUIRow3TxtBox.setAttribute('id', 'txtUIRow3_' + (UIPanelCount + 1).toString());
            newUIRow3TxtBox.setAttribute('type', 'text');
            newUIRow3TxtBox.setAttribute('class', 'txtAdminUserItems');
            newUIRow3p.appendChild(newUIRow3TxtBox);

            var newUIRow3BtnRemove = document.createElement('input');
            newUIRow3BtnRemove.setAttribute('id', 'btnUIRemoveItem_' + (UIPanelCount + 1).toString());
            newUIRow3BtnRemove.setAttribute('type', 'button');
            newUIRow3BtnRemove.setAttribute('class', 'btnAdminUserItems');
            newUIRow3BtnRemove.setAttribute('value', 'Remove');
            newUIRow3BtnRemove.setAttribute('style', 'margin-left:8px;');
            newUIRow3BtnRemove.onclick = function() { onUIRemoveItem('pnlUI_' + (UIPanelCount + 1).toString()); }
            newUIRow3p.appendChild(newUIRow3BtnRemove);

            var newUIRow3BtnMoveUp = document.createElement('input');
            newUIRow3BtnMoveUp.setAttribute('id', 'btnUIMoveItemUp_' + (UIPanelCount + 1).toString());
            newUIRow3BtnMoveUp.setAttribute('type', 'button');
            newUIRow3BtnMoveUp.setAttribute('class', 'btnAdminUserItems');
            newUIRow3BtnMoveUp.setAttribute('value', 'Up');
            newUIRow3BtnMoveUp.onclick = function() { onUIMoveItemUp('pnlUI_' + (UIPanelCount + 1).toString()); }
            newUIRow3p.appendChild(newUIRow3BtnMoveUp);

            var newUIRow3BtnMoveDn = document.createElement('input');
            newUIRow3BtnMoveDn.setAttribute('id', 'btnUIMoveItemDn_' + (UIPanelCount + 1).toString());
            newUIRow3BtnMoveDn.setAttribute('type', 'button');
            newUIRow3BtnMoveDn.setAttribute('class', 'btnAdminUserItems');
            newUIRow3BtnMoveDn.setAttribute('value', 'Dn');
            newUIRow3BtnMoveDn.onclick = function() { onUIMoveItemDn('pnlUI_' + (UIPanelCount + 1).toString()); }
            newUIRow3p.appendChild(newUIRow3BtnMoveDn);
            newUIDiv.appendChild(newUIRow3p);

            btnAddNewUI.parentNode.insertBefore(newUIDiv, btnAddNewUI);
        }
    }
}

function onAddExistUI(order, columnName, receiptLabel, prompt, required) {
    var allDivs = document.getElementsByTagName('div');
    if (allDivs != null) {
        var UIPanelCount = 0;
        for (var i = 0; i < allDivs.length; i++) {
            if (document.getElementsByTagName('div')[i].id.substring(0, 5) == 'pnlUI') {
                UIPanelCount++;
            }
        }
        var btnAddNewUI = document.getElementById('btnAddNewUserItem');
        if (btnAddNewUI != null) {
            var newUIDiv = document.createElement('div');
            newUIDiv.setAttribute('id', 'pnlUI_' + (UIPanelCount + 1).toString());
            newUIDiv.setAttribute('class', 'pnlAdminUserItems');
            newUIDiv.setAttribute('style', 'width:445px;');

            //New User Item - row 1 ColumnName
            var newUIRow1p = document.createElement('p');

            var newUIRow1Span = document.createElement('span');
            newUIRow1Span.setAttribute('style', 'display:inline-block;width:100px;');
            var newUIRow1SpanTxt = document.createTextNode('Column ID:');
            newUIRow1Span.appendChild(newUIRow1SpanTxt);
            newUIRow1p.appendChild(newUIRow1Span);

            var newUIRow1TxtBox = document.createElement('input');
            newUIRow1TxtBox.setAttribute('id', 'txtUIRow1_' + (UIPanelCount + 1).toString());
            newUIRow1TxtBox.setAttribute('type', 'text');
            newUIRow1TxtBox.setAttribute('class', 'txtAdminUserItems');
            newUIRow1TxtBox.setAttribute('onblur', 'onColumnNameBlur(txtUIRow1_' + (UIPanelCount + 1).toString() + ')');
            newUIRow1TxtBox.setAttribute('onfocus', 'onColumnNameFocus(txtUIRow1_' + (UIPanelCount + 1).toString() + ')');            
            newUIRow1TxtBox.value = columnName;
            newUIRow1p.appendChild(newUIRow1TxtBox);

            var newUIRow1ChkSpan = document.createElement('span');
            newUIRow1ChkSpan.setAttribute('class', 'chkAdminUserItems');

            var newUIRow1Chk = document.createElement('input');
            newUIRow1Chk.setAttribute('id', 'chkUIRequiredItemRow1_' + (UIPanelCount + 1).toString());
            newUIRow1Chk.setAttribute('type', 'checkbox');
            if (required == 'true') { newUIRow1Chk.checked = true; }
            newUIRow1ChkSpan.appendChild(newUIRow1Chk);

            var newUIRow1ChkSpanLabel = document.createElement('label');
            newUIRow1ChkSpanLabel.setAttribute('for', 'chkUIRequiredItemRow1_' + (UIPanelCount + 1).toString());
            var newUIRow1ChkTxt = document.createTextNode('Required Item');
            newUIRow1ChkSpanLabel.appendChild(newUIRow1ChkTxt);
            newUIRow1ChkSpan.appendChild(newUIRow1ChkSpanLabel);

            newUIRow1p.appendChild(newUIRow1ChkSpan);
            newUIDiv.appendChild(newUIRow1p);

            //New User Item - row 2 ReceiptLabel
            var newUIRow2p = document.createElement('p');
            newUIRow2p.setAttribute('style', 'margin-top:3px;');

            var newUIRow2Span = document.createElement('span');
            newUIRow2Span.setAttribute('style', 'display:inline-block;width:100px;');
            var newUIRow2SpanTxt = document.createTextNode('Receipt Desc:');
            newUIRow2Span.appendChild(newUIRow2SpanTxt);
            newUIRow2p.appendChild(newUIRow2Span);

            var newUIRow2TxtBox = document.createElement('input');
            newUIRow2TxtBox.setAttribute('id', 'txtUIRow2_' + (UIPanelCount + 1).toString());
            newUIRow2TxtBox.setAttribute('type', 'text');
            newUIRow2TxtBox.setAttribute('class', 'txtAdminUserItems');
            newUIRow2TxtBox.value = receiptLabel;
            newUIRow2p.appendChild(newUIRow2TxtBox);
            newUIDiv.appendChild(newUIRow2p);

            //New User Item - row 3 UserPrompt
            var newUIRow3p = document.createElement('p');
            newUIRow3p.setAttribute('style', 'margin-top:3px;');

            var newUIRow3Span = document.createElement('span');
            newUIRow3Span.setAttribute('style', 'display:inline-block;width:100px;');
            var newUIRow3SpanTxt = document.createTextNode('User Prompt:');
            newUIRow3Span.appendChild(newUIRow3SpanTxt);
            newUIRow3p.appendChild(newUIRow3Span);

            var newUIRow3TxtBox = document.createElement('input');
            newUIRow3TxtBox.setAttribute('id', 'txtUIRow3_' + (UIPanelCount + 1).toString());
            newUIRow3TxtBox.setAttribute('type', 'text');
            newUIRow3TxtBox.setAttribute('class', 'txtAdminUserItems');
            newUIRow3TxtBox.value = prompt;
            newUIRow3p.appendChild(newUIRow3TxtBox);

            var newUIRow3BtnRemove = document.createElement('input');
            newUIRow3BtnRemove.setAttribute('id', 'btnUIRemoveItem_' + (UIPanelCount + 1).toString());
            newUIRow3BtnRemove.setAttribute('type', 'button');
            newUIRow3BtnRemove.setAttribute('class', 'btnAdminUserItems');
            newUIRow3BtnRemove.setAttribute('value', 'Remove');
            newUIRow3BtnRemove.setAttribute('style', 'margin-left:8px;');
            newUIRow3BtnRemove.onclick = function() { onUIRemoveItem('pnlUI_' + (UIPanelCount + 1).toString()); }
            newUIRow3p.appendChild(newUIRow3BtnRemove);

            var newUIRow3BtnMoveUp = document.createElement('input');
            newUIRow3BtnMoveUp.setAttribute('id', 'btnUIMoveItemUp_' + (UIPanelCount + 1).toString());
            newUIRow3BtnMoveUp.setAttribute('type', 'button');
            newUIRow3BtnMoveUp.setAttribute('class', 'btnAdminUserItems');
            newUIRow3BtnMoveUp.setAttribute('value', 'Up');
            newUIRow3BtnMoveUp.onclick = function() { onUIMoveItemUp('pnlUI_' + (UIPanelCount + 1).toString()); }
            newUIRow3p.appendChild(newUIRow3BtnMoveUp);

            var newUIRow3BtnMoveDn = document.createElement('input');
            newUIRow3BtnMoveDn.setAttribute('id', 'btnUIMoveItemDn_' + (UIPanelCount + 1).toString());
            newUIRow3BtnMoveDn.setAttribute('type', 'button');
            newUIRow3BtnMoveDn.setAttribute('class', 'btnAdminUserItems');
            newUIRow3BtnMoveDn.setAttribute('value', 'Dn');
            newUIRow3BtnMoveDn.onclick = function() { onUIMoveItemDn('pnlUI_' + (UIPanelCount + 1).toString()); }
            newUIRow3p.appendChild(newUIRow3BtnMoveDn);
            newUIDiv.appendChild(newUIRow3p);

            btnAddNewUI.parentNode.insertBefore(newUIDiv, btnAddNewUI);
        }
    }
}

function onAddNewPayItem(init) {
    if (hasRegistrants == true) {
        usersRegistered();
        return;
    }
    var allDivs = document.getElementsByTagName('div');
    if (allDivs != null) {
        var PIPanelCount = 0;
        for (var i = 0; i < allDivs.length; i++) {
            if (document.getElementsByTagName('div')[i].id.substring(0, 5) == 'pnlPI') {
                PIPanelCount++;
            }
        }
        if (init == 'frmChkBox' && PIPanelCount > 0) { return; }
        var btnAddNewPI = document.getElementById('btnAddNewPayItem');
        if (btnAddNewPI != null) {
            var newPIDiv = document.createElement('div');
            newPIDiv.setAttribute('id', 'pnlPI_' + (PIPanelCount + 1).toString());
            newPIDiv.setAttribute('class', 'pnlAdminUserItems');
            newPIDiv.setAttribute('style', 'width:445px;');

            //New Pay Item - row 1 ColumName
            var newPIRow1p = document.createElement('p');

            var newPIRow1Span = document.createElement('span');
            newPIRow1Span.setAttribute('style', 'display:inline-block;width:100px;');
            var newPIRow1SpanTxt = document.createTextNode('Column ID:');
            newPIRow1Span.appendChild(newPIRow1SpanTxt);
            newPIRow1p.appendChild(newPIRow1Span);

            var newPIRow1TxtBox = document.createElement('input');
            newPIRow1TxtBox.setAttribute('id', 'txtPIRow1_' + (PIPanelCount + 1).toString());
            newPIRow1TxtBox.setAttribute('type', 'text');
            newPIRow1TxtBox.setAttribute('class', 'txtAdminUserItems');
            newPIRow1TxtBox.setAttribute('onblur', 'onColumnNameBlur(txtPIRow1_' + (PIPanelCount + 1).toString() + ')');
            newPIRow1TxtBox.setAttribute('onfocus', 'onColumnNameFocus(txtPIRow1_' + (PIPanelCount + 1).toString() + ')');            
            newPIRow1p.appendChild(newPIRow1TxtBox);

            var newPIRow1ChkSpan = document.createElement('span');
            newPIRow1ChkSpan.setAttribute('class', 'chkAdminUserItems');

            var newPIRow1Chk = document.createElement('input');
            newPIRow1Chk.setAttribute('id', 'chkPIAttendeesItemRow1_' + (PIPanelCount + 1).toString());
            newPIRow1Chk.setAttribute('type', 'checkbox');
            newPIRow1ChkSpan.appendChild(newPIRow1Chk);

            var newPIRow1ChkSpanLabel = document.createElement('label');
            newPIRow1ChkSpanLabel.setAttribute('for', 'chkPIAttendeesItemRow1_' + (PIPanelCount + 1).toString());
            var newPIRow1ChkTxt = document.createTextNode('Attendees');
            newPIRow1ChkSpanLabel.appendChild(newPIRow1ChkTxt);
            newPIRow1ChkSpan.appendChild(newPIRow1ChkSpanLabel);

            newPIRow1p.appendChild(newPIRow1ChkSpan);
            newPIDiv.appendChild(newPIRow1p);

            //New Pay Item - row 2 ReceiptLabel
            var newPIRow2p = document.createElement('p');
            newPIRow2p.setAttribute('style', 'margin-top:3px;');

            var newPIRow2Span = document.createElement('span');
            newPIRow2Span.setAttribute('style', 'display:inline-block;width:100px;');
            var newPIRow2SpanTxt = document.createTextNode('Receipt Desc:');
            newPIRow2Span.appendChild(newPIRow2SpanTxt);
            newPIRow2p.appendChild(newPIRow2Span);

            var newPIRow2TxtBox = document.createElement('input');
            newPIRow2TxtBox.setAttribute('id', 'txtPIRow2_' + (PIPanelCount + 1).toString());
            newPIRow2TxtBox.setAttribute('type', 'text');
            newPIRow2TxtBox.setAttribute('class', 'txtAdminUserItems');
            newPIRow2p.appendChild(newPIRow2TxtBox);

            var newPIRow2ChkSpan = document.createElement('span');
            newPIRow2ChkSpan.setAttribute('class', 'chkAdminUserItems');

            var newPIRow2Chk = document.createElement('input');
            newPIRow2Chk.setAttribute('id', 'chkPINonAttendeesItemRow2_' + (PIPanelCount + 1).toString());
            newPIRow2Chk.setAttribute('type', 'checkbox');
            newPIRow2ChkSpan.appendChild(newPIRow2Chk);

            var newPIRow2ChkSpanLabel = document.createElement('label');
            newPIRow2ChkSpanLabel.setAttribute('for', 'chkPINonAttendeesItemRow2_' + (PIPanelCount + 1).toString());
            var newPIRow2ChkTxt = document.createTextNode('Non-Attendees');
            newPIRow2ChkSpanLabel.appendChild(newPIRow2ChkTxt);
            newPIRow2ChkSpan.appendChild(newPIRow2ChkSpanLabel);

            newPIRow2p.appendChild(newPIRow2ChkSpan);
            newPIDiv.appendChild(newPIRow2p);

            //New Pay Item - row 3 UserPrompt
            var newPIRow3p = document.createElement('p');
            newPIRow3p.setAttribute('style', 'margin-top:3px;');

            var newPIRow3Span = document.createElement('span');
            newPIRow3Span.setAttribute('style', 'display:inline-block;width:100px;');
            var newPIRow3SpanTxt = document.createTextNode('User Prompt:');
            newPIRow3Span.appendChild(newPIRow3SpanTxt);
            newPIRow3p.appendChild(newPIRow3Span);

            var newPIRow3TxtBox = document.createElement('input');
            newPIRow3TxtBox.setAttribute('id', 'txtPIRow3_' + (PIPanelCount + 1).toString());
            newPIRow3TxtBox.setAttribute('type', 'text');
            newPIRow3TxtBox.setAttribute('class', 'txtAdminUserItems');
            newPIRow3p.appendChild(newPIRow3TxtBox);
            newPIDiv.appendChild(newPIRow3p);

            //New Pay Item - row 4 itemCost
            var newPIRow4p = document.createElement('p');
            newPIRow4p.setAttribute('style', 'margin-top:3px;');

            var newPIRow4Span = document.createElement('span');
            newPIRow4Span.setAttribute('style', 'display:inline-block;width:100px;');
            var newPIRow4SpanTxt = document.createTextNode('Item Cost:');
            newPIRow4Span.appendChild(newPIRow4SpanTxt);
            newPIRow4p.appendChild(newPIRow4Span);

            var newPIRow4TxtBox = document.createElement('input');
            newPIRow4TxtBox.setAttribute('id', 'txtPIRow4_' + (PIPanelCount + 1).toString());
            newPIRow4TxtBox.setAttribute('type', 'text');
            newPIRow4TxtBox.setAttribute('class', 'txtAdminUserItems');
            newPIRow4p.appendChild(newPIRow4TxtBox);

            var newPIRow4BtnRemove = document.createElement('input');
            newPIRow4BtnRemove.setAttribute('id', 'btnPIRemoveItem_' + (PIPanelCount + 1).toString());
            newPIRow4BtnRemove.setAttribute('type', 'button');
            newPIRow4BtnRemove.setAttribute('class', 'btnAdminUserItems');
            newPIRow4BtnRemove.setAttribute('value', 'Remove');
            newPIRow4BtnRemove.setAttribute('style', 'margin-left:8px;');
            newPIRow4BtnRemove.onclick = function() { onPIRemoveItem('pnlPI_' + (PIPanelCount + 1).toString()); }
            newPIRow4p.appendChild(newPIRow4BtnRemove);

            var newPIRow4BtnMoveUp = document.createElement('input');
            newPIRow4BtnMoveUp.setAttribute('id', 'btnPIMoveItemUp_' + (PIPanelCount + 1).toString());
            newPIRow4BtnMoveUp.setAttribute('type', 'button');
            newPIRow4BtnMoveUp.setAttribute('class', 'btnAdminUserItems');
            newPIRow4BtnMoveUp.setAttribute('value', 'Up');
            newPIRow4BtnMoveUp.onclick = function() { onPIMoveItemUp('pnlPI_' + (PIPanelCount + 1).toString()); }
            newPIRow4p.appendChild(newPIRow4BtnMoveUp);

            var newPIRow4BtnMoveDn = document.createElement('input');
            newPIRow4BtnMoveDn.setAttribute('id', 'btnPIMoveItemDn_' + (PIPanelCount + 1).toString());
            newPIRow4BtnMoveDn.setAttribute('type', 'button');
            newPIRow4BtnMoveDn.setAttribute('class', 'btnAdminUserItems');
            newPIRow4BtnMoveDn.setAttribute('value', 'Dn');
            newPIRow4BtnMoveDn.onclick = function() { onPIMoveItemDn('pnlPI_' + (PIPanelCount + 1).toString()); }
            newPIRow4p.appendChild(newPIRow4BtnMoveDn);
            newPIDiv.appendChild(newPIRow4p);

            btnAddNewPI.parentNode.insertBefore(newPIDiv, btnAddNewPI);
        }
    }
}

function onAddExistPI(order, columnName, receiptLabel, prompt, cost, visible) {
    var allDivs = document.getElementsByTagName('div');
    if (allDivs != null) {
        var PIPanelCount = 0;
        for (var i = 0; i < allDivs.length; i++) {
            if (document.getElementsByTagName('div')[i].id.substring(0, 5) == 'pnlPI') {
                PIPanelCount++;
            }
        }
        var btnAddNewPI = document.getElementById('btnAddNewPayItem');
        if (btnAddNewPI != null) {
            var newPIDiv = document.createElement('div');
            newPIDiv.setAttribute('id', 'pnlPI_' + (PIPanelCount + 1).toString());
            newPIDiv.setAttribute('class', 'pnlAdminUserItems');
            newPIDiv.setAttribute('style', 'width:445px;');

            //New Pay Item - row 1 ColumnName
            var newPIRow1p = document.createElement('p');

            var newPIRow1Span = document.createElement('span');
            newPIRow1Span.setAttribute('style', 'display:inline-block;width:100px;');
            var newPIRow1SpanTxt = document.createTextNode('Column ID:');
            newPIRow1Span.appendChild(newPIRow1SpanTxt);
            newPIRow1p.appendChild(newPIRow1Span);

            var newPIRow1TxtBox = document.createElement('input');
            newPIRow1TxtBox.setAttribute('id', 'txtPIRow1_' + (PIPanelCount + 1).toString());
            newPIRow1TxtBox.setAttribute('type', 'text');
            newPIRow1TxtBox.setAttribute('class', 'txtAdminUserItems');
            newPIRow1TxtBox.setAttribute('onblur', 'onColumnNameBlur(txtPIRow1_' + (PIPanelCount + 1).toString() + ')');
            newPIRow1TxtBox.setAttribute('onfocus', 'onColumnNameFocus(txtPIRow1_' + (PIPanelCount + 1).toString() + ')');                        
            newPIRow1TxtBox.value = columnName;
            newPIRow1p.appendChild(newPIRow1TxtBox);

            var newPIRow1ChkSpan = document.createElement('span');
            newPIRow1ChkSpan.setAttribute('class', 'chkAdminUserItems');

            var newPIRow1Chk = document.createElement('input');
            newPIRow1Chk.setAttribute('id', 'chkPIAttendeesItemRow1_' + (PIPanelCount + 1).toString());
            newPIRow1Chk.setAttribute('type', 'checkbox');
            if (visible == 'always' || visible == 'attend') { newPIRow1Chk.checked = true; }
            newPIRow1ChkSpan.appendChild(newPIRow1Chk);

            var newPIRow1ChkSpanLabel = document.createElement('label');
            newPIRow1ChkSpanLabel.setAttribute('for', 'chkPIAttendeesItemRow1_' + (PIPanelCount + 1).toString());
            var newPIRow1ChkTxt = document.createTextNode('Attendees');
            newPIRow1ChkSpanLabel.appendChild(newPIRow1ChkTxt);
            newPIRow1ChkSpan.appendChild(newPIRow1ChkSpanLabel);

            newPIRow1p.appendChild(newPIRow1ChkSpan);
            newPIDiv.appendChild(newPIRow1p);

            //New Pay Item - row 2 ReceiptLabel
            var newPIRow2p = document.createElement('p');
            newPIRow2p.setAttribute('style', 'margin-top:3px;');

            var newPIRow2Span = document.createElement('span');
            newPIRow2Span.setAttribute('style', 'display:inline-block;width:100px;');
            var newPIRow2SpanTxt = document.createTextNode('Receipt Desc:');
            newPIRow2Span.appendChild(newPIRow2SpanTxt);
            newPIRow2p.appendChild(newPIRow2Span);

            var newPIRow2TxtBox = document.createElement('input');
            newPIRow2TxtBox.setAttribute('id', 'txtPIRow2_' + (PIPanelCount + 1).toString());
            newPIRow2TxtBox.setAttribute('type', 'text');
            newPIRow2TxtBox.setAttribute('class', 'txtAdminUserItems');
            newPIRow2TxtBox.value = receiptLabel;
            newPIRow2p.appendChild(newPIRow2TxtBox);

            var newPIRow2ChkSpan = document.createElement('span');
            newPIRow2ChkSpan.setAttribute('class', 'chkAdminUserItems');

            var newPIRow2Chk = document.createElement('input');
            newPIRow2Chk.setAttribute('id', 'chkPINonAttendeesItemRow2_' + (PIPanelCount + 1).toString());
            newPIRow2Chk.setAttribute('type', 'checkbox');
            if (visible == 'always' || visible == 'no_attend') { newPIRow2Chk.checked = true; }
            newPIRow2ChkSpan.appendChild(newPIRow2Chk);

            var newPIRow2ChkSpanLabel = document.createElement('label');
            newPIRow2ChkSpanLabel.setAttribute('for', 'chkPINonAttendeesItemRow2_' + (PIPanelCount + 1).toString());
            var newPIRow2ChkTxt = document.createTextNode('Non-Attendees');
            newPIRow2ChkSpanLabel.appendChild(newPIRow2ChkTxt);
            newPIRow2ChkSpan.appendChild(newPIRow2ChkSpanLabel);

            newPIRow2p.appendChild(newPIRow2ChkSpan);
            newPIDiv.appendChild(newPIRow2p);

            //New Pay Item - row 3 UserPrompt
            var newPIRow3p = document.createElement('p');
            newPIRow3p.setAttribute('style', 'margin-top:3px;');

            var newPIRow3Span = document.createElement('span');
            newPIRow3Span.setAttribute('style', 'display:inline-block;width:100px;');
            var newPIRow3SpanTxt = document.createTextNode('User Prompt:');
            newPIRow3Span.appendChild(newPIRow3SpanTxt);
            newPIRow3p.appendChild(newPIRow3Span);

            var newPIRow3TxtBox = document.createElement('input');
            newPIRow3TxtBox.setAttribute('id', 'txtPIRow3_' + (PIPanelCount + 1).toString());
            newPIRow3TxtBox.setAttribute('type', 'text');
            newPIRow3TxtBox.setAttribute('class', 'txtAdminUserItems');
            newPIRow3TxtBox.value = prompt;
            newPIRow3p.appendChild(newPIRow3TxtBox);
            newPIDiv.appendChild(newPIRow3p);

            //New Pay Item - row 4 ItemCost
            var newPIRow4p = document.createElement('p');
            newPIRow4p.setAttribute('style', 'margin-top:3px;');

            var newPIRow4Span = document.createElement('span');
            newPIRow4Span.setAttribute('style', 'display:inline-block;width:100px;');
            var newPIRow4SpanTxt = document.createTextNode('Item Cost:');
            newPIRow4Span.appendChild(newPIRow4SpanTxt);
            newPIRow4p.appendChild(newPIRow4Span);

            var newPIRow4TxtBox = document.createElement('input');
            newPIRow4TxtBox.setAttribute('id', 'txtPIRow4_' + (PIPanelCount + 1).toString());
            newPIRow4TxtBox.setAttribute('type', 'text');
            newPIRow4TxtBox.setAttribute('class', 'txtAdminUserItems');
            newPIRow4TxtBox.value = cost;
            newPIRow4p.appendChild(newPIRow4TxtBox);

            var newPIRow4BtnRemove = document.createElement('input');
            newPIRow4BtnRemove.setAttribute('id', 'btnPIRemoveItem_' + (PIPanelCount + 1).toString());
            newPIRow4BtnRemove.setAttribute('type', 'button');
            newPIRow4BtnRemove.setAttribute('class', 'btnAdminUserItems');
            newPIRow4BtnRemove.setAttribute('value', 'Remove');
            newPIRow4BtnRemove.setAttribute('style', 'margin-left:8px;');
            newPIRow4BtnRemove.onclick = function() { onPIRemoveItem('pnlPI_' + (PIPanelCount + 1).toString()); }
            newPIRow4p.appendChild(newPIRow4BtnRemove);

            var newPIRow4BtnMoveUp = document.createElement('input');
            newPIRow4BtnMoveUp.setAttribute('id', 'btnPIMoveItemUp_' + (PIPanelCount + 1).toString());
            newPIRow4BtnMoveUp.setAttribute('type', 'button');
            newPIRow4BtnMoveUp.setAttribute('class', 'btnAdminUserItems');
            newPIRow4BtnMoveUp.setAttribute('value', 'Up');
            newPIRow4BtnMoveUp.onclick = function() { onPIMoveItemUp('pnlPI_' + (PIPanelCount + 1).toString()); }
            newPIRow4p.appendChild(newPIRow4BtnMoveUp);

            var newPIRow4BtnMoveDn = document.createElement('input');
            newPIRow4BtnMoveDn.setAttribute('id', 'btnPIMoveItemDn_' + (PIPanelCount + 1).toString());
            newPIRow4BtnMoveDn.setAttribute('type', 'button');
            newPIRow4BtnMoveDn.setAttribute('class', 'btnAdminUserItems');
            newPIRow4BtnMoveDn.setAttribute('value', 'Dn');
            newPIRow4BtnMoveDn.onclick = function() { onPIMoveItemDn('pnlPI_' + (PIPanelCount + 1).toString()); }
            newPIRow4p.appendChild(newPIRow4BtnMoveDn);
            newPIDiv.appendChild(newPIRow4p);

            btnAddNewPI.parentNode.insertBefore(newPIDiv, btnAddNewPI);
        }
    }
}

//Specific textbox validations
function onColumnNameFocus(id) {
    if (hasRegistrants == true) {
        usersRegistered();
        return;
    }
}

function onColumnNameBlur(id) {
    var regex = /\W+/;  //Test for Non-Alphanumeric characters. Underscores allowed. No Spaces
    if (regex.test(id.value) == true) {
        alert('Invalid Column Name.\n' +
          'Column names are used in our database and Excel spreadsheet column headers and must contain alphanumeric characters only (A-Z, a-z, 0-9).\n' +
          'Spaces cannot be inserted. Use an underscore to show a space.\n\n' +
          'For example, COLUMN A should be entered as COLUMN_A.\n' +
          'All column names will be automatically converted to uppercase.\n\n' +
          'Please correct your entry before continuing.');
        id.focus();
    }
}

function onUserEmailBlur(id) {
    var regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/
    if (regex.test(id.value) == false) {
        alert('Invalid E-mail syntax.\n' +
          'You have entered an invalid E-mail address. Your E-mail is used for registration confirmation and online payment receipts.\n\n' +
          'If you do not have a valid E-mail address you will not be able to complete this online registration form.\n\n' +
          'Please correct your entry before continuing.');
        id.value = '';
        id.focus();
    }
}

//New Event Submission options
function submitNewEvent() {
    document.getElementById('asyncFileUploadInfo').value = null;
    document.getElementById('asyncFileUploadInfo').style.display = 'none';
    document.getElementById('asyncFileUploadAgenda').value = null;
    document.getElementById('asyncFileUploadAgenda').style.display = 'none';
    document.getElementById('asyncFileUploadPrintReg').value = null;
    document.getElementById('asyncFileUploadPrintReg').style.display = 'none';
    document.getElementById('fromClient').value = 'Submit';
    var fAction = document.getElementById('fileAction').value;
    if (fAction.substring((fAction.length - 1)) == ',') { document.getElementById('fileAction').value = fAction.substring(0, (fAction.length - 1)); }

    //Submit New Admin Event and registration
    //ß = <alt>225, Γ = <alt>226 π = <alt>227
    var toServer = document.getElementById('fromClient');
    var toServerUserItems = document.getElementById('fromClientUserItems');
    var toServerPayItems = document.getElementById('fromClientPayItems');
    var strUserItems = '';
    var strPayItems = '';

    //Gather User and Pay Item information
    if (document.getElementById('chkAddEventOnlineReg').checked == true) {
        var UIPanelCount = 0;
        var PIPanelCount = 0;
        var allDivs = document.getElementsByTagName('div');
        if (allDivs != null) {
            for (var i = 0; i < allDivs.length; i++) {
                if (document.getElementsByTagName('div')[i].id.substring(0, 5) == 'pnlUI') {
                    UIPanelCount++;
                }
                if (document.getElementsByTagName('div')[i].id.substring(0, 5) == 'pnlPI') {
                    PIPanelCount++;
                }
            }
        }
        //Gather User Item Information
        for (var UICount = 0; UICount < UIPanelCount; UICount++) {
            var userItem = document.getElementById('pnlUI_' + (UICount + 1).toString());
            strUserItems += 'orderß' + (UICount + firstUIPosition).toString() + 'Γ';
            strUserItems += 'columnNameß' + document.getElementById('txtUIRow1_' + (UICount + 1).toString()).value + 'Γ';
            strUserItems += 'receiptLabelß' + document.getElementById('txtUIRow2_' + (UICount + 1).toString()).value + 'Γ';
            strUserItems += 'promptß' + document.getElementById('txtUIRow3_' + (UICount + 1).toString()).value + 'Γ';
            strUserItems += 'requiredß' + document.getElementById('chkUIRequiredItemRow1_' + (UICount + 1).toString()).checked.toString() + 'Γ';
            strUserItems += 'π';
        }

        //Gather Pay Item Information
        okToSubmit = true;
        for (var PICount = 0; PICount < PIPanelCount; PICount++) {
            var payItem = document.getElementById('pnlPI_' + (PICount + 1).toString());
            strPayItems += 'orderß' + (PICount + firstUIPosition + UICount).toString() + 'Γ';
            strPayItems += 'columnNameß' + document.getElementById('txtPIRow1_' + (PICount + 1).toString()).value + 'Γ';
            strPayItems += 'receiptLabelß' + document.getElementById('txtPIRow2_' + (PICount + 1).toString()).value + 'Γ';
            strPayItems += 'promptß' + document.getElementById('txtPIRow3_' + (PICount + 1).toString()).value + 'Γ';
            strPayItems += 'costß' + document.getElementById('txtPIRow4_' + (PICount + 1).toString()).value + 'Γ';
            if (document.getElementById('chkPIAttendeesItemRow1_' + (PICount + 1).toString()).checked == true && document.getElementById('chkPINonAttendeesItemRow2_' + (PICount + 1).toString()).checked == true) {
                strPayItems += 'visibleßalwaysΓ';
            }
            if (document.getElementById('chkPIAttendeesItemRow1_' + (PICount + 1).toString()).checked == true && document.getElementById('chkPINonAttendeesItemRow2_' + (PICount + 1).toString()).checked == false) {
                strPayItems += 'visibleßattendΓ';
            }
            if (document.getElementById('chkPINonAttendeesItemRow2_' + (PICount + 1).toString()).checked == true && document.getElementById('chkPIAttendeesItemRow1_' + (PICount + 1).toString()).checked == false) {
                strPayItems += 'visibleßno_attendΓ';
            }
            if (document.getElementById('chkPIAttendeesItemRow1_' + (PICount + 1).toString()).checked == false && document.getElementById('chkPINonAttendeesItemRow2_' + (PICount + 1).toString()).checked == false) {
                alert('Each payable item you have created must be made visible to either: attendees or non-attendees or both.\nPlease check at least one checkbox in each payable item.');
                document.getElementById('txtPIRow1_' + (PICount + 1).toString()).focus();
                okToSubmit = false;
            }
            strPayItems += 'π';
        }
    }

    //Submit to Server
    if (okToSubmit == false) {
        okToSubmit = true;
        return;
    } else {
        //Validate at least the Event Title is entered
        if (document.getElementById('txtEventTitle').value.length == 0) {
            alert("You Must have an Event Title for this event");
            document.getElementById('txtEventTitle').focus();
        }
        strUserItems = strUserItems.substring(0, (strUserItems.length - 1));
        toServerUserItems.value = strUserItems;
        strPayItems = strPayItems.substring(0, (strPayItems.length - 1));
        toServerPayItems.value = strPayItems;
        toServer.value = 'Submit';
        theForm.submit(); //For Server side submit
    }
}

function cancelNewEvent() {
    var toCancelServer = document.getElementById('fromClient');
        toCancelServer.value = 'Cancel';
        theForm.submit(); //For Server side submit
}

//General ClientSide Functions
function getTimeStamp() {
    var now = new Date();
    var year = now.getFullYear();
    var month = now.getMonth();
    var day = now.getDate();
    var hour = now.getHours();
    var min = now.getMinutes();
    var sec = now.getSeconds();
    var msec = now.getMilliseconds();
    month += 1;
    if (month < 10) {
        month = '0' + month;
    }
    if (day < 10) {
        day = '0' + day;
    }
    if (hour < 10) {
        hour = '0' + hour;
    }
    if (min < 10) {
        min = '0' + min;
    }
    if (sec < 10) {
        sec = '0' + sec;
    }
    if (msec < 100) {
        if (msec < 10) {
            msec = '00' + msec;
        } else {
            msec = '0' + msec;
        }
    }
    return year.toString() + month.toString() + day.toString() + hour.toString() + min.toString() + sec.toString() + msec.toString();
}

//Must always be at the end of each .js file to notify server that the script load completed.
if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
