var FadeInterval = 100;
var StartFadeAt = 7;
var FadeSteps = new Array();
	FadeSteps[1] = "ff";
	FadeSteps[2] = "ee";
	FadeSteps[3] = "dd";
	FadeSteps[4] = "cc";
	FadeSteps[5] = "bb";
	FadeSteps[6] = "aa";
	FadeSteps[7] = "99";
var W3CDOM = (document.createElement && document.getElementsByTagName);
addEvent(window, 'load', initFades);

function addEvent(obj, eventType,fn, useCapture)
{
	if (obj.addEventListener) {
		obj.addEventListener(eventType, fn, useCapture);
		return true;
	} else {
		if (obj.attachEvent) {
			var r = obj.attachEvent("on"+eventType, fn);
			return r;
		}
	}
}

// The function that initializes the fade and hooks the script into the page
function initFades()
{
	if (!W3CDOM) return;
    
// This section highlights targets from the URL (browser address bar)
    
    // Get the URL
    var currentURL = unescape(window.location);
    // If there is a '#' in the URL
    if (currentURL.indexOf('#')>-1)
        // Highlight the target
        DoFade(StartFadeAt, currentURL.substring(currentURL.indexOf('#')+1,currentURL.length));
    

// This section searches the page body for anchors and adds onclick events so that their targets get highlighted
    
    // Get the list of all anchors in the body
    var anchors = document.body.getElementsByTagName('a');

    // For each of those anchors
    for (var i=0;i<anchors.length;i++)

        // If there is a '#' in the anchors href
        if (anchors[i].href.indexOf('#')>-1)

            // Add an onclick event that calls the highlight function for the target
            anchors[i].onclick = function(){Highlight(this.href);return true};

// FADE ID=FADE
 var fader = document.getElementById('fade');
 if (fader) 
 	{	
		DoFade(StartFadeAt,'fade');
		document.getElementById('error').focus();
	}

}

// This function is just a small wrapper to use for the oncick events of the anchors
function Highlight(target) {

	// Get the target ID from the string that was passed to the function
    var targetId = target.substring(target.indexOf('#')+1,target.length);
    DoFade(StartFadeAt, targetId);
}

// This is the recursive function call that actually performs the fade
function DoFade(colorId, targetId) {
    if (colorId >= 1) {
		document.getElementById(targetId).style.backgroundColor = "#ffff" + FadeSteps[colorId];
		
        // If it's the last color, set it to transparent
        if (colorId==1) {
            document.getElementById(targetId).style.backgroundColor = "#fff";
			
		}
        colorId--;
		
        // Wait a little bit and fade another shade
        setTimeout("DoFade("+colorId+",'"+targetId+"')", FadeInterval);
	}
	// If an input, 
	if (document.getElementById(targetId).nodeName=="INPUT" || document.getElementById(targetId).nodeName=="SELECT") {
		document.getElementById(targetId).focus();
	}
}
