//--GLOBAL------------------------------------------------------
//-------BROWSER DETECTION--------------------------------------	
var MODAL = null;
window.onfocus = RaiseModal;
document.onclick = RaiseModal;

var ie = null;
var ie4 = null;
var ie5 = null;
var ie6 = null;
var ns = null;
var ns4 = null;
var ns6 = null;
var version = navigator.appVersion;

if(navigator.appName == 'Microsoft Internet Explorer')
{
	ie = true;
}else if(navigator.appName == 'Netscape'){
	ns = true;
}
if(ie)
{
	version = version.substr(navigator.appVersion.indexOf('MSIE')+5,1);
	switch(version){
		case '4':
			ie4 = true;
			break;
		case '5':
			ie5 = true;
			break;
		case '6':
			ie6 = true;
			break;
	}
}else if(ns){
	version = version.charAt(0);
	switch(version){
		case '4':
			ns4 = true;
			break;
		case '5':  // yes this is correct NS6 spits out 5 as its version
			ns6 = true;
			break;
	}
}

function OpenHelp(fileName, langTypeID)
{
	var strLang = '';
	
	langTypeID == ''?0:parseInt(langTypeID);
	
	if(langTypeID > 0)
	{
		for(var i = 0; i < LANGUAGE_TYPES.length; i++)
		{
			if(langTypeID == LANGUAGE_TYPES[i][1])
			{
				strLang = LANGUAGE_TYPES[i][0] + '/';
			}
		}
	}
	
//	openWin('Help/' + strLang + fileName, '', 255, 255, 640, 480);
	ModalWin('Help/' + strLang + fileName, '', 255, 255, 640, 480, true, false);
}

function PopUpImage(inImg){
	/*
	This Function will PopUp the image in a new (sized to the graphic) window 
	and center the window.  it will handle if graphic is too big for the screen resolution.
	usage:PopUpImage('../dsn/vortallogic/content/images/sample.jpg');
	BROWSER TESTED: NS6.02, IE5.5, NS4.08(minor issues)
	ns4.08 - must be called from href="javascript;PopUpImage(image);", and
						small issue with getting image size, but will be able to resize		
	*/
	var NewImage = new Image();
	var s,width,height,top,left;
	var initializer;
	var winW = window.screen.width;
	var winH = window.screen.height;	
	var NewImageWinWidth,NewImageWinHeight
	var re = / /gi; //find all spaces
	
	/* since image gets padded in both browsers, 
	add a spacer to the new window W/H */
	var wSpacer = 335;
	var hSpacer = 235;
	
	/* when screen is not big enough to handle image, 
	subtract these vars from winW/winH from the actual window W/H */	
	var redoWinW = 20;
	var redoWinH = 150;
	
	//set src and replace ' ' with '%20' for URL friendly graphic display
	NewImage.src = inImg.replace(re,'%20');

	initializer = NewImage.src;	 //Needed for NS4 - "alert(NewImage.src);" works better.

	NewWinWidth = NewImage.width + wSpacer;
	NewWinHeight = NewImage.height + hSpacer;

	//if screen resolution width is less than image width, then redo window size
	if (winW <= NewWinWidth)
		width = winW - redoWinW;
	else
		width = NewWinWidth;
	//if screen resolution height is less than image height, then redo window size
	if (winH <= NewWinHeight)
		height = winH - redoWinH;
	else
		height = NewWinHeight;
	
	//set the x/y coordinates for the new window to be centered
	top = winH/2 - (height/2);
	left = winW/2 - (width/2);
	//do window open command
	var myWin = openWin(NewImage.src, 'LargeImage', top, left, width, height, false, false, false, true, true)
	myWin.focus();
}//end of PopUpImage()
/*
CenterWin Centers a popup window on the client screen by
getting client screen resolution and subtracting 1/2 by 1/2 of
the width and height of the window passed in.  This can be included
at the bottom of all popup windows.
tested in ns4.08,ns6,ie5.5
*/
function CenterWin(inWinW,inWinH){
	//---get screen width/height
	var sWidth = window.screen.width;
	var sHeight = window.screen.height;
	//---do division to get middle of all windows
	var sMiddleW = sWidth/2;
	var sMiddleH = sHeight/2;		
	var inWinMiddleW = inWinW/2;
	var inWinMiddleH = inWinH/2;
	//---do subtraction to know where to place window
	var x = sMiddleW - inWinMiddleW;
	var y = sMiddleH - inWinMiddleH;
	//---do the placement
	window.resizeTo(inWinW,inWinH)
	window.moveTo(x,y)
} //end of CenterWin()
function TrimJS(inFieldValue){					
	var inFieldLength = inFieldValue.length;					
	var i,startI,endI;
					
	if (inFieldLength > 0){					
		//
		//start from beginning and find the fist non-space
		//
		for(i=0; i < inFieldLength; i++){
							
			if(inFieldValue.charAt(i) != ' '){								
				startI = i;
				i = inFieldLength;
			} 									
		}
		//
		//start from end and find the first non-space
		//
		for(i=inFieldLength-1; i >= 0; i--){
			//alert(inFieldValue.charAt(i))
			if(inFieldValue.charAt(i) != ' '){								
				endI = i+1;
				i = 0;
			}
		}
		//alert('->'+inFieldValue.substring(startI,endI)+'<-');
		return inFieldValue.substring(startI,endI)
	}//end of if()
	else {return '';}
}//end of jsTrim
//--GET TAG FROM ID OR ACTUAL TAG-------------------------------------
function GetTag(tag)
{
	try
	{
		if(((typeof tag) != 'string') && ((typeof tag) != 'number'))
		{
			return tag;
		}else if(document.getElementById(tag) != null){
			return document.getElementById(tag);
		}
		return null;
	}
	catch(er){}
}

//--GET an HTML Collection of TAGS of a certain name that is assigned to it by the name="myName" attribute of a tag-------------------------------------
function GetTags(tagName)
{
	try
	{
		if(((typeof tagName) != 'string') && ((typeof tagName) != 'number'))
		{
			return tag;
		}else if(document.getElementsByName(tagName) != null){
			return document.getElementsByName(tagName);
		}
		return null;
	}
	catch(er){}
}

//--GET an HTML Collection of TAGS of a certain name, such as input, select, a, etc-------------------------------------
function GetTagsByName(tagName)
{
	try
	{
		if(((typeof tagName) != 'string') && ((typeof tagName) != 'number'))
		{
			return tagName;
		}else if(document.getElementsByTagName(tagName) != null){
			return document.getElementsByTagName(tagName);
		}
		return null;
	}
	catch(er){}
}


