function setfocus()
{
document.getElementById("Red1").focus();
}

function increase(Inp,chg)
{
   nextval=Math.floor(window.document.forms['Form1'].elements[Inp].value);
   nextval=nextval + Math.floor(chg);
   if (nextval>-1 && nextval<256)
   window.document.forms['Form1'].elements[Inp].value = nextval;

   SetSample();
   return;
}

function GiveHex(Dec)
{
   if(Dec == 10)
      Value = "A";
   else
   if(Dec == 11)
      Value = "B";
   else
   if(Dec == 12)
      Value = "C";
   else
   if(Dec == 13)
      Value = "D";
   else
   if(Dec == 14)
      Value = "E";
   else
   if(Dec == 15)
      Value = "F";
   else
      Value = "" + Dec;

   return Value;
}

function DecToHex(Red,Green,Blue)
{
   Red4 = window.document.forms['Form1'].elements['Red1'].value;
   Green4 = window.document.forms['Form1'].elements['Green1'].value;
   Blue4 = window.document.forms['Form1'].elements['Blue1'].value;

   a = GiveHex(Math.floor(Red / 16));
   b = GiveHex(Red % 16);
   c = GiveHex(Math.floor(Green / 16));
   d = GiveHex(Green % 16);
   e = GiveHex(Math.floor(Blue / 16));
   f = GiveHex(Blue % 16);

   z = a + b + c + d + e + f;

   return z;
}

function SetSample()
{
   Red1 = window.document.forms['Form1'].elements['Red1'].value;
   Green1 = window.document.forms['Form1'].elements['Green1'].value;
   Blue1 = window.document.forms['Form1'].elements['Blue1'].value;
   Red2 = window.document.forms['Form1'].elements['Red2'].value;
   Green2 = window.document.forms['Form1'].elements['Green2'].value;
   Blue2 = window.document.forms['Form1'].elements['Blue2'].value;

   if (Red1<0)
   {alert("Background Color Red value must be between 0 and 255"); return false;};
   if (Red1>255)
   {alert("Background Color Red value must be between 0 and 255"); return false;};
   if (Green1<0)
   {alert("Background Color Green value must be between 0 and 255"); return false;};
   if (Green1>255)
   {alert("Background Color Green value must be between 0 and 255"); return false;};
   if (Blue1<0)
   {alert("Background Color Blue value must be between 0 and 255"); return false;};
   if (Blue1>255)
   {alert("Background Color Blue value must be between 0 and 255"); return false;};
   if (Red2<0)
   {alert("Text Color Red value must be between 0 and 255"); return false;};
   if (Red2>255)
   {alert("Text Color Red value must be between 0 and 255"); return false;};
   if (Green2<0)
   {alert("Text Color Green value must be between 0 and 255"); return false;};
   if (Green2>255)
   {alert("Text Color Green value must be between 0 and 255"); return false;};
   if (Blue2<0)
   {alert("Text Color Blue value must be between 0 and 255"); return false;};
   if (Blue2>255)
   {alert("Text Color Blue value must be between 0 and 255"); return false;};


   z=DecToHex(Red1,Green1,Blue1);
   document.getElementById('Sample1').style.backgroundColor='#' + z;
   y=DecToHex(Red2,Green2,Blue2);
   document.getElementById('SampleText').style.color='#' + y;

}

function ColorContrast()
{
   Red1 = window.document.forms['Form1'].elements['Red1'].value;
   Green1 = window.document.forms['Form1'].elements['Green1'].value;
   Blue1 = window.document.forms['Form1'].elements['Blue1'].value;
   Red2 = window.document.forms['Form1'].elements['Red2'].value;
   Green2 = window.document.forms['Form1'].elements['Green2'].value;
   Blue2 = window.document.forms['Form1'].elements['Blue2'].value;

   color1=(Red1*299+Green1*587+Blue1*114)/1000;
   color2=(Red2*299+Green2*587+Blue2*114)/1000;
   if (color1<color2)
   {brighttest=color2-color1}
   else {brighttest=color1-color2};

   if (brighttest>125)
   {window.document.forms['Form1'].elements['BrightTestValue'].value="Pass - value="+brighttest}
   else{window.document.forms['Form1'].elements['BrightTestValue'].value="Fail - value="+brighttest};

   colortest=Math.max(Red1,Red2)-Math.min(Red1,Red2)+Math.max(Green1,Green2)-Math.min(Blue1,Blue2);
   colortest=colortest+Math.max(Blue1,Blue2)-Math.min(Blue1,Blue2);
   if (colortest>500)
   {window.document.forms['Form1'].elements['ColorTestValue'].value="Pass - value="+colortest}
   else{window.document.forms['Form1'].elements['ColorTestValue'].value="Fail - value="+colortest};

   return false;
}

cms.custom.home =
{
    initializeMenu : function()
    {
        // Haal de titels uit de content items op en geef elk item een unieke ID
        var container = document.getElementById('textContentHome');
        var h2s = container.getElementsByTagName('H2');
        var h2Count = h2s.length;

        var menuTitles = new Array()

        var iIndex = 0;
        do
        {
            var h2 = h2s[0];
            var div = h2.parentNode;
            div.parentNode.rel = iIndex;

            menuTitles[iIndex++] = h2.innerHTML;
            div.removeChild(h2);
        }
        while (h2s.length > 0)

        // Voeg de titels toe als menu items
        var menuItemContainer = null;
        if (menuItemContainer = document.getElementById('menuItemsHome'))
        {
            var uls = menuItemContainer.getElementsByTagName('UL');
            if (uls.length > 0)
            {
                var menu = uls[0];

                for (var iIndex = 0; iIndex < h2Count; iIndex++)
                {
                    var li = document.createElement('LI');
                    var a = document.createElement('A');
                    a.href = '#';
                    a.innerHTML = menuTitles[iIndex];
                    a.rel = iIndex;

                    cms.event.attach(a, 'click', this.showHomeContentEvent, this, true);

                    if (iIndex == 0)
                    {
                        a.className = 'active';
                    }

                    li.appendChild(a);

                    menu.appendChild(li);
                }
            }
        }

        // Toon standaard het eerste item
        this.showHomeContent(0);
    },

    showHomeContentEvent : function(event)
    {
        var index = (event.srcElement || event.target).rel;

        this.showHomeContent(index);

        return false;
    },

    showHomeContent : function(showIndex)
    {
        // Verberg de bestaande blokken en toon alleen het nieuwe block
        var blocks = document.getElementById('textContentHome').childNodes;
        for (var iIndex = 0; iIndex < blocks.length; iIndex++)
        {
            if (blocks[iIndex].tagName == 'DIV')
            {
                if (blocks[iIndex].rel == showIndex)
                {
                    blocks[iIndex].style.display = 'block';
                }
                else
                {
                    blocks[iIndex].style.display = 'none';
                }
            }
        }

        // Stel het juiste item als actief in
        var menuItemContainer = null;
        if (menuItemContainer = document.getElementById('menuItemsHome'))
        {
            var uls = menuItemContainer.getElementsByTagName('UL');
            if (uls.length > 0)
            {
                var menuItems = uls[0].getElementsByTagName('LI');

                for (var iIndex = 0; iIndex < menuItems.length; iIndex++)
                {
                    var as = menuItems[iIndex].getElementsByTagName('A');
                    var a = as[0];

                    if (iIndex == showIndex)
                    {
                        if (!a.className.match(/\s?active/))
                        {
                            a.className += ' active';
                        }
                    }
                    else
                    {
                        a.className = a.className.replace(/\s?active/, '');
                    }
                }
            }
        }
    }
}