
//PCHG! 13-Oct-03
//	Now selecting the content of text box and not leaving it if data is invalid
//
IE4 = (document.all && !document.getElementById) ? true : false;
NS4 = (document.layers) ? true : false;
IE5 = (document.all && document.getElementById) ? true : false;
NS6 = (!document.all && document.getElementById) ? true : false;

//AADD:4-10-08:Compare Modes like MODE.Add etc rather than 1 or 2
var MODE = {Review:1, Add:2, Change:3, Delete:4, Confirm:5};

//trim - removes white spaces
function trim(str)
{
	return( (""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );
}//trim
	
//getGridRowObj
//	@gridname
//	@row
//	@fieldname
// 3-26-08:Changes made to switch to VS2005
function getGridRowObj(gridname, row, fieldname)
{
	//return getObject(gridname + '__ctl' + String(row) + '_' + fieldname);
	return getObject(gridname + '_ctl' + getPaddedRow(row) + '_' + fieldname);
}//getGridRowObj

function getPaddedRow(row)
{
    var len = String(row).length;
    if (len < 2)
        return '0' + String(row);
    else
        return row;
}//getPaddedRow

//findGrid - PADD! 13-oct-03
//
function findGrid()
{
	var indx;
	
	var totfrm=document.forms.length;
	for(fcnt = 0; fcnt < document.forms.length; fcnt++)
	{
		for(i = 0; i < document.forms[fcnt].elements.length; i++)
		{
			var elm = document.forms[fcnt].elements[i];
			if(elm.id.indexOf("dgAdd") == 0 || elm.id.indexOf("dgChange") == 0)
			{
				indx = elm.id.indexOf("_");
				return document.getElementById(elm.id.substr(0, indx));	
			}//if
		}//for
	}
}//findGrid

//findGrid - PADD! 12-Apr-07
// CKK 06-12-2007 I created this function under the name findBoundedControlByName already
/*function findGridByName(gridname)
{
	var indx;
	
	var totfrm=document.forms.length;
	for(fcnt = 0; fcnt < document.forms.length; fcnt++)
	{
		for(i = 0; i < document.forms[fcnt].elements.length; i++)
		{
			var elm = document.forms[fcnt].elements[i];
			if(elm.id.indexOf(gridname) == 0)
			{
				indx = elm.id.indexOf("_");
				return document.getElementById(elm.id.substr(0, indx));	
			}//if
		}//for
	}
}//findGridByName*/

function HideOrShowHeadertable(tableName,gridName)
{
	var objgrid;
	if(gridName)
		objgrid = findBoundedControlByName(gridName);
	else
		objgrid= findGrid();
		
	if(objgrid)
	{
		var objhead = getObject(tableName)
		if(objhead)
		{
			objhead.style.visibility = "visible";
			objhead.style.borderCollapse = "collapse";
		}
	}
	else
	{
		var objhead = getObject(tableName)
		if(objhead)
		{
			objhead.style.visibility = "hidden";
			objhead.style.borderCollapse = "separate";
		}
	}
}//HideOrShowHeadertable

function findBoundedControlByName(name)
{
	var indx;
	
	var totfrm=document.forms.length;
	for(fcnt = 0; fcnt < document.forms.length; fcnt++)
	{
		for(i = 0; i < document.forms[fcnt].elements.length; i++)
		{
			var elm = document.forms[fcnt].elements[i];
			if(elm.id.indexOf(name) == 0)
			{
				indx = elm.id.indexOf("_");
				return document.getElementById(elm.id.substr(0, indx));	
			}//if
		}//for
	}
}//findBoundedControlByName

//findReviewGrid - SADD! 06-Nov-03
//
function findReviewGrid()
{
	var indx;
	var totfrm=document.forms.length;
	for(fcnt = 0; fcnt < document.forms.length; fcnt++)
	{
		for(i = 0; i < document.forms[fcnt].elements.length; i++)
		{
			var elm = document.forms[fcnt].elements[i];
			if(elm.id.indexOf("dgReview") == 0)
			{
				indx = elm.id.indexOf("_");
				return document.getElementById(elm.id.substr(0, indx));	
			}//if
		}//for
	}
}//findReviewGrid
	
//define global arrays to store default values for segment validations
// the values generated out of the segment validation table will override this
var arrSegNames = new Array();
var arrMinLens = new Array();
var arrMaxLens = new Array();
var arrDataTypes = new Array();

//setValidations -- PADD! Oct-10-2003
//	@codetype - FND/CLS etc.
//	@codename - Fund/Class etc.
//	@minLen - minimum length of code
//	@maxLen - maximum length of code
//	@dataType - allowable data type
//
function setValidations(codetype, codename, minLen, maxLen, dataType)
{
	arrSegNames[codetype] = codename;
	arrMinLens[codetype] = minLen;
	arrMaxLens[codetype] = maxLen;
	arrDataTypes[codetype] = dataType;
}//setValidations

//initSegCodes -- PADD! Oct-10-2003
//	this should be called to initialize the default values from segment 
//	code setup pages
//
function initSegCodes()
{
	//call this so that this is initialized only once.
	if (arrSegNames.length > 0)
		return;
	//following loads the default validation sets in the internal arrays
	setValidations("FND", "Fund", 2, 2, "N");
	setValidations("FUN", "Function", 3, 3, "N");
	setValidations("CLS", "Class",  3, 3, "N");
	setValidations("OBJ", "Object", 4, 4, "N");
	setValidations("STA", "State",  3, 3, "N");
	setValidations("SFX", "Suffix", 4, 4, "N");
	setValidations("PGM", "Program", 3, 3, "N");
}//initSegCodes

//HasValidChars -- PADD! Oct-10-2003
//	@sText - text to check
//	@ValidChars - valid characters
//	This checks if the text has any invalid characters 
//
function hasValidChars(sText, ValidChars)
{
	var i;
	var c;
	for (i = 0; i < sText.length; i++) 
	{ 
		c = sText.charAt(i); 
		if (ValidChars.indexOf(c) == -1) 
		{
			return false;
		}//if
	}//for
	return true;
}//HasValidChars

//IsEmpty -- PADD! 10-Oct-03
//	@val - the value 
//	whether empty or not
//
function isEmpty(val)
{
	if(!val)
		return true;
	if(typeof val == "undefined")
		return true;
	return (trim(val).length == 0);
}//isEmpty

//IsNumeric -- PADD! Oct-10-2003
//	@sText - text to check
//
function isNumeric(sText)
{
	var ValidChars = "0123456789";
	return hasValidChars(sText, ValidChars);
}//isNumeric

//IsAlphabetic -- PADD! Oct-10-2003
//	@sText - text to check
//
function isAlphabetic(sText)
{
	var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	return hasValidChars(sText, ValidChars);
}//isNumeric

//IsAlphaNumeric -- PADD! Oct-10-2003
//	@sText - text to check
//
function isAlphaNumeric(sText)
{
	var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01223456789";
	return hasValidChars(sText, ValidChars);
}//isNumeric

//validCode -- PADD! Oct-10-2003
//	@codetype - code type FND/CLS etc.
//	@obj - the control whose value to check
//	@returnOnEmpty - return this if the control value is empty
//
//	Following is called to check the segment codes. It checks for the
//	globalCodeMinLen etc that should be defined dynamically by the calling page
//	but if they are not defined then default checks are made 
//
function validCode(codetype, obj, returnOnEmpty)
{
	//initialize the arrays - it happens only once
	initSegCodes();
	
	var code = obj.value;
	var minlen, maxlen, datatype;	
	var indx;
	var codename = arrSegNames[codetype];
	
	//we will return that empty codes are not valid
	if(isEmpty(code))	
		return returnOnEmpty;
		
	//load the default values if the global values are not provided.
	if(typeof globalCodeMinLen != "undefined" &&  globalCodeMinLen > 0)
		minlen = globalCodeMinLen;
	else
		minlen = arrMinLens[codetype];
		
	if (typeof globalCodeMaxLen != "undefined" && globalCodeMaxLen > 0)
		maxlen = globalCodeMaxLen;
	else
		maxlen = arrMaxLens[codetype];
	
	if (typeof globalCodeDataType != "undefined" && (globalCodeDataType == "A" || globalCodeDataType == "N" || globalCodeDataType == "X"))
		datatype = globalCodeDataType;
	else
		datatype = arrDataTypes[codetype];

	//check the code for min len and max len
	if(code.length < minlen)
		return codename + " Code must be at least " + minlen + " characters";
	if(code.length > maxlen)
		return codename + " Code must be less than " + maxlen + " characters";
	
	//check the code for data type	
	switch (datatype)
	{
		case "A":
			if(!isAlphabetic(code))
				return codename + " Code must be Alphabetic.";
			break;
			
		case "N":
			if(!isNumeric(code))
				return codename + " Code must be Numeric.";
			break;
			
		case "X":
			if(!isAlphaNumeric(code))
				return codename + " Code must be Alphanumeric."; 
			break;
	}//switch
	return true;
}//validCode

//onBlurCheck - PADD! 10-Oct-03
//	@codetype - FND/CLS etc.
//	@obj - the control
//	This is to be called when onblur of each code input box
//
function onBlurSegCode(codetype, obj)
{
	var str = validCode(codetype, obj, true);
	if(str == true)
		;
	else
	{
		alert(str);
		obj.select();
		obj.focus();
	}//else
	
	CheckDuplicates(obj);
}//onBlurCheck

//checkMaxLen - RADD! 13-Oct-03
//	checks if the pased value is valid integer or not
function validInt(value)
{
	if(isNaN(parseInt(value)))
		return false;
	else
		return true;	 
}//validInt

//checkSegType - RADD! 13-Oct-03
//	This is to be called when onblur of each SEGMENT TYPE input box
//  Validation still to be added for this input box and to be confirmed from Piyush and Joseph
function checkSegType(obj)
{
	var segtype = obj.value;
	
}//checkSegType

//checkMinLen - RADD! 13-Oct-03
//	This is to be called when onblur of each MINIMUM LENGTH input box
function checkMinLen(obj)
{
	var ret = validInt(obj.value); 
	if(ret)
	{
		var minlen = obj.value;
		if(minlen < 0 || minlen > 5)
		{
			alert(MSG_MIN_SEGLEN);
		}
	}
	else
	{
		alert(MSG_MIN_SEGLEN);
	}		
}//checkMinLen

//checkMaxLen - RADD! 13-Oct-03
//	This is to be called when onblur of each Maximum Length input box and check its value against the Minimum Length input box.
function checkMaxLen(obj,minlenfield)
{
	var ret = validInt(obj.value);
	
	if(ret)
	{
		var maxlen = obj.value;
		var objminlen = getGridObj(obj, minlenfield);
		
		if(objminlen)
			minlen = objminlen.value;
			if(maxlen < minlen || maxlen > 5)
			{
				alert(MSG_MAX_SEGLEN);
			}	
	}
	else
	{
		alert(MSG_MAX_SEGLEN);
	}		
}//checkMaxLen


//onChangeSegCode - PADD! 10-Oct-03
//	this is to be called if above is not called. Any one of this to be called and not both
//
function onChangeSegCode(codetype, obj)
{
	var str = validCode(codetype, obj, true);
	if(str == true)
		;
	else
	{
		alert(str);
		obj.select();
		obj.focus();
	}//else
}//onChangeSegCode

//checkMark - PADD! 10-Oct-03
//	@obj - the control
//	This is used to enable the check mark in the row which is updated
//
function checkMarkForLookup(obj)
{
	var chkbox = getGridObject(obj, "chkSelected");
	var hdbox  = getGridObject(obj, "hdSelected");
	
	if(chkbox)
		chkbox.checked = true;
		
	if(hdbox)
		hdbox.value = 1;	
}//checkMarkForLookup

//checkMark - PADD! 10-Oct-03
//	@obj - the control
//	This is used to enable the check mark in the row which is updated
//
function checkMark(obj)
{
	var chkbox = getGridObj(obj, "chkSelected");
	var hdbox  = getGridObj(obj, "hdSelected");
	
	if(chkbox)
		chkbox.checked = true;
		
	if(hdbox)
		hdbox.value = 1;	
}//checkMark

//SADD - 20-Apr-04
//This is to uncheck the check mark
function uncheckMark(obj)
{
	var chkbox = getGridObj(obj, "chkSelected");
	var hdbox  = getGridObj(obj, "hdSelected");
	
	if(chkbox)
		chkbox.checked = false;
		
	if(hdbox)
		hdbox.value = 0;	
				
}//checkMark

//checkMark - RADD! 21-Oct-03
//	@obj - the control
//	This is used to enable the check mark in the row which is updated when lookup are used
//
function checkMarkChkBox(obj)
{
	var chkbox = getGridObject(obj, "chkSelected");
	var hdbox  = getGridObject(obj, "hdSelected");
	
	if(chkbox)
		chkbox.checked = true;
	if(hdbox)
		hdbox.value = 1;
		
		
}//checkMark

//SADD - 20-Apr-04
//This is to uncheck the check mark in case of lookup blur
function uncheckMarkChkBox(obj)
{
	var chkbox = getGridObject(obj, "chkSelected");
	var hdbox  = getGridObject(obj, "hdSelected");
	
	if(chkbox)
		chkbox.checked = false;
	if(hdbox)
		hdbox.value = 0;
}//checkMark

//checkMarkNE - SADD! 23-Apr-04
//	@obj - the control
//	This is used to enable the check mark if not empty
//
function checkMarkNE(obj)
{
	if (obj.value != '')
	{
		checkMark(obj);	
	}
}//checkMark

//checkMarkChkBoxNE - SADD! 23-Apr-04
//	@obj - the control
//	This is used to enable the check mark if not empty : for Lookup in datagrid
//
function checkMarkChkBoxNE(obj)
{
	if (obj.value != '')
	{
		checkMarkChkBox(obj);	
	}
}//checkMark

//getGridObj - PADD! 10-Oct-03
//	@obj- the control whose id is used to find
//	@fieldname - the name whose control is to be found
//Do not use this method when 'obj' is lookup control. use getGridObject() instead.
function getGridObj(obj, fieldname)
{
	return getObject(getGridID(obj, fieldname));
}//getDotNetObj

//getGridObject - RADD! 10-Oct-03
//	@obj- the control whose id is used to find
//	@fieldname - the name whose control is to be found
//	This is used to get grid object using a lookup control's id - because lookup control have extra _
//
function getGridObject(obj, fieldname)
{
	return getObject(getGridIDT(obj, fieldname));
}//getDotNetObj


//getGridID - PADD! 10-Oct-03
//	@obj -  the control whose id is used to find
//	@fieldname - whose id is created in this method
// Do not use this method when 'obj' is a lookup control. Use GetGridIDT() instead
function getGridID(obj, fieldname)
{
	var str;
	var objid = obj.id;
	var indx;
	
	indx = objid.lastIndexOf("_");	
	str = objid.substring(0, indx);	
	str = str + "_" + fieldname;
	return str;
}//getDotNetID

//getGridIDT - RADD! 10-Oct-03
//	@obj -  the control whose id is used to find
//	@fieldname - whose id is created in this method
//	This is used to get id of other controls in grid using the lookup control that is part of
//	grid. Because lookup control has extra _ we are using this method
function getGridIDT(obj, fieldname)
{
	var str;
	var strtwo;
	var objid = obj.id;
	var indx;
	var indxtwo;
		
	indx = objid.lastIndexOf("_");	
	str = objid.substring(0, indx);
	indxtwo = str.lastIndexOf("_");
	strtwo = str.substring(0,indxtwo);
	strtwo = strtwo + "_" + fieldname;
	return strtwo;
}//getDotNetID

//getObject
//	@id - 
//	following will return an object with passed id
//
function getObject(id)
{
	if(IE4)	
		return document.all(id);
	else if(NS4)
		return document.layers(id);
	else 
		return document.getElementById(id);
}//getObject

function $(id)
{
	return getObject(id);
}

function setFocus(obj)
{
	if(obj)
	{
		if(!obj.disabled)
		{
			obj.focus();
			if(typeof obj == "textbox")
				obj.select();
		}
	}
}//setFocus

//onClickCheck - PADD! 10-Oct-03
//	@obj - the check box
// This will not let user click or at least change the checkbox status
//  Dont ASK WHY - we want it...
//
function onClickCheck(obj)
{
	obj.checked = !(obj.checked);
}//onClickCheck

//needToSaveRow_Common - PADD! 11-Oct-03
//	@gridid - id of the grid to 
//	@nRow - row of the grid to check
//  Following is a common function called by each needToSaveRow() methods in each page
//	It checks for the chkSelected or hdSelected values if they are true or not
//
function needToSaveRow_Common(gridid, nRow)
{
		var chkSelected = getGridRowObj(gridid, nRow, "chkSelected");
		var hdSelected = getGridRowObj(gridid, nRow, "hdSelected");
		var bCheck;

		bCheck = false;
		if(chkSelected)
			bCheck = chkSelected.checked;
		if(hdSelected)
			bCheck = (parseInt(hdSelected.value) > 0);
		return bCheck;
}//needToSave_Common

//needToSaveRow - PADD! 11-Oct-03
//	@gridid - 
//	@nrow - 
//	This function should be overridden in each page
function needToSaveRow(gridid, nRow)
{
	return needToSaveRow_Common(gridid, nRow);
}//needToSaveRow

//askCancelChanges - PADD! 11-Oct-03
//	following is called by onCancel
//  it calls needToSaveRow which is defined in each page
//
function askCancelChanges()
{
	var objcurrmode = getObject('ctlModeButtons_hdCurrentMode');
	if (objcurrmode)
	{
		//if current mode is review then do not check for any changes
		if (objcurrmode.value == '1')
		{
			return true;
		}
	}
	
	var objgrid = findGrid();
	if (!objgrid) return;
	for (var i=2; i < objgrid.rows.length + 1; i++)
	{
		if(needToSaveRow(objgrid.id, i) == true)
		{
			//return (confirm(MSG_CONFIRM_CANCEL));
			if (confirm(MSG_CONFIRM_CANCEL) == true)
			{
				//set the LastAction from 'Find" to ""
				//this is because if some data was changed and then 
				//user cancels the changes, a new set of data needs to be
				//refelected in the next mode, otherwise the changed data might
				//show up again
				var hdnLastAction = getObject("ctlModeButtons_hdLastAction");
				if (hdnLastAction)
				{
					hdnLastAction.value = '';
				}
				return true;
			}
			else
			{
				//do not cancel changes, remain in same window
				return false;
			}
		}//if
	}//for i
	return true;
}//askCancelChanges
	
/* ---- PREMOVE! This if needed put in every page and then remove this --
function OnFIDPageUnload(bConfirm)
{
	if(typeof bConfirm == "undefined" || bConfirm == false)
		return;
	alert("You are about to unload this page: " + window.location.href);
	window.location = "javascript:void(0);";
	return false;
}//OnFIDPageUnload
------------------------------------------------------------------------- */

function OpenErrWindow(url)
{
	var oNewWindow;
	//SMCHG : 8/6/07 : set the window name from null to '' to avoid multiple browser to use the same window
	oNewWindow = window.open(url, "", "height=400, width=480, top=100, left=600, resizable=yes, scrollbars=yes, toolbar=no, menubar=no, location=no, status=no", true);
	oNewWindow.focus();
}//OpenErrWindow

function OpenLookupWindow(url)
{
	var oNewWindow;
	//SMCHG : 8/6/07 : set the window name from null to '' to avoid multiple browser to use the same window
	oNewWindow = window.open(url, "", "height=300, width=350, top=100, left=600, resizable=yes, scrollbars=yes, toolbar=no, menubar=no, location=no, status=no", true);
	oNewWindow.focus();
}//OpenLookupWindow

function popupWindow(url, title)
{
	var oNewWindow;
	oNewWindow = window.open(url, title, "height=350, width=490, top=100, left=300, resizable=yes, scrollbars=yes, toolbar=no, menubar=no, location=no, status=no", true);
	//oNewWindow.opener.disabled = "disabled";
	oNewWindow.focus();
	return oNewWindow;
}//popupWindow

function GetCurrentRowControl(objControl, strothercontrol)
{
	//get the control name for default control or a new control in the same row
	var objid = objControl.id;

	return GetCurrentRowControlById(objid, strothercontrol);
}//GetCurrentRowControl

function GetCurrentRowControlById(objControlId, strothercontrol)
{
	//get the control name for default control or a new control in the same row
	var strbeforeval;
	var strafterval;
	var objid = objControlId;
	var indx;
	var lControlName;
	
	indx = objid.lastIndexOf("_");
	strbeforeval = objid.substring(0, indx);	
	strafterval = objid.substring(indx+1,objid.length);	
	
	if (strothercontrol.length != 0 )
	{
		//return back the specified control
		lControlName = strbeforeval + '_' + strothercontrol;
	}
	else
	{
		//return back the default control
		lControlName = strbeforeval + '_' + strafterval;
	}
	return lControlName;
}//GetCurrentRowControlById

function CheckDuplicates(objControl)
{
	//check if Code already Exists

	if (objControl.value.length == 0)
	{
		//return if cell is empty
		return false;
	}
	
	var ctl;
	var msg="";
	var valid=true;
	var strcodes="";
	var ctr=0;
	var indx;

	var objgrid = findGrid();
	
	var lSelectedControl;
	lSelectedControl = GetCurrentRowControl(objControl, '');

	var controlname;
	indx = objControl.id.lastIndexOf("_");	
	var controlname = objControl.id.substring(indx+1, objControl.id.length);	
	
	ctl = objgrid.id;
	
	//check in each row for that column if it is a duplicate
	for ( var i=2; i<objgrid.rows.length + 1; i++ )
	{
		var objCurrentRowControl = getGridRowObj(ctl, i, controlname);

		if(objCurrentRowControl)
		{
			if (objCurrentRowControl.value.length != 0 && lSelectedControl != objCurrentRowControl.id)
			{
				if (ctr > 0)
				{
					strcodes = strcodes + ","
				}
				strcodes = strcodes + '"' + objCurrentRowControl.value + '"';
				ctr = ctr + 1;
			}
		}
	}//for
	
	var strthiscode;
	strthiscode = '"' + objControl.value + '"';
	
	if (InStr(strcodes,strthiscode) > -1)
	{
		alert(objControl.value + ' already exists in this column.');
		objControl.value = '';
		objControl.select();
		objControl.focus();
		return false;
	}
	return true;
}//CheckDuplicates

function InStr(strSearch, charSearchFor)
/*
InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
						was found in the string str.  (If the character is not
						found, -1 is returned.)
	                        
Requires use of:
	Mid function
	Len function
*/
{
	for (i=0; i < strSearch.length; i++)
	{
		if (charSearchFor == Mid(strSearch, i, charSearchFor.length))
		{
			return i;
		}
	}
	return -1;
}//InStr

function Mid(str, start, len)
/***
        IN: str - the string we are LEFTing
            start - our string's starting position (0 based!!)
            len - how many characters from start we want to get

        RETVAL: The substring from start to start+len
***/
{
        // Make sure start and len are within proper bounds
        if (start < 0 || len < 0) return "";

        var iEnd, iLen = String(str).length;
        if (start + len > iLen)
                iEnd = iLen;
        else
                iEnd = start + len;

        return String(str).substring(start,iEnd);
}//Mid

function showtip(current,e,ctrl)
{
	//display tooltip
	var objCode;
	objCode=getObject(ctrl + "_hdCode");

	var objDesc;
	objDesc=getObject(ctrl + "_hdDescription");
	
	if(!objDesc)
		return;
		
	var text=objDesc.value;

	if (document.all)
	{
		thetitle=text.split('<br>')
		if (thetitle.length > 1)
		{
			thetitles=""
			for (i=0; i<thetitle.length-1; i++)
			thetitles += thetitle[i] + "\r\n"
			current.title = thetitles
		}
		else current.title = text
	}

	else if (document.layers)
	{
		document.tooltip.document.write( 
			'<layer bgColor="#FFFFE7" style="border:1px ' +
			'solid black; font-size:12px;color:#000000;">' + text + '</layer>')
		document.tooltip.document.close()
		document.tooltip.left=e.pageX+5
		document.tooltip.top=e.pageY+5
		document.tooltip.visibility="show"
	}
}//showtip

function hidetip()
{
	//hide tooltip
	if (document.layers)
		document.tooltip.visibility="hidden"
}//hidetip

//ShowErrorInfoBox - SADD! 31-Mar-04
//	@errortype - E- Error, I - Information
//	@errormessage - Error message to be displayed
//display error messages during form validation in new window
function ShowErrorInfoBox(errortype, errormessage)
{
	//SMCHG : 8/6/07 : set the window name from null to '' to avoid multiple browser to use the same window
	if (errortype == 'E')
	{
		//open error window
		window.open('../include/frmErrInfoBox.aspx?ErrorType=E&Message=' + errormessage + '', '', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,dependent=yes,scrollbars=no,resizable=no,width=400,height=100,top=200, left=100', '_blank');
	}
	else
	{
		//open information window
		window.open('../include/frmErrInfoBox.aspx?ErrorType=I&Message=' + errormessage + '', '', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,dependent=yes,scrollbars=no,resizable=no,width=400,height=100,top=200, left=100', '_blank');
	}
}//ShowErrorInfoBox

function modalwin(url,mwidth,mheight, mtop, mleft)
{
	if (document.all&&window.print) //if ie5
	{
		eval('window.showModelessDialog(url,"","help:0;status=no;resizable:1;dialogWidth:'+mwidth+'px;dialogHeight:'+mheight+'px;dialogTop:'+mtop+'px;dialogLeft:'+mleft+'px")')
	}
	else
	{
		eval('window.open(url,"","width='+mwidth+'px,height='+mheight+'px,top='+mtop+'px,left='+mleft+'px,resizable=1,scrollbars=1")')
	}
}//modalwin

function onBlurAmount(obj)
{
	var amt;
	//empty amount values are okay
	if (isEmpty(obj.value))
		return;
	obj.value = trim(obj.value);
	
	//get the float value	
	if(!isFloat(obj.value))
	{
		alert("Invalid amount value");
		obj.select();
		obj.focus();
		return;
	}//if

	amt = obj.value;
	amt = amt.replace(/,/g,"");
	
	amt = parseFloat(amt);
	
	if(checkMaxAmount(amt))
	{
		obj.value = amt;
		obj.value = formatAmountData(amt);
	}
	else
	{
		obj.select();
		obj.focus();
	}
}//onBlurAmount

function checkMaxAmount(amt)
{
	//get the amount
	if (amt > 999999999999)
	{
		alert("The amount is more than maximum value allowed");
		return false;
	}
	return true;
}//checkMaxAmount

function isFloat(sText)
{
	var ValidChars = "-0123456789.,";
	var bVal;		
	if(!hasValidChars(sText, ValidChars))
		return false;
	if(isNaN(parseFloat(sText)))
		return false;
	return true;
}//isNumeric
	
function formatAmountData(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + '' + dblValue + '.' + strCents);
}//formatAmountData

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}//isInteger

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}//stripCharsInBag

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}//daysInFebruary

