Event.observe(window, 'load', function() {
    if(!$('whiteLabel')){
	   $('container').setStyle({'background':'transparent url(../img/branding/bg-body.png) repeat-y scroll center top'})	
	}
});

document.observe("dom:loaded", function() {

    if($('true') != null) {

        if($('true').checked == true) {
            if($('accntLockedBy') != null) {
                $('accntLockedBy').show();
            }

            if($('accntLockedDate') != null) {
                $('accntLockedDate').show();
            }
            $('accntLockedReason').show();

            } else {
                if($('accntLockedBy') != null) {
                    $('accntLockedBy').hide();
                }

                if($('accntLockedDate') != null) {
                    $('accntLockedDate').hide();
                }
                $('accntLockedReason').hide();
        }
    }

    $$('[name="userAccountStatus.accountLocked"]').each(function(elmtOpsLockUnlock) {

        elmtOpsLockUnlock.observe('click',function() {

            if($('true').checked == true) {
                if($('accntLockedBy') != null) {
                    $('accntLockedBy').show();
                }

                if($('accntLockedDate') != null) {
                    $('accntLockedDate').show();
                }
                $('accntLockedReason').show();

            }else {
                if($('accntLockedBy') != null) {
                    $('accntLockedBy').hide();
                }

                if($('accntLockedDate') != null) {
                    $('accntLockedDate').hide();
                }
                $('accntLockedReason').hide();
            }
            });
        });
    /* End - Ops Locking/Unlocking */

    //Site.js code need to move there.
    $('branding-logo').setStyle({'cursor':'pointer'}).observe('click', function(){
            window.location = "#";
    });

    /* UCDON0010 related java script start */
       if($('nextId')!=null || $('nextDisabledId')!=null ){
        $('nextId').hide();
        $('nextDisabledId').show();
       }
    /* UCDON0010 related java script end */

    /*FUR0070 Start*/
    //Accessing a div using class name.
    var element = $$('div.fur0070hiddenDiv');
    if(element.size()>0){
        if($('S') != null && $('S').checked == true) {
            element[0].show();
            if($F('selectedCharityName').length >0 ){
             $('charityName').value=$F('selectedCharityName');
              //$('charityName').readOnly=true;
            }
        }else {
            element[0].hide();
        }
    }
    var element2 = $$('div.fur0080hiddenDiv');
    if(element2.size()>0) {
        if($('addJsLink')!=null )
            $('addJsLink').show(); // Show js add link
        if($('M') == null || $('M').checked == true) {
            element2[0].show();
                var charitySupportedInd="";
                var fundraiserSplitOverrideInd="";
                if($('charitySupportedInd')){
                    charitySupportedInd=$F('charitySupportedInd');
                }
        }else {
            element2[0].hide();
        }
        //On load call for UCFUR0070 back button.
        //onloadCharitydetails();
    }


    if($('S') != null){
    $('S').observe('click', function(event){
        element[0].show();
        element2[0].hide();
        onChangeMultipleCharityIndicator();

     });
    }
    if($('M') != null){
    $('M').observe('click', function(event){
        element[0].hide();
        element2[0].show();
        onChangeMultipleCharityIndicator();
     });
    }
    /*FUR0070 End*/

       if($('otherHiddenField') != null){
            $('otherHiddenField').hide();
            if($('OtherOccasion') != null){
            if($('OtherOccasion').checked == true) {
                $('otherHiddenField').show();
            }
            $$('[name="personalChallengeEvents.specialOccasion"]').each(function(elmt) {
                elmt.observe('click',function(){

                if($('OtherOccasion').checked == true) {
                    $('otherHiddenField').show();
                }else {
                    $('otherHiddenField').hide();
                }
                });
            });
            }
           }


       /*UCFUR0010 Speical occasion - Start */
       if($('otherHiddenField') != null){
            $('otherHiddenField').hide();
            if($('OTHER_OCC') != null){
            if($('OTHER_OCC').checked == true) {
                $('otherHiddenField').show();
            }
            $$('[name="specialOccasionEvents.specialOccasion"]').each(function(elmt) {
                elmt.observe('click',function(){

                if($('OTHER_OCC').checked == true) {
                    $('otherHiddenField').show();
                }else {
                    $('otherHiddenField').hide();
                }
                });
            });
            }
           }
       /*UCFUR0010 Speical occasion - End */

            if($('otherHiddenFieldMore') != null){
            $('otherHiddenFieldMore').hide();

            if($('OTHER') != null){
            if($('OTHER').checked == true) {
                $('otherHiddenFieldMore').show();
            }
            $$('[name="personalChallengeEvents.challengeDetails"]').each(function(elmt) {
                elmt.observe('click',function(){

                if($('OTHER').checked == true) {
                    $('otherHiddenFieldMore').show();
                }else {
                    $('otherHiddenFieldMore').hide();
                }
                });
            });
            }
           }


             var elementForFur40 = $$('div.fur0040Hiddencontent');
             if(elementForFur40.size()>0) {
                $$('div.fur0040Hiddencontent')[0].hide();
                if($('N') != null){
                if($('N').checked == true) {
                    $$('div.fur0040Hiddencontent')[0].show();
                }

                $$('[name="personalChallengeEvents.organisedEvent"]').each(function(elmt) {


                    elmt.observe('click',function(){

                    if($('N').checked == true) {

                        $$('div.fur0040Hiddencontent')[0].show();
                    }else {
                        $$('div.fur0040Hiddencontent')[0].hide();
                    }
                    });
                });
                }
             }

             var elementForFur40 = $$('div.fur0040Hiddencontent');
             if(elementForFur40.size()>0) {
                $$('div.fur0040Hiddencontent')[0].hide();
                if($('U') != null){
                if($('U').checked == true) {
                    $$('div.fur0040Hiddencontent')[0].show();
                }

                $$('[name="fundraisingEvents.organisedEvent"]').each(function(elmt) {


                    elmt.observe('click',function(){

                    if($('U').checked == true) {

                        $$('div.fur0040Hiddencontent')[0].show();
                    }else {
                        $$('div.fur0040Hiddencontent')[0].hide();
                    }
                    });
                });
                }
             }

             var elementForFur40 = $$('div.fur0040Hiddencontent');
             if(elementForFur40.size()>0) {
                $$('div.fur0040Hiddencontent')[0].hide();

                if($('U') != null){
                if($('U').checked == true) {
                    $$('div.fur0040Hiddencontent')[0].show();
                }

                $$('[name="specialOccasionEvents.organisedEvent"]').each(function(elmt) {


                    elmt.observe('click',function(){

                    if($('U').checked == true) {

                        $$('div.fur0040Hiddencontent')[0].show();
                    }else {
                        $$('div.fur0040Hiddencontent')[0].hide();
                    }
                    });
                });
                }
             }

                if($('otherHiddenFieldEvents') != null){
                $('otherHiddenFieldEvents').hide();
                if($('018') != null){
                if($('018').checked == true) {
                    $('otherHiddenFieldEvents').show();
                }
                $$('[name="fundraisingEvents.activityRaisedMoney"]').each(function(elmt) {
                    elmt.observe('click',function(){

                    if($('018').checked == true) {
                        $('otherHiddenFieldEvents').show();
                    }else {
                        $('otherHiddenFieldEvents').hide();
                    }
                    });
                });
                }
                }

                if($('otherHiddenFieldPersonal') != null){
                $('otherHiddenFieldPersonal').hide();

                if($('039') != null){

                if($('039').checked == true) {
                    $('otherHiddenFieldPersonal').show();
                }
                $$('[name="personalChallengeEvents.activityRaisedMoney"]').each(function(elmt) {
                    elmt.observe('click',function(){

                    if($('039').checked == true) {
                        $('otherHiddenFieldPersonal').show();
                    }else {
                        $('otherHiddenFieldPersonal').hide();
                    }
                    });
                });
                }
                }


                if($('otherHiddenFieldSpecial') != null){
                $('otherHiddenFieldSpecial').hide();
                if($('009') != null){
                if($('009').checked == true) {
                    $('otherHiddenFieldSpecial').show();
                }
                $$('[name="specialOccasionEvents.activityRaisedMoney"]').each(function(elmt) {
                    elmt.observe('click',function(){

                    if($('009').checked == true) {
                        $('otherHiddenFieldSpecial').show();
                    }else {
                        $('otherHiddenFieldSpecial').hide();
                    }
                    });
                });
                }
                }


            /*FUR0070 End*/

            /*Donar page starts*/

            // For donation to charity to include donors message, assign the on click behavior for the check box.
            if($('includeMessage') != null)
            {
                 $('myMessage').writeAttribute("disabled", "disabled");
                 $('includeMessage').observe('click', function(event){

                    if($('includeMessage').checked == true)
                    {
                        if($('myMessage').value.length > 0)
                        {
                            $('myMessage').value = "";
                        }
                        $('myMessage').removeAttribute("disabled");
                        $('myMessage').removeClassName('disabledStyle');
                    }
                    else
                    {
                        if($('myMessage').value.length > 0)
                        {
                            $('myMessage').value = "";
                        }
                        $('myMessage').writeAttribute("disabled", "disabled");
                        $('myMessage').addClassName('disabledStyle');
                    }
                });
            }

            // For donation to fundraiser to include donors message, assign the on click behavior for the check box.
            if($('fundraserIncludeMessage') != null){
                 $('fundraiserMyMessage').removeClassName('disabledStyle');
                 $('fundraserIncludeMessage').observe('click', function(event){

                     if($('fundraserIncludeMessage').checked == true)
                     {
                        if($('fundraiserMyMessage').value.length > 0)
                        {
                            $('fundraiserMyMessage').value = "";
                        }
                        $('fundraiserMyMessage').removeAttribute("disabled");
                        $('fundraiserMyMessage').removeClassName('disabledStyle');
                     }
                     else
                     {
                        if($('fundraiserMyMessage').value.length > 0)
                        {
                            $('fundraiserMyMessage').value = "";
                        }
                        $('fundraiserMyMessage').writeAttribute("disabled", "disabled");
                        $('fundraiserMyMessage').addClassName('disabledStyle');
                     }
                });
            }

            // For fundraiser and charity the donors name to be assigned the on click behavior on the check box.
            if($('showName') != null){
                 $('myName').writeAttribute("disabled", "disabled");
                 $('showName').observe('click', function(event){

                    if($('showName').checked == true)
                    {
                        if($('myName').value.length > 0)
                        {
                            $('myName').value = "";
                        }
                        $('myName').removeAttribute("disabled");
                        $('myName').removeClassName('disabledStyle');
                    }
                    else
                    {
                        if($('myName').value.length > 0)
                        {
                            $('myName').value = "";
                        }
                        $('myName').writeAttribute("disabled", "disabled");
                        $('myName').addClassName('disabledStyle');

                    }
                 });
            }

            // For fundraiser donation we need the my message section ticked by default. Even if it is not
            // mandatory. On fresh load and all subsequent load it would be enabled.

			
			
            if($('fundraiserMyMessage') != null){
                $('fundraserIncludeMessage').checked = true;
                $('fundraiserMyMessage').removeAttribute("disabled");
                $('fundraiserMyMessage').removeClassName('disabledStyle');
            }

            // For both fundraiser and charity donation we need the my message to be enabled only if
            // message is provided. On fresh load it would be disabled in all other cases it would
            // depend on the value in the text area.
            if($('myMessage') != null)
            {
                if ($('myMessage').value.length > 0)
                {
                    $('includeMessage').checked = true;
                    $('myMessage').removeAttribute("disabled");
                    $('myMessage').removeClassName('disabledStyle');
                }
                else{
                    $('myMessage').writeAttribute("disabled", "disabled");
                    $('myMessage').addClassName('disabledStyle');
                    $('myMessage').value = "";
                    $('includeMessage').checked = false;
                }
            }

            // For both fundraiser and charity donation we need the show name of donor to be enabled only if
            // name is provided. On fresh load it would be disabled in all other cases it would
            // depend on the value in the text field.
            if($('myName') != null)
            {
                if ($('myName').value.length > 0)
                {
                    $('showName').checked = true;
                    $('myName').removeAttribute("disabled");
                    $('myName').removeClassName('disabledStyle');
                }
                else{
                    $('myName').writeAttribute("disabled", "disabled");
                    $('myName').addClassName('disabledStyle');
                    $('myName').value = "";
                    $('showName').checked = false;
                }
            }


			if ($('fundraiserPage')){
				 $('showName').checked = true;
				 $('myName').removeAttribute("disabled");
				 $('myName').removeClassName('disabledStyle');				
			}
			


/* Collect gift Aid  Start */
            $$('[name="giftAidOwnMoney"]').each(function(eleme) {

                if($('giftAidYes').checked == true && getBenefitInKindOrNot=="Y") {
                    $('giftAidNotes').show();

                }else {
                    $('giftAidNotes').hide();
                }
                eleme.observe('click',function(){

                if($('giftAidYes').checked == true && getBenefitInKindOrNot=="Y") {
                //TODO-To check benefitInKindorNot in future
                if($('giftAidYes').checked == true) {
                    $('giftAidNotes').show();

                }else {
                    $('giftAidNotes').hide();
                }
                }
                });
            });

            showAndHideGiftAidDetails();

            $$('[name="addressDetailsCorrect"]').each(function(elemen) {
                elemen.observe('click',function(){

                if($('detailCorrectNo').checked == true) {

                    if($('changeAddressDisplay')!="" && $('changeAddressDisplay')!=null ){
                    $('changeAddressDisplay').show();
                    }
                    if($('changeAddress')!="" && $('changeAddress')!=null ){
                        $('changeAddress').show();
                    }

                }
                if($('detailCorrectYes').checked == true) {

                if($('changeAddressDisplay')!="" && $('changeAddressDisplay')!=null ){
                    $('changeAddressDisplay').hide();
                    }
                if($('changeAddress')!="" && $('changeAddress')!=null ){
                    $('changeAddress').hide();
                }

                }

                });
            });
            /* Collect gift Aid  End */
            //added for UCDON0100 to show or hide Payment date details.
            selectMonthOfDay();
            onSelectAmount();
            /**Start makeDonationForFundraiser.jsp*/
            $$('[name="allocateYourDonate"]').each(function(radioAllocateYourDonate) {
                radioAllocateYourDonate.observe('click',function(){
                    if($('indvidualMember').checked == true) {
                        $('memberName').removeAttribute("disabled");
                    }else{
                        $('memberName').writeAttribute("disabled", "disabled");
                    }
                });
            });
            /**End makeDonationForFundraiser.jsp*/

            /** Code for tooltip start*/
            $$('div.open_error_popup').each(function(elmt){
                elmt.className = 'error_popup_closed';
            });
            /** Code for tooltip end*/

            /** Fundraiser Portal */
            $$('ul.groupSubmenu').each( function(elmt) {
                elmt.hide();
            });

            $$('legend.legendportal').each( function(elemt) {
                elemt.observe('click', function() {

                    $$('ul.groupSubmenu').each( function(elmt) {
                     elmt.hide();
            });
                    var ele = elemt.siblings('ul')[0];
                    Effect.toggle(ele.id, 'blind', {
                        duration :0.5
                    });
                    elemt.toggleClassName("open");
                });
            });

            if($('haveCharityContri') != null){
                $('haveCharityContri').innerHTML = "Has your charity contributed to the cost of your event?*";
            }
            $$('[name="fundraisingReasonBean.howManyCharities"]').each(function(elemt) {
                elemt.observe('click',function(){
                    if($('M').checked == true) {
                        $('haveCharityContri').innerHTML = "Have any of your charities contributed to the cost of your event?* ";
                    }else{
                        $('haveCharityContri').innerHTML = "Has your charity contributed to the cost of your event?*";
                    }
                });
            });

            if($('yourTeamTable') != null){

                if($('yourTeamTable').down().down('tr').siblings().size() == 0  ){

                       if( $('teamMemberRemoveLink') != null && $('teamMemberRemoveLink') !='' ){
                       $('teamMemberRemoveLink').hide();
                   }

                    if($('networkMemberRemoveLink')!=null && $('networkMemberRemoveLink')!='' ){
                    $('networkMemberRemoveLink').hide();
                      }

            }
            }

            if($('yourTeamTable') != null){

                if( $('yourTeamTable').down().down('tr').siblings().size() == 1 ){

                     if($('teamAmendMemberRemoveLink')!=null && $('teamAmendMemberRemoveLink')!='' ){
                         $('teamAmendMemberRemoveLink').hide();
                       }

                }
            }

            $$('form').each(function(elemt) {
                elemt.writeAttribute("autocomplete", "off");
            });

        });

//End of onload function.
/* prototype for Unique Url Page -start */
// Check Address ajax call - start */

