
var win = null;
var win = null;
var GRIDADDMODE = 0;//used for CA GRID.
var rowEdited;
var lookupWidth;
var lookupHeight;



//Event Handling for draging the popup window
var objDrag = new Object();
objDrag.zIndex = 0;
var bIE = true;
var MaxZIndex = 1000;
var lookUpFrame = null;
var frame = null;
var lookUpWidth = 400, lookUpHeight = 300;
var lookUpID = "lookupID";
var parentctrlID = null;
var parentctrlIDVal = null;

function ClosePopupWindow() {

	lookUpFrame = document.getElementById(lookUpID);
	if(parentctrlID!=null && parentctrlIDVal!=null)
	{
	    if ((parentctrlIDVal.value=="")||(parentctrlIDVal.value=='')||(parentctrlIDVal.value==null)) 
	    {
		    parentctrlID.value = "";
	    }
	}
	lookUpFrame.style.visibility = "hidden";
	lookUpFrame.style.display = "none";
}
function ShowLookup(url, title, h, w, scroll) {

	
	lookupWidth = w;
	lookupHeight = h;
	var lookupindex = url.indexOf("lookupid=");
	if(url.indexOf("ctrlID=") != -1)
	{
	 parentctrlID = document.getElementById(url.substring(url.indexOf("ctrlID=")+7,url.indexOf("&")));
	 parentctrlIDVal = document.getElementById(url.substring(url.indexOf("ctrlID=")+7,url.indexOf("&"))+ "_Val");
	}
	if (lookupindex != -1) {
		lookupID = url.substring(lookupindex + 9);
		var extracturl = url.substring(lookupindex + 9);
		if (extracturl.indexOf("&") >= 0) {
			lookupID = extracturl.substring(0, extracturl.indexOf("&"));
		}
	} else {
		lookupID = "undefined";
	}
	
	if (lookUpFrame == null) {
		//create look up frame:
		lookUpFrame = document.createElement("DIV");
	}
	var sc = "no";
	if (scroll == true) {
		sc = "yes";
	}
	if(document.body.clientWidth<w)
	{
	    w=document.body.clientWidth;
	}
	lookUpFrame.innerHTML = "<div id='LookUpWnd' allowtransparency=\"true\" style='height:20;width:" + w + ";background-color:gray;color:black;cursor:move;' onmousedown=\"StartDrag(event,'" + lookupID + "');\"><table style='height:20;width:" + w + ";border:solid 1 black;background-color:#88AAA9;'><tr><td><span class='blacktextbold'>" + title + "</span></td><td align=right><a href=\"javascript:ClosePopupWindow('" + lookupID + "');\"><img src='" + webRoot + "Images/close.gif' border='0' /></a></td></tr></table><iframe id='r' style=\"position:absolute;left:0;top:0;z-index:-4\" height='25' width=" + w + " onmousedown=\"StopDrag(event);\"></iframe><iframe  onmousedown=\"StopDrag(event);\" id='IFrameLookup' width=" + w + " height=" + h + " style='cursor:move;z-index:-4;background-color:white' frameborder=1 scrolling=" + sc + " src=" + url + " /></div>";
	document.body.appendChild(lookUpFrame);
	lookUpFrame.style.position = "absolute";
	lookUpFrame.style.zIndex = 60000;
	document.body.onresize = PositionLookUpFrame;
	window.onresize = PositionLookUpFrame;
	document.body.onscroll = PositionLookUpFrame;
	window.onscroll = PositionLookUpFrame;
	lookUpFrame.setAttribute("id", lookupID);
	
	
	//show the lookup frame:
	lookUpFrame.style.visibility = "visible";
	lookUpFrame.style.display = "block";
	
	//Kiran Banda: make the popup a modal dialog
	ShowModalWindow(lookupID);
	
	PositionLookUpFrame();
}

function IsIE()
{
	var browser=navigator.appName
	var b_version=navigator.appVersion
	var version=parseFloat(b_version)
	if (browser=="Microsoft Internet Explorer")
	{
		return true;
	}
	return false;
	
}