//--SET FORM ACTION -------------------------------------------
function FormAction(FormName, Action)
{
	try
	{
		document[FormName].action = Action;
	}
	catch(er)
	{
	}
}
//--SET FIELD FOCUS---------------------------------------------
function SetFocus(tag)
{
	try
	{
		tag = GetTag(tag);
		tag.focus();
	}
	catch(er){}
}
//--GET FIELD VALUE---------------------------------------------
function GetVal(FormName,FieldName)
{
	try
	{
		if(document[FormName][FieldName])
		{
			return document[FormName][FieldName].value;
		}
	}
	catch(er)
	{
		return '';
	}
}
//--SET FIELD VALUE---------------------------------------------
function SetVal(FormName,FieldName,FieldValue)
{
	try
	{
		document[FormName][FieldName].value = FieldValue;
	}
	catch(er){}
}
//--SET/GET FIELD VALUE-------------------------------------------
// FieldValue is optional
function FormVal(FormName, FieldName, FieldValue)
{
	try
	{
		if(arguments.length==3)
		{
			if(document[FormName][FieldName])
			{
				document[FormName][FieldName].value = FieldValue;
			}
		}else{
			if(document[FormName][FieldName])
			{
				return document[FormName][FieldName].value;
			}
		}
	}
	catch(er)
	{
	}
}
//--SET/GET OPENER FIELD VALUE------------------------------------
// FieldValue is optional
function OpenerFormVal(FormName, FieldName, FieldValue)
{
	try
	{
		if(arguments.length==3)
		{
			if(window.opener.document[FormName][FieldName])
			{
				/*if something is already in the text field ask if user wants to append or overwrite*/
				if (window.opener.document[FormName][FieldName].value.length > 0){
					if (confirm('Press \'OK\' to replace current text value, or \n\n press \'Cancel\' to add to the current text value.')){
						window.opener.document[FormName][FieldName].value = FieldValue;
					}else{window.opener.document[FormName][FieldName].value += '\n' + FieldValue;}
				}else{window.opener.document[FormName][FieldName].value = FieldValue;}
			}
		}else{
			if(window.opener.document[FormName][FieldName])
			{
				return window.opener.document[FormName][FieldName].value;
			}
		}
	}
	catch(er)
	{
	}
}
//--SELECT RADIO BUTTON ----------------------------------------------
function SelectRadioButton(FormName,Status,FieldName,RadioNumber)
{
	if(Status){document[FormName][FieldName][RadioNumber].checked = true}
	if(!Status){document[FormName][FieldName][RadioNumber].checked = false}
}
function SelectRadioByName(FormName,FieldName, Value)
{
	if(document[FormName][FieldName])
	{
		for(var i = 0; i < document[FormName][FieldName].length; i++)
		{
			if(document[FormName][FieldName][i].value == Value)
			{
				document[FormName][FieldName][i].checked = true;
			}
		}
	}
}
//--GET SELECTED RADIO BUTTON ----------------------------------------
function GetSelectedIndexRadio(FormName, FieldName){
	//Returns index of selected radio button
	try{
		if(document[FormName][FieldName])
		{
			for(var i = 0; i < document[FormName][FieldName].length; i++)
			{
				if(document[FormName][FieldName][i].checked){return i;}
			}
		}
	}
	catch(e){}
}
function GetSelectedRadioValue(FormName, FieldName){
//Return value of selected option (not index)
/*
	try{
		return document[FormName][FieldName][GetSelectedIndexRadio(FormName,FieldName)].value;
	}
	catch(e){return document[FormName][FieldName].value;}
*/
//Changed to this format by dduval in order to get this function to work in mozilla AND ie
	var objFormField = document[FormName].elements[FieldName]
	var strValue = 0;
	intControlLength = objFormField.length
	for (i=0;i<intControlLength;i++)
	{
		if(objFormField[i].checked)
		{
			strValue = objFormField[i].value;
		}
	}
	return strValue;
}

	function getRadialValue(FormName, strFieldName)
	{
		var objFormField = document[FormName].elements[strFieldName]
		var strValue = 0;
		intControlLength = objFormField.length
		for (i=0;i<intControlLength;i++)
		{
			if(objFormField[i].checked)
			{
				strValue = objFormField[i].value;
			}
		}
		return strValue;
	}
