if(navigator.appName.indexOf("Microsoft") > -1){
	var toggle = 'block';
} else {
	var toggle = 'table-row';
}


/*************************************************************************\
Form button mouseover events. Looks at the scrElement in the event to 
determine if it is type button or submit and changes the class type.
\*************************************************************************/

/*
extends isValidCharacters to validate for alpha/numerics.
*/
function isValidAlphaNumeric(obj)
{
	isValidCharacters("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ",obj);
}

/*************************************************************************\
isValidCharacters(Characters, Form object,true)
Parameter 1 - Only characters allowed
Parameter 2 - Form object
Returns if the form element characters given are valid and specifies the
character that is incorrect in the form field.
\*************************************************************************/
function isValidCharacters(chars,obj) 
{
	var field = obj.value;
	field = Trim(field);
	obj.value = field;
	if(!field == "")
	{
		var charset = chars
		var valid = "yes";
		var temp;
		for (var i=0; i<field.length; i++) 
		{
			temp = "" + field.substring(i, i+1);
			if (charset.indexOf(temp) == "-1") 
			{
				return false;
			}
		}
	}
	return true;
}




/*************************************************************************\
RemoveCharacters(Form object, Character To Replace, Replace With Character)
Removes the requested character from the object text specified. 
Will remove any character specified.
\*************************************************************************/
function RemoveCharacters(obj,char1,repl)
{
	var field = obj.value;
	if(!field == "")
	{	
		field = field.toString().replace(char1,repl);
		//field = field.toString().replace(/\+char+|\,/g,repl);
		obj.value = field;
	}
}
/*************************************************************************\
Trim(Character String)
Removes the trailing spaces in a string.
\*************************************************************************/
function Trim(str)
{
	return str.replace(/^\s*|\s*$/g,"");
}
/*************************************************************************\
isValidZip(Form object,true)
Parameter 1 - Form object
\*************************************************************************/
function isValidZip(obj) 
{
	var field = obj.value;
	field = Trim(field);
	obj.value = field;
	var valid = "0123456789-";
	var hyphencount = 0;
	if(!field == "")
	{
		if (field.length!=5 && field.length!=10) 
		{
			return false;
		}
		for (var i=0; i < field.length; i++) 
		{
			temp = "" + field.substring(i, i+1);
			if (temp == "-") hyphencount++;
			if (valid.indexOf(temp) == "-1") 
			{
				return false;
			}
			if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) 
			{
				return false;
			}
		}
		return true;
	}
	return true;
}
/*************************************************************************\
isValidEmail(Form object,true)
Parameter 1 - Form object
\*************************************************************************/
function isValidEmail(obj) 
{
	var field = obj.value;
	field = Trim(field);
	obj.value = field;
	if(field != "")
	{
		if(field.indexOf("@") == -1)
		{
			return false;
		}
	
		if(field.indexOf(".") == -1)
		{
			return false;
		}	
		var emailPat=/^(.+)@(.+)$/
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
		var validChars="\[^\\s" + specialChars + "\]"
		var quotedUser="(\"[^\"]*\")"
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
		var atom=validChars + '+'
		var word="(" + atom + "|" + quotedUser + ")"
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
		var matchArray=field.match(emailPat)
		if (matchArray==null) 
		{
			return false;
		}
		var user=matchArray[1]
		var domain=matchArray[2]
		if (user.match(userPat)==null) 
		{
			return false;
		}
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null) 
		{
			for (var i=1;i<=4;i++) 
			{
				if (IPArray[i]>255) 
				{
					return false;
				}
			}
			return true;
		}
		
		var domainArray=domain.match(domainPat)
		if (domainArray==null) 
		{
			return false;
		}
		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
		{
			return false;
		}
		if (len<2) 
		{
			return false;
		}
		return true;
	}
	return true;
}
/*************************************************************************\
isValidMoney(Form object)
Parameter 1 - Form object
Returns if the dollar amount given is valid and formats, removes $ and ,
from the field. If dollar amount is given with 3 decimal places script
will round up to two decimal places
\*************************************************************************/
function isValidMoney(obj) 
{
	var field = obj.value;
	field = Trim(field);
	obj.value = field;
	if(!field == "")
	{	
		if(isValidCharacters("-0123456789.$,",obj) != false)
		{
			var matchRegEx = field.match(/^[+-]?((\$\d*)|(\$\d*\.\d{2})|(\d*)|(\d*\.\d{2}))$/);
			if(matchRegEx == null)
			{
				return false;
			}
			field = field.toString().replace(/\$|\,/g,'');

			sign = (field== (field = Math.abs(field)));
			field = Math.floor(field*100+0.50000000001);
			cents = field%100;
			field = Math.floor(field/100).toString();
			if(field.length > 10)
			{
				return false;				
			}
			if(cents<10)
			{
				cents = "0" + cents;
			}
			for (var i = 0; i < Math.floor((field.length-(1+i))/3); i++)
			{
				field = field.substring(0,field.length-(4*i+3)) + field.substring(field.length-(4*i+3));
			}
			//number = new Number(field);
			//field = number.toFixed(2);
			obj.value = (((sign)?'':'-') + field + '.' + cents);
		}
	}
	return true;
}
/*************************************************************************\
isNumeric(Form object, true)
Parameter 1 - Form object
Returns if the form element characters given are valid
\*************************************************************************/
function isNumeric(obj)
{
	var field = obj.value;
	field = Trim(field);
	obj.value = field;
	if(!field == "")
	{
		var charset = '0123456789';
		var valid = "yes";
		var temp;
		fieldsize = Math.floor(field).toString();
		if(fieldsize.length > 10)
		{
			return false;			
		}
		else
		{
			for (var i=0; i<field.length; i++) 
			{
				temp = "" + field.substring(i, i+1);
				if (charset.indexOf(temp) == "-1") 
				{
					return false;
				}
			}
		}
	}
	return true;
}
/*************************************************************************\
isValidPercentage(Form object)
Returns if the form element characters given are valid
\*************************************************************************/
function isValidPercentage(obj)
{
	var field = obj.value;
	field = Trim(field);
	obj.value = field;
	if(!field == "")
	{
		field = field.toString().replace(/\%|\,/g,'');
		obj.value = field;
		var charset = '-.0123456789';
		var valid = "yes";
		var temp;
		fieldsize = Math.floor(field).toString();
		if(fieldsize.length > 10)
		{
			return false;			
		}
		else
		{
			for (var i=0; i<field.length; i++) 
			{
				temp = "" + field.substring(i, i+1);
				if (charset.indexOf(temp) == "-1") 
				{
					return false;
				}
			}
		}
	}
	return true;
}
/*************************************************************************\
isValidDecimal(Form object)
Returns if the form element characters given are valid
\*************************************************************************/
function isValidDecimal(obj)
{
	var field = obj.value;
	field = Trim(field);
	obj.value = field;
	if(!field == "")
	{
		field = field.toString().replace(/\%|\,/g,'');
		obj.value = field;
		var charset = '-.0123456789';
		var valid = "yes";
		var temp;
		fieldsize = Math.floor(field).toString();
		if(fieldsize.length > 10)
		{
			return false;			
		}
		else
		{
			for (var i=0; i<field.length; i++) 
			{
				temp = "" + field.substring(i, i+1);
				if (charset.indexOf(temp) == "-1") 
				{
					return false;
				}
			sign = (field== (field = Math.abs(field)));
			field = Math.floor(field*100+0.50000000001);
			cents = field%100;
			field = Math.floor(field/100).toString();
			if(cents<10)
			{
				cents = "0" + cents;
			}
			obj.value = (((sign)?'':'-') + field + '.' + cents);
			}
		}
	}
	return true;
}
/*************************************************************************\
isValidPositiveDecimal(Form object)
Returns if the form element characters given are valid
\*************************************************************************/
function isValidPositiveDecimal(obj)
{
	field = obj.value;
	field = Trim(field);
	obj.value = field;
	if(!field == "")
	{
		if(isValidCharacters("0123456789.,",obj) != false)
		{
			field = field.toString().replace(/\%|\,/g,'');
			obj.value = field;
			var charset = '.0123456789';
			var valid = "yes";

			fieldsize = Math.floor(field).toString();
			if(fieldsize.length > 10)
			{
				return false;			
			}
			else
			{
				for (var i=0; i<field.length; i++) 
				{
					sign = (field== (field = Math.abs(field)));
					field = Math.floor(field*100+0.50000000001);
					cents = field%100;
					field = Math.floor(field/100).toString();
					if(cents<10)
					{
						cents = "0" + cents;
					}
					obj.value = (field + '.' + cents);
				}
			}
		}
	}
	return true;
}
/*************************************************************************\
isValidPhoneNumber(Form object,true)
Parameter 1 - Form object
Returns if the dollar amount given is valid and formats, removes $ and ,
from the field. If dollar amount is given with 3 decimal places script
will round up to two decimal places
\*************************************************************************/
function isValidPhoneNumber(obj) 
{
	field = obj.value;
	field = Trim(field);
	obj.value = field;
	if(!field == "")
	{	
		field = field.toString().replace(/\(|\,/g,'');
		field = field.toString().replace(/\)|\,/g,'');
		field = field.toString().replace(/\.|\,/g,'');
		field = field.toString().replace(/\-|\,/g,'');
		obj.value = field;		

		var areacode = field.substring(0,3);
		var num1 = field.substring(3,6);
		var num2 = field.substring(6,10);
		
		if(isValidCharacters("0123456789,",obj) != false)
		{
			var matchRegEx = field.match(/^(\d{3})-?\d{3}-?\d{4}$/);
			if(matchRegEx == null)
			{
				return false;
			}
		}
		obj.value = (areacode+'-'+num1+'-'+num2);
	}
	return true;
}
/*************************************************************************\
isValidSSN(Form object,true)
Parameter 1 - Form object
Returns if the social security number is valid. Checks the matchArr pattern
against the value given. SSN format should be ###-##-####. isValidSSN does
not require - between numbers.
\*************************************************************************/
function isValidSSN(obj)
{
	var field = obj.value;
	field = Trim(field);
	obj.value = field;
	if(!field == "")
	{
		field = field.toString().replace(/\-|\,/g,'');
		obj.value = field;
		
		var num1 = field.substring(0,3);
		var num2 = field.substring(3,5);
		var num3 = field.substring(5,9);		
					
		if(isValidCharacters("0123456789,",obj) != false)
		{
			var matchRegEx = field.match(/^(\d{3})-?\d{2}-?\d{4}$/);
			var numDashes = field.split('-').length - 1;
			if(matchRegEx == null || numDashes == 1)
			{
				return false;
			}
			else
			{
				if(parseInt(matchRegEx[1],10)==0)
				{
					return false;
				}
			}
		}
		obj.value = (num1+'-'+num2+'-'+num3);
	}
	return true;
}
/*************************************************************************\
isValidDate(Form object,true)
Parameter 1 - Form object
Function call when user calls script onblur on a date field

\*************************************************************************/
function isValidDate(obj) 
{
	var field = obj.value;
	field = Trim(field);
	obj.value = field;
	if(!field == "")
	{
		if(isValidCharacters("0123456789/-.",obj) != false)
		{
			if (chkdate(obj) == false) 
			{	
				return false;
			}
			else 
			{
				return true;
			}
		}
	}
	return true;
}


