 function checkindex()
		{
			var tag=true;
			var grid = igtbl_getGridById('Grid1xuwg');
			var rowCount = grid.Rows.length;
			var indexvalue;
			for (var i = 0;i < rowCount;i++)
			{
				var row = grid.Rows.getRow(i);
				indexvalue=row.getCell(1).getValue();
				if(indexvalue=="" || indexvalue==null)
				{
				    if(arguments && arguments[0]=='RateResponse')
				    { tag=true;}
				    else
				    {
					tag=false;
					document.all.tdMessage.colSpan = 2;
				    document.all.trMessage.style.display = 'block';
				    document.all.divMessage.innerHTML = "Error:<br>Please input a number greater than zero.<br><br>";
					}
				}
				
				for(var j=i+1;j<rowCount;j++)
				{
					var row2 = grid.Rows.getRow(j);
					if (indexvalue == row2.getCell(1).getValue())
					{
						document.all.tdMessage.colSpan = 2;
				        document.all.trMessage.style.display = 'block';
				        document.all.divMessage.innerHTML = "Error:<br>Sorry,the Index Rate you input already exist.<br><br>";
						tag=false;
					}
				}
			}
			return tag;
		}
		
function DelRow()
		{
			var grid = igtbl_getGridById('Grid1xuwg');	
			var row ;//= igtbl_getActiveRow('Grid1xuwg');
			
			if(igtbl_getLength(grid.SelectedRows) == 0)
			{
				document.all.tdMessage.colSpan = 2;
				document.all.trMessage.style.display = 'block';
				document.all.divMessage.innerHTML = "Please choose a row to delete.<br><br>";
				return false;
			}
			else
			{	
			    var RateKey;
			    if(document.getElementById("ddlRate").options.length>0)
                    RateKey=document.getElementById("ddlRate").options[document.getElementById("ddlRate").selectedIndex].value;
                
				for (var o in grid.SelectedRows)
				{
					row = igtbl_getRowById(o);
					var rowValue=row.getCell(1).getValue();	
				    AddMktFloaterConfirm("Confirm delete of row: index rate "+row.getCell(1).getValue(),AddFloaterOkFun,null);
                    //confirmbt("deleteRow","RateResponse.aspx?rowValue="+rowValue+"&RateKey="+RateKey,null);
                    //return false;                   			   
			    }
			}
		}
		
function ChangeTemplate(sender,id){var objCom=document.getElementById(id);if(sender.value==102||sender.value==107||sender.value==108){objCom.disabled=false;} else{objCom.disabled=true;objCom.selectedIndex=0;}}

