
function show_field(div_name, input_field_name){
	document.getElementById(div_name).style.display = 'inline';
	document.forms(0)(input_field_name).focus();
}

function hide_field(div_name, input_field_name){
	document.getElementById(div_name).style.display = 'none';
//	document.forms(0)(input_field_name).focus();
}

function CountChars(strSourceObject,strCounterObject,strText,intMaxCharacters) {
	var objSource = getObject(strSourceObject);
	var objCounter = getObject(strCounterObject);
	var NumCharsLeft = intMaxCharacters - objSource.value.length;

	if(NumCharsLeft <= 0) {
		NumCharsLeft=0;
		objSource.value=objSource.value.substr(0,intMaxCharacters);
	}
	objCounter.innerHTML = strText.replace("{CHAR}",NumCharsLeft);
}

function emailContactInformation()
{ 
	
	submitFlag = 1;
	if(submitFlag == 1){
		document.forms(0).submit();
	}
}

function dosubmit(page_name, submit_type)
{
	if(document.forms['root_form'].global_error_msg.value.length > 0)
	{
		error_msg_value = document.forms['root_form'].global_error_msg.value;
		error_msg_value = fn_replace(error_msg_value, '\n', '\n<br>');
		display_error_message(error_msg_value);
//		alert(document.forms['root_form'].global_error_msg.value);
	}
	else
	{
		//JMH 20050531- Changing form submittal method to allow Firefox to work.
		//document.forms['root_form'].submit_type.value = submit_type;
		document.forms['root_form'].page_name.value = page_name;
		document.forms['root_form'].submit_type.value = submit_type;
		document.forms['root_form'].submit();
	}
	document.forms['root_form'].global_error_msg.value = '';
}

function getObject(obj) {
	var theObj;
	if(document.all) {
		if(typeof obj=="string") {
			return document.all(obj);
		} else {
			return obj.style;
		}
	}
	if(document.getElementById) {
		if(typeof obj=="string") {
			return document.getElementById(obj);
		} else {
			return obj.style;
		}
	}
	return null;
}
function display_error_message(error_message)
{
		document.getElementById("error_msg_area").style.display = 'inline';
		document.getElementById("error_msg_area").innerHTML = '<b>PLEASE NOTE:</b><br>' + error_message + '<br>';
}

//To reference an iframe's href location:
//window.frames.i.location.href = 

function show_details_iframe(line_num, override)
{
	i = line_num;
	
	if (override != 'hide')
	{
		if (window.frames.rfp_generator_iframe_tool_iframe.document.getElementById(i+"_show").value == 'false' || override == 'show')
		{
			
			window.frames.rfp_generator_iframe_tool_iframe.document.getElementById("detail"+i).style.display = 'inline';
			window.frames.rfp_generator_iframe_tool_iframe.document.getElementById("plus"+i).src = 'images/bminus.gif';
			window.frames.rfp_generator_iframe_tool_iframe.document.getElementById(i+"_show").value = 'true';
		}
		else
		{
			window.frames.rfp_generator_iframe_tool_iframe.document.getElementById("detail"+i).style.display = 'none';
			window.frames.rfp_generator_iframe_tool_iframe.document.getElementById("plus"+i).src = 'images/bplus.gif';
			window.frames.rfp_generator_iframe_tool_iframe.document.getElementById(i+"_show").value = 'false';
		}
	}
	else
	{
		window.frames.rfp_generator_iframe_tool_iframe.document.getElementById("detail"+i).style.display = 'none';
		window.frames.rfp_generator_iframe_tool_iframe.document.getElementById("plus"+i).src = 'images/bplus.gif';
		window.frames.rfp_generator_iframe_tool_iframe.document.getElementById(i+"_show").value = 'false';
	}
}

function show_all_details_iframe(show_or_hide)
{
	for (i = 1; i <= (window.frames.rfp_generator_iframe_tool_iframe.document.forms['root_form'].rfp_rowcount.value); i++) 
	{	
		if (window.frames.rfp_generator_iframe_tool_iframe.document.getElementById(i+"_div_exists").value == 'true')
		{
			if (show_or_hide == 'show')
			{
				show_details_iframe(i, 'show');
			}
			else
			{
				show_details_iframe(i, 'hide');
			}
		}
	}
	if (show_or_hide == 'show')
	{
/*		
onclick="if(document.getElemen­tById && 
document.getElementById('cell4­3').childNodes[0].nodeType == 3) 
{document.getElementById('cell­43').childNodes[0].nodeValue = 'New 
words';};">Change cell 43</button> 
*/
		document.getElementById("show_button_cell").innerHTML = "<a href=javascript:show_all_details_iframe('hide')>HIDE ALL DETAILS</a>";
	}
	else
	{
		document.getElementById("show_button_cell").innerHTML = "<a href=javascript:show_all_details_iframe('show')>SHOW ALL DETAILS</a>";
	}
}

