/************

General

************/

function MHAlert(msg)
{
    showServiceMessage(msg);
}
function MHShow(id,show)
{
    if (show)
        $(id).show();
    else
        $(id).hide();        
}

function MHEffect(div, state, duration)
{
    if (state==false)
        new Effect.BlindDown(div,  {duration: duration});
    else
        new Effect.BlindUp(div,  {duration: duration});
        
}

function updateContent(container,url,postparameters,onSuccessDelegate) 
{
    var poststr = postparameters;
    if (poststr == undefined)
        poststr = "";
        
     new Ajax.Request(url, 
     {   
        method: 'post',  
        parameters: postparameters, 
        onSuccess: function(transport) 
        {     
            try
            { $(container).innerHTML = transport.responseText; }
            catch (e)
            { MHAlert(e.message); }
           
           if (onSuccessDelegate != undefined)
           {
                if (typeof(onSuccessDelegate) == "function")
                    onSuccessDelegate();
                else
                   if (onSuccessDelegate != undefined) 
                        eval(onSuccessDelegate);
           }
        },
        onFailure: function(transport)
        {
            MHAlert("Error. Please try again later");
        }
     }); 
}

function Switcher(switchon, firstVal, secondVal, firstDel, secondDel)
{
    var object = $(switchon);
    if (object.innerHTML == firstVal)
    {
        if ((firstDel != undefined) && (typeof(firstDel)=="function")) 
            firstDel();
        object.innerHTML = secondVal;
    }
    else
    {
        if ((secondDel != undefined) && (typeof(secondDel)=="function")) 
            secondDel();
        object.innerHTML = firstVal;
    }    
}

function addClass(id, clsName, add)
{
    if (add)
        $(id).addClassName(clsName);
    else
        $(id).removeClassName(clsName);        
}

function submitForm(form)
{
    $(form).submit();
}

function FixApostrophe(inString)
{
    var s = new String(inString);
    
    return s.replace('\'','\\\'');
}

function ImprovedvalidateNotEmpty(elem, errorContainerId, errorMessage, Error )
{
    var val = elem.value;
    var errorContainer = $(errorContainerId);
    if(val.length == 0)
	{
	    Error.found = true;
	    Error.elementToFocus = elem;
		errorContainer.innerHTML = errorMessage;
		errorContainer.show();
	}
	else if (Error.found == false)
	    errorContainer.hide();
}

function ImprovedvalidateEmail(elem, errorContainerId, errorMessage, Error)
{
	var errorContainer = $(errorContainerId);
	var email = elem.value;
	if(email.length == 0 || email.match(/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z]{2,6}(\.[a-zA-Z]{2})?$/) == null)
    {    
	 	Error.found = true;
	    Error.elementToFocus = elem;
		errorContainer.innerHTML = errorMessage;
		errorContainer.show();
    }
	else if (Error.found == false)
		errorContainer.hide();
}


/************

    submitChangePassForm

************/

function submitChangePassForm()
{
	var pas1 = $('NewPassword');
	var pas2 = $('RetypedNewPassword');
	var errCont = $('PasswordErrorContainer');

    if (pas1.value.length < 6)
    {
        errCont.innerHTML = 'Password cannot be shorter than 6 characters';
        errCont.show();
    }
    else if (pas1.value != pas2.value)
    {
        errCont.innerHTML = 'Original and re-typed password do not match';
        errCont.show();
    }
    else
        submitForm('EditUserForm');
}

/************

Survey/Poll

************/
function visabillitySetter(elem, cssRule, visible)
{
    var link = elem;
    while (link!= null && link.className.indexOf(cssRule) == -1)
        link = getParent(link);
    if (visible==false)
        Effect.BlindUp(link, {duration: 1}); 
    else
        Effect.BlindDown(link, {duration: .5}); 
}

function showPoll(state)
{
    visabillitySetter($('PollDiv'),"PollContainer", state);
}

function pollSwitch(sender)
{
    Switcher(sender,'Add Survey','Remove Survey',showPoll(true),function(){clearPollElement();showPoll(false);});
}

function clearPollElement()
{
    var pollQuestion = $('pollQuestion');  
    pollQuestion.value = "";   
    var options = $("PollDiv").getElementsByClassName("caPollOption");
    for(var i=0; i<options.length; i++)
    {
        options[i].value="";
    }
}

function addOption()
{
    addOptionWithDuration(.5);
}