function ShowModalWindow(lookupWindowID)
{
	
	var foregroundElement = document.getElementById('fgElement');
	
	
    var backgroundElement = document.createElement('div');	
    backgroundElement.setAttribute("id","bgElement");
    backgroundElement.style.display = 'block';
    backgroundElement.style.visibility = 'visible';
   backgroundElement.style.position = 'absolute';
    backgroundElement.style.left = '0px';
    backgroundElement.style.top = '0px';
    backgroundElement.style.zIndex = 10;
    backgroundElement.style.backgroundColor = '#222222';		
    backgroundElement.style.width = '100%';
    backgroundElement.style.height = '100%';			
	
    var iFrameElement = document.createElement('iframe');
    iFrameElement.style.width = '100%';
    iFrameElement.style.height = '100%';
    iFrameElement.style.backgroundColor = '#222222';
    iFrameElement.style.zIndex = 5;
    if(IsIE())
    {
	    backgroundElement.style.filter = "progid:DXImageTransform.Microsoft.alpha(opacity='40')";
	    iFrameElement.style.filter = "progid:DXImageTransform.Microsoft.alpha(opacity='40')";
    }
    else
    {
	    backgroundElement.style.opacity = '0.4';
	  
    }	
	
    backgroundElement.appendChild(iFrameElement);
    if(foregroundElement == null)
	{	
	    foregroundElement = document.createElement('div');	
	    document.body.appendChild(foregroundElement);    
	}
	else
	{
	    // Clear the children
	    for(var i=0,l=foregroundElement.children.length;i<l;i++)
	    {   
	        foregroundElement.removeChild(foregroundElement.children[i]);
	    }
	}
	
	foregroundElement.setAttribute("id","fgElement");	
    foregroundElement.style.position = 'static';
    foregroundElement.style.display = 'block';
    //foregroundElement.style.zIndex = 1010;	
	
	var popupElement = document.getElementById(lookupWindowID);
	popupElement.style.display = 'block';
	popupElement.style.zIndex = 1050;
	popupElement.style.position = 'absolute';
	
	var dWidth = document.body.clientWidth;
	var dHeight = document.body.clientHeight;
	
	if(dWidth < lookupWidth)
	{   
	    popupElement.style.width = dWidth - 20;
	    dWidth = lookupWidth;
	}
	if(dHeight < lookupHeight)
	{
	    popupElement.style.width = dHeight - 20;
	    dHeight = lookupHeight;
	}
	
	popupElement.style.left = (dWidth - lookupWidth) / 2;
	popupElement.style.top =  (dHeight - lookupHeight) / 2;
	
	document.body.removeChild(popupElement);
	
	foregroundElement.appendChild(popupElement);	
	foregroundElement.appendChild(backgroundElement);
}



function CloseModalWindow(lookupWindowID)
{
	
	var foregroundElement = document.getElementById('fgElement');	
	foregroundElement.style.display = 'none';
	
}


//Positions the lookup in the center of the browser's window.
function PositionLookUpFrame() {


	if (lookUpFrame != null) {	 
		lookUpFrame.style.left ="350px";//document.documentElement.clientWidth / 2 - lookupWidth / 2; //  + document.body.scrollLeft+100;
		lookUpFrame.style.top = "132px";//document.documentElement.clientHeight/ 2 - lookupHeight / 2; //+ document.body.scrollTop+100;
			
		lookUpTopPosition=new Number(document.documentElement.clientHeight / 2 - lookupHeight / 2);
		leastValue=new Number(1);		
		if(lookUpTopPosition<leastValue)
		{
		    lookUpFrame.style.top=21;
		    lookUpFrame.style.left=1;
		}
	}
}
function BringToFront(id) {
	var target = document.getElementById(id);
	MaxZIndex = MaxZIndex + 1;
	target.style.zIndex = MaxZIndex;
}
function SuppressBubble(event) {
	if (bIE) {
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	} else {
		if (event) {
			event.stopPropagation();
		}
	}
}
function StartDrag(event, id) {

    // Kiran Banda
    // The following condition is required to solve an issue which is as follows:
    // When there is a lengthier text that is shown in a popup, it is better to 
    // enclose that text within a <span/> tag and set the overflow property to auto.
    // Having set so, when the user clicks on the scrollbar,focus can never be taken off the popup !!
    // IF block below handles that issue :-)
    if(event.srcElement.tagName == 'SPAN')
    {
      return true;
    }
	var x, y;
	objDrag.elNode = document.getElementById(id);
	if (bIE) {
		x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	} else {
		x = event.pageX;
		y = event.pageY;
	}
	objDrag.cursorStartX = x;
	objDrag.cursorStartY = y;
	objDrag.elStartLeft = parseInt(objDrag.elNode.style.left, 10);
	objDrag.elStartTop = parseInt(objDrag.elNode.style.top, 10);
	BringToFront(objDrag.elNode.id);
	if (bIE) {
		document.attachEvent("onmousemove", Drag);
		document.attachEvent("onmouseup", StopDrag);
	} else {
		document.addEventListener("mousemove", Drag, true);
		document.addEventListener("mouseup", StopDrag, true);
	}
	SuppressBubble(event);
}
function Drag(event) {
	var x, y;
	if (bIE) {
		x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	} else {
		x = event.pageX;
		y = event.pageY;
	}
	objDrag.elNode.style.left = (objDrag.elStartLeft + x - objDrag.cursorStartX) + "px";
	objDrag.elNode.style.top = (objDrag.elStartTop + y - objDrag.cursorStartY) + "px";
	SuppressBubble(event);
}
function StopDrag(event) {
	objDrag.elNode = null;
	if (bIE) {
		document.detachEvent("onmousemove", Drag);
		document.detachEvent("onmouseup", StopDrag);
	} else {
		document.removeEventListener("mousemove", Drag, true);
		document.removeEventListener("mouseup", StopDrag, true);
	}
}
function getAbsoluteLeft(node) {
	var currentNode = node;
	var left = 0;
	while (currentNode.tagName != "BODY") {
		left += currentNode.offsetLeft;
		currentNode = currentNode.offsetParent;
	}
	return left;
}
function getAbsoluteTop(node) {
	var currentNode = node;
	var top = 0;
	while (currentNode.tagName != "BODY") {
		top += currentNode.offsetTop;
		currentNode = currentNode.offsetParent;
	}
	return top;
}



