﻿(function()
{
    window.postCommunityQuestion = function(txtQuestionClientID)
    {
        var txtQuestion = document.getElementById(
            txtQuestionClientID);

        if ((this != null) &&
				(typeof (this.href) != 'undefined') &&
				(txtQuestion != null) &&
				(txtQuestion.value != txtQuestion.defaultValue))
        {
            var questionText = txtQuestion.value;
            questionText = questionText.replace('.', '');
            this.href += encodeURIComponent(questionText);
        }
    };

    window.validateQuestionText = function(
		txtQuestionTextClientID,
		minQuestionLength)
    {
        var questionLengthIsValid = true;

        var txtQuestionText = document.getElementById(
			txtQuestionTextClientID);

        if ((txtQuestionText != null) &&
			(txtQuestionText.value.length > 0) &&
			(minQuestionLength > 0))
        {
            if (txtQuestionText.value.length < minQuestionLength)
            {
                questionLengthIsValid = false;
            }
        }

        return questionLengthIsValid;
    };

    window.showReportAbuseLinks = function()
    {
        if (typeof ($$) == 'function')
        {
            $$('div.cmnty_reportabuse').invoke('show');
        }
    };

    window.toggleReportAbuseTypes = function(
		abuseFlagTypesName,
        abuseFlagTypesDivID)
    {
        var abuseFlagTypesDivs = document.getElementsByName(
			abuseFlagTypesName);

        if ((abuseFlagTypesDivs != null) &&
			(abuseFlagTypesDivs.length > 0))
        {
            for (var index = 0; index < abuseFlagTypesDivs.length; index++)
            {
                if (abuseFlagTypesDivs[index].id != abuseFlagTypesDivID)
                {
                    abuseFlagTypesDivs[index].style.display = 'none';
                }
            }
        }
        else
        {
            abuseFlagTypesDivs = document.getElementsByTagName(
                'ul');

            for (var index = 0; index < abuseFlagTypesDivs.length; index++)
            {
                if ((abuseFlagTypesDivs[index].attributes != null) &&
                    (abuseFlagTypesDivs[index].attributes.length > 0) &&
                    (abuseFlagTypesDivs[index].attributes.getNamedItem('name') != null) &&
                    (abuseFlagTypesDivs[index].attributes.getNamedItem('name').value == abuseFlagTypesName) &&
                    (abuseFlagTypesDivs[index].id != abuseFlagTypesDivID))
                {
                    abuseFlagTypesDivs[index].style.display = 'none';
                }
            }
        }

        var abuseFlagTypesDiv = document.getElementById(
			abuseFlagTypesDivID);

        if (abuseFlagTypesDiv != null)
        {
            if (abuseFlagTypesDiv.style.display.toLowerCase() == 'none')
            {
                abuseFlagTypesDiv.style.display = '';
            }
            else
            {
                abuseFlagTypesDiv.style.display = 'none';
            }
        }
    };

    window.hideReportAbuseLink = function(
		hlReportAbuseClientID,
		spanAbuseReportedID)
    {
        var hlReportAbuse = document.getElementById(
			hlReportAbuseClientID);

        if (hlReportAbuse != null)
        {
            hlReportAbuse.onclick = '';
            hlReportAbuse.style.display = 'none';
        }

        var spanAbuseReported = document.getElementById(
			spanAbuseReportedID);

        if (spanAbuseReported != null)
        {
            spanAbuseReported.style.display = '';
        }
    };

    window.flagQuestionAbuse = function(
		questionID,
		abuseFlagTypeID,
		abuseFlagTypesDivID,
		hlReportAbuseClientID,
		spanAbuseReportedID)
    {
        if (typeof (RemoteScriptingCall) == 'function')
        {
            var flagQuestionAbuseXml = (
                '<FlagQuestionAbuse QuestionID="' +
                questionID +
                '" AbuseFlagTypeID="' +
                abuseFlagTypeID +
                '" />');

            RemoteScriptingCall(
                (ContentProviderUrl +
                    '/cmntyqna/Services/Community.asmx'),
                flagQuestionAbuseXml,
                'FlagQuestionAbuse',
                'http://www.bizbuysell.com/cmntyqna',
                'ResponseData');
        }

        var abuseFlagTypesDiv = document.getElementById(
			abuseFlagTypesDivID);

        if (abuseFlagTypesDiv != null)
        {
            abuseFlagTypesDiv.style.display = 'none';
        }

        window.hideReportAbuseLink(
			hlReportAbuseClientID,
			spanAbuseReportedID);
    };

    function flagQuestionAbuseCallBack(
        xmlRequest)
    {
        if ((xmlRequest.readyState == 4) &&
            (xmlRequest.responseXML != null))
        {
            // Do nothing for now
        }
    }

    window.flagAnswerAbuse = function(
		answerID,
		abuseFlagTypeID,
		abuseFlagTypesDivID,
		hlReportAbuseClientID,
		spanAbuseReportedID)
    {
        if (typeof (RemoteAJAXCall) == 'function')
        {
            var flagAnswerAbuseXml = (
                '<FlagAnswerAbuse AnswerID="' +
                answerID +
                '" AbuseFlagTypeID="' +
                abuseFlagTypeID +
                '" />');

            RemoteAJAXCall(
                flagAnswerAbuseCallBack,
                (ContentProviderUrl +
                    '/cmntyqna/Services/Community.asmx'),
                flagAnswerAbuseXml,
                'FlagAnswerAbuse',
                'http://www.bizbuysell.com/cmntyqna',
                -1,
                '',
                false);
        }

        var abuseFlagTypesDiv = document.getElementById(
			abuseFlagTypesDivID);

        if (abuseFlagTypesDiv != null)
        {
            abuseFlagTypesDiv.style.display = 'none';
        }

        window.hideReportAbuseLink(
			hlReportAbuseClientID,
			spanAbuseReportedID);
    };

    function flagAnswerAbuseCallBack(
        xmlRequest)
    {
        if ((xmlRequest.readyState == 4) &&
            (xmlRequest.responseXML != null))
        {
            // Do nothing for now
        }
    }

    window.toggleAnswerQuestionForm = function(
		answerQuestionFormClientID,
		answerQuestionButtonClientID)
    {
        var answerQuestionForm = document.getElementById(
			answerQuestionFormClientID);

        if (answerQuestionForm != null)
        {
            if (answerQuestionForm.style.display.toLowerCase() == 'none')
            {
                answerQuestionForm.style.display = '';
            }
            else
            {
                answerQuestionForm.style.display = 'none';
            }
        }

        var answerQuestionButton = document.getElementById(
			answerQuestionButtonClientID);

        if (answerQuestionButton != null)
        {
            if (answerQuestionButton.style.display.toLowerCase() == 'none')
            {
                answerQuestionButton.style.display = '';
            }
            else
            {
                answerQuestionButton.style.display = 'none';
            }
        }

        return false;
    };

    window.clickClear = function(
		color)
    {
        if (this != null)
        {
            if (this.value == this.defaultValue)
            {
                this.value = '';

                if (!color)
                {
                    color = '404040';
                }

                this.style.color = (
					'#' +
					color);
            }
        }
    };

    window.clickRecall = function(
		color)
    {
        if (this != null)
        {
            if (this.value == '')
            {
                this.value = this.defaultValue;

                if (!color)
                {
                    color = 'BBBBBB';
                }

                this.style.color = (
					'#' +
					color);
            }
        }
    };

    var hlShowInLineRegistrationFormClientID = '';

    window.setShowInLineRegistrationFormHyperLinkClientID = function(
        hlShowInLineRegistrationFormClientIDLocal)
    {
        hlShowInLineRegistrationFormClientID = hlShowInLineRegistrationFormClientIDLocal;
    };

    var imgBtnSubmitClientID = '';

    window.setSubmitImageButtonClientID = function(
        imgBtnSubmitClientIDLocal)
    {
        imgBtnSubmitClientID = imgBtnSubmitClientIDLocal;
    };

    window.toggleInLineRegistrationForm = function(
	    show,
	    showErrorMessage,
	    errorValidationGroup)
    {
        var inLineRegistrationForm = document.getElementById(
			'cmnty_register');

        if (typeof (showErrorMessage) == 'undefined')
        {
            showErrorMessage = false;
        }

        if (inLineRegistrationForm != null)
        {
            if (typeof (show) != 'undefined')
            {
                if (show)
                {
                    inLineRegistrationForm.style.display = '';
                }
                else
                {
                    inLineRegistrationForm.style.display = 'none';
                }
            }
            else
            {
                if (inLineRegistrationForm.style.display == '')
                {
                    inLineRegistrationForm.style.display = 'none';
                }
                else
                {
                    inLineRegistrationForm.style.display = '';
                }
            }
        }

        if (hlShowInLineRegistrationFormClientID != null)
        {
            var hlShowInLineRegistrationForm = document.getElementById(
                hlShowInLineRegistrationFormClientID);

            if (hlShowInLineRegistrationForm != null)
            {
                hlShowInLineRegistrationForm.style.display = 'none';
            }
        }

        if (imgBtnSubmitClientID != null)
        {
            var imgBtnSubmit = document.getElementById(
                imgBtnSubmitClientID);

            if (imgBtnSubmit != null)
            {
                imgBtnSubmit.style.display = '';
            }
        }

        if ((showErrorMessage) &&
            (typeof (errorValidationGroup) != 'undefined'))
        {
            var errorMessage = 'In order to submit your question you must be registered and logged in.  Please see the form below.';

            var addErrorMessageFunctionCall = (
				'Add' +
				errorValidationGroup +
				'ErrorMessage(errorMessage);');

            eval(addErrorMessageFunctionCall);
        }
    };

    window.CheckMaxLength = function(
        maxLength,
        errorMessageClientID,
        evt)
    {
        var that = this;

        function inner()
        {
            var errorMessage = null;

            if (typeof (errorMessageClientID) != 'undefined')
            {
                errorMessage = document.getElementById(
                    errorMessageClientID);
            }

            if ((that) &&
                (that != null) &&
                (typeof (that.value) != 'undefined') &&
                (that.value) &&
                (that.value != ''))
            {
                // Ignore newlines (WI#5769)
                var tempValue = that.value.replace(
                    /\r/g,
                    '').replace(
                        /\n/g,
                        '');

                if (tempValue.length > maxLength)
                {
                    that.value = that.value.substring(
                        0,
                        (that.value.length -
                            (tempValue.length -
                                maxLength)));

                    that.scrollTop = that.scrollHeight;

                    if ((errorMessage) &&
                        (errorMessage != null))
                    {
                        errorMessage.style.display = '';
                    }
                }
                else if ((tempValue.length < maxLength) &&
                    (errorMessage != null))
                {
                    errorMessage.style.display = 'none';
                }
            }
        }

        setTimeout(
            inner,
            1);
    };
})();