using System;
using System.Web;

namespace digioz
{
    /// <summary>
    /// Contains helper methods which can be used in different controls.
    /// </summary>
    public static class ControlsHelper
    {
        public static string GetDecodedUrl(string psInput)
        {
            // To allow the user to enter Url in the format "Default.aspx?id=14",
            // add the '/' character at the beginning of the string.
            psInput = String.Format("/{0}", psInput);

            string lsDecodedUrl = HttpUtility.UrlDecode(psInput.Substring(
                psInput.ToLower().LastIndexOf('/')));

            // Take into account default page can have url /Default.aspx
            // or /Default.aspx?id=1.
            if (psInput.ToLower().LastIndexOf("default.aspx") != -1 &&
                psInput.ToLower().LastIndexOf('?') == -1)
            {
                lsDecodedUrl = String.Format("{0}{1}", lsDecodedUrl, "?id=1");
            }

            return lsDecodedUrl;
        }
    }
}