//******************************	GENERIC FUNCTIONS	**************************************

//--------------------------------------------------------------------------------------------
//Auth: Arvind Paul
//Date: 10/28/2004
//Desc: This function is used to simulate the DOM method getElementById for
//		different browser versions

function GetObjectByID(ID)
{
	//IE, NS 6+
	if (document.getElementById)
		return document.getElementById(ID);
	//IE
	else if (document.all)
		return document.all[ID];
	//NS 4
	else if (document.layers)
		return document.layers[ID];
	else
	{
		alert('Incompatible Browser version. Please use Microsft Internet Explorer.');
		return false;
	}
}

//--------------------------------------------------------------------------------------------
//Auth: Arvind Paul
//Date: 10/28/2004
//Desc: This function is used to return an image object given the image ID

function GetImageByID(ID)
{
	//IE, NS 6+
	if (document.getElementById)
		return document.getElementById(ID);
	//IE
	else if (document.all)
		return document.images[ID];
	//NS 4
	else if (document.layers)
		return document.images[ID];
	else
	{
		alert('Incompatible Browser version. Please use Microsft Internet Explorer.');
		return false;
	}
}

//--------------------------------------------------------------------------------------------
//Auth: Arvind Paul
//Date: 10/28/2004
//Desc: This function is used to simulate the innerText method of IE5+ for
//		different browser versions

function GetInnerText(oElement)
{
	var ie5 = (document.getElementsByTagName && document.all) ? true : false;
	if (ie5) return oElement.innerText;	//Not needed but it is faster
	
	var str = '';
	
	for (var i=0; i<oElement.childNodes.length; i++)
	{
		switch (oElement.childNodes.item(i).nodeType)
		{
			case 1: //ELEMENT_NODE
				str += GetInnerText(oElement.childNodes.item(i));
				break;
			case 3:	//TEXT_NODE
				str += oElement.childNodes.item(i).nodeValue;
				break;
		}
	}
	
	return str;
}

//--------------------------------------------------------------------------------------------
//Auth: Arvind Paul
//Date: 11/06/2004
//Desc: This function checks if the last event was the Enter keypress.

function IsEnterKeypress(oEvent)
{	
	if (window.event)
		var iKeyCode = window.event.keyCode;
	else if (oEvent)
		var iKeyCode = oEvent.which;
	else
		return false;
	
	if (iKeyCode == 13)
		return true;
	else
		return false;
}
//--------------------------------------------------------------------------------------------
//Auth: Flossy Veronica
//Date: 26/04/2006
//Desc: to view record details in a popup... by setting the window size and features

function openPopUp(url,strWindowName,iHeight,iWidth,iLeftAlign,iTopAlign,iScrollBar)
{
	window.open(url,strWindowName,'height ='+iHeight+',width ='+iWidth+',left ='+iLeftAlign+',top ='+iTopAlign+',scrollbars='+iScrollBar+',directories=0,location=0,menubar=0,resizable=1,status=0,titlebar=0,toolbar=0');
}	


//--------------------------------------------------------------------------------------------
//Auth: Navin Joseph
//Date: 28/04/2006
//Desc: This function use to close the window
  function closeWindow()
	{
				window.close();
	}

//--------------------------------------------------------------------------------------------
//Auth: Navin Joseph
//Date: 28/04/2006
//Desc: Functions checks whether the passed value is a valid integer or not
			
  function isValidInteger(oCallingObj)
	{	
		iNumber = oCallingObj.value;
		if (iNumber != '')
			{		
				if(parseInt(iNumber)!=iNumber)  
					{
						return false;
					}
				else
					{
						oCallingObj.value = parseInt(iNumber);			
						return true;		
					}
		     }
	}
//---------------------------------------------------------------------------------------------
//Auth: Navin Joseph
//Date: 28/04/2006
//Desc: This function used to open pop up window

 function openWindow(url,strWindowName,iHeight,iWidth,iLeftAlign,iTopAlign,iScrollBar)
 {
	window.open(url,strWindowName,'height ='+iHeight+',width ='+iWidth+',left ='+iLeftAlign+',top ='+iTopAlign+',scrollbars='+iScrollBar+'');
 }	
//----------------------------------------------------------------------------------------------
//
//****************************		VISIBILITY FUNCTIONS	**********************************

