﻿// Creates an event listener for the 'window' object that executes the 'resizeOverlay' function
// when the 'onload' event is fired.
addEvent(window, 'load', loadFormFields, false);

// Creates an event listener by recieving the object to which the lister should be applied,
// the event for which to listen, the function to execute when the event is fired, and the 
// state at which to fire the function.
function addEvent(elm, evType, fn, useCapture) 
{ 
    if (elm.addEventListener) 
    { 
        elm.addEventListener(evType, fn, useCapture); 
        return true; 
    } 
    else if (elm.attachEvent) 
    { 
        var r = elm.attachEvent('on' + evType, fn); 
        return r; 
    }
    else 
    { 
        elm['on' + evType] = fn; 
    }
}

/***
* Load form fields from query string parameters.
***/
function loadFormFields()
{
    var query = window.location.search.substring(1);
    var parms = query.split('&');
    for (var i = 0; i < parms.length; i++)
    {
        var pos = parms[i].indexOf('=');
        if (pos > 0)
        {
            var _key = parms[i].substring(0, pos);
            var _val = parms[i].substring(pos + 1);
            var _element = document.getElementById(_key);
	    var _text = unescape(_val);
	    if(_element.options == null)
            {
                 _element.value = _text;
            }
            else            
            {
		for(var _i=0;_i < _element.options.length; _i++)
		{
                    _element.options[_i].selected = false;
                    if(_element.options[_i].value == _val)
                    {
                        _element.options[_i].selected = true;
	            }
		}
	    }
        }
    }
}