function addOptionWithDuration(duration) 
{
    var PollDivMarkup = '<table class="PollTable">' +
                                    '<tr>' +
                                        '<td>Survey Optional Result</td>' +
                                        '<td><input type="text" name="pollOptions" class="CreateRemedyTextField TextField caPollOption"  /></td>' +
                                        '<td><a href="javascript:void(0)" onclick="removePollOption(this, \'PollTable\' );return false;">Remove</a></td>' +
                                    '</tr>' +
                                '</table>';
    
    var PollContainer = $('PollDiv');
    new Insertion.Bottom(PollContainer, PollDivMarkup);
    var newOption = PollContainer.lastChild;
    showEffect(newOption, duration);
    setTimeout(function(){
        newOption.getElementsByTagName('input')[0].focus();
    }, duration * 1000);    
}

function removePollOption(elem, cssRule)
{
    var link = elem;
    while (link!= null && link.className.indexOf(cssRule) == -1)
        link = getParent(link);
    Effect.BlindUp(link, {duration: .5, afterFinish:function(obj){Element.remove(obj.element);}});
}

function enableVoting(state)
{
    var vis = 'visible';
    var toShow = 'VoteAgain';
    var toHide = 'ChangeVote';
    if(!state)
    {
        $('VoteForm').submit();
        vis = 'hidden';
        toShow = 'ChangeVote';
        toHide = 'VoteAgain';
        
    }    
    var Radio = $$('#SurveyContainerInner .OptionRadio');
    Radio.each(function (cur) {
	    cur.style.visibility=vis;
    });
    var toShow = $(toShow);
    toShow.show();
    var toHide = $(toHide);
    toHide.hide();        
}

function getPollSubview(treatmentId, showResults)
{
    updateContent('PollOuter',siteRoot + '/Polls/View.aspx','treatmentId=' + treatmentId + '&showResults=' + showResults);
}	
function getSitePollSubview(showResults)
{
    updateContent('SitePollOuter',siteRoot + '/SitePolls/View.aspx','showResults=' + showResults);
}	
function voteSitePoll(form)
{
    var formm=$(form);    
    var inputs = $$('#' + form.id + ' input[name=selectedOption]');
    var selectedOption = 0;
    inputs.each(function (curRadio) {
		if (curRadio.checked) selectedOption = curRadio.value;
	});
    
    if (selectedOption!=0)
        updateContent('SitePollOuter',siteRoot + '/SitePolls/Vote.aspx','selectedOption=' + selectedOption);
    else
        MHAlert("You must select one of the options");
}	

function selectPollOption(radioButton)
{
    $$('#SurveyContainerInner .SelectedPollOption').each(function(cur)
    {
        cur.removeClassName('SelectedPollOption');
    });
    addClass(radioButton,'SelectedPollOption',true);
}

/******************

Subscribtion

*******************/
function switchSubscriptionView()
{
    Switcher('subscribeSwitch','Subscribe','Close Subscription', 
        function(){MHEffect('SubscribtionOuter',false,1);}, 
        function(){MHEffect('SubscribtionOuter',true,1);});
}

function submitSubscription(form)
{
    var form = $(form);
    var Error = {};
    var element = $('SubscriptionName');
    var errorContainer = $('SubscriptionErrorContainer');
    
    if (element.value=="")
    {
        errorContainer.innerHTML = "You must enter subscription name!";
        errorContainer.show();
        if(element != null)
            element.focus();
    }
    else
    {
	    errorContainer.hide();            
	    form.submit();
	}	    
}

function showSubscription(state)
{
    MHEffect('SubscribtionOuter',!state,1);    
    MHShow('ShowSubscribeLink',!state);
    MHShow('HideSubscribeLink',state);
    MHShow('navShowSub',!state);
    MHShow('navHideSub',state);
}

function UpdateTreatmentSubscribe(formId)
{
    var Form = $(formId);
    var Id = $F($$('#' + formId + ' input[name=TreatmentId]')[0]);
    var Comments = $$('#' + formId + ' input[name=Comment]')[0].checked==true;
    var Votes = $$('#' + formId + ' input[name=Votes]')[0].checked==true;
    var VotesNum = $F($$('#' + formId + ' select[name=VotesNum]')[0]);
    var Name = $F($$('#' + formId + ' input[name=Name]')[0]);
    var Email = $F($$('#' + formId + ' input[name=Email]')[0]);
 	new Ajax.Request(siteRoot + "/Subscriptions/NewTreatmentSubscribe.aspx",
        {
            parameters: { TreatmentId: Id, Comment: Comments, Votes: Votes, VotesNum: VotesNum, Name: Name, Email: Email},
            onFailure: function(t){
                MHAlert("Error. Please try again");
            },
            onSuccess: function(t){
                MHAlert(t.responseText, 350, 120);
                if (t.responseText=='Your subscription request has been saved')
                    showSubscription(false);
            }
        });    
}