//--------------------------------------------------------------------------------------------
//Auth: Arvind Paul
//Date: 10/28/2004
//Desc: This function checks if an element is hidden - accepts the element object as input

function IsElementHidden(oElement)
{
	return ((document.layers) ? ((oElement.visibility == 'hide') ? true : false) :
									((oElement.style.display == 'none') ? true : false))
}



//--------------------------------------------------------------------------------------------
//Auth: Arvind Paul
//Date: 10/28/2004
//Desc: This function is used to show or hide an element - accepts the element object as input

function ShowElement(oElement, bShow)
{
	if (document.layers)
		oElement.visibility = bShow ? 'show' : 'hide';
	else
		oElement.style.display = bShow ? '' : 'none';
}



//--------------------------------------------------------------------------------------------
//Auth: Arvind Paul
//Date: 10/28/2004
//Desc: This function toggles visibility of an element - accepts the element ID as input.
//		Optionally can accept an Image ID, and toggle the image on show / hide

function ToggleVisibilityByID(sElementID, sImageID, sExpandImageURL, sCollapseImageURL)
{
	// pass in the ID of the element and the image we want to toggle
	var oElement = GetObjectByID(sElementID);
	var oImage = GetImageByID(sImageID);
	
	if (IsElementHidden(oElement))
	{
		// it was OFF, now turn it ON
		ShowElement(oElement,true);
		if (oImage && sCollapseImageURL)
			oImage.src = sCollapseImageURL;
	}
	else
	{
		// it was ON, now turn it OFF
		ShowElement(oElement,false);
		if (oImage && sExpandImageURL)
			oImage.src = sExpandImageURL;
	}
}

//****************************		FORMATTING FUNCTIONS	**********************************

//--------------------------------------------------------------------------------------------
//Auth: Arvind Paul
//Date: 11/29/2004
//Desc: This function is used to trim the input string

function Trim(sString) 
{
	// Remove leading spaces and carriage returns
	  
	while ((sString.substring(0,1) == ' ') || (sString.substring(0,1) == '\n') || (sString.substring(0,1) == '\r'))
	{
		sString = sString.substring(1,sString.length);
	}

	// Remove trailing spaces and carriage returns
	while ((sString.substring(sString.length-1,sString.length) == ' ') || (sString.substring(sString.length-1,sString.length) == '\n') || (sString.substring(sString.length-1,sString.length) == '\r'))
	{
		sString = sString.substring(0,sString.length-1);
	}
	
	return sString;
}

//--------------------------------------------------------------------------------------------

//Auth: Flossy Veronica
//Date: 05/03/2006
//Desc: This function validates the date