function DaysArray(n) {
    for (var i = 1; i <= n; i++) 
    {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
    } 
   return this;
}//DaysArray

function isDate(dtStr)
{
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2099;

	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strMonth=dtStr.substring(0,pos1);
	var strDay=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy");
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month");
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day");
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date");
		return false;
	}
	return true;
}//isDate

function isDateValid(dtStr)
{
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2099;

	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strMonth=dtStr.substring(0,pos1);
	var strDay=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy");
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month");
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day");
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date");
		return false;
	}
	return true;
}//isDateValid

//Function to compare two dates
function compareDates(varDate1,varDate2,strCompare)
{
	try
	{
		//Assuming the dates are in mm/dd/yyyy formate
		var dt1 = varDate1.split("/");
		var dt2 = varDate2.split("/");
		//if date is not valid, return false
		if(dt1.length<3)
			return false;
		if(dt2.length<3)
			return false;
		//remove any leading zeroes so the parseInt method will work correctly
		//as long as year is passed in correctly, will never have problem
		if(dt1[0].charAt(0)=="0")
			dt1[0] = dt1[0].substring(1,2);
		if(dt1[1].charAt(0)=="0")
			dt1[1] = dt1[1].substring(1,2);
		if(dt2[0].charAt(0)=="0")
			dt2[0] = dt2[0].substring(1,2);
		if(dt2[1].charAt(0)=="0")
			dt2[1] = dt2[1].substring(1,2);
		//create the day, month, and year objects
		var objYear = parseInt(dt1[2]);
		var objMonth = parseInt(dt1[0]);
		var objDay = parseInt(dt1[1]);
		
		var objYear2 = parseInt(dt2[2]);
		var objMonth2 = parseInt(dt2[0]);
		var objDay2 = parseInt(dt2[1]);
		
		var dteDate1 = new Date(); 
		var dteDate2 = new Date(); 
		//set the values for the date and the time to zero
		//since that is not used in calculations
		//srinim033110: if we dont set the date along with the month, setmonth will try to set to 31
		//and if there is no 31st in that month, then pushes to next month. so set the date as 1st by default.
		dteDate1.setMonth(objMonth -1,objDay);
		//dteDate1.setDate(objDay);
		dteDate1.setFullYear(objYear);
		dteDate1.setHours(0,0,0,0);
		
		dteDate2.setMonth(objMonth2 -1,objDay2);
		//dteDate2.setDate(objDay2);
		dteDate2.setFullYear(objYear2);
		dteDate2.setHours(0,0,0,0);
		
		if ((strCompare == "LT") && (dteDate1 < dteDate2)) 
		{
		    return true; 
		}
		else if ((strCompare == "GT") && (dteDate1 > dteDate2)) 
		{
			return true; 
		}
		else if ((strCompare == "EQ") && (dteDate1.toString() == dteDate2.toString())) 
		{//CKK 02-01-07 == comparison was not working, comparing two strings works
			return true; 
		}
		else if ((strCompare == "LTE") && (dteDate1 <= dteDate2)) 
		{
			return true; 
		}
		else if ((strCompare == "GTE") && (dteDate1 >= dteDate2)) 
		{ 
			return true; 
		}
		else 
		{
			return false; 
		}
	}
	catch(e)
	{
		return false;
	}
}//compareDates