function UpdateRemedySubscribe(formId)
{
    var Form = $(formId);
    var Id = $F($$('#' + formId + ' input[name=remedyId]')[0]);
    var Treatment = $$('#' + formId + ' input[name=Treatment]')[0].checked==true;
    var Name = $F($$('#' + formId + ' input[name=Name]')[0]);
    var Email = $F($$('#' + formId + ' input[name=Email]')[0]);

 	new Ajax.Request(siteRoot + "/Subscriptions/NewRemedySubscribe.aspx",
        {
            parameters: { remedyId: Id, Treatment: Treatment, Name: Name, Email: Email},
            onFailure: function(t){
                MHAlert("Error. Please try again");
            },
            onSuccess: function(t){
                MHAlert(t.responseText, 350, 120);
            }
        });
}

function UpdateConditionSubscribe(formId)
{
    var Form = $(formId);
    var Id = $F($$('#' + formId + ' input[name=ConditionId]')[0]);
    var Treatment = $$('#' + formId + ' input[name=Treatment]')[0].checked==true;
    var Name = $F($$('#' + formId + ' input[name=Name]')[0]);
    var Email = $F($$('#' + formId + ' input[name=Email]')[0]);

 	new Ajax.Request(siteRoot + "/Subscriptions/NewConditionSubscribe.aspx",
        {
            parameters: { conditionId: Id, Treatment: Treatment, Name: Name, Email: Email},
            onFailure: function(t){
                MHAlert("Error. Please try again");
            },
            onSuccess: function(t){
                MHAlert(t.responseText, 350, 120);
            }
        });
}

function UpdateCommunitySubscribe(formId)
{
    var Form = $(formId);
    var Id = $F($$('#' + formId + ' input[name=AuthorId]')[0]);
    var Post = $$('#' + formId + ' input[name=post]')[0].checked==true;
    var Treatment = $$('#' + formId + ' input[name=treatment]')[0].checked==true;
    var Remedy = $$('#' + formId + ' input[name=remedy]')[0].checked==true;
    var Name = $F($$('#' + formId + ' input[name=Name]')[0]);
    var Email = $F($$('#' + formId + ' input[name=Email]')[0]);

 	new Ajax.Request(siteRoot + "/Subscriptions/NewCommunitySubscription.aspx",
        {
            parameters: { AuthorId: Id, post: Post, treatment: Treatment, remedy: Remedy, Name: Name, Email: Email},
            onFailure: function(t){
                MHAlert("Error. Please try again");
            },
            onSuccess: function(t){
                MHAlert(t.responseText, 350, 120);
            }
        });
}

function removeSubscriptionByName(id, name)
{
	var params= 'name=' + name;
 	new Ajax.Request(siteRoot + "/Subscriptions/DeleteSubscription.aspx",
        {
            parameters: params,
            onFailure: function(t){
                MHAlert("Error. Please try again");
            },
            onSuccess: function(t){
				if(t.responseText == "OK")
				{
				    //Raise a Success messageBox
                    var subscribtionOuter = $('SubscriptionRow' + id);
                    new Effect.BlindUp(subscribtionOuter,  {duration: 1});
				}
				else
				{
				    //Raise a Error messageBox
				}
            }
        });
}

function showSubscriptionWithId(id)
{
    var subscribtionOuter = $('SubscribtionOuter' + id);
    new Effect.BlindDown(subscribtionOuter,  {duration: 1});
    var ActionBarEdit = $('ActionBarEdit' + id);
    var ActionBarClose = $('ActionBarClose' + id);
    ActionBarEdit.hide();
    ActionBarClose.show();
}
function hideSubscriptionWithId(id)
{
    var subscribtionOuter = $('SubscribtionOuter' + id);
    new Effect.BlindUp(subscribtionOuter,  {duration: 1});
    var ActionBarEdit = $('ActionBarEdit' + id);
    var ActionBarClose = $('ActionBarClose' + id);
    ActionBarEdit.show();
    ActionBarClose.hide();
}