//--GET SELECTED INDEX VALUE---(IE4,NS4)------------------------
function getSelectedIndex(FormName,FieldName)
{
	try
	{
		return document[FormName][FieldName].selectedIndex;
	}
	catch(er)
	{
	}
}
function GetSelectedVal(FormName, FieldName){
	//Return value of selected option (not index number)
	try{
		if(document[FormName][FieldName]){
			return document[FormName][FieldName].options[getSelectedIndex(FormName, FieldName)].value ;
		}
	}
	catch(e){
	}
}
//-- ADD RADIO BUTTON AFTER APPENDTO TAG --------------------------------------------------------
function AddRadioButton(AppendTo, FieldName, value, checked)
{
	var radio = document.createElement('input');
	radio.type = 'radio';
	radio.id = FieldName;
	radio.name = FieldName;
	radio.onclick = function(){SelectRadio(this);}
	radio.value = value;
	GetTag(AppendTo).appendChild(radio);
	if(checked){SelectRadio(radio);}
}
function SelectRadio(tag)
{
	var list  = document[tag.form.name][tag.name];
	if(parseInt(list.length).toString() == 'NaN')
	{
		tag.checked = true;
	}else{
		for(var i = 0; i < list.length; i++)
		{
			if(list[i].value == tag.value)
			{
				list[i].checked = true;
			}else{
				list[i].checked = false;
			}
		}
	}
}
//--IS CHECK BOX CHECKED----------------------------------------
function IsChecked(FormName,FieldName)
{
	try
	{
		if(document[FormName][FieldName].checked){return document[FormName][FieldName].checked}
	}
	catch(er)
	{
		return false;
	}
}
//--SELECT / UNSELECT CHECK BOX BY NAME----------------------------
function Check(FormName, FieldName)
{
	try
	{
		document[FormName][FieldName].checked = true;
	}
	catch(er)
	{
	}
}
function UnCheck(FormName, FieldName)
{
	try
	{
		document[FormName][FieldName].checked = false;
	}
	catch(er)
	{
	}
}
function SetCheck(FormName, FieldName, Checked)
{
	try
	{
		document[FormName][FieldName].checked = Checked;
	}
	catch(er)
	{
	}
}
//--SELECT RADIO BUTTON CHECKED-----------------------------------
function IsRadioChecked(FormName,FieldName,RadioNumber)
{
	try
	{
		return document[FormName][FieldName][RadioNumber].checked;
	}
	catch(er)
	{
		return false;
	}
}
//--MAKE SELECTED ----------------------------------------------
function MakeSelected(FormName,FieldName,InValue)
{
	try
	{
		for(var i = 0; i < document[FormName][FieldName].options.length; i++)
		{
			if(document[FormName][FieldName].options[i].value == InValue)
			{
				document[FormName][FieldName].selectedIndex = i;
			}
		}
	}
	catch(er)
	{
	}
}
function AddOption(FormName, FieldName, OptionValue, OptionText) {
	var oOption = document.createElement('option');
	oOption.value = OptionValue;
	oOption.appendChild(document.createTextNode(OptionText));
	document[FormName][FieldName].appendChild(oOption);
}
function RemoveAllOptions(FormName, FieldName){
	document[FormName][FieldName].length=0 ;
}
function RemoveOption(FormName, FieldName, Value)
{
//	try
//	{
		var iPos = 0;
//alert(document[FormName][FieldName].length);
		for(var i = 0; i < document[FormName][FieldName].length; i++)
		{
			if(document[FormName][FieldName][i].value.toUpperCase() == Value.toString().toUpperCase()){iPos--}
			document[FormName][FieldName][i].value = document[FormName][FieldName][iPos].value;
			document[FormName][FieldName][i].text = document[FormName][FieldName][iPos].text;
			iPos++;
		}
		document[FormName][FieldName].length = document[FormName][FieldName].length--;
//	}
//	catch(er)
//	{
//		alert(er.description);
//	}
}
//--SET FRONT HTML-----Bold-Italic-Underline--------------------
function SetFront(FormName,bold,italic,underline)
{
		if(IsChecked(FormName,bold))      {front = '<b>';} else {front = ''}
		if(IsChecked(FormName,italic))    {front = front + '<i>';}
		if(IsChecked(FormName,underline)){front = front + '<u>';}
		return front;
}
//--SET BACK HTML-----Bold-Italic-Underline---------------------
function SetBack(FormName,bold,italic,underline)
{
		if(IsChecked(FormName,bold))      {back = '</b>';} else {back = '';}
		if(IsChecked(FormName,italic))    {back = '</i>' + back;}
		if(IsChecked(FormName,underline)){back = '</u>' + back;}
		return back;
}
//--SET TEXT LENGTH LIMIT---------------------------------------
function FormatText(text,fontsize)
{
		var TextLengthLimit
		if(fontsize == 1){TextLengthLimit = 62}
		if(fontsize == 2){TextLengthLimit = 43}
		if(fontsize == 3){TextLengthLimit = 38}
		if(fontsize == 4){TextLengthLimit = 33}
		if(fontsize == 5){TextLengthLimit = 24}
		if(fontsize == 6){TextLengthLimit = 18}
		if(fontsize == 7){TextLengthLimit = 12}
	
		if(text.length > TextLengthLimit)
		{
				text = text.substr(0,TextLengthLimit) + '...';
		}
		return text;
}
//############################################################################################
//##################### Replace These ########################################################
//############################################################################################
//--DISPLAY POP UP WINDOW---------------(IE4)--------------------
function openWin(href, name, top, left, width, height, Status, Toolbar, Menubar, Scrollbars, Resizable)
{
	var s = 'top=' + top + ',left=' + left + ',width=' + width + ',height=' + height + ',';

	if(Status)
	{
		s += 'status=yes,';
	}else{
		s += 'status=no,';
	}


	if(Toolbar)
	{
		s += 'toolbar=yes,';
	}else{
		s += 'toolbar=no,';
	}

	if(Menubar)
	{
		s += 'menubar=yes,';
	}else{
		s += 'menubar=no,';
	}

	if(Scrollbars)
	{
		s += 'scrollbars=yes,';
	}else{
		s += 'scrollbars=no,';
	}

	if(Resizable)
	{
		s += 'resizable=yes';
	}else{
		s += 'resizable=no';
	}
	return window.open( href, name, s);
}
//This function differs b/c it can be called from an anchor tag.
function OpenWin(href, name, top, left, width, height, Status, Toolbar, Menubar, Scrollbars, Resizable)
{
	var s = 'top='+top+',left='+left+',width='+width+',height='+height + ',';
	if(Status)
	{
		s += 'status=yes,';
	}else{
		s += 'status=no,';
	}


	if(Toolbar)
	{
		s += 'toolbar=yes,';
	}else{
		s += 'toolbar=no,';
	}

	if(Menubar)
	{
		s += 'menubar=yes,';
	}else{
		s += 'menubar=no,';
	}

	if(Scrollbars)
	{
		s += 'scrollbars=yes,';
	}else{
		s += 'scrollbars=no,';
	}

	if(Resizable)
	{
		s += 'resizable=yes';
	}else{
		s += 'resizable=no';
	}
	window.open( href, name, s);
}
//############################################################################################
//##################### With These ###########################################################
function ModalWin(page, name, top, left, width, height, scrollBars, Resizable, Toolbar, StatusBar, MenuBar)
{
	try
	{
		
	
		var strParam = ',height=' + height + ',top=' + top + ',left=' + left
		if(MenuBar)
		{
			strParam += 'menubar=yes,';
		}
		else{
			strParam += 'menubar=no,';
		}	
		if(Toolbar)
		{
			strParam += 'toolbar=yes,';
		}else{
			strParam += 'toolbar=no,';
		}

		if(StatusBar)
		{
			strParam += 'status=yes,';
		}else{
			strParam += 'status=no,';
		}


		if(Resizable)
		{
			strParam += 'resizable=yes,';
		}else{
			strParam += 'resizable=no,';
		}

		if(scrollBars)
		{
			strParam += 'scrollbars=yes';
		}else{
			strParam += 'scrollbars=no';
		}

		MODAL = window.open(page, name, 'width=' + width + strParam);
		MODAL.onblur = RaiseModal;
	}
	catch(er){}
}
function RaiseModal()
{
	try
	{
		MODAL.focus();
	}
	catch(er){}
}

function FocusOpener()
{
	window.opener.focus();
}
function RefreshOpener()
{
	FocusOpener();
	window.opener.location.reload();
}
function Close()
{
	window.close();
}
//############################################################################################
//############################################################################################
//--CHANGE PAGE LOCATION --------------------------------------------------
function GoToSite(URL, FramName)
{
	try
	{
		if(arguments[1])
		{
			top.window[FramName].location.href = URL;
		}else{
			window.document.location.href = URL;
		}
		return URL;
	}
	catch(er){}
}
//--CHANGE THE CLASS OF A TAG------------------------
function ChangeClass(tag, NewClass)
{
	try
	{
		tag = GetTag(tag);
		tag.className = NewClass;		
	}
	catch(er){}
}