function GotoPage(obj)
{
	var strId = obj.id; 
	var lIdx = strId.lastIndexOf("_txtPageNum");
	var ctrlName = strId.substring(0, lIdx);
	
	var objPageNum = getObject(obj.id);
	if (objPageNum)
	{
		//check if it is a valid page number
		var objtotrec = getObject(ctrlName + '_hdTotalRecords');
		if (objtotrec)
		{
			if (parseInt(objPageNum.value) <=0 || parseInt(objPageNum.value) > parseInt(objtotrec.value))
			{
				alert('Record number should be greater than 0 and less than the total records.')
				return false;
			}
			
			var objNewPageNum = getObject(ctrlName + '_hdNewPageNum');
			if (objNewPageNum)
			{
				objNewPageNum.value = objPageNum.value;
			}
			
			//loop through all the forms and see if the control is available there and
			//submit it
			var indx;
			
			var totfrm=document.forms.length;
			for(fcnt = 0; fcnt < document.forms.length; fcnt++)
			{
				for(i = 0; i < document.forms[fcnt].elements.length; i++)
				{
					var elm = document.forms[fcnt].elements[i];
					if(elm.id.indexOf(ctrlName + "_hdNewPageNum") == 0)
					{
						document.forms[fcnt].submit();
						return true;
					}//if
				}//for
			}
		}
		else
		{
			alert('Cannot validate current request.');
			return false;
		}
	}
}//GotoPage

