
var whitespace = " \t\n\r";

function isEmpty(s)
{
	return ((s == null) || (s.length == 0));
}

function isWhitespace (s)
{
	var i;
	
	if (isEmpty(s)) return true;
	
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}
	return true;
}

function Strip(strValue)
{
	while(strValue.charAt(0) == " ")
	{
		strValue = strValue.substr(1);
	}
	
	var iLength = strValue.length;
	
	while(strValue.charAt(iLength - 1) == " ")
	{
		strValue = strValue.substr(0, iLength - 1);
		
		iLength = strValue.length;
	}
	
	return strValue;
}

function ForceEntry(val, str)
{
	var strInput = new String(val.value);
	
	if (isWhitespace(strInput))
	{
		val.focus();
		alert(str);
		return false;
	}
	else
		return true;
}

function AddPhrase(objField, strPhrase)
{
	return AddPhrase(objField, strPhrase, true);
}

function AddPhrase2(objField, strPhrase, bFocus)
{
	var strNewValue, strOldValue;

//	strValue = parent.page_session.document.forms[0].elements[objField].value;
//	strOldValue = parent.document.forms[0].elements[objField].value;
	strOldValue = self.opener.document.forms[0].elements[objField].value;
	
	if(strOldValue.indexOf(strPhrase) >= 0)
	{
		return false;
	}
	
	if(strOldValue.lastIndexOf(";") > 1)
	{
		iSlice =  strOldValue.lastIndexOf(";");
		strOldValue = strOldValue.substring(0, iSlice + 2);
	}
	else
	{
		strOldValue = "";
	}
	
    	strNewValue = strOldValue + strPhrase + "; ";

//	parent.page_session.document.forms[0].elements[objField].value += strPhrase;
//	parent.document.forms[0].elements[objField].value += strPhrase;
//	parent.page_session.document.forms[0].elements[objField].value += '; ';
//	parent.document.forms[0].elements[objField].value += '; ';
	self.opener.document.forms[0].elements[objField].value = strNewValue;
//	parent.document.forms[0].elements[objField].value = strNewValue;
	if(bFocus)
	{
		self.opener.document.forms[0].elements[objField].focus();
//		parent.document.forms[0].elements[objField].focus();
	}
//	parent.document.forms[0].elements[objField].value = strNewValue;
//	parent.document.forms[0].elements[objField].focus();
	//parent.page_session.document.forms[0].elements[objField].focus();

	return true;
}

function AddPhrase(objField, strPhrase, bFocus)
{
	var strNewValue, strOldValue;

	strOldValue = objField.value;
	
	if(strOldValue.indexOf(strPhrase) >= 0)
	{
		return false;
	}
	
	if(strOldValue.lastIndexOf(";") > 1)
	{
		iSlice =  strOldValue.lastIndexOf(";");
		strOldValue = strOldValue.substring(0, iSlice + 2);
	}
	else
	{
		strOldValue = "";
	}
	
    	strNewValue = strOldValue + strPhrase + "; ";
    	
	objField.value = strNewValue;
	if(bFocus)
	{
		objField.focus();
	}

	return true;
}
