﻿

function RenderContentsChord(divContainerId, bUseSmallSizing)
{
    for (i=0; i<document.images.length; i++)
    { 
        // if the image has a FretNumber we can assume it is on a chordbox
        if (document.images[i].getAttribute('Fret'))
        {
            if (document.images[i].getAttribute('OwnerPrefix') == divContainerId.substr(0, divContainerId.indexOf('divChord')))
            {
                if (document.images[i].getAttribute('Number') == 'X' || document.images[i].getAttribute('Number') == 'O')
                {
                    //SetPositionNumber(document.images[i], bUseSmallSizing);
                    new ChordBoxContainer(document.images[i]).SetPositionNumber(document.images[i], bUseSmallSizing);
                }
                else if (document.images[i].id.indexOf('Number_String') != -1)
                {
                    //SetPositionNumber(document.images[i], bUseSmallSizing);
                    new ChordBoxContainer(document.images[i]).SetPositionNumber(document.images[i], bUseSmallSizing);
                }
                else if (document.images[i].id.indexOf('Dot_String') != -1)
                {
                    //SetPositionDot(document.images[i], bUseSmallSizing); // true to use the small background image scaling
                    new ChordBoxContainer(document.images[i]).SetPositionDot(document.images[i], bUseSmallSizing);
                }
            }
        }      
    }
}



function ChordNameBlur(txtBox, chordBoxClientId, hiddenFieldClientId)
{
    if (txtBox.value.indexOf(':') != -1 || txtBox.value.indexOf('|') != -1 || txtBox.value.indexOf('-') != -1)
    {
        alert("The chord name cannot contain the characters '|', ':' or '-'");
    }

    var owner = chordBoxClientId.substr(chordBoxClientId.indexOf('divChord'));

    var hiddenField = document.getElementById(hiddenFieldClientId);
    var hiddenValue = hiddenField.value;

    if (hiddenValue == '')
    {
        hiddenValue = ':::';
    }

    // we need to get the array of items, add in the new name then put the arrays back as a string
    var arrItems = hiddenValue.split(':');

    arrItems[0] = txtBox.value;         

    hiddenField.value = ArrayToString(arrItems, ':');
}



// removes an array of values from a 2d array of the form key-value1, key-value2
function RemoveValuesFrom2dArray(arrArray, key, arrValues)
{
    var indexesToRemove = new Array();
    
    for(i=0; i<arrArray.length; i++)
    {
        var arrInnerArray = arrArray[i].split('-');
        
        for (j=0; j<arrValues.length; j++)
        {
            if (arrInnerArray[0] == key && arrInnerArray[1] == arrValues[j])
                indexesToRemove.push(i);
        }
    }
    
    if (indexesToRemove.length > 0)
    {
        // we want to remove specific items from the array:
        var arrNewArray = new Array();
        
        // foreach item in the original array
        for (i=0; i<arrArray.length; i++)
        {
            var add = true;
            
            // if the current index is in the indexes to remove list we want to continue and not add
            for(j=0; j<indexesToRemove.length; j++)
            {
                if (i == indexesToRemove[j])
                {
                    add = false;
                    break;
                }
            }
            
            if (add)
                arrNewArray.push(arrArray[i]);
        }
        
        return arrNewArray;
    }
    
    // we've had no indexes to remove so return the original array
    return arrArray;
}