//function to get the values from the query string
function Request_QueryString(FieldName) 
{
	var QueryString = '' 
	var FieldValue = '' 
	var Start = 0 
	var End = 0 
	// Grab the querystring 
	QueryString = window.location.search 
	// Convert field name and querystring to lowercase so that 
	// function is not case sensitive. 
	FieldName = FieldName.toLowerCase() 
	QueryString = QueryString.toLowerCase() 
	// Look for field as first item ... 
	Start = QueryString.indexOf(FieldName + '=') 
	// If field is not the first ... 
	if(Start!=1) { 
	// Search appended fields 
	Start = QueryString.indexOf('&' + FieldName + '=') 
	// If field wasn't found at all, return empty string. 
	if(Start==-1)
	{
	return(FieldValue)
	} 
	// Setup start position after equal sign 
	Start += FieldName.length + 2 
	} 
	else 
	{ 
	// Setup start position after equal sign 
	Start = FieldName.length + 2 
	} 
	// Search for beginning of next field 
	End = QueryString.indexOf('&', Start + 1) 
	// if another field was not defined, set end to length of querystring 
	if(End==-1){End=QueryString.length} 
	// Parse the field value 
	FieldValue = window.location.search.substring(Start, End) 
	// unescape special characters within the value (such as %20 = space character) 
	FieldValue = unescape(FieldValue) 
	// Return the results 
	return(FieldValue) 
}//Request_QueryString

/* ================================================================================ Create Request Object ================================================================================ */ 
function request(){} 
	request.prototype.QueryString = Request_QueryString; 
	var Request = new request; 


//tooltip functions 
//------------------------------------------- start tooltip functions 
/*
var x,y,zInterval;
document.onmousemove = setMouseCoords;

function init() {
	for(i=0;i<document.getElementsByTagName("a").length;i++) {
		if(document.getElementsByTagName("a")[i].className == "toolLink") {
			document.getElementsByTagName("a")[i].onmouseout = hideToolTip;
		}
	}
}

function setMouseCoords(e) {
	if(document.all) {
		x = window.event.clientX;
		y = window.event.clientY;
	} else {
		x = e.pageX;
		y = e.pageY;
	}
}

function showToolTip(obj) 
{
	if (obj.value.length == 0)
		{return false;}
	var zText = checksinglequote(obj.value);
	doShowToolTip(zText);
}

function doShowToolTip(zText) 
{
	clearInterval(zInterval);
	document.getElementById("toolTip").style.top = (y+5) + "px";
	document.getElementById("toolTip").style.left = x + "px";
	document.getElementById("toolTip").innerHTML = checksinglequote(zText);
	document.getElementById("toolTip").style.display = "block";
	document.getElementById("toolTip").style.width = 250;
}

function hideToolTip() {
	document.getElementById("toolTip").style.display = "none";
	clearInterval(zInterval);
}

function checksinglequote(str)
{
	var vSingleQuote = str.indexOf("'"); 
	if (vSingleQuote > 0)
	{ 
		//there's a single quote in there somewhere 
		var vBeforeSingleQuote = str.substring(0,vSingleQuote); 
		//move just ahead of the single quote 
		vSingleQuote = (vSingleQuote + 1); 
		var vAfterSingleQuote = str.substring(vSingleQuote, (str.length)); 
		return vBeforeSingleQuote + "\'" + vAfterSingleQuote 
	} 
	return str;
}

this.onload = init;
*/
//------------------------------------------- end tooltip functions 

function hideSpanObject(obj)
{
	//hide the span
	if (obj)
	{
		obj.style.display = "none";
		obj.style.position = "absolute";
	}
}//hideSpanObject