function checkAddressUrl(){
       var urlProfileName = $F('profilePageAddress');
       var allowChars=/^[0-9A-Za-z$\-_\.+!*'(),]{0,104}$/;
       var errorMsg;
       document.getElementById('showError').innerHTML="";
       if(urlProfileName == "") {
            errorMsg="Please enter a profile name as you want it to appear in your web address.";
            document.getElementById('showError').innerHTML=errorMsg;
            $('showError').show();
            $('crossImage').show();
            if ($('fieldError') != null && $('fieldError') !="") {
                $('fieldError').hide();
            }
       } else if(!(allowChars.test(urlProfileName)) ) {
             errorMsg="Invalid characters included within your Profile name. Please try again.";
             document.getElementById('showError').innerHTML=errorMsg;
             $('showError').show();
             $('crossImage').show();
             if ($('fieldError') != null && $('fieldError') !="") {
                $('fieldError').hide();
             }
       } else {
           var urlName = escape(urlProfileName);
           var url = "ajaxCheckAddress.action";
           var params = 'urlProfileName=' + urlName;
               new Ajax.Request(url, {
                method :'POST',
                parameters :params,
                asynchronous :true,
                onSuccess :showUrlResponse
            });
       }

       function showUrlResponse(transport){
            var xml_doc = transport.responseXML.documentElement;
            hideTickImage();
            $('checkAddress').href='#';
            var errorMsg = xml_doc.getAttribute("filedErrorMessage");
            if (errorMsg != null && errorMsg != '') {
                $('showError').show();
                if($('error')!= null && $('error')!="") {
                     $('error').hide();
                }
                $('showError').innerHTML = errorMsg;
                if($('crossImage')!= null && $('crossImage')!="") {
                    $('crossImage').show();
                }
            } else {
                var record = xml_doc.getAttribute("record");
                var profileName = xml_doc.getAttribute("profileName");

                if(record=="NOREC"){
                     if($('radioOptions')!= null && $('radioOptions')!="") {
                     $('radioOptions').hide();
                     }
                     if($('error')!= null && $('error')!="") {
                     $('error').hide();
                     }
                     if($('errorMsg')!= null && $('errorMsg')!="") {
                        $('errorMsg').hide();
                      }
                     if($('alternativeAddressTitle')!= null && $('alternativeAddressTitle')!="") {
                     $('alternativeAddressTitle').hide();
                     }
                     if($('profilePageAddress')!= null && $('profilePageAddress')!="") {
                     $('profilePageAddress').value=profileName;
                     }
                     if($('tickImage')!= null && $('tickImage')!="") {
                     $('tickImage').show();
                     }
                     $('checkAddress').href='#';
                }
                if(record=="REC"){
                    var outerPara = document.createElement('p');
                     var htmlText = "";
                     if($('radioOptions')!= null && $('radioOptions')!="") {
                     $('radioOptions').innerHTML="";
                     }
                     if(virginURL == null) {
                         virginURL = "";
                     }
                    for (i = 0; i < xml_doc.childNodes[0].childNodes.length; i++) {
                        var populateSelectedUrl = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("selectedUrl");
                        var inputRadioComponent = "<input type=\"radio\" value=\""+populateSelectedUrl+"\" id=\"selectedUrl_"+i+"\" name=\"createUrlBean.selectedAlternativeUrl\"/>";
                        var labelRadioComponent = "<label id=\"label_"+i+"\" for=\"selectedUrl_"+i+"\">"+virginURL+populateSelectedUrl+"</label>";
                        htmlText += inputRadioComponent;
                        htmlText += labelRadioComponent;
                    }

                    if($('err1')!= null && $('err1')!="") {
                        $('err1').innerHTML="There's another fundraiser out there with the same name!";
                    }
                    if($('err2')!= null && $('err2')!="") {
                        $('err2').innerHTML="We've suggested an alternative below but you can always";
                    }
                    if($('err3')!= null && $('err3')!="") {
                        $('err3').innerHTML="try a different name and check if it's available.";
                    }

                    if($('error')!= null && $('error')!="") {
                        $('error').show();
                    }
                    if($('errorMsg')!= null && $('errorMsg')!="") {
                        $('errorMsg').show();
                        }

                    if($('alternativeAddressTitle')!= null && $('alternativeAddressTitle')!="") {
                        $('alternativeAddressTitle').show();
                    }

                    outerPara.innerHTML = htmlText;

                     if($('radioOptions')!= null && $('radioOptions')!="") {
                         $('radioOptions').show();
                         $('radioOptions').appendChild(outerPara);
                     }
                     if($('checkAddressAlternative')!= null && $('checkAddressAlternative')!="") {
                        $('checkAddressAlternative').show();
                        }

                     $('profilePageAddress').value=profileName;

                    if($('crossImage')!= null && $('crossImage')!="") {
                        $('crossImage').show();
                    }
                    $('checkAddress').href='#';
                }
            }
     }
}

/* Check Address ajax call - start */
 function hideTickImage() {
     if($('tickImage') != null) {
        $('tickImage').hide();
     }
     if($('crossImage') != null) {
        $('crossImage').hide();
     }
     if($('showError') != null) {
        $('showError').hide();
     }
     if($('errorEmptyUrlName') != null) {
        $('errorEmptyUrlName').hide();
     }
     if($('fieldError') != null) {
        $('fieldError').hide();
     }
     if($('errorImageForTeam') != null) {
            $('errorImageForTeam').hide();
     }
     if($('checkAddress') != null){
         $('checkAddress').href='javascript:checkAddressUrl()';
     }
     if($('checkTeamAddress') != null){
         $('checkTeamAddress').href='javascript:checkTeamAddressUrl()';
     }
 }
 /* Check Address ajax call - start */

/* prototype for Unique Url Page -start */

/* Confirm chosen charity  */
 function addSelectedCharity() {
     var selectedCharityName = $F('addCharityName');
     var selectedCharityId = $F('addCharityId');
     var allowChars=/[a-zA-Z0-9]{1}[a-zA-Z0-9 ]{0,40}/;
     var error;

     $('showError').hide();
     var url = "ajaxAddCharityAction.action";
     var params = 'selectedCharityName=' + escape(selectedCharityName);
     params = params + '&selectedCharityId=' + selectedCharityId;

     new Ajax.Request(url, {
            method :'POST',
            parameters :params,
            asynchronous :true,
            onSuccess :displayUrlResponse
        });

    $('multiCharityErrorImage').hide();
    $('multiCharityErrorMessage').hide();
    $('showError').hide();
    $('showExceedFive').hide();
    $('charityAlreadyExist').hide();

     function displayUrlResponse(transport){
            var NODE_ERROR_CODE = "errorCode";
            var NODE_ERROR_DESCRIPTION = "errorDescription";
            var VALIDATION_CODE_BLANK_TEXT_PROVIDED =  "BLANK_TEXT_PROVIDED";
            var VALIDATION_CODE_INVALID_CHARACTERS =  "INVALID_CHARACTERS_FOR_CHARITY_NAME";

            var xml_doc = transport.responseXML.documentElement;
            var errorMessage = xml_doc.getAttribute("errorMessage");
            var charityName = xml_doc.getAttribute("selcharityName");
            var errorCode = xml_doc.getAttribute(NODE_ERROR_CODE);
            var errorDescription = xml_doc.getAttribute(NODE_ERROR_DESCRIPTION);

            if (errorCode == VALIDATION_CODE_BLANK_TEXT_PROVIDED) {
                 error="<font color='red'>"+errorDescription+"</font>";
                 document.getElementById('showError').innerHTML=error;
                 $('showError').show();
                 $('multiCharityErrorImage').show();
            }
            else if (errorCode == VALIDATION_CODE_INVALID_CHARACTERS) {
                 error="<font color='red'>"+errorDescription+"</font>";
                 document.getElementById('showError').innerHTML=error;
                 $('showError').show();
                 $('multiCharityErrorImage').show();
            }
            else
            {

            theList = $('createCharity');
            newList = document.createElement('span');
            theList.parentNode.replaceChild(newList,theList);
            newList.id = "createCharity";

            newCharityTitle = document.createElement('strong');
            newCharityTitle.appendChild(document.createTextNode("Here's how the money will be split between the charities:"));
            newList.appendChild(newCharityTitle);

                if (errorMessage == "No" ) {
                    var percentRaised = 0;
                    for (i = 0; i < xml_doc.childNodes[0].childNodes.length; i++) {

                        var addCharityName = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityName");
                        var addCharityId = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityId");
                        var addCharityFundPercentage = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityFundPercentage");
                        percentRaised = percentRaised + Number(addCharityFundPercentage);
                        newCharity = document.createElement('p');
                        newCharity.setAttribute('class', 'label-above-input');
                        newCharity.id = i;
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            newCharityName = document.createElement('<SPAN class="label-fixed-width"/>');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }else if (navigator.appName == "Netscape")  {
                            newCharityName = document.createElement('span');
                            newCharityName.setAttribute('class', 'label-fixed-width');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }
                        newCharity.appendChild(document.createTextNode(" "));
                        charityId = document.createElement('input');
                        charityId.setAttribute('type', 'hidden');
                        charityId.setAttribute('id', 'charityId'+i);
                        charityId.setAttribute('name', 'charityId'+i);
                        charityId.setAttribute('value', addCharityId);
                        newCharity.appendChild(charityId);
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            charityFundPercent = document.createElement('<input TYPE="text" onChange="onChangeDisplayTotalForCharity('+'value'+','+i+');" id="'+'charityFundPercentage'+i+'" value="'+addCharityFundPercentage+'" size="3" maxlength="3" />');
                            newCharity.appendChild(charityFundPercent);

                        } else if (navigator.appName == "Netscape") {
                            charityFundPercent = document.createElement('input');
                            charityFundPercent.setAttribute('type', 'text');
                            charityFundPercent.setAttribute('id', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('name', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('value', addCharityFundPercentage);
                            charityFundPercent.setAttribute('onchange', "javascript:onChangeDisplayTotalForCharity("+"value"+","+i+");");
                            charityFundPercent.setAttribute('size','3');
                            charityFundPercent.setAttribute('maxlength','3');
                            newCharity.appendChild(charityFundPercent);
                        }
                        newCharity.appendChild(document.createTextNode("%"));
                        newCharity.appendChild(document.createTextNode(" "));
                        removeCharity = document.createElement('a');
                        removeCharity.id = "removeCharity"+i;
                        removeCharity.setAttribute('href', "javascript:deletedSelectedCharity("+i+");");
                        removeCharity.appendChild(document.createTextNode("Remove"));
                        newCharity.appendChild(removeCharity);
                        newList.appendChild(newCharity);
                    }

                    fundSplitPercentAdd = document.createElement('p');
                         fundSplitPercentAdd.setAttribute('class', 'label-above-input');
                         fundSplitPercentAdd.id = 'totalSplitAdd';
                         fundSplitPercentAdd.appendChild(document.createTextNode("Total fund split = "));
                         fundSplitPercentAdd.appendChild(document.createTextNode(percentRaised));
                         fundSplitPercentAdd.appendChild(document.createTextNode("%"));
                         newCharity.appendChild(fundSplitPercentAdd);
                         newList.appendChild(fundSplitPercentAdd);



                    hideIds('totalSplitAdd');
                    $('addCharityName').clear();
                    $('addCharityId').clear();
                    $('showExceedFive').hide();
                    $('charityAlreadyExist').hide();

                } else if (errorMessage == "Yes") {
                for (i = 0; i < xml_doc.childNodes[0].childNodes.length; i++) {

                        var addCharityName = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityName");
                        var addCharityId = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityId");
                        var addCharityFundPercentage = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityFundPercentage");

                        newCharity = document.createElement('p');
                        newCharity.setAttribute('class', 'label-above-input');
                        newCharity.id = i;
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            newCharityName = document.createElement('<SPAN class="label-fixed-width"/>');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }else if (navigator.appName == "Netscape")  {
                            newCharityName = document.createElement('span');
                            newCharityName.setAttribute('class', 'label-fixed-width');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }
                        newCharity.appendChild(document.createTextNode(" "));
                        charityId = document.createElement('input');
                        charityId.setAttribute('type', 'hidden');
                        charityId.setAttribute('id', 'charityId'+i);
                        charityId.setAttribute('name', 'charityId'+i);
                        charityId.setAttribute('value', addCharityId);
                        newCharity.appendChild(charityId);
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            charityFundPercent = document.createElement('<input TYPE="text" onChange="onChangeDisplayTotalForCharity('+'value'+','+i+');" id="'+'charityFundPercentage'+i+'" value="'+addCharityFundPercentage+'" size="3" maxlength="3" />');
                            newCharity.appendChild(charityFundPercent);

                        } else if (navigator.appName == "Netscape") {
                            charityFundPercent = document.createElement('input');
                            charityFundPercent.setAttribute('type', 'text');
                            charityFundPercent.setAttribute('id', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('name', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('value', addCharityFundPercentage);
                            charityFundPercent.setAttribute('onchange', "javascript:onChangeDisplayTotalForCharity("+"value"+","+i+");");
                            charityFundPercent.setAttribute('size','3');
                            charityFundPercent.setAttribute('maxlength','3');
                            newCharity.appendChild(charityFundPercent);
                        }
                        newCharity.appendChild(document.createTextNode("%"));
                        newCharity.appendChild(document.createTextNode(" "));
                        removeCharity = document.createElement('a');
                        removeCharity.id = "removeCharity"+i;
                        removeCharity.setAttribute('href', "javascript:deletedSelectedCharity("+i+");");
                        removeCharity.appendChild(document.createTextNode("Remove"));
                        newCharity.appendChild(removeCharity);
                        newList.appendChild(newCharity);
                    }
                var errorDisplay = "<font color='red'>"+errorDescription+"</font>";
                //var errorDisplay = "<font color='red'>You can only select a maximum of 5 charities.</font>";
                    document.getElementById('showExceedFive').innerHTML = errorDisplay;
                    $('addCharityName').clear();
                    $('addCharityId').clear();
                $('showExceedFive').show();
                $('charityAlreadyExist').hide();
                } else if (errorMessage == "charityAlreadyExist") {
                for (i = 0; i < xml_doc.childNodes[0].childNodes.length; i++) {

                        var addCharityName = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityName");
                        var addCharityId = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityId");
                        var addCharityFundPercentage = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityFundPercentage");
                        percentRaised = percentRaised + Number(addCharityFundPercentage);
                        newCharity = document.createElement('p');
                        newCharity.setAttribute('class', 'label-above-input');
                        newCharity.id = i;
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            newCharityName = document.createElement('<SPAN class="label-fixed-width"/>');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }else if (navigator.appName == "Netscape")  {
                            newCharityName = document.createElement('span');
                            newCharityName.setAttribute('class', 'label-fixed-width');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }
                        newCharity.appendChild(document.createTextNode(" "));
                        charityId = document.createElement('input');
                        charityId.setAttribute('type', 'hidden');
                        charityId.setAttribute('id', 'charityId'+i);
                        charityId.setAttribute('name', 'charityId'+i);
                        charityId.setAttribute('value', addCharityId);
                        newCharity.appendChild(charityId);
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            charityFundPercent = document.createElement('<input TYPE="text" onChange="onChangeDisplayTotalForCharity('+'value'+','+i+');" id="'+'charityFundPercentage'+i+'" value="'+addCharityFundPercentage+'" size="3" maxlength="3" />');
                            newCharity.appendChild(charityFundPercent);

                        } else if (navigator.appName == "Netscape") {
                            charityFundPercent = document.createElement('input');
                            charityFundPercent.setAttribute('type', 'text');
                            charityFundPercent.setAttribute('id', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('name', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('value', addCharityFundPercentage);
                            charityFundPercent.setAttribute('onchange', "javascript:onChangeDisplayTotalForCharity("+"value"+","+i+");");
                            charityFundPercent.setAttribute('size','3');
                            charityFundPercent.setAttribute('maxlength','3');
                            newCharity.appendChild(charityFundPercent);
                        }
                        newCharity.appendChild(document.createTextNode("%"));
                        newCharity.appendChild(document.createTextNode(" "));
                        removeCharity = document.createElement('a');
                        removeCharity.id = "removeCharity"+i;
                        removeCharity.setAttribute('href', "javascript:deletedSelectedCharity("+i+");");
                        removeCharity.appendChild(document.createTextNode("Remove"));
                        newCharity.appendChild(removeCharity);
                        newList.appendChild(newCharity);
                    }
                var errorDisplay = "<font color='red'>You have already selected this charity.</font>";
                    document.getElementById('charityAlreadyExist').innerHTML = errorDisplay;
                    $('addCharityName').clear();
                    $('addCharityId').clear();
                $('showExceedFive').hide();
                $('charityAlreadyExist').show();
            }
        }
    }

 }

 function deletedSelectedCharity(charityIndex) {
     var selectedCharityIndex = charityIndex;

     var url = "ajaxDeleteCharityAction.action";
     var params = 'selectedCharityIndex=' + selectedCharityIndex;
     new Ajax.Request(url, {
            method :'POST',
            parameters :params,
            asynchronous :true,
            onSuccess :reDisplayUrlResponse
    });


     function reDisplayUrlResponse(transport){
            var xml_doc = transport.responseXML.documentElement;

            theList = $('createCharity');
            charityListSize = xml_doc.childNodes[0].childNodes.length;
            if (charityListSize == 0) {
                newList = document.createElement('span');
                theList.parentNode.replaceChild(newList,theList);
                newList.id = "createCharity";
                $('createCharity').innerHTML = "";
                $('charityAlreadyExist').hide();
                $('showExceedFive').hide();
            } else {
                newList = document.createElement('span');
                theList.parentNode.replaceChild(newList,theList);
                newList.id = "createCharity";

                newCharityTitle = document.createElement('strong');
                newCharityTitle.appendChild(document.createTextNode("Chosen charities"));
                newList.appendChild(newCharityTitle);
                var percentRaised = 0;

                for (i = 0; i < charityListSize; i++) {

                        var addCharityName = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityName");
                        var addCharityId = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityId");
                        var addCharityFundPercentage = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityFundPercentage");
                        percentRaised = percentRaised + Number(addCharityFundPercentage);

                        newCharity = document.createElement('p');
                        newCharity.setAttribute('class', 'label-above-input');
                        newCharity.id = i;
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            newCharityName = document.createElement('<SPAN class="label-fixed-width"/>');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }else if (navigator.appName == "Netscape")  {
                            newCharityName = document.createElement('span');
                            newCharityName.setAttribute('class', 'label-fixed-width');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }
                        newCharity.appendChild(document.createTextNode(" "));
                        charityId = document.createElement('input');
                        charityId.setAttribute('type', 'hidden');
                        charityId.setAttribute('id', 'charityId'+i);
                        charityId.setAttribute('name', 'charityId'+i);
                        charityId.setAttribute('value', addCharityId);
                        newCharity.appendChild(charityId);
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            charityFundPercent = document.createElement('<input TYPE="text" onChange="onChangeDisplayTotalForCharity('+'value'+','+i+');" id="'+'charityFundPercentage'+i+'" value="'+addCharityFundPercentage+'" size="3" maxlength="3" />');
                            newCharity.appendChild(charityFundPercent);

                        } else if (navigator.appName == "Netscape") {
                            charityFundPercent = document.createElement('input');
                            charityFundPercent.setAttribute('type', 'text');
                            charityFundPercent.setAttribute('id', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('name', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('value', addCharityFundPercentage);
                            charityFundPercent.setAttribute('onchange', "javascript:onChangeDisplayTotalForCharity("+"value"+","+i+");");
                            charityFundPercent.setAttribute('size','3');
                            charityFundPercent.setAttribute('maxlength','3');
                            newCharity.appendChild(charityFundPercent);
                        }
                        newCharity.appendChild(document.createTextNode("%"));
                        newCharity.appendChild(document.createTextNode(" "));
                        removeCharity = document.createElement('a');
                        removeCharity.id = "removeCharity"+i;
                        removeCharity.setAttribute('href', "javascript:deletedSelectedCharity("+i+");");
                        removeCharity.appendChild(document.createTextNode("Remove"));
                        newCharity.appendChild(removeCharity);
                        newList.appendChild(newCharity);
                }

                fundSplitPercentAdd = document.createElement('p');
                         fundSplitPercentAdd.setAttribute('class', 'label-above-input');
                         fundSplitPercentAdd.id = 'totalSplitRemove';
                         fundSplitPercentAdd.appendChild(document.createTextNode("Total fund split = "));
                         fundSplitPercentAdd.appendChild(document.createTextNode(percentRaised));
                         fundSplitPercentAdd.appendChild(document.createTextNode("%"));
                         newCharity.appendChild(fundSplitPercentAdd);
                         newList.appendChild(fundSplitPercentAdd);


                hideIds('totalSplitRemove');
                $('showExceedFive').hide();
                $('charityAlreadyExist').hide();
            }

    }
 }
 /*
 function onloadCharitydetails() {

     var url = "ajaxLoadCharityAction.action";
     new Ajax.Request(url, {
            method :'POST',
            asynchronous :true,
            onSuccess :displayUrlResponse
    });


     function displayUrlResponse(transport){
            var xml_doc = transport.responseXML.documentElement;

            theList = $('createCharity');

            charityListSize = xml_doc.childNodes[0].childNodes.length;

            if (charityListSize == 0) {
                newList = document.createElement('span');
                theList.parentNode.replaceChild(newList,theList);
                newList.id = "createCharity";
                $('createCharity').innerHTML = "";
            } else {
                newList = document.createElement('span');
                theList.parentNode.replaceChild(newList,theList);
                newList.id = "createCharity";

                newCharityTitle = document.createElement('strong');
                newCharityTitle.appendChild(document.createTextNode("Chosen charities"));
                newList.appendChild(newCharityTitle);
                var charitySupportedInd="";
                var fundraiserSplitOverrideInd="";
                var percentRaised = 0;

                if($('charitySupportedInd')){
                    charitySupportedInd=$F('charitySupportedInd');
                    fundraiserSplitOverrideInd=$F('fundraiserSplitOverrideInd');
                }


                for (i = 0; i < charityListSize; i++) {

                        var addCharityName = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityName");
                        var addCharityId = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityId");
                        var addCharityFundPercentage = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityFundPercentage");
                        percentRaised = percentRaised + Number(addCharityFundPercentage);
                        newCharity = document.createElement('p');
                        newCharity.setAttribute('class', 'label-above-input');
                        newCharity.id = i;
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            newCharityName = document.createElement('<SPAN class="label-fixed-width"/>');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }else if (navigator.appName == "Netscape")  {
                            newCharityName = document.createElement('span');
                            newCharityName.setAttribute('class', 'label-fixed-width');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }
                        newCharity.appendChild(document.createTextNode(" "));
                        charityId = document.createElement('input');
                        charityId.setAttribute('type', 'hidden');
                        charityId.setAttribute('id', 'charityId'+i);
                        charityId.setAttribute('name', 'charityId'+i);
                        charityId.setAttribute('value', addCharityId);
                        newCharity.appendChild(charityId);

                        if (navigator.appName == "Microsoft Internet Explorer") {
                            var classDisabled="";
                            var readOnly=true;
                            var ele1='<input TYPE="text" onChange="onChangeDisplayTotalForCharity('+'value'+','+i+');" id="'+'charityFundPercentage'+i+'" value="'+addCharityFundPercentage+'" size="3" maxlength="3"';
                            if(charitySupportedInd=="R" && fundraiserSplitOverrideInd=="N"){
                                classDisabled="disabledStyle";
                                ele1=ele1+'class="'+classDisabled+'" readonly="'+readOnly+'"/>'
                            }
                            else{

                            ele1=ele1+' />'

                            }
                            charityFundPercent = document.createElement(ele1);
                            newCharity.appendChild(charityFundPercent);

                        } else if (navigator.appName == "Netscape") {
                            charityFundPercent = document.createElement('input');
                            charityFundPercent.setAttribute('type', 'text');
                            charityFundPercent.setAttribute('id', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('name', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('value', addCharityFundPercentage);
                            charityFundPercent.setAttribute('onchange', "javascript:onChangeDisplayTotalForCharity("+"value"+","+i+");");
                            charityFundPercent.setAttribute('size','3');
                            charityFundPercent.setAttribute('maxlength','3');
                            if(charitySupportedInd=="R" && fundraiserSplitOverrideInd == "N"){
                                charityFundPercent.setAttribute('disabled','true');
                            }

                            newCharity.appendChild(charityFundPercent);
                        }
                        newCharity.appendChild(document.createTextNode("%"));
                        newCharity.appendChild(document.createTextNode(" "));
                        if(charitySupportedInd != "R") {
                            removeCharity = document.createElement('a');
                            removeCharity.id = "removeCharity"+i;
                            removeCharity.setAttribute('href', "javascript:deletedSelectedCharity("+i+");");
                            removeCharity.appendChild(document.createTextNode("Remove"));
                            newCharity.appendChild(removeCharity);
                        }
                        newList.appendChild(newCharity);
                }
                fundSplitPercentAdd = document.createElement('p');
                         fundSplitPercentAdd.setAttribute('class', 'label-above-input');
                         fundSplitPercentAdd.id = 'totalSplitOnload';
                         fundSplitPercentAdd.appendChild(document.createTextNode("Total fund split = "));
                         fundSplitPercentAdd.appendChild(document.createTextNode(percentRaised));
                         fundSplitPercentAdd.appendChild(document.createTextNode("%"));
                         newCharity.appendChild(fundSplitPercentAdd);
                         newList.appendChild(fundSplitPercentAdd);

              hideIds('totalSplitOnload');

                $('showExceedFive').hide();
                $('charityAlreadyExist').hide();
            }
    }
 }
 */
 function onChangeDisplayTotalForCharity(textIndex,charityIndex) {
     var charityUpdatedValue = textIndex;
     var selectedCharityIndex = charityIndex;
     var allowChars=/^[0-9]{0,3}$/;
     var error;
    var charitySupportedInd="";
    var fundraiserSplitOverrideInd="";

    if($('charitySupportedInd')){
        charitySupportedInd=$F('charitySupportedInd');
        fundraiserSplitOverrideInd=$F('fundraiserSplitOverrideInd');
    }

     if(charityUpdatedValue.blank() || (charityUpdatedValue=="0" &&  fundraiserSplitOverrideInd.blank() )) {
         error="<font color='red'>Please enter correct split percentage.</font>";
         document.getElementById('showExceedFive').innerHTML = error;
         $('showExceedFive').show();
     } else if (charityUpdatedValue.search(allowChars)) {
         error="<font color='red'>Please enter correct split percentage.</font>";
         document.getElementById('showExceedFive').innerHTML = error;
         $('showExceedFive').show();
     } else {
         $('showError').hide();
         var url = "ajaxOnChangeForCharity.action";
         var params = 'selectedCharityIndex=' + selectedCharityIndex + '&charityUpdatedValue=' + charityUpdatedValue;
         new Ajax.Request(url, {
                method :'POST',
                parameters :params,
                asynchronous :true,
                onSuccess :showUrlResponse
         });
     }

     function showUrlResponse(transport){
            var xml_doc = transport.responseXML.documentElement;
            var errorMessage = xml_doc.getAttribute("errorMessage");
            var totalFundSplit = xml_doc.getAttribute("totalFundSplit");
            var charitySupportedInd="";
            var fundraiserSplitOverrideInd="";

            if($('charitySupportedInd')){
                charitySupportedInd=$F('charitySupportedInd');
                fundraiserSplitOverrideInd=$F('fundraiserSplitOverrideInd');
            }

            theList = $('createCharity');
            newList = document.createElement('span');
            theList.parentNode.replaceChild(newList,theList);
            newList.id = "createCharity";

            newCharityTitle = document.createElement('strong');
            newCharityTitle.appendChild(document.createTextNode("Chosen charities"));
            newList.appendChild(newCharityTitle);

            if (errorMessage == "No" ) {
                for (i = 0; i < xml_doc.childNodes[0].childNodes.length; i++) {

                    var addCharityName = xml_doc.childNodes[0].childNodes[i]
                        .getAttribute("charityName");
                    var addCharityId = xml_doc.childNodes[0].childNodes[i]
                        .getAttribute("charityId");
                    var addCharityFundPercentage = xml_doc.childNodes[0].childNodes[i]
                        .getAttribute("charityFundPercentage");

                    newCharity = document.createElement('p');
                    newCharity.setAttribute('class', 'label-above-input');
                    newCharity.id = i;
                    if (navigator.appName == "Microsoft Internet Explorer") {
                        newCharityName = document.createElement('<SPAN class="label-fixed-width"/>');
                        newCharityName.appendChild(document.createTextNode(addCharityName));
                        newCharity.appendChild(newCharityName);
                    }else if (navigator.appName == "Netscape")  {
                        newCharityName = document.createElement('span');
                        newCharityName.setAttribute('class', 'label-fixed-width');
                        newCharityName.appendChild(document.createTextNode(addCharityName));
                        newCharity.appendChild(newCharityName);
                    }
                    newCharity.appendChild(document.createTextNode(" "));
                    charityId = document.createElement('input');
                    charityId.setAttribute('type', 'hidden');
                    charityId.setAttribute('id', 'charityId'+i);
                    charityId.setAttribute('name', 'charityId'+i);
                    charityId.setAttribute('value', addCharityId);
                    newCharity.appendChild(charityId);
                    if (navigator.appName == "Microsoft Internet Explorer") {
                        var readonly="";
                        if(charitySupportedInd=="R" && fundraiserSplitOverrideInd=="N"){
                            readonly=" readOnly ";
                        }
                        charityFundPercent = document.createElement('<input TYPE="text" onChange="onChangeDisplayTotalForCharity('+'value'+','+i+');" id="'+'charityFundPercentage'+i+'" value="'+addCharityFundPercentage+'" size="3" maxlength="3"'+readonly+' />');
                        newCharity.appendChild(charityFundPercent);

                    } else if (navigator.appName == "Netscape") {
                        charityFundPercent = document.createElement('input');
                        charityFundPercent.setAttribute('type', 'text');
                        charityFundPercent.setAttribute('id', 'charityFundPercentage'+i);
                        charityFundPercent.setAttribute('name', 'charityFundPercentage'+i);
                        charityFundPercent.setAttribute('value', addCharityFundPercentage);
                        charityFundPercent.setAttribute('onchange', "javascript:onChangeDisplayTotalForCharity("+"value"+","+i+");");
                        charityFundPercent.setAttribute('size','3');
                        charityFundPercent.setAttribute('maxlength','3');
                        if(charitySupportedInd=="R" && fundraiserSplitOverrideInd == "N"){
                            charityFundPercent.setAttribute('readOnly','true');
                        }
                        newCharity.appendChild(charityFundPercent);
                    }
                    newCharity.appendChild(document.createTextNode("%"));
                    newCharity.appendChild(document.createTextNode(" "));
                    if(charitySupportedInd != "R") {
                        removeCharity = document.createElement('a');
                        removeCharity.id = "removeCharity"+i;
                        removeCharity.setAttribute('href', "javascript:deletedEventBaseSelectedCharity("+i+");");
                        removeCharity.appendChild(document.createTextNode("Remove"));
                        newCharity.appendChild(removeCharity);
                    }
                    newList.appendChild(newCharity);
                }
                fundSplitPercent = document.createElement('p');
                fundSplitPercent.setAttribute('class', 'label-above-input');
                fundSplitPercent.id = 'totalSplit';
                fundSplitPercent.appendChild(document.createTextNode("Total fund split = "));
                fundSplitPercent.appendChild(document.createTextNode(totalFundSplit));
                fundSplitPercent.appendChild(document.createTextNode("%"));
                newList.appendChild(fundSplitPercent);
                hideIds('totalSplit');
                $('showExceedFive').hide();
                $('charityAlreadyExist').hide();
                $('totalNotHundredErrorMessage').hide();
            } else if (errorMessage == "Yes") {
                var fundSplitAmount = 0;
                for (i = 0; i < xml_doc.childNodes[0].childNodes.length; i++) {

                    var addCharityName = xml_doc.childNodes[0].childNodes[i]
                        .getAttribute("charityName");
                    var addCharityId = xml_doc.childNodes[0].childNodes[i]
                        .getAttribute("charityId");
                    var addCharityFundPercentage = xml_doc.childNodes[0].childNodes[i]
                        .getAttribute("charityFundPercentage");
                    fundSplitAmount+=Number(addCharityFundPercentage);
                    newCharity = document.createElement('p');
                    newCharity.setAttribute('class', 'label-above-input');
                    newCharity.id = i;
                    if (navigator.appName == "Microsoft Internet Explorer") {
                        newCharityName = document.createElement('<SPAN class="label-fixed-width"/>');
                        newCharityName.appendChild(document.createTextNode(addCharityName));
                        newCharity.appendChild(newCharityName);
                    }else if (navigator.appName == "Netscape")  {
                        newCharityName = document.createElement('span');
                        newCharityName.setAttribute('class', 'label-fixed-width');
                        newCharityName.appendChild(document.createTextNode(addCharityName));
                        newCharity.appendChild(newCharityName);
                    }
                    newCharity.appendChild(document.createTextNode(" "));
                    charityId = document.createElement('input');
                    charityId.setAttribute('type', 'hidden');
                    charityId.setAttribute('id', 'charityId'+i);
                    charityId.setAttribute('name', 'charityId'+i);
                    charityId.setAttribute('value', addCharityId);
                    newCharity.appendChild(charityId);
                    if (navigator.appName == "Microsoft Internet Explorer") {
                        var readonly="";
                        if(charitySupportedInd=="R" && fundraiserSplitOverrideInd=="N"){
                            readonly=" readOnly ";
                        }
                        charityFundPercent = document.createElement('<input TYPE="text" onChange="onChangeDisplayTotalForCharity('+'value'+','+i+');" id="'+'charityFundPercentage'+i+'" value="'+addCharityFundPercentage+'" size="3" maxlength="3"'+readonly+' />');
                        newCharity.appendChild(charityFundPercent);

                    } else if (navigator.appName == "Netscape") {
                        charityFundPercent = document.createElement('input');
                        charityFundPercent.setAttribute('type', 'text');
                        charityFundPercent.setAttribute('id', 'charityFundPercentage'+i);
                        charityFundPercent.setAttribute('name', 'charityFundPercentage'+i);
                        charityFundPercent.setAttribute('value', addCharityFundPercentage);
                        charityFundPercent.setAttribute('onchange', "javascript:onChangeDisplayTotalForCharity("+"value"+","+i+");");
                        charityFundPercent.setAttribute('size','3');
                        charityFundPercent.setAttribute('maxlength','3');
                        if(charitySupportedInd=="R" && fundraiserSplitOverrideInd == "N"){
                            charityFundPercent.setAttribute('readOnly','true');
                        }
                        newCharity.appendChild(charityFundPercent);
                    }
                    newCharity.appendChild(document.createTextNode("%"));
                    newCharity.appendChild(document.createTextNode(" "));
                    if(charitySupportedInd != "R") {
                        removeCharity = document.createElement('a');
                        removeCharity.id = "removeCharity"+i;
                        removeCharity.setAttribute('href', "javascript:deletedEventBaseSelectedCharity("+i+");");
                        removeCharity.appendChild(document.createTextNode("Remove"));
                        newCharity.appendChild(removeCharity);
                    }
                    newList.appendChild(newCharity);
                }

                fundSplitPercent = document.createElement('p');
                fundSplitPercent.setAttribute('class', 'label-above-input');
                fundSplitPercent.id = 'totalSplit';
                fundSplitPercent.appendChild(document.createTextNode("Total fund split = "));
                fundSplitPercent.appendChild(document.createTextNode(fundSplitAmount));
                fundSplitPercent.appendChild(document.createTextNode("%"));
                newList.appendChild(fundSplitPercent);
                hideIds('totalSplit');

                var errorDisplay = "<font color='red'>Your fundraising split does not equal 100%. Please update the values.</font>";
                document.getElementById('showExceedFive').innerHTML = errorDisplay;
                $('showExceedFive').show();
                $('charityAlreadyExist').hide();
                $('totalNotHundredErrorMessage').hide();
            }
    }

 }

 function addSelectedCharityForEvent() {
     var selectedCharityName = $F('addCharityName');
     var selectedCharityId = $F('addCharityId');
     var allowChars=/[a-zA-Z0-9]{1}[a-zA-Z0-9 ]{0,40}/;
     var error;


    $('showError').hide();
    var url = "ajaxAddCharityForEvent.action";
    var params = 'selectedCharityName=' + escape(selectedCharityName);
    params = params + '&selectedCharityId=' + selectedCharityId;
           new Ajax.Request(url, {
            method :'POST',
            parameters :params,
            asynchronous :true,
            onSuccess :displayUrlResponse
        });

    $('multiCharityErrorImage').hide();
    $('multiCharityErrorMessage').hide();
    $('showError').hide();
    $('showExceedFive').hide();
    $('charityAlreadyExist').hide();

     function displayUrlResponse(transport){
            var NODE_ERROR_CODE = "errorCode";
            var NODE_ERROR_DESCRIPTION = "errorDescription";
            var VALIDATION_CODE_BLANK_TEXT_PROVIDED =  "BLANK_TEXT_PROVIDED";
            var VALIDATION_CODE_INVALID_CHARACTERS =  "INVALID_CHARACTERS_FOR_CHARITY_NAME";
            var VALIDATION_CODE_CHARITYCOUNT_EXCEEDED =  "CHARITYCOUNT_EXCEEDED";

            var xml_doc = transport.responseXML.documentElement;
            var errorMessage = xml_doc.getAttribute("errorMessage");
            var charityName = xml_doc.getAttribute("selcharityName");
            var errorCode = xml_doc.getAttribute(NODE_ERROR_CODE);
            var errorDescription = xml_doc.getAttribute(NODE_ERROR_DESCRIPTION);
            var charitySupportedInd="";
            if($('charitySupportedInd')){
                    charitySupportedInd=$F('charitySupportedInd');
            }


            if (errorCode == VALIDATION_CODE_BLANK_TEXT_PROVIDED) {
                 error="<font color='red'>"+errorDescription+"</font>";
                 document.getElementById('showError').innerHTML=error;
                 $('showError').show();
                 $('multiCharityErrorImage').show();
            }
            else if (errorCode == VALIDATION_CODE_INVALID_CHARACTERS) {
                 error="<font color='red'>"+errorDescription+"</font>";
                 document.getElementById('showError').innerHTML=error;
                 $('showError').show();
                 $('multiCharityErrorImage').show();
            }
            else if(errorCode == VALIDATION_CODE_CHARITYCOUNT_EXCEEDED)
            {
                error="<font color='red'>"+errorDescription+"</font>";
                 document.getElementById('showError').innerHTML=error;
                 $('showError').show();
                 $('multiCharityErrorImage').show();
            }
            else
            {

            theList = $('createCharity');
            newList = document.createElement('span');
            theList.parentNode.replaceChild(newList,theList);
            newList.id = "createCharity";

            newCharityTitle = document.createElement('strong');
            newCharityTitle.appendChild(document.createTextNode("Chosen charities"));
            newList.appendChild(newCharityTitle);

                if (errorMessage == "No" ) {
                    for (i = 0; i < xml_doc.childNodes[0].childNodes.length; i++) {

                        var addCharityName = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityName");
                        var addCharityId = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityId");
                        var addCharityFundPercentage = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityFundPercentage");

                        newCharity = document.createElement('p');
                        newCharity.setAttribute('class', 'label-above-input');
                        newCharity.id = i;
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            newCharityName = document.createElement('<SPAN class="label-fixed-width"/>');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }else if (navigator.appName == "Netscape")  {
                            newCharityName = document.createElement('span');
                            newCharityName.setAttribute('class', 'label-fixed-width');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }
                        newCharity.appendChild(document.createTextNode(" "));
                        charityId = document.createElement('input');
                        charityId.setAttribute('type', 'hidden');
                        charityId.setAttribute('id', 'charityId'+i);
                        charityId.setAttribute('name', 'charityId'+i);
                        charityId.setAttribute('value', addCharityId);
                        newCharity.appendChild(charityId);
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            charityFundPercent = document.createElement('<input TYPE="text" onChange="onChangeDisplayTotal('+'value'+','+i+');" id="'+'charityFundPercentage'+i+'" value="'+addCharityFundPercentage+'" size="3" maxlength="3" />');
                            newCharity.appendChild(charityFundPercent);

                        } else if (navigator.appName == "Netscape") {
                            charityFundPercent = document.createElement('input');
                            charityFundPercent.setAttribute('type', 'text');
                            charityFundPercent.setAttribute('id', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('name', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('value', addCharityFundPercentage);
                            charityFundPercent.setAttribute('onchange', "javascript:onChangeDisplayTotal("+"value"+","+i+");");
                            charityFundPercent.setAttribute('size','3');
                            charityFundPercent.setAttribute('maxlength','3');
                            newCharity.appendChild(charityFundPercent);
                        }
                        newCharity.appendChild(document.createTextNode("%"));
                        newCharity.appendChild(document.createTextNode(" "));
                        if (charitySupportedInd != "R") {
                            removeCharity = document.createElement('a');
                            removeCharity.id = "removeCharity"+i;
                            removeCharity.setAttribute('href', "javascript:deletedEventBaseSelectedCharity("+i+");");
                            removeCharity.appendChild(document.createTextNode("Remove"));
                            newCharity.appendChild(removeCharity);
                        }

                        newList.appendChild(newCharity);
                    }
                    $('addCharityName').clear();
                    $('addCharityId').clear();
                    $('showExceedFive').hide();
                    $('charityAlreadyExist').hide();
                } else if (errorMessage == "Yes") {
                for (i = 0; i < xml_doc.childNodes[0].childNodes.length; i++) {

                        var addCharityName = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityName");
                        var addCharityId = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityId");
                        var addCharityFundPercentage = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityFundPercentage");

                        newCharity = document.createElement('p');
                        newCharity.setAttribute('class', 'label-above-input');
                        newCharity.id = i;
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            newCharityName = document.createElement('<SPAN class="label-fixed-width"/>');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }else if (navigator.appName == "Netscape")  {
                            newCharityName = document.createElement('span');
                            newCharityName.setAttribute('class', 'label-fixed-width');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }
                        newCharity.appendChild(document.createTextNode(" "));
                        charityId = document.createElement('input');
                        charityId.setAttribute('type', 'hidden');
                        charityId.setAttribute('id', 'charityId'+i);
                        charityId.setAttribute('name', 'charityId'+i);
                        charityId.setAttribute('value', addCharityId);
                        newCharity.appendChild(charityId);
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            charityFundPercent = document.createElement('<input TYPE="text" onChange="onChangeDisplayTotal('+'value'+','+i+');" id="'+'charityFundPercentage'+i+'" value="'+addCharityFundPercentage+'" size="3" maxlength="3" />');
                            newCharity.appendChild(charityFundPercent);

                        } else if (navigator.appName == "Netscape") {
                            charityFundPercent = document.createElement('input');
                            charityFundPercent.setAttribute('type', 'text');
                            charityFundPercent.setAttribute('id', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('name', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('value', addCharityFundPercentage);
                            charityFundPercent.setAttribute('onchange', "javascript:onChangeDisplayTotal("+"value"+","+i+");");
                            charityFundPercent.setAttribute('size','3');
                            charityFundPercent.setAttribute('maxlength','3');
                            newCharity.appendChild(charityFundPercent);
                        }
                        newCharity.appendChild(document.createTextNode("%"));
                        newCharity.appendChild(document.createTextNode(" "));
                        if (charitySupportedInd !="R") {
                            removeCharity = document.createElement('a');
                            removeCharity.id = "removeCharity"+i;
                            removeCharity.setAttribute('href', "javascript:deletedEventBaseSelectedCharity("+i+");");
                            removeCharity.appendChild(document.createTextNode("Remove"));
                            newCharity.appendChild(removeCharity);
                        }
                        newList.appendChild(newCharity);
                    }

                var errorDisplay = "<font color='red'>"+errorDescription+"</font>";
                //var errorDisplay = "<font color='red'>You can only select a maximum of 5 charities.</font>";
                    document.getElementById('showExceedFive').innerHTML = errorDisplay;
                    $('addCharityName').clear();
                    $('addCharityId').clear();
                $('showExceedFive').show();
                $('charityAlreadyExist').hide();
                } else if (errorMessage == "charityAlreadyExist") {
                for (i = 0; i < xml_doc.childNodes[0].childNodes.length; i++) {

                        var addCharityName = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityName");
                        var addCharityId = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityId");
                        var addCharityFundPercentage = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityFundPercentage");

                        newCharity = document.createElement('p');
                        newCharity.setAttribute('class', 'label-above-input');
                        newCharity.id = i;
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            newCharityName = document.createElement('<SPAN class="label-fixed-width"/>');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }else if (navigator.appName == "Netscape")  {
                            newCharityName = document.createElement('span');
                            newCharityName.setAttribute('class', 'label-fixed-width');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }
                        newCharity.appendChild(document.createTextNode(" "));
                        charityId = document.createElement('input');
                        charityId.setAttribute('type', 'hidden');
                        charityId.setAttribute('id', 'charityId'+i);
                        charityId.setAttribute('name', 'charityId'+i);
                        charityId.setAttribute('value', addCharityId);
                        newCharity.appendChild(charityId);
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            charityFundPercent = document.createElement('<input TYPE="text" onChange="onChangeDisplayTotal('+'value'+','+i+');" id="'+'charityFundPercentage'+i+'" value="'+addCharityFundPercentage+'" size="3" maxlength="3" />');
                            newCharity.appendChild(charityFundPercent);

                        } else if (navigator.appName == "Netscape") {
                            charityFundPercent = document.createElement('input');
                            charityFundPercent.setAttribute('type', 'text');
                            charityFundPercent.setAttribute('id', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('name', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('value', addCharityFundPercentage);
                            charityFundPercent.setAttribute('onchange', "javascript:onChangeDisplayTotal("+"value"+","+i+");");
                            charityFundPercent.setAttribute('size','3');
                            charityFundPercent.setAttribute('maxlength','3');
                            newCharity.appendChild(charityFundPercent);
                        }
                        newCharity.appendChild(document.createTextNode("%"));
                        newCharity.appendChild(document.createTextNode(" "));
                        if (charitySupportedInd !="R") {
                            removeCharity = document.createElement('a');
                            removeCharity.id = "removeCharity"+i;
                            removeCharity.setAttribute('href', "javascript:deletedEventBaseSelectedCharity("+i+");");
                            removeCharity.appendChild(document.createTextNode("Remove"));
                            newCharity.appendChild(removeCharity);
                        }
                        newList.appendChild(newCharity);
                    }
                var errorDisplay = "<font color='red'>You have already selected this charity.</font>";
                    document.getElementById('charityAlreadyExist').innerHTML = errorDisplay;
                    $('addCharityName').clear();
                    $('addCharityId').clear();
                $('showExceedFive').hide();
                $('charityAlreadyExist').show();
            }
        }
    }
 }

 function deletedEventBaseSelectedCharity(charityIndex) {
     var selectedCharityIndex = charityIndex;

     var url = "ajaxDeleteEventBaseCharity.action";
     var params = 'selectedCharityIndex=' + selectedCharityIndex;
     new Ajax.Request(url, {
            method :'POST',
            parameters :params,
            asynchronous :true,
            onSuccess :reDisplayUrlResponse
    });


     function reDisplayUrlResponse(transport){
            var xml_doc = transport.responseXML.documentElement;

            theList = $('createCharity');
            charityListSize = xml_doc.childNodes[0].childNodes.length;
            if (charityListSize == 0) {
                newList = document.createElement('span');
                theList.parentNode.replaceChild(newList,theList);
                newList.id = "createCharity";
                $('createCharity').innerHTML = "";
                $('charityAlreadyExist').hide();
                $('showExceedFive').hide();
            } else {
                newList = document.createElement('span');
                theList.parentNode.replaceChild(newList,theList);
                newList.id = "createCharity";

                newCharityTitle = document.createElement('strong');
                newCharityTitle.appendChild(document.createTextNode("Chosen charities"));
                newList.appendChild(newCharityTitle);
                var percentRaised = 0;
                for (i = 0; i < charityListSize; i++) {

                        var addCharityName = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityName");
                        var addCharityId = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityId");
                        var addCharityFundPercentage = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityFundPercentage");
                        percentRaised = percentRaised + Number(addCharityFundPercentage);

                        newCharity = document.createElement('p');
                        newCharity.setAttribute('class', 'label-above-input');
                        newCharity.id = i;
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            newCharityName = document.createElement('<SPAN class="label-fixed-width"/>');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }else if (navigator.appName == "Netscape")  {
                            newCharityName = document.createElement('span');
                            newCharityName.setAttribute('class', 'label-fixed-width');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }
                        newCharity.appendChild(document.createTextNode(" "));
                        charityId = document.createElement('input');
                        charityId.setAttribute('type', 'hidden');
                        charityId.setAttribute('id', 'charityId'+i);
                        charityId.setAttribute('name', 'charityId'+i);
                        charityId.setAttribute('value', addCharityId);
                        newCharity.appendChild(charityId);
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            charityFundPercent = document.createElement('<input TYPE="text" onChange="onChangeDisplayTotal('+'value'+','+i+');" id="'+'charityFundPercentage'+i+'" value="'+addCharityFundPercentage+'" size="3" maxlength="3" />');
                            newCharity.appendChild(charityFundPercent);

                        } else if (navigator.appName == "Netscape") {
                            charityFundPercent = document.createElement('input');
                            charityFundPercent.setAttribute('type', 'text');
                            charityFundPercent.setAttribute('id', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('name', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('value', addCharityFundPercentage);
                            charityFundPercent.setAttribute('onchange', "javascript:onChangeDisplayTotal("+"value"+","+i+");");
                            charityFundPercent.setAttribute('size','3');
                            charityFundPercent.setAttribute('maxlength','3');
                            newCharity.appendChild(charityFundPercent);
                        }
                        newCharity.appendChild(document.createTextNode("%"));
                        newCharity.appendChild(document.createTextNode(" "));
                        removeCharity = document.createElement('a');
                        removeCharity.id = "removeCharity"+i;
                        removeCharity.setAttribute('href', "javascript:deletedEventBaseSelectedCharity("+i+");");
                        removeCharity.appendChild(document.createTextNode("Remove"));
                        newCharity.appendChild(removeCharity);
                        newList.appendChild(newCharity);
                }

                fundSplitPercentAdd = document.createElement('p');
                         fundSplitPercentAdd.setAttribute('class', 'label-above-input');
                         fundSplitPercentAdd.id = 'totalSplitEvent';
                         fundSplitPercentAdd.appendChild(document.createTextNode("Total fund split = "));
                         fundSplitPercentAdd.appendChild(document.createTextNode(percentRaised));
                         fundSplitPercentAdd.appendChild(document.createTextNode("%"));
                         newCharity.appendChild(fundSplitPercentAdd);
                         newList.appendChild(fundSplitPercentAdd);


                hideIds('totalSplitEvent');
                $('showExceedFive').hide();
                $('charityAlreadyExist').hide();
            }

    }
 }

 function onChangeDisplayTotal(textIndex,charityIndex) {
     var charityUpdatedValue = textIndex;
     var selectedCharityIndex = charityIndex;
     var allowChars=/^[0-9]{0,3}$/;
     var error;
     if(charityUpdatedValue.blank()) {
         error="<font color='red'>Please enter correct split percentage.</font>";
         document.getElementById('showExceedFive').innerHTML = error;
         $('showExceedFive').show();
     } else if (charityUpdatedValue.search(allowChars)) {
         error="<font color='red'>Please enter correct split percentage.</font>";
         document.getElementById('showExceedFive').innerHTML = error;
         $('showExceedFive').show();
     } else {
         $('showError').hide();

         var url = "ajaxOnChangeEventCharity.action";
         var params = 'selectedCharityIndex=' + selectedCharityIndex + '&charityUpdatedValue=' + charityUpdatedValue;
         new Ajax.Request(url, {
                method :'POST',
                parameters :params,
                asynchronous :true,
                onSuccess :showUrlResponse
         });
     }

     function showUrlResponse(transport){
            var xml_doc = transport.responseXML.documentElement;
            var errorMessage = xml_doc.getAttribute("errorMessage");
            var totalFundSplit = xml_doc.getAttribute("totalFundSplit");

            theList = $('createCharity');
            newList = document.createElement('span');
            theList.parentNode.replaceChild(newList,theList);
            newList.id = "createCharity";
            newCharityTitle = document.createElement('strong');
            newCharityTitle.appendChild(document.createTextNode("Chosen charities"));
            newList.appendChild(newCharityTitle);

            if (errorMessage == "No" ) {
                for (i = 0; i < xml_doc.childNodes[0].childNodes.length; i++) {

                    var addCharityName = xml_doc.childNodes[0].childNodes[i]
                        .getAttribute("charityName");
                    var addCharityId = xml_doc.childNodes[0].childNodes[i]
                        .getAttribute("charityId");
                    var addCharityFundPercentage = xml_doc.childNodes[0].childNodes[i]
                        .getAttribute("charityFundPercentage");

                    newCharity = document.createElement('p');
                    newCharity.setAttribute('class', 'label-above-input');
                    newCharity.id = i;
                    if (navigator.appName == "Microsoft Internet Explorer") {
                        newCharityName = document.createElement('<SPAN class="label-fixed-width"/>');
                        newCharityName.appendChild(document.createTextNode(addCharityName));
                        newCharity.appendChild(newCharityName);
                    }else if (navigator.appName == "Netscape")  {
                        newCharityName = document.createElement('span');
                        newCharityName.setAttribute('class', 'label-fixed-width');
                        newCharityName.appendChild(document.createTextNode(addCharityName));
                        newCharity.appendChild(newCharityName);
                    }
                    newCharity.appendChild(document.createTextNode(" "));
                    charityId = document.createElement('input');
                    charityId.setAttribute('type', 'hidden');
                    charityId.setAttribute('id', 'charityId'+i);
                    charityId.setAttribute('name', 'charityId'+i);
                    charityId.setAttribute('value', addCharityId);
                    newCharity.appendChild(charityId);
                    if (navigator.appName == "Microsoft Internet Explorer") {
                        charityFundPercent = document.createElement('<input TYPE="text" onChange="onChangeDisplayTotal('+'value'+','+i+');" id="'+'charityFundPercentage'+i+'" value="'+addCharityFundPercentage+'" size="3" maxlength="3" />');
                        newCharity.appendChild(charityFundPercent);

                    } else if (navigator.appName == "Netscape") {
                        charityFundPercent = document.createElement('input');
                        charityFundPercent.setAttribute('type', 'text');
                        charityFundPercent.setAttribute('id', 'charityFundPercentage'+i);
                        charityFundPercent.setAttribute('name', 'charityFundPercentage'+i);
                        charityFundPercent.setAttribute('value', addCharityFundPercentage);
                        charityFundPercent.setAttribute('onchange', "javascript:onChangeDisplayTotal("+"value"+","+i+");");
                        charityFundPercent.setAttribute('size','3');
                        charityFundPercent.setAttribute('maxlength','3');
                        newCharity.appendChild(charityFundPercent);
                    }
                    newCharity.appendChild(document.createTextNode("%"));
                    newCharity.appendChild(document.createTextNode(" "));
                    removeCharity = document.createElement('a');
                    removeCharity.id = "removeCharity"+i;
                    removeCharity.setAttribute('href', "javascript:deletedEventBaseSelectedCharity("+i+");");
                    removeCharity.appendChild(document.createTextNode("Remove"));
                    newCharity.appendChild(removeCharity);
                    newList.appendChild(newCharity);
                }
                fundSplitPercent = document.createElement('p');
                fundSplitPercent.setAttribute('class', 'label-above-input');
                fundSplitPercent.id = 'totalSplit';
                fundSplitPercent.appendChild(document.createTextNode("Total fund split = "));
                fundSplitPercent.appendChild(document.createTextNode(totalFundSplit));
                fundSplitPercent.appendChild(document.createTextNode("%"));
                newList.appendChild(fundSplitPercent);

                totalSplitEvent('totalSplit');
                $('showExceedFive').hide();
                $('charityAlreadyExist').hide();
                $('totalNotHundredErrorMessage').hide();
            } else if (errorMessage == "Yes") {
                for (i = 0; i < xml_doc.childNodes[0].childNodes.length; i++) {

                    var addCharityName = xml_doc.childNodes[0].childNodes[i]
                        .getAttribute("charityName");
                    var addCharityId = xml_doc.childNodes[0].childNodes[i]
                        .getAttribute("charityId");
                    var addCharityFundPercentage = xml_doc.childNodes[0].childNodes[i]
                        .getAttribute("charityFundPercentage");

                    newCharity = document.createElement('p');
                    newCharity.setAttribute('class', 'label-above-input');
                    newCharity.id = i;
                    if (navigator.appName == "Microsoft Internet Explorer") {
                        newCharityName = document.createElement('<SPAN class="label-fixed-width"/>');
                        newCharityName.appendChild(document.createTextNode(addCharityName));
                        newCharity.appendChild(newCharityName);
                    }else if (navigator.appName == "Netscape")  {
                        newCharityName = document.createElement('span');
                        newCharityName.setAttribute('class', 'label-fixed-width');
                        newCharityName.appendChild(document.createTextNode(addCharityName));
                        newCharity.appendChild(newCharityName);
                    }
                    newCharity.appendChild(document.createTextNode(" "));
                    charityId = document.createElement('input');
                    charityId.setAttribute('type', 'hidden');
                    charityId.setAttribute('id', 'charityId'+i);
                    charityId.setAttribute('name', 'charityId'+i);
                    charityId.setAttribute('value', addCharityId);
                    newCharity.appendChild(charityId);
                    if (navigator.appName == "Microsoft Internet Explorer") {
                        charityFundPercent = document.createElement('<input TYPE="text" onChange="onChangeDisplayTotal('+'value'+','+i+');" id="'+'charityFundPercentage'+i+'" value="'+addCharityFundPercentage+'" size="3" maxlength="3" />');
                        newCharity.appendChild(charityFundPercent);

                    } else if (navigator.appName == "Netscape") {
                        charityFundPercent = document.createElement('input');
                        charityFundPercent.setAttribute('type', 'text');
                        charityFundPercent.setAttribute('id', 'charityFundPercentage'+i);
                        charityFundPercent.setAttribute('name', 'charityFundPercentage'+i);
                        charityFundPercent.setAttribute('value', addCharityFundPercentage);
                        charityFundPercent.setAttribute('onchange', "javascript:onChangeDisplayTotal("+"value"+","+i+");");
                        charityFundPercent.setAttribute('size','3');
                        charityFundPercent.setAttribute('maxlength','3');
                        newCharity.appendChild(charityFundPercent);
                    }
                    newCharity.appendChild(document.createTextNode("%"));
                    newCharity.appendChild(document.createTextNode(" "));
                    removeCharity = document.createElement('a');
                    removeCharity.id = "removeCharity"+i;
                    removeCharity.setAttribute('href', "javascript:deletedEventBaseSelectedCharity("+i+");");
                    removeCharity.appendChild(document.createTextNode("Remove"));
                    newCharity.appendChild(removeCharity);
                    newList.appendChild(newCharity);
                }
                var errorDisplay = "<font color='red'>Your fundraising split does not equal 100%. Please update the values.</font>";
                document.getElementById('showExceedFive').innerHTML = errorDisplay;
                $('showExceedFive').show();
                $('charityAlreadyExist').hide();
                $('totalNotHundredErrorMessage').hide();
            }
    }

 }

 function onChangeMultipleCharityIndicator() {

     var url = "ajaxOnChangeMultipleCharityIndicator.action";
     new Ajax.Request(url, {
            method :'POST',
            asynchronous :true,
            onSuccess :displayUrlResponse
    });


     function displayUrlResponse(transport){
            var xml_doc = transport.responseXML.documentElement;
            if($('M') != null && $('M').checked == true) {
                theList = $('createCharity');

                charityListSize = xml_doc.childNodes[0].childNodes.length;
                if (charityListSize == 0) {
                    newList = document.createElement('span');
                    theList.parentNode.replaceChild(newList,theList);
                    newList.id = "createCharity";
                    $('createCharity').innerHTML = "";
                } else {
                newList = document.createElement('span');
                theList.parentNode.replaceChild(newList,theList);
                newList.id = "createCharity";
                newCharityTitle = document.createElement('strong');
                newCharityTitle.appendChild(document.createTextNode("Chosen charities"));
                newList.appendChild(newCharityTitle);

                var charitySupportedInd="";
                var fundraiserSplitOverrideInd="";

                if($('charitySupportedInd')){
                    charitySupportedInd=$F('charitySupportedInd');
                    fundraiserSplitOverrideInd=$F('fundraiserSplitOverrideInd');
                }

                for (i = 0; i < charityListSize; i++) {

                        var addCharityName = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityName");
                        var addCharityId = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityId");
                        var addCharityFundPercentage = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("charityFundPercentage");
                        newCharity = document.createElement('p');
                        newCharity.setAttribute('class', 'label-above-input');
                        newCharity.id = i;
                        if (navigator.appName == "Microsoft Internet Explorer") {
                            newCharityName = document.createElement('<SPAN class="label-fixed-width"/>');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }else if (navigator.appName == "Netscape")  {
                            newCharityName = document.createElement('span');
                            newCharityName.setAttribute('class', 'label-fixed-width');
                            newCharityName.appendChild(document.createTextNode(addCharityName));
                            newCharity.appendChild(newCharityName);
                        }
                        newCharity.appendChild(document.createTextNode(" "));
                        charityId = document.createElement('input');
                        charityId.setAttribute('type', 'hidden');
                        charityId.setAttribute('id', 'charityId'+i);
                        charityId.setAttribute('name', 'charityId'+i);
                        charityId.setAttribute('value', addCharityId);
                        newCharity.appendChild(charityId);

                        if (navigator.appName == "Microsoft Internet Explorer") {
                            var readonly="";
                            if(charitySupportedInd=="R" && fundraiserSplitOverrideInd=="N"){
                                readonly=" readOnly ";
                            }
                            charityFundPercent = document.createElement('<input TYPE="text" onChange="onChangeDisplayTotalForCharity('+'value'+','+i+');" id="'+'charityFundPercentage'+i+'" value="'+addCharityFundPercentage+'" size="3" maxlength="3"'+ readonly +' />');
                            newCharity.appendChild(charityFundPercent);

                        } else if (navigator.appName == "Netscape") {
                            charityFundPercent = document.createElement('input');
                            charityFundPercent.setAttribute('type', 'text');
                            charityFundPercent.setAttribute('id', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('name', 'charityFundPercentage'+i);
                            charityFundPercent.setAttribute('value', addCharityFundPercentage);
                            charityFundPercent.setAttribute('onchange', "javascript:onChangeDisplayTotalForCharity("+"value"+","+i+");");
                            charityFundPercent.setAttribute('size','3');
                            charityFundPercent.setAttribute('maxlength','3');
                            if(charitySupportedInd=="R" && fundraiserSplitOverrideInd == "N"){
                                charityFundPercent.setAttribute('readOnly','true');
                            }
                            newCharity.appendChild(charityFundPercent);
                        }

                        newCharity.appendChild(document.createTextNode("%"));
                        newCharity.appendChild(document.createTextNode(" "));
                        if(charitySupportedInd != "R") {
                            removeCharity = document.createElement('a');
                            removeCharity.id = "removeCharity"+i;
                            removeCharity.setAttribute('href', "javascript:deletedSelectedCharity("+i+");");
                            removeCharity.appendChild(document.createTextNode("Remove"));
                            newCharity.appendChild(removeCharity);
                        }

                        newList.appendChild(newCharity);
                }


                }
                $('charityId').value = "";
                $('charityName').value = "";
                $('eventPlace').value = "";
                $('O').checked = false;
                $('U').checked = false;
                $('showExceedFive').hide();
            } else if ($('S') != null && $('S').checked == true) {

                if($('selectedCharityName').value.length>0){
                    $('charityName').value = $('selectedCharityName').value;
                    $('charityName').readOnly=true;
                }

                $('addCharityId').value = "";
                $('addCharityName').value = "";
                $('eventPlace').value = "";
                $('O').checked = false;
                $('U').checked = false;

                $('multiCharityErrorImage').hide();
                $('multiCharityErrorMessage').hide();
                $('showError').hide();
                $('showExceedFive').hide();
                $('charityAlreadyExist').hide();
            }
    }
 }

    function manualDonorAddressEntry(){
        $$('[name="buildingNameBoxDisplay"]')[0].setValue("true");
        manualAddressEntry();
    }
/* Confirm chosen charity */
 /*Make Dynamic the country selection, it will hide the postcode ,
    building name or number and addressLookup fields*/
    function manualAddressEntry () {
        if ($("countryOfResidence") != null) {
        var countryName = $F('countryOfResidence');
        }

        if ($("displayAddress") != null) {
            if ($('displayAddressLine1') != null) {
                $('displayAddressLine1').innerHTML = "";
            }

            if ($('displayAddressLine2') != null) {
                 $('displayAddressLine2').innerHTML = "";
            }

            if ($('displayCity') != null) {
                 $('displayCity').innerHTML = "";
            }

             if ($('displayCounty') != null) {
                 $('displayCounty').innerHTML = "";
             }

            if ($('displayPostCode') != null) {
                 $('displayPostCode').innerHTML = "";
            }
            $('displayAddress').hide();


        }

        if( $('displayAddressData')!=null && $("displayAddressData") != ''){
                    $('displayAddressData').hide();

        }

        if( $('postcodeChange')!=null && $("postcodeChange") != ''){
                    $('postcodeChange').show();
        }

        if( $('addressLookupDiv')!=null && $("addressLookupDiv") != ''){
                    $('addressLookupDiv').show();
        }

        //Check Visiblity

        if ($("displayAddress")!=null) {
           var visibility= $('displayAddress').visible();
        }

       addressListShow();
       clearPostcodeDetails();
        showDetailsOfPostcode();
        hideDisplayAddressData();

    }

/*Clear Address parameter List*/
    function clearParameter() {

        if ($('insertAddressLine1') != null) {
            var addressLine1 =$F('insertAddressLine1');
        }
        if ($('insertAddressLine2') != null) {
            var addressLine2 = $F('insertAddressLine2');
        }
        if ($('insertTownOrCity') != null) {
            var city = $F('insertTownOrCity');
        }
        if ($('insertCounty') != null) {
            var country = $F('insertCounty');
        }
        if ($('insertPostCode') != null) {
            var postcode = $F('insertPostCode');
        }


        if( addressLine1 != "" && addressLine1 != null) {
            $('insertAddressLine1').value = "";
        }
        if( addressLine2 != "" && addressLine2 != null) {
            $('insertAddressLine2').value = "";
        }
        if( city != "" && city != null) {
            $('insertTownOrCity').value = "";
        }
        if( country != "" && country != null) {
            $('insertCounty').value = "";
        }
        if( country != "" && country != null) {
            $('insertPostCode').value = "";
        }

    }

    /**Clear post code and  Building number*/
    function clearPostcodeDetails()
    {
        if ($('regPostCode') != null) {
            var buildingNumber =$F('regPostCode');
        }
        if ($('regBuildingNmNo') != null) {
            var pagePostcode =$F('regBuildingNmNo');
        }
        if( buildingNumber != "" && buildingNumber != null) {
            $('regBuildingNmNo').value = "";
        }
        if( pagePostcode != "" && pagePostcode != null) {
            $('regPostCode').value = "";
        }
        clearParameter();

    }

    /**Show and Hide Address Arrow*/
    function  addressListShow()
    {
        if ($('countryOfResidence') != null) {
            var countryName = $F('countryOfResidence');
        }
    if(countryName=='GB'){
      if ($('findAddress') != null) {
                 $('findAddress').show();
      }

      if ($('detailedAddress') != null) {
                 $('detailedAddress').hide();
      }
    }
    else {
             if ($('findAddress') != null) {
                 $('findAddress').hide();
         }

        if ($('detailedAddress') != null) {
                 $('detailedAddress').show();
         }
        if ($("addressChanged") != null){
            $("addressChanged").value=true;
              if($("detailAddressWithoutSession")!=null){
                  if($('postcodeerror') != null) {
                        $('postcodeerror').hide();
                    }
                    if($('buildingnumbererror') != null) {
                        $('buildingnumbererror').hide();
                    }
                    if($('postcodeerrorimg') != null) {
                        $('postcodeerrorimg').hide();
                    }
                    if($('buildingnumbererrorimg') != null) {
                        $('buildingnumbererrorimg').hide();
                    }
                $("detailAddressWithoutSession").show();
              }
              if ($('displayAddressLine1') != null) {
                $('displayAddressLine1').innerHTML = "";
            }

            if ($('displayAddressLine2') != null) {
                 $('displayAddressLine2').innerHTML = "";
            }

            if ($('displayCity') != null) {
                 $('displayCity').innerHTML = "";
            }

             if ($('displayCounty') != null) {
                 $('displayCounty').innerHTML = "";
             }

            if ($('displayPostCode') != null) {
                 $('displayPostCode').innerHTML = "";
            }
              if ($("regPostCode") != null) {
                  $("regPostCode").value="";
              }
              if($('postcodeerror') != null) {
                    $('postcodeerror').hide();
                }
                if($('buildingnumbererror') != null) {
                    $('buildingnumbererror').hide();
                }
                if($('postcodeerrorimg') != null) {
                    $('postcodeerrorimg').hide();
                }
                if($('buildingnumbererrorimg') != null) {
                    $('buildingnumbererrorimg').hide();
                }
          }
    }
 }

    function  showDetailsOfPostcode()
    {
         if ($("displayIdForbuildingNameNumber") != null) {
                 $('displayIdForbuildingNameNumber').show();
      }
      if ($("regBuildingNmNo") != null) {
                 $('regBuildingNmNo').show();
      }
      if ($("regBuildingNmNo") != null) {
                 $('regBuildingNmNo').show();
      }

      if ($("displayIdPostCode") != null) {
                 $('displayIdPostCode').show();
      }
      if ($("regPostCode") != null) {
                 $('regPostCode').show();
      }
    }

/**Hide Display Address Data*/
    function hideDisplayAddressData()
    {
        if( $('displayAddressData')!=null && $("displayAddressData") != ''){
                    $('displayAddressData').hide();
                }
        if ($("displayAddressSession") != null) {
            $("displayAddressSession").hide();
        }
        if ($("displayAddressManual") != null){
            $("displayAddressManual").hide();
        }

    }

/** UCDON0100 related java script start */
    function selectMonthOfDay() {
        if($('paymentMode')!=null){
            if($F('paymentMode') == 'M') {
                $('paymentDayOfMonth').show();
                $('payPalPaymentOption').hide();
            } else {
                $('paymentDayOfMonth').hide();
                $('payPalPaymentOption').show();
            }
        }
    }

    function onSelectAmount() {
        if ($('otherAmount') != null) {
            $('otherAmount').writeAttribute("readonly", "readonly");

            if($('100').checked == true)
            {
                $('otherAmount').value = "100.00";
                $('otherAmount').addClassName('disabledStyle');
                $('otherAmount').writeAttribute("readonly", "readonly");
            } else if ($('50').checked == true) {
                $('otherAmount').value = "50.00";
                $('otherAmount').addClassName('disabledStyle');
                $('otherAmount').writeAttribute("readonly", "readonly");
            } else if ($('20').checked == true) {
                $('otherAmount').value = "20.00";
                $('otherAmount').addClassName('disabledStyle');
                $('otherAmount').writeAttribute("readonly", "readonly");
            } else if ($('10').checked == true) {
                $('otherAmount').value = "10.00";
                $('otherAmount').addClassName('disabledStyle');
                $('otherAmount').writeAttribute("readonly", "readonly");
            } else if ($('other').checked == true) {
                if ($('otherAmount').value == "100.00" || $('otherAmount').value == "50.00" ||
                $('otherAmount').value == "20.00" || $('otherAmount').value == "10.00")
                {
                    $('otherAmount').value = "";
                }
                $('otherAmount').removeClassName('disabledStyle');
                $('otherAmount').removeAttribute("readOnly");
            }
        }
    }
    /**This function used for to select the team members and indivisuals */
    function onSelectTeam() {
        if ($('sponsorTeam') != null) {
            if($('sponsorTeam').checked == true) {
                $('indvidualMember').writeAttribute("readonly", "readonly");
            }
        }
        if ($('indvidualMember') != null){
            if($('indvidualMember').checked == true) {
                $('sponsorTeam').writeAttribute("readonly", "readonly");
            }
        }
    }
/** UCDON0100 related java script end */

/** UCDON0010 related java script start */
    function disabledNext() {

        if($('nextId')!=null || $('nextDisabledId')!=null ){

            if($('passwordChar01').value == '' || $('passwordChar02').value == '' ){
                $('nextId').hide();
                $('nextDisabledId').show();
            }else {
                $('nextId').show();
                $('nextDisabledId').hide();
            }
        }
    }
/** UCDON0010 related java script end */

/** script for tooltip starts here */

// global variable for error popups

 var IE = document.all ? true : false;
 var currentOpenErrorPop = "";
 var errorPopDelay = 100;
 var popupOver = false;
 var popupOpen = false;
 var popupEvent;
 var popupEventY;
 var popupEventX
 var popupName;
 var popupTimeout;

 function open_error_popup(e, name) {
     popupOver = true;
     popupEventY = e.clientY - 10;
     popupEventX = e.clientX - 250;
     popupName = name;
     popupTimeout = setTimeout("fire_error_popup_from_mem()", errorPopDelay);
 }

 function fire_error_popup_from_mem() {
     fire_error_popup(popupEvent, popupName);
 }

 function fire_error_popup(e, name) {
     if (popupOver) {
         popupOpen = true;
         var xPos = popupEventX;
         var yPos = popupEventY;
                         closeOpenErrorPopup();
         if ($(name)) {
             $(name).className = 'error_popup_open';
             if (IE) {
                 var leftScroll = document.documentElement.scrollLeft;
                 var topScroll = document.documentElement.scrollTop;
                 $(name).style.left = xPos;
                 $(name).style.top = yPos + topScroll;
             }
             else {
                 var leftScroll = pageXOffset;
                 var topScroll = pageYOffset;
                 $(name).style.left = xPos + "px";
                 $(name).style.top = (yPos + topScroll) + "px";
             }
             currentOpenErrorPop = name;
         }
     }
     return false;
 }

 //closes error popups
 function close_error_popup(category) {
     if (popupOpen) {
         if ($(category)) {
             $(category).className = 'error_popup_closed';
         }
         currentOpenErrorPop = "";
         popupOpen = false;
         popupOver = false;
         popupEvent = null;
         popupName = null;
     }
     else {
         clearTimeout(popupTimeout);
         popupOver = false;
         popupEvent = null;
         popupName = null;
     }
     return false;
 }

///////////////////////////////////////





 function open_error_popup_charity(e, name) {
     popupOver = true;
     popupEventY = e.clientY - 10;
     popupEventX = e.clientX ;
     popupName = name;
     popupTimeout = setTimeout("fire_error_popup_from_mem_charity()", errorPopDelay);
 }

 function fire_error_popup_from_mem_charity() {
     fire_error_popup_charity(popupEvent, popupName);
 }

 function fire_error_popup_charity(e, name) {
     if (popupOver) {
         popupOpen = true;
         var xPos = popupEventX;
         var yPos = popupEventY;
                         closeOpenErrorPopup();
         if ($(name)) {
             $(name).className = 'error_popup_open_charity';
             if (IE) {
                 var leftScroll = document.documentElement.scrollLeft;
                 var topScroll = document.documentElement.scrollTop;
                 $(name).style.left = xPos;
                 $(name).style.top = yPos + topScroll;
             }
             else {
                 var leftScroll = pageXOffset;
                 var topScroll = pageYOffset;
                 $(name).style.left = xPos + "px";
                 $(name).style.top = (yPos + topScroll) + "px";
             }
             currentOpenErrorPop = name;
         }
     }
     return false;
 }

 //closes error popups
 function close_error_popup_charity(category) {
     if (popupOpen) {
         if ($(category)) {
             $(category).className = 'error_popup_closed_charity';
         }
         currentOpenErrorPop = "";
         popupOpen = false;
         popupOver = false;
         popupEvent = null;
         popupName = null;
     }
     else {
         clearTimeout(popupTimeout);
         popupOver = false;
         popupEvent = null;
         popupName = null;
     }
     return false;
 }

















// expands menu items on fundraiser portal
function setMenuItemExpanded(menuItemId) {

    // anything currentexpanded becomes just current
    $$('li.currentexpanded').each( function(elmt) {
        elmt.addClassName('current');
    });

    // anything expanded ceases to be so
    $$('li.expanded').each( function(elmt) {
        elmt.removeClassName('expanded');
    });

    // finally set the supplied element as expanded
    $(menuItemId).addClassName('expanded');

    return;
}

function flipflopWidget(element){
    var checkboxValue = document.getElementById('photoGalleryCheckbox').checked;
    var imageGalleryCalledAlready = false;
    if($(element).visible()){
        $(element).hide();
    } else{
        $(element).show();
      var charityId = $('ajaxImageContent').value;
      imageGalleryAjax('a', charityId, true);
       imageGalleryCalledAlready = true;
    }
    if(checkboxValue && imageGalleryCalledAlready == false) {
      var charityId = $('ajaxImageContent').value;
       imageGalleryAjax('a', charityId, true)
    }
}

function pageOnload() {
    var checkboxValue = document.getElementById('photoGalleryCheckbox').checked;

     if(checkboxValue) {
      var charityId = $('ajaxImageContent').value;
       imageGalleryAjax('a', charityId, true)
    }
}

function callImageGallery(editFlag)
{
    ajaxGetter('/image-gallery-web/AlbumThumbnailsDisplay.action?albumOwnerType=a&albumOwnerId=12345&showEditButtons='+editFlag, 'galleryDiv');
}

    /*
    * This is generic function to handle image gallery functionality.
    */
   function imageGalleryAjax(albumOwnerType, albumOwnerId, showEditButtons) {
        var url = "/image-gallery-web/AlbumThumbnailsDisplay.action?";
        var params = 'albumOwnerType=' + albumOwnerType + '&albumOwnerId='
                + albumOwnerId + '&showEditButtons=' + showEditButtons ;
        var ajaxCallString = url + params;
        ajaxGetter(ajaxCallString, 'galleryDiv');
   }



 function closeOpenErrorPopup() {
     if (currentOpenErrorPop != "") {
         if ($(currentOpenErrorPop)) {
             $(currentOpenErrorPop).className = 'error_popup_closed';
         }
     }
 }
 /** Tooltip script Ends here */
 /** Team  and Team : team URL check */

 function checkTeamAddressUrl(){
       var webTeamAddress = $F('webTeamAddress');
       var allowChars=/^[0-9A-Za-z$\-_\.+!*'(),]{0,50}$/;
       var errorMsg;
       document.getElementById('showError').innerHTML="";
       if(webTeamAddress == "") {
            errorMsg="Please enter a profile name as you want it to appear in your web address.";
            document.getElementById('showError').innerHTML=errorMsg;
             $('error').hide();
             $('radioOptions').hide();
             $('alternativeAddressTitle').hide();
             if($('errorEmptyUrlName')!= null && $('errorEmptyUrlName')!="") {
              $('errorEmptyUrlName').hide();
             }
             if($('checkAddressAlternativeServer')!= null && $('checkAddressAlternativeServer')!="") {
              $('checkAddressAlternativeServer').hide();
             }
       } else if(!(allowChars.test(webTeamAddress)) ) {
             errorMsg="Invalid characters included within your Profile name. Please try again.";
              $('showError').innerHTML = errorMsg;
              if($('errorEmptyUrlName')!= null && $('errorEmptyUrlName')!="") {
              $('errorEmptyUrlName').hide();
               }
              if($('errorImageForTeam')!= null && $('errorImageForTeam')!="") {
               $('errorImageForTeam').hide();
               }

              $('showError').show();
              $('error').hide();
              $('radioOptions').hide();
              $('alternativeAddressTitle').hide();

              if($('checkAddressAlternativeServer')!= null && $('checkAddressAlternativeServer')!="") {
              $('checkAddressAlternativeServer').hide();
             }

       } else {
           var urlName = escape(webTeamAddress);
           var url = "ajaxCheckTeamAddress.action";
           var params = 'webTeamAddress=' + webTeamAddress;
               new Ajax.Request(url, {
                method :'POST',
                parameters :params,
                asynchronous :true,
                onSuccess :showUrlResponse
            });
       }

       function showUrlResponse(transport){
            var xml_doc = transport.responseXML.documentElement;
            var errorMsg = xml_doc.getAttribute("filedErrorMessage");
            if($('checkAddressAlternativeServer')!= null && $('checkAddressAlternativeServer')!="") {
              $('checkAddressAlternativeServer').hide();
            }
            if (errorMsg != null && errorMsg != '') {
                $('showError').show();
                if($('error')!= null && $('error')!="") {
                     $('error').hide();
                }
                $('showError').innerHTML = errorMsg;
                if($('crossImage')!= null && $('crossImage')!="") {
                    $('crossImage').show();
                }
                if($('errorEmptyUrlName')!= null && $('errorEmptyUrlName')!="") {
                    $('errorEmptyUrlName').hide();
                    $('errorImageForTeam').hide();
                }
            } else {
                var record = xml_doc.getAttribute("record");
                var teamName = xml_doc.getAttribute("teamName");

                if(record=="NOREC"){
                     if($('radioOptions')!= null && $('radioOptions')!="") {
                     $('radioOptions').hide();
                     }
                     if($('error')!= null && $('error')!="") {
                     $('error').hide();
                     }
                     if($('errorMsg')!= null && $('errorMsg')!="") {
                        $('errorMsg').hide();
                      }
                     if($('alternativeAddressTitle')!= null && $('alternativeAddressTitle')!="") {
                     $('alternativeAddressTitle').hide();
                     }
                     if($('webTeamAddress')!= null && $('webTeamAddress')!="") {
                     $('webTeamAddress').value=teamName;
                     }
                     if($('tickImage')!= null && $('tickImage')!="") {
                     $('tickImage').show();
                     }
                }
                if(record=="REC"){
                     var outerPara = document.createElement('p');
                     var htmlText = "";
                     if($('radioOptions')!= null && $('radioOptions')!="") {
                     $('radioOptions').innerHTML="";
                     }
                    for (i = 0; i < xml_doc.childNodes[0].childNodes.length; i++) {
                        var populateSelectedUrl = xml_doc.childNodes[0].childNodes[i]
                            .getAttribute("selectedUrl");
                        var inputRadioComponent = "<input type=\"radio\" value=\""+populateSelectedUrl+"\" id=\"selectedUrl_"+i+"\" name=\"fundraisingTeam.selectedURLSuggestionList\"/>";
                        var labelRadioComponent = "<label id=\"label_"+i+"\" for=\"selectedUrl_"+i+"\">http://www.virginmoneygiving.com/team/"+populateSelectedUrl+"</label>";
                        htmlText += inputRadioComponent;
                        htmlText += labelRadioComponent;
                    }

                    if($('err1')!= null && $('err1')!="") {
                        $('err1').innerHTML="We're sorry but this address is already in use. We've put an alternative in the box � if you'd like to use this just click �next'. You can also ";
                    }
                    if($('err2')!= null && $('err2')!="") {
                        $('err2').innerHTML="make up a new address, or chose one from our list of suggestions below, but you'll need to click �check address' again.";
                    }
                    if($('error')!= null && $('error')!="") {
                        $('error').show();
                    }
                    if($('errorMsg')!= null && $('errorMsg')!="") {
                        $('errorMsg').show();
                        }

                    if($('alternativeAddressTitle')!= null && $('alternativeAddressTitle')!="") {
                        $('alternativeAddressTitle').show();
                    }

                    outerPara.innerHTML = htmlText;

                     if($('radioOptions')!= null && $('radioOptions')!="") {
                         $('radioOptions').show();
                         $('radioOptions').appendChild(outerPara);
                     }
                     if($('checkAddressAlternative')!= null && $('checkAddressAlternative')!="") {
                        $('checkAddressAlternative').show();
                        }

                     $('profilePageAddress').value=teamName;

                    if($('tickImage')!= null && $('tickImage')!="") {
                        $('tickImage').show();
                    }

                }
            }
     }
}

function addToMyTeam(elemt, flag){
        var tr = elemt.up().up();
        var noOfTrs= tr.siblings('tr');

    if(noOfTrs.size() <1){
         $('recordFound').innerHTML="";
    }
        var td = tr.down('td').siblings('td');
        var IdToAdd = elemt.readAttribute("name");
    td[0].innerHTML='<input type="hidden" name="memberIdsToAdd" value="'+IdToAdd+'"/><a  id="networkMemberRemoveLink" href="#" name="'+IdToAdd+'">Remove<img height="30" width="30" src="'+imageRemove+'" title="Remove" alt="Remove" class="next"/></a>';
    td[0].down('a').observe('click',function(){
        removeFromMyTeam(this,'N');
    });
    $('yourTeamTable').down().insert(tr);

    if($('yourTeamTable').down().down('tr').siblings().size() != 0){
        $('networkMemberRemoveLink').show();
    } else {
        $('networkMemberRemoveLink').hide();
    }
}

function removeFromMyTeam(elemt, flag){
    var tr = elemt.up().up();
    var td = tr.down('td').siblings('td');
    var IdToRemove = elemt.readAttribute("name");
    td[0].innerHTML='<input type="hidden" name="memberIdsToRemove" value="'+IdToRemove+'"/><a href="#" name="'+IdToRemove+'"><img src="'+addNetwork+'" alt="Add to team" title="Add to team"/></a>';
    td[0].down('a').observe('click',function(){
        addToMyTeam(this,'N');
    });
    $('searchResultTable').down().insert(tr);

    if($('yourTeamTable').down().down('tr').siblings().size() != 0){
        $('networkMemberRemoveLink').show();
    } else {
        $('networkMemberRemoveLink').hide();
    }
}
//fundraiserAddPeopleNetwork.jsp End

//fundraisingCreateTeamMember.jsp Start
function addToMyTeamMembers(elemt, flag){

    var tr = elemt.up().up();
    var noOfTrs= tr.siblings('tr');
    if(noOfTrs.size() <1){
         $('recordFound').innerHTML="";
    }
    var td = tr.down('td').siblings('td');
    var IdToAdd = elemt.readAttribute("name");
    td[0].innerHTML='<input type="hidden" name="memberIdsToAdd" value="'+IdToAdd+'"/><a id="teamMemberRemoveLink" href="#" name="'+IdToAdd+'">Remove<img height="30" width="30" src="'+imageRemove+'" title="Remove" alt="Remove" class="next"/></a>';
    td[0].down('a').observe('click',function(){
        removeFromMyTeamMembers(this,'N');
    });
    $('yourTeamTable').down().insert(tr);

    if($('yourTeamTable').down().down('tr').siblings().size() != 0){
        $('teamMemberRemoveLink').show();
    } else {
        $('teamMemberRemoveLink').hide();
    }
}

function removeFromMyTeamMembers(elemt, flag){
        var tr = elemt.up().up();
    var td = tr.down('td').siblings('td');
    var IdToRemove = elemt.readAttribute("name");
    td[0].innerHTML='<input type="hidden" name="memberIdsToRemove" value="'+IdToRemove+'"/><a href="#" name="'+IdToRemove+'"><img src="'+addtoTeam+'" alt="Add to team" title="Add to team"/></a>';
    td[0].down('a').observe('click',function(){
        addToMyTeamMembers(this,'N');
    });
    $('searchResultTable').down().insert(tr);

    if($('yourTeamTable').down().down('tr').siblings().size() != 0){
        $('teamMemberRemoveLink').show();
    } else {
        $('teamMemberRemoveLink').hide();
    }
}
//fundraisingCreateTeamMember.jsp End

//fundraisingCreateTeamMember.jsp Start
function addToInvitedMembers(elemt){
    $('noRecordFound').innerHTML="";
    $('invitedTeamMembers').show();
    var tr = elemt.up().up();
    var td = tr.down('td').siblings('td');
    td[0].addClassName('addpeopletbletd addpeoplebtmbor');
    td[0].setStyle('padding-bottom:10px;');
    var emailAddress = elemt.up().siblings('td')[0].innerHTML;
    td[0].innerHTML='<a href="#">Remove<img height="30" width="30" src="'+imageRemove+'" title="Remove" alt="Remove" class="next"/></a>';
    td[0].down('a').observe('click',function(){
        removeFromInvitedMembers(this);
    });
    $('invitedMemberTable').down().insert(tr);
}

function removeFromInvitedMembersForAmend(elemt){
   $('removeInvited').show();
    var tr = elemt.up().up();
    var td = tr.down('td').siblings('td');
    var IdToRemove = elemt.readAttribute("name");
    td[0].innerHTML='<input type="hidden" name="emailAddressToBeRemoved" value="'+IdToRemove+'"/>';
    $('removeInvited').down().insert(tr);
    $('removeInvited').hide();

}

function removeFromInvitedMembers(elemt){

    var tr = elemt.up().up();
    tr.remove();

}
function setRemoveFlag(elemt){
    var IdToRemove = elemt.readAttribute("id");
    var removeFlag = elemt.up().siblings('td')[1].down();
    removeFlag.value = IdToRemove;
}

function setSelectedNetwork(elemt){
    var td = elemt.up().siblings();
    if($F(elemt) != '0'){
        var url = "fundraiserAmendMembersDisplay.action?selectedNetworkId="+$F(elemt);
        td[1].down('a').writeAttribute('href',url);
        td[1].down('a').show();
    }else{
        var url = "#";
        td[1].down('a').writeAttribute('href',url);
        td[1].down('a').hide();
    }
}
//fundraisingCreateTeamMember.jsp End

/* Function to check the number of characters entered in Text area. */
var count = 400;
function limiter() {
    var tex = document.userAccountStatus.reason.value;
    var len = tex.length;

    if (len > count) {
        tex = tex.substring(0, count);
        document.userAccountStatus.reason.value = tex;
        return false;

    } else {
        return true;
    }
}

/*
 * This is generic function to set maxLength of a textarea.
 * You need to pass element and masLength you want to set for you textarea.
 * Need to call on key up and down.
 * Ex. onkeydown="textareaMaxLength(this, 1000);" onkeyup="textareaMaxLength(this, 1000);"
 */
function textareaMaxLength(element, maxLength){
    var count = maxLength;
    var tex = $F(element);
    var len = tex.length;
    var remaningcount = count-len;
    if (len > count) {
        tex = tex.substring(0, count);
        element.setValue(tex);
        return false;
    }
}

//Start - Ajax call for search fundraiser by email on fundraiserAddPeopleNetwork.jsp
function searchFundraiserByEmailIdForNetwork(){
    $('noRecordFound').innerHTML="";
    $('recordFound').innerHTML="";
    $('errorMsgForEmail').innerHTML="";

     var emailadd = $F('emailadd');
     if(emailadd == null || emailadd == ""){
         $('errorMsgForEmail').innerHTML = "<p class='errorMessagenofloat'>Please tell us what you'd like to search for.</p>";
         return;
     }
     if(emailadd.indexOf('@') < 0){
         $('errorMsgForEmail').innerHTML = "<p class='errorMessagenofloat'>Please enter a valid email address.</p>";
         return;
     }
     var params = 'emailAddressSearchText=' + emailadd;
     var url = "ajaxSearchRegisteredFundraiser.action";
     new Ajax.Request(url, {
            method :'POST',
            parameters :params,
            asynchronous :true,
            onSuccess :displaySearchResultForNetwork
    });

     function displaySearchResultForNetwork(transport){
         var xml_doc = transport.responseXML.documentElement;
         createTableForNetwork(xml_doc);
     }
}
function createTableForNetwork(xml_doc){
    memberListSize = xml_doc.getAttribute("listSize");
    emailAddressFound = xml_doc.getAttribute("emailAddressFound");

    if(emailAddressFound == 'Yes' && memberListSize == 0){
        var noRecordMsg = "<p class='errorMessagenofloat'> " +
                    "Email address you are searching for is already added as team member. </p>";
        $('noRecordFound').innerHTML=noRecordMsg;
    }else{
    if(memberListSize == 0){
        var noRecordMsg = "<p class='errorMessagenofloat'> We can't find anyone that matches your search - Please try again.</p>";
        $('noRecordFound').innerHTML=noRecordMsg;

    } else {
        var recordMsg =
            recordMsg = "<p class='errorMessage'> We've found " + memberListSize + " people that match your search - please choose who you'd like to add to your network.</p>";

        $('recordFound').innerHTML=recordMsg;

        theTable = $('searchResultTable');
        if (navigator.appName == "Microsoft Internet Explorer") {
            newTable = document
                    .createElement('<TABLE class="setupevent-search-results" style="width:98%;" id="searchResultTable"/>');
            newTable.setAttribute('class', 'setupevent-search-results');
            theTable.parentNode.replaceChild(newTable,theTable);

        } else if (navigator.appName == "Netscape") {
            newTable = document.createElement('TABLE');
            theTable.parentNode.replaceChild(newTable,theTable);
            newTable.setAttribute('id', 'searchResultTable');
            newTable.setAttribute('class', 'setupevent-search-results');
            newTable.setAttribute('style', 'width:98%;');
        }

        var tabBody = document.createElement('TBODY');
        var email;
        var foreName;
        var surName;
        for (i = 0; i < memberListSize; i++) {
            email = xml_doc.childNodes[0].childNodes[i].getAttribute("emailAddress");
            foreName = xml_doc.childNodes[0].childNodes[i].getAttribute("fundraiserName");
            surName = xml_doc.childNodes[0].childNodes[i].getAttribute("fundraiserSurName");
            id = xml_doc.childNodes[0].childNodes[i].getAttribute("fundraiserId");



            var span = document.createElement('Table');
            span.setAttribute('width','440');


            var tableCol = document.createElement('TR');

            var titleCell1 = document.createElement("TD");
            titleCell1.setAttribute('width','300');
            if(navigator.appName == "Microsoft Internet Explorer"){
                titleCell1.setAttribute('className','addemailtd');
            }else if(navigator.appName == "Netscape"){
                titleCell1.setAttribute('class','addemailtd');
            }

            textStrong1 = document.createElement("strong");
            br = document.createElement("br");

            textStrong1.appendChild(document.createTextNode(foreName +" "+ surName));
            titleCell1.appendChild(textStrong1);
            titleCell1.appendChild(textStrong1);
            titleCell1.appendChild(br);
            titleCell1.appendChild(document.createTextNode(email));

            tableCol.appendChild(titleCell1);


            var titleCell2 = new Element('TD');

            titleCell2.innerHTML = '<a href="#" name="f'+ id +'"><img src="'+addNetwork+'" alt="Add to network" title="Add to network"/></a>';

            if(navigator.appName == "Microsoft Internet Explorer"){
                titleCell2.setAttribute('className','addpeopletbletd addpeoplebtmbor');
            }else if(navigator.appName == "Netscape"){
                titleCell2.setAttribute('class','addpeopletbletd addpeoplebtmbor');
            }


            titleCell2.down('a').observe('click',function(){
                addToMyTeam(this,'Y');
            });
            tableCol.appendChild(titleCell2);

            tabBody.appendChild(tableCol);

            var tableCol2 = document.createElement('TR');

            var titleCell3 = document.createElement("TD");
            titleCell3.appendChild(document.createTextNode(email));

            if(navigator.appName == "Microsoft Internet Explorer"){
                titleCell3.setAttribute('className','addemailtd');
            }else if(navigator.appName == "Netscape"){
                titleCell3.setAttribute('class','addemailtd');
            }

            tableCol2.appendChild(titleCell3);

        }
        newTable.appendChild(tabBody);
    }
    }
}
//End - Ajax call for search fundraiser by email on fundraiserAddPeopleNetwork.jsp

//Start - Ajax call for search fundraiser by email on fundraisingCreateTeamMemner.jsp
function searchFundraiserByEmailIdForTeam(){
    $('noRecordFound').innerHTML="";
    $('recordFound').innerHTML="";
    $('errorMsgForEmail').innerHTML="";

     var emailadd = $F('emailadd');
     if(emailadd == null || emailadd == ""){
         $('errorMsgForEmail').innerHTML = "<p class='errorMessagenofloat'>Please tell us what you'd like to search for.</p>";
         return;
     }
     if(emailadd.indexOf('@') < 0){
         $('errorMsgForEmail').innerHTML = "<p class='errorMessagenofloat'>Please enter a valid email address.</p>";
         return;
     }
     var params = 'emailAddressSearchText=' + emailadd;
     var url = "ajaxSearchRegisteredFundraiser.action";
     new Ajax.Request(url, {
            method :'POST',
            parameters :params,
            asynchronous :true,
            onSuccess :displaySearchResult
    });

     function displaySearchResult(transport){
         var xml_doc = transport.responseXML.documentElement;
         createTableForTeam(xml_doc);
     }
}

function createTableForTeam(xml_doc){
    memberListSize = xml_doc.getAttribute("listSize");
    emailAddressFound = xml_doc.getAttribute("emailAddressFound");
    emailAddressNotFound = xml_doc.getAttribute("emailAddress");
    actualEmailAddress= xml_doc.getAttribute("actualEmailAddress");
    if(emailAddressFound == 'Yes' && memberListSize == 0){
        var noRecordMsg = "<p class='errorMessagenofloat'> " +
                    "Email address you are searching for is already added as team member. </p>";
        $('noRecordFound').innerHTML=noRecordMsg;
        $('noResultFoundTable').down().hide();
        $('searchResultTable').down().hide();

    }else{
    if(memberListSize == 0){
        var noRecordMsg = "<p class='errorMessagenofloat'> Sorry - this person isn&#39;t registered with us at the moment. If you&#39;d like us to invite them to join just click the button below and we&#39;ll send them an email.<br/><br/>If they then register, we'll automatically add them to your team. </p>";
        $('noRecordFound').innerHTML=noRecordMsg;
        theTable = $('noResultFoundTable');
        //$('searchResultTable').down().innerHTML="";
        $('searchResultTable').down().hide();

        if (navigator.appName == "Microsoft Internet Explorer") {
            newTable = document
                    .createElement('<TABLE class="setupevent-search-results" style="width:98%;" id="noResultFoundTable"/>');

            theTable.parentNode.replaceChild(newTable,theTable);
        } else if (navigator.appName == "Netscape") {
            newTable = document.createElement('TABLE');
            theTable.parentNode.replaceChild(newTable,theTable);
            newTable.setAttribute('id', 'noResultFoundTable');
            newTable.setAttribute('class', 'setupevent-search-results');
        }

        var tableBody = document.createElement('TBODY');
        var tableCol = document.createElement('TR');

        var titleCell1 = document.createElement("TD");
        titleCell1.appendChild(document.createTextNode(emailAddressNotFound));
        titleCell1.innerHTML+='<input type="hidden" name="emailAddressToBeInvited" value="'+actualEmailAddress+'"/>';

        if(navigator.appName == "Microsoft Internet Explorer"){
            titleCell1.setAttribute('className','addemailtd');
        }else if(navigator.appName == "Netscape"){
               titleCell1.setAttribute('class','addemailtd');
        }
        tableCol.appendChild(titleCell1);

        var titleCell4 = new Element('TD');

        if(navigator.appName == "Microsoft Internet Explorer"){
            titleCell4.setAttribute('className','addpeopletbletd addpeoplebtmbor');
        }else if(navigator.appName == "Netscape"){
            titleCell4.setAttribute('class','addpeopletbletd addpeoplebtmbor');
        }


        titleCell4.innerHTML = '<a href="#" ><img src="'+inviteThisPerson+'" alt="Invite this person" title="Invite this person"/></a>';
        titleCell4.setStyle('padding-bottom:10px;');
        titleCell4.down('a').observe('click',function(){
                addToInvitedMembers(this);
        });

        tableCol.appendChild(titleCell4);
        tableBody.appendChild(tableCol);

        newTable.appendChild(tableBody);

    } else {
        var recordMsg =
            recordMsg = "<p class='errorMessage'> We've found " + memberListSize + " people that match your search - please choose who you'd like to add to your team.</p>";

        $('recordFound').innerHTML=recordMsg;
        $('noResultFoundTable').down().hide();

        theTable = $('searchResultTable');
        if (navigator.appName == "Microsoft Internet Explorer") {
            newTable = document
                    .createElement('<TABLE class="setupevent-search-results" style="width:98%;" id="searchResultTable"/>');
            theTable.parentNode.replaceChild(newTable,theTable);
        } else if (navigator.appName == "Netscape") {
            newTable = document.createElement('TABLE');
            newTable.setAttribute('width', '100%');
            theTable.parentNode.replaceChild(newTable,theTable);
            newTable.setAttribute('id', 'searchResultTable');
            newTable.setAttribute('class', 'setupevent-search-results');
            newTable.setAttribute('style', 'width:98%;');
        }

        var tabBody = document.createElement('TBODY');


        var email;
        var foreName;
        var surName;
        for (i = 0; i < memberListSize; i++) {
            email = xml_doc.childNodes[0].childNodes[i].getAttribute("emailAddress");
            foreName = xml_doc.childNodes[0].childNodes[i].getAttribute("fundraiserName");
            surName = xml_doc.childNodes[0].childNodes[i].getAttribute("fundraiserSurName");
            id = xml_doc.childNodes[0].childNodes[i].getAttribute("fundraiserId");

            var span = document.createElement('Table');
            span.setAttribute('width','440');


            var tableCol = document.createElement('TR');

            var titleCell1 = document.createElement("TD");
            titleCell1.setAttribute('width','300');
            if(navigator.appName == "Microsoft Internet Explorer"){
                titleCell1.setAttribute('className','addemailtd');
            }else if(navigator.appName == "Netscape"){
                   titleCell1.setAttribute('class','addemailtd');
            }

            textStrong1 = document.createElement("strong");
            br = document.createElement("br");

            textStrong1.appendChild(document.createTextNode(foreName +" "+ surName));
            titleCell1.appendChild(textStrong1);
            titleCell1.appendChild(textStrong1);
            titleCell1.appendChild(br);
            titleCell1.appendChild(document.createTextNode(email));

            tableCol.appendChild(titleCell1);


            var titleCell2 = new Element('TD');

            titleCell2.innerHTML = '<a href="#" name="f'+ id +'"><img src="'+addtoTeam+'" alt="Add to team" title="Add to team"/></a>';

            if(navigator.appName == "Microsoft Internet Explorer"){
                titleCell2.setAttribute('className','addpeopletbletd addpeoplebtmbor');
            }else if(navigator.appName == "Netscape"){
                   titleCell2.setAttribute('class','addpeopletbletd addpeoplebtmbor');
            }


            titleCell2.down('a').observe('click',function(){
                addToMyTeamMembers(this,'Y');
            });
            tableCol.appendChild(titleCell2);

            tabBody.appendChild(tableCol);

            var tableCol2 = document.createElement('TR');

            var titleCell3 = document.createElement("TD");
            titleCell3.appendChild(document.createTextNode(email));

            if(navigator.appName == "Microsoft Internet Explorer"){
                titleCell3.setAttribute('className','addemailtd');
            }else if(navigator.appName == "Netscape"){
                   titleCell3.setAttribute('class','addemailtd');
            }
            tableCol2.appendChild(titleCell3);


        }
        newTable.appendChild(tabBody);
    }
    }
}
//End - Ajax call for search fundraiser by email on fundraisingCreateTeamMemner.jsp

/** This function is call for fundriser text area limit check. - START*/
function myMessageLimiter(elementId, limit) {
    // default 100
    var count = 100;
    if(limit && limit > 0){
        count = limit;
    }
    var tex =  document.getElementById(elementId).value;
    var len = tex.length;
    var remaningcount = count-len;

    if (len > count) {
        tex = tex.substring(0, count);
        document.getElementById(elementId).value = tex;
        return false;
    }
}


//Start - Ajax call for search fundraiser by email on fundraisingAmendTeamMemner.jsp
function searchFundraiserByEmailIdForAmendTeam(){
    $('noRecordFound').innerHTML="";
    $('recordFound').innerHTML="";
    $('errorMsgForEmail').innerHTML="";

     var emailadd = $F('emailadd');
     if(emailadd == null || emailadd == ""){
         $('errorMsgForEmail').innerHTML = "<p class='errorMessagenofloat'>Please tell us what you'd like to search for.</p>";
         return;
     }
     if(emailadd.indexOf('@') < 0){
         $('errorMsgForEmail').innerHTML = "<p class='errorMessagenofloat'>Please enter a valid email address.</p>";
         return;
     }
     var params = 'emailAddressSearchText=' + emailadd;
     var url = "ajaxSearchRegisteredFundraiser.action";
     new Ajax.Request(url, {
            method :'POST',
            parameters :params,
            asynchronous :true,
            onSuccess :displaySearchResult
    });

     function displaySearchResult(transport){
         var xml_doc = transport.responseXML.documentElement;
         createTableForAmendTeam(xml_doc);
     }
}

function createTableForAmendTeam(xml_doc){
    memberListSize = xml_doc.getAttribute("listSize");
    emailAddressFound = xml_doc.getAttribute("emailAddressFound");

    if(emailAddressFound == 'Yes' && memberListSize == 0){
        var noRecordMsg = "<p class='errorMessagenofloat'> " +
                    "Email address you are searching for is already added as team member. </p>";
        $('noRecordFound').innerHTML=noRecordMsg;
        $('noResultFoundTable').down().hide();
        $('searchResultTable').down().hide();
    }else{
    if(memberListSize == 0){
        var noRecordMsg = "<p class='errorMessagenofloat'> Sorry - this person isn&#39;t registered with us at the moment. If you&#39;d like us to invite them to join just click the button below and we&#39;ll send them an email.<br/><br/>If they then register, we'll automatically add them to your team. </p>";
        $('noRecordFound').innerHTML=noRecordMsg;
        theTable = $('noResultFoundTable');
        $('searchResultTable')
        $('searchResultTable').down().hide();


        if (navigator.appName == "Microsoft Internet Explorer") {
            newTable = document
                    .createElement('<TABLE class="setupevent-search-results" id="noResultFoundTable"/>');
            theTable.parentNode.replaceChild(newTable,theTable);
        } else if (navigator.appName == "Netscape") {
            newTable = document.createElement('TABLE');
            theTable.parentNode.replaceChild(newTable,theTable);
            newTable.setAttribute('id', 'noResultFoundTable');
            newTable.setAttribute('class', 'setupevent-search-results');
        }

        var tableBody = document.createElement('TBODY');
        var tableCol = document.createElement('TR');

        var titleCell1 = document.createElement("TD");
        titleCell1.appendChild(document.createTextNode($F('emailadd')));
        tableCol.appendChild(titleCell1);

        var titleCell4 = new Element('TD');
        titleCell4.innerHTML = '<a href="#" ><img src="'+inviteThisPerson+'" alt="Invite this person" title="Invite this person"/></a>';
        titleCell4.down('a').observe('click',function(){
            addToInvitedMembersForAmend(this);
        });

        tableCol.appendChild(titleCell4);
        tableBody.appendChild(tableCol);

        newTable.appendChild(tableBody);

    } else {
        var recordMsg =
            recordMsg = "<p class='errorMessage'> We've found " + memberListSize + " people that match your search - please choose who you'd like to add to your team.</p>";

        $('recordFound').innerHTML=recordMsg;

        theTable = $('searchResultTable');
        $('noResultFoundTable').down().hide();
        if (navigator.appName == "Microsoft Internet Explorer") {
            newTable = document
                    .createElement('<TABLE class="setupevent-search-results" id="searchResultTable"/>');
            theTable.parentNode.replaceChild(newTable,theTable);
        } else if (navigator.appName == "Netscape") {
            newTable = document.createElement('TABLE');
            theTable.parentNode.replaceChild(newTable,theTable);
            newTable.setAttribute('id', 'searchResultTable');
            newTable.setAttribute('class', 'setupevent-search-results');
        }

        var tabBody = document.createElement('TBODY');

        var tableColTitle = document.createElement('TR');

        titleCell1 = document.createElement("TD");
        textStrong1 = document.createElement("strong");
        textStrong1.appendChild(document.createTextNode(""));
        titleCell1.appendChild(textStrong1);
        tableColTitle.appendChild(titleCell1);

        titleCell2 = document.createElement("TD");
        textStrong2 = document.createElement("strong");
        textStrong2.appendChild(document.createTextNode("First name"));
        titleCell2.appendChild(textStrong2);
        tableColTitle.appendChild(titleCell2);

        titleCell3 = document.createElement("TD");
        textStrong3 = document.createElement("strong");
        textStrong3.appendChild(document.createTextNode("Last name"));
        titleCell3.appendChild(textStrong3);
        tableColTitle.appendChild(titleCell3);

        titleCell4 = document.createElement("TD");
        textStrong4 = document.createElement("strong");
        textStrong4.appendChild(document.createTextNode(""));
        titleCell4.appendChild(textStrong4);
        tableColTitle.appendChild(titleCell4);

        tabBody.appendChild(tableColTitle);

        var email;
        var foreName;
        var surName;
        for (i = 0; i < memberListSize; i++) {
            email = xml_doc.childNodes[0].childNodes[i].getAttribute("emailAddress");
            foreName = xml_doc.childNodes[0].childNodes[i].getAttribute("fundraiserName");
            surName = xml_doc.childNodes[0].childNodes[i].getAttribute("fundraiserSurName");
            id = xml_doc.childNodes[0].childNodes[i].getAttribute("fundraiserId");

            var tableCol = document.createElement('TR');

            var titleCell1 = document.createElement("TD");
            titleCell1.appendChild(document.createTextNode(email));
            tableCol.appendChild(titleCell1);

            var titleCell2 = document.createElement("TD");
            titleCell2.appendChild(document.createTextNode(foreName));
            tableCol.appendChild(titleCell2);

            var titleCell3 = document.createElement("TD");
            titleCell3.appendChild(document.createTextNode(surName));
            tableCol.appendChild(titleCell3);

            var titleCell4 = new Element('TD');
            titleCell4.innerHTML = '<a href="#" name="f'+ id +'"><img src="'+addtoTeam+'" alt="Add to team" title="Add to team"/></a>';
            titleCell4.down('a').observe('click',function(){
                    addToMyTeamMembersForAmend(this,'Y');
            });
            tableCol.appendChild(titleCell4);

            tabBody.appendChild(tableCol);
        }
        newTable.appendChild(tabBody);
    }
    }
}
//End - Ajax call for search fundraiser by email on fundraisingAmendTeamMemner.jsp

//fundraisingAmendTeamMember.jsp Start
function addToMyTeamMembersForAmend(elemt, flag){
    var tr = elemt.up().up();
    var noOfTrs= tr.siblings('tr');
    if(noOfTrs.size() <2){
         $('recordFound').innerHTML="";
         $('searchResultTable').hide();

    }
    var td = tr.down('td').siblings('td');
    var IdToAdd = elemt.readAttribute("name");
td[2].innerHTML='<input type="hidden" name="memberIdsToAdd" value="'+IdToAdd+'"/><a href="#" id="teamAmendMemberRemoveLink" name="'+IdToAdd+'">Remove<img height="30" width="30" src="'+imageRemove+'" title="Remove" alt="Remove" class="next"/></a>';
td[2].down('a').observe('click',function(){
    removeFromMyTeamMembersForAmend(this,'N');
});
$('yourTeamTable').down().insert(tr);

    if($('yourTeamTable').down().down('tr').siblings().size() != 1 ){
        $('teamAmendMemberRemoveLink').show();
    } else {

        $('teamAmendMemberRemoveLink').hide();
    }
}
function removeFromMyTeamMembersForAmend(elemt, flag){
     $('searchResultTable').show();
    var tr = elemt.up().up();
    var td = tr.down('td').siblings('td');
    var IdToRemove = elemt.readAttribute("name");
    td[2].innerHTML='<input type="hidden" name="memberIdsToRemove" value="'+IdToRemove+'"/><a href="#" name="'+IdToRemove+'"><img src="'+addtoTeam+'" alt="Add to team" title="Add to team"/></a>';
    td[2].down('a').observe('click',function(){
        addToMyTeamMembersForAmend(this,'N');
    });
    $('searchResultTable').down().insert(tr);

    if($('yourTeamTable').down().down('tr').siblings().size() == 1){

        $('teamAmendMemberRemoveLink').hide();
    } else {

        $('teamAmendMemberRemoveLink').show();
    }

}
//fundraisingAmendTeamMember.jsp End

//Start - Ajax call for search fundraiser by email on fundraiserAddPeopleNetwork.jsp
function searchFundraiserByEmailIdForAmendNetwork(){
    $('noRecordFound').innerHTML="";
    $('recordFound').innerHTML="";
    $('errorMsgForEmail').innerHTML="";

     var emailadd = $F('emailadd');
     if(emailadd == null || emailadd == ""){
         $('errorMsgForEmail').innerHTML = "<p class='errorMessagenofloat'>Please tell us what you'd like to search for.</p>";
         return;
     }
     if(emailadd.indexOf('@') < 0){
         $('errorMsgForEmail').innerHTML = "<p class='errorMessagenofloat'>Please enter a valid email address.</p>";
         return;
     }
     var params = 'emailAddressSearchText=' + emailadd;
     var url = "ajaxSearchRegisteredFundraiser.action";
     new Ajax.Request(url, {
            method :'POST',
            parameters :params,
            asynchronous :true,
            onSuccess :displaySearchResultForNetwork
    });

     function displaySearchResultForNetwork(transport){
         var xml_doc = transport.responseXML.documentElement;
         createTableForAmendNetwork(xml_doc);
     }
}
function createTableForAmendNetwork(xml_doc){
    memberListSize = xml_doc.getAttribute("listSize");
    emailAddressFound = xml_doc.getAttribute("emailAddressFound");

    if(emailAddressFound == 'Yes' && memberListSize == 0){
        var noRecordMsg = "<p class='errorMessagenofloat'> " +
                    "Email address you are searching for is already added as team member. </p>";
        $('noRecordFound').innerHTML=noRecordMsg;
        $('emailSearchResult').hide();
    }else{
    if(emailAddressFound == 'No') {
        var noRecordMsg = "<p class='errorMessagenofloat'> We can't find anyone that matches your search - Please try again.</p>";
        $('noRecordFound').innerHTML=noRecordMsg;
        $('recordFound').hide();
        $('emailSearchResult').hide();
    }
    else if(memberListSize == 0){
        var noRecordMsg = "<p class='errorMessagenofloat'> We can't find anyone that matches your search - Please try again.</p>";
        $('noRecordFound').innerHTML=noRecordMsg;
        $('recordFound').hide();
        $('emailSearchResult').hide();

    } else {
        $('recordFound').show();
        $('emailSearchResult').show();
        var recordMsg =
            recordMsg = "<p class='errorMessage'> We've found " + memberListSize + " people that match your search - please choose who you'd like to add to your network.</p>";

        $('recordFound').innerHTML=recordMsg;

        theTable = $('searchResultTable');
        if (navigator.appName == "Microsoft Internet Explorer") {
            newTable = document
                    .createElement('<TABLE class="setupevent-search-results" id="searchResultTable"/>');
            theTable.parentNode.replaceChild(newTable,theTable);
        } else if (navigator.appName == "Netscape") {
            newTable = document.createElement('TABLE');
            theTable.parentNode.replaceChild(newTable,theTable);
            newTable.setAttribute('id', 'searchResultTable');
            newTable.setAttribute('class', 'setupevent-search-results');
        }

        var tabBody = document.createElement('TBODY');

        var tableColTitle = document.createElement('TR');

        titleCell1 = document.createElement("TD");
        textStrong1 = document.createElement("strong");
        textStrong1.appendChild(document.createTextNode(""));
        titleCell1.appendChild(textStrong1);
        tableColTitle.appendChild(titleCell1);

        titleCell2 = document.createElement("TD");
        textStrong2 = document.createElement("strong");
        textStrong2.appendChild(document.createTextNode("First name"));
        titleCell2.appendChild(textStrong2);
        tableColTitle.appendChild(titleCell2);

        titleCell3 = document.createElement("TD");
        textStrong3 = document.createElement("strong");
        textStrong3.appendChild(document.createTextNode("Last name"));
        titleCell3.appendChild(textStrong3);
        tableColTitle.appendChild(titleCell3);

        titleCell4 = document.createElement("TD");
        textStrong4 = document.createElement("strong");
        textStrong4.appendChild(document.createTextNode(""));
        titleCell4.appendChild(textStrong4);
        tableColTitle.appendChild(titleCell4);

        tabBody.appendChild(tableColTitle);

        var email;
        var foreName;
        var surName;
        for (i = 0; i < memberListSize; i++) {
            email = xml_doc.childNodes[0].childNodes[i].getAttribute("emailAddress");
            foreName = xml_doc.childNodes[0].childNodes[i].getAttribute("fundraiserName");
            surName = xml_doc.childNodes[0].childNodes[i].getAttribute("fundraiserSurName");
            id = xml_doc.childNodes[0].childNodes[i].getAttribute("fundraiserId");

            var tableCol = document.createElement('TR');

            var titleCell1 = document.createElement("TD");
            titleCell1.appendChild(document.createTextNode(email));
            tableCol.appendChild(titleCell1);

            var titleCell2 = document.createElement("TD");
            titleCell2.appendChild(document.createTextNode(foreName));
            tableCol.appendChild(titleCell2);

            var titleCell3 = document.createElement("TD");
            titleCell3.appendChild(document.createTextNode(surName));
            tableCol.appendChild(titleCell3);

            var titleCell4 = new Element('TD');
            titleCell4.innerHTML = '<a href="#" name="f'+ id +'"><img src="'+addNetwork+'" alt="Add to network" title="Add to network"/></a>';
            titleCell4.down('a').observe('click',function(){
                addToMyNetworkForAmend(this,'Y');
            });
            tableCol.appendChild(titleCell4);

            tabBody.appendChild(tableCol);
        }
        newTable.appendChild(tabBody);
    }
    }
}
//End - Ajax call for search fundraiser by email on fundraiserAddPeopleNetwork.jsp

//fundraiserAmendMembers.jsp Start
function addToMyNetworkForAmend(elemt, flag){
        var tr = elemt.up().up();
        var td = tr.down('td').siblings('td');
        var IdToAdd = elemt.readAttribute("name");
    td[2].innerHTML='<input type="hidden" name="memberIdsToAdd" value="'+IdToAdd+'"/><a href="#" name="'+IdToAdd+'">Remove<img height="30" width="30" src="'+imageRemove+'" title="Remove" alt="Remove" class="next"/></a>';
    td[2].down('a').observe('click',function(){
        removeFromMyNetworkForAmend(this,'N');
    });
    $('yourTeamTable').down().insert(tr);
}

function removeFromMyNetworkForAmend(elemt, flag){
    var tr = elemt.up().up();
    if(tr.siblings().size() == 1){
        return;
    }
    var td = tr.down('td').siblings('td');
    var IdToRemove = elemt.readAttribute("name");
    td[2].innerHTML='<input type="hidden" name="memberIdsToRemove" value="'+IdToRemove+'"/><a href="#" name="'+IdToRemove+'"><img src="'+addNetwork+'" alt="Add to team" title="Add to network"/></a>';
    td[2].down('a').observe('click',function(){
        addToMyNetworkForAmend(this,'N');
    });
    $('searchResultTable').down().insert(tr);
}
//fundraiserAmendMembers.jsp End

function addToInvitedMembersForAmend(elemt){
    $('noRecordFound').innerHTML="";
    $('searchResultTable').down().show();

    if( $('invitedTeamMembers') !=null && $('invitedTeamMembers')!=''){
        $('invitedTeamMembers').show();
    }
    var tr = elemt.up().up();
    var td = tr.down('td').siblings('td');
    var emailAddress = elemt.up().siblings('td')[0].innerHTML;
    td[0].innerHTML='<input type="hidden" name="emailAddressToBeInvited" value="'+emailAddress+'"/><a href="#">Remove<img height="30" width="30" src="'+imageRemove+'" title="Remove" alt="Remove" class="next"/></a>';
    td[0].down('a').observe('click',function(){
        removeFromInvitedMembersForAmend(this);
    });
    $('invitedMemberTable').down().insert(tr);
}

//This function is used to prevent user form multiple submission.
var formSubmitted = false;

function submitForm ( )
{if ( formSubmitted )
  {
      return false;
  }
  else
  {
    formSubmitted = true;
    return true;
  }
}

/**This function is for to show and hide the details giftaid related divs when donating money through fundraiser secreens */
function showAndHideGiftAidDetails() {

    if ($('giftAidYes')) {
      var dType = fundraiserSplitOverrideInd=$F('donorType');
      if($('giftAidYes').checked == true) {
          if(dType == "F" && getBenefitInKindOrNot=="Y") {
              $('giftAidNotes').show();
          }
          else {
              $('giftAidNotes').hide();
          }
        }
        else  if($('giftAidNoOther').checked == true || $('giftAidNoCompany').checked == true) {
                $('giftAidNotes').hide();
        }

    }
}

function hideIds(notHide) {

  if(notHide != 'totalSplitRemove' && $('totalSplitRemove') != null && $('totalSplitRemove') != '') {

     $('totalSplitRemove').hide();
  }
  if(notHide != 'totalSplit' && $('totalSplit') != null && $('totalSplit') != '') {

     $('totalSplit').hide();
  }
  if(notHide != 'totalSplitAdd' && $('totalSplitAdd') != null && $('totalSplitAdd') != '') {

     $('totalSplitAdd').hide();
  }
  if(notHide != 'totalSplitEvent' && $('totalSplitEvent') != null && $('totalSplitEvent') != '') {

     $('totalSplitEvent').hide();
  }
  if(notHide != 'totalSplitOnload' && $('totalSplitOnload') != null && $('totalSplitOnload') != '') {

     $('totalSplitOnload').hide();
  }
}



function showCashbackData(choosenRadio){


  var listElementStyle = $('payToCharity').style;
  var listElementStyle2 = $('payToMe').style;

  if(choosenRadio == "charity"){
    if (listElementStyle.display=="none"){
    listElementStyle.display="block";
    listElementStyle2.display="none";
    }
  }else if(choosenRadio == "me"){
    if (listElementStyle2.display=="none"){
    listElementStyle2.display="block";
    listElementStyle.display="none";
    }
  }
}

//
// Variables and functions used by the cashback matching pages
//

var cashbackSelectCharityBaseUrl = null;
var cashbackDefaultCharityId = null;
var cashbackDefaultCharityName = null;

function setCashbackSelectCharityBaseUrl(url) {
    cashbackSelectCharityBaseUrl = escape(url);
//    alert("cashbackSelectCharityBaseUrl=" + cashbackSelectCharityBaseUrl)
}


function cashbackOpenCharityDetailsPopup(charityId) {
//        alert('cashbackOpenCharityPopup(' + charityId + ')');
        var fullurl="/charity-web/charity/finalCharityHomepage.action?charityId=" + charityId + "&displayReason=cashback";
        var params = 'height=500,width=790,scrollbars=yes,status=yes,resizable=yes'
        var windowId = "cashbackOpenCharityPopup";
        openedWindow = window.open(fullurl,windowId,params);
        openedWindow.focus();
        return true;
}


function cashbackSelectCharity(openedWindow,charityId) {
//        alert('fundraiser.cashbackSelectCharity(openedWindow=' + openedWindow + ' , charity= ' + charityId + ')');
        var fullurl=cashbackSelectCharityBaseUrl + "?selectedCharityId=" + charityId;
//        alert('fullurl=' + fullurl);
        this.document.location = fullurl;
        return true;
}


function cashbackOpenInviteCharityPopup(charityId,charityName) {
//        alert('cashbackOpenCharityPopup(' + charityId + ',' + charityName + ')');
        cashbackDefaultCharityId = charityId;
        cashbackDefaultCharityName = charityName;
        var fullurl="/giving/about-us/find-charity-cashback.jsp";
        var params = 'height=700,width=750,scrollbars=yes,status=yes,resizable=yes'
        var windowId = "cashbackInviteCharityPopup";
        openedWindow = window.open(fullurl,windowId,params);
        openedWindow.focus();
        return true;
}

function getCashbackDefaultCharityId()
{
    return cashbackDefaultCharityId;
}

function getCashbackDefaultCharityName()
{
    return cashbackDefaultCharityName;
}

function cashbackSelectDefaultCharity() {
    var fullurl=cashbackSelectCharityBaseUrl + "?selectedCharityId=" + cashbackDefaultCharityId;
//        alert('fullurl=' + fullurl);
    this.document.location = fullurl;
    return true;

}


/* NEW JAVASCRIPT GET AJAX FUNCTION TO USE */

var ajaxLoader = "<div align='center'><br /><br /><img id='loader_gif' src='/fundraiser-web/img/lightbox/loading_tcm21-25470.gif' alt='loading...'/></div>";
var requestedPage = 0;

function ajaxGetterTridion(url,content) {
	
    document.getElementById(content).innerHTML = ajaxLoader;
    
	new Ajax.Updater(''+content+'',url,
    {
      method:'get',
      evalScripts: true
    });

    return false;
}

function ajaxGetterTridionRepeat(url,content) {
	
    document.getElementById(content).innerHTML = ajaxLoader;
    
	new Ajax.Updater(''+content+'',url,
    {

		method:'get',
		  onSuccess: function(transport){
		   	
		   //alert('function called again'+requestedPage);
		   if(requestedPage < 2){		 	
		     requestedPage ++;
			 ajaxGetterTridionRepeat(url,content);
		   }		  
		},
		
		onFailure: function(){
		  //alert('function called again'+requestedPage);
		   if(requestedPage < 2){		 	
		     requestedPage ++;
			 ajaxGetterTridionRepeat(url,content);
			 
		   }
		   
		},
		
        evalScripts: true
    });

    return false;
}



//new version

function editDetails(ID){
 	 
	  //chaeck value of the radio buttons
	 donationName(ID);
	 donationMessage(ID);
	 
	 //hide all the edit donation buttons
	 temp = $$('div.editButton');
			temp.each(function(s){

				s.removeClassName('editButton');
				s.addClassName('editButtonHide');

			}.bind(this));
			
	//display the hidden DIV to edit donation message		
	 var listElementStyle = $('editDetailsDIVID'+ID).style;		
     listElementStyle.display ="block"; 
	 

     $('saveChangesButton').removeClassName('continue-block');
	 $('saveChangesButton').addClassName('editButtonHide');
}

 function cancelDetails(ID){
 
	 //show all the edit buttons
	 temp = $$('div.editButtonHide');
			temp.each(function(s){

				s.removeClassName('editButtonHide');
				s.addClassName('editButton');

			}.bind(this));
	 
	 //hide the displayed DIV to edit donation message		
	 var listElementStyle = $('editDetailsDIVID'+ID).style;		
     listElementStyle.display ="none"; 
	 
	 //reset the Donor name and message to correct values
	 $('sponsorDetails'+ID).value = $('sponsorNameID'+ID).innerHTML;
	 $('messageDetails'+ID).value = $('messageToEditID'+ID).innerHTML;
	 
	 $('saveChangesButton').addClassName('continue-block');
	 $('saveChangesButton').removeClassName('editButton');
}

function donationName(ID){
    //check to see if radio button exsist
	if($('anonymous'+ID) != null){
		//check to see if anonymous is clicked
	    if($('anonymous'+ID).checked == true){
	      $('sponsorDetails'+ID).writeAttribute("disabled", "disabled");
	      $('sponsorDetails'+ID).addClassName('disabledStyle');
		  $('sponsorDetails'+ID).value = "";
	    }else if($('name'+ID).checked == true){	 
		   $('sponsorDetails'+ID).value = $('sponsorNameID'+ID).innerHTML;
           $('sponsorDetails'+ID).removeAttribute("disabled");
           $('sponsorDetails'+ID).removeClassName('disabledStyle');		   
    	}else{
		}
	}
}

function donationMessage(ID){
	if($('messageDetailsChecked'+ID).checked == true) {
           $('messageDetails'+ID).removeAttribute("disabled");
           $('messageDetails'+ID).removeClassName('disabledStyle');	
	}else{
	      $('messageDetails'+ID).writeAttribute("disabled", "disabled");
	      $('messageDetails'+ID).addClassName('disabledStyle');
          $('messageDetails'+ID).value = "";
    }

}

function checkDonorName(name, ID){
	if(name == false){
	 $('anonymous'+ID).writeAttribute("checked", "checked");
	}else{
	 $('name'+ID).writeAttribute("checked", "checked");	
	}
   donationName(ID);
}

function checkDonorMessage(name, ID){
	if(name == true){
	 $('messageDetailsChecked'+ID).writeAttribute("checked", "checked");
	 $('messageDetails'+ID).value = $('messageToEditID'+ID).innerHTML;
	}else{
	 $('messageDetailsChecked'+ID).removeAttribute("checked");	
	} 
}

function donationEditSubmit(ID, donorName, donationMessage, donationContactChecked ,maxRecentDonations){

    $('amendedDonationId').value = ID;
    $('amendedDonorName').value = donorName;
    $('amendedDonationMessage').value = donationMessage;
    $('donationContactChecked').value = donationContactChecked;
    document.forms[0].action = '/fundraiser-web/fundraiser/amendExistingDonation.action?maxRecentDonations=' + maxRecentDonations;
    document.forms[0].submit();

}

function onSelectProvider(){
	if($('usepp') == null || $('usepp').value != "true"){		
		if( $('paymentDetails') ){
			if( $('STANDARD').checked == true ){				
				$('paymentDetails').show();
			}
			else{
				$('paymentDetails').hide();
			}
		}
	}
}



function fundraiserContactsSubmit() {
    var selectedEmails = checkEmails();
    $('fundraiserEmail').value = selectedEmails;
    document.forms['fetchFundraiserPageContactsTable'].action = '/fundraiser-web/fundraiser/fundraiserSendEmailDisplayInPortal.action?invocation=myDonors';
}





function checkEmails() {
    txt = "";
    if ($('checkbox')) {
		
		if(document.fetchFundraiserPageContactsTable.checkbox.length){
        boxes = document.fetchFundraiserPageContactsTable.checkbox.length;
        for (i = 0; i < boxes; i++) {
            if (document.fetchFundraiserPageContactsTable.checkbox[i].checked)
            {
                txt = txt + document.fetchFundraiserPageContactsTable.checkbox[i].value + ";"
            }
        }
		
		}else{
			   if(document.fetchFundraiserPageContactsTable.checkbox.checked){  
		       		txt = txt + document.fetchFundraiserPageContactsTable.checkbox.value + ";"
			   }
		}

    }
 
    return txt;
}




function donationContactChange(ID) {
    if ($('checkboxDonationContact'+ID).value == 'N') {
        $('checkboxDonationContact'+ID).value = 'Y';
    } else {
        $('checkboxDonationContact'+ID).value = 'N';
    }
}


var checkboxes = false;

function checkAll(field){
	
	
	if(checkboxes == false){
	  
	  if(document.fetchFundraiserPageContactsTable.checkbox.length){
	  
      for (i = 0; i < document.fetchFundraiserPageContactsTable.checkbox.length; i++){
		document.fetchFundraiserPageContactsTable.checkbox[i].checked = true ;
	  }
	  }else{
		 document.fetchFundraiserPageContactsTable.checkbox.checked = true; 
	  }
	  checkboxes = true;
	  return false;	
	}
	
	if(checkboxes == true){
		
	   if(document.fetchFundraiserPageContactsTable.checkbox.length){	
	  for (i = 0; i < document.fetchFundraiserPageContactsTable.checkbox.length; i++){
		document.fetchFundraiserPageContactsTable.checkbox[i].checked = false ;
	  }
	  }else{
	   document.fetchFundraiserPageContactsTable.checkbox.checked = false ;
	  }
	  checkboxes = false;
	  return false;
	}
}

// TRAC2233: Facebook changes
function popupFacebookAuthorisation(action) {
    //alert('popupFacebook(' + action + ')');
    if (action == null || action == "true") {
        var fullurl="/fundraiser-web/fundraiser/facebook_authoriseApplication.action";
        var params = 'height=500,width=790,scrollbars=yes,status=yes,resizable=yes'
        var windowId = "vmgfundraiserpopupfacebookauth";
        openedWindow = window.open(fullurl,windowId,params);
        openedWindow.focus();
    }
    return true;
}

// TRAC2233: Facebook changes
function popupPostMessage(action, maxSize) {
    //alert('popupFacebook(' + action + ')');
    var message = document.getElementById('facebookMessage').value;
    if ((message == null || message == "" || message.length < 1) || (message != null && message.length > maxSize)) {
        document.forms[0].target = "";
        document.forms[0].submit();
        return true;
    }
    if (action != null) {
        var fullurl=action+"&facebookMessage="+message+"&messageInvocation=popup";
        var params = 'height=500,width=790,scrollbars=yes,status=yes,resizable=yes'
        var windowId = "vmgfundraiserpopupfacebookpost";
        openedWindow = window.open(fullurl,windowId,params);
        openedWindow.focus();
    }
    return true;
}


function addURL(URL){
    var urlToAdd = " http://"+URL;
	$('facebookMessage').value = $('facebookMessage').value+= urlToAdd;
	return false;
}

function changeTarget() {
  if ($('showSubmit') != null) {
        var listElementStyle = $('showSubmit').style;
        listElementStyle.display="block";
    }
    return true;
}

function checktarget() {
    document.forms[0].target = "";
    return true;
}

function toggleCanEmail() {
    if($('includeMessage').checked == true) {
        $('includeMessage').value = true;
    } else {
        $('includeMessage').value = false;
    }
}