/*************************************************************************\
chkdate(Form object)
Function called from isValidDate function
Returns if the date given is valid and formats correctly 01/01/2003. Dates
can be given with different seperators . / - Function will reformat with /
and will set all month day and year values according to the format 01/01
even if the user does not enter month and day with 2 digit values
\*************************************************************************/
function GetFullYear(year) {
    return (year + parseInt(val.century)) - ((year <=
(parseInt(val.cutoffyear) % 100)) ? 0 : 100);
}

function chkdate(obj) 
{
	var strDatestyle = "US";
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var strday;
	var intMonth;
	var intYear;
	var booFound = false;
	var field = obj;
	var seperator = "/"
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "01";
	strMonthArray[1] = "02";
	strMonthArray[2] = "03";
	strMonthArray[3] = "04";
	strMonthArray[4] = "05";
	strMonthArray[5] = "06";
	strMonthArray[6] = "07";
	strMonthArray[7] = "08";
	strMonthArray[8] = "09";
	strMonthArray[9] = "10";
	strMonthArray[10] = "11";
	strMonthArray[11] = "12";
	strDate = field.value;
	if (strDate.length < 1) 
	{
		return true;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 
		{
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) 
			{
				err = 1;
				return false;
			}
			else 
			{
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
		booFound = true;
   		}
	}
	if (booFound == false) 
	{
		if (strDate.length > 5) 
		{
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
   		}
		else
		{
			err = 1;
			return false;
		}
	}
	if (strYear.length == 2) 
	{
		if (strYear >= 50)
		{
			strYear = '19' + strYear;
		}
		else
		{
			strYear = '20' + strYear;
		}
	}
	if (strYear.length == 3 || strYear.length == 1)
	{
		return false;	
	}
	// US style
	if (strDatestyle == "US") 
	{
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) 
	{
		err = 2;
		return false;
	}
	strday = intday.toString();
	if (strday.length == 1)
	{
		strday = '0' + intday;
	}
	else
	{
		strday = intday;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) 
	{
		for (i = 0;i<12;i++) 
		{
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) 
			{
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
   			}
		}
		if (isNaN(intMonth)) 
		{
			err = 3;
			return false;
		}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) 
	{
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1)
	{
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1))

	{
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1))
	{
		err = 7;
		return false;
	}
	if (intMonth == 2)
	{
		if (intday < 1) 
		{
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true) 
		{
			if (intday > 29) 
			{
				err = 9;
				return false;
			}
		}
		else 
		{
			if (intday > 28)
			{
				err = 10;
				return false;
			}
		}
	}
	if (strDatestyle == "US") 
	{
		field.value = strMonthArray[intMonth-1] + seperator + strday+ seperator + strYear;
	}
	else
	{
		field.value = strday + seperator + strMonthArray[intMonth-1] + seperator + strYear;
	}
