﻿/// <reference name="ErrorIcons.js"/>

function findDictionaryControl(id)
{
    if (typeof(errElem) != 'undefined')
    {
        for (i=0;i<errElem.length;i++)
        {
            if ((errElem[i] == id) || (errElem[i].indexOf(id) != -1))
            {
                var c = $(strPHID + errElem[i]);
                if (c) return c; // return array of controls instead...?
            }
        }
    }
    return;
}

function findAttributeControl(AttName)
{

    var att;
    if (AttName.indexOf('^') != -1)
    {
        att = AttName.split('^');
    }
    else
    {
        att = [AttName];
    }
    if (typeof(ControlID) != 'undefined')
    {
        for (i=0;i<ControlID.length;i++)
        {
            var c = $get(strPHID + ControlID[i]);
            if (c)
            {
                for (j=0;j<att.length;j++)
                {
                    if (c.getAttribute('AppDataName') == att[j])
                    {
                        return c; // return array of controls instead...?
                    }
                }
            }
        }
    }
    return;
}

function dispErrIcon()
{
	var prm = Sys.WebForms.PageRequestManager.getInstance();
    if (typeof(errIcon) != 'undefined' && errIcon.length > 0)
    {
        for (iei=0;iei<errIcon.length;iei++)
        {
            var copyE = document.createElement('img');
            copyE.id = 'imgErrIcon' + iei.toString();
            copyE.src = errIcon[iei];
            copyE.style['height'] = '18px';
            copyE.style['width'] = '18px';
            copyE.style.styleFloat = 'left';
            copyE.alt = errMsg[iei].replace('&#10;', '\n').replace('&#189;', ' 1/2').replace('&quot;', '\"');
            copyE.title = copyE.alt;
            if (errElem[iei] != "")
            {
                var anchor = findDictionaryControl(errElem[iei]);
                if (anchor && !findErrIcon(anchor, copyE.id))
                {
                    copyE.style['position'] = 'relative';
                    copyE.style['top'] = '-38px';
                    copyE.style['display'] = 'inline';
                    if (anchor.parentNode.childNodes[0].nodeName != 'IMG')
                    {
                        anchor.parentNode.parentNode.appendChild(copyE);
                    }
                }
            }
            else
            {
                anchor = findAttributeControl(errAtt[iei]);
                if (anchor && !findErrIcon(anchor, copyE.id))
                {
                    copyE.style['position'] = 'relative';
                    copyE.style['display'] = 'inline';
                    if (anchor.parentNode.childNodes[0].nodeName != 'IMG')
                    {
                        anchor.parentNode.appendChild(copyE);
                    }
                }
            }
        }
        errIcon = [];
        errElem = [];
        errMsg = [];
        errAtt = [];
    }
}

function findErrIcon(anchor, id)
{
    var retVar = false;
    for (fei = 0; fei < anchor.parentNode.parentNode.childNodes.length; fei++)
    {
        retVar = (retVar || anchor.parentNode.parentNode.childNodes[fei].id == id);
    }
    for (fei = 0; fei < anchor.parentNode.childNodes.length; fei++)
    {
        retVar = (retVar || anchor.parentNode.childNodes[fei].id == id);
    }
    return retVar;
}

if(typeof(Sys) != 'undefined') Sys.Application.notifyScriptLoaded();