//--CHANGE CURSOR TO LINK HAND NORMALLY PASS(this)-------------------------
function ShowHand(tag)
{
	try
	{
		tag = GetTag(tag);
		if(ie)
		{
			tag.style.cursor = 'hand';
		}else{
			tag.style.cursor = 'pointer';
		}
	}
	catch(er){}
}
// -change div style position to ABSOLUTE
function ShowDivPos(idList)
{
	try
	{
		for(var i = 0; i < arguments.length; i++)
		{
			var tag = GetTag(arguments[i]);
			if(tag)
			{
				tag.style.position = 'absolute';
			}
		}
	}
	catch(er)
	{
	}
}
//--HIDE HTML INSIDE OF DIV TAG---------------(IE5,NS6)--------------------
function HideDivPos(idList)
{
	try
	{
		for(var i = 0; i < arguments.length; i++)
		{
			var tag = GetTag(arguments[i]);
			if(tag)
			{
				tag.style.position = '';
			}
		}
	}
	catch(er)
	{
	}
}

//--SHOW HTML INSIDE OF DIV TAG---------------(IE5,NS6)--------------------
function ShowDiv(idList)
{
	try
	{
		for(var i = 0; i < arguments.length; i++)
		{
			var tag = GetTag(arguments[i]);
			if(tag)
			{
				tag.style.visibility = 'visible';
			}
		}
	}
	catch(er)
	{
	}
}
//--HIDE HTML INSIDE OF DIV TAG---------------(IE5,NS6)--------------------
function HideDiv(idList)
{
	try
	{
		for(var i = 0; i < arguments.length; i++)
		{
			var tag = GetTag(arguments[i]);
			if(tag)
			{
				tag.style.visibility = 'hidden';
			}
		}
	}
	catch(er)
	{
	}
}
//--TOGGLE HTML INSIDE OF DIV TAG ON AND OFF ---(IE5, NS6)---------------------
function ToggleDiv(idList)
{
	try
	{
		for(var i = 0; i < arguments.length; i++)
		{
			var tag = GetTag(arguments[i]);
			if(tag)
			{
				if(tag.style.visibility == 'hidden')
				{
					ShowDiv(tag);
				}else{
					HideDiv(tag);
				}
			}
		}
	}
	catch(er)
	{
	}
}
//------------ WARNING THESE FUNCTIONS WILL CHANGE PAGE LAYOUT ----------------
//--MAKE TAG INVISIBLE AND REMOVE FROM PAGE LAYOUT ----------------------------
function NoDisplay(tag)
{
	for(var i = 0; i < arguments.length; i++)
	{
		tag = GetTag(arguments[i]);
		tag.style.display = 'none';
	}
}
//--MAKE TAG VISIBLE AND REMOVE FROM PAGE LAYOUT ------------------------------
function Display(tag)
{
	for(var i = 0; i < arguments.length; i++)
	{
		tag = GetTag(arguments[i]);
		tag.style.display = 'block';
	}
}
//--GET HTML THAT MAKES UP DIV TAG --------------------------------------------
	function GetHTMLByID(id)
	{
		return document.getElementById(id);
	}
//--SET INNERHTML VALUE OF A TAG WITH AN ID ------------------------------------
//  This Works in IE5+ and NS6+
function SetInnerHTML(tag, value)
{
	try
	{
		var tag = GetTag(tag);
		tag.innerHTML = value;
	}
	catch(er)
	{
	}
}
//--SET STYLE OF ANY TAG WITH AN ID
	function SetStyle(id, property, value)
	{
		document.getElementById(id).style[property] = value;
	}
//--SET TEXTAREA LENGTH LIMIT---------------------------------------
function textCounter(FieldName,FormName,maxlimit)
{
	if(document[FormName] == null) return;
		if(document[FormName][FieldName].value.length > maxlimit) // if too long...trim it!
			document[FormName][FieldName].value = document[FormName][FieldName].value.substring(0, maxlimit);
}
//--GET COLOR---------------------------------------------------
	function GetColor(Color,FieldName,FormName)
	{	
		document[FormName][FieldName].value=Color;
	}