//Validation for date
function checkIsValidDate(dateStr) 
{
	
	// dateStr must be of format month day year with either slashes
	// or dashes separating the parts. Some minor changes would have
	// to be made to use day month year or another format.
	// This function returns True if the date is valid.
	var slash1 = dateStr.indexOf("/");
	if (slash1 == -1) { slash1 = dateStr.indexOf("-"); }
	if (slash1 == -1) { slash1 = dateStr.indexOf("."); }
	// if no slashes or dashes or dots, invalid date
	if (slash1 == -1) { 
	alert('Please enter a date in the format MM/DD/YYYY');
	return false; }
	var dateMonth = dateStr.substring(0, slash1)
	var dateMonthAndYear = dateStr.substring(slash1+1, dateStr.length);
	var slash2 = dateMonthAndYear.indexOf("/");
	if (slash2 == -1) { slash2 = dateMonthAndYear.indexOf("-"); }
	if (slash2 == -1) { slash2 = dateMonthAndYear.indexOf("."); }
	// if not a second slash or dash or dot, invalid date
	if (slash2 == -1) { 
	alert('Please enter a date in the format MM/DD/YYYY');
	return false; }
	
	//To chech whether special characters entered
	var dateDay = dateMonthAndYear.substring(0, slash2);
	var iChars = "!@#$%^&*()+=-[]\\\';,/{}|\":<>?";
	var errFlag = 0;
	for (var iCount = 0; iCount < dateDay.length; iCount++) 
	{
		if (iChars.indexOf(dateDay.charAt(iCount)) != -1)
		{
			errFlag = 1;
		}
	}
	if(errFlag == 1)
	{
		alert('Please enter a valid day');
		return false;
	}
	
	var dateYear = dateMonthAndYear.substring(slash2+1, dateMonthAndYear.length);
	if ( (dateMonth == "") || (dateDay == "") || (dateYear == "") ) { return false; }
	// if any non-digits in the month, invalid date
	for (var x=0; x < dateMonth.length; x++) {
		var digit = dateMonth.substring(x, x+1);
		if ((digit < "0") || (digit > "9")) {
    	alert('Please enter a valid month.');
		return false; }
	}
	// convert the text month to a number
	var numMonth = 0;
	for (var x=0; x < dateMonth.length; x++) {
		digit = dateMonth.substring(x, x+1);
		numMonth *= 10;
		numMonth += parseInt(digit);
	}
	if ((numMonth <= 0) || (numMonth > 12)) { 
	alert('Please enter a valid month.');
	return false; }
	// if any non-digits in the day, invalid date
	for (var x=0; x < dateDay.length; x++) {
		digit = dateDay.substring(x, x+1);
		if ((digit < "0") || (digit > "9")) {return false; }
	}
	// convert the text day to a number
	var numDay = 0;
	for (var x=0; x < dateDay.length; x++) {
		digit = dateDay.substring(x, x+1);
		numDay *= 10;
		numDay += parseInt(digit);
	}
	if ((numDay <= 0) || (numDay > 31)) { 
	alert('Please enter a valid day.');
	return false; }
	// February can't be greater than 29 (leap year calculation comes later)
	if ((numMonth == 2) && (numDay > 29)) { 
	alert('Please enter a valid day.');
	return false; }
	// check for months with only 30 days
	if ((numMonth == 4) || (numMonth == 6) || (numMonth == 9) || (numMonth == 11)) { 
		if (numDay > 30) { 
		alert('Please enter a valid day.');
		return false; }
	}
	// if any non-digits in the year, invalid date
	for (var x=0; x < dateYear.length; x++) {
		digit = dateYear.substring(x, x+1);
		if ((digit < "0") || (digit > "9")) { 
		alert('Please enter a valid year.');
		return false; }
	}
	// convert the text year to a number
	var numYear = 0;
	for (var x=0; x < dateYear.length; x++) {
		digit = dateYear.substring(x, x+1);
		numYear *= 10;
		numYear += parseInt(digit);
	}
	// Year must be a 4-digit year
	//NOTE: Original Code supprted 2 and 4 digit years.
	//	Since this led to errors in Specialist Eligibility searches,
	//	only 4 digit dates are supported by appending the following line.
	//  if ( (dateYear.length != 2) && (dateYear.length != 4) ) {
	if ( (dateYear.length != 4) ) {  
	alert('Please enter a valid year in the format YYYY.');
	return false; }
	// if 2-digit year, use 50 as a pivot date
	//NOTE: Original Code supprted 2 and 4 digit years.
	//	Since this led to errors in Specialist Eligibility searches,
	//	only 4 digit dates are supported now. Hence following lines were commented.
	//  if ( (numYear < 50) && (dateYear.length == 2) ) { numYear += 2000; }
	//  if ( (numYear < 100) && (dateYear.length == 2) ) { numYear += 1900; }
	if ((numYear <= 1752) || (numYear > 9999)) { 
	alert('Please enter a valid year.');
	return false; }
	// check for leap year if the month and day is Feb 29
	if ((numMonth == 2) && (numDay == 29)) {
		var div4 = numYear % 4;
		var div100 = numYear % 100;
		var div400 = numYear % 400;
		// if not divisible by 4, then not a leap year so Feb 29 is invalid
		if (div4 != 0) { 
		alert('Not a leap year! February has 28 days.');
		return false; }
		// at this point, year is divisible by 4. So if year is divisible by
		// 100 and not 400, then it's not a leap year so Feb 29 is invalid
		if ((div100 == 0) && (div400 != 0)) {
		alert('Not a leap year! February has 28 days.');
		return false; }
	}
	// date is valid
	return true;
}