function showAppError(appErrPath)
{
	document.location.href=appErrPath;
}//showAppError

//Next two functions set the url of the parent window based on the section id passed and sets
//the tree to that node too.
function setIndexBySec(secId)
{
	var parWindow = window.opener.parent.document;
	//var objTree = parWindow.getElementById("ctlAppTreeMenu_tvReviewAppStat");
	var objTreeArray = parWindow.getElementById("ctlAppTreeMenu_hdTreeArray");
	var arrTree = objTreeArray.value.split("~@");
	//var curIndex = objTree.selectedNodeIndex;

	var nset = false;
	var treeCtr = 0;

	while (!nset)
	{
		if (treeCtr >= arrTree.length) {break;}
		
		var curString = arrTree[treeCtr];

		if (curString.length > 0)
		{
			var curArrString = curString.split("^");
			
			if (secId == curArrString[1])
			{
				nset=true;
				//gotoSecNew(curArrString[3], curArrString[1], curArrString[2], curArrString[6]);
				//SMCHG: 09/29/2006: passing the parameters exactly as from clicking the tree node
				//gotoSecNew(curArrString[3], curArrString[1], curArrString[2], curArrString[6], curArrString[7], curArrString[8]);
				//ACHG:7-16-07:Modified to pass the Fiscal year as view errors was not taking the tree to the right node
				gotoSecNew(curArrString[3], curArrString[1], curArrString[2], curArrString[6], curArrString[7], curArrString[9], curArrString[8]);
			}
		}

		treeCtr = treeCtr + 1;
	}
}//setIndexBySec

function gotoSecNew(path, secid, type, parent, lvlno, index, curYear)
{
	var parWindow = window.opener.parent.document;
	var objUserMode = parWindow.getElementById("ctlAppTreeMenu_hdUserMode");

	window.close();
	
	if (InStr(path,"?") > -1)
	{
		window.opener.parent.location.href = path + "&Mode=" + objUserMode.value + "&secid=" + secid + "&type=" + type + "&parent=" + parent + "&lvlno=" + lvlno + "&index=" + index + "&fy=" + curYear;
	}
	else
	{
		window.opener.parent.location.href = path + "?Mode=" + objUserMode.value + "&secid=" + secid + "&type=" + type + "&parent=" + parent + "&lvlno=" + lvlno + "&index=" + index + "&fy=" + curYear;
	}
}//gotoSecNew

/*
function oldgotoSecNew(path, secid, type, index)
{
	var parWindow = window.opener.parent.document;
	var objUserMode = parWindow.getElementById("ctlAppTreeMenu_hdUserMode");

	window.close();
	
	if (InStr(path,"?") > -1)
	{
		window.opener.parent.location.href = path + "&Mode=" + objUserMode.value + "&secid=" + secid + "&type=" + type + "&index=" + index;
	}
	else
	{
		window.opener.parent.location.href = path + "?Mode=" + objUserMode.value + "&secid=" + secid + "&type=" + type + "&index=" + index;
	}
}
*/

/********************************* TOOL TIP CODE ***********************************/
/*
var oToolTip = new Object();
oToolTip._topDivZIndex = 10000;
oToolTip._oBody = null;
oToolTip._oHelperIframe = null;
oToolTip._oToolTipDiv = null;
oToolTip._mousePos = new Object();
// Add dynamic div to the page
oToolTip._init = function()
{
	// Creating and adding dynamic iframe to the page source.
	oToolTip._oBody = document.getElementsByTagName("BODY").item(0);
	oToolTip._oHelperIframe = document.createElement("IFRAME");
	
	if (oToolTip._oHelperIframe)//sadd
	{
		oToolTip._oHelperIframe.style.border = 0;
		oToolTip._oHelperIframe.width = 0;
		oToolTip._oHelperIframe.height = 0;
		oToolTip._oHelperIframe.style.position = "absolute";
		oToolTip._oBody.appendChild(oToolTip._oHelperIframe);

		// Creating and adding dynamic DIV to the page source (for the tool-tip).
		oToolTip._oToolTipDiv = document.createElement("DIV");
		oToolTip._oToolTipDiv.style.border = 0;
		oToolTip._oToolTipDiv.width = 0;
		oToolTip._oToolTipDiv.height = 0;
		oToolTip._oToolTipDiv.style.position = "absolute";
		oToolTip._oBody.appendChild(oToolTip._oToolTipDiv);

		oToolTip._attachToEvent(document, 'onmousemove', oToolTip._mousemove);
	}
}

// Should return the div actual width.
oToolTip._getToolTipDivWidth = function()
{
	// We are checking the inner table because of a bug in NS/Mozilla with the DIV-->offsetWidth
	var tableWidth = "" + oToolTip._oToolTipDiv.getElementsByTagName("table").item(0).offsetWidth;
	if(tableWidth.indexOf('px') > -1)
	{
		return parseInt(tableWidth.substring(0, tableWidth.infexOf('px')));
	} 
	else 
	{
		return tableWidth;
	}
}

// Should return the div actual Height.
oToolTip._getToolTipDivHeight = function()
{
	// We are checking the inner table because of a bug in NS/Mozilla with the DIV-->offsetHeight
	var tableHeight = "" + oToolTip._oToolTipDiv.getElementsByTagName("table").item(0).offsetHeight;
	if(tableHeight.indexOf('px') > -1)
	{
		return parseInt(tableHeight.substring(0, tableHeight.infexOf('px')));
	} 
	else 
	{
		return tableHeight;
	}
}

oToolTip._mousemove = function(e)
{
	if(typeof(e) == 'undefined')e = event;
	oToolTip._mousePos.Y = e.clientY;
	oToolTip._mousePos.X = e.clientX;
	if(oToolTip._oToolTipDiv.style.visibility == 'visible')
	{
		oToolTip._fixTipPosition();
	}
}

// Will move the div and the helper iframe to the given X and Y position
oToolTip._fixTipPosition = function()
{
	// Set the Y position
	if(oToolTip._mousePos.Y > Math.round(oToolTip._oBody.clientHeight / 2))
	{
		// Open to top
		oToolTip._oHelperIframe.style.top = oToolTip._mousePos.Y - oToolTip._getToolTipDivHeight() + oToolTip._oBody.scrollTop; 
	} 
	else 
	{
		// Open to bottom
		oToolTip._oHelperIframe.style.top = oToolTip._mousePos.Y + oToolTip._oBody.scrollTop; 
	}

	// Set the X position
	if(oToolTip._mousePos.X > Math.round(oToolTip._oBody.clientWidth / 2))
	{
		// Open to left
		oToolTip._oHelperIframe.style.left = oToolTip._mousePos.X - oToolTip._getToolTipDivWidth() + oToolTip._oBody.scrollLeft; 
	} 
	else 
	{
		// Open to right
		oToolTip._oHelperIframe.style.left = oToolTip._mousePos.X + 5 + oToolTip._oBody.scrollLeft; 
	}

	oToolTip._oToolTipDiv.style.top = oToolTip._oHelperIframe.style.top;
	oToolTip._oToolTipDiv.style.left = oToolTip._oHelperIframe.style.left;
}

oToolTip._attachToEvent = function(obj, name, func) 
{
	name = name.toLowerCase();
	// Add the hookup for the event.
	if(typeof(obj.addEventListener) != "undefined") 
	{
		if(name.length > 2 && name.indexOf("on") == 0) name = name.substring(2, name.length);
		obj.addEventListener(name, func, false);
	} else if(typeof(obj.attachEvent) != "undefined")
	{
		obj.attachEvent(name, func);
	} 
	else 
	{
		if(eval("obj." + name) != null)
		{
			// Save whatever defined in the event
			var oldOnEvents = eval("obj." + name);
			eval("obj." + name) = function(e) 
			{
				try
				{
					func(e);
					eval(oldOnEvents);
				} catch(e){}
			};
		} 
		else 
		{
			eval("obj." + name) = func;
		}
	}
}

// Will show the div and the helper iframe.
oToolTip.showToolTip = function(toolTipMessage)
{
	if (oToolTip._oHelperIframe)
	{
		oToolTip._oHelperIframe.style.zIndex = oToolTip._topDivZIndex++;
		var divContent = "<table style='border:1px solid black; font-family:verdana,sans serrif; font-size=11px; background-color:LightGoldenrodYellow' cellspacing='0' cellpading='0'><tr><td>" + toolTipMessage + "</td></tr></table>";
		oToolTip._oToolTipDiv.innerHTML = divContent; 
		oToolTip._mousePos
		oToolTip._oToolTipDiv.style.zIndex = oToolTip._topDivZIndex++;
		oToolTip._oHelperIframe.style.top = oToolTip._oToolTipDiv.style.top;
		oToolTip._oHelperIframe.style.left = oToolTip._oToolTipDiv.style.left;
		oToolTip._oHelperIframe.width = oToolTip._getToolTipDivWidth();
		oToolTip._oHelperIframe.height = oToolTip._getToolTipDivHeight();
		oToolTip._oHelperIframe.style.visibility = 'visible';
		oToolTip._oToolTipDiv.style.visibility = 'visible';

		oToolTip._fixTipPosition();
	}
}

// Will hide the div and the helper iframe.
oToolTip.hideToolTip = function()
{
	if (oToolTip._oHelperIframe)
	{
		oToolTip._oHelperIframe.style.visibility = 'hidden';
		oToolTip._oToolTipDiv.style.visibility = 'hidden';
	}
}

// Attach to the onload event
oToolTip._attachToEvent(window, 'onload', oToolTip._init);


function showToolTip(obj) 
{
	if (obj.value.length == 0)
		{return false;}
	var zText = checksinglequote(obj.value);
	
	oToolTip.showToolTip(zText);
}

function hideToolTip() 
{
	oToolTip.hideToolTip();
}

function checksinglequote(str)
{
	var vSingleQuote = str.indexOf("'"); 
	if (vSingleQuote > 0)
	{ 
		//there's a single quote in there somewhere 
		var vBeforeSingleQuote = str.substring(0,vSingleQuote); 
		//move just ahead of the single quote 
		vSingleQuote = (vSingleQuote + 1); 
		var vAfterSingleQuote = str.substring(vSingleQuote, (str.length)); 
		return vBeforeSingleQuote + "\'" + vAfterSingleQuote 
	} 
	return str;
}
*/

