var NewCount = 0;
var bInit = true;

function SetCategoryId(count,catID)
{
	if (count == 1) {
		document.forms[0].IntCat1.value=catID;
	}
	if (count == 2) {
		document.forms[0].IntCat2.value=catID;
	}
	if (count == 3) {
		document.forms[0].IntCat3.value=catID;
	}
}

function RemoveCategoryId(count)
{
	if (count == 1) {
		document.forms[0].IntCat1.value="";
	}
	if (count == 2) {
		document.forms[0].IntCat2.value="";
	}
	if (count == 3) {
		document.forms[0].IntCat3.value="";
	}
}

function KeepCount(obj)
{
	
	if (obj.checked)
	{
		if (NewCount > 2){
			alert("You may only select up to 3 topics!")
			return false;
		}
		NewCount++;
		SetCategoryId(NewCount,obj.name)
	}
	else
	{
		NewCount--;
		RemoveCategoryId(NewCount+1)
	}
}

function submitForm()
{
	if (NewCount == 0)
	{
		alert("You must select at least one topic!");
		return false;
	}
	else
	{
		document.forms[0].submit();
	}
}

// ======================================================================================
// LEGACY ASP ROW HIGHTLIGHTING FUNCTIONS
// The following several functions are used for pages like customer_list.asp (invite customers).
// When item is selected, the code will highlight the row this item is in. The code will also
// select/unselect all the checkboxes when top checkbox is clicked.

// Assumptions:
// 1. Code will not highlight rows in Netscape 4, but will select/unselect checkboxes with the 
//    click of the top checkbox.
// 2. The name of the top checkbox (the one that selects all other checkboxes) has to be
//    "chkAll" (no quotes).

function setAllChecked()
{
	var bChecked = document.forms[0].chkAll.checked;
	var i;

	for (i=0;i<document.forms[0].elements.length;i++) {
		e = document.forms[0].elements[i];
		if ((e.type=="checkbox")&&(e.name!="chkAll")) {
			e.checked = bChecked;
		}
	}
	setAllRowStatus();
}

function setAllRowStatus()
{
	var i;
	var bAllChecked = true;

	for (i=0;i<document.forms[0].elements.length;i++) {
		e = document.forms[0].elements[i];
		if ((e.type=="checkbox")&&(e.name!="chkAll")) {
			if (!(e.checked)) {
				bAllChecked = false;
			}
			setRowHilite(e);
		}
	}
	document.forms[0].chkAll.checked = bAllChecked;
}

function setRowHilite(obj)
{
	//will only run for ie 5+ and Mozilla
	if (!(document.layers)) {
		var bChecked;

		if ((obj.type == "checkbox") && (obj.name != 'chkAll')) {
			bChecked = obj.checked;
			while (obj.tagName!="TR") {
				obj=obj.parentNode;
			}
		}

			if (bChecked) {
				obj.className = 'univTableRowHighlightOn';
			}
			else {
				obj.className = 'univTableRowHighlightOff';
			}
	}
}

// ======================================================================================
// .NET ROW HIGHTLIGHTING FUNCTIONS
// alert("obj.type: " + obj.type + " , obj.name: " + obj.name + " , obj.tagName =" + obj.tagName);
// CQ:65047 - added check for "NotChild" ID for checkboxes you do not want to include in the master/child group. 				
function setAllCheckboxes(bHiliteRow, clientID)
{
	checkCount = 0;
	var bChecked = document.getElementById(clientID).checked;
	var i;
	for (i=0;i<document.forms[0].elements.length;i++) {
		e = document.forms[0].elements[i];
		if ((e.type=="checkbox")&&(e.id!=clientID)&&(e.id.indexOf("NotChild")==-1))
		{
			e.checked = bChecked;
			if (bChecked) {
				checkCount++;
			}
		}
		if (bHiliteRow&&(e.id.indexOf("NotChild")==-1)) {
			setRowHilight(e, clientID);
		}
	}
}

function HilightCheckedRows(clientID)
{	
	var i;
	for (i=0;i<document.forms[0].elements.length;i++) {
		e = document.forms[0].elements[i];
		if ((e.type=="checkbox")&&(e.id!=clientID)&&(e.id.indexOf("NotChild")==-1))
		{
			if (e.checked) {
				setRowHilight(e, clientID);
			}
		}
	}
}