//This function checks whether the date value entered by the user is not null and then
//check the Valid date
function validateDateSpec(obj)
{

if(obj.value != "")
	{
	obj.value = Trim(obj.value)
	} //remove leading,trailing spaces
if (obj.value != '') //if date is not blank
{
	if (!checkIsValidDate(obj.value))
	{
		obj.select();
		obj.focus();
		event.returnValue = false;
		return false;
	}
}
return true
}

	
	
	
	
	//Function used to toggle visibility
	function ToggleVisibility(ElementID,ImageID)
	{
	// pass in the ID of the element and the image we want to toggle
	// for IE
	if (document.all)    
	{ 
		var oImage  = document.images[ImageID];
		var oElement = eval("document.all." + ElementID + ".style");
		var hidden = "none";	
		var visible = "";	
	}
	// for Netscape 4.x
	else if (document.layers) 
	{ 
		var oImage  = document.images[ImageID];
		var oElement = document.layers[ElementID];
		var hidden = "hide";	
		var visible = "show";
	}
	//for Netscape 6+
	else	
	{	
		var oImage = document.getElementById(ImageID);
		var oElement = document.getElementById(ElementID).style;
		var hidden = "none";	
		var visible = "";
	}
	// for Netscape 4.x
	if (document.layers) 
	{ 
		if ( oElement.visibility == hidden) 
		{		
			// it was OFF, now turn it ON
			oImage.src = 'images/treeMinimize.gif';
			oElement.visibility = visible;
		} 
		else 
		{
			// it was ON, now turn it OFF
			oImage.src = 'images/treeMaximize.gif';
			oElement.visibility = hidden;
		}
	}
	// all other browsers
	else 
	{	
		if ( oElement.display == "none") 
		{		
			// it was OFF, now turn it ON
			oImage.src = 'images/treeMinimize.gif';
			oElement.display = visible;
		} 
		else 
		{
			// it was ON, now turn it OFF
			oImage.src = 'images/treeMaximize.gif';
			oElement.display = hidden;
		}
	}
}
//--------------------------------------------------------------------------------------------