//--------------------- Tool Tip - End ----------------------//

//--------------------- New Toop Tip Code - Start -------------------//

 document.write("<div id=\"PopupDiv\"  style=\"position:absolute; top:25px; left:50px; padding:4px; display:none; border:1px solid black; background-color:LightGoldenrodYellow; color:#000000; font-family:verdana,sans serrif; font-size=10px; z-index:100\"> </div>");
 document.write("<iframe id=\"DivShim\"  src=\"javascript:false;\"  scrolling=\"no\"  frameborder=\"0\"  style=\"position:absolute; top:0px; left:0px; display:none;\"> </iframe>");

function showToolTip(obj,text)
{
    if (obj.value.length == 0)
	    {return false;}
	    var zText
    //if text exists, use that, else take the objects text
    if(text)
	    zText = checksinglequote(text);
    else
	    zText = checksinglequote(obj.value);
    	
    var DivRef = document.getElementById('PopupDiv');
    var IfrRef = document.getElementById('DivShim');

    if (DivRef && IfrRef)
    {
	    try
	    {
		    DivRef.style.display = "block";
		    DivRef.innerHTML = breakLines(40, zText);
    		
		    IfrRef.style.width = DivRef.offsetWidth;
		    IfrRef.style.height = DivRef.offsetHeight;

		    //was not displaying correctly scrolled in IE or at all in firefox
		    var pos = getAbsolutePosition(obj);
		    //alert("X: " + pos.x + " Y: " + pos.y);
		    DivRef.style.top = (pos.y+15) + "px"; 
		    IfrRef.style.top = (pos.y+15) + "px"; 
    	
		    DivRef.style.left = (pos.x+10) + "px";
		    IfrRef.style.left = (pos.x+10) + "px";
    		
		    /*DivRef.style.top = findPosY(obj)+15; 
		    IfrRef.style.top = findPosY(obj)+15; 
    	
		    DivRef.style.left = findPosX(obj)+10;
		    IfrRef.style.left = findPosX(obj)+10;*/
    		
		    IfrRef.style.zIndex = DivRef.style.zIndex - 1;
		    IfrRef.style.display = "block";
        
		    attachToEvent(obj, 'onmousedown', hideToolTip);
	    }
	    catch(e)
	    {
		    //do nothing
	    }
    }
}//showToolTip

function hideToolTip()
{
    var DivRef = document.getElementById('PopupDiv');
    var IfrRef = document.getElementById('DivShim');
    if (DivRef && IfrRef)
    {
	    DivRef.style.display = "none";
	    IfrRef.style.display = "none";
    }
}//hideToolTip

function checksinglequote(str)
{
	var vSingleQuote = str.indexOf("'"); 
	if (vSingleQuote > 0)
	{ 
		//there's a single quote in there somewhere 
		var vBeforeSingleQuote = str.substring(0,vSingleQuote); 
		//move just ahead of the single quote 
		vSingleQuote = (vSingleQuote + 1); 
		var vAfterSingleQuote = str.substring(vSingleQuote, (str.length)); 
		return vBeforeSingleQuote + "\'" + vAfterSingleQuote 
	} 
	return str;
}//checksinglequote

function attachToEvent(obj, name, func) 
{
	name = name.toLowerCase();
	// Add the hookup for the event.
	if(typeof(obj.addEventListener) != "undefined") 
	{
		if(name.length > 2 && name.indexOf("on") == 0) name = name.substring(2, name.length);
		obj.addEventListener(name, func, false);
	} else if(typeof(obj.attachEvent) != "undefined")
	{
		obj.attachEvent(name, func);
	} 
	else 
	{
		if(eval("obj." + name) != null)
		{
			// Save whatever defined in the event
			var oldOnEvents = eval("obj." + name);
			eval("obj." + name) = function(e) 
			{
				try
				{
					func(e);
					eval(oldOnEvents);
				} catch(e){}
			};
		} 
		else 
		{
			eval("obj." + name) = func;
		}
	}
}//attachToEvent

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}//findPosX

function findPosY(obj)
{
	if(typeof(e) == 'undefined')
		e = event;
	if(e)
	{	//error was taking place of e, so had to check for clientY
		//CKK 09/18/06
		if(e.clientY)
			return e.clientY - 15;
		else
		{
			e = event;
			if(e.clientY)
				return e.clientY - 15;
		}
	}

/*
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
*/

}//findPosY

function breakLines(max, text) 
{
	max--;
	text = "" + text;
	var temp = "";
	var chcount = 0; 
	for (var i = 0; i < text.length; i++) // for each character ... 
	{   
		var ch = text.substring(i, i+1); // first character
		var ch2 = text.substring(i+1, i+2); // next character
		if (ch == '\n') // if character is a hard return
		{  
			temp += ch;
			chcount = 1;
		}
		else
		{
			if (chcount >= max && ch == ' ') // line has max chacters on this line
			{
				temp += '<br>' + ch; // go to next line
				chcount = 1; // reset chcount
			}
			else  // Not a newline or max characters ...
			{
				temp += ch;
				chcount++; // so add 1 to chcount
			}
		}
	}
	return (temp); // sends value of temp back
}//breakLines

//---------------------- New Tool Tip Code - End ----------------------//

function Now_MMDDYYYY()
{
	//returns todays date in mm/dd/yyyy format
	var aceDate=new Date()
	var aceYear=aceDate.getYear()
	if (aceYear < 1000)
	aceYear+=1900
	var aceDay=aceDate.getDay()
	var aceMonth=aceDate.getMonth()+1
	if (aceMonth<10)
	aceMonth="0"+aceMonth
	var aceDayMonth=aceDate.getDate()
	if (aceDayMonth<10)
	aceDayMonth="0"+aceDayMonth
	return (aceMonth+"/"+aceDayMonth+"/"+aceYear);
}//Now_MMDDYYYY

//AADD:09_30_05:To replace all characters
function replaceAll( str, from, to )
{
	var idx = str.indexOf(from);
	while ( idx > -1 )
	{
		str = str.replace(from, to);
		idx = str.indexOf(from);
	}

	return str;
}//replaceAll

function formatObjText(obj)
{
	if(obj.value)
	{
		obj.value = CommaFormatted(replaceAll(obj.value, ",", ""));
	}
}//formatObjText

//AADD:09_30_05:Formats the amount into commaFormated amount
function CommaFormatted(amount)
{
	amount += '';
	amount = replaceAll(amount, ",", "");

	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2);
	var d = a[1];
	var i = parseInt(a[0]);
	var minus = '';
	var a = [];

	if(isNaN(i)) 
		{ return ''; }

	if(i < 0) 
		{ minus = '-'; }

	i = Math.abs(i);

	var n = new String(i);

	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}

	if(n.length > 0) 
		{ a.unshift(n); }

	n = a.join(delimiter);

	if (d==undefined)
		d="00";

	if(d.length < 1) 
		{ amount = n; }
	else 
	{ amount = n + '.' + d; }
	
	amount = minus + amount;
	return amount;
}//CommaFormatted

function showalert(code)
{
	if(code != '')			
	{
		var msgcode = code;
		var itmtag ='';
		
		msgcode = "CMM__" + msgcode.toUpperCase();
		
		var garr = g_cmm_arr;
		if (garr)
		{
			for (var cm_cnt = 0; cm_cnt<garr.length; cm_cnt++) 
			{
				var cm_itm = garr[cm_cnt].split("^");

				if (arguments[1] != undefined) //tag given
				{
					if (cm_itm[0] == msgcode + "__" + arguments[1].toUpperCase())
					{
						alert(cm_itm[1]);
						break;
					}
				}
				else
				{
					if (cm_itm[0].toUpperCase() == msgcode)
					{
						alert(cm_itm[1]);
						break;
					}						
				}
			}
		}
	}
}//showalert

