﻿// JScript File
var m_sExternalParams = null;

function LayoutChanged(asAttribute, asValue)
{
    var loParent = window.parent;
    if(loParent != null)
    {
        loParent.document.DemoView.imgChart.src="Pages/Demo/ShowChart.aspx?width=570&height=280&" 
            + asAttribute + "=" + asValue
            + (m_sExternalParams != null ? m_sExternalParams : "");
    }
}

function FontFamilyChanged(asAttribute, addlFontFamily)
{
    if (addlFontFamily != null)
    {
        if(addlFontFamily.selectedIndex > -1)
        {
            LayoutChanged(asAttribute, addlFontFamily.options[addlFontFamily.selectedIndex].value);
        }
    }
}

function FontSizeChanged(asAttribute, addlFontSize)
{
    if (addlFontSize != null)
    {
        if(addlFontSize.selectedIndex > -1)
        {
            LayoutChanged(asAttribute, addlFontSize.options[addlFontSize.selectedIndex].value);
        }
    }
}

function ColorIndexChanged(asAttribute, addlColorList)
{
    if (addlColorList != null)
    {
        if(addlColorList.selectedIndex > -1)
        {
            LayoutChanged(asAttribute, addlColorList.options[addlColorList.selectedIndex].value);
        }
    }
}

function ColorValueChanged(asAttribute, atxtA, atxtR, atxtG, atxtB)
{
    if(atxtA != null
        && atxtR != null
        && atxtG != null
        && atxtB != null)
    {
        var lsColor = "";

        var lsAlpha = "";
        if(atxtA.value != "")
        {
            try
            {
                lsAlpha = parseInt(atxtA.value, 10).toString(16);
                if(lsAlpha.length < 2)
                {
                    lsAlpha = "0" + lsAlpha;
                }
            }
            catch(e)
            {
                lsAlpha = "00";
            }
        }
        else
        {
            lsAlpha = "00";
        }

        var lsRed = "";
        if(atxtR.value != "")
        {
            try
            {
                lsRed = parseInt(atxtR.value, 10).toString(16);
                if(lsRed.length < 2)
                {
                    lsRed = "0" + lsRed;
                }
            }
            catch(e)
            {
                lsRed = "00";
            }
        }
        else
        {
            lsRed = "00";
        }

        var lsGreen = "";
        if(atxtG.value != "")
        {
            try
            {
                lsGreen = parseInt(atxtG.value, 10).toString(16);
                if(lsGreen.length < 2)
                {
                    lsGreen = "0" + lsGreen;
                }
            }
            catch(e)
            {
                lsGreen = "00";
            }
        }
        else
        {
            lsGreen = "00";
        }

        var lsBlue = "";
        if(atxtB.value != "")
        {
            try
            {
                lsBlue = parseInt(atxtB.value, 10).toString(16);
                if(lsBlue.length < 2)
                {
                    lsBlue = "0" + lsBlue;
                }
            }
            catch(e)
            {
                lsBlue = "00";
            }
        }
        else
        {
            lsBlue = "00";
        }
        
        lsColor = lsAlpha + lsRed + lsGreen + lsBlue;
        LayoutChanged(asAttribute, lsColor);
    }
}

function DropDown_SelectedIndexChanged(asAttribute, addlDropDown)
{
    if (addlDropDown != null)
    {
        if(addlDropDown.selectedIndex > -1)
        {
            LayoutChanged(asAttribute, addlDropDown.options[addlDropDown.selectedIndex].value);
        }
    }
}

function LoadTheme(asThemeFile)
{
    var loParent = window.parent;
    if(loParent != null)
    {
        loParent.document.DemoView.imgChart.src = "Pages/Demo/ShowChart.aspx?width=570&height=280&LoadTheme=" + asThemeFile;
    }
}

function LoadThemeFromDDL(addlThemeList)
{
    if (addlThemeList != null)
    {
        if(addlThemeList.selectedIndex > -1)
        {
            LoadTheme(addlThemeList.options[addlThemeList.selectedIndex].value);
        }
    }
}

function QueryStringParameter(asParameter, avDefaultValue, asURL)
{
	var llPos;
	var lsSearch = asURL != null ? asURL : window.location.search.replace(/%26/g, "&");

	if ((llPos = lsSearch.search(asParameter + "=")) > -1)
	{
		var lsValue = lsSearch.slice(llPos + asParameter.length + 1);

		if ((llPos = lsValue.search(/&/)) > -1)
			lsValue = lsValue.slice(0, llPos);

		lsValue = unescape(lsValue);
	}

	return(lsValue != null && lsValue != "" ? lsValue : avDefaultValue);
}