//--TOGGLE CHECK ALL---(IE4,NS4)------[check boxes with different names]------------
function ToggleSelected(FormName,Status,StringOfFieldNames)
{
	var ArrayOfFieldNames=StringOfFieldNames.split('|');
		for(var i = 0; i < ArrayOfFieldNames.length; i++)
		{
			if(Status){document[FormName][ArrayOfFieldNames[i]].checked = true;}
			if(!Status){document[FormName][ArrayOfFieldNames[i]].checked = false;}
		}
}
//--CHECK ALL---(IE4,NS4)-------[check boxes with same name]---------------------------
function CheckAll(FormName,Status,FieldName)
{
	try
	{
		if(document[FormName][FieldName])
		{
			for(var i = 0; i < document[FormName][FieldName].length; i++)
			{
				if(document[FormName][FieldName](i).name==FieldName)
				{
					document[FormName][FieldName](i).checked = Status;
				}
			}
		}
	}
	catch(er)
	{
	}
}
//--DISABLE & ENABLE FORM INPUTS---(IE4)-------------------------
///////////////////////////////////////////////////////Netscape 4 does NOT support Disable
function DisableForm(FormName,status,StringOfFieldNames)
{
	var ArrayOfFieldNames = StringOfFieldNames.split('|');
	for(var i = 0; i < ArrayOfFieldNames.length; i++)
	{
		if(document[FormName][ArrayOfFieldNames[i]]) {
			if(status == 1)
			{
				document[FormName][ArrayOfFieldNames[i]].disabled = false;
			}else{
				document[FormName][ArrayOfFieldNames[i]].disabled = true;
			}
		}
	}
}
function ReadOnlyForm(FormName,status,StringOfFieldNames,backColor)
{
	if(!backColor){
		if(status == 1){
			backColor = '#cccccc';
		}else{
			backColor = '#ffffff';
		}
	}
	
	var ArrayOfFieldNames = StringOfFieldNames.split('|');
	for(var i = 0; i < ArrayOfFieldNames.length; i++)
	{
		if(document[FormName][ArrayOfFieldNames[i]]) {
			var Tag = document[FormName][ArrayOfFieldNames[i]] ;
			if(status == 1)
			{
				switch(Tag.type.toUpperCase()){
				case 'SELECT-ONE':
					Tag.onclick = new Function('MakeSelected(Form,this.id,\'' + Tag.value + '\');');
					Tag.onchange = null;
					Tag.style.backgroundColor = backColor;
					break;
				case 'CHECKBOX':
					Tag.onclick = new Function('return false;');
					Tag.style.backgroundColor = backColor;
					break;
				default:
					Tag.readOnly = true;
					Tag.style.backgroundColor = backColor;
					break;
				}
			}else{
				switch(Tag.type.toUpperCase()){
				case 'SELECT-ONE':
					Tag.onclick = new Function(Tag.onclick);
					Tag.onchange = new Function(Tag.onchange);
					Tag.style.backgroundColor = backColor;
					break;
				case 'CHECKBOX':
					Tag.onclick = new Function(Tag.onclick);
					Tag.style.backgroundColor = backColor;
					break;	
				default:
					Tag.readOnly = false;
					Tag.style.backgroundColor = backColor;
					break;
				}
			}
		}
	}
}
function BlankOutReadOnly(Form, FieldList){
	//This Function will blank out ReadOnly fields when the user hits the space bar or delete key.
	switch(window.event.keyCode){
		//32 Space bar, 46 delete
		case 32:
		case 46:
			var ArrayOfFieldNames = FieldList.split('|');
			for(var i = 0; i < ArrayOfFieldNames.length; i++)
			{
				SetVal(Form, ArrayOfFieldNames[i], '');			
			}
			break;
	}
}
//--SUBMIT FORM---(IE4,NS4)--------------------------------------
function SubmitForm(FormName)
{
	try
	{
		document[FormName].submit();
	}
	catch(er)
	{
	}
}
//--POPULATE ARRAY--Populates an array with data---(IE4,NS4)------
function PopulateArray(ArrayName, StringOfData)
{
	var ArrayOfData = StringOfData.split('|');
	for(var i = 0; i < ArrayOfData.length; i++)
	{
		ArrayName[i] = ArrayOfData[i];
	}
}
//--POPULATE ARRAY 2D--Populates a two dimensional array---(IE4,NS4)--
function PopulateArray2D(ArrayName,ArrayNumber,StringOfData)
{
	var ArrayOfData = StringOfData.split('|');
	for(var i = 0; i < ArrayOfData.length; i++)
	{
		ArrayName[ArrayNumber][i] = ArrayOfData[i];
	}
}
//--FORMAT PHONE NUMBER--Validates a phone number to include CountryCode, AreaCode and PhoneNumber --(IE4,IE5,NS4,NS6)-----
//FieldName = INPUT that displays number; others are INPUT tags holding value
//--Need to have three hidden text boxes on page for CountryCode, AreaCode and Phone to be populated by functions
//--Need to have one text box for user to enter Phone Number
function FormatPhoneNumber (FormName, FieldName, CountryCodeField, AreaCodeField, PhoneNumberField, Required, DisplayName)
{
	//removes possible characters keyed in then 
	//checks Phone Number for length (between 10-13) and numeric
	//If everything is correct, formats phone number and changes values for three 'hidden'
	//text boxes for CountryCode, AreaCode, and PhoneNumber 
	//else it leaves the value as user keyed and returns false
	//checks for the following characters:
		// ' ', '-', '_', '.', '\', '(', ')', '+'
	re = / |-|_|\.|\\|\(|\)|\+/g;
	str = GetVal(FormName, FieldName);
	newstr = str.replace(re, '');
	Required = Required.toString().toLowerCase();
	
	if(parseInt(newstr,10) != newstr)
	{
		//not numeric; return false
		//do not change value of text box
		if(newstr.length==0)
		{
			if(Required == "true")
			{
				alert (DisplayName + ' number must be provided');
				return false;
			}else{
				//Phone is blank, but not required - return true 
				return true;
			}
		}else{
			alert (DisplayName + ' number contains invalid characters');
			return false;
		}
//		return false;
	}else{
		//string is numeric once characters removed
		//check to see if length between 10-13 characters
		if(newstr.length >= 10 && newstr.length <14 )
		{
			//length = 7; return true and set textbox value = newstr
			if(newstr.length == 10)
			{
				SetVal(FormName, FieldName, '+1 (' + newstr.substr(0,3) + ') ' + newstr.substr(3,3) + '-' + newstr.substr(6,4));
				SetVal(FormName, CountryCodeField, '1');
				SetVal(FormName, AreaCodeField, newstr.substr(0,3));
				SetVal(FormName, PhoneNumberField, newstr.substr(3,7));
			}else{
				slength = newstr.length;
				SetVal(FormName, FieldName, '+' + newstr.substr(0,slength-10) + ' (' + newstr.substr(slength-10,3) + ') ' + newstr.substr(slength-7,3) + '-' + newstr.substr(slength-4,4));
				SetVal(FormName, CountryCodeField, newstr.substr(0,slength-10));
				SetVal(FormName, AreaCodeField, newstr.substr(slength-10,3));
				SetVal(FormName, PhoneNumberField, newstr.substr(slength-7,7));
			}
			return true;
		}else{	//length < 10; return false and do not change value of textbox value
			if(newstr.length < 10)
			{
				alert (DisplayName +  ' number must be at least 10 digits');
			}else{
				alert (DisplayName + ' number is too long');
			}
			return false;
		}
	}
}
//**********************************************************************************************************	
//********************************* START OF FORM VALIDATION FUNCTIONS *************************************
//**********************************************************************************************************		
//--IS FORM EMPTY--Check if form field is empty---(IE4,NS4)-------------------------------------------------
function IsFormEmpty(FormName,StringOfFieldNames)
{
	var ArrayOfFieldNames=StringOfFieldNames.split('|');
	var ErrorString = '';
	for(var i = 0; i < ArrayOfFieldNames.length; i++)
	{
		if(document[FormName][ArrayOfFieldNames[i]].value.length < 1)
		{
			ErrorString = ErrorString + ArrayOfFieldNames[i] + '\n     ';
		}
	}
	if(ErrorString.length > 0)
	{
			alert('Please fill out the following form fields.\n     ' + ErrorString);
			return false;
	}else{
			return true;
	}
}
//--IS FORM EMPTY--Check if form field is empty, receives Display Name for alert box---(IE4,NS4)-------------------------------------------------
function IsFormEmptyDisplayName(FormName,StringOfFieldNames,StringofDisplayNames)
{
	var ArrayOfFieldNames=StringOfFieldNames.split('|');
	var ArrayOfDisplayNames=StringofDisplayNames.split('|');
	var ErrorString = '';
	for (var i=0; i < ArrayOfFieldNames.length; i++)
	{
		if(document[FormName][ArrayOfFieldNames[i]].value.length < 1)
		{
			ErrorString = ErrorString + ArrayOfDisplayNames[i] + '\n\t';
		}
	}
	if(ErrorString.length > 0)
	{
		alert('Please fill out the following form fields.\n     ' + ErrorString);
		return false;
	}else{
		return true;
	}
}
//--IS EMAIL--Check if form field is a valid email address---(IE4,NS4)--------------------------------------
function IsEmail(FormName,FieldName)
{
/*	var Email = document[FormName][FieldName].value;
    var eLength = Email.length;
    var i = 1;
    var Status = '';
	while((i < eLength) && (Email.charAt(i) != '@')){i++}
	if((i >= eLength) || (Email.charAt(i) != '@')){Status = false;}
	else {i =  i + 2;}
	while ((i < eLength) && (Email.charAt(i) != '.')){i++}
	if((i >= eLength - 1) || (Email.charAt(i) != '.')){Status= false;}
	else {Status = true;}
	if(!Status){alert('Invalid Email Address')}
	return Status;
*****Changed to a regex by dduval
*/

  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  return regex.test(document[FormName][FieldName].value);
}
//--IS MATCHING--Check if two form fields are the same---(IE4,NS4)-----------------------------------------
function IsMatching(FormName,FieldNameOne,FieldNameTwo)
{
	if(document[FormName][FieldNameOne].value == document[FormName][FieldNameTwo].value)
	{
		return true;
	}else{
		alert('Passwords do not match');
		return false;
	}
}
//--CHECK LENGTH--Check if form field is the proper length---(IE4,NS4)--------------------------------------
//****Note:(RequiredLengthOne should be lower than RLTwo for Type=Between)----------------------------------
function CheckLength(FormName,FieldName,DisplayName,RequiredLengthOne,RequiredLengthTwo,Type)
{
	var StringLength = document[FormName][FieldName].value.length;
	var Message = DisplayName + ' improper length'
	try
	{
		switch(Type.toUpperCase()){
			case 'EQUAL':
				if(StringLength != RequiredLengthOne){throw DisplayName}
				break;
			case 'LESSTHAN':
				if(StringLength >= RequiredLengthOne){throw DisplayName}
				break;
			case 'GREATERTHAN':
				if(StringLength <= RequiredLengthOne){throw DisplayName}
				break;
			case 'BETWEEN':
				if((StringLength < RequiredLengthOne) || (StringLength > RequiredLengthTwo)){throw DisplayName}
				break;
			case 'OREQUAL':
				if((StringLength == RequiredLengthOne) || (StringLength == RequiredLengthTwo)){throw DisplayName}
				break;
			default:
			break;
		}
	}
	catch(er)
	{
//		alert(er);
		return false;
	}
	return true;
/*
	if(Type == 'Equal')
	{
		if(StringLength == RequiredLengthOne)
		{
			return true;
		}else{
			alert(Message);
			return false;
		}
	}
	if(Type == 'LessThan')
	{
		if(StringLength < RequiredLengthOne){return true;}
		else {alert(Message); return false;}
	}
	if(Type == 'GreaterThan')
	{
		if(StringLength > RequiredLengthOne){return true;}
		else {alert(Message); return false;}
	}
	if(Type == 'Between')
	{
		if((StringLength > RequiredLengthOne) && (StringLength < RequiredLengthTwo)){return true;}
		else {alert(Message); return false;}
	}
	if(Type == 'OrEqual')
	{
		if((StringLength == RequiredLengthOne) || (StringLength == RequiredLengthTwo)){return true;}
		else {alert(Message); return false;}
	}
*/
}
//--IS NUMERIC--Check if form field has only numbers in it---(IE4,NS4)--------------------------------------
function IsNumeric(FormName,FieldName,DisplayName)
{
	var StringToCheck = document[FormName][FieldName].value;
	var nums = new Array(0,1,2,3,4,5,6,7,8,9);
	var Message = DisplayName + ' can only contain numbers.'
    var check;
    AddToString = '';
		for(var i = 0; i < StringToCheck.length; i++)
		{
			check = '';
			for(var j=0 ; j < nums.length ; j++)
			{
				if(StringToCheck.charAt(i) == String(nums[j])){check = 't';}
			}
			AddToString = AddToString + check;
		}
		if(AddToString.length >= StringToCheck.length && StringToCheck.length > 0){return true;}
		else {alert(Message); return false;}
}
//--CHECK CHARACTERS--Check if form field has only the characters you specify in it---(IE4,NS4)-------------
function CheckCharacters(FormName,FieldName,DisplayName,StringOfCharacters)
{
	var ArrayOfCharacters=StringOfCharacters.split('|');
	var StringToCheck = document[FormName][FieldName].value;
	var Message = 'Please check ' +DisplayName+ ' for invalid characters.';
    var check;
    AddToString = '';
		for (var i=0 ; i < StringToCheck.length ; i++){
			check = '';
			for (var j=0 ; j < ArrayOfCharacters.length ; j++){
				if(StringToCheck.charAt(i) == ArrayOfCharacters[j]){check = 't';}
			}
			AddToString = AddToString + check;
		}
		if(AddToString.length >= StringToCheck.length){return true;}    
		else {alert(Message); return false;}
}
//--IN STRING--Check if certain characters are in a string---(IE4,NS4)-------------------------------------	
function InString(StringToCheck,StringOfCharacters)
{	
	var ArrayOfCharacters=StringOfCharacters.split('|');
    var InThere;
	for (var i=0 ; i < StringToCheck.length ; i++)
	{
		check = '';
		for (var j=0 ; j < ArrayOfCharacters.length ; j++)
		{
			if(StringToCheck.charAt(i) == ArrayOfCharacters[j]){InThere = true}
		}
	}
	if(InThere)
	{
		return true;
	}else{
		return false;
	}
}
//--IS DROP DOWN CHANGED--Checks if drop down list has been changed---(IE4,NS4)-----------------------------
function IsDropDownChanged(FormName,FieldName,DisplayName)
{
	var Message = 'Please choose a ' + DisplayName;
	if(getSelectedIndex(FormName,FieldName) > 0)
	{
		return true;
	}else{
		alert(Message);
		return false;
	}
}
//--IS DROP DOWN SELECTED--Checks if drop down list has value <> 'SelectOne' ---(IE4)-----------------------------
//--Use this function if the dropdown box may have only one option at times and therefor IsDropDownChanged
//--Will not always return the desired response. 
function IsDropDownSelected(FormName,FieldName,DisplayName)
{
	var Message = 'Please choose a ' + DisplayName;
	if(GetVal(FormName,FieldName) != 'SelectOne')
	{
		return true;
	}else{
		alert(Message);
		return false;
	}
}
//--DASH FORMAT--Checks zip code and phone numbers for '-' inputs a '-' if in the correct place---(IE4)-----Has not been tested in NS4	
function DashFormat(FormName,FieldName,FirstSet,SecondSet)
{
	var Str = document[FormName][FieldName].value;
	for (var i=0 ; i < Str.length ; i++)
	{
		if(InString(Str,'-'))
		{
			re = /-/;
			document[FormName][FieldName].value = Str.replace(re, '');
		}
		Str = document[FormName][FieldName].value;
	}
	var First = Str.substr(0,FirstSet);
	var Second = Str.substr(FirstSet,SecondSet);
	if((Str.length > FirstSet) && (!InString(Str,'-')))
	{
		document[FormName][FieldName].value = First + '-' + Second;
	}
}
//--AUTO MOVE--Moves focus from one field [Use with 'OnKeyPress'] to another---(IE4)-----Has not been tested in NS4	
function AutoMove(FormName,FromField,ToField)
{
	var Length = document[FormName][FromField].value.length;
	var MaxLength = document[FormName][FromField].maxLength;
	if((Length + 1) == MaxLength)
	{
		document[FormName][FromField].value = document[FormName][FromField].value + String.fromCharCode(event.keyCode);
 		event.returnValue = false;
		document[FormName][ToField].focus();
	}
}
//--AUTO FORMAT--Auto puts in a '-' for [Use with 'OnKeyPress'] zip codes and phone numbers---(IE4)------Has not been test in NS4	
//----------------------------------------FirstSet is 5 for zip, 3 for phone - SecondSet is 4 for zip, 4 for phone	
function AutoFormat(FormName,FieldName,FirstSet,SecondSet)
{
	var Str = document[FormName][FieldName].value;
	var First = Str.substr(0,FirstSet);
	var Second = Str.substr(FirstSet,SecondSet);
	if((Str.length > FirstSet-1) && (!InString(Str,'-')) && (!InString(String.fromCharCode(event.keyCode),'-')))
	{
		document[FormName][FieldName].value = First + '-' + Second;
	}
}
// --------------------------------------------------------------------
// FUNCTION NAME		: MultiSelectOptions
// Browser Compatiblity : Netscape4.08 (Win2k)
//                      : IE5.0 (Win2K)
//                      : Opera : Untested
// ARGS                 : string inStrForm : form name
//                      : string inStrElement : MUST be a <select> tag
//                      : int inIntSlctValue : value to make selected
// description          : finds inIntSlctValue in <select>, and makes it selected
// --------------------------------------------------------------------
function MultiSelectOptions(inStrForm,inStrElement,inIntSlctValue)
{
	var i;
	var SelectLen = document[inStrForm][inStrElement].length;
	for (i=0 ; i<SelectLen ; i++)
	{
		if(document[inStrForm][inStrElement][i].value == inIntSlctValue)
		{
			document[inStrForm][inStrElement][i].selected = true;
		}
	}
}
// --------------------------------------------------------------------
// FUNCTION NAME				: GetElementFromDlmtdStr
// Browser Compatiblity : Netscape4.08 (Win2k)
//                      : IE5.0 (Win2K)
//                      : Opera : Untested
// ARGS                 : string inStrAry : string that is delimted by the Delimiter
//                      : string Delimiter : must be a char like ',' or '|'
//                      : int inIntSlctValue : element # to return 
// description          : inStrAry = 'a,b,c,d,e' ElementNumber (0,1,2,3,4) = (a,b,c,d,e) 
// --------------------------------------------------------------------
function GetElementFromDlmtdStr(inStrAry,Delimiter,ElementNumber)
{
	var inStrAry2;
	inStrAry2 = inStrAry;
	inStrAry2 = inStrAry2.split(Delimiter);
	return inStrAry2[ElementNumber];
}
function GetDate(){
	//returns today's date
	var d, s = "";           //Declare variables.
   	d = new Date();                           //Create Date object.
   	s += (d.getMonth() + 1) + "/";            //Get month
  	s += d.getDate() + "/";                   //Get day
   	s += d.getYear();                         //Get year.
   	return(s);                                //Return date.
}
function DaysInMonth(date)
{
	switch(date.getMonth())
	{
	case 0:	//January
		return 31;
		break;
	case 1:	//February
		if(isLeapYear(date))
		{
			return 29;
		}else{
			return 28;
		}
		break;
	case 2:	//March
		return 31;
		break;
	case 3:	//April
		return 30;
		break;
	case 4:	//May
		return 31;
		break;
	case 5:	//June
		return 30;
		break;
	case 6:	//July
		return 31;
		break;
	case 7:	//August
		return 31;
		break;
	case 8:	//September
		return 30;
		break;
	case 9:	//October
		return 31;
		break;
	case 10:	//November
		return 30;
		break;
	case 11:	//December
		return 31;
		break;
	}
}
function MonthName(date)
{
	switch(date.getMonth())
	{
	case 0:	//January
		return 'January';
		break;
	case 1:	//February
		return 'February';
		break;
	case 2:	//March
		return 'March';
		break;
	case 3:	//April
		return 'April';
		break;
	case 4:	//May
		return 'May';
		break;
	case 5:	//June
		return 'June';
		break;
	case 6:	//July
		return 'July';
		break;
	case 7:	//August
		return 'August';
		break;
	case 8:	//September
		return 'September';
		break;
	case 9:	//October
		return 'October';
		break;
	case 10:	//November
		return 'November';
		break;
	case 11:	//December
		return 'December';
		break;
	}
}
function isLeapYear(date)
{
	if((date.getFullYear() % 400) == 0)
	{
		return true;
	}else if((date.getFullYear() % 100) == 0){
		return false;
	}else if((date.getFullYear() % 4) == 0){
		return true;
	}
	return false;
}
function RemoveAllChildren(tag)
{
	try
	{
		for(var i = (tag.childNodes.length - 1); i >= 0; i--)
		{
			RemoveAllChildren(tag.childNodes[i]);
			tag.childNodes[i].removeNode();
		}
	}
	catch(er){}
}
//Changes Style Class for all Children of given tag
function ChangeAllChildrensClass(tag, OldClass, NewClass)
{
	try
	{
		tag = GetTag(tag);
		for(var i = (tag.childNodes.length - 1); i >= 0; i--)
		{
			ChangeAllChildrensClass(tag.childNodes[i], OldClass, NewClass);
			if(tag.childNodes[i].className.toUpperCase() == OldClass.toUpperCase())
			{
				tag.childNodes[i].className = NewClass;
			}
		}
	}
	catch(er){}
}
function CopyVal(FromForm, FromField, ToForm, ToField){
	//Copies value from one form to another
	//assumes field values are compatible (checkbox-to-radio and vice versa not handled)
	try	{
		var tagFrom = document[FromForm][FromField] ;
		var tagTo = document[ToForm][ToField] ;
		if((tagFrom)&&(tagTo)){
			if (tagFrom.type){
				//non-collection objects
				switch (tagFrom.type.toUpperCase()){
					case 'CHECKBOX': ;
						if (tagTo.type.toUpperCase()=='CHECKBOX'){
							tagTo.checked = tagFrom.checked ;	
						}
						else{								
							if (tagFrom.checked){
								tagTo.value = tagFrom.value ;
							}
							else{
								tagTo.value = 0	;
							}
						}
						break;
					
					case 'SELECT-ONE': ;
						var Index = getSelectedIndex(FromForm, FromField) ;
						var Value = tagFrom[Index].value ;
						//if value not available, store the index of selected item button
						if (tagTo.length){
							//To is a collection
							MakeSelected(ToForm,ToField, Value) ;
						}
						else{
							//To is a non-collection
							tagTo.value = Value	;
						}
						break ;
						
					default: ;
						if (tagTo.type){
							//To is a non-collection
							switch (tagTo.type.toUpperCase()){
								case 'CHECKBOX': ;
									tagTo.checked = (tagFrom.value!=='0') ;
									break ;
								
								case 'SELECT-ONE': ;
									MakeSelected(ToForm,ToField, tagFrom.value) ;
									break ;
							
								default: ;
									//Most will probably go through here because most write to text, hidden
									tagTo.value = tagFrom.value ;
									break ;
							}
						}
						else{
							
							//To is a collection
							switch (tagTo[Index].type.toUpperCase()){
								case 'RADIO': ;
									SelectRadioByName(ToForm,ToField, Value) ;
									break ;
								
								default: ;
									MakeSelected(ToForm,ToField, Value) ;
									break ;
							}
						}
						break;
				}
			}
			else{
				//collection objects
				//assumes value has been assigned to each collection object
				var Index = GetSelectedIndexRadio(FromForm, FromField) ;
				var Value = tagFrom[Index].value ;
				switch (tagFrom[Index].type.toUpperCase()){
					case 'RADIO': ;
						//if value not available, store the index of selected radio button
						if (tagTo.length){
							//To is a collection
							SelectRadioByName(ToForm,ToField, Value) ;
						}
						else{
							//To is a non-collection
							tagTo.value = Value	;
						}
						break ;
						
					default: ;
						tagTo.value = Value ;
						break ;
				}
			}
		}
	}
	catch(e){
		alert('Error encountered');
	}	
}

