/** Functions used by custom tags */
function requestFocusEx(thisForm,thisField,thisValue,thisError){alert(thisError);thisField.focus();thisField.select();return false;}
function wordCountEx(texts){var tokens=trim(texts).split(" ");return tokens.length;}
function selectByText(listbox,text){for (var i=0;i<listbox.options.length;i++){if(listbox.options[i].text==text){listbox.options[i].selected=true;return;}}}
function blank(){}
startList=function(){if(document.all&&document.getElementById){navRoot=document.getElementById("popup");
if(navRoot!=null){for(i=0;i<navRoot.childNodes.length;i++){node=navRoot.childNodes[i];
if(node.nodeName=="B"){node.onmouseover=function(){this.className+=" over";}
node.onmouseout=function(){this.className=this.className.replace(" over","");}}}}}}
window.onload=startList;

/** Trims a string */
function trim(sInString) 
{
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}

/** Gets expiry date for cookie based on duration */
function getExpiryDate(nodays)
{
	var UTCstring;
	Today = new Date();
	nomilli = Date.parse(Today);
	Today.setTime(nomilli + nodays*24*60*60*1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

/** Sets a cookie variable */
function setCookie(name, value, duration)
{
	var expiryDate = "";
	if (duration > 0) expiryDate = "expires=" + getExpiryDate(duration);
	cookiestring = name + "=" + escape(value) + ";" + expiryDate;
	document.cookie = cookiestring;
}

/** Gets a cookie variable */
function getCookie(cookiename) 
{
	var cookiestring = "" + document.cookie;
	var index1 = cookiestring.indexOf(cookiename);
	if (index1 == -1 || cookiename == "") return ""; 
	var index2 = cookiestring.indexOf(';', index1);
	if (index2 == -1) index2 = cookiestring.length; 
	return unescape(cookiestring.substring(index1 + cookiename.length+1, index2));
}

/** Counts how many words in a text. */
function wordCount(texts)
{
	var tokens = trim(texts).split(" ");
	return tokens.length;
}

/** Validate email using a valid regular expression */
function validateEmail(email, regular_expression)
{
	var filter = /^[\w-]+(\.[\w-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)*?\.[a-z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?$/;
	if (filter.test(email)) return true;
	else return false;
}

/** Validate email argument passed from ColdFusion form */
function validateFormEmail(thisForm, thisField, thisValue)
{
	if (thisValue.length == 0) return true;
	if (!validateEmail(thisValue)) 
	{
		alert("test");
		return false;
	}
	
	return true;
}

/** Set focus to the corresponding ColdFusion form field after error */
function requestFocus(thisForm, thisField, thisValue, thisError)
{
	alert(thisError);
	thisField.focus();
	thisField.select();
	return false;
}

/** Select an element in list box by its text */
function selectByText(listbox, text)
{
	for (var i=0; i<listbox.options.length; i++)
	{
		if (listbox.options[i].text == text)
		{
			listbox.options[i].selected = true;
			return;
		}
	}
}

/** Select a single element in list box by its text */
function selectByTextSingle(listbox, text)
{
	for (var i=0; i<listbox.options.length; i++)
	{
		if (listbox.options[i].text == text)
		{
			listbox.selectedIndex = i;
			return;
		}
	}
}

/** Select a single element in list box by its value */
function selectByValueSingle(listbox, text)
{
	for (var i=0; i<listbox.options.length; i++)
	{
		if (listbox.options[i].value == value)
		{
			listbox.selectedIndex = i;
			return;
		}
	}
}