function iframe_update_parent(parent_input_name, new_value)
{
	//alert('going to update ' + parent_input_name + ' to equal ' + new_value);
	parent.document.getElementById(parent_input_name).value = new_value;
	
}

function iframe_update_parent_radio(parent_radio_id)
{
	parent.document.getElementById(parent_radio_id).checked = true;
}

function show_details(line_num, override)
{
	i = line_num;
	
	if (override != 'hide')
	{
		if (document.getElementById(i+"_show").value == 'false' || override == 'show')
		{
			document.getElementById("detail"+i).style.display = 'inline';
			document.getElementById("plus"+i).src = 'images/bminus.gif';
			document.getElementById(i+"_show").value = 'true';
		}
		else
		{
			document.getElementById("detail"+i).style.display = 'none';
			document.getElementById("plus"+i).src = 'images/bplus.gif';
			document.getElementById(i+"_show").value = 'false';
		}
	}
	else
	{
		document.getElementById("detail"+i).style.display = 'none';
		document.getElementById("plus"+i).src = 'images/bplus.gif';
		document.getElementById(i+"_show").value = 'false';
	}
}

function show_all_details(show_or_hide)
{
	for (i = 1; i <= (document.forms['root_form'].rfp_rowcount.value); i++) 
	{	
		
		if (document.getElementById(i+"_div_exists").value == 'true')
		{
			if (show_or_hide == 'show')
			{
				show_details(i, 'show');
			}
			else
			{
				show_details(i, 'hide');
			}
		}
	}
	
	if (show_or_hide == 'show')
	{
/*		
onclick="if(document.getElemen­tById && 
document.getElementById('cell4­3').childNodes[0].nodeType == 3) 
{document.getElementById('cell­43').childNodes[0].nodeValue = 'New 
words';};">Change cell 43</button> 
*/
		document.getElementById("show_button_cell").innerHTML = "<a href=javascript:show_all_details('hide')>HIDE ALL DETAILS</a>";
	}
	else
	{
		document.getElementById("show_button_cell").innerHTML = "<a href=javascript:show_all_details('show')>SHOW ALL DETAILS</a>";
	}
		
}

function scrollable_table_load() {
	if (document.getElementById && document.getElementsByTagName) {  
		var allTables = document.getElementsByTagName('table');
		if (!allTables) { return; }

		for (var i = 0; i < allTables.length; i++) {
			if (allTables[i].className.match(/[\w\s ]*scrollTable[\w\s ]*/)) {
				var trs = allTables[i].getElementsByTagName("tr");
				for (var j = 0; j < trs.length; j++) {
					removeClassName(trs[j], 'alternateRow');
					addCSSClass(trs[j], 'normalRow');
				}
				for (var k = 0; k < trs.length; k += 2) {
					removeClassName(trs[k], 'normalRow');
					addCSSClass(trs[k], 'alternateRow');
				}
			}
		}
	}
}

function open_window(URL, width, Height, window_name, hide_all_extras) 
{ 
	if(width == '' || width == undefined)
	{
		width = 500;
	}
	if(Height == '' || Height == undefined)
	{
		Height = 300;
	}
	if (window_name == '' || window_name == undefined)
	{
		window_name = 'open_window';
	}

	if (hide_all_extras == 'yes'){
		window_name = window.open(URL,window_name,'toolbar=no,status=no,directories=no,personalbar=no,menubar=no,addressbar=no,scrolling=no,resizable=no,width=' + width + ',height=' + Height + ',scrollbars=0, left=50, top=50, screenX=50, screenY=50');
	}else{
		window_name = window.open(URL,window_name,'toolbar=yes,status=yes,directories=yes,personalbar=yes,menubar=yes,addressbar=yes,scrolling=yes,resizable=yes,width=' + width + ',height=' + Height + ',scrollbars=2, left=50, top=50, screenX=50, screenY=50');
	}
	window_name.focus()
}

function check_text_exists(text_name, text_value)
{
	if(text_value.length == 0)
	{
		document.forms['root_form'].global_error_msg.value = document.forms['root_form'].global_error_msg.value + text_name + ' must be populated.<br>';
	}
}


function fn_replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);

    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;

}

function right_trim() { 
  return this.replace(/\s+$/gi, ""); 
}

function left_trim() { 
  return this.replace(/^\s*/gi, ""); 
} 

//sample call var_text.trim()
function trim() { 
  return this.rightTrim().leftTrim();
} 

String.prototype.right_trim = right_trim; 
String.prototype.left_trim = left_trim; 
String.prototype.trim = trim;

