// Author: Frode T. Lie
// (place Revisions/updates/credits here)

// 0.9  20020809 first atempt by ftl



// This script and many more are available free online at -->
// The JavaScript Source!! http://javascript.internet.com -->


// getParams() generates an Array with all parameters given on the command line as follows
// myfile.htm#param1=value1&param1=value2 or 
// myfile.htm?param1=value1&param1=value2

function getParams() {
	var idx = document.location.href.indexOf('?');
	if (idx == -1) {
		var idx = document.location.href.indexOf('#');
	}
	var params = new Array();

	if (idx != -1) {
		
		var pairs = document.location.href.substring(idx+1, document.location.href.length).split('&');
		for (var i=0; i<pairs.length; i++) {
			nameVal = pairs[i].split('=');
			params[nameVal[0]] = nameVal[1];
			params[nameVal[0]].name = nameVal[1];
		   }
	} else {
		params[0] = "";
		}
	return params;
	}



// feedForm goes trough all controls on form theForm (0 will use the first Form) in frame theFrame, 
// and sees if the control name is defined as a parameter 
// on the command line. if so, insert the value of the prameter into the control
// e.g. myform.htm?username=MrX  wil insert MrX in the input box (control) named username.
// The parameters must first be fetched by getParams.

var params = getParams();

function feedForm(theFrame, theForm) {
	if (typeof(theForm)!= "undefined") {
		theForm = 0;
		}
		
	var n = 0;
	if (frames.length > 0) {
		if (frames[theFrame].document.forms.length > 0) {
			n =  frames[theFrame].document.forms[theForm].elements.length;
			}
		}
	for (var i=0; i<n ; i++) {
		var x = params[frames[theFrame].document.forms[theForm].elements[i].getAttribute('name')];
		if (typeof(x )!= "undefined") {
			frames[theFrame].document.forms[theForm].elements[i].value = params[frames['fraMain'].document.forms[theForm].elements[i].name];
			}
		}

	if (typeof(params["doSubmit"] )!= "undefined") {
		if (params["doSubmit"]=="yes") {
			frames[theFrame].document.forms[theForm].submit();
			}
		}
	}

