if (/msie/i.test (navigator.userAgent)) //only override IE
{
	document.nativeGetElementById = document.getElementById;
	document.getElementById = function(id)
	{
		var elem = document.nativeGetElementById(id);
		if(elem)
		{
			//make sure that it is a valid match on id
			if(elem.id == id)
			{
				return elem;
			}
			else
			{
				//otherwise find the correct element
				for(var i=1;i<document.all[id].length;i++)
				{
					if(document.all[id][i].id == id)
					{
						return document.all[id][i];
					}
				}
			}
		}
		return null;
	};
}



function FormHelper() {
}

FormHelper.prototype.createForm = function (formAction, formName){
  var formMethod = "post";
  if (document.getElementById) {
    var form = document.createElement('form');
      if (document.all) { // what follows should work with NN6 but doesn't in M14
        form.method = formMethod;
        form.name = formName;
        form.action = formAction;
        form.target = '_top';
      }
      else if (document.getElementById) { // so here is the NN6 workaround
        form.setAttribute('method', formMethod);
        form.setAttribute('name', formName);
        form.setAttribute('action', formAction);
        form.target = '_top';
      }
    document.body.appendChild(form);
  }
  return form;
}

// This function adds input field to the given form of given type 
// with the given name and value.
FormHelper.prototype.addField = function (form, fieldType, fieldName, fieldValue) {
  if (document.getElementById) {
    var input = document.createElement('input');
      if (document.all) { // what follows should work with NN6 but doesn't in M14
        input.type = fieldType;
        input.name = fieldName;
        input.value = fieldValue;
      }
      else if (document.getElementById) { // so here is the NN6 workaround
        input.setAttribute('type', fieldType);
        input.setAttribute('name', fieldName);
        input.setAttribute('value', fieldValue);
      }
    form.appendChild(input);
  }
}

FormHelper.prototype.getElementValue = function (name,form)
{
	var formObject = document.forms[form];
	var els = formObject.elements;
	return this.getValue(els[name]);
}

FormHelper.prototype.setElementValue = function (name, value, form)
{
	var formObject = document.forms[form];
	var els = formObject.elements;
	this.setValue(els[name],value);
}





FormHelper.prototype.setValue = function (obj, value)
{
	if (obj == null) {
		return;
	}
	
	if ((typeof(obj)!='object')) {
		return;
	}
	
	if (this.isEmpty(value)) {
		return;
	}
	
	var type = 'undefined';
	if (obj.length > 0) {
		for (i = 0; i < obj.length; i++) {
			if (obj[i]) {
				type = obj[i].type;
			}
		}
	}
	else {
		type = obj.type;
	}

	switch(type)
	{
		case 'undefined': 
			return;
		break;
		case 'radio': 
			for(var x=0; x < obj.length; x++) {
				if (obj[x].value == value) {
					obj[x].checked = true;
				}
			}
			break;
		case 'select-one': 
			obj.selectedIndex = value; 
			break;
		case 'checkbox' :
			values = value.split(',');
			for(var i=0; i < values.length; i++) {
				value = values[i];
				for(var x = 0; x < obj.length; x++) {
					if (obj[x].value == value) {
						obj[x].checked = true;
					}
				}
			}
			break;
		case 'select-multiple':
			for(var x=0; x < obj.length; x++) 
				obj[x].selected = value[x];
			break;

		default:
		

		
			obj.value = value; 
		break;
	}
}

FormHelper.prototype.getValue = function (obj)
{
	if ((typeof(obj)!='object')) {
		return false;
	}
	var value = '';
	var type = '';
	if (obj.length > 0) {
		for (i = 0; i < obj.length; i++) {
			if (obj[i]) {
				type = obj[i].type;
			}
		}
	}
	else {
		type = obj.type;
	}

	switch (type) {
		case "select-one" :
			return (obj.options[obj.selectedIndex].value);
		case "select-multiple" :
			for (i = 0; i < obj.length; i++) {
				if (obj.options[i].selected) {
					return obj.options[i].value;
				}
			}
			return value;
		case "checkbox" :
			for (i = 0; i < obj.length; i++) {
				if (obj[i].checked) {
					return  obj[i].value;
				}
			}
			if (obj.checked) {
				return obj.value;
			}
		case "radio" :
			for (i = 0; i < obj.length; i++) {
				if (obj[i].checked) {
					return obj[i].value;
				}
			}
			return "";
		default :
			return (obj.value);
	}
}


// Check whether string s is empty.
FormHelper.prototype.isEmpty = function (s)
{   
	return ((s == null) || (s.length == 0))
}


var _formHelper = new FormHelper;