function showSubscriptionCondition()
{
    var subscribtionOuter = $('SubscribtionOuter');
    new Effect.BlindDown(subscribtionOuter,  {duration: 1});
    var ShowSubscribeNav = $('navShowSub');
    var HideSubscribeNav = $('navHideSub');
    ShowSubscribeNav.hide();
    HideSubscribeNav.show();
}

function hideSubscriptionCondition()
{
    var subscribtionOuter = $('SubscribtionOuter');
    new Effect.BlindUp(subscribtionOuter,  {duration: 1});
    var ShowSubscribeNav = $('navShowSub');
    var HideSubscribeNav = $('navHideSub');
    ShowSubscribeNav.show();
    HideSubscribeNav.hide();
}

function subscriptionSignup(form, action)
{
    form = $(form);
    new Ajax.Request(siteRoot + "/" + action + ".aspx",
    {
        parameters: form.serialize(true),
        onFailure: function(t){
            MHAlert("Error, Please try again later.");
        },
        onSuccess: function(t){
            MHAlert("The email address " + t.responseText, 350, 120);
        }
    });
}

/****************

    Suggestions

****************/

function submitSuggestComment(form)
{
    var form = $(form);
    var Error = {};
    Error.elementToFocus = null;
    Error.found = false;
    var element = form.getElementsBySelector('input[name=author]')[0]; 
    validateNotEmpty(element, 'AuthorErrorContainer', "Author cannot be empty!", Error);
    element = form.getElementsBySelector('input[name=email]')[0]; 
    validateNotEmpty(element, 'EmailErrorContainer', "Email cannot be empty!", Error);
    element = form.getElementsBySelector('textarea[name=comment]')[0]; 
    validateNotEmpty(element, 'CommentErrorContainer', "Comment cannot be empty!", Error);
	
	if(Error.found == false)
	    form.submit();    
	else
	{
        if(Error.elementToFocus != null)
            Error.elementToFocus.focus();
    }
}

function submitSuggestion(form)
{
    var form = $(form);
    var Error = {};
    Error.elementToFocus = null;
    Error.found = false;
    var title = $('title');
    var content = $('content');
    
    ImprovedvalidateNotEmpty(title, 'SuggestErrorContainer', "Title cannot be empty", Error);
    ImprovedvalidateNotEmpty(content, 'SuggestErrorContainer', "Suggestion cannot be empty", Error);
    
	if(Error.found == false)
	{
	    form.submit(); 
	}
	else
	{
        if(Error.elementToFocus != null)
            Error.elementToFocus.focus();
    }	    
}

function submitSuggestionUnReg(form)
{
    var form = $(form);
    var Error = {};
    Error.elementToFocus = null;
    Error.found = false;
    var title = $('title');
    var content = $('content');
    var name = $('name');
    var email = $('email');
    var captcha = $('commentCaptcha');
    
    ImprovedvalidateNotEmpty(title, 'SuggestErrorContainer', "Title cannot be empty", Error);
    ImprovedvalidateNotEmpty(content, 'SuggestErrorContainer', "Suggestion cannot be empty", Error);
    ImprovedvalidateNotEmpty(name, 'SuggestErrorContainer', "Name cannot be empty", Error);
    ImprovedvalidateEmail(email, 'SuggestErrorContainer', "Email is invalid", Error);
    ImprovedvalidateNotEmpty(captcha, 'SuggestErrorContainer', "captcha cannot be empty", Error);
    
	if(Error.found == false)
	{
	    form.submit(); 
	    document.getElementById(this).submit();   
	}
	else
	{
        if(Error.elementToFocus != null)
            Error.elementToFocus.focus();
    }	    
}

/******************

Blog

*******************/

function showRecentPost(curDiv, postDiv)
{
    var postsOuter = $(curDiv);
    postsOuter.hide();
    
    var showdiv = $(postDiv);
    showdiv.show();
}

function submitBlogCommentReg(form)
{
    var form = $(form);
    var Error = {};
    Error.elementToFocus = null;
    Error.found = false;
    
    var comment = form.CommentBox;
    ImprovedvalidateNotEmpty(comment, 'CommentErrorContainer', "You must enter a comment", Error);
	if(Error.found == false)
	{
	    form.submit(); 
	}
	else
	{
        if(Error.elementToFocus != null)
            Error.elementToFocus.focus();
    }
}