//checkNoEmpty - PADD! 12-Jan-05
//	@field
//	@msg
function checkNoEmpty(field, msg)
{
	if(isEmpty(field.value))
	{
		alert(msg);
		field.focus();
		return false;
	}
	return true;
}//checkNoEmpty

//common validations for phone, zip, city, email
//------- start address validation

function gValidateAddress(obj, tag, rownum)
{
	if (isEmpty(gObjStr(obj)))
	{
		alerterr("Address " + tag + " is empty", rownum);
		//gsetFocusObj(obj);
		return false;
	}	
	return true;
}//gValidateAddress

function gValidateCity(obj, rownum)
{
	if(!gValEmptyCity(gObjStr(obj), rownum) || !gCheckCity(gObjStr(obj), rownum))
	{
		//gsetFocusObj(obj);
		return false;
	} 
	return true;
}//gValidateCity

function gValEmptyCity(objval, rownum)
{
	if (isEmpty(objval))
	{
		alerterr("City is empty", rownum);
		return false;
	}	
	return true;
}//gValEmptyCity

function gCheckCity(objval, rownum)
{
	var vStringExp = /[a-zA-Z]/i
	
	if(!isEmpty(objval))
	{
		var matches="";
		matches = vStringExp.exec(objval);

		if(matches == null)
		{ 
			alerterr("Enter alphabetic charactes for city", rownum);
			return false;
		}
	}
	return true;
}//gCheckCity

function gValidateState(obj, rownum)
{
	if (isEmpty(gObjStr(obj)))
	{
		alerterr("State is empty", rownum);
		//gsetFocusObj(obj);
		return false;
	}	
	return true;
}//gValidateState

function gValidateZip(obj, tag, rownum)
{
	if(!gValEmptyZip(gObjStr(obj), tag, rownum) || !gCheckZipCode(gObjStr(obj), tag, rownum))
	{
		//gsetFocusObj(obj);
		return false;
	} 
	return true;
}//gValidateZip

function gValEmptyZip(objval, tag, rownum)
{
	if (isEmpty(objval))
	{
		alerterr("Zip " + tag +" is empty", rownum);
		return false;
	}
	return true;	
}//gValEmptyZip

function gCheckZipCode(objval, tag, rownum)
{
	var vZipExp1 = /^\d{5}$/i
	var vZipExp2 = /^\d{4}$/i

	if (tag == '1')
	{
		if(!isEmpty(objval))
		{
			var matches="";
			matches = vZipExp1.exec(objval);

			if(matches == null)
			{
				alerterr("Invalid!. Enter a valid Zip Code", rownum);
				return false;
			}
		} 
	}
	
	if (tag == '2')
	{
		if(!(isEmpty(objval)))
		{
			var matches="";
			matches = vZipExp2.exec(objval);
			
			if(matches == null)
			{
				alerterr("Invalid!. Enter a valid Zip Code", rownum);
				return false;
			}
		} 
	}
	return true;
}//gCheckZipCode

function gObjStr(obj)
{
	//obj can be a field object or a value
	//if obj focus will go back to object, in case of error
	var strval='';

	if (typeof obj.id != 'undefined' && getObject(obj.id))
	{
		strval = obj.value;
	}
	else
	{
		strval = obj;
	}
	return strval;
}//gObjStr

function gsetFocusObj(obj)
{
	if(typeof obj != "undefined")
	{
		if (obj)
		{
			if (getObject(obj.id))
			{
				if (!getObject(obj.id).disabled && getObject(obj.id).type != 'hidden')
				{
					getObject(obj.id).focus();
				}
			}
		}
	}
}//gsetFocusObj

function gsetFocusStr(strobj)
{
	if(strobj != '')
	{
		if (getObject(strobj))
		{
			if (!getObject(strobj).disabled)
			{
				getObject(strobj).focus();
			}
		}
	}
}//gsetFocusStr

function gValidatePhone(obj, tag, rownum)
{
	if(!gValEmptyPhone(gObjStr(obj), tag, rownum) || !gCheckPhone(gObjStr(obj), tag, rownum))
	{
		//gsetFocusObj(obj);
		return false;
	} 
	return true;
}//gValidatePhone

function alerterr(msg, rownum)
{
	if (rownum == null || rownum == '')
	{
		alert(msg);
	}	
	else
	{
		alert("Row : " + rownum + " - " + msg, rownum);
	}
}//alerterr

function gValEmptyPhone(objval, tag, rownum)
{
	if (isEmpty(objval))
	{
		alerterr("Phone " + tag + " is empty", rownum);
		return false;
	}	
	return true;
}//gValEmptyPhone

function gCheckPhone(objval, tag, rownum)
{
	var vPhone1 = /^\d{3}$/i
	var vPhone2 = /^\d{4}$/i
	var vPhoneExt = /^\d{10}$/i

	if (tag == '1' || tag == '2')
	{
		if(!(isEmpty(objval)))
		{
			var matches="";
			matches = vPhone1.exec(objval);

			if(matches == null)
			{
				if(tag == '1')
				{
					alerterr("Enter 3 digit Phone Number.", rownum);
				}
				else
				{
					alerterr("Enter 3 digit Phone Suffix.", rownum);
				}
				return false;
			}
		}
	}
	
	if (tag == '3')
	{
		if(!(isEmpty(objval)))
		{
			var matches="";
			matches = vPhone2.exec(objval);

			if(matches == null)
			{
				alerterr("Enter 4 digit Phone Prefix.", rownum);
				return false;
			}
		}
	}
	return true;
}//gCheckPhone

function gValidateFax(obj, tag, rownum)
{
	if(!gValEmptyFax(gObjStr(obj), tag, rownum) || !gCheckFax(gObjStr(obj), tag, rownum))
	{
		//gsetFocusObj(obj);
		return false;
	} 
	return true;
}//gValidateFax

function gValEmptyFax(objval, tag, rownum)
{
	if (isEmpty(objval))
	{
		alerterr("Fax " + tag + " is empty", rownum);
		return false;
	}	
	return true;
}//gValEmptyFax

function gCheckFax(objval, tag, rownum)
{
	var vPhone1 = /^\d{3}$/i
	var vPhone2 = /^\d{4}$/i
	var vPhoneExt = /^\d{10}$/i

	if (tag == '1' || tag == '2')
	{
		if(!(isEmpty(objval)))
		{
			var matches="";
			matches = vPhone1.exec(objval);

			if(matches == null)
			{
				alerterr("Enter 3 digit Fax Number", rownum);
				return false;
			}
		}
	}
	
	if (tag == '3')
	{
		if(!(isEmpty(objval)))
		{
			var matches="";
			matches = vPhone2.exec(objval);

			if(matches == null)
			{
				alerterr("Enter 4 digit Fax Number", rownum);
				return false;
			}
		}
	}
	return true;
}//gCheckFax

function gValidateEMail(obj, tag, rownum)
{
	if (!gValEmptyEMail(gObjStr(obj), tag, rownum))
		return false;

	if (!gCheckEMail(gObjStr(obj), tag, rownum))
		return false;

	return true;
}//gValidateEMail

function gValEmptyEMail(objval, tag, rownum)
{
	if (isEmpty(objval))
	{
		alerterr("EMail is empty", rownum);
		return false;
	}	
	return true;
}//gValEmptyEMail

//ACMNT7-3-06
/*
//validEmail - AADD! 1-Jan-06
//	@email - email value
function validEmail(str) 
{
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }

  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}
*/
function validEmail(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}

	if (str.indexOf(at,(lat+1))!=-1){
	return false;
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	return false;
	}

	if (str.indexOf(dot,(lat+2))==-1){
	return false;
	}

	if (str.indexOf(" ")!=-1){
	return false;
	}

 	return true;			
}//validEmail
	
function gCheckEMail(objval, rownum)
{
	var vEmailExp = /^[a-z][a-zA-Z0-9_\.]+@[a-z_0-9\.]+\.[a-z]{3}$/i
		
	if(!isEmpty(objval))
	{
		if (!validEmail(objval))
		{
			alerterr("Invalid!. Enter a valid e-Mail ID", rownum);
			return false;
		}
	} 
	return true;
}//gCheckEMail
//--end address validation

function IsPopupBlocker() 
{
	var strNewURL = "Dummy.htm"
	var Strfeature = "" ;
	//SMCHG : 8/6/07 : set the window name from null to '' to avoid multiple browser to use the same window
	var WindowOpen = window.open(strNewURL,"","height=0,width=0,top=0,left=0,toolbar=no,location=no,directories=no,status=yes,menubar=no,dependent=no,scrollbars=no,resizable=no", '_blank');
	try
	{
		var obj = WindowOpen.name;
		WindowOpen.close();
	} 
	catch(e)
	{ 
		alert("System has been blocked by POP-UP BLOCKER.\nPlease disable the POP-UP BLOCKER and try again\nor\nPlease contact your system administrator. ");
	}
}//IsPopupBlocker