//This function generates options for the primary grouping drop-down.
			function PopulatePrimaryGrouping()
			{
				var oPrimaryListBox = GetObjectByID('slctPrimaryGrouping');
				BuildListBoxFromArray(oPrimaryListBox, groupingOptions);
				return oPrimaryListBox;
			}
			function InitializeGroupingOptions(selectedValue1, selectedValue2, groupingOptions)
			{
				var oPrimaryListBox = PopulatePrimaryGrouping(groupingOptions);
					if (oPrimaryListBox != null)
					{
						for(var i=0; i<oPrimaryListBox.options.length; i++)
						{
							if (oPrimaryListBox.options[i].value == selectedValue1)
							{
								oPrimaryListBox.selectedIndex = i;
								break;
							}
						}
					}
					var oSecondaryListBox = PopulateSecondaryGrouping(groupingOptions);
					if (oSecondaryListBox != null)
					{
						for(var i=0; i<oSecondaryListBox.options.length; i++)
						{
							if (oSecondaryListBox.options[i].value == selectedValue2)
							{
								oSecondaryListBox.selectedIndex = i;
								break;
							}
						}
					}
				}
			function init(selectedValue1, selectedValue2, groupingOptions)
			{
					InitializeGroupingOptions(selectedValue1, selectedValue2, groupingOptions);
			}
			function PopulateSecondaryGrouping(groupingOptions)
				{
					var oPrimaryListBox = GetObjectByID('slctPrimaryGrouping');
					var oSecondaryListBox = GetObjectByID('slctSecondaryGrouping');
					
					var primaryGroupingIndex = oPrimaryListBox.selectedIndex;
					if (primaryGroupingIndex == 0)
					{	
						oSecondaryListBox.options.length = 0;
						oSecondaryListBox.options[0] = new Option('-- Select Primary Grouping --', 0);
					}
					else
					{
						BuildListBoxFromArray(oSecondaryListBox, groupingOptions);
						oSecondaryListBox.options[primaryGroupingIndex] = null;
					}
					
					return oSecondaryListBox;
				}
				
			//This function builds options into a list box based on the input array.
			function BuildListBoxFromArray(oListBox, array)
			{
				//Clear the list box
				oListBox.options.length = 0;
				
				//Build the list box with the values in the array using new Option ('text value', 'option value')
				for(var i=0; i<array.length; i++)
					oListBox.options[i] = new Option(array[i],i);
			}
			
			function DoSort(iValue,objSpan,hidSortColumn,hidSortValue,hidSortOrder)
			{
				document.getElementById('hidSortColumn').value = objSpan;
				if(document.getElementById('hidSortValue').value != iValue)
				{
					document.getElementById('hidSortOrder').value = 1;
					document.getElementById('hidSortValue').value = iValue;
				}
				else
				{
					document.getElementById('hidSortValue').value = iValue;
					if(document.getElementById('hidSortOrder').value =='')
					{
						document.getElementById('hidSortOrder').value = 0;
					}
					else
					{
						if(document.getElementById('hidSortOrder').value == 0)
						{
							document.getElementById('hidSortOrder').value = 1;
						}
						else
						{
							document.getElementById('hidSortOrder').value = 0;
						}
					}
				}
			}
			
			
			
			
			function SortTable(oCallingObj, sTBodyID, sImageID, iColumnNo, sDataType)
			{
				
				
				var oTBody = sTBodyID;
				var oImage  = GetImageByID(sImageID);
				var oTRows = oTBody.childNodes;
				var arrTRows = new Array();
				for (var i=1; i<oTRows.length; i++) {
					arrTRows[i-1] = oTRows[i];
				}
				if (sDataType == null)
					sDataType = 'alphanumeric';
				
				if (oTBody._currentSortIcon != null)
					if (oTBody._currentSortIcon != oImage)
						oTBody._currentSortIcon.src = 'images/spacer.gif';
				
				oTBody._currentSortIcon = oImage;
					
				if (oTBody._descending == null)
					oTBody._descending = new Array();

				if (oTBody._descending[iColumnNo])	// catch the null/
				{
					oTBody._descending[iColumnNo] = false;
					oTBody._currentSortIcon.src = 'images/sectionMinimize.gif';
				}
				else
				{
					oTBody._descending[iColumnNo] = true;
					oTBody._currentSortIcon.src = 'images/sectionMaximize.gif';
				}
				arrTRows.sort(SortByColumn(iColumnNo, oTBody._descending[iColumnNo], sDataType));
				
				for (var i=0; i<arrTRows.length; i++) {
					oTBody.appendChild(arrTRows[i]);
				}
			}
			
			
			//This function is used to do an array sort of a column in a table
			function SortByColumn(iColumnNo, bDescending, sDataType)
			{
								
				function _compare(n1, n2)
				{
					var data1 = GetInnerText(n1.cells[iColumnNo]);
					var data2 = GetInnerText(n2.cells[iColumnNo]);
					switch (sDataType)
					{
						case 'numeric':
							if(data1.substring(1,2) == "$" 
							|| data2.substring(1,2) == "$")
							{
								
								data1 = data1.substring(2,data1.length);
								data2 = data2.substring(2,data2.length);
							}
							data1 = replaceIt(data1,",","");
							data2 = replaceIt(data2,",","");
							
							if(data1 == " "
							|| Trim(data1) == "")
							{
								data1 = 0
							}
							if(data2 == " "
								|| Trim(data2) == "")
							{
								data2 = 0
							}
							
							if (parseFloat(data1) < parseFloat(data2))
								v = (bDescending) ? +1 : -1;
							else if (parseFloat(data1) > parseFloat(data2))
								v = (bDescending) ? -1 : +1;
							else 
								v = 0;
							break;
						case 'numericBrace':
							if(data1.substring(1,2) == "$" 
							|| data2.substring(1,2) == "$")
							{
								
								data1 = data1.substring(2,data1.length);
								data2 = data2.substring(2,data2.length);
							}
							data1 = replaceIt(data1,",","");
							data2 = replaceIt(data2,",","");
							
							data1 = replaceIt(data1,"(","-");
							data1 = replaceIt(data1,")","");
							data2 = replaceIt(data2,"(","-");
							data2 = replaceIt(data2,")","");
						
							if(data1 == " "
							|| Trim(data1) == "")
							{
								data1 = 0
							}
							if(data2 == " "
								|| Trim(data2) == "")
							{
								data2 = 0
							}
							
							if (parseFloat(data1) < parseFloat(data2))
								v = (bDescending) ? +1 : -1;
							else if (parseFloat(data1) > parseFloat(data2))
								v = (bDescending) ? -1 : +1;
							else 
								v = 0;
							break;
							
						case 'money':
							data1 = data1.substring(2,data1.length);
							data2 = data2.substring(2,data2.length);
							data1 = replaceIt(data1,",","");
							data2 = replaceIt(data2,",","");

							if(data1 == " "
							|| data1 == "")
							{
								data1 = 0
							}
							if(data2 == " "
								|| data2 == "")
							{
								data2 = 0
							}
							if (parseFloat(data1.substring(1)) < parseFloat(data2.substring(1)))
								v = (bDescending) ? +1 : -1;
							else if (parseFloat(data1.substring(1)) > parseFloat(data2.substring(1)))
								v = (bDescending) ? -1 : +1;
							else 
								v = 0;
							break;
							
						case 'date':
							if (Date.parse(data1) < Date.parse(data2))
								v = (bDescending) ? +1 : -1;
							else if (Date.parse(data1) > Date.parse(data2))
								v = (bDescending) ? -1 : +1;
							else 
								v = 0;
							break;
							
						case 'alphanumeric':
						default:
							if ((data1 + "") < (data2 + ""))
								v = (bDescending) ? +1 : -1;
							else if ((data1 + "") > (data2 + ""))
								v = (bDescending) ? -1 : +1;
							else 
								v = 0;
					}

					return v;
				}
				
				return _compare;
			}
			
			//Function used to replace all the occurences of the string		
			function replaceIt(sString, sReplaceThis, sWithThis) 
			{ 
			if (sReplaceThis != "" && sReplaceThis != sWithThis) 
			{ 
				var counter = 0; 
				var start = 0; 
				var before = ""; 
				var after = ""; 
				while (counter<sString.length) 
				{ 
					start = sString.indexOf(sReplaceThis, counter); 
					if (start == -1) 
					{ 
						break; 
					} 
					else 
					{ 
						before = sString.substr(0, start); 
						after = sString.substr(start + sReplaceThis.length, sString.length); 
						sString = before + sWithThis + after; 
						counter = before.length + sWithThis.length; 
					} 
				} 
			} 
			return sString; 
		}				