function submitBlogCommentUnReg(form) {
    var form = $(form);
    var Error = {};
    Error.elementToFocus = null;
    Error.found = false;

    var comment = form.CommentBox;
    var commentEmail = form.commentEmail;
    var commentName = form.commentName;
    var commentCaptcha = form.commentCaptcha;

    ImprovedvalidateNotEmpty(commentCaptcha, 'CommentErrorContainer', "You must enter the code", Error);
    ImprovedvalidateNotEmpty(comment, 'CommentErrorContainer', "You must enter a comment", Error);
    ImprovedvalidateNotEmpty(commentName, 'CommentErrorContainer', "You must enter a name", Error);
    ImprovedvalidateNotEmpty(commentEmail, 'CommentErrorContainer', "You must enter an email address", Error);

    if (Error.found == false) {
        form.submit();
        document.getElementById(this).submit();
    }
    else {
        if (Error.elementToFocus != null)
            Error.elementToFocus.focus();
    }
}

function getPostAddComment(outerDiv, postId)
{
    updateContent('PostPH' + outerDiv, siteRoot + '/Community/Blogs/AddComment.aspx','postId=' + postId);
    $('PostComment' + outerDiv).hide();
    $('PostHideComment' + outerDiv).show();
}	

function hidePostComment(outerDiv)
{
    $('NewCommentWrapper').remove();
    $('PostComment' + outerDiv).show();
    $('PostHideComment' + outerDiv).hide();
}	

function openAddBlogComment()
{
    var addCommentContainer = $('AddBlogComment');
    if(addCommentContainer.style.display == "none")
        new Effect.BlindDown(addCommentContainer, {duration: 0.9});
    else 
        new Effect.BlindUp(addCommentContainer, {duration: 0.9});
}

function RemoveAutoFeed(id)
{
    new Ajax.Request(siteRoot + "/Community/Blogs/DeleteAutoFeed.aspx",
    {
        parameters: { inId: id},
        onFailure: function(t){
            MHAlert("Error. Please try again");
        },
        onSuccess: function(t){
            var outerDiv = $$(".AutoFeedOuter")[0];
            outerDiv.innerHTML = t.responseText;
        }
    });
}

function removePostById(id, divId)
{
	var params= 'postId=' + id;
 	new Ajax.Request(siteRoot + "/Community/Blogs/DeletePost.aspx",
        {
            parameters: params,
            onFailure: function(t){
                MHAlert("Error. Please try again");
            },
            onSuccess: function(t){
				if(t.responseText == "OK")
				{
				    //Raise a Success messageBox
                    var PostOuter = $(divId);
                    var PostCommentsOuter = $('PostPH' + divId);
                    new Effect.BlindUp(PostOuter,  {duration: 1});
                    new Effect.BlindUp(PostCommentsOuter, {duration: 1});
				}
				else
				{
				    //Raise a Error messageBox
				    MHAlert("Error. Please try again");
				}
            }
        });
}


function SaveAutoFeed(divId)
{
    var Url = $F($$('#' + divId + ' input[name=Url]')[0]);
    
    showProgressBarDialog();
    new Ajax.Request(siteRoot + "/Community/Blogs/AddAutoFeed.aspx",
        {
            parameters: { inUrl: Url},
            onFailure: function(t){
                Dialog.closeInfo();
                MHAlert("This feed url already exists.");
            },
            onSuccess: function(t){
                var outerDiv = $$(".AutoFeedOuter")[0];
                outerDiv.innerHTML = t.responseText;
                Dialog.closeInfo();
            }
        });        
}

function AddAutoFeed()
{
    var newDiv = $('SingleAutoFeedNew')
    if (newDiv!=null) 
        MHAlert("There is a new feed open, save it first.");
    else
        updateContent('NewAutoFeedOuter', siteRoot + '/Community/Blogs/NewAutoFeed.aspx', undefined,undefined);
}

function selectSearchTab(number)
{
    for(var i = 1; i<=5; i++)
    {
        addClass("tab" + i,'active-tab',(i==number));
        addClass("tab" + i,'active-tab-body',(i==number));
        addClass("tabButton" + i,'active-tab',(i==number));
        addClass("tabButton" + i,'active-tab-body',(i==number));
    }
}