//javascript code for detail window
var popUpWidth = 450, popUpHeight = 150; //named constants
function getY(oElement) {
	var iReturnValue = 0;
	while (oElement != null) {
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}
function getX(oElement) {
	var iReturnValue = 0;
	while (oElement != null) {
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}
function getAbsolutePos(el) {
	var tagName = el.tagName;
	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 = this.getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}


// Replace all the occurences of a given string with a new string
function ReplaceAll(strDetails, searchString,replaceString)
{

    var index = 0;
    while(index != -1)
    {
        index = strDetails.indexOf(searchString);        
        if(index >=0)
        {
            strDetails = strDetails.replace(searchString,replaceString);
        }
    }
    
    return strDetails;

}


//Closes the pop up window:
function ClosePopUpDetailsWindow() {
	var popUpFrame = document.getElementById("HierarchialGridFullSummaryDiv");
	if (popUpFrame != null) {
		popUpFrame.style.visibility = "hidden";
	}
}

//javascript code is ended for popup close window.
function ClosePopupWindow(lookupID) {
	var popID = lookupID;
	var popupID = document.getElementById(popID);
	if(parentctrlID!=null && parentctrlIDVal!=null)
	{
	    if ((parentctrlIDVal.value=="")||(parentctrlIDVal.value=='')||(parentctrlIDVal.value==null)) 
	    {
		    parentctrlID.value = "";
	    }
	}
	popupID.style.visibility = "hidden";
	popupID.style.display = "none";
	CloseModalWindow();
}

function setValue(concatString, ctrlID) {

	var collection = concatString.split(",");
	var hdnText = document.getElementById(ctrlID);
	if (hdnText != null) {
		hdnText.value = collection[0];
	}
	var hdnValue = document.getElementById(ctrlID + "_Val");
	if (hdnValue != null) {
		hdnValue.value = collection[1];
	}
	//General place for calling any extra functions which required to disable or any other operaions of the remainging controls.
	//specific to the page name caseRecordSerarch - paddhu 
	if (window.DisableLookupField) {
		DisableLookupField();
	}
}






//Used in OnSort / OnPage functions
function SetCtlValue(controlID, val) {
	document.getElementById(controlID).value = val;
}
function GetCtlValue(controlID) {
	return document.getElementById(controlID).value;
}

function ColumnVisibilityGrid(grid, columnindex1, columnindex2) {
	if (columnindex1 != null) {
		var column1 = grid.Table.Columns[columnindex1];
		column1.DataCellCssClass = "invisible";
		column1.HeadingCellCssClass = "invisible";
		column1.Visible = false;
		grid.Render();
	}
	if (columnindex2 != null) {
		var column2 = grid.Table.Columns[columnindex2];
		column2.DataCellCssClass = "";
		column2.HeadingCellCssClass = "";
		column2.Visible = true;
		grid.Render();
	}
	return true;
}
function SimpleDelete(grid, rowID) {
	if (window.ClearTxtRowid) {
		ClearTxtRowid();
	}
	if (document.getElementById("ctl01_txtrowid") != null) {
		var trowid = document.getElementById("ctl01_txtrowid");
		if (trowid != null) {
			trowid.value = "";
		}
	}
	//The above line has copied from after delete command need to check the impact on other places - oct 11-2006 - padmanaban
	grid.EditCancel();	
	grid.Delete(grid.GetRowFromClientId(rowID));
	if (window.ReRenderActionColumn) {
		window.ReRenderActionColumn(grid);
	}
	gridRowInEditMode = false;
}
function DeleteOperationGrid(grid, rowId, flagcol, flagVal, confirmation) {
	if (flagcol != -1) {
		var Item = grid.GetRowFromClientId(rowId);
		if (flagVal == 1) {
			grid.Delete(grid.GetRowFromClientId(rowId));
		} else {
			Item.SetValue(flagcol, "3", true);
			grid.Render();
		}
	} else {
		grid.Delete(grid.GetRowFromClientId(rowId));
	}
}
function GenralCMReLoadGrid() {
	RenderActionLink(this, null);
}
function GetGridCellValue(gridID, rowid, Index) {
	var Item = gridID.Table.GetRow(rowid);
	return Item.Cells[Index].Value;
}
function DeleteGridRowServer(gridID, id, rowid) {
	if (confirm(lblDelCfmMsg)) {
        //custom function after DeleteGridRowServer need to be implement in individual parent page - paddhu
		if (window.CustomAfterDeleteGridRowServer) {
			window.CustomBeforeDeleteGridRowServer(gridID, id, rowid);
		}
		var flagcol = getGridFlagIndex(gridID);
		var Item = gridID.Table.GetRow(rowid);     

        //   DeleteOperationGrid( gridID,rowid,flagcol,flagVal,lblDelCfmMsg);
		if (flagcol != -1) {
			var flagVal = parseInt(Item.Cells[flagcol].Value);
			var Item = gridID.GetRowFromClientId(rowid);
			if (flagVal == 1) {
				gridID.Delete(gridID.GetRowFromClientId(rowid));
			} else {
				Item.SetValue(flagcol, "3", true);
			}
		} else {
			gridID.Delete(gridID.GetRowFromClientId(rowid));
		}
		RenderActionLink(gridID, id); 
            //custom function after DeleteGridRowServer need to be implement in individual parent page - paddhu
		if (window.CustomAfterDeleteGridRowServer) {
			window.CustomAfterDeleteGridRowServer(gridID, id, rowid);
		}
	}
	
	if (window.ReRenderActionColumn) {
		window.ReRenderActionColumn(gridID);
	}
}
function RenderActionLink(gridID, idPrefix) {
	var gridFlaginx = getGridFlagIndex(gridID);
	var actionInx = getActionColumnIndex(gridID);
    //ctl01_ctl01_dgrdPhysioMonitoring_0_10
	if (idPrefix == null) {
		paramActionContl = gridID.Id.substring(0, gridID.Id.lastIndexOf("_")) + "_" + gridID.Id + "_0_" + actionInx;
		idPrefix = paramActionContl;
	}
    
 //validate existence
	gridID.Render();
	var Count = gridID.Table.GetRowCount();
	for (var i = 0; i < Count; i++) {
		var Item = gridID.Table.GetRow(i);
		if (Item.Cells[gridFlaginx].Value == "3") { 
            //ctl01_ctl01_dgrdPhysioMonitoring_0_10
			var id = idPrefix + "_" + i;
			var delVar = document.getElementById("lnkDelete_" + id);
			if (delVar != null) {
				delVar.outerHTML = lblDeleted;
				//delVar.outerHTML = lblRemoved;
				delVar.innnerHTML = "";
				delVar.innerText = "";
				delVar.outerText = "";
			}
			var EditVar = document.getElementById("lnkEdit_" + id);
			if (EditVar != null) {
				EditVar.outerHTML = "";
				EditVar.innnerHTML = "";
				EditVar.innerText = "";
				EditVar.outerText = "";
			}
		}
	}
}


function GridContentValidator(grid, rowid) {
	var Item = grid.Table.GetRow(rowid);
	if (UpdateValidator(null, Item) == 2) {
		return false;
	}
	return true;
}
function UpdateGridRow(grid, rowid, flagindx, validationRequired) {

	var Item = grid.Table.GetRow(rowid);
	if (typeof validationRequired != "undefined") {
		if (validationRequired == true) {
			if (UpdateValidator(null, Item) == 2) {
				return false;
			}
		}
	}
	if (flagindx != -1) {
		var val = Item.Cells[flagindx].Value;
		if (val == 0) {
			grid.EditComplete();
		    Item.SetValue(flagindx, "2", true);
			grid.Render();
			
		}else if(val == -1)
		{
		    grid.EditComplete();
		    Item.SetValue(flagindx, "1", true);
			grid.Render();
		}
		
	}
	
	grid.EditComplete();
	if (typeof validationRequired != "undefined") {
		return true;
	}
}
function CancelGridEdit(grid) {
//

	//to update the txt row id .. hardcode will be remove shortly
	if (document.getElementById("ctl01_txtrowid") != null) {
		var trowid = document.getElementById("ctl01_txtrowid");
		if (trowid != null) {
			trowid.value = "";
		}
	}
	grid.EditCancel();
	//grid.Postback(null);//Code changed by GiriBabu to clear the values when cancel hyperlink is clicked
	
}


function GetUpdateContent(row, GridFlagInx, confirmation, grid) {
	var idTempRowid = row.ClientId;
	if (row.ClientId.indexOf(" ") != -1) {
		idTempRowid = row.ClientId.substring(row.ClientId.indexOf(" ") + 1);
	}
	
	if (GRIDADDMODE != 1) {
		return "<a class=\"lineage\" href=\"javascript:UpdateGridRow(" + grid + "," + idTempRowid + "," + GridFlagInx + ");\">" + lblUpdate + "</a>  <a class=\"lineage\" href=\"javascript:CancelGridEdit(" + grid + " );\">" + lblCancel + "</a>";
	} else {
		GRIDADDMODE = 0;
		return "<a class=\"lineage\" href=\"javascript:UpdateGridRow(" + grid + "," + idTempRowid + "," + GridFlagInx + ");\">" + lblInsert + "</a>  <a class=\"lineage\" href=\"javascript:SimpleDelete(" + grid + ",'" + idTempRowid + "');\">" + lblCancel + "</a>";
	}
}
function editGridRow(grid, rowId) {
	//to update the txt row id .. hardcode will be remove shortly
	if (document.getElementById("ctl01_txtrowid") != null) {
		var trowid = document.getElementById("ctl01_txtrowid");
		if (trowid != null) {
			trowid.value = rowId;
		}
	}
	grid.Edit(grid.GetRowFromClientId(rowId));
	if (window.ReRenderActionColumn) {
		window.ReRenderActionColumn(grid);
	}
}
function GetInsertCancelGridContent(row, GridFlagInx, confirmation, grid) {

   
	return "<a class=\"lineage\" href=\"javascript:InsertGridRow(" + grid + ");\">" + lblInsert + "</a>  <a class=\"lineage\" href=\"javascript:CancelGridEdit(" + grid + " );\">" + lblCancel + "</a>";
}
function InsertGridRow(grid) {
	

	grid.EditComplete();
}
function ResetGridContent(row, grid) {
	return "<a class=\"lineage\" href=\"javascript:ResetGridValues(" + grid + "," + row.ClientId + ");\">" + lblReset + "</a>";
}
function ResetAllGridContent(row, GridFlagInx, confirmation, grid) {
	return "<a class=\"lineage\" href=\"javascript:ResetAllGridValues(" + grid + "," + row.ClientId + ");\">" + lblReset + "</a>";
}
function GetEditGridContent(row, GridFlagInx, confirmation, grid) {
	var confirmsg = lblDelCfmMsg;
	if (GridFlagInx != -1) {
		if (row.Cells[GridFlagInx].Value == "3") {
			return "<b>" + lblDeleted + "</b>";
		} else {
			return getGridEditRemoveLink(row, GridFlagInx, confirmation, grid, confirmsg);
		}
	} else {
		return getGridEditRemoveLink(row, GridFlagInx, confirmation, grid, confirmsg);
	}
}
function GetDeleteGridContent(row, GridFlagInx, confirmation, grid) {
	var confirmsg = lblDelCfmMsg;
	if (GridFlagInx != -1) {
		if (row.Cells[GridFlagInx].Value == "3") {
			return "<b>" + lblDeleted + "</b>";
		} else {
			return getGridRemoveLink(row, GridFlagInx, confirmation, grid, confirmsg);
		}
	} else {
		return getGridRemoveLink(row, GridFlagInx, confirmation, grid, confirmsg);
	}
}
function GetEditOnlyGridContent(row, GridFlagInx, confirmation, grid) {
	return getGridEditLink(row, GridFlagInx, confirmation, grid);
}
function GetEditOnlyGridContentWithDisplayText(row, GridFlagInx, confirmation, grid, EditText) {
	if (GridFlagInx != -1 && row.Cells[GridFlagInx].Value != "3") {
		return "<a class=\"lineage\" href=\"javascript:editGridRow(" + grid + ",'" + row.ClientId + "');\">" + EditText + "</a> ";
	}
}
function getGridEditLink(row, GridFlagInx, confirmation, grid, confirmsg) {
	return "<a class=\"lineage\" href=\"javascript:editGridRow(" + grid + ",'" + row.ClientId + "');\">" + lblEdit + "</a> ";
}
function getGridRemoveLink(row, GridFlagInx, confirmation, grid, confirmsg) {
	if (GridFlagInx != -1) {
		return "<a class=\"lineage\" href=\"javascript:deleteGridRow(" + grid + ",'" + row.ClientId + "' ,'" + GridFlagInx + "',' " + row.Cells[GridFlagInx].Value + "','" + confirmation + "','" + confirmsg + "' );\">" + lblRemove + "</a>";
	} else {
		return "<a class=\"lineage\" href=\"javascript:deleteGridRow(" + grid + ",'" + row.ClientId + "' ,'" + GridFlagInx + "','-1','" + confirmation + "','" + confirmsg + "' );\">" + lblRemove + "</a>";
	}
}
function getGridRemoveLinkPostBack(row, GridFlagInx, confirmation, grid, confirmsg) {
	if (GridFlagInx != -1) {
		return "<a class=\"lineage\" href=\"javascript:deleteGridRowPostBack(" + grid + ",'" + row.ClientId + "' ,'" + GridFlagInx + "',' " + row.Cells[GridFlagInx].Value + "','" + confirmation + "','" + confirmsg + "' );\">" + lblRemove + "</a>";
	} else {
		return "<a class=\"lineage\" href=\"javascript:deleteGridRowPostBack(" + grid + ",'" + row.ClientId + "' ,'" + GridFlagInx + "','-1','" + confirmation + "','" + confirmsg + "' );\">" + lblRemove + "</a>";
	}
}
function getGridEditRemoveLink(row, GridFlagInx, confirmation, grid, confirmsg) {
	if (GridFlagInx != -1) {
		return "<a class=\"lineage\" href=\"javascript:editGridRow(" + grid + ",'" + row.ClientId + "');\">" + lblEdit + "</a>  <a class=\"lineage\" href=\"javascript:deleteGridRow(" + grid + ",'" + row.ClientId + "' ,'" + GridFlagInx + "',' " + row.Cells[GridFlagInx].Value + "','" + confirmation + "','" + confirmsg + "' );\">" + lblRemove + "</a>";
	} else {
		return "<a class=\"lineage\" href=\"javascript:editGridRow(" + grid + ",'" + row.ClientId + "');\">" + lblEdit + "</a>  <a class=\"lineage\" href=\"javascript:deleteGridRow(" + grid + ",'" + row.ClientId + "' ,'" + GridFlagInx + "','-1','" + confirmation + "','" + confirmsg + "' );\">" + lblRemove + "</a>";
	}
}
function setDDCellValue(DataItem, col, field ,setIndex) {
    
	var mytextbox = document.getElementById(col);
	if (mytextbox != null) {		
		if(DataItem.GetMember(field).Value == null)  
		{ 
		    mytextbox.selectedIndex= setIndex;  // set the dropdown values as default index 
		}
		else
		{
		    mytextbox.value = DataItem.GetMember(field).Value;
		}
		
	}
	return true;
}
function getDDCellValue(DataItem, col, field) {
	
	var mytextbox = document.getElementById(col);
	var myindex = mytextbox.selectedIndex;
	if (myindex != -1) {
		return mytextbox.options[myindex].value;
	} else {
		return "";
	}
}
function getDDCellText(DataItem, col, field) {
	
	var mytextbox = document.getElementById(col);
	DataItem.GetMember(field).Value = mytextbox.value;
	var myindex = mytextbox.selectedIndex;
	if (myindex != -1) {
	 
		return mytextbox.options[myindex].text;
	} else {
		return "";
	}
}
function onDelete(item) {
	return true;
}
function OnInsert(item) {
	return true;
}
function askConfirmationtoProceed(confmsg) {
	if (confirm(confmsg)) {
		return true;
	} else {
		return false;
	}
}

function GetEditGridContentDisplayText(row, GridFlagInx, confirmation, grid, edittext, removetext) {
	var confirmsg = lblDelCfmMsg;
	if (GridFlagInx != -1) {
		if (row.Cells[GridFlagInx].Value == "3") {
			return "<b>" + lblDeleted + "</b>";
		} else {
			return getGridEditRemoveLinkDiplayText(row, GridFlagInx, confirmation, grid, confirmsg, edittext, removetext);
		}
	} else {
		return getGridEditRemoveLinkDisplayText(row, GridFlagInx, confirmation, grid, confirmsg, edittext, removetext);
	}
}
function getGridEditRemoveLinkDiplayText(row, GridFlagInx, confirmation, grid, confirmsg, edittext, removetext) {
	if (GridFlagInx != -1) {
	    if(edittext=="" && edittext==null&&removetext=="" && removetext==null)
	    {
		return "<a class=\"lineage\" href=\"javascript:editGridRow(" + grid + ",'" + row.ClientId + "');\">" + lblEdit + "</a>  <a href=\"javascript:deleteGridRow(" + grid + ",'" + row.ClientId + "' ,'" + GridFlagInx + "',' " + row.Cells[GridFlagInx].Value + "','" + confirmation + "','" + confirmsg + "' );\">" + lblRemove + "</a>";
		}
		else
		{
		    var returnurl="";
		    if(edittext!="" && edittext!=''&&edittext!=null)
		    {
		    returnurl="<a class=\"lineage\" href=\"javascript:editGridRow(" + grid + ",'" + row.ClientId + "');\">" + edittext + "</a>";
		    }
		    if(removetext!="" &&removetext!=''&& removetext!=null)
		    {
		    returnurl=returnurl+" <a class=\"lineage\" href=\"javascript:deleteGridRow(" + grid + ",'" + row.ClientId + "' ,'" + GridFlagInx + "',' " + row.Cells[GridFlagInx].Value + "','" + confirmation + "','" + confirmsg + "' );\">" + removetext + "</a>";
		    }
		    
		return returnurl;
		 
		}
		
	} else {
		return "<a class=\"lineage\" href=\"javascript:editGridRow(" + grid + ",'" + row.ClientId + "');\">" + lblEdit + "</a>  <a href=\"javascript:deleteGridRow(" + grid + ",'" + row.ClientId + "' ,'" + GridFlagInx + "','-1','" + confirmation + "','" + confirmsg + "' );\">" + lblRemove + "</a>";
	}
}
function getCellText(DataItem, col, field) {
	var mytextbox = document.getElementById(col);
	return mytextbox.value;
}

function setCellValue(DataItem, col, field) {
	var mytextbox = document.getElementById(col);
	if (mytextbox != null) {
		if (DataItem.GetMember(field).Value != null) {
			mytextbox.value = DataItem.GetMember(field).Value;
		} else {
			mytextbox.value = "";
		}
	}
	return true;
}
function CallbackOnDropDownChage(txtrowid, grid, callback, callbackparam) {
	var rowid = document.getElementById(txtrowid).value;
	grid.EditComplete();
	var rowEdited = document.getElementById(txtrowid).value;
	if (rowEdited != "") {
		var Item = grid.Table.GetRow(rowEdited);
		grid.Edit(Item);
	}
	callback.Callback(callbackparam);
}
function CallBackEditCustomGridRow(callback, txtrowid, callbackparam, rowval) {
	document.getElementById(txtrowid).value = rowval;
	callback.Callback(callbackparam);
}
function CallBackUpdateCustomGridRow(grid, rowid, flagindx, callback, callbackparam, txtrowid) {
	UpdateGridRow(grid, rowid, flagindx);
	callback.Callback("OnLoadDropDown");
	document.getElementById(txtrowid).value = "";
}
function CallBackCancelCustomGridEdit(grid, rowid, flagindx, txtrowid) {
	document.getElementById(txtrowid).value = "";
	CancelGridEdit(grid, rowid, flagindx);
}
function CallBackdeleteGridRow(grid, rowId, flagcol, flagVal, confirmation, confmsg, callback, callbackparam) {
	deleteGridRow(grid, rowId, flagcol, flagVal, confirmation, confmsg);
	callback.Callback(callbackparam);
}
function CallBackOnLoadGrid(grid, txtrowid) {
	var rowEdited = document.getElementById(txtrowid).value;
	if (rowEdited != "") {
		var Item = grid.Table.GetRow(rowEdited);
		grid.Edit(Item);
	}
}
function GetGridCustomEditRemoveLink(row, GridFlagInx, confirmation, grid, confirmsg) {
	if (GridFlagInx != -1) {
		return "<a class=\"lineage\" href=\"javascript:EditCustomGridRow(" + grid + ",'" + row.ClientId + "');\">" + lblEdit + "</a>  <a href=\"javascript:deleteGridRow(" + grid + ",'" + row.ClientId + "' ,'" + GridFlagInx + "',' " + row.Cells[GridFlagInx].Value + "','" + confirmation + "','" + confirmsg + "' );\">" + lblRemove + "</a>";
	} else {
		return "<a class=\"lineage\" href=\"javascript:EditCustomGridRow(" + grid + ",'" + row.ClientId + "');\">" + lblEdit + "</a>  <a href=\"javascript:deleteGridRow(" + grid + ",'" + row.ClientId + "' ,'" + GridFlagInx + "','-1','" + confirmation + "','" + confirmsg + "' );\">" + lblRemove + "</a>";
	}
}
function ReSetGridModeAdd() {
	GRIDADDMODE = 1;
}
function SetGridModeAdd() {
	GRIDADDMODE = 1;
}
function GetUpdateContentCancelCustom(row, GridFlagInx, confirmation, grid) {
	
	if (GRIDADDMODE != 1) {
		return "<a class=\"lineage\" href=\"javascript:UpdateCustomGridRow(" + grid + "," + row.ClientId + "," + GridFlagInx + ");\">" + lblUpdate + "</a>  <a href=\"javascript:CancelCustomGridEdit(" + grid + "," + row.ClientId + "," + GridFlagInx + ");\">" + lblCancel + "</a>";
	} else {
		//GRIDADDMODE=0; 
		return "<a class=\"lineage\" href=\"javascript:UpdateCustomGridRow(" + grid + "," + row.ClientId + "," + GridFlagInx + ");\">" + lblInsert + "</a>  <a href=\"javascript:SimpleDelete(" + grid + ",'" + row.ClientId + "');\">" + lblCancel + "</a>";
	}
}
function IsNumericForCntrl(sText) {
	var flag = IsNumeric(sText.value);
	if (flag == false) {
		alert("Enter Only Numeric Values");
		sText.value = "";
		sText.focus();
		return false;
	} else {
		return true;
	}
}
function AllowNumericOnly(control, event) {
	if (event.keyCode > 47 && event.keyCode < 58) {
		event.returnValue = true;
	} else {
		event.returnValue = false;
	}
}
function AllowNumericDecimalOnly(control, event) {
	if (event.keyCode >= 46 && event.keyCode < 58) {
		event.returnValue = true;
	} else {
		event.returnValue = false;
	}
}




function setDateTimeCellValue(DataItem, col, field) {
	var mytextbox = document.getElementById(col);
	var datetime = new Date(DataItem.GetMember(field).Value); 
	var vmonth = (datetime.getMonth() + 1);
	var vdate = datetime.getDate();
	var vyear = datetime.getFullYear();
	if (vdate == "1" && vmonth == "1" && vyear == "1970") {
		effdate = lblSysDate;
	} else {
		if (vmonth < 10) {
			vmonth = "0" + vmonth;
		}
		if (vdate < 10) {
			vdate = "0" + vdate;
		}
		var effdate = vmonth + "/" + vdate + "/" + datetime.getFullYear();
	}
	mytextbox.value = effdate;
	return true;
}


function DeleteOperationGridPostBack(grid, rowId, flagcol, flagVal, confirmation) {
	//
	if (flagcol != -1) {
		var Item = grid.GetRowFromClientId(rowId);
		if (flagVal == 1) {
			grid.Delete(grid.GetRowFromClientId(rowId));
		} else {
			Item.SetValue(flagcol, "3", true);
			grid.Render();
			grid.Delete(grid.GetRowFromClientId(rowId));
		}
	} else {
		grid.Delete(grid.GetRowFromClientId(rowId));
	}
}
function deleteGridRowPostBack(grid, rowId, flagcol, flagVal, confirmation, confmsg) {
	confmsg = lblDelCfmMsg;
	if (confirmation == "true") 
	{
		if (confirm(confmsg)) 
		{
			DeleteOperationGridPostBack(grid, rowId, flagcol, flagVal, confirmation);
		}
	} 
	else 
	{
		DeleteOperationGridPostBack(grid, rowId, flagcol, flagVal, confirmation);
	}
}
function GetEditGridContentPostbackDelete(row, GridFlagInx, confirmation, grid) {
	
	var confirmsg = lblDelCfmMsg;
	if (GridFlagInx != -1) {
		if (row.Cells[GridFlagInx].Value == "3") {
			return "<b>" + lblDeleted + "</b>";
		} else {
			return getGridEditRemoveLinkPostBack(row, GridFlagInx, confirmation, grid, confirmsg);
		}
	} else {
		return getGridEditRemoveLinkPostBack(row, GridFlagInx, confirmation, grid, confirmsg);
	}
}
function getGridEditRemoveLinkPostBack(row, GridFlagInx, confirmation, grid, confirmsg) {
	if (GridFlagInx != -1) {
		return "<a class=\"lineage\" href=\"javascript:editGridRow(" + grid + ",'" + row.ClientId + "');\">" + lblEdit + "</a>  <a class=\"lineage\" href=\"javascript:deleteGridRowPostBack(" + grid + ",'" + row.ClientId + "' ,'" + GridFlagInx + "',' " + row.Cells[GridFlagInx].Value + "','" + confirmation + "','" + confirmsg + "' );\">" + lblRemove + "</a>";
	} else {
		return "<a class=\"lineage\" href=\"javascript:editGridRow(" + grid + ",'" + row.ClientId + "');\">" + lblEdit + "</a>  <a class=\"lineage\" href=\"javascript:deleteGridRowPostBack(" + grid + ",'" + row.ClientId + "' ,'" + GridFlagInx + "','-1','" + confirmation + "','" + confirmsg + "' );\">" + lblRemove + "</a>";
	}
}
function deleteCustomGridRow(grid, rowId, flagcol, flagVal, confirmation, confmsg) {
	confmsg = lblDelCfmMsg;
	if (confirmation == "true") {
		if (confirm(confmsg)) {
			DeleteOperationGridPostBack(grid, rowId, flagcol, flagVal, confirmation);
		}
	} else {
		DeleteOperationGridPostBack(grid, rowId, flagcol, flagVal, confirmation);
	}
}

function CancelCustomGridEdit(grid, rowid, flagindx) {
	
	if (document.getElementById("ctl01_txtrowid") != null) {
		var trowid = document.getElementById("ctl01_txtrowid");
		if (trowid != null) {
			trowid.value = "";
		}
	}
	CancelGridEdit(grid, rowid, flagindx);
	if (typeof pageCancel != "undefined") {
		if (pageCancel == true) {
			CancelPageCustomGridEdit(grid, rowid, flagindx);
		}
	}
	if (window.ReRenderActionColumn) {
		window.ReRenderActionColumn(grid);
	}
	
	gridRowInEditMode = false;
}
function getGridFlagIndex(gridID) {
	var Index = gridID.Table.GetRowCount();
	if (Index == 0) {
		return -1;
	}
	var Item = gridID.Table.GetRow(Index - 1);
	var gridFlagIndex = -1;
	var i = 0;
	for (i = 0; i < gridID.Table.Columns.length; i++) {
		if (Item.Table.Columns[i].DataField.toLowerCase() == "gridflag") {
			gridFlagIndex = i;
			break;
		}
	}
	return gridFlagIndex;
}
function AddNewEmptyGridRow(gridID) {	
	gridID.Table.AddEmptyRow();
	GRIDADDMODE = 1;
	var Index = gridID.Table.GetRowCount();
	var Item = gridID.Table.GetRow(Index - 1);
	var gridFlagIndex = getGridFlagIndex(gridID);
	if (gridFlagIndex != -1) {
		Item.SetValue(gridFlagIndex, "1", true);
	}
	gridID.CurrentPageIndex = gridID.PageCount - 1;
	gridID.Render();
	gridID.Edit(Item);
}
function AddNewGridRow(gridID) {
	gridID.Table.AddRow();
	var Index = gridID.Table.GetRowCount();
	var Item = gridID.Table.GetRow(Index - 1);
	var gridFlagIndex = getGridFlagIndex(gridID);
	if (gridFlagIndex != -1) {
		Item.SetValue(gridFlagIndex, "1", true);
	}
	return false;
}
function ResetGridValues(grid, rowItem) {
	var rowItem = grid.Table.GetRow(rowItem);
	var gridIndex = getGridFlagIndex(grid);
	for (i = 0; i < grid.Table.GetRowCount(); i++) {
		if (i != gridIndex) {
			if (rowItem.Table.Columns[i].AllowEditing == true) {
				rowItem.SetValue(i, "", true);
			}
		}
	}
	if (gridIndex != "-1") {
		rowItem.SetValue(gridIndex, "2", true);//updated
	}
	grid.Render();
}
function ResetAllGridValues(grid, rowItem) {
	var rowItem = grid.Table.GetRow(rowItem);
	var gridIndex = getGridFlagIndex(grid);
	for (i = 0; i < grid.Table.GetRowCount(); i++) {
		if (i != gridIndex) {
			rowItem.SetValue(i, "", true);
		}
	}
	if (gridIndex != "-1") {
		rowItem.SetValue(gridIndex, "2", true);//updated
	}
	grid.Render();
}
function ClearCAGrid(grid) {
	var Index = grid.Table.GetRowCount();
	for (var i = 0; i < Index; i++) {
		grid.Select(grid.Table.GetRow(0));
		grid.DeleteSelected();
	}
	grid.Table.Data.length = 0;
	grid.RecordCount = 0;
	return true;
}

//disable the control after set the value ... eg. used in criteria succes grid in add plan page.
function setCustomCellValue(DataItem, col, field) {
	var mytextbox = document.getElementById(col);
	if (mytextbox != null) {
		if (DataItem.GetMember(field).Value != null) {
			mytextbox.value = DataItem.GetMember(field).Value;
			if (DataItem.GetMember("Key").Value == "0") {
				mytextbox.disabled = true;
			}
		} else {
			mytextbox.value = "";
		}
	}
	return true;
}
//Fucntion will return list of fields which configured for validation
function fnGetvalidatableFields(grid) {
	var arrfields = new Array();
	count = 0;
	for (i = 0; i < EditableGridControls.length; i++) {
		if (EditableGridControls[i].indexOf(":") != -1) {
			var fieldName = EditableGridControls[i].substring(EditableGridControls[i].indexOf(":") + 1);
			arrfields[count++] = fieldName;
		}
	}
	return arrfields;
}

    // Function to check if a string is null or empty
    // Returns true if the string is either null or empty, false otherwise
    function StringIsNullOrEmpty(str)
    {
        if(str == null || Trim(str).length == 0)
        {
            return true;
        }
        return false;    
    } 

    //trim the space for the given string ...
    function Trim(str) 
    {
	    return str.replace(/^\s*|\s*$/g, "");
    }