//AddField is used to create table using javascript
function AddField(table,x,y,field,caption,colspan){
	// table	= name of table you want to add field to
	// x		= row you want field added to
	// y		= column you want field added to; 0 = Use whole row
	// field	= string of HTML that defines field (ex. '<input type=\"text\"/>')
	// caption	= caption for field...goes to the left of field; no caption passed in forces field to use caption area
	// colspan	= number of columns you want the field to take up; default is 1; 

	var oTab = document.getElementById(table) ;
	var oRow, oCell ;
	var cellNum = 0 ;
	if(!colspan){colspan=1} ;
	
	oCell = document.getElementById(table+x+'td'+y) ;
	if(!oCell){
		oRow = oTab.insertRow(oTab.rows.length) ;
		//oRow.width='100%' ;
		if(y!=0){
			for(i=1; i<=4; i++){
				if((i<=y)||(i>=y+colspan)){ //skip cell if previous cell had colspan
					//Caption cells
					oCell = oRow.insertCell(cellNum) ;
					oCell.id = table+x+'td'+i+'label' ;
					oCell.className = 'PrimaryBoldText' ;
					oCell.noWrap = true ;
					oCell.align = 'right' ;
					oCell.vAlign = 'top' ;
					if((caption)&&(i==y)){
						oCell.innerHTML = caption ;
					}
					cellNum++ ;
					//Data cells
					oCell = oRow.insertCell(cellNum) ;
					oCell.id = table+x+'td'+i ;
					oCell.className = 'PrimaryBoldText' ;
					oCell.noWrap = true ;
					oCell.vAlign = 'top' ;
					if(i==y){
						oCell.innerHTML = field ;
						//if(caption){
							oCell.colSpan = (colspan*2)-1 ;
						//}else{
						//	oCell.colSpan = (colspan*2) ;
						//}
					}
					cellNum++ ;
				}
			}
		}else{
			oCell = oRow.insertCell(-1);
			oCell.width = '100%' ;
			oCell.colSpan = 8 ;
			oCell.id = table+x+'td'+y ;
			oCell.className = 'PrimaryBoldText' ;
			oCell.noWrap = true ;
			oCell.innerHTML = field ;
		}
	}else{
   		if(caption){
			oCell.colSpan = (colspan*2)-1 ;
			oCell.innerHTML = field ;
			oCell = document.getElementById(table+x+'td'+y+'label') ;
			oCell.innerHTML = caption ;
		}else{
			oCell.colSpan = (colspan*2) ;
			oCell.innerHTML = field ;
		}
	}
}
function ChangeToLabel(Field)
{
	//This function basically makes a tag a Label by changing the borderstyle and background
	//color and setting the tag to readonly.
	
	var T = GetTag(Field);	
	T.style.borderStyle = 'none';	
	T.style.backgroundColor = 'transparent';	
	T.readOnly=true;
}
function Round(Val,Dec){
	//Dec designates the number of digits after the decimal point
	//Dec should always be an integer value for Round to function correctly
    //if the optional value field is not used, it will return a value with 2 digits after the decimal point
    //when used to return the closest integer value (i.e. 3 in case of 2.5; 2 in case of 2.489)
    //use 0 as Dec,
	if(!Dec){
		Dec = 2 ;
	}
	return Math.round(Val * Math.pow(10,Dec)) / Math.pow(10,Dec) ;
}

function checkDate(strDate){
    if(strDate.length>0){
            var dateregex=/^[ ]*[0]?(\d{1,2})\/(\d{1,2})\/(\d{4,})[ ]*$/;
             var match=strDate.match(dateregex);
             if (match){
                       var tmpdate=new Date(match[3],parseInt(match[1],10)-1,match[2]);
                  if (tmpdate.getDate()==parseInt(match[2],10) && tmpdate.getFullYear()==parseInt(match[3],10) && (tmpdate.getMonth()+1)==parseInt(match[1],10)){ 
                    return true; 
                    }
             }
         return false;
    }
    else{
         return true;
    }
}

function GetParentTagByNodeName(INtagChildTag, INstrParentNodeName)
{
	if(INtagChildTag.parentNode.nodeName.toUpperCase() == INstrParentNodeName.toUpperCase())
	{
		return INtagChildTag.parentNode;
	}
	else
	{
		return GetParentTagByNodeName(INtagChildTag.parentNode, INstrParentNodeName);
	}
}