function getSearchresults(searchVal, searchType, page, first, sort)
{
    //To-Do Set Treatments as the first tab
    var orderTable = new Array(2,1,3,4,5);
    
    var url = siteRoot + "/Home/AjaxSearch.aspx";
    var colorTabs = false;
    // notice the use of a proxy to circumvent the Same Origin Policy. 
    new Ajax.Request(url, {   
        method: 'get', 
        parameters: { 
            'searchStream': searchVal,
            'inType': searchType,
            'page': page,
            'sort': sort
        },  
        onSuccess: function(transport) {     
            var myDiv = $('tab' + searchType);     
            if (transport.responseText!=null)    
            {   
                myDiv.innerHTML = transport.responseText;
                if (page==1)
                {                
                    var CountAll = $F($$('#tab' + searchType + ' input[name=maxResults]')[0]);
                    if (CountAll != null)
                    {
                        var tabButton = $('tabButton' + searchType);
                        if (tabButton != null) tabButton.innerHTML = CountAll;
                        
//                        var CountThis = $$('input[name=maxResultsNum]');                                                
//                        if ((CountThis.length==5) && (first) && (false))
//                        {
//                            var temp = CountThis[0];
//                            CountThis[0] = CountThis[1];
//                            CountThis[1] = temp;

//                            var counter = 1;
//                            var firstresult = 0;
//                            CountThis.each(function(num){
//                                if(($F(num)>0) && (firstresult==0))
//                                    firstresult=orderTable[counter-1];
//                                counter=counter+1;        
//                            });
//                            colorTabs = true;
//                        }
                    }
                }
                location="#MainHeaderShadow";  
                if (colorTabs) selectSearchTab(firstresult);                
            }
            else       
                myDiv.innerHTML = "";
        } 
    }); 
}

function getPostsPage(page)
{
    var url = siteRoot + "/Community/Blogs/PostsPage.aspx";    
    updateContent('Posts', siteRoot + '/Community/Blogs/PostsPage.aspx', 'page='+page,function(){location="#MainHeaderShadow";});
}

function getArchivedPostsPage(year, month, page)
{
    var url = siteRoot + "/Community/Blogs/ArchivePostsPage.aspx";    
    updateContent('Posts', siteRoot + '/Community/Blogs/ArchivePostsPage.aspx', 'page='+page+'&year='+year+'&month='+month,function(){location="#MainHeaderShadow";});
}

function sortTreatmentsBy(sorter)
{
    var url = siteRoot + "/Home/MostHelpful.aspx";    
    updateContent('MostHelpfulOut', url, 'sorter='+sorter,null);
}

function sortCondTreatmentsBy(id, type, sorter)
{
    var url = siteRoot + "/Conditions/MostHelpful.aspx";    
    updateContent('MostHelpfulOut', url, 'id='+id+'&type='+type+'&sorter='+sorter,null);
}

function TreatsortCondTreatmentsBy(id, type, sorter) {
    var url = siteRoot + "/Treatments/MostHelpful.aspx";
    updateContent('MostHelpfulOut', url, 'id=' + id + '&type=' + type + '&sorter=' + sorter, null);
}

function HelpedMeComment(id, isHelped, isBig) {
    //var addCommentContainer = $('HelpedComment' + id);
    //addCommentContainer.hide();
    if ((isBig == undefined) || (isBig))
        updateContent('HelpedComment' + id, siteRoot + "/Treatments/HelpedComment.aspx", 'id=' + id + '&isHelped=' + isHelped,
        function() {
            var HelpedMeText = $('HelpedMeCount' + id);
            var HelpedCount = $('HelpedMeText' + id);
            if (HelpedCount.value != '') HelpedMeText.innerHTML = HelpedCount.value;
        });
    else
        updateContent('HelpedComment' + id, siteRoot + "/Treatments/MiniHelpedComment.aspx", 'id=' + id + '&isHelped=' + isHelped,
        function() {
            var HelpedMeText = $('HelpedMeCount' + id);
            var HelpedCount = $('HelpedMeText' + id);
            if (HelpedCount.value != '') HelpedMeText.innerHTML = HelpedCount.value;
        });

    //new Effect.BlindUp(addCommentContainer, { duration: 0.9 });    
}

function CancelHelpedMeComment(id) {
    var addCommentContainer = $('HelpedComment' + id);
    //new Effect.BlindUp(addCommentContainer, { duration: 0.9 });
    addCommentContainer.innerHTML = '';
}