﻿// JScript File

    function GallerySelectImage( id, height, width )
    {
        var img = $(id);
        if ( img != null )
        {
            var styleString = "";
            if ( height != 0 )
            {
                if ( height > 223)
                {
                    height = 223;
                }
                styleString = "height:" + height + "px;";
            }
            else if ( width != 0 )
            {
                styleString = "width:" + width + "px;";
            }
            if ( img.src.indexOf( "SizedImage.ashx" ) > 0 )
            {
                $('pictureBox').replace("<img id='pictureBox' style='" + styleString + "'  src='" + ImgFromSizedImage( img.src, height, width ) + "' />" );
            }
            else
            {
               $('pictureBox').replace("<img id='pictureBox' style='" + styleString + "' src='" + img.src + "' />" );
            }
        }
    }

        function StringForToken( src,  token,  separator)
        {
            var returnedString = "";
            var i = src.indexOf(token);
            if (i >= 0)
            {
                var j;
                j = src.indexOf(separator, i + token.length);
                if (j < 0)
                {
                    j = src.length;
                }
                returnedString = src.substring(i + token.length, j );
            }
            return returnedString;
        }

        function ImgFromSizedImage( sizedImage,  height,  width)
        {
            var img = StringForToken(sizedImage, "src=", "&");
            var strHeight = StringForToken(sizedImage, "height=", "&");
            var strWidth = StringForToken(sizedImage, "width=", "&");
            var strbgcolor = StringForToken(sizedImage, "bgcolor=", "&");
            var strFill = StringForToken(sizedImage, "fill=", "&");
            var initPic;
            initPic ="SizedImage.ashx?src=" + img;
            if (height > 0)
            {
                initPic += "&height=" + height;
            }
            if (width > 0)
            {
                initPic += "&width=" + width;
            }
            if (strFill.length > 0)
            {
                initPic += "&fill=" + strFill;
            }
            if (strbgcolor.length > 0)
            {
                initPic += "&bgcolor=" + strbgcolor;
            }
            return initPic;
        }