//--------------------------------------------------------------------------------------------
//Auth: Uma
//Date: 09/01/2006
//Desc: This function is used to check if user has Caps Lock ON 
//		while entering password / setting new password

function capsDetect(oTxtpassword,e,oCapsWarning)
{
	var oCapWarningId = oCapsWarning.id;
	var point = fGetXYcord(oTxtpassword);
	//display settings for the warning message
	with (document.getElementById(oCapWarningId).style) 
	{
		left = point.x;
		top  = point.y+oTxtpassword.offsetHeight+1;
	}
	
//if the browser did not pass event information to the handler,
//check in window.event
	if( !e ) 
	{ 
		e = window.event; 
	} 
	if( !e ) 
	{ 
		return; 
	}
//what (case sensitive in good browsers) key was pressed
//this uses all three techniques for checking, just in case
	var theKey = 0;
	
	if( e.which ) 
	{ 
		theKey = e.which;      //Netscape 4+, etc.
	} 
	else if( e.keyCode )      //Internet Explorer, etc.
	{ 
		theKey = e.keyCode; 
	} 
	else if( e.charCode ) 
	{ 
		theKey = e.charCode  //Gecko - probably not needed
	} 
	
//was the shift key was pressed
	var theShift = false;
	if( e.shiftKey )
	{ 
		theShift = e.shiftKey; //Internet Explorer, etc.
	} 
	else if( e.modifiers )	  //Netscape 4
	{ 
//check the third bit of the modifiers value (says if SHIFT is pressed)
		if( e.modifiers & 4 ) 
		{ 
		//bitwise AND
			theShift = true;
		}
	} 
//if upper case, check if shift is not pressed
    if( theKey > 64 && theKey < 91 && !theShift )
    {
		document.getElementById(oCapWarningId).style.display = '';
    }
 //if lower case, check if shift is pressed
    else if( theKey > 96 && theKey < 123 && theShift ) 
	{
		document.getElementById(oCapWarningId).style.display = '';
	}
	else
	{
		document.getElementById(oCapWarningId).style.display = 'none';
	}

//function used to determine location of the warning message.
	function fGetXYcord(aTag)
	{
		var oTmp = aTag;
		var pt = new Point(0,0);	
		do 
		{
  			pt.x += oTmp.offsetLeft;
  			pt.y += oTmp.offsetTop;
  			oTmp = oTmp.offsetParent;
		} while(oTmp.tagName!= "BODY");
		return pt;
	}
//function to get x-y cordinates
	function Point(iX, iY)
	{
		this.x = iX;
		this.y = iY;
	}
}
//--------------------------------------------------------------------------------------------	
//--------------------------------------------------------------------------------------------	
//--------------------------------------------------------------------------------------------
//Auth: Navin Joseph
//Date: 27/12/2006
//Desc: similar to ToggleVisibility but added the additional fuctionality of with child node
//----------------------------------------------------------------------
//-----------------------------
//Function used to toggle visibility
	function ToggleVisibility(ElementID,ImageID)
	{
	// pass in the ID of the element and the image we want to toggle
	// for IE
	if (document.all)    
	{ 
		var oImage  = document.images[ImageID];
		var oElement = eval("document.all." + ElementID + ".style");
		var hidden = "none";	
		var visible = "";	
	}
	// for Netscape 4.x
	else if (document.layers) 
	{ 
		var oImage  = document.images[ImageID];
		var oElement = document.layers[ElementID];
		var hidden = "hide";	
		var visible = "show";
	}
	//for Netscape 6+
	else	
	{	
		var oImage = document.getElementById(ImageID);
		var oElement = document.getElementById(ElementID).style;
		var hidden = "none";	
		var visible = "";
	}
	// for Netscape 4.x
	if (document.layers) 
	{ 
		if ( oElement.visibility == hidden) 
		{		
			// it was OFF, now turn it ON
			oImage.src = 'images/treeMinimize.gif';
			oElement.visibility = visible;
		} 
		else 
		{
			// it was ON, now turn it OFF
			oImage.src = 'images/treeMaximize.gif';
			oElement.visibility = hidden;
		}
	}
	// all other browsers
	else 
	{	
		if ( oElement.display == "none") 
		{		
			// it was OFF, now turn it ON
		
			oImage.src = 'images/treeMinimize.gif';
			oElement.display = visible;
		} 
		else 
		{
			// it was ON, now turn it OFF
			oImage.src = 'images/treeMaximize.gif';
			oElement.display = hidden;
		}
	}
}	
	

	//Function to encode escape sequences (Equivalent to Server.HtmlEncode)
	function htmlEncode(source, display, tabs)
	{
		function special(source)
		{
			var result = '';
			for (var i = 0; i < source.length; i++)
			{
				var c = source.charAt(i);
				if (c < ' ' || c > '~')
				{
					c = '&#' + c.charCodeAt() + ';';
				}
				result += c;
			}
			return result;
		}
		
		function format(source)
		{
			// Use only integer part of tabs, and default to 4
			tabs = (tabs >= 0) ? Math.floor(tabs) : 4;
			
			// split along line breaks
			var lines = source.split(/\r\n|\r|\n/);
			
			// expand tabs
			for (var i = 0; i < lines.length; i++)
			{
				var line = lines[i];
				var newLine = '';
				for (var p = 0; p < line.length; p++)
				{
					var c = line.charAt(p);
					if (c === '\t')
					{
						var spaces = tabs - (newLine.length % tabs);
						for (var s = 0; s < spaces; s++)
						{
							newLine += ' ';
						}
					}
					else
					{
						newLine += c;
					}
				}
				// If a line starts or ends with a space, it evaporates in html
				// unless it's an nbsp.
				newLine = newLine.replace(/(^ )|( $)/g, '&nbsp;');
				lines[i] = newLine;
			}
			
			// re-join lines
			var result = lines.join('<br />');
			
			// break up contiguous blocks of spaces with non-breaking spaces
			result = result.replace(/  /g, ' &nbsp;');
			
			// tada!
			return result;
		}

		var result = source;
		
		// ampersands (&)
		result = result.replace(/\&/g,'&amp;');

		// less-thans (<)
		result = result.replace(/\</g,'&lt;');

		// greater-thans (>)
		result = result.replace(/\>/g,'&gt;');
		
		if (display)
		{
			// format for display
			result = format(result);
		}
		else
		{
			// Replace quotes if it isn't for display,
			// since it's probably going in an html attribute.
			result = result.replace(new RegExp('"','g'), '&quot;');
		}

		// special characters
		result = special(result);
		
		// tada!
		return result;
	}

