
var comparison_ids = [];

function pts_rmm_expand_collapse(spantag)
{
	var bh_expcol = document.getElementById(spantag);

	if(bh_expcol.style.display == "none")
	{
		bh_expcol.style.display = "block";
	}
	else
	{
		bh_expcol.style.display = "none";
	}
}
function pts_rmm_jump_form(form)
{ 
	var newIndex = form.selector.selectedIndex; 
	window.location.assign(form.selector.options[newIndex].value); 
}
function pts_rmm_jump_to_page(k)
{
	this.location.href = "index.php?k=" + k;
}
function pts_rmm_hide_element(eid)
{
	if(document.getElementById(eid))
		document.getElementById(eid).style.display = "none";
}
function pts_rmm_show_element(eid)
{
	if(document.getElementById(eid))
		document.getElementById(eid).style.display = "block";
}
function formInputCheck(alert_array)
{
	if(alert_array.length == 0)
		return true;
	else
	{
		var message_box_text = "Before continuing, you must first fix the following fields:\n\n";
		for(var i = 0; i < alert_array.length; i++)
		{
			message_box_text += "- " + alert_array[i] + "\n";
		}
		alert(message_box_text);
		return false;
	}
}
function pts_rmm_object_checked(oid)
{
	if(document.getElementById(oid).checked)
		return true;
	return false;
}
function pts_rmm_set_list_item(select_id, set_to)
{
	if(document.getElementById(select_id).length < 1)
		return;

	for(i = 0; i < document.getElementById(select_id).length; i++)
	{
		if(document.getElementById(select_id).options[i].value == set_to)
			document.getElementById(select_id).selectedIndex = i;
	}
}
function pts_rmm_get_list_item(select_id)
{
	var item_value = document.getElementById(select_id).options[document.getElementById(select_id).selectedIndex].value;

	if(pts_rmm_is_int_string(item_value))
	{
		if(item_value[0] == "0" && item_value.length > 1)
			item_value = item_value.substring(1);

		item_value = parseInt(item_value);
	}

	return item_value;
}
function pts_rmm_is_int_string(str)
{
	for(var i = 0; i < str.length; i++)
	{
		var ch = str[i];

		if(ch != 0 && ch != 1 && ch != 2 && ch != 3 && ch != 4 && ch != 5 && ch != 6 && ch != 7 && ch != 8 && ch != 9)
			return false;
	}
	return true;
}

function pts_rmm_switch_add_type(select_obj, select_type)
{
	if(select_obj.value == "test" || select_type == "test")
	{
		pts_rmm_show_element("select_test");
		pts_rmm_hide_element("select_suite");
		document.getElementById("test_type").value = "TEST";
	}
	else
	{
		pts_rmm_hide_element("select_test");
		pts_rmm_show_element("select_suite");
		document.getElementById("test_type").value = "SUITE";
	}

	pts_rmm_hide_element("test_details");
}
function pts_rmm_add_a_test_init()
{
	pts_rmm_switch_add_type(this, "suite");
}
function pts_rmm_setup_test_details()
{
	document.getElementById("test_details").innerHTML = "";

	if(document.getElementById("test_type").value == "SUITE")
	{
		var test_target = pts_rmm_get_list_item("select_suite");
		customAjaxPost("suite_setup_details&u=" + test_target, "test_details");
	}
	else
	{
		var test_target = pts_rmm_get_list_item("select_test");
		customAjaxPost("test_setup_details&u=" + test_target, "test_details");
	}

	document.getElementById("to_test").value = test_target;

	pts_rmm_show_element("test_details");
}
function pts_rmm_update_selected_name(select_obj)
{
	var select_id = select_obj.id;
	var select_name = document.getElementById(select_id).options[document.getElementById(select_id).selectedIndex].innerHTML;

	document.getElementById(select_id + "_selected").value = document.getElementById(select_id + "_name").innerHTML + ": " + select_name;
}
function pts_rmm_result_comparison_check(comparison_id, tag_img_id)
{
	var img_check = document.getElementById(tag_img_id).src;
	img_check = img_check.substring((img_check.length - 7));

	if(img_check == "tag.png")
	{
		comparison_ids.push(comparison_id);
		document.getElementById(tag_img_id).src = "css/icons/tag_invert.png"
	}
	else
	{
		for(var i = 0; i < comparison_ids.length; i++)
		{
			if(comparison_ids[i] == comparison_id)
			{
				comparison_ids[i] = "";
			}
		}

		document.getElementById(tag_img_id).src = "css/icons/tag.png"
	}
}
function pts_rmm_result_comparison_go()
{
	var compare_string = "";

	for(var i = 0; i < comparison_ids.length; i++)
	{
		if(comparison_ids[i] != "")
		{
			compare_string += comparison_ids[i] + "__";
		}
	}

	compare_string = compare_string.substring(0, compare_string.length - 2);

	if(compare_string != "")
	{
		pts_rmm_jump_to_page("test_results&i=" + compare_string);
	}
}
function pts_rmm_schedule_days_toggle(check_element)
{
	if(check_element.name == "system_all")
	{
		pts_rmm_expand_collapse("hide_system_checkboxes");
	}
}
function pts_rmm_validate_schedule()
{
	if(document.getElementById("schedule_title").value == "")
	{
		alert("The schedule's title cannot be left empty.");
		return false;
	}
	if(document.getElementById("schedule_description").value == "")
	{
		alert("The schedule's description cannot be left empty.");
		return false;
	}

	return true;
}
function pts_rmm_user_register_validate()
{
	if(document.getElementById("register_user").value == "")
	{
		alert("The user-name cannot be left empty.");
		return false;
	}
	if(document.getElementById("register_email").value.length < 4)
	{
		alert("An e-mail address must be supplied.");
		return false;
	}
	if(document.getElementById("register_first").value == "")
	{
		alert("A first name must be supplied.");
		return false;
	}
	if(document.getElementById("register_last").value == "")
	{
		alert("A last name must be supplied.");
		return false;
	}

	return true;
}
