var verifyAssociation = false;
var verifyAssociationSourceCode = false;
var verifyCoupon = false;
var verifySpouse = false;
var verifyRegTypeSourceCode = false;
var verifyRegData = false;
var regDataDesc = "";
var conferenceId = "";

function changeType(thisRegType, confId, isAssociation, hasExhibitorCoupon, regDataJson, passport, spouse, sessionId) {

    clearBoxes();

    conferenceId = confId;

    if(regDataJson!='') {
        var regDataObj = eval('(' + regDataJson + ')');
        showRegistrationDataBox(thisRegType.value,regDataObj);
    }
    
    if(hasExhibitorCoupon) {
        showExhibitorCouponBox(thisRegType.value, exhibitorArray);
    }
    if(isAssociation) {
        var needsSourceCode = false;
        if(confId==366) {
            needsSourceCode = true;
        }
        showAssociations(thisRegType.value, associationArray, needsSourceCode);
    }

    if(confId==363 || confId==373) {
        if(thisRegType.value==14 || thisRegType.value==15) {
            showRegTypeSourceCode(thisRegType.value);
        }
    }

    if(confId==374) {
        fdicAlert(thisRegType.value);
    }

    //showEvents(thisRegType.value, confId, sessionId, 0, passport);
    //showMiscItems(thisRegType.value, confId, sessionId, 0, spouse);

}

function showRegistrationDataBox(regtypeid,regDataObj) {

    var regdataHtml = "<br/>";
    regdataHtml += "<table border=0 cellpadding=0 cellspacing=1>";
    regdataHtml += "<tr>";
    regdataHtml += "<td align=right style='white-space: nowrap;'>";
    regdataHtml += regDataObj.desc + ":";
    regdataHtml += "</td>";
    regdataHtml += "<td>";
    regdataHtml += "<input type=text name=registrationData size=15 maxlength=100 />";
    regdataHtml += "</td>";
    regdataHtml += "</tr>";
    regdataHtml += "</table>";

    var thisDiv = getObjectById("regdataBox" + regtypeid);
    thisDiv.innerHTML = regdataHtml;
    thisDiv.style.display='block';

    regDataDesc = regDataObj.desc;

    if(regDataObj.required=='Y') {
        verifyRegData = true;
    }

}


function showExhibitorCouponBox(regtypeid, exhibArray) {

    var couponHtml = "<br/>";
    couponHtml += "<table border=0 cellpadding=0 cellspacing=1 style='margin:0;padding:0;'>";
    couponHtml += "<tr>";
    couponHtml += "<td align=right style='white-space: nowrap;'>Coupon Code:</td>";
    couponHtml += "<td align=left><input type=text name=exhibitorCouponCode size=10 maxlength=30></td>";
    couponHtml += "</tr>";
    couponHtml += "<tr>";
    couponHtml += "<td align=right style='white-space: nowrap;'>Exhibitor:</td>";
    couponHtml += "<td align=left>";
    couponHtml += "<select name=exhibitorCouponId>";
    couponHtml += "<option />";

    for(i=0; i < exhibArray.length; i++) {
    couponHtml += "<option value='" + exhibArray[i][0] + "'>" + exhibArray[i][1] + "</option>";
    }
    couponHtml += "</select>";
    couponHtml += "</td>";
    couponHtml += "</tr>";
    couponHtml += "</table><br/>";

    var thisDiv = getObjectById("couponBox" + regtypeid);
    thisDiv.innerHTML = couponHtml;
    thisDiv.style.display='block';

    verifyCoupon = true;

}

function showAssociations(regtypeid, assocArray, needsSourceCode) {

    var assocHtml = "<br/>";
    assocHtml += "<table border=0 cellpadding=0 cellspacing=1>";
    assocHtml += "<tr>";
    assocHtml += "<td align=right style='white-space: nowrap;'>";
    assocHtml += "Select Your Association:";
    assocHtml += "</td>";
    assocHtml += "<td>";
    assocHtml += "<select name=Association>";
    assocHtml += "<option/>";
    for(i=0; i < assocArray.length; i++) {
    assocHtml += "<option value='" + assocArray[i][0] + "'>" + assocArray[i][1] + "</option>";
    }
    assocHtml += "</select>";
    assocHtml += "</td>";
    assocHtml += "</tr>";
    if(needsSourceCode) {
    assocHtml += "<tr>";
    assocHtml += "<td align=right style='white-space: nowrap;'>";
    assocHtml += "Association Source Code:";
    assocHtml += "</td>";
    assocHtml += "<td>";
    assocHtml += "<input type=text name=mktgsourcecode  size=10 maxlength=15 />";
    assocHtml += "</td>";
    assocHtml += "</tr>";
    }
    assocHtml += "</table>";

    var thisDiv = getObjectById("assocBox" + regtypeid);
    thisDiv.innerHTML = assocHtml;
    thisDiv.style.display='block';

    verifyAssociation = true;
    verifyAssociationSourceCode = needsSourceCode;
}



function showRegTypeSourceCode(regtypeid) {
    clearBoxes();

    var assocHtml = "<br/>";
    assocHtml += "<table border=0 cellpadding=0 cellspacing=1>";
    assocHtml += "<tr>";
    assocHtml += "<td align=right style='white-space: nowrap;'>";
    assocHtml += "Promo Code:";
    assocHtml += "</td>";
    assocHtml += "<td>";
    assocHtml += "<input type=text name=mktgsourcecode  size=15 maxlength=100 />";
    assocHtml += "</td>";
    assocHtml += "</tr>";
    assocHtml += "</table>";

    var thisDiv = getObjectById("assocBox" + regtypeid);
    thisDiv.innerHTML = assocHtml;
    thisDiv.style.display='block';
    
    verifyRegTypeSourceCode = true;
}

