function getByID( id, doc )
{
	if ( doc == null ) doc = 'document';

	if (eval(doc).getElementById) {
		// Newer browsers
		return eval(doc).getElementById(id);
	}
	else if (eval(doc).all) {
		// IE4
		return eval(doc).all[id];
	}
	else if (eval(doc).layers) {
		// NS4
		return eval(doc).layers[id];
	}
	else {
		alert( 'We couldn\'t recognize your browser.  Please use a different one or upgrade to the newest version.' );
		window.close();
	}
}

function getFormInputsByName (form, inputName) {
  var inputs = new Array();
  for (var i = 0; i < form.length; i++) {
    if (form.elements[i].name == inputName) {
      inputs.push(form.elements[i]);
    }
  }
  return inputs;
}

function changeColor( id, color ) {
	var tag = getByID( id );
	if (tag.style)
		tag.style.backgroundColor = color;
	else if (tag.document && tag.document.bgColor)
		tag.document.bgColor = color;
}
 
var changedColor = '#ffddee';
var unchangedColor = 'white';

function markChanged( id ) {
    changeColor('row.'+id, changedColor);
} 

function markUnchanged( id ) {
    changeColor('row.'+id, unchangedColor);
} 

// onSubmit handlers for double-click protection
 
function refuseDoubleClick()
{
        alert('It looks like this form has already been submitted.  In order to prevent duplicate or broken data, we are refusing this submission.  You may re-load this page to re-submit');
        return false;
}
 
function testDoubleClick()
{
        return confirm('It looks like this form has already been submitted. If you re-submit it it could result in duplicate, or even broken, data.  Do you wish to proceed?');
}

var doubleClickProtect = false;

// If submitted once, use one of the above functions.
function checkDoubleClick( force )
{
	if ( doubleClickProtect ) {
	        if ( force ) {
        	        return refuseDoubleClick();
	        } else {
        	        return testDoubleClick();
	        }
	} else {
		doubleClickProtect = true;
		return true;
	}
}

// Useful for creating a pop-up notification of some sort

var popUpWin
function Open_PopUp(page,x,y,scroll){
        scroll = (isNaN(scroll)) ? 0:scroll;
	x = (isNaN(x))? 480:x;
	y = (isNaN(y))? 288:y;
    if(popUpWin!=true){popUpWin = window.open(page,'w2','width=' + x + ',height=' + y + ',toolbar=0,menubar=0,resizable=no,status=0,scrollbars=' + scroll + ',left=100,top=50');}
	setTimeout('popUpWin.focus()',200);
}

// Used to show or hide
function changeDiv(the_div,the_change) {
  var the_style = getStyleObject(the_div);
  if (the_style != false)
  {
    the_style.display = the_change;
  }
}

function getStyleObject(objectId) {
  if (document.getElementById && document.getElementById(objectId)) {
    return document.getElementById(objectId).style;
  } else if (document.all && document.all(objectId)) {
    return document.all(objectId).style;
  } else {
    return false;
  }
}
// Form validation (by paulm@oho.com)

function test_item_name (item_name, thisform)
{
    return (test_item (thisform[item_name]));

}

function set_id (item_name, id, thisform)
{
    if (!thisform[item_name].id) {
	thisform[item_name].id = id;
    }

}

function test_item (item)
{
var i;
/* alert (item.type + "  " + item.name); */
    
if (item.type == "text" || item.type == "textarea" || item.type=="password") {
    if (item.value != "") {
	return true;
    } else {
	return false;
    }
} else if (item.type == "checkbox" || item.type == "radio") {
    return item.checked;
} else if (item.type == "select-one") {
    for (i = 0; i < item.length; i++) 
    {
	if (item[i].selected && item[i].value != "") {
		return true;
	}
    }
    return false;
} else {
    for (i = 0; i < item.length; i++) 
    {
	if (test_item(item[i])) {
		return true;
	}
    }
}
}
function test_items (thisform)
{
    var i;	
    var emptyitems = "";
    for (i=0; i < thisform.length; i++) {
	
//	thisform[i].id = "TEST";
	if (thisform[i].id != "" && thisform[i].id.substring(thisform[i].id.length - 2) == "rq" ) {
	    if (!thisform[i].id) {
		var j;
		var item = thisform[i];
		for (j=0; i < item.length; j++) 
		{		
		    if (item[j].id != "") 
		    {
		        if (test_item_name (item.name, thisform))
			{

			} else {
			    if (thisform[i].id) {
				emptyitems += thisform[i].id;
			    } else {
			 	emptyitems += thisform[i].name;
			    }
			    emptyitems += "\n";
		
			}
		    }
		}
	     } else {
		if (test_item_name (thisform[i].name, thisform)) {

		} else {
		    if (thisform[i].id) {
			changeColor (thisform[i].id, changedColor);
			thisform[i].onfocus=function onfocus(event) {
			    changeColor(this.id,unchangedColor);
			};
			emptyitems += thisform[i].id.substring(0, thisform[i].id.length - 2);
		    } else {
			emptyitems += thisform[i].name;
		    }
		    emptyitems += "\n";
		}
	    }
	}
    }
    if (emptyitems != "") {
	alert ("You need to enter information for the following items: \n\n" + emptyitems);
	return false;
    } else {
	return true;
    }
}

function redirectFromSelect(id) {
  var sel = getByID(id);
  var newURL = sel.options[sel.selectedIndex].value;
  if (newURL) location.href = newURL;
}


// Toggle an Objects visibilityfunction toggle2(objid) {  var obj = getByID(objid);  if (obj.style.display == "none")    obj.style.display = '';  else    obj.style.display = "none";}
                                                                                                                                                           