//to get the control from the parent window grid control
function getParentGridObj(currctlid, thisobjid)
{
	return getParentObj(GetCurrentRowControl(window.opener.document.getElementById(currctlid), thisobjid));
}//getParentGridObj

//to get the control from the parent window 
function getParentObj(objid)
{
	return window.opener.document.getElementById(objid);
}//getParentObj

function clearcombo(objcombo)
{
	//clear all items in dropdown
	if (objcombo)
	{
		for (var i=objcombo.options.length-1; i>=0; i--)
		{
			objcombo.options[i] = null;
		}
		objcombo.selectedIndex = -1;
	}
}//clearcombo

function isValidPassword(sText)
{
	return PWDhasValidChars(sText);
}//isValidPassword

function hasValidAsciiChars(sText)
{
	//Check password - Alphanumeric - will check ascii code between 32 AND 126
	var i;
	var c;
	for (i = 0; i < sText.length; i++) 
	{ 
		c = sText.charAt(i);
		
		//check for spaces
		if (asciiCode(c) == 32)
		{
			alert('Spaces are not allowed.');
			return false;
		}
		
		//allow ascii chars between 33 and 126
		if (asciiCode(c) < 33 || asciiCode(c) > 126)
		{
			return false;
		} 
	}//for
	return true;
}//hasValidAsciiChars

function setPhoneFormat(obj, tag)
{
	/* set the phone format in (999)999-(9999) format*/
	/* tag - for display message, can pass 'phone, fax etc.*/

	resetPhoneFormat(obj, false);
	if (obj.value.length > 0)
	{
		if (obj.value.length < 10)
		{
			alert('Please provide a 10 digit ' + tag + ' number.');
			obj.focus();
			return false;
		}
		
		obj.value = returnPhoneFormat(obj.value);
	}
}//setPhoneFormat

function resetPhoneFormat(obj, flag)
{
	/* remove the phone format from (999)999-(9999) and make it to 9999999999*/
	/*flag - true - focus will be set on the field*/
	
	if (obj.value.length > 0)
	{
		obj.value = replacePhoneChars(obj.value);
	}
	
	if (flag)
	{
		obj.select();
		obj.focus();
	}
}//resetPhoneFormat

function returnPhoneFormat(val)
{
	/* set the phone format in (999)999-(9999) format*/
	return "(" + Mid(val,0,3) + ") " + Mid(val,3,3) + "-" + Mid(val,6,4);
}//returnPhoneFormat

function replacePhoneChars(val)
{
	/* remove the characters ()- from phone format*/
	val = val.replace(/[(]/g,"");
	val = val.replace(/[)]/g,"");
	val = val.replace(/-/g,"");
	val = val.replace(/ /g,"");
	
	return val;
}//replacePhoneChars

function disableLookup(val, id)
{
	var lookup = getObject(id + "_hdCode");
	var lookup_desc = getObject(id + "_txtDescription");
	var lookup_btn = getObject(id + "_btnLookup_before");
	
	if(val)
	{
	    if (lookup)
	    {
	        lookup.value = "";
		    lookup.style.background='#edeeee';
		}
		if (lookup_desc)
		{
		    lookup_desc.value = "";
		    lookup_desc.style.background='#edeeee';
		}
		//lookup_btn.value = "";
	}
	else
	{
	    if (lookup)
	        lookup.style.background='white';
	    if (lookup_desc)
		    lookup_desc.style.background='white';
	}

    if (lookup)
	    lookup.disabled = val;
    if (lookup_desc)
	    lookup_desc.disabled = val;
    if (lookup_btn)
	    lookup_btn.disabled = val;
}//disableLookup

//taken from calendar, will return the position of a control,
//may not look right for embedded elements because of containing rectangle
function getAbsolutePosition(el)
{
	var SL = 0, ST = 0;
	var is_div = /^div$/i.test(el.tagName);
	if (is_div && el.scrollLeft)
		SL = el.scrollLeft;
	if (is_div && el.scrollTop)
		ST = el.scrollTop;
	var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
	if (el.offsetParent) {
		var tmp = getAbsolutePosition(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	
	//added
	/*var is_ie = ( /msie/i.test(navigator.userAgent) &&
		!/opera/i.test(navigator.userAgent) );
	if (is_ie) {
		r.y += document.body.scrollTop;
		r.x += document.body.scrollLeft;
	} else {
		r.y += window.scrollY;
		r.x += window.scrollX;
	}*/
	return r;
}//getAbsolutePosition

function isChildOf(obj,parentId)
{//search for the parent element as long as the element is valid
	while(obj)
	{//match found, return;
		if(obj.id==parentId)
			return true;
		obj = obj.parentElement;
	}
	return false;
}//isChildOf

function addClientEvent(el, evname, func) 
{
	if (el.attachEvent) { // IE
		el.attachEvent("on" + evname, func);
	} else if (el.addEventListener) { // Gecko / W3C
		el.addEventListener(evname, func, true);
	} else {
		el["on" + evname] = func;
	}
}//addClientEvent

function removeClientEvent(el, evname, func) 
{
	if (el.detachEvent) { // IE
		el.detachEvent("on" + evname, func);
	} else if (el.removeEventListener) { // Gecko / W3C
		el.removeEventListener(evname, func, true);
	} else {
		el["on" + evname] = null;
	}
}//removeClientEvent

//setVisibleElement - PADD! 22-May-07
//	@elemId - element id
//	@visible - true to display
//			 - false to hide
//	this hides or displays an element - either div/span/any other html element 
//	whose id is given
function setVisibleElement(elemId, visible)
{
	if (visible)
		displayElement(elemId);
	else
		hideElement(elemId);
}//setVisibleElement

//displayElement - PADD! 22-May-07
//	@elemId - element id
function displayElement(elemId)
{
	var div = $(elemId);
	if (div)
	{
		div.style.display = "";
		div.style.visibility = "visible";
	}
}//displayElement

//hideElement - PADD! 22-May-07
//	@elemId - element id
function hideElement(elemId)
{
	var div = $(elemId);
	if (div)
	{
		div.style.display = "none";
		div.style.visibility = "hidden";
	}
}//hideElement

//determine if the browser is IE
function isIE()
{
	return ( /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent) );
}//isIE

function getTopWindowCoord(offset)
{
	if(isIE())
	{//for IE, take away 50 for the height of the explorer bar
		return window.screenTop + offset - 50;
	}
	else
	{
		return window.screenY + offset;
	}
}//getTopWindowCoord

function getLeftWindowCoord(offset)
{
	if(isIE())
	{
		return window.screenLeft + offset;
	}
	else
	{
		return window.screenX + offset;
	}
}//getLeftWindowCoord

function getScrollBottom(p_oElem)
{
    //12/23/2009:when the calculated amount is < 0, then the fotter setting running in loop
    //and hanging the page. 
    var bottom = p_oElem.scrollHeight - p_oElem.scrollTop - p_oElem.clientHeight;
    if (bottom>=0)
        return p_oElem.scrollHeight - p_oElem.scrollTop - p_oElem.clientHeight;
    else
        return p_oElem.scrollTop;
}//getScrollBottom

function check_backspace_Event(obj)
{
    if (obj)
    {
        if (obj.className == 'disabled_textbox' || obj.disabled || obj.readOnly)
        {            
            var keyCode = (event.which)?event.which:event.keyCode;
            if ((keyCode == 8) || (keyCode == 46))
            event.returnValue = false;
        }
    }
}

//sriniMAdd:032009: used to find if invalid chars present in the passed string.
//if user does not pass InValidChars then default will be used.
function hasInValidChars(sText, InValidChars)
{
    var i;
    var c;
    var invalidstr =  "~%^,&+";
    if (InValidChars != "")
        invalidstr = InValidChars;
        
    for (i = 0; i < sText.length; i++) 
    { 
	    c = sText.charAt(i); 
	    if (invalidstr.indexOf(c) >= 0) 
	    {
	        alert('The following charecters are not allowed ' + invalidstr );
		    return true;
	    }//if
    }//for	    
}//hasInValidChars

function removeHTMLTags(htmlString)
 {
    if(htmlString){
      var mydiv = document.createElement("div");
       mydiv.innerHTML = htmlString;

        if (document.all) // IE Stuff
            return mydiv.innerText;
        else // Mozilla does not work with innerText
            return mydiv.textContent;            
  }
}

function IsProjectTypeContract(obj)
{
    if(obj)
    {
        if (obj.value == 'M' || obj.value == 'C' || obj.value == 'G')
        {
            return true;
        }
    }
    return false;
	
}//IsProjectTypeContract

function IsMATypeContract(obj)
{
    if(obj)
    {
        if (obj.value == 'M' || obj.value == 'C')
        {
            return true;
        }
    }
    return false;
	
}//IsProjectTypeContract