//--------------------------------------------------------------------------------------------
//Auth: Arvind Paul
//Date: 05/28/2008
//Desc: This function is used to limit the number of characters being entered
//		and prompt if the character limit is exceeded.
function CountCharactersInTextArea(fieldName, fieldDescription, maxLength) 
{
    var field = GetObjectByID(fieldName);
    var fieldCounter = GetObjectByID(fieldName + '_counter');
    var remainingCharacters;
    
    if (field.value.length > (Number(maxLength))) // if too long...trim it!
    {
        field.value = field.value.substring(0, (Number(maxLength)));
        alert(fieldDescription + " has to be limited to " + maxLength + " characters.");
    }
    
    if (fieldCounter != null)
    {
        remainingCharacters = maxLength - field.value.length;
        fieldCounter.innerHTML = '<font color="Green"><i>You can type ' + remainingCharacters + ' more characters.</i></font>';
    }
}
/* utility functions */
function GetWindowWidth()
{
	var width =
		document.documentElement && document.documentElement.clientWidth ||
		document.body && document.body.clientWidth ||
		document.body && document.body.parentNode && document.body.parentNode.clientWidth ||
		0;
		
	return width;
}
function GetWindowHeight()
{
    var height =
		document.documentElement && document.documentElement.clientHeight ||
		document.body && document.body.clientHeight ||
  		document.body && document.body.parentNode && document.body.parentNode.clientHeight ||
  		0;
  		
  	return height;
}
function MM_preloadImages() 
{
    var doc = document; 
    if(doc.images)
    { 
        if(!doc.MM_p)
        {
			doc.MM_p = new Array();
        }
        var icnt, j, ImgFiles
        icnt = 0;
        j = doc.MM_p.length
        ImgFiles = MM_preloadImages.arguments; 
        for(icnt = 0; icnt< ImgFiles.length; icnt++)
        {
			if (ImgFiles[icnt].indexOf("#") != 0)
			{
				doc.MM_p[j] = new Image; 
				doc.MM_p[j++].src = ImgFiles[icnt];
			}
        }
    }
}
// javascript to cancel page event, works fine in IE and firefox.
function CancelPgEvent(evt)
{
	if(evt!=null)
	{
		if (window.event)
		{
			window.event.returnValue = false;
		}
		else
		{
			evt.preventDefault();
		}
	}
}
// javascript method used to get a elements left and top position
function FindElementPosition(obj) 
{
	var curleft = curtop = 0;
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
/* 
	Added value script for isValidInteger method, isvalidInteger will not allow
	zeros at the beginning, this method will check numeric value from 0 - 9.
*/
function IsValidNumeric(objElement)
{
	var strNumericChars = "0123456789";
	var bIsValidNumeric = true;
	for (var i = 0; i < objElement.value.length; i++)
	{
		if(strNumericChars.indexOf(objElement.value.charAt(i)) == -1)
		{
			bIsValidNumeric = false;
			break;
		}
	}
	return bIsValidNumeric;
}
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
// Javascript function that can be used to add a event to a control.
var Dom = 
 {
    get: function(el) 
    {
        if (typeof el === 'string') 
        {
            return document.getElementById(el);
        }
        else
        {
            return el;
        }
    },
    add: function(el, dest) 
    {
        var el = this.get(el);
        var dest = this.get(dest);
        dest.appendChild(el);
    },
    remove: function(el) 
    {
        var el = this.get(el);
        el.parentNode.removeChild(el);
    }
};
var Event = 
{
    add: function() 
    {
        if (window.addEventListener) 
        {
            return function(el, type, fn) 
            {
                Dom.get(el).addEventListener(type, fn, false);
            };
        } 
        else if (window.attachEvent) 
        {
            return function(el, type, fn) 
            {
                var f = function() 
                {
                    fn.call(Dom.get(el), window.event);
                };
            Dom.get(el).attachEvent('on' + type, f);
            };
        }
    }()
};

function ToggleDatePicker(inputfield, triggerele, minDate, maxDate) {
    Calendar.setup({
        inputField: inputfield,
        trigger: triggerele,
        animation: false,
        fdow: 1,
        min: parseInt(minDate),
        max: parseInt(maxDate),
        bottomBar: false,
        dateFormat: '%m/%d/%Y',
        onSelect: function() { document.getElementById(inputfield).focus(); this.hide(); }
    });
}
function ParseDate(strDate)
{
	var strRetDateVal, strDay, strMon, strYear;
	strYear = strDate.substring(0, 4);
	strDate = strDate.replace(strYear, '');
	strMon = strDate.substring(0, 2);
	strDate = strDate.replace(strMon, '');
	strDay = strDate;
	strRetDateVal = strMon + "/" + strDay + "/" + strYear;
	return strRetDateVal;
}