function clearBoxes() {

    if(document.regtypeForm.RegistrationType.length > 1) {
        for(x=0;x<document.regtypeForm.RegistrationType.length;x++) {
            var couponDiv = getObjectById("couponBox" + document.regtypeForm.RegistrationType[x].value);
            couponDiv.innerHTML = "";
            couponDiv.style.display='none';

            var assocDiv = getObjectById("assocBox" + document.regtypeForm.RegistrationType[x].value);
            assocDiv.innerHTML = "";
            assocDiv.style.display='none';

            var regdataDiv = getObjectById("regdataBox" + document.regtypeForm.RegistrationType[x].value);
            regdataDiv.innerHTML = "";
            regdataDiv.style.display='none';

        }
    } else {
        var couponDiv = getObjectById("couponBox" + document.regtypeForm.RegistrationType.value);
        couponDiv.innerHTML = "";
        couponDiv.style.display='none';

        var assocBox = getObjectById("couponBox" + document.regtypeForm.RegistrationType.value);
        assocBox.innerHTML = "";
        assocBox.style.display='none';

        var regdataDiv = getObjectById("regdataBox" + document.regtypeForm.RegistrationType.value);
        regdataDiv.innerHTML = "";
        regdataDiv.style.display='none';
    }

    verifyCoupon = false;
    verifyAssociation = false;
    verifyAssociationSourceCode = false;
    verifyRegTypeSourceCode = false;
    verifyRegData = false;
    regDataDesc = "";
}

function fdicAlert(id) {
    switch (id){
        case '540':
            alert("Be sure to select your HOT workshops/evolutions (see instructions at top of page)");
            break;
        case '543':
            alert("Be sure to select your HOT workshops/evolutions (see instructions at top of page)");
            break;
        case '3':
            alert("ADVISORY: Your registration type selection does NOT include HOT workshops (see instructions at top of page)");
            break;
    }
}


function verifyRegTypeForm() {

    isChecked = false;

    if(document.regtypeForm.RegistrationType.length > 1) {
        for(x=0; x<document.regtypeForm.RegistrationType.length; x++) {
            if(document.regtypeForm.RegistrationType[x].checked) {
                isChecked = true;
                break;
            }
        }
    } else {
        if(document.regtypeForm.RegistrationType.checked) {
            isChecked = true;
        }
    }

    if(!isChecked) {
        alert("Please Select A Registration Type");
        return false;
    }

   /**** Reg Data Verify ****/
    if(verifyRegData) {
        if(document.regtypeForm.registrationData.value.length<1) {
            alert("Please Provide Your " + regDataDesc);
            return false;
        }
   }

    /**** Coupon Verify ****/
    if(verifyCoupon) {

        if(document.regtypeForm.exhibitorCouponCode.value.length<1) {
            alert("You Must Provide The Coupon Code For This Registration Type");
            return false;
        }
        if(document.regtypeForm.exhibitorCouponId[document.regtypeForm.exhibitorCouponId.selectedIndex].value=="") {
            alert("You Must Select The Exhibitor Who Provided Your Coupon");
            return false;
        }
    }

    /**** Association Type Verify ****/
    if(verifyAssociation) {
        if(document.regtypeForm.Association.value.length<1) {
            alert("Please select your Association");
            return false;
        }
    }

    /**** Verify Association Source Code ****/
    if(verifyAssociationSourceCode) {
        var validCode = false;


        if(conferenceId=='366' && document.regtypeForm.Association.value=='353' && document.regtypeForm.mktgsourcecode.value=='10001') {
            validCode = true;
        } else if(conferenceId=='366' && document.regtypeForm.Association.value=='354' && document.regtypeForm.mktgsourcecode.value=='20002') {
            validCode = true;
        } else if(conferenceId=='366' && document.regtypeForm.Association.value=='355' && document.regtypeForm.mktgsourcecode.value=='30003') {
            validCode = true;
        } else if(conferenceId=='366' && document.regtypeForm.Association.value=='376' && document.regtypeForm.mktgsourcecode.value=='40004') {
            validCode = true;
        } else if(conferenceId=='366' && document.regtypeForm.Association.value=='385' && document.regtypeForm.mktgsourcecode.value=='50005') {
            validCode = true;    
        }


        if(!validCode) {
            alert("The Association Promotional Code Does Not Match The Association You Provided");
            return false;
        }
    }

    /**** Verify Reg Type Source Code ****/
    if(verifyRegTypeSourceCode) {
      
        var validCode = false;
        regtypeid = "";

        if(document.regtypeForm.RegistrationType.length > 1) {
            for(x=0; x<document.regtypeForm.RegistrationType.length; x++) {
                if(document.regtypeForm.RegistrationType[x].checked) {
                    regtypeid = document.regtypeForm.RegistrationType[x].value;
                    break;
                }
            }
        } else {
            if(document.regtypeForm.RegistrationType.checked) {
                 regtypeid = document.regtypeForm.RegistrationType.value;
            }
        }

        if((conferenceId=='363' || conferenceId=='373') && (regtypeid=='14' || regtypeid=='15') && (document.regtypeForm.mktgsourcecode.value.toUpperCase()=='PGDP' || document.regtypeForm.mktgsourcecode.value.toUpperCase()=='APPA-PG')) {
            document.regtypeForm.mktgsourcecode.value = document.regtypeForm.mktgsourcecode.value.toUpperCase();
            validCode = true;
        }

        if(!validCode) {
            alert("The Promo Code Does Not Match The Registration Type You Provided");
            return false;
        }
    }


    return true;
}