function ShowUploding()
{
    document.getElementById("loading").style.display = "block";
    document.getElementById("Protec").style.display = "block";
    if(document.all)
        document.getElementById("Protec").innerHTML="<iframe frameborder='0' style='z-index:1000; text-align:center;vertical-align:middle;filter:Alpha(opacity=50);background-color:#EFEFEB;width:100%; height:100%;'></iframe>";
}
function HidUploding()
{
    document.getElementById("loading").style.display = "none";
    document.getElementById("Protec").style.display = "none";
}
function ChangeUploadInst2(file)
{	
    if (file.value.length != 0)
    {	
        if (file.getAttribute("isChange") == "0")	
        { 
            file.setAttribute("isChange","1");
            sum += 1;
	        document.all.ibUploadInstrument.src='../Img/up_add.gif';
	        document.all.ibReplace.src ='../Img/up_Replace.gif';
	        document.all.ibReplace.disabled=false;
	        document.all.ibUploadInstrument.disabled=false;
	    }
    }
	else if (file.getAttribute("isChange") == "1"){file.setAttribute("isChange","0");	sum -= 1;}
	
  if (sum ==0 )
 	{
	document.all.ibUploadInstrument.src='../Img/up_addgray.gif';
	document.all.ibReplace.src='../Img/up_Replacegray.gif';
	document.all.ibUploadInstrument.disabled=true;
	document.all.ibReplace.disabled=true;
	}
}
		
		function ShowPath(oButton, oEvent)
		{
		    ShowUploding();
			var obj = igtbl_getGridById("Grid1xuwg");

			if (obj != null)
			{
				var oColumns = obj.Bands[0].Columns;	
				
				if (oColumns[2].Key == "ID")	SetPathCol(oColumns,oButton,2,3);
				else	SetPathCol(oColumns,oButton,3,4);
			}
			HidUploding();
		}
		
		function SetPathCol(oColumns,oButton,colFull,colShort)
		{
				if (oButton.getText() == 'ShortPath')
				{
					oColumns[colFull].setHidden(true);
					oColumns[colShort].setHidden(false);
					oButton.setText('FullPath');
				}
				else
				{
					oColumns[colFull].setHidden(false);
					oColumns[colShort].setHidden(true);
					oButton.setText('ShortPath');
				}
		}
	
		function PolicyLimit(oButton, oEvent)
		{
			if (CheckRepeat(2,'Sorry,the new RateShock you input already exist') == true)
			{
				oEvent.needPostBack=true;
			}
		}
				
		function PrepayTable(oButton, oEvent)
		{
			if (CheckShift() == true)		oEvent.needPostBack=true;
		}
		
		function AccountLink(oButton, oEvent)
		{
			if (CheckLink('Grid1xuwg') == true)		oEvent.needPostBack=true;
		}
		
		function ReinvestChange(gridName,cellId)
		{		    
		    var cell = igtbl_getCellById(cellId);	
			if(cell.getOldValue()!=null&&cell.getOldValue()==cell.getValue())   return;
		    var oGrid = igtbl_getGridById(gridName);
			var oBands = oGrid.Bands;			
			var oRow=cell.Row;
			var oBand = oBands[0];
			var oColumns = oBand.Columns;			
			var oddColor="#d8e4f8";
			var evenColor="#ffffff";
			var editableColor="#efc980";
            if(cell.Column.Index==6)//Type
			{
			    var oMethod = oRow.getCell(19);
			    var oRate = oRow.getCell(20);
			    if(cell.getValue()==21)//Type=='Simple'
			    {
			        var oBalloon = oRow.getCell(8);//Balloon
			        oBalloon.setValue('NA');
			        oBalloon.setEditable(false);			        
			        oMethod.setValue(-1);
			        oMethod.setEditable(false);
			        oRate.setValue(-1);
			        oRate.setEditable(false);
			        var oRemIO=oRow.getCell(22);//RemIO (mo)
			        oRemIO.setValue('None');
			        oRemIO.setEditable(false);
			        
			        if (cell.getOldValue()==22)//Non
			        {
			            var oTeaSprd=oRow.getCell(15);//TeaSprd
			            oTeaSprd.setEditable(true);
			            oTeaSprd.Element.style.backgroundColor=editableColor;
			            if(oTeaSprd.getOldValue()!=null)
			                oTeaSprd.setValue(oTeaSprd.getOldValue());
			            else
			                oTeaSprd.setValue(0);			            
			        }
			        
			        if(oRow.getIndex()%2==1)
			        {
			            oBalloon.Element.style.backgroundColor=oddColor;
			            oMethod.Element.style.backgroundColor=oddColor;
			            oRate.Element.style.backgroundColor=oddColor;
			            oRemIO.Element.style.backgroundColor=oddColor;
			        }
			        else
			        {
			            oBalloon.Element.style.backgroundColor=evenColor;
			            oMethod.Element.style.backgroundColor=evenColor;
			            oRate.Element.style.backgroundColor=evenColor;
			            oRemIO.Element.style.backgroundColor=evenColor;
			        }
			    }
			    else if(cell.getValue()==22)//Type=='NonMaturity'
			    {
			        var oBalloon = oRow.getCell(8);//Balloon
			        if (cell.getOldValue()!=22)
			        {
			            if (oMethod.getOldValue()!=null)    oMethod.setValue(oMethod.getOldValue());
			            else oMethod.setValue(4);//Method=Model
			            oMethod.setEditable(true);
			            oMethod.Element.style.backgroundColor=editableColor;
			            if(oMethod.getValue()==4)//Method==Model
			            {
			                if (oRate.getOldValue()!=null)  oRate.setValue(oRate.getOldValue());
			                oRate.setEditable(true);
			                oRate.Element.style.backgroundColor=editableColor;
			            }
			            else
			            {
			                oRate.setValue(-1);
			                oRate.setEditable(false);
			                if(oRow.getIndex()%2==1)
			                    oRate.Element.style.backgroundColor=oddColor;
			                else
			                    oRate.Element.style.backgroundColor=evenColor;   
			            }			            			            			            
			        }
			        if(cell.getOldValue()!=21)
			        {
			            oBalloon.setValue('NA');
			            oBalloon.setEditable(false);
			            oBalloon.Element.style.backgroundColor=editableColor;
			            if(oBalloon.getOldValue()!=null)
			                oBalloon.setValue(oBalloon.getOldValue());
			            else
			                oBalloon.setValue(0);
			        }
			        
			        oBalloon.setValue('NA');
			        oBalloon.setEditable(false);
			        var oTeaSpr = oRow.getCell(15);//Tea Spr
			        oTeaSpr.setEditable(false);
			        var oRemIO=oRow.getCell(22);//RemIO (mo)
			        oRemIO.setValue('None');
			        oRemIO.setEditable(false);
			        if(oRow.getIndex()%2==1)
			        {
			            oRemIO.Element.style.backgroundColor=oddColor;
			            oBalloon.Element.style.backgroundColor=oddColor;
			            oTeaSpr.Element.style.backgroundColor=oddColor;
			        }
			        else
			        {
			            oRemIO.Element.style.backgroundColor=evenColor;
			            oBalloon.Element.style.backgroundColor=evenColor;
			            oTeaSpr.Element.style.backgroundColor=evenColor;
			        }
			    }
			    else if(cell.getValue()==31||cell.getValue()==35)//31,Type=='MBS';35,Type=='Loan'
			    {
			        var oBalloon = oRow.getCell(8);//Balloon	
			        oMethod.setValue(-1);
			        oMethod.setEditable(false);
			        oRate.setValue(-1);
			        oRate.setEditable(false);	
			        if(oRow.getIndex()%2==1)
			        {
			            oMethod.Element.style.backgroundColor=oddColor;
			            oRate.Element.style.backgroundColor=oddColor;
			        }
			        else
			        {
			            oMethod.Element.style.backgroundColor=evenColor;
			            oRate.Element.style.backgroundColor=evenColor;
			        }	      
			        if(cell.getOldValue()==21 ||cell.getOldValue()==22)//Simple or Non
			        {
			            oBalloon.setEditable(true);
			            oBalloon.Element.style.backgroundColor=editableColor;
			            if(oBalloon.getOldValue()!=null)
			                oBalloon.setValue(oBalloon.getOldValue());
			            else
			                oBalloon.setValue(0);
			            if (cell.getOldValue()==22)//Non
			            {
			                var oTeaSprd=oRow.getCell(15);//TeaSprd
			                oTeaSprd.setEditable(true);
			                oTeaSprd.Element.style.backgroundColor=editableColor;
			                if(oTeaSprd.getOldValue()!=null)
			                    oTeaSprd.setValue(oTeaSprd.getOldValue());
			                else
			                    oTeaSprd.setValue(0);			            
			            }
			        }
			        
			        var oRemIO=oRow.getCell(22);//RemIO (mo)
			        if(cell.getOldValue()!=31&&cell.getOldValue()!=35)
			        {
			            oRemIO.setEditable(true);
			            oRemIO.Element.style.backgroundColor=editableColor;
			            if(oRemIO.getOldValue()!=null)
			                oRemIO.setValue(oRemIO.getOldValue());
			            else
			                oRemIO.setValue(0);
			        }
			    }
			}// end Type
			else if(cell.Column.Index==9)//Fixed/Adj
			{
			    var oTeaserSpr=oRow.getCell(15);//Teaser Spr
			    var oRstFreq=oRow.getCell(23);//Reset Freq
			    var oFirstRst=oRow.getCell(24);//First Reset(mo)
			    var oLookback=oRow.getCell(25);//Lookback
			    var oPerCap=oRow.getCell(28);//Per Cap
			    var oPerFloor=oRow.getCell(29);//Per Floor
			    if(cell.getValue()==0)//Fixed/Adj=='Fixed'
			    {			        			        
			        oTeaserSpr.setEditable(false);
			        oRstFreq.setEditable(false);
			        oRstFreq.setValue(13);//set Reset Freq='NA'
			        oFirstRst.setEditable(false);
			        oLookback.setEditable(false);
			        oPerCap.setEditable(false);
			        oPerCap.setValue('None');
			        oPerFloor.setEditable(false);
			        oPerFloor.setValue('None');
			        
			        if(oRow.getIndex()%2==1)
			        {
			            oTeaserSpr.Element.style.backgroundColor=oddColor;
			            oRstFreq.Element.style.backgroundColor=oddColor;
			            oFirstRst.Element.style.backgroundColor=oddColor;
			            oLookback.Element.style.backgroundColor=oddColor;
			            oPerCap.Element.style.backgroundColor=oddColor;
			            oPerFloor.Element.style.backgroundColor=oddColor;
			        }
			        else
			        {
			            oTeaserSpr.Element.style.backgroundColor=evenColor;
			            oRstFreq.Element.style.backgroundColor=evenColor;
			            oFirstRst.Element.style.backgroundColor=evenColor;
			            oLookback.Element.style.backgroundColor=evenColor;
			            oPerCap.Element.style.backgroundColor=evenColor;
			            oPerFloor.Element.style.backgroundColor=evenColor;
			        }
			    }
			    else//Fixed/Adj=='Adjustable'
			    {
			        
			        oRstFreq.setEditable(true);
			        if(oRstFreq.getOldValue()==null||oRstFreq.getOldValue()==13)
			        {
			            oRstFreq.setValue(7);//Semiannually
			        }
			        else
			        {
			            oRstFreq.setValue(oRstFreq.getOldValue());
			        }			            
			        var oInstType = oRow.getCell(6);
			        if (oInstType.getValue() != 22)//NonMaturity
			        {
			            oTeaserSpr.setEditable(true);
			            oTeaserSpr.Element.style.backgroundColor=editableColor;
			        }
			        
			        oFirstRst.setEditable(true);
			        oLookback.setEditable(true);
			        oPerCap.setEditable(true);
			        oPerFloor.setEditable(true);
			        
			        oRstFreq.Element.style.backgroundColor=editableColor;
			        oFirstRst.Element.style.backgroundColor=editableColor;
			        oLookback.Element.style.backgroundColor=editableColor;
			        oPerCap.Element.style.backgroundColor=editableColor;
			        oPerFloor.Element.style.backgroundColor=editableColor;		        
			    }
			}//end Fixed/Adj
			else if(cell.Column.Index==19)//Method
			{
			    var oRate=oRow.getCell(20);
			    if(cell.getValue()==4)//Method==Model
			    {
			        if(oRate.getOldValue()!=null)   oRate.setValue(oRate.getOldValue());
			        else    oRate.setValue(-1);
			        oRate.setEditable(true);
			        oRate.Element.style.backgroundColor=editableColor;
			    }
			    else
			    {
			        SetCellReadOnly(cell,20,-1);
			        
			    }
			}//End Method
		}		
		
		function SetCellReadOnly(cell,col,dftValue)
		{
			cell.Row.getCell(col).setValue(dftValue);
			cell.Row.getCell(col).setEditable(false);
			
			if (cell.Row.getIndex()%2 == 1)
				cell.Row.getCell(col).Element.style.backgroundColor = "#d8e4f8";
			else
				cell.Row.getCell(col).Element.style.backgroundColor = "#ffffff";
		}
		
		function SetCellEdit(cell,col)
		{
			cell.Row.getCell(col).setEditable(true);
			cell.Row.getCell(col).Element.style.backgroundColor = "#efc980";
		}		
		
		function ChangeGrowthType(gridName, cellId)
		{
		    var cell = igtbl_getCellById(cellId);	
		    if (cell.getOldValue()!=null&&cell.getOldValue()==cell.getValue())  return;
			var oGrid = igtbl_getGridById(gridName);
			var oBands = oGrid.Bands;			
			var oBand = oBands[0];
			var oColumns = oBand.Columns;			
			var elem = cell.Element;
			//elem.runtimeStyle.backgroundColor = "Red";
			var growthTypeIndex=6;
			if (cell.Column.Index == growthTypeIndex)
			{
				if (cell.getValue() == 1 || cell.getValue() == 2)//GrowthType=='None' or 'Maintain'
				{
				    if (cell.getOldValue()==null || (cell.getOldValue()!=1&&cell.getOldValue()!=2))
				    {
					    for (var i = growthTypeIndex+1;i < oColumns.length;i++)
					    {
						    cell.Row.getCell(i).setValue(null);
						    cell.Row.getCell(i).setEditable(false);
						
						    if (cell.Row.getIndex()%2 == 1)
							    cell.Row.getCell(i).Element.style.backgroundColor = "#d8e4f8";
						    else
							    cell.Row.getCell(i).Element.style.backgroundColor = "#ffffff";
					    }
					 }					
				}
				else//GrowthType=='Target' or 'NewBusiness' or PrRunoff
				{
				    if(cell.getOldValue()==null||(cell.getOldValue()==1||cell.getOldValue()==2))
				    {
					    for (var i = growthTypeIndex+1;i < oColumns.length;i++)
					    {
						    cell.Row.getCell(i).setValue(0);
						    cell.Row.getCell(i).setEditable(true);
						    cell.Row.getCell(i).Element.style.backgroundColor = "#efc980";
					    }	
					}
				}
			}
			if (cell.Column.Index>growthTypeIndex)			
			{
			    if (SchedTargetParser(cell.getValue()) == false)
			        cell.setValue(cell.getOldValue());
			}
		}
		
		function ChangePeriod(gridName, cellId)
		{			
		    var oGrid=igtbl_getGridById(gridName);var oBands=oGrid.Bands;var oBand=oBands[0];var oColumns=oBand.Columns
		    var cell = igtbl_getCellById(cellId);	
		    if (cell.getOldValue()!=null&&cell.getOldValue()==cell.getValue())  return;
		    var growthTypeIndex=5;
		    if(cell.Column.Index>5)//Period
		    {
		        if (SchedTargetParser(cell.getValue()) == false)
			        cell.setValue(cell.getOldValue());
		    }
		    if(cell.Column.Index==growthTypeIndex) {
				if(cell.getValue()==1)//GrowthType=='None'
				{
					for(var i=growthTypeIndex+1;i<oColumns.length;i++) {
						cell.Row.getCell(i).setValue(0);
					}
				}
			}
		}
		
		function SchedTargetParser(schedTarget)
        {
            var rtnVal = true;
            var constTarget=0;
            var mult = 0;
            try
            {
                var idxPercent = schedTarget.lastIndexOf('%');
                if (idxPercent < 0)
                {
                    if(isNaN(schedTarget))
                        return false;
                }
                else
                {
                    var tmpFormula = schedTarget.substring(0, idxPercent);
                    var idxPlus = tmpFormula.lastIndexOf('+');
                    var idxMinus = tmpFormula.lastIndexOf('-');
                    var idxSpliter = (idxPlus > idxMinus) ? idxPlus : idxMinus;
                    if (idxSpliter > 0)
                    {
                        if(isNaN(tmpFormula.substring(0, idxSpliter)) ||isNaN(tmpFormula.substring(idxSpliter))) 
                            return false;
                    }
                    else
                    {
                        if(isNaN(tmpFormula)) return false;
                    }
                }
            }
            catch(e)
            {
                rtnVal = false;
            }
            return rtnVal;
        }
		
		function ConfirmMessage(obj,message)
		{			
			if (obj.checked == true)
			{
				if (confirm(message) == false)
					obj.checked = false;
			}
		}
		
		function GoTo(url)
		{
			var param = window.location.search;
			var type = GetType(param);
		    window.location=url+'?type='+type;
		}
		
		function EditLink()
		{
			var param = window.location.search;
			var type = GetType(param);
			//alert(param);
			document.all.content.src = '../Account/AccountLink.aspx?type='+type;
		}
		
		function pos_uwg_AfterExitEditModeHandler(gridName, cellId)
		{
			var oGrid = igtbl_getGridById(gridName);
			var oBands = oGrid.Bands;
			var oBand = oBands[0];
			var oColumns = oBand.Columns;								
			var oRows =  oGrid.Rows;
			var oRow;
			var cell = igtbl_getCellById(cellId);			
			
			if (cell.Column.Index == 5 || cell.Column.Index == 6 || cell.Column.Index == 7 ||cell.Column.Index == 9 ||cell.Column.Index ==10)
			{	
			    var selectedInst = 0; var currNotional=0;var bookvalue=0;var mktvalue=0;		
				for (var i = 0;i < oRows.length;i++){
					oRow = oRows.getRow(i);					
					if (oRow.getHidden() == false){	
						oRow.getCell(8).setValue(parseFloat(oRow.getCell(6).getValue())*parseFloat(oRow.getCell(7).getValue()));
				        oRow.getCell(11).setValue(parseFloat(oRow.getCell(8).getValue())*parseFloat(oRow.getCell(9).getValue())/100.0);
					    oRow.getCell(12).setValue(parseFloat(oRow.getCell(8).getValue())*parseFloat(oRow.getCell(10).getValue())/100.0);
					    if(oRow.getCell(5).getValue() == true){ selectedInst++;		
					    currNotional = parseFloat(currNotional)+parseFloat(oRow.getCell(8).getValue());
					    bookvalue=parseFloat(bookvalue)+parseFloat(oRow.getCell(11).getValue());	
					    mktvalue=parseFloat(mktvalue)+parseFloat(oRow.getCell(12).getValue());	
					    }
					}
				}
				oColumns[5].setFooterText(selectedInst);
				oColumns[8].setFooterText(DisplayFormat(currNotional,0));
				oColumns[11].setFooterText(DisplayFormat(bookvalue,0));
				oColumns[12].setFooterText(DisplayFormat(mktvalue,0));
			}
		}
		
		function SetAllChecked()
		{	
			if(allFlag == 1)
			{
				var menuHType1 = igmenu_getMenuById("Grid1Hmenu");
				var menuHType2 = igmenu_getMenuById("Grid2Hmenu");
				var topH = menuHType1.getItems()[0];
				var subH = topH.getItems();
				SetAllCheck(subH);
				
				topH = menuHType2.getItems()[0];
				subH = topH.getItems();
				SetAllCheck(subH);
			}
		}
		
		function SetAllCheck(subH)
		{
			var iM;
				
			for (iM = 0;iM <subH.length;iM++)
			{
				if (subH[iM].getTag() == -1)
				{
					subH[iM].setChecked(true);
				}
				else
				{
					subH[iM].setChecked(false);
				}
			}
		}
		
		function SetInclude(menuId, itemId)
		{
			var menuInstType,menuHierarchy;
			var oGrid1 = igtbl_getGridById("Grid1xuwg");
			var oGrid2 = igtbl_getGridById("Grid2xuwg");
			var menuHType1 = igmenu_getMenuById("Grid1uwm");
			var menuHType2 = igmenu_getMenuById("Grid2uwm");
			var oGrid;
			var item = igmenu_getItemById(itemId);
						
			if (menuId.indexOf("Grid1") != -1)
			{
				menuHierarchy = menuHType1;
				oGrid = oGrid1;
			}
			else if (menuId.indexOf("Grid2") != -1)
			{
				menuHierarchy = menuHType2;
				oGrid = oGrid2;
			}
			
			if (item.getTag() != -1)
			{
				if (item.getTag() == 1)
					SetIncludeVal(oGrid,true);
				else
					SetIncludeVal(oGrid,false);
			}
		}
		
		function SetIncludeVal(grid,isInclude)
		{
			var oBands = grid.Bands;
			var oBand = oBands[0];
			var oColumns = oBand.Columns;								
			var oRows =  grid.Rows;
			var selectedInst = 0,currNotional = 0;
			
			for (var i = 0;i < oRows.length;i++)
			{
				var oRow = oRows.getRow(i);
				if (oRow.getHidden() == true) continue;
				oRow.getCell(4).setValue(isInclude);
				if (isInclude == true)
				{
					selectedInst++;
					currNotional = parseFloat(currNotional)+parseFloat(oRow.getCell(7).getValue());
				}
			}
			
			oColumns[4].setFooterText(selectedInst);
			oColumns[7].setFooterText(DisplayFormat(currNotional,0));		
		}
		
		function Filter(menuId,itemId,bChecked)
		{
			var menuInstType,menuHierarchy;
			var oGrid1 = igtbl_getGridById("Grid1xuwg");
			var oGrid2 = igtbl_getGridById("Grid2xuwg");
			/*var menuInstType1 = igmenu_getMenuById("Grid1uwm");
			var menuInstType2 = igmenu_getMenuById("Grid2uwm");*/
			var menuHType1 = igmenu_getMenuById("Grid1Hmenu");
			var menuHType2 = igmenu_getMenuById("Grid2Hmenu");
			var oGrid;
						
			if (menuId.indexOf("Grid1") != -1)
			{
				//menuInstType = menuInstType1;
				menuHierarchy = menuHType1;
				oGrid = oGrid1;
			}
			if (menuId.indexOf("Grid2") != -1)
			{
				//menuInstType = menuInstType2;
				menuHierarchy = menuHType2;
				oGrid = oGrid2;
			}
			
			var oBands = oGrid.Bands;
			var oBand = oBands[0];
			var oColumns = oBand.Columns;								
			var oRows =  oGrid.Rows;
			var oRow;
			var rowCount = oGrid.Rows.length;
			//var topInst = menuInstType.getItems()[0];
			var topH = menuHierarchy.getItems()[0];
			//var subInst = topInst.getItems();
			var subH = topH.getItems();
			var selectedInst = 0,currNotional = 0;	
			var checkedH = new Array();			
		
			//checkedInst = DetectChecked(subInst,itemId,bChecked);
			checkedH = DetectChecked(subH,itemId,bChecked);
			
			if (checkedH.length == 0)
			{
				for(var iRow = 0;iRow < rowCount;iRow++)
				{
					oRow = oRows.getRow(iRow);
					oRow.setHidden(true);
				}
			}
			else
			{
				if (checkedH[0] == -1)
				{
					for(var iRow = 0;iRow < rowCount;iRow++)
					{						
						oRow = oRows.getRow(iRow);
						oRow.setHidden(false);
						
						if (oRow.getCell(4).getValue() == true)
						{
							selectedInst++;
							oRow.getCell(7).setValue(parseFloat(oRow.getCell(5).getValue())*parseFloat(oRow.getCell(6).getValue()));
							currNotional = parseFloat(currNotional)+parseFloat(oRow.getCell(7).getValue());
						}
					}
				}
				else
				{
					var iM;
					var low,high;				
					
					for (var iRow = 0;iRow < rowCount;iRow++)
					{
						oRow = oRows.getRow(iRow);
						low = 0;
						high = checkedH.length-1;
						
						while(high-low>1)
						{
							var pos = parseInt((high+low)/2);
							
							if (checkedH[pos]>oRow.getCell(1).getValue())
								high = pos;
							else
								low = pos;
						}
						
						for (iM = low;iM <=high;iM++)
						{
							if (checkedH[iM] == oRow.getCell(1).getValue())
							{
								oRow.setHidden(false);
							
								if (oRow.getCell(4).getValue() == true)
								{
									selectedInst++;
									oRow.getCell(7).setValue(parseFloat(oRow.getCell(5).getValue())*parseFloat(oRow.getCell(6).getValue()));
									currNotional = parseFloat(currNotional)+parseFloat(oRow.getCell(7).getValue());
								}
								
								break;
							}
						}
						
						if (iM > high)
							oRow.setHidden(true);						
					}
				}			
			}
			
			oColumns[4].setFooterText(selectedInst);
			oColumns[7].setFooterText(DisplayFormat(currNotional,0));				
		}
		
		
		function DetectChecked(subM,itemId,bChecked)
		{		
			var item = igmenu_getItemById(itemId);
			var checkedM = new Array();
			var iCheck = 0;
			var low = 0,high = subM.length-1;
			var itemExist = false;
			
			while(high-low>1)
			{
				var p = parseInt((high+low)/2);
				
				if (subM[p].getText() > item.getText())
					high = p;
				else
					low = p;
			}
			
			for (var i = low;i <=high;i++)
			{
				if (subM[i].Id == itemId)
				{
					itemExist = true;
					break;
				}
			}
			
			for (var i = 0;i < subM.length;i++)
			{
				if (subM[i].Id != itemId)
				{
					if (subM[i].getTag() == -1 && subM[i].getChecked() == true)
					{
						if (itemExist == false)
						{
							checkedM[0] = -1;
							break;
						}
						else
						{
							subM[i].setChecked(false);
						}
					}
					else if (subM[i].getChecked() == true)
					{
						checkedM[iCheck] = subM[i].getText();
						iCheck++;
					}
				}
				else if (bChecked == true)
				{
					if (item.getTag() == -1)
					{
						checkedM[0] = -1;
						break;
					}
					else
					{
						checkedM[iCheck] = item.getText();
						iCheck++;
					}
				}
			}

			return checkedM;
		}		
		
		function DisplayFormat(inVal,digitalLen)
		{
			var retVal="",dotPos,split = 0,tempVal="";
			
			inVal = inVal.toString();				
			dotPos = inVal.indexOf(".");

			if (dotPos == -1)
			{
				for (var i = 0;i < digitalLen;i++)
				{
					retVal = retVal + "0";
				}
				
				if (digitalLen > 0)		retVal += ".";				
				
				for (var i = inVal.length-1;i >= 0;i--)
				{
					if (split == 3)
					{
						retVal += ","+inVal.charAt(i);
						split = 1;
					}
					else
					{
						retVal += inVal.charAt(i);
						split++;
					}
				}
			}
			else
			{
				var currLen = inVal.length - dotPos -1;
				var intPart = inVal.substring(0,dotPos);
				
				if (digitalLen > 0)
				{
					if (currLen == digitalLen)
					{
						for (var i = inVal.length-1;i >= dotPos;i--)
						{
							retVal += inVal.charAt(i);
						}
					}
					else if (currLen > digitalLen)
					{
						for (var i = inVal.length-currLen+digitalLen-1;i >= dotPos;i--)
						{
							retVal += inVal.charAt(i);
						}
					}
					else
					{
						for (var i = 0;i < digitalLen-currLen;i++)
						{
							retVal += "0";
						}
					
						for (var i = inVal.length-1;i>=dotPos;i--)
						{
							retVal += inVal.charAt(i);
						}
					}
				}
				
				for (var i = intPart.length-1;i >= 0;i--)
				{
					if (split == 3)
					{
						retVal += ","+intPart.charAt(i);
						split = 1;
					}
					else
					{
						retVal += intPart.charAt(i);
						split++;
					}
				}
			}			
			
			for (var i = retVal.length-1;i>=0;i--)
			{
				tempVal += retVal.charAt(i);
			}
			
			return tempVal;
		}
		
		function CheckLink(gridName)
		{
			var oGrid = igtbl_getGridById(gridName);
			var oRows = oGrid.Rows;		
			var oBands = oGrid.Bands;
			var oBand = oBands[0];
			var oColumns = oBand.Columns;
			var count = oColumns.length;
			var row;
			var expre = /^ +$/;
			var url = /^(https?:\/\/)?([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*)?$/;
			re = new RegExp(expre)
			
			for (var i = 0;i < oRows.length;i++)
			{
				row = oRows.getRow(i);
	
				if (row.getCell(2).getValue() == null || row.getCell(2).getValue().length == 0 || row.getCell(2).getValue().match(re) != null)
				{
					DisplayMessage("Please input Link Name.<br><br>",1);
					return false;
				}
				
				if (row.getCell(3).getValue() == null || row.getCell(3).getValue().length == 0 || row.getCell(3).getValue().match(re) != null)
				{
					DisplayMessage("Please input Link URL.<br><br>",1);
					return false;
				}				
				
				if (row.getCell(3).getValue().match(url) == null)
				{
					DisplayMessage("Link URL format is not correct.<br><br>",1);
					return false;
				}
			}
			
			return true;
		}
		function checkInvalidChars(ctl)
		{
		    var invalidChars=new RegExp(/["%","<",">","*","$"]+/);
		    var matchcontent=ctl.value.match(invalidChars);
			if(matchcontent != null)
			{
			    DisplayMessage("Invalid chars "+matchcontent+".<br><br>",2);
				return false;
		    }
		}
		
		function CheckAccount()
		{
			var r, re;                     
			var expre = /^ +$/;
			var regEx = /^[\w\.-]+(\+[\w-]*)?@([\w-]+\.)+[\w-]+$/;
			var regFiscal1 = /^[1-12]{1}\/[1-9]{1}\d{3}$/;
			var regFiscal2 = /^[0]{1}[1-9]{1}\/[1-9]{1}\d{3}$/;
			var regFiscal3 = /^[1]{1}[0-2]{1}\/[1-9]{1}\d{3}$/;
			var nameMaxLength=25;
			var faxMaxLength=20;
			var emailMaxLength=50;
			var phoneMaxLength=20;
			var companyMaxLength=30;
			var addressMaxLength=30;
			var citymaxLength=50;
			var stateMaxLength=30;
			var zipMaxLength=10;
			var invalidChars=new RegExp(/["%","<",">","*","$"]+/);
			re = new RegExp(expre)
          if(document.getElementById("RadioSelect_0").checked==true)
          {
			if (document.all.tbPrimaryName.value.length == 0 || document.all.tbPrimaryName.value.match(re) != null)
			{
				DisplayMessage("Please input Primary Model Operator Name.<br><br>",2);
				return false;
			}		
			
			if(document.all.tbPrimaryName.value.length>nameMaxLength)
			{
				DisplayMessage("Primary Model Operator Name's length can not be more "+nameMaxLength+".<br><br>",2);
				return false;
			}
			if(document.all.tbPrimaryName.value.match(invalidChars))
			{
			    DisplayMessage("Primary Model Operator Name has invalid chars: "+document.all.tbPrimaryName.value.match(invalidChars)+".<br><br>",2);
			    return false;
			}

           
			if (document.all.tbPrimaryEmail.value.length == 0 || document.all.tbPrimaryEmail.value.match(re) != null)
			{
				DisplayMessage("Please input Primary Model Operator Email.<br><br>",2);
				return false;
			}
			if(document.all.tbPrimaryEmail.value.length>emailMaxLength)
			{
				DisplayMessage("Length of Primary Model Operator's Email can not be more"+emailMaxLength+".<br><br>",2);
				return false;
			}
			
			if (document.all.tbPrimaryEmail.value != document.all.tbPrimaryEmail.OldValue && document.all.tbPrimaryEmail.value.match(regEx) == null)
			{
				DisplayMessage("Primary Model Operator email format is incorrect: please reenter the address.<br><br>",2);
				return false;				
			}			
			
			if (document.all.tbSecondaryEmail.value != document.all.tbSecondaryEmail.OldValue && document.all.tbSecondaryEmail.value.match(regEx) == null)
			{
				document.all.tbSecondaryEmail.value="mail@mail.com";		
			}
			if (document.all.tbSecondaryEmail.value.length == 0 || document.all.tbSecondaryEmail.value.match(re) != null)
			{
				document.all.tbSecondaryEmail.value="mail@mail.com";
			}
			
			if (document.all.tbPrimaryPhone.value.length == 0 || document.all.tbPrimaryPhone.value.match(re) != null)
			{
				DisplayMessage("Please input Primary Model Operator Phone Number.<br><br>",2);
				return false;
			}
			if(document.all.tbPrimaryPhone.value.length>phoneMaxLength)
			{
				DisplayMessage("Length of Primary Model Operator Phone number can not be more"+phoneMaxLength+".<br><br>",2);
				return false;
			}
			if(document.all.tbPrimaryPhone.value.match(invalidChars))
			{
			    DisplayMessage("Primary Model Operator Phone Number has invalid chars:"+document.all.tbPrimaryPhone.value.match(invalidChars)+".<br><br>",2);
			    return false;
			}
			
//			if (document.all.tbPrimaryFax.value.length == 0 || document.all.tbPrimaryFax.value.match(re) != null)
//			{
//				DisplayMessage("Please input Primary Model Operator Fax Number.<br><br>",2);
//				return false;
//			}
//			if(document.all.tbPrimaryFax.value.length>faxMaxLength)
//			{
//				DisplayMessage(" Length of Primary Model Operator's Fax Number can not be more "+faxMaxLength+".<br><br>",2);
//				return false;
//			}
//			if(document.all.tbPrimaryFax.value.match(invalidChars))
//			{
//			    DisplayMessage("Primary Model Operator's Fax Number has invalid chars:"+document.all.tbPrimaryFax.value.match(invalidChars)+".<br><br>",2);
//				return false;
//			}
			
	     }
	   else if(document.getElementById("RadioSelect_1").checked==true)
       {
			 if(document.all.tbSecondaryName.value.match(invalidChars))
			{
			    DisplayMessage("Secondary Model Operator Name has invalid chars: "+document.all.tbSecondaryName.value.match(invalidChars)+".<br><br>",2);
			    return false;
			}
			
			if (document.all.tbSecondaryName.value.length == 0 || document.all.tbSecondaryName.value.match(re) != null)
			{
				DisplayMessage("Please input Secondary Model Operator Name.<br><br>",2);
				return false;
			}
			if(document.all.tbSecondaryName.value.length>nameMaxLength)
			{
				DisplayMessage("Length of Secondary Model Operator Name can not be more "+nameMaxLength+".<br><br>",2);
				return false;
			}
			
			
			if (document.all.tbSecondaryEmail.value.length == 0 || document.all.tbSecondaryEmail.value.match(re) != null)
			{
				DisplayMessage("Please input Secondary Model Operator Email.<br><br>",2);
				return false;
			}
			if(document.all.tbSecondaryEmail.value.length>emailMaxLength)
			{
			    DisplayMessage("Length of Secondary Model Operator Email can not be more"+emailMaxLength+".<br><br>",2);
				return false;
			}
			
			if (document.all.tbSecondaryEmail.value != document.all.tbSecondaryEmail.OldValue && document.all.tbSecondaryEmail.value.match(regEx) == null)
			{
				DisplayMessage("Secondary Model Operator email format is incorrect: please reenter the address.<br><br>",2);
				return false;				
			}
			if (document.all.tbPrimaryEmail.value != document.all.tbPrimaryEmail.OldValue && document.all.tbPrimaryEmail.value.match(regEx) == null)
			{
				document.all.tbPrimaryEmail.value="mail@mail.com";			
			}	
			if (document.all.tbPrimaryEmail.value.length == 0 || document.all.tbPrimaryEmail.value.match(re) != null)
			{
				document.all.tbPrimaryEmail.value="mail@mail.com";
			}
			
			if (document.all.tbSecondaryPhone.value.length == 0 || document.all.tbSecondaryPhone.value.match(re) != null)
			{
				DisplayMessage("Please input Secondary Model Operator Phone.<br><br>",2);
				return false;
			}
			if(document.all.tbSecondaryPhone.value.length>phoneMaxLength)
			{
			    DisplayMessage("Secondary Model Operator Phone's Length can not be more "+phoneMaxLength+".<br><br>",2);
				return false;
			}
			if(document.all.tbSecondaryPhone.value.match(invalidChars))
			{
			   DisplayMessage("Secondary Model Operator Phone has invalid chars:"+document.all.tbSecondaryPhone.value.match(invalidChars)+".<br><br>",2);
				return false;
			}
			
//			if (document.all.tbSecondaryFax.value.length == 0 || document.all.tbSecondaryFax.value.match(re) != null)
//			{
//				DisplayMessage("Please input Secondary Model Operator Fax.<br><br>",2);
//				return false;
//			}
//			if(document.all.tbSecondaryFax.value.length>faxMaxLength)
//			{
//				DisplayMessage("Secondary Model Operator Fax's length can not be more "+faxMaxLength+".<br><br>",2);
//				return false;
//			}
//			if(document.all.tbSecondaryFax.value.match(invalidChars))
//			{
//			    DisplayMessage("Secondary Model Operator Fax has invalid chars:"+document.all.tbSecondaryFax.value.match(invalidChars)+".<br><br>",2);
//				return false;
//			}
	  }
			if (document.all.tbCompany.value.length == 0 || document.all.tbCompany.value.match(re) != null)
			{
				DisplayMessage("Please input Company.<br><br>",2);
				return false;
			}
			if(document.all.tbCompany.value.match(invalidChars))
			{
			    DisplayMessage("Company has invalid chars: "+document.all.tbCompany.value.match(invalidChars)+".<br><br>",2);
				return false;
			}
			
			if (document.all.tbAddress1.value.length == 0 || document.all.tbAddress1.value.match(re) != null)
			{
				DisplayMessage("Please input Address1.<br><br>",2);
				return false;
			}
			if(document.all.tbAddress1.value.match(invalidChars))
			{
			    DisplayMessage("Address1 has invalid chars:"+document.all.tbAddress1.value.match(invalidChars)+".<br><br>",2);
				return false;
			}
			if(document.all.tbAddress2.value.match(invalidChars))
			{
			   DisplayMessage("Address2 has invalid chars:"+document.all.tbAddress2.value.match(invalidChars)+".<br><br>",2);
				return false;
			}
			
			
//			if (document.all.tbCity.value.length == 0 || document.all.tbCity.value.match(re) != null)
//			{
//				DisplayMessage("Please input City.<br><br>",2);
//				return false;
//			}
//			if(document.all.tbCity.value.length>citymaxLength)
//			{
//				DisplayMessage("City's length can not be more "+citymaxLength+".<br><br>",2);
//				return false;
//			}
//			if(document.all.tbCity.value.match(invalidChars))
//			{
//			    DisplayMessage("City has invalid chars:"+document.all.tbCity.value.match(invalidChars)+".<br><br>",2);
//				return false;
//			}
//			
//			if (document.all.tbState.value.length == 0 || document.all.tbState.value.match(re) != null)
//			{
//				DisplayMessage("Please input State.<br><br>",2);
//				return false;
//			}
//			if(document.all.tbState.value.length>stateMaxLength)
//			{				
//			    DisplayMessage("State's length can not be more "+stateMaxLength+".<br><br>",2);
//				return false;
//			}
//			if(document.all.tbState.value.match(invalidChars))
//			{
//			    DisplayMessage("State has invalid chars: "+document.all.tbState.value.match(invalidChars)+".<br><br>",2);
//				return false;
//			}
//			
//			if (document.all.tbZip.value.length == 0 || document.all.tbZip.value.match(re) != null)
//			{
//				DisplayMessage("Please input Zip.<br><br>",2);
//				return false;
//			}
//			if(document.all.tbZip.value.length>zipMaxLength)
//			{
//			    DisplayMessage("Zip's length can not be more "+zipMaxLength+".<br><br>",2);
//				return false;
//			}
//			if(document.all.tbZip.value.match(invalidChars))
//			{
//			    DisplayMessage("Zip has invalid chars: "+document.all.tbZip.value.match(invalidChars)+".<br><br>",2);
//				return false;
//			}
			return true;		
		}
		
		function Decay(gridName, cellId)
		{
			var oGrid = igtbl_getGridById(gridName);
			var oRow = igtbl_getRowById(cellId);	
			var cell = oRow.getCell(0);	
			window.open('EarDecay.aspx?instkey='+cell.getValue(),'','toolbar=no,menubar=no,titlebar=yes,directories=no,resizable=no,status=yes,fullscreen=no,top=300,left=500,scrollbars=yes,width=300,height=550');
		}
		
		function Methodchanged(gridName, selectId, cellId)
		{
		
			var oGrid = igtbl_getGridById(gridName);
			var oRow = igtbl_getRowById(cellId);	
			var cell = oRow.getCell(0);	

			if(cellId=="Grid1xuwg_rc_0_20")
			{
	           if(document.getElementById(selectId).value==1)
	           {
	           	 var arrayValueS=oRow.getCell(21).Column.ValueList.toString().split(",")[0];
			       oRow.getCell(21).setValue(arrayValueS);
			       
			        oRow.getCell(22).setValue(-1);
			       	oRow.getCell(21).setEditable(true);
			        oRow.getCell(22).setEditable(false);
//	           		oRow.getCell(23).setEditable(true);
//			        oRow.getCell(24).setEditable(true);
	           }
	           else if(document.getElementById(selectId).value==4)
			   {
//			        oRow.getCell(23).setValue("NA");
//			        oRow.getCell(24).setValue("NA");
//			        oRow.getCell(23).setEditable(false);
//			        oRow.getCell(24).setEditable(false);
			       oRow.getCell(21).setEditable(true);
			       oRow.getCell(22).setEditable(true);
			       
			       var arrayValueS=oRow.getCell(21).Column.ValueList.toString().split(",")[0];
			       oRow.getCell(21).setValue(arrayValueS);
			       var arrayValue2=oRow.getCell(22).Column.ValueList.toString().split(",")[0];
			       oRow.getCell(22).setValue(arrayValue2);
			   }
			   else
			   {
			       oRow.getCell(21).setEditable(false);
			       oRow.getCell(22).setEditable(false);	
//			       	oRow.getCell(23).setEditable(false);
//			        oRow.getCell(24).setEditable(false);
			        
	           		oRow.getCell(21).setValue(-1);
			        oRow.getCell(22).setValue(-1);
//			       	 oRow.getCell(23).setValue("NA");
//			        oRow.getCell(24).setValue("NA");
			       
			   }
			}
			
			//window.open('EarDecay.aspx?instkey='+cell.getValue(),'','toolbar=no,menubar=no,titlebar=yes,directories=no,resizable=no,status=yes,fullscreen=no,top=300,left=500,scrollbars=yes,width=300,height=550');
		}
				
		function PopPortfolio()
		{
			var param = window.location.search;
			var earKey,acctKey;
			
			earKey = ParseParam(param)[0];
			acctKey = ParseParam(param)[1];
			window.open('PortfolioAssumption.aspx?earkey='+earKey+'&acctkey='+acctKey,'','location=no,status=yes,toolbar=no,menubar=no,scrollbars=yes,width=800,height=630');
		}
		
		function ParseParam(param)
		{
			var pos = param.indexOf("?");
			var arr = param.substring(pos+1).split("&");
			var paramArr,earKey,acctKey;
			
			for (i = 0;i < arr.length;i++)
			{
				paramArr = arr[i].split("=");
				
				if (paramArr[0] == "earkey")	earKey= paramArr[1];
				if (paramArr[0] == "acctkey")	acctKey = paramArr[1];
			}
			
			return new Array(earKey,acctKey);
		}
		
		function GetType(param)
		{
			var pos = param.indexOf("?");
			var arr = param.substring(pos+1).split("&");
			var type,paramArr;
			
			for (i = 0;i < arr.length;i++)
			{
				paramArr = arr[i].split("=");
				
				if (paramArr[0] == "type")	
				{
					type= paramArr[1];
					break;
				}
			}
			
			return type;
		}			
		
		function CheckLog(source,Results)
		{
		if (source==10)
		{
		    var result=document.getElementById('DDResult');
		    if(result.options.length>0&&result.selectedIndex!=-1)
		    {var url = '../RunLog/Log.aspx?Flag=RESULTDETAIL&ResultKey='+result.options[result.selectedIndex].value;
			 window.open(url,'','toolbar=no,titlebar=yes,directories=no,status=yes,location=no,scrollbars=no,width=802,height=792');		    
		    }
		}
		else if (source==11) 
		{
		    var result=document.getElementById('DDResult');
		    if(result.options.length>0&&result.selectedIndex!=-1)
		    {var url = '../RunLog/Log.aspx?Flag=RESULTERR&ResultKey='+result.options[result.selectedIndex].value;
			 window.open(url,'','toolbar=no,titlebar=yes,directories=no,status=yes,location=no,scrollbars=no,width=802,height=792');		    
		    }
		}
		else
		{
		    var grid = igtbl_getGridById(Results);	
            var row ;
            
			//var obj = event.srcElement;
			if (igtbl_getLength(grid.SelectedRows)==0 && igtbl_getLength(grid.SelectedCells)==0)	
			{
				DisplayMessage('Please choose a result at first',1)
				return false;
			}
			if(igtbl_getLength(grid.SelectedRows) ==0)
		    {
		        var Cell;
		        for (var o in grid.SelectedCells)
			    {
				    Cell = igtbl_getCellById(o);
	            } 
	            row = Cell.getRow();
		    }
			else
			{
			     for (var o in grid.SelectedRows)
				    row = igtbl_getRowById(o);
			}
			
			if (source == 1)
			{
				if (row.getCellFromKey("Run Log").getValue() == "1" || row.getCellFromKey("Run Log").getValue() == "3")
				{
					var url = '../RunLog/Log.aspx?Flag=RESULTDETAIL&ResultKey='+row.getCellFromKey("RunKey").getValue();
					window.open(url,'','toolbar=no,titlebar=yes,directories=no,status=yes,location=no,scrollbars=no,width=800,height=780');
				}
			}
			else
			{
				if (row.getCellFromKey("Run Log").getValue() == "2" || row.getCellFromKey("Run Log").getValue() == "3")
				{
					var url = '../RunLog/Log.aspx?Flag=RESULTERR&ResultKey='+row.getCellFromKey("RunKey").getValue();
					window.open(url,'','toolbar=no,titlebar=yes,directories=no,status=yes,location=no,scrollbars=no,width=800,height=780');
				}
			}
		}
			return false;
		}
		
		function IsReport(ev)
		{
			var isExcel;
			var isPdf;
			var report;
			if(document.all)
			{
			    ev=document.getElementById("lbReport");
			 }
			if (document.getElementById("DDResult").selectedIndex != -1 && ev.selectedIndex != -1)
			{
				isExcel = document.getElementById("DDResult").options[document.getElementById("DDResult").selectedIndex].value + "excel" + ev.options[ev.selectedIndex].value;
				isPdf = document.getElementById("DDResult").options[document.getElementById("DDResult").selectedIndex].value + "pdf" + ev.options[ev.selectedIndex].value;
				report = ev.options[ev.selectedIndex];
				//if (report[isExcel] == "1")	
//				if(report.attributes.getNamedItem(isExcel).value== "1")		
//				 {
//				    document.getElementById("ibExcel").src = "../Img/Exporttoexcel.gif";
//				 }
//				else		document.getElementById("ibExcel").src = "../Img/Exporttoexcelgray.gif";
//				
//				if (report.attributes.getNamedItem(isPdf).value == "1")		document.getElementById("ibPdf").src = "../Img/export_pdf.gif";
//				else		document.getElementById("ibPdf").src = "../Img/export_pdfgray.gif";
				
//				if (report.attributes.getNamedItem(isExcel).value == "1" || report.attributes.getNamedItem(isPdf).value == "1")		
//				{
//					//document.getElementById("ibArchive").src = "../Img/ArchiveL.gif";
//				}
//				else
//				{	
//					//document.getElementById("ibArchive").src = "../Img/ArchiveLgray.gif";
//				}
			}
		}
		
		function CheckExcel()
		{
			var isExcel;
			var report;
			
			if (document.all.DDResult.selectedIndex != -1 && document.all.lbReport.selectedIndex != -1)
			{
				isExcel = document.all.DDResult.options[document.all.DDResult.selectedIndex].value + "excel" + document.all.lbReport.options[document.all.lbReport.selectedIndex].value;
				report = document.all.lbReport.options[document.all.lbReport.selectedIndex];
								
				if (report[isExcel] == "1")		return true;
				else		return false;
			}
			else
			{
				return false;
			}
		}
		
		
		function CheckPdf()
		{
			var isPdf;
			var report;
			
			if (document.all.DDResult.selectedIndex != -1 && document.all.lbReport.selectedIndex != -1)
			{
				isPdf = document.all.DDResult.options[document.all.DDResult.selectedIndex].value + "pdf" + document.all.lbReport.options[document.all.lbReport.selectedIndex].value;
				report = document.all.lbReport.options[document.all.lbReport.selectedIndex];
								
				if (report[isPdf] == "1")		return true;
				else		return false;
			}
			else
			{
				return false;
			}
		}
		
		function CheckSelected()
		{
			if (document.all.DDResult.selectedIndex == -1)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		
		function CheckReport()
		{
			if (CheckSelected() == true)
			{
				if (CheckExcel() == true || CheckPdf() == true)
				{
					return true;
				}
				else
				{
					return false;
				}
			}
			else
			{
				return false;
			}
		}
		
		
		function SelectAll()
		{
			for (var i = 0;i < document.all.lbIn.options.length;i++)
			{
				document.all.lbIn.options[i].selected = true;
			}
		}
		
		function MoveAll(source,target)
		{
			var text;
			var value;
			var option;
			var leng=source.options.length;
			for (var i = 0;i < leng;i++)
			{
				text = source.options[i].text;
				value = source.options[i].value;
				option = document.createElement("OPTION");
				target.options.add(option);
				option.text = text;
				option.value = value;
				//source.options.remove(i);				
			}
			
			for (var i = 0;i < leng;i++)
			{
			   source.options[0]=null;
			}
			
		}
		
		function MoveSelected(source,target)
		{
			HiddenMessage();
			var text;
			var value;
			var option;
			var IsSelected = "false";
			var selectedList="";
			var leng=source.options.length;
			for (var i = 0;i < leng; i++)
			{
			   // alert(source.options[i].selected+":"+i +":"+source.options[i].text);
				if (source.options[i].selected)
				{
					text = source.options[i].text;
					value = source.options[i].value;
					option = document.createElement("OPTION");
					target.options.add(option);
					option.text = text;
					option.value = value;
					if(selectedList=="")
					    selectedList="'"+i+"'";
					else
					    selectedList +=",'"+i+"'";
					IsSelected="True";
				}
			}
			if(selectedList!="")
			{
			    var sIndex=selectedList.split(',');
			    for(var i =0;i<sIndex.length;i++)
			    {
			        var ss=sIndex[i].replace("'","").replace("'","");
			       
			        if(i==0)
			        {			        
			            source.options[ss]=null;
			        }
			        else
			          source.options[ss-i]=null;
			    }
			    
			}
			if(IsSelected=="false")
			{
			   DisplayMessage("Please select one Report at least!");
			}
		}
		
		function MoveUpSelected(source)
		{
			HiddenMessage();
			
			var text1;
			var value1;
			var text2;
			var value2;
			var option;
			
			//alert(document.getElementById(source).selectedIndex);
			
			for (var i = 0;i < document.getElementById(source).options.length;i++)
			{
				if (document.getElementById(source).options[i].selected)
				{
				    text1 = document.getElementById(source).options[i-1].text;
					value1 = document.getElementById(source).options[i-1].value;
					
					text2 = document.getElementById(source).options[i].text;
					value2 = document.getElementById(source).options[i].value;
					
				    document.getElementById(source).options[i-1].text=text2;
				    document.getElementById(source).options[i-1].value=value2;
				    document.getElementById(source).options[i].text = text1;
					document.getElementById(source).options[i].value = value1;
					document.getElementById(source).options[i-1].selected=true;
					document.getElementById(source).options[i].selected=false;
				}
			}
		}
		
		function MoveDownSelected(source)
		{
			HiddenMessage();
			
			var text1;
			var value1;
			var text2;
			var value2;
			var option;
			
			//alert(document.getElementById(source).selectedIndex);
			
			for (var i = document.getElementById(source).options.length-1;i>=0;i--)
			{
				if (document.getElementById(source).options[i].selected)
				{
				    text1 = document.getElementById(source).options[i+1].text;
					value1 = document.getElementById(source).options[i+1].value;
					
					text2 = document.getElementById(source).options[i].text;
					value2 = document.getElementById(source).options[i].value;
					
				    document.getElementById(source).options[i+1].text=text2;
				    document.getElementById(source).options[i+1].value=value2;
				    document.getElementById(source).options[i].text = text1;
					document.getElementById(source).options[i].value = value1;
					
					document.getElementById(source).options[i+1].selected=true;
					document.getElementById(source).options[i].selected=false;
				}
			}
		}
		
		function CanAddBatch()
		{
			var r, re;                     
			var expre = /^ +$/
			re = new RegExp(expre)
			r = document.getElementById("tbNew").value.match(re);
		   
			
			if (r != null || document.getElementById("tbNew").value.length == 0)		
			{
				DisplayMessage("Warning: Please input a report name.<br><br>",4);				
				return false;
			}
			else	
			{
				HiddenMessage();
				return true;
			}
		}
				
		function DisplayMessage(message,colspan)
		{
		    //document.getElementById("tdMessage").colSpan = colspan;
			
			document.getElementById("divMessage").style.display = 'block';
			document.getElementById("trMessage").style.display = 'block';
			document.getElementById("divMessage").innerHTML = message;
		}
		
		function HiddenMessage()
		{
			document.all.trMessage.style.display = 'none';
			document.all.divMessage.style.display = 'none';
		}
		
		function CanDelete()
		{
			var resultindex = document.getElementById("DDResult").selectedIndex;
			
			if (resultindex == -1)		return false;
			else		return true;
		}
		
		function CanRename(Results)
		{
			var r, re;                     
			var expre = /^ +$/
			re = new RegExp(expre)
			r = document.getElementById('tbName').value.match(re);
			var result = document.getElementById(Results);
			if (result.selectedIndex == -1)		return false;
			else
			{
				if (SelectedCount(Results) == 1 && document.getElementById('tbName').value.length != 0 && r == null)	return true;
				else return false;
			}
		}		
		
		function CanViewRunSetting()
		{	
			var grid = igtbl_getGridById('Grid1xuwg');	
			var row ;
			if(igtbl_getLength(grid.SelectedRows) == 0 && igtbl_getLength(grid.SelectedCells)==0)
			{
				document.all.tdMessage.colSpan = 2;
				document.all.trMessage.style.display = 'block';
				document.all.divMessage.innerHTML = "Please choose a row at first.<br><br>";

				return false;
			}
			else if(igtbl_getLength(grid.SelectedRows)>1)
			{
			    document.all.tdMessage.colSpan = 2;
				document.all.trMessage.style.display = 'block';
				document.all.divMessage.innerHTML = "More than one row were choosed.<br><br>";
				return false;
			}
			else
			{		
			    if(igtbl_getLength(grid.SelectedRows) ==0)
			    {
			        var Cell;
			        for (var o in grid.SelectedCells)
				    {
					    Cell = igtbl_getCellById(o);
		            } 
		            row = Cell.getRow();
			    }
				else
				{
				    for (var o in grid.SelectedRows)
				    {
					    row = igtbl_getRowById(o);
		            } 
		         }
				var param = window.location.search;
				type = GetType(param);
				window.open('../Simulation/Simulation.aspx?type='+type+'&runkey='+row.getCellFromKey("RunKey").getValue(),'','toolbar=no,menubar=no,titlebar=yes,directories=no,resizable=yes,status=yes,fullscreen=no,top=10,left=10,scrollbars=no,width=830,height=670');
				return true;
				
			}
		}
		
		function SelectedCount(Results)
		{
			var result = document.getElementById(Results);
			
			var count = 0;
				
			for (var i = 0;i < result.options.length;i++)
			{
				if (result.options[i].selected)		count++;
			}
				
			return count;
		}
		
		function uwgRein_AfterExitEditModeHandler(gridName, cellId){
			//Add code to handle your event here.
			var oCell = igtbl_getCellById(cellId);
			var oRow = oCell.Row;
			var oGrowth = oRow.getCell(4);

			if (oGrowth.getValue() == "Maintain" || oGrowth.getValue() == "None" ||oRow.getCell(2).getValue() == "-1" ||oRow.getCell(2).getValue() == "-2")
			{
				oCell.setValue(null);
			}
			else
			{
			}
		}
		
		function changegrowth(sender)
		{
			var oSpeed = igtbl_getElementById("Grid1_uwg__ctl0__ctl0_ddlBuy");
			var oRate = igtbl_getElementById("rate");
			var oInst = igtbl_getElementById("Grid1_uwg__ctl0__ctl0_ddlInst");
			var strPrefix = "Grid1_uwg__ctl0__ctl0_tb";
			var i = 0;
			if (oSpeed.value == "Self")
			{
				oRate.style.display = 'none';
				oInst.style.display = 'none';
			}
			else
			{
				if (oSpeed.value == "Rate")
				{
					oRate.style.display = 'block';
					oInst.style.display = 'none';
				}
				else
				{
					oRate.style.display = 'none';
					oInst.style.display = 'block';
				}
			}
			if (sender.value == "None")
			{
				oSpeed.disabled = true;
				oRate.disabled = true;
				oInst.disabled = true;
				while(true)
				{
					oPeriod = igtbl_getElementById(strPrefix+i);
					if (oPeriod == null || oPeriod == undefined)
						break;
					oPeriod.disabled = true;
					i++;
				}
			}
			else
			{
				if (sender.value == "Maintain")
				{
					oSpeed.disabled = false;
					oRate.disabled = false;
					oInst.disabled = false;
					while(true)
					{
						oPeriod = igtbl_getElementById(strPrefix+i);
						if (oPeriod == null || oPeriod == undefined)
							break;
						oPeriod.disabled = true;
						i++;
					}
				}
				else
				{
					oSpeed.disabled = false;
					oRate.disabled = false;
					oInst.disabled = false;
					while(true)
					{
						oPeriod = igtbl_getElementById(strPrefix+i);
						if (oPeriod == null || oPeriod == undefined)
							break;
						oPeriod.disabled = false;
						i++;
					}					
				}
			}						
		}
		
		function changebuy(sender)
		{
			var oRate = igtbl_getElementById("rate");
			var oInst = igtbl_getElementById("Grid1_uwg__ctl0__ctl0_ddlInst");
			if (sender.value == "Self")
			{
				oRate.style.display = 'none';
				oInst.style.display = 'none';
			}
			else
			{
				if (sender.value == "Rate")
				{
					oRate.style.display = 'block';
					oRate.value = 0;
					oInst.style.display = 'none';
				}
				else
				{
					oRate.style.display = 'none';
					oInst.style.display = 'block';
				}
			}			
		}
	    
	    function checknumform2(oButton, oEvent)
	    {
	         
	      var grid = igtbl_getGridById('Grid1xuwg');
	      var rowCount = grid.Rows.length;
		  var r, re;                     
	      var expre = /^-?[1-9]+\d*$|^-?0\.{1}\d+$|^0$|^-?[1-9]+\d*\.{1}\d+$/;
	      re = new RegExp(expre)
	     
	      for (var i = 0;i < rowCount;i++)
		    {
			    var row = grid.Rows.getRow(i);
			    
			    if (row.getCell(20).getValue()!=4)
			    { 
			        if(row.getCell(23).getValue().match(re)==null || row.getCell(24).getValue().match(re)==null)
			        {
				        document.all.tdMessage.colSpan = 2;
				        document.all.trMessage.style.display = 'block';
				        document.all.divMessage.innerHTML = "Sorry,the BetaUP and BetaDn must be numbers.<br><br>";
				        return false;
				    }
			    }
		    }
			oEvent.needPostBack=true;    
	    }

		function uwgRein_AfterRowTemplateOpenHandler(gridName, rowId)
		{
			//Add code to handle your event here.
			var oRow = igtbl_getRowById(rowId);
			var oCell = oRow.getCell(4);
			var oSpeed = igtbl_getElementById("Grid1_uwg__ctl0__ctl0_ddlBuy");
			var oRate = igtbl_getElementById("rate");
			var oInst = igtbl_getElementById("Grid1_uwg__ctl0__ctl0_ddlInst");
			var strPrefix = "Grid1_uwg__ctl0__ctl0_tb";
			var i = 0;
			if (oRow.getCell(5).getValue() == "Self")
			{
				oRate.style.display = 'none';
				oInst.style.display = 'none';
			}
			else
			{
				if (oRow.getCell(5).getValue() == "Rate")
				{
					oRate.style.display = 'block';
					oInst.style.display = 'none';
				}
				else
				{
					oRate.style.display = 'none';
					oInst.style.display = 'block';
				}
			}
			if (oCell.getValue() == "None")
			{
				oSpeed.disabled = true;
				oRate.disabled = true;
				oInst.disabled = true;
				while(true)
				{
					oPeriod = igtbl_getElementById(strPrefix+i);
					if (oPeriod == null || oPeriod == undefined)
						break;
					oPeriod.disabled = true;
					i++;
				}
			}
			else
			{
				if (oCell.getValue() == "Maintain")
				{
					oSpeed.disabled = false;
					oRate.disabled = false;
					oInst.disabled = false;
					while(true)
					{
						oPeriod = igtbl_getElementById(strPrefix+i);
						if (oPeriod == null || oPeriod == undefined)
							break;
						oPeriod.disabled = true;
						i++;
					}
				}
				else
				{
					oSpeed.disabled = false;
					oRate.disabled = false;
					oInst.disabled = false;
					while(true)
					{
						oPeriod = igtbl_getElementById(strPrefix+i);
						if (oPeriod == null || oPeriod == undefined)
							break;
						oPeriod.disabled = false;
						i++;
					}					
				}
			}
		}
		
		function uwgRein_TemplateUpdateCellsHandler(gridName, controlId, cellId)
		{
			//Add code to handle your event here.
			var oRow = igtbl_getRowById(cellId);
			var oGrowth = oRow.getCell(4);						
			
			if (controlId == "Grid1_uwg__ctl0__ctl0_tb0")	
			{
				if (oRow.getCell(5).getValue() == "Self")
				{
					oRow.getCell(6).setValue("");
				}
				else
				{
					if (oRow.getCell(5).getValue() == "Rate")
					{
						var oCell = igtbl_getElementById("rate");
						//alert(oCell.value);
						oRow.getCell(6).setValue(oCell.value);
					}
					else
					{
						var oCell = igtbl_getElementById("Grid1_uwg__ctl0__ctl0_ddlInst");
						//alert(oCell.value);
						oRow.getCell(6).setValue(oCell.value);
					}
				}				
			}
			
			var id = "Grid1_uwg__ctl0__ctl0_tb" + (oRow.cells.length-8);

			if (controlId == id)
			{			
				if (oRow.getCell(2).getValue() == "-1" ||oRow.getCell(2).getValue() == "-2")
				{				
					for (var i = 4;i < 7;i++)
					{
						oRow.getCell(i).setValue(null);
					}
				}
				else if (oGrowth.getValue() == "Maintain" || oGrowth.getValue() == "None")
				{
					for (var i = 7;i < oRow.cells.length;i++)
					{
						oRow.getCell(i).setValue(null);
					}		
					
					var period = igtbl_getElementById(id);
					period.value = "";							
				}	
			}				
		}
		
		function ChangeType(sender)
		{
			var oSpeed = igtbl_getElementById("speed");
			var oTable = igtbl_getElementById("Grid1_uwg_ctl00_ctl00_ddlTable");
			var oMult = igtbl_getElementById("mult");

			if (sender.value.indexOf("Table") != -1)
			{
				oSpeed.style.display = 'none';
				oTable.style.display = 'block';
				oMult.disabled=false;
				oMult.value = 1;
			}
			else
			{
				oSpeed.style.display = 'block';
				oTable.style.display = 'none';
				if (sender.value == "ZM")
			    {
			        oSpeed.disabled = true;
			        oMult.disabled=false;
				    oSpeed.value = "";
				    oMult.value = 1;
			    }
			    else//Constant			
			    {
			        oSpeed.disabled = false;
			        oMult.disabled = true;
				    oMult.value = "";
			    }
			}		    
		}
		
		function uwgNev_AfterRowTemplateOpenHandler(gridName, rowId)
		{
			//Add code to handle your event here.
			var oRow = igtbl_getRowById(rowId);	
			var oCell = oRow.getCell(6);
			var oSpeed = igtbl_getElementById("speed");
			var oTable = igtbl_getElementById("Grid1_uwg_ctl00_ctl00_ddlTable");
			var oType = igtbl_getElementById("Grid1_uwg_ctl00_ctl00_ddlType");
			var oMult = igtbl_getElementById("mult");		
			var isNon = oRow.getCellFromKey("IsNonMaturity").getValue();			
			
			if (oCell.getValue() && oCell.getValue().indexOf("Table") != -1)
			{
				oSpeed.style.display = 'none';
				oTable.style.display = 'block';
				if (isNon == false)
				{
				    oMult.disabled = false;
				    oType.disabled=false;
				}
				else
				{
				    oMult.disabled=true;
				    oType.disabled=true;
				}
			}
			else
			{
			    oType.disabled=false;
				oSpeed.style.display = 'block';
				oTable.style.display = 'none';					
				
				if (oCell.getValue() == "ZM")
				{
				    oSpeed.disabled = true;
				    oMult.disabled = false;
				    oSpeed.value = "";
				}
				else
				{
				    oSpeed.disabled = false;
				    oMult.disabled = true;
				    oMult.value = "";
				}
			}			
		}
		function uwgNev_TemplateUpdateCellsHandler(gridName, controlId, cellId)
		{
			//Add code to handle your event here.
			var oRow = igtbl_getRowById(cellId);	
						
			if (controlId == "mult")
			{
				var cell=igtbl_getCellById(cellId);
				
				if (oRow.getCell(6).getValue().indexOf("Table") != -1)
				{					
					var oCell = igtbl_getElementById("Grid1_uwg_ctl00_ctl00_ddlTable");
					oRow.getCell(7).setValue(oCell.value);
				}
				else if (oRow.getCell(6).getValue() == "ZM")
				{
					var oCell = igtbl_getElementById("speed");
					oRow.getCell(7).setValue("");		
				}
				else //if (oRow.getCell(6).getValue() == "PSA" || oRow.getCell(6).getValue() == "CPR")
				{
					var oCell = igtbl_getElementById("speed");
					if (isNaN(oCell.value))
					    oRow.getCell(7).setValue(0);	
					else
					    oRow.getCell(7).setValue(oCell.value);
					oRow.getCell(8).setValue("");	
				}
//				else
//				{
//					oRow.getCell(7).setValue("na");	
//					oRow.getCell(8).setValue("na");	
//				}
			}
			
			if (oRow.getCell(2).getValue() == -1 || oRow.getCell(2).getValue() == -2)
			{
				oRow.getCell(6).setValue("");
				oRow.getCell(7).setValue("");
				oRow.getCell(8).setValue("");
			}
		}
		
		function ControlType()
		{
			var grid = igtbl_getGridById('Grid1xuwg');	
			var oBands = grid.Bands;
			var oBand = oBands[0];
			var oRows = grid.Rows;
			var oColumns = oBand.Columns;
			var row;
			var cell ;	
			
			for (var i = 0;i < oRows.length;i++)
			{
				row = oRows.getRow(i);
				cell = row.getCell(3);
				
				if (cell.getValue() != 31)		oRows.getRow(i).getCell(7).setEditable(false);
				else		oRows.getRow(i).getCell(7).setEditable(true);
			}
			
			return false;
		}
		
		function Validation_AfterExitEditModeHandler(gridName, cellId)
		{
			var cell = igtbl_getCellById(cellId);
			var row = cell.Row;			
			
			if (row.getCell(2).getValue().toLowerCase().indexOf('allowance for loan losses') != -1)
			{
				if (parseFloat(cell.getValue()) >= 0)
				{
					document.all.tdMessage.colSpan = 2;
					document.all.trMessage.style.display = 'block';
					document.all.divMessage.innerHTML = 'Warning: Per regulatory reporting guidelines, the Allowance for Loan Losses account must never have a debit balance.<br><br>';	
				}
				else
					document.all.trMessage.style.display = 'none';
			}
			else
			{
				document.all.trMessage.style.display = 'none';
				
				if (cell.Column.Index != 6 && parseFloat(cell.getValue()) < 0)
				{
					if (cell.getOldValue() != undefined)		
						cell.setValue(cell.getOldValue());	
				}
			}
			
			IsChange(cell);
		}
		
		function CheckChange(gridName, cellId)
		{
			var cell = igtbl_getCellById(cellId)
			
			IsChange(cell);
		}
		
		function IsChange(cell)
		{
			if (cell.getOldValue() != undefined && cell.getOldValue() != cell.getValue())
			{
				cell.Element.style.fontWeight = "bold";
			}
			else
			{
				cell.Element.style.fontWeight = "";
			}
		}
		
		function SetOrigValue(cell)
		{
			if (cell.getOldValue() != undefined)
				cell.setValue(cell.getOldValue());
		}
		
		function SetCustomValue(cell,value)
		{
			cell.setValue(value);
		}
		
		
		function re_uwg_AfterExitEditModeHandler(gridName, cellId)
		{
			var cell = igtbl_getCellById(cellId);
			
			if (cell.Column.Index == 3)
			{
				if (cell.getValue() == 31)
				{
					cell.Row.getCell(7).setEditable(true);
					cell.Row.getCell(7).setValue(0);
					IsChange(cell.Row.getCell(7));
				}
			}
			
			if (cell.Column.Index == 7 && cell.Row.getCell(3).getValue() == 31)
			{
				var r, re;                     
				var expre = /^-?[1-9]+\d*$|^0$/
				re = new RegExp(expre)
				r = cell.getValue().match(re);
				
				if (r == null)
				{
					SetCustomValue(cell,0);
					document.all.trMessage.style.display = 'block';
					document.all.divMessage.innerHTML = "RemIO must be an integer.<br><br>";
				}
				else
				{
					document.all.trMessage.style.display = 'none';
				}
			}
			else
				document.all.trMessage.style.display = 'none';
			
			IsChange(cell);
		}
		
		function re_uwg_BeforeEnterEditModeHandler(gridName, cellId)
		{
			var cell = igtbl_getCellById(cellId);
			
			if (cell.Column.Index == 7)
			{
				if (cell.Row.getCell(3).getValue() != 31)	
				{
					cell.setValue('None');
					cell.setEditable(false);
					IsChange(cell);
					
					return 1;
				}
			}
		}
		
		
		function ColumnHeaderClick(gridName, columnId, button)
		{
			var oGrid = igtbl_getGridById(gridName);
			var oRows = oGrid.Rows;	
			if (oRows.length > 0)
			{
				var cell = oRows.getRow(0).getCell(1);	
				cell.getRow().activate();			
			}					
		}
		var canGoBack=false;
		var setback=false;
		function istrue()
		{
		    if(canGoBack==true)
		    {
		      clearInterval(Timer);
		      return true;
		    }
		}
		function DelShift()
		{
			var grid = igtbl_getGridById('Grid1xuwg');	
			var row ;//= igtbl_getActiveRow('Grid1xuwg');
			
			if(igtbl_getLength(grid.SelectedRows) == 0)
			{
				document.all.tdMessage.colSpan = 2;
				document.all.trMessage.style.display = 'block';
				document.all.divMessage.innerHTML = "Please choose a row to delete.<br><br>";
                canGoBack=false;
                setback=true;
				return false;
			}
			else
			{	
			    var ShiftValue;			
				for (var o in grid.SelectedRows)
				{
					row = igtbl_getRowById(o);
					ShiftValue=row.getCell(0).getValue()
			    }
				DisplayMessage(	'Confirm delete of row: Shift '+row.getCell(1).getValue(),1);
				
               var tbId=document.getElementById("tbID").value;
               var PrepayKey;
               var AgeValue=document.getElementById("tbAddAge").value;
//               var ShiftValue=document.getElementById("tbShift").value;
               var indexKey;
               var CpnSpd = document.getElementById("tbSpread").value;
               
               if(document.getElementById("ddlIndex").options.length>0)
                    indexKey=document.getElementById("ddlIndex").options[document.getElementById("ddlIndex").selectedIndex].text;
               if(document.getElementById("ddlPrepay").options.length>0)
                    PrepayKey=document.getElementById("ddlPrepay").options[document.getElementById("ddlPrepay").selectedIndex].value;
              
              confirmbt("deleteShift","Prepaytable.aspx?IDValue="+tbId+"&PrepayKey="+PrepayKey+"&indexKey="+indexKey+"&CpnSpd="+CpnSpd+"&ShiftValue="+ShiftValue+"&AgeValue="+AgeValue,null);
              
               return false;
			}   
			
		}
		
		function DelAge()
		{
			var grid = igtbl_getGridById('Grid1xuwg');	
			var oBands = grid.Bands;
			var oBand = oBands[0];
			var oColumns = oBand.Columns;	
			var col;			
			
			if (igtbl_getLength(grid.SelectedColumns) == 0)		
			{
				document.all.tdMessage.colSpan = 2;
				document.all.trMessage.style.display = 'block';
				document.all.divMessage.innerHTML = "Please choose an Age column to delete.<br><br>";

				return false;
			}
			else
			{
				for (var o in grid.SelectedColumns)
					col = igtbl_getColumnById(o);
					
				if (col.HeaderText == "Shift")
				{
					document.all.tdMessage.colSpan = 2;
					document.all.trMessage.style.display = 'block';
					document.all.divMessage.innerHTML = "Please choose an Age column to delete.<br><br>";

					return false;
				}
				else
				{
					//parseInt(oColumns[j].HeaderText.substr(4)
					var AgeValue=col.HeaderText.substr(4);			
				    
				    DisplayMessage("Confirm delete of column: "+ col.HeaderText,1);
    				
                   var tbId=document.getElementById("tbID").value;
                   var PrepayKey;
                  // var AgeValue=document.getElementById("tbAddAge").value;
                   var ShiftValue=document.getElementById("tbShift").value;
                   var indexKey;
                   var CpnSpd = document.getElementById("tbSpread").value;
                   
                   if(document.getElementById("ddlIndex").options.length>0)
                        indexKey=document.getElementById("ddlIndex").options[document.getElementById("ddlIndex").selectedIndex].text;
                   if(document.getElementById("ddlPrepay").options.length>0)
                        PrepayKey=document.getElementById("ddlPrepay").options[document.getElementById("ddlPrepay").selectedIndex].value;
                  
                  confirmbt("deleteAge","Prepaytable.aspx?IDValue="+tbId+"&PrepayKey="+PrepayKey+"&indexKey="+indexKey+"&CpnSpd="+CpnSpd+"&ShiftValue="+ShiftValue+"&AgeValue="+AgeValue,null);
                  
                   return false;
				}
			}		
		}
	   var shiftid="ibDelShift"
       function AddFloaterOkFun()
       {
            __doPostBack(shiftid , "Click");
   	        document.getElementById("trMessage").style.display="none";
       }
       function CanceFun()
       {
            //document.getElementById('popGrid').style.display='none';
   		    document.getElementById("trMessage").style.display="none";
       }
       function AddMktFloaterConfirm(message,OkFun,CancelF)
       {
               DisplayMessage(message,2);
               document.getElementById("buttons").style.display = 'block';
               if(OkFun){
           		       document.getElementById("Ok1").onclick =OkFun;
           		       }
           		       if(CancelF)
           		       {
           		       document.getElementById("Cancel1").onclick=CancelF;
           		       }
           		       else
           		       {
		         document.getElementById("Cancel1").onclick = function(){
		         document.getElementById("trMessage").style.display="none";
		       }
		       }
       }
		
		function Checknumform(Pam,Pname)
		{
			var r, re;                     
			var expre = /^-?[1-9]+\d*$|^0$/
			re = new RegExp(expre)
			r = Pam.match(re);
			if (r == null)
			{
				document.all.tdMessage.colSpan = 2;
				document.all.trMessage.style.display = 'block';
				document.all.divMessage.innerHTML = ""+Pname+" must be a integer.<br><br>";
				
				return false;
			}
			return true;
		}
		function CheckAddShift(tbName,addName)
		{
			var grid = igtbl_getGridById('Grid1xuwg');
			var rowCount = grid.Rows.length;
			var shift = document.getElementById(tbName).value
			var r, re;                     
			var expre;
			var discrip="";
			if (addName=="Shift")
			{
			    expre = /^-?[1-9]+\d*$|^0$/;
			    discrip="The Shift value must be an integer: please retry."
			}
			else
			{
			    expre = /^-?[1-9]+\d*$|^-?0\.{1}\d+$|^0$|^-?[1-9]+\d*\.{1}\d+$/;
			    discrip=addName+" must be a number."
			}
			re = new RegExp(expre)
			r = shift.match(re);
			
			if (shift.length == 0)		
			{
				document.all.tdMessage.colSpan = 2;
				document.all.trMessage.style.display = 'block';
				document.all.divMessage.innerHTML = "Please input a "+addName+".<br><br>";
				
				return false;
			}

			if (r == null)
			{
				document.all.tdMessage.colSpan = 2;
				document.all.trMessage.style.display = 'block';
				document.all.divMessage.innerHTML = ""+discrip+"<br><br>";
				
				return false;
			}
			
			for (var i = 0;i < rowCount;i++)
			{
				var row = grid.Rows.getRow(i);
				if (shift == row.getCell(0).getValue())
				{
					document.all.tdMessage.colSpan = 2;
					document.all.trMessage.style.display = 'block';
					document.all.divMessage.innerHTML = "Sorry,the new "+addName+" you input already exist.<br><br>";
					
					return false;
				}
			}
			
			return true;
		}
		
		function CheckPeriod()
		{
			var fwdPeriod = document.all.tbFwdPeriod.value;
			var r, re;                     
			var expre = /^[1-9]+\d*$/
			re = new RegExp(expre)
			r = fwdPeriod.match(re);
			
			if (r == null)
			{
				document.all.tdMessage.colSpan = 4;
				document.all.trMessage.style.display = 'block';
				document.all.divMessage.innerHTML = "Please input a Forward Period between 1-360.<br><br>";
				
				return false;
			}		
			
			return true;
		}
		
		function CheckDay()
		{
			var r, re;                     
			var expre = /^[1-9]+\d*$/
			var days = document.all.tbDay.value;
			re = new RegExp(expre)
			 
			
			if (days.length == 0)
			{
				document.all.trMessage.style.display = 'block';
				document.all.divMessage.innerHTML = "Please input a Day<br><br>";
				
				return false;
			}
			
			r = days.match(re);		 
			
			if (r == null)
			{
				document.all.trMessage.style.display = 'block';
				document.all.divMessage.innerHTML = "Day must be an integer.<br><br>";
				
				return false;
			}
			
			var grid = igtbl_getGridById('Grid1xuwg');
			var rowCount = grid.Rows.length;
			
			for (var i = 0;i < rowCount;i++)
			{
				if (grid.Rows.getRow(i).getCell(0).getValue() == days)
				{
					document.all.trMessage.style.display = 'block';
					document.all.divMessage.innerHTML = "Sorrry,the new Day you input is repeated.<br><br>";
					
					return false;
				}
			}
			
			return true;
		}
		
		function CheckDelDay()
		{
			var grid = igtbl_getGridById('Grid1xuwg');
			
			if(igtbl_getLength(grid.SelectedRows) == 0)
			{
				document.all.trMessage.style.display = 'block';
				document.all.divMessage.innerHTML = "Please choose a row to delete.<br><br>";

				return false;
			}
			
			return true;
		}
		
		function CheckAddAge()
		{
			var grid = igtbl_getGridById('Grid1xuwg');
			var oBands = grid.Bands;
			var oBand = oBands[0];
			var oColumns = oBand.Columns;
			var count = oColumns.length;
			var age = document.all.tbAddAge.value;	
			var expre = /^[1-9]+\d*$/
			re = new RegExp(expre)
			r = age.match(re);		
			
			if (age.length == 0)
			{
				document.all.tdMessage.colSpan = 2;
				document.all.trMessage.style.display = 'block';
				document.all.divMessage.innerHTML = "Please input a Age.<br><br>";
				
				return false;
			}
			
			if (r == null)
			{
				document.all.tdMessage.colSpan = 2;
				document.all.trMessage.style.display = 'block';
				document.all.divMessage.innerHTML = "The Age value must be a positive integer: please retry.<br><br>";
				
				return false;
			}
			
			for (var j = 2;j < count;j++)
			{
				if (parseInt(oColumns[j].HeaderText.substr(4)) == parseInt(age))
				{
					document.all.tdMessage.colSpan = 2;
					document.all.trMessage.style.display = 'block';
					document.all.divMessage.innerHTML = "Sorrry,the new Age you input is repeated.<br><br>";

					return false;
				}
			}
			
			return true;
		}
		
		function CheckShift()
		{
			var grid = igtbl_getGridById('Grid1xuwg');
			var rowCount = grid.Rows.length;
			var shift = new Array(rowCount);
			
			for(var i=0;i<rowCount;i++)
			{
				var row = grid.Rows.getRow(i);
				shift[i] = row.getCell(1).getValue();
			}
			
			for(var i=0;i<rowCount-1;i++)
				for(var j=i+1;j<rowCount;j++)
					if(shift[i]==shift[j])
					{
						document.all.tdMessage.colSpan = 2;
						document.all.trMessage.style.display = 'block';
						document.all.divMessage.innerHTML = "Sorry,the new Shift you input is repeated.<br><br>";
						
						return false;
					}

			return true;
		}
		
		function CheckRepeat(col,message)
		{
			var grid = igtbl_getGridById('Grid1xuwg');
			var rowCount = grid.Rows.length;
			var check = new Array(rowCount);
			var temp;
			
			for (var i = 0;i < rowCount;i++)
			{
				check[i] = grid.Rows.getRow(i).getCell(col).getValue();
			}
			
			
			for (i = 0;i < rowCount - 1;i++)
			{
				for (j = i+1;j < rowCount;j++)
				{
					if (check[i] == check[j])
					{
						if (grid.Rows.getRow(i).getCell(col).getOldValue() != undefined && grid.Rows.getRow(i).getCell(col).getOldValue() != grid.Rows.getRow(i).getCell(col).getValue())
							temp = i+1;
						else
							temp = j+1;
						
						document.all.tdMessage.colSpan = col;
						document.all.trMessage.style.display = 'block';
						document.all.divMessage.innerHTML = "" +message+ " which is at "+temp+" row.<br><br>";
						
						return false;
					}
				}
			}
			
			return true;
		}
		
		function CheckTableRepet(Objvalue,obj)
		{
		    var tag=true;
//		    var Objvalue=document.getElementById("RateName").value;
//            var obj=document.getElementById("ddlRate").options;
            var expre = /^ +$/
			re = new RegExp(expre)
			r = Objvalue.match(re);
			if (r != null || Objvalue.length == 0)		
			{
                document.all.tdMessage.colSpan = 2;
	            document.all.trMessage.style.display = 'block';
                document.getElementById("divMessage").innerHTML = "The name for a table must include text: please retry.<br><br>";
                return false;
			}
            if(r=="" || Objvalue.length>0)
            {
               for (var i = 0;i <obj.length;i++)
                {
	                if(document.getElementById("RateName").value.toLowerCase()==obj[i].text.toLowerCase())
	                {	        
	                    document.all.tdMessage.colSpan = 2;
			            document.all.trMessage.style.display = 'block';
		                document.getElementById("divMessage").innerHTML = "The name for a table must be unique: please retry.<br><br>";
		                return false;
	                }	
     	        }
         	}
         	 return true;
		}
		function ChangeFwdType()
		{
			if (document.all.ddlFwdType.selectedIndex == 0)
			{
				document.getElementById("spanFwdType").style.width = "40px";
				document.all.spanResetFQ.style.visibility = 'hidden';
				document.all.spanFwdPeriod.style.visibility = 'hidden';
				document.getElementById("dateChooseDiv").style.visibility='hidden';
				document.getElementById('asofDatediv').style.visibility='hidden';
			}
			else
			{
				document.getElementById("spanFwdType").style.width = "150px";
				document.all.spanResetFQ.style.visibility = 'visible';
				document.all.spanFwdPeriod.style.visibility = 'visible';
                document.getElementById("dateChooseDiv").style.visibility='visible';
				document.getElementById('asofDatediv').style.visibility='visible';
			}
		}
		
		
		function CheckFloater(floater)
		{
			var floaterIndex = "";
				
			if (document.all.ddlFloater2.value == "-1" && document.all.ddlFloater3.value == "-1")
				return;
					
			if (floater == 1)
			{
				if (document.all.ddlFloater1.value == document.all.ddlFloater2.value)
				{
					floaterIndex = document.all.ddlFloater1.selectedIndex;
						
					if (floaterIndex+1 == document.all.ddlFloater1.length)
						document.all.ddlFloater1.selectedIndex = 0;
					else
						document.all.ddlFloater1.selectedIndex = floaterIndex + 1;
												
				}
					
				if (document.all.ddlFloater1.value == document.all.ddlFloater3.value)
				{
					floaterIndex = document.all.ddlFloater1.selectedIndex;
						
					if (floaterIndex+1 == document.all.ddlFloater1.length)
						document.all.ddlFloater1.selectedIndex = 0;
					else
						document.all.ddlFloater1.selectedIndex = floaterIndex + 1;
				}
					
				if (document.all.ddlFloater1.value == document.all.ddlFloater2.value)
					CheckFloater(1);
			}
				
			else if (floater == 2)
			{
				if (document.all.ddlFloater2.value == document.all.ddlFloater1.value)
				{
					floaterIndex = document.all.ddlFloater2.selectedIndex;
						
					if (floaterIndex+1 == document.all.ddlFloater2.length)
						document.all.ddlFloater2.selectedIndex = 1;
					else
						document.all.ddlFloater2.selectedIndex = floaterIndex + 1;
				}
					
				if (document.all.ddlFloater2.value == document.all.ddlFloater3.value)
				{
					floaterIndex = document.all.ddlFloater2.selectedIndex;
						
					if (floaterIndex+1 == document.all.ddlFloater2.length)
						document.all.ddlFloater2.selectedIndex = 1;
					else
						document.all.ddlFloater2.selectedIndex = floaterIndex + 1;
				}
					
				if (document.all.ddlFloater2.value == document.all.ddlFloater1.value)
					CheckFloater(2);
			}
			else if (floater == 3)
			{
				if (document.all.ddlFloater3.value == document.all.ddlFloater1.value)
				{
					floaterIndex = document.all.ddlFloater3.selectedIndex;
						
					if (floaterIndex+1 == document.all.ddlFloater3.length)
						document.all.ddlFloater3.selectedIndex = 1;
					else
						document.all.ddlFloater3.selectedIndex = floaterIndex + 1;
				}
					
				if (document.all.ddlFloater3.value == document.all.ddlFloater2.value)
				{
					floaterIndex = document.all.ddlFloater3.selectedIndex;
						
					if (floaterIndex+1 == document.all.ddlFloater3.length)
						document.all.ddlFloater3.selectedIndex = 1;
					else
						document.all.ddlFloater3.selectedIndex = floaterIndex + 1;
				}
				if (document.all.ddlFloater3.value == document.all.ddlFloater1.value)
					CheckFloater(3);
			}
		}
		
		function SelectAllGrid(gridName)
		{
			var oGrid = igtbl_getGridById(gridName);
			var oRows = oGrid.Rows;
			
			/*for(i=0; i<oRows.length; i++)
			{
				oRow = oRows.getRow(i);
				oRow.setSelected(true);
				
				if(oRow.ChildRowsCount > 0) 
				{
					var oChildRows = oRow.Rows;
					for(j=0; j<oChildRows.length; j++)
					{
						oChildRow = oChildRows.getRow(j);
						oChildRow.setSelected(true);
					}
				}
			}*/
			if (oRows.length > 0)
			{
				oGrid.selectRowRegion(oRows.getRow(0),oRows.getRow(oGrid.Rows.length-1));
				oRows.getRow(0).activate();		
			}
		}
		
		function ImgClick(nones,objs,heights,oriHeights)
		{
			var obj;			
			
			if (objs != '' && window.event.srcElement.sh == 'hide')
			{
				var o = objs.split(';');
				var h = heights.split(';');
				
				for (var i = 0;i < o.length;i++)
				{
					obj = document.getElementById(o[i]);
					obj.style.height = h[i];					
				}
			}			
			else if (objs != '' && window.event.srcElement.sh == 'show')
			{
				var o = objs.split(';');
				var h = oriHeights.split(';');
				
				for (var i = 0;i < o.length;i++)
				{
					obj = document.getElementById(o[i]);
					obj.style.height = h[i];					
				}
			}
			
			if (nones != '')
			{
				var non = nones.split(';');				
				
				for (var i = 0;i < non.length;i++)
				{
					obj = document.getElementById(non[i]);
					
					if (obj.style.display != 'none')
					{
						obj.style.display = 'none';
						
					}
					else
					{
						obj.style.display = 'block';						
					}
				}
			}
			
			if (window.event.srcElement.sh == 'hide')
				window.event.srcElement.sh = 'show';
			else
				window.event.srcElement.sh = 'hide';
			
			ChangeImg(window.event.srcElement);
			
			return false;
		}
		
		function ChangeImg(source)
		{
			if (source.src.indexOf('up') != -1)
			{
				source.src = '../Img/bt_down.gif';
			}
			else if (source.src.indexOf('down') != -1)
			{
				source.src = '../Img/bt_up.gif';
			}
			else if (source.src.indexOf('left') != -1)
			{
				source.src = '../Img/bt_right.gif';
			}
			else
			{
				source.src = '../Img/bt_left.gif';
			}			
		}
		function guiheights(name,lenth)
		{
		    name.style.height=document.body.clientHeight-lenth;
		}
		
	 function getClipboard() {
           if (window.clipboardData) {
              return(window.clipboardData.getData('Text'));
           }
           else if (window.netscape) {
              netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
              var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
              if (!clip) return;
              var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
              if (!trans) return;
              trans.addDataFlavor('text/unicode');
              clip.getData(trans,clip.kGlobalClipboard);
              var str = new Object();
              var len = new Object();
              try {
                 trans.getTransferData('text/unicode',str,len);
              }
              catch(error) {
                 return null;
              }
              if (str) {
                 if (Components.interfaces.nsISupportsWString){ str=str.value.QueryInterface(Components.interfaces.nsISupportsWString);}
                 else if (Components.interfaces.nsISupportsString) {str=str.value.QueryInterface(Components.interfaces.nsISupportsString);}
                 else {str = null;}
              }
              if (str) {            
                 return str.data.substring(0,len.value / 2);
              }
              
           }
           return null;
        }
		var CellData = new Array();
		
		function IsDeleteColumn(str){
		    var rtn=false;
		    if(str.toString().toLowerCase()=='del' || str.toString().toLowerCase()=='delete')
		        rtn=true;
		    return rtn;
		}		
	
		function CopyPaste(gridName)
		{
		    if(!gridName) return;
			var oGrid = igtbl_getGridById(gridName);
			 if(!oGrid){return;}
			if (oGrid==null) return;
			var oRows = oGrid.Rows;		
			var oBands = oGrid.Bands;
			var oBand = oBands[0];
			var oColumns = oBand.Columns;
			var count = oColumns.length;
			var strCopyText = "";
			var iCount = 0;
			var iSelectedCount = 0;
			var strText = "";
			var strRowIndex = "";
			var isEmptyCellData="No";	
		document.onkeydown=function(event)
		{ 
		    event=window.event||event    
			if (event.ctrlKey && event.keyCode == 65)
			{	
				for(i=0; i<oRows.length; i++)
				{
					oRow = oRows.getRow(i);
					oRow.setSelected(true);
					if(oRow.ChildRowsCount > 0) 
					{
						var oChildRows = oRow.Rows;
						for(j=0; j<oChildRows.length; j++)
						{
							oChildRow = oChildRows.getRow(j);
							oChildRow.setSelected(true);
						}
					}
				}
			}
			else
			{ //ctl and c to copy selected cell.
				if (event.ctrlKey && event.keyCode == 67)
				{	
					if ( igtbl_getLength(oGrid.SelectedRows) > 0)					
					{
						for (j = 0;j<count;j++)
						{
							if (IsDeleteColumn( oColumns[j].HeaderText)==false && oColumns[j].Hidden == false)
							{
								strCopyText += oColumns[j].HeaderText +"\t";
							}
						}
						strCopyText = strCopyText.substring(0,strCopyText.length-1)+ "\r\n";
						
						for(i=0; i<oRows.length; i++)
						{
							var oSelectedRow = oRows.getRow(i);
							if (oSelectedRow.getSelected())
							{
								for (j = 0;j<count;j++)
								{
									var oSelectedCell = oSelectedRow.getCell(j);
									
									if (IsDeleteColumn( oColumns[j].HeaderText)==false && oColumns[j].Hidden == false)
									{
										var parts = oSelectedCell.Id.split("_");
										CellData[iCount] = new Array(parts[2],parts[3],oSelectedCell.getValue());
										iCount++;
										if(oColumns[j].ColumnType=="5")
										{
										   if(!document.all)
										   { strCopyText += oSelectedCell.getElement().innerHTML.replace("<nobr>","").replace("</nobr>","").replace("<nobr title=\"\">","").replace("&nbsp;","")+"\t";}
										   else
										   { strCopyText += oSelectedCell.getElement().innerText+"\t";}
										}
										else
										{
										  if(oSelectedCell.getValue()!=null)
										  {
										    strCopyText += oSelectedCell.getValue()+"\t";
										  }
										  else
										    strCopyText += ""+"\t";
										}
									}
								}
								strCopyText = strCopyText.substring(0,strCopyText.length-1)+ "\r\n";
							}
						}
						strCopyText = strCopyText.substring(0,strCopyText.length-1);
					}		
					
					if ( igtbl_getLength(oGrid.SelectedRows) == 0)					
					{
						for (j = 0;j<count;j++)
						{
							if (IsDeleteColumn( oColumns[j].HeaderText)==false && oColumns[j].Selected && oColumns[j].Hidden == false)
							{
								strCopyText += oColumns[j].HeaderText +"\t";
								iSelectedCount++;
							}
						}
						if (iSelectedCount > 0)
						{
							strCopyText = strCopyText.substring(0,strCopyText.length-1)+ "\r\n";

							for(i=0; i<oRows.length; i++)
							{
								var oSelectedRow = oRows.getRow(i);
								for (j = 0;j<count;j++)
								{
									if (oColumns[j].Selected && IsDeleteColumn( oColumns[j].HeaderText)==false && oColumns[j].Hidden == false)
									{
										var oSelectedCell = oSelectedRow.getCell(j);
										alert(oSelectedCell.getValue());
										if(oSelectedCell.getValue()!=null)
										    strCopyText += oSelectedCell.getValue()+"\t";	
										else
										    strCopyText += " "+"\t";
										var parts = oSelectedCell.Id.split("_");
										CellData[iCount] = new Array(parts[2],parts[3],oSelectedCell.getValue());
										iCount++;		
									}
								}
								strCopyText = strCopyText.substring(0,strCopyText.length-1)+ "\r\n";
							}
							strCopyText = strCopyText.substring(0,strCopyText.length-1);
						}
					}
				    CopyToClipboard(strCopyText.toString());
					
				}
				else
				{
					//ctl and v to paste back.
					if(event.ctrlKey && event.keyCode == 86)
					{
						var str =getClipboard();
						var iPos = 0;
						var iRow;
						var iCol;
						var strText;
						var oArrRows;//=str.split("\r\n");//paste back to split rows from excel.
						if (window.clipboardData) oArrRows=str.split("\r\n");
						else oArrRows=str.split("\n");
						//if(str.split("\r\n").length==0) oArrRows=str.split("\n");
			            var len = oArrRows.length-1;
			            var star = 1;
						//paste back content if  contain title then  i from 1,else i from 0.
					    if(CellData.length==0)
		                {
		                  isEmptyCellData ="Yes";
		                  // len = oArrRows.length;
		                   //star = 0;
		                   var con=0;
		                   for(i=0; i<oRows.length; i++)
			               {
				                oRow = oRows.getRow(i);
				                if(oRow.getSelected())
				                {
				                      for(j=0;j<count;j++)
				                      {
				                         oCell=oRow.getCell(j);
				                         if(oColumns[j].Hidden==false && IsDeleteColumn( oColumns[j].HeaderText)==false)
				                         {
				                            CellData[con]= new Array(i,j,"");
				                            con++;
				                         }
				                      }
				                      
				                }
				           }
				        }
				      
				        var TempCells =oArrRows[0].split("\t");//split to cell. 				        
				        var startj =0;
				        if(IsDeleteColumn(TempCells[0].toString())==true)
				        {
				            startj = 1;
				        }
						for( i = star;i<=len;i++)
						{
						    if(!oArrRows[i]) continue;
							var oArrCells = oArrRows[i].split("\t");//split to cell.
							for(j=startj;j<oArrCells.length;j++)
							{
								if (IsDeleteColumn( oArrCells[j])==false)
								{			
									iRow = CellData[iPos][0];
									iCol = CellData[iPos][1];
									strText = CellData[iPos][2];
											
									if (parseInt(iRow) != -1)
									{		
										var oCell = oRows.getRow(iRow).getCell(iCol);
										if (oCell.isEditable() || oCell.Column.AllowUpdate==3)
										{
										    if(oColumns[iCol].ColumnType.toString()=='5')
										    {
										        var VList=oColumns[iCol].ValueList.toString().split(",");
										       
										        for(k=0;k<VList.length;k++)
										        {
										            if(oArrCells[j]==VList[k])
										            {
										                 oCell.setValue(VList[k-1]);
										            }
										        }
										    }
										    else
										    {
										        try{ 
										        if( oArrCells[j].toString().charAt(0)=="("){
										       oArrCells[j]="-"+ oArrCells[j].toString().replace('(','').replace(')','');}
										         } 
										         catch(convertExp){}
											    oCell.setValue(oArrCells[j]);
											    if(oCell.Column.DataType==5 || oCell.Column.DataType==19)
											    {oCell.setValue(parseFloat(oArrCells[j].toString().replace(/,/g,'')));}
											}
										}
									}
									iPos++;
								}
								
							}
						}
					}
				}
			}
			if(isEmptyCellData =="Yes")
			{
			    CellData = new Array();	
			}
			}		
		}
		
        function CopyToClipboard(meintext)
        {
        if (window.clipboardData)
        {
        // the IE-manier
        window.clipboardData.setData("Text", meintext);
        }
        else if (window.netscape)
        {
            // dit is belangrijk maar staat nergens duidelijk vermeld:
            // you have to sign the code to enable this, or see notes below
           try {  
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
            }  
            catch (e)  
            {  
               DisplayMessage("Copy action is blocked by your browser settings. To activate,<br>modify the configuration of Firefox as follows:<br>1) Open a new tab and type <b>about:config</b> on the address line. <br>Press <Enter> and click past the warning dialog. <br>2) Set Value = true for Preference Name =<br>signed.applets.codebase_principal_support. Close tab.",1);
            }  
            // maak een interface naar het clipboard
            var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
            if (!clip) return;
            //alert(clip);
            // maak een transferable
            var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
            if (!trans) return;

            // specificeer wat voor soort data we op willen halen; text in dit geval
            trans.addDataFlavor('text/unicode');

            // om de data uit de transferable te halen hebben we 2 nieuwe objecten
            // nodig om het in op te slaan
            var str = new Object();
            var len = new Object();
            var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
            var copytext=meintext;
            str.data=copytext;
            trans.setTransferData("text/unicode",str,copytext.length*2);
            var clipid=Components.interfaces.nsIClipboard;
            if (!clip) return false;
            clip.setData(trans,null,clipid.kGlobalClipboard);
            clip.getData("text/unicode")
        }
        else
        {
        return false;
        }

        //alert("Following info was copied to your clipboard: " + meintext);
        return false;
        }
// function flashcopy(meintext) {
//  if (window.clipboardData) {
//    window.clipboardData.setData("Text", meintext)
//  } else {
//    var flashcopier = 'flashcopier';
//    if(!document.getElementById(flashcopier)) {
//      var divholder = document.createElement('div');
//      divholder.id = flashcopier;
//      document.body.appendChild(divholder);
//    }
//    document.getElementById(flashcopier).innerHTML = '';
//    var divinfo = '<embed src="../img/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(meintext)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
//    document.getElementById(flashcopier).innerHTML = divinfo;
//  }
//  alert(meintext);
//  return false;
//}
	

		function CopyPaste2(gridName)
		{
			var oGrid = igtbl_getGridById(gridName);
			var oRows = oGrid.Rows;		
			var oBands = oGrid.Bands;
			var oBand = oBands[0];
			var oColumns = oBand.Columns;
			var count = oColumns.length;
			var strCopyText = "";
			var iCount = 0;
			var iSelectedCount = 0;
			var strText = "";
			var strRowIndex = "";
			
			if (event.ctrlKey && event.keyCode == 65)
			{	
				for(i=0; i<oRows.length; i++)
				{
					oRow = oRows.getRow(i);
					oRow.setSelected(true);
					if(oRow.ChildRowsCount > 0) 
					{
						var oChildRows = oRow.Rows;
						for(j=0; j<oChildRows.length; j++)
						{
							oChildRow = oChildRows.getRow(j);
							oChildRow.setSelected(true);
						}
					}
				}
			}
			else
			{ 
				//ctl and c to copy selected cell.
				if (event.ctrlKey && event.keyCode == 67)
				{	
					
					if ( igtbl_getLength(oGrid.SelectedRows) > 0)					
					{
						for (j = 0;j<count;j++)
						{
							if (oColumns[j].HeaderText != "Delete" && oColumns[j].Hidden == false)
							{
								strCopyText += oColumns[j].HeaderText +"\t";
							}
						}
						strCopyText = strCopyText.substring(0,strCopyText.length-1)+ "\r\n";
						
						for(i=0; i<oRows.length; i++)
						{
							var oSelectedRow = oRows.getRow(i);
							if (oSelectedRow.getSelected())
							{
								for (j = 0;j<count;j++)
								{
									var oSelectedCell = oSelectedRow.getCell(j);
									
									if (oColumns[j].HeaderText != "Delete" && oColumns[j].Hidden == false)
									{
										var parts = oSelectedCell.Id.split("_");
										CellData[iCount] = new Array(parts[2],parts[3],oSelectedCell.getValue());
										iCount++;
										if(oColumns[j].ColumnType=="5")
										{
										    strCopyText += oSelectedCell.getElement().innerText+"\t";
										}
										else
										    strCopyText += oSelectedCell.getValue()+"\t";
									}
								}
								strCopyText = strCopyText.substring(0,strCopyText.length-1)+ "\r\n";
							}
						}
						strCopyText = strCopyText.substring(0,strCopyText.length-1);
					}		
					
					if ( igtbl_getLength(oGrid.SelectedRows) == 0)					
					{
						for (j = 0;j<count;j++)
						{
							if (oColumns[j].HeaderText != "Delete" && oColumns[j].Selected && oColumns[j].Hidden == false)
							{
								strCopyText += oColumns[j].HeaderText +"\t";
								iSelectedCount++;
							}
						}
						if (iSelectedCount > 0)
						{
							strCopyText = strCopyText.substring(0,strCopyText.length-1)+ "\r\n";

							for(i=0; i<oRows.length; i++)
							{
								var oSelectedRow = oRows.getRow(i);
								for (j = 0;j<count;j++)
								{
									if (oColumns[j].Selected && oColumns[j].HeaderText != "Delete" && oColumns[j].Hidden == false)
									{
										var oSelectedCell = oSelectedRow.getCell(j);
										strCopyText += oSelectedCell.getValue()+"\t";	
										var parts = oSelectedCell.Id.split("_");
										CellData[iCount] = new Array(parts[2],parts[3],oSelectedCell.getValue());
										iCount++;		
									}
								}
								strCopyText = strCopyText.substring(0,strCopyText.length-1)+ "\r\n";
							}
							strCopyText = strCopyText.substring(0,strCopyText.length-1);
						}
					}
					//alert(strCopyText.split("\r\n"));
					window.clipboardData.setData("Text",strCopyText.toString());
				}
				else
				{
					//ctl and v to paste back.
					if(event.ctrlKey && event.keyCode == 86)
					{
					    oGrid.AllowAddNew = 1;
						var str = window.clipboardData.getData("Text");
						//alert(str);
						var iPos = 0;
						var iRow;
						var iCol;
						var strText;
						var oArrRows = str.split("\r\n");//paste back to split rows from excel.
			         
						//paste back content if  contain title then  i from 1,else i from 0.
						for( i = 1;i<oArrRows.length-1;i++)
						{
							var oArrCells = oArrRows[i].split("\t");//split to cell.
							for(j=0;j<oArrCells.length;j++)
							{
								if (oArrCells[j].toString().toLowerCase() != "delete")
								{			
//									iRow = CellData[iPos][0];
//									iCol = CellData[iPos][1];
//									strText = CellData[iPos][2];		
									if (parseInt(iRow) != -1)
									{		
										var oCell = oRows.getRow(i).getCell(j+1);
										if (oCell.isEditable())
										{
										    if(oColumns[iCol].ColumnType.toString()=='5')
										    {
										        var VList=oColumns[iCol].ValueList.toString().split(",");
										       
										        for(k=0;k<VList.length;k++)
										        {
										            if(oArrCells[j]==VList[k])
										            {
										                 oCell.setValue(VList[k-1]);
										            }
										        }
										    }
										    else
										    {
											    oCell.setValue(oArrCells[j]);
											}
										}
									}
									iPos++;
								}
							}
						}
					}
				}
			}		
		}
		//function description:copy and paste to ultrawebgrid
		function CopyAndPaste(gridName, cellId, key)
		{
			var oGrid = igtbl_getGridById(gridName);
			var oRows = oGrid.Rows;		
			var oBands = oGrid.Bands;
			var oBand = oBands[0];
			var oColumns = oBand.Columns;
			var count = oColumns.length;
			var strCopyText = "";
			var iCount = 0;
			var iSelectedCount = 0;
			var strText = "";
			var strRowIndex = "";
			cell = igtbl_getCellById(cellId);
			if(key==113)
				cell.activate();
			//for (j = 0;j<count;j++)
			//{
			//	alert(oColumns[j].Selected);
			//}		
		
			//ctl and a to choose all cell,in this case you must be choose a cell then you can choose ultrawebgrid all cell,otherwise you  will choose all page content.
			if (event.ctrlKey && event.keyCode == 65)
			{	
				for(i=0; i<oRows.length; i++)
				{
					oRow = oRows.getRow(i);
					oRow.setSelected(true);
					if(oRow.ChildRowsCount > 0) 
					{
						var oChildRows = oRow.Rows;
						for(j=0; j<oChildRows.length; j++)
						{
							oChildRow = oChildRows.getRow(j);
							oChildRow.setSelected(true);
						}
					}
				}
			}
			else
			{ 
				//ctl and c to copy selected cell.
				if (event.ctrlKey && event.keyCode == 67)
				{	
					
					if ( igtbl_getLength(oGrid.SelectedRows) > 0)					
					{
						for (j = 0;j<count;j++)
						{
							if (oColumns[j].Key != "Delete" && oColumns[j].Hidden == false)
							{
								strCopyText += oColumns[j].HeaderText +"\t";
							}
						}
						strCopyText = strCopyText.substring(0,strCopyText.length-1)+ "\r\n";
						
						for(i=0; i<oRows.length; i++)
						{
							var oSelectedRow = oRows.getRow(i);
							if (oSelectedRow.getSelected())
							{
								for (j = 0;j<count;j++)
								{
									var oSelectedCell = oSelectedRow.getCell(j);
									if (oColumns[j].Key != "Delete" && oColumns[j].Hidden == false)
									{
										var parts = oSelectedCell.Id.split("_");
										CellData[iCount] = new Array(parts[1],parts[2],oSelectedCell.getValue());
										iCount++;
										strCopyText += oSelectedCell.getValue()+"\t";
									}
								}
								strCopyText = strCopyText.substring(0,strCopyText.length-1)+ "\r\n";
							}
						}
						strCopyText = strCopyText.substring(0,strCopyText.length-1);
					}
					
					
					if ( igtbl_getLength(oGrid.SelectedRows) == 0)					
					{
						for (j = 0;j<count;j++)
						{
							if (oColumns[j].Key != "Delete" && oColumns[j].Selected && oColumns[j].Hidden == false)
							{
								strCopyText += oColumns[j].HeaderText +"\t";
								iSelectedCount++;
							}
						}
						if (iSelectedCount > 0)
						{
							strCopyText = strCopyText.substring(0,strCopyText.length-1)+ "\r\n";

							for(i=0; i<oRows.length; i++)
							{
								var oSelectedRow = oRows.getRow(i);
								for (j = 0;j<count;j++)
								{
									if (oColumns[j].Selected && oColumns[j].Key != "Delete" && oColumns[j].Hidden == false)
									{
										var oSelectedCell = oSelectedRow.getCell(j);
										strCopyText += oSelectedCell.getValue()+"\t";	
										var parts = oSelectedCell.Id.split("_");
										CellData[iCount] = new Array(parts[1],parts[2],oSelectedCell.getValue());
										iCount++;		
									}
								}
								strCopyText = strCopyText.substring(0,strCopyText.length-1)+ "\r\n";
							}
							strCopyText = strCopyText.substring(0,strCopyText.length-1);
						}
					}
					window.clipboardData.setData("Text",strCopyText.toString());
				}
				else
				{
					if(event.ctrlKey && event.keyCode == 86)
					{
						var str = window.clipboardData.getData("Text");
						var iPos = 0;
						var iRow;
						var iCol;
						var strText;
						var oArrRows = str.split("\r\n");//paste back to split rows from excel.
						
						//paste back content if  contain title then  i from 1,else i from 0.
						for( i = 1;i<oArrRows.length-1;i++)
						{
							var oArrCells = oArrRows[i].split("\t");//split to cell.
							for(j=0;j<oArrCells.length;j++)
							{
								if (oArrCells[j].toString().toLowerCase() != "delete")
								{							
									iRow = CellData[iPos][0];
									iCol = CellData[iPos][1];
									strText = CellData[iPos][2];		
									if (parseInt(iRow) != -1)
									{						
										var oCell = oRows.getRow(iRow).getCell(iCol);
										if (oCell.isEditable())
											oCell.setValue(oArrCells[j]);
									}
									iPos++;
								}
							}
						}
						//clear record information.
					}
				}
			}		
		}		

//ajax

        var _XMLHTTP = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"]; 

        function _newActiveXObject(array) { 
        var returnValue;  
        for (var i = 0; i < array.length; i++) { 
        try { 
        returnValue = new ActiveXObject(array[i]); 
        break; 
        } catch (ex) {} 
        } 
        return returnValue; 
        } 

        function getAjax(){ 
        var ajax = false; 
        ajax = _newActiveXObject(_XMLHTTP); 
        if (!ajax && typeof XMLHttpRequest!='undefined') { 
        ajax = new XMLHttpRequest(); 
        } 
        return ajax; 
        } 

        var oReq;
		
		function CreateXMLHTTPRequest()
		{
		    oReq = getAjax();
		} 
		
		function OnStateChanged()
		{
			if (oReq.readyState == 4)
			{
				if (oReq.status == 200)
				{
					var ret = oReq.responseText;
					
					if (ret.indexOf("Failure#")!=-1)	
					{
					    if(document.getElementById("loading")!=null)
					    {
					        HidUploding();
					    }
					    ret= ret.replace("Failure#","")
					    DisplayMessage(ret,1);
					    document.getElementById("buttons").style.display = 'none';
					}	
					else if(ret=="Success")
					{
					    document.location.href=document.location.href;
					}	
					else if(ret.indexOf("Success#")!=-1)	
					{
					    var obj = window.top.document.getElementById('spanBankName');if (obj != null) obj.innerHTML="Institution: "+ret.replace("Success#","");
					    
						document.location.href=document.location.href;
					}
					else
					{
					   if(document.getElementById("loading")!=null)
					   {
					      HidUploding();
					   }
					   // return false;
					}
				}
			}
		}
	    function hidbtmesage()
	    {
	     document.getElementById("buttons").style.display = 'none';
	     document.getElementById("trMessage").style.display="none";
	    }
	 function confirmbt(requestStr,urlStr,isCOA)
        {
           document.getElementById("buttons").style.display = 'block';
        
		   document.getElementById("Ok1").onclick = function()
		   {
		  	     CreateXMLHTTPRequest();
			     oReq.onreadystatechange = OnStateChanged;
			     oReq.open("POST",urlStr,true);
			     oReq.send(requestStr);		 
		         if(urlStr=="upload.aspx" || urlStr.indexOf("accountinfo.aspx")!=-1)
		         {
		            ShowUploding();
		            hidbtmesage();
		         }
		         else if(urlStr.indexOf("RunLog.aspx")!=-1)
		         {
		            document.getElementById("buttons").style.display = 'none';
		            if(isCOA=="COA")
		            {
		               // DisplayMessage("Your uploading process of COA has been initiated. Email confirmation that this request has been received by the job server should arrive momentarily.<br><br>You will receive a second email to indicate the start of processing, followed by a third message when the uploading process of COA has completed.",1);
		               document.all.divMessage.innerHTML = "Your uploading process of COA has been initiated. Email confirmation that this request has been received by the job server should arrive momentarily.<br>You will receive a second email to indicate the start of processing, followed by a third message when the uploading process of COA has completed.";
		            }
		            else if(isCOA == "instruments")
		                document.all.divMessage.innerHTML ="Your uploading instruments process has been initiated. Email confirmation that this request has been received by the job server should arrive momentarily.<br>You will receive a second email to indicate the start of processing, followed by a third message when the uploading instruments process has completed.";
		         }
		         else
		         {
		            hidbtmesage();
		         }
		   }
		     document.getElementById("Cancel1").onclick = function(){
		     hidbtmesage();
		   }
        }
  
    function uploadAjax(requestStr,urlStr,isCOA)
    {
         if(isCOA=="COA")
            DisplayMessage("Your uploading process of COA has been initiated. Email confirmation that this request has been received by the job server should arrive momentarily.<br>You will receive a second email to indicate the start of processing, followed by a third message when the uploading process of COA has completed.",1);
         else if(isCOA == "instruments")
            DisplayMessage("Your uploading instruments process has been initiated. Email confirmation that this request has been received by the job server should arrive momentarily.<br>You will receive a second email to indicate the start of processing, followed by a third message when the uploading instruments process has completed.",1);
	    
         CreateXMLHTTPRequest();
		 oReq.onreadystatechange = OnStateChanged;
		 oReq.open("POST",urlStr,true);
		 oReq.send(requestStr);
    }
    function hidAnalysis()
	{
	   if(GetType(window.location.search)=="bond")
	   {
	     document.getElementById("Analysis").style.display="none";
	   }
	}
//--clear js error on client's Status 
//Çå³ý¿Í»§¶Ë½Å±¾´íÎó
function killErrors() {
return true;
}
window.onerror = killErrors;
//--
function Ctl(ctlId){if(ctlId)return document.getElementById(ctlId);}