function setAllRowStatus2(bHiliteRow, clientID)
{
	var i;
	var bAllChecked = true;
	checkCount = 0;
	for (i=0;i<document.forms[0].elements.length;i++) {
		e = document.forms[0].elements[i];
		if ((e.type=="checkbox")&&(e.id!=clientID))
		{
			if (!(e.checked)) {
				bAllChecked = false;
			}
			else {
				checkCount++;
			}
		}
		if (bHiliteRow&&(e.id.indexOf("NotChild")==-1)) {
			setRowHilight(e, clientID);
		}
	}
	document.getElementById(clientID).checked = bAllChecked;
}

function setRowHilight(obj, clientID)
{
	//will only run for ie 5+ and Mozilla
	if (!(document.layers))
	{
		var bChecked;

		if ((obj.type == "checkbox") && (obj.id != clientID))
		{
			bChecked = obj.checked;
			while (obj.tagName.toUpperCase()!="TR")
			{
				obj=obj.parentNode;
			}
			if (bChecked)
			{
				switch (obj.className)
				{
					case 'alternatingItem':
					case 'alternatingItemHighlightOn':
					case 'alternatingItemHighlightOff':
						obj.className = 'alternatingItemHighlightOn';
						break;
					default:
						obj.className = 'highlightOn';
						break;
				}
			}
			else
			{
				switch (obj.className)
				{
					case 'alternatingItem':
					case 'alternatingItemHighlightOn':
					case 'alternatingItemHighlightOff':
						obj.className = 'alternatingItemHighlightOff';
						break;
					default:
						obj.className = 'highlightOff';
						break;
				}
			}
		}
	}
}


// ======================================================================================

// Disables form button and optionally replaces the text inside the button.
function DisableButton(button, text)
{
	button.className = 'button buttonDisabled';
	button.disabled = true;
	if (text.length > 0)
	{
		//button.style.width = "";
		button.value = text;
	}
}

// Enables form button and optionally replaces the text inside the button.
function EnableButton(button, text)
{
	button.className = 'button';
	button.disabled = false;
	if (text.length > 0)
		button.value = text;
}

// This is a legacy function which should no longer be used.  Doesn't appear to be in use,
// but calling newer function just in case.
function disableSubmitButton(obj, text)
{
	DisableButton(obj, text);
}


/* Checks whether a string is numeric, allowing for negative numbers and decimals
pattern: ^-{0,1}\d*\.{0,1}\d+$
	^ == beginning of line
	-{0,1} == 0 or 1 minus signs 
	\d* == 0 or more digits
	\.{0,1} == 0 or 1 decimal points
	\d == 1 or more digits
	$ == end of line  
*/
function isStringNumeric(string)
{
	var regularExpression = /^-{0,1}\d*\.{0,1}\d+$/;
	return regularExpression.test(string)
}

// highlights the text inside a textbox or textarea
function HighlightTextBox(textBoxId)
{
	var textBox = document.getElementById(textBoxId);
	textBox.focus();
	textBox.select();
}

// determines if enter button has been clicked.
// used for some form submission stuff to disable
// form submission when enter is clicked.
function isEnterClick(event)
{
	var elem = (event.srcElement) ? event.srcElement : event.target;
	
	try
	{
		if (!(elem.tagName.toLowerCase() == 'input' || 
				elem.tagName.toLowerCase() == 'select' || 
				elem.tagName.toLowerCase() == 'option' || 
				elem.tagName.toLowerCase() == 'textarea'))
		{
			return false;
		}
		else
		{
			if (elem.attributes.getNamedItem('type') != null && 
				(elem.attributes.getNamedItem('type').value.toLowerCase() == 'submit' ||
					elem.attributes.getNamedItem('type').value.toLowerCase() == 'image' ||
					elem.attributes.getNamedItem('type').value.toLowerCase() == 'button'))
				 {
					return false;
				 }
		}
	}
	catch(e)
	{
		return false;
	}
	
	var keypress;
	if (event.keyCode)
		keypress = event.keyCode;
	else 
		keypress = event.which;

	return (keypress == 13);
}

function cancelSubmit(event)
{
	var elem = (event.srcElement) ? event.srcElement : event.target;

	if ((elem.tagName.toLowerCase() == 'input' || 
			elem.tagName.toLowerCase() == 'select' || 
			elem.tagName.toLowerCase() == 'option' || 
			elem.tagName.toLowerCase() == 'textarea'))
	{
		return false;
	}
		
	return true;
}