return true;
}
function LeapYear(intYear) 
{
	if (intYear % 100 == 0) 
	{
		if (intYear % 400 == 0) 
		{ 
			return true;
		}
	}
	else 
	{
		if ((intYear % 4) == 0) 
		{ 
			return true; 
		}
	}
	return false;
}
function isXPSP2()
{ // returns 0 if not WinXP SP2 returns 22 (height of status bar) if it is.
	var g_fIsSP2 = (window.navigator.userAgent.indexOf("SV1") != -1);
	if (g_fIsSP2)
	{
   		return true;
	}
	else
	{
   		return false;
	}
}		


function FindFirstFormFieldByName(docForm, fieldName)
{
	var pattern = new RegExp("^_ctl[0-9][0-9]*:" + fieldName + "$");
	var pattern2 = new RegExp("^_ctl[0-9][0-9]*:.*:" + fieldName + "$");

	for (var i = 0 ; i < docForm.elements.length ; i++)
	{
	    if (docForm.elements[i].name == fieldName)
	    {
    	    return docForm.elements[i];
	    }
	    else
	    {
		    if (pattern.test(docForm.elements[i].name) || pattern2.test(docForm.elements[i].name))
		    {
			    return docForm.elements[i];
		    }
	    }
	}
	return null;
}

function ViewSource()
{
	parent.document.location = 'view-source:' + parent.document.location.href;
}

function AddOptionToListBox(listBox, value, text)
{
	listBox[listBox.length] = new Option(text, value);
}

function DeleteOptionFromListBoxByValue(listBox, value)
{
	var deletedOne = true;
	
	while (deletedOne)
	{
		deletedOne = false;
		for (var i = listBox.options.length - 1; i >= 0; i--)
		{
			if (listBox.options[i].value == value)
			{
				listBox.options[i] = null;
				deletedOne = true;
			}
		}
	}
}

function DeleteOptionFromListBoxByText(listBox, text)
{
	var deletedOne = true;
	
	while (deletedOne)
	{
		deletedOne = false;
		for (var i = listBox.options.length - 1; i >= 0; i--)
		{
			if (listBox.options[i].text == text)
			{
				listBox.options[i] = null;
				deletedOne = true;
			}
		}
	}
}

function EmptyListBox(listBox)
{
	for (var i = listBox.options.length - 1; i >= 0; i--)
	{
		listBox.options[i] = null;
	}
}

// Function to sort a list box by its TEXT attribute.
function SortListBoxByText(listBox)
{
	SortListBox(listBox, "Text");
}

// Function to sort a list box by its VALUE attribute.
function SortListBoxByValue(listBox)
{
	SortListBox(listBox, "Value");
}

// Function to sort a list box by either its TEXT or its VALUE attribute.
function SortListBox(listBox, byTextOrValue)
{
	var a = new Array();
	
	// First, put the listbox into an array.
	for (var i = 0 ; i < listBox.options.length ; i++)
	{
		if (byTextOrValue == "Value")
		{
			a[i] = [listBox.options[i].value, listBox.options[i].text];
		}
		else
		{
			a[i] = [listBox.options[i].text, listBox.options[i].value];
		}
	}
	
	// Sort the array - sorts by the value in the first dimension.
	a.sort();
	
	// Replace the options in the listbox.
	for (var i = 0 ; i < a.length ; i++)
	{
		listBox.options[i] = new Option(a[i][0], a[i][1]);
	}
}


function clearWord()
	{
	userWord = "";
	document.forms[0].result.value = ""; 
	}
	
var userWord = "";

function TrapKey(obj, e)
				{
	thekey = String.fromCharCode(event.keyCode);
	userWord += thekey;
	for (var i = 0; i < obj.options.length; i++) {
		var txt = obj.options[i].text.toUpperCase();
				    
	document.forms[0].result.value = userWord; 
	if (txt.indexOf(userWord) == 0) {
		obj.options[i].selected = true;
		obj.options[i].focus();
		break;
		}
	}
	setTimeout("clearWord()", 3000)
}


function isDefined(object)
{ 
	return (typeof(object) != "undefined")? true: false;
}


function TextareaMaxLength(field, maxlen)
{
	if (field.value.length > maxlen)
	{
		field.value = field.value.substring(0, maxlen);
	}
}


/*************************************************************************\
CaseFirstLetters(textbox)
Capitalizes first letter of each word of the textbox
\*************************************************************************/
function CaseFirstLetters(txt)
{
	var aryNames = txt.value.split(' ');
	var nNames = aryNames.length;
	for (var i = 0; i < nNames; i++)
	{
		aryNames[i] = aryNames[i].substr(0, 1).toUpperCase() + aryNames[i].substr(1);
	}
	txt.value = aryNames.join(' ');
}

/*************************************************************************\
isNum(number)
Returns true if the form element characters given are valid number
\*************************************************************************/
function isNum(val)
{
	if ( isNaN(Number(val)))
	{
		return false;
	}
	return true;
}

