
function CreateTable(I_Odd_Output,RowCount)
{


var intROW;
intROW = 1;
//alert("RowCount"+RowCount)
//alert("IN CREATE TABLE")
//I_Odd_Output[intROW] = new Array(2)
//I_Odd_Output[intROW+1] = new Array(2)

//alert("in I_Odd_Output[intROW][2] AMOUNT  : "+I_Odd_Output[intROW][2])
//alert("in I_Odd_Output[intROW][1]  : "+I_Odd_Output[intROW][1])

//alert("in I_Odd_Output[intROW][2] AMOUNT2  : "+I_Odd_Output[intROW + 1][2])
//alert("I_Odd_Output[intROW + 1][0]"+I_Odd_Output[intROW + 1][1] )    

//var items = '123';      ///////////Store length 
//alert(items);
//alert("intROW"+intROW)
//alert(document.getElementById("lbl"));
var tbody = document.getElementById("tblCertCal").getElementsByTagName("tbody")[0];

//alert("Tbody"+tbody)
var rows = document.getElementById("tblCertCal")
//alert("Tbody"+rows)
tbody.setAttribute("innerText","");
	
var j = parseInt(RowCount);
for (var i=1;i < j ;i++) 
{ 
	//alert("infor"+i)
	//ONMOUSEOUT='changeColor(this, \"OUT\");'
	//ONMOUSEOVER='changeColor(this, \"OVER\");'   
	//var tr = document.createElement("<TR ONCLICK='getVal(this);'>" );
	//alert("BTable");
	
	var tr = document.createElement("<TR  ONCLICK='getVal(this,this.rowIndex  );' ONMOUSEOVER='changeColor(this, \"OVER\");'ONMOUSEOUT='changeColor(this, \"OUT\");' >" );
	
	//alert("currID 123-->"+id)
	//var currID = "row1"
	//alert("currID-->"+currID)
	//alert(tr.setAttribute("id",currID));
	//alert("ID-->" + document.getElementById("currID"));
	//document.getElementById("lbl").value =  this.parentNode.parentNode.rowIndex
	//alert("ROW ID"+this.parentNode.parentNode.rowIndex);
	
	var cell1 =document.createElement("TD");	
	
	var txtMinCertAmt =document.createElement("<input>");
	var MinCertAmt = I_Odd_Output[i][2]
			////xmlDoc.getElementsByTagName('RFQ_ID')
	
	if(MinCertAmt.length == 0)
	{
		cell1.innerHTML = "&nbsp;"; 
		//tr.style.align = 'left';
		tr.appendChild(cell1);	
	} 
	else
	{	
		txtMinCertAmt = document.createTextNode(MinCertAmt);		
		cell1.appendChild(txtMinCertAmt);
		tr.style.align = 'right'
		tr.style.bgColor = "#c1cdc1";
		tr.appendChild(cell1);
	}
	var txtNoCert =document.createElement("<input>");
	var cell2 =document.createElement("TD");
	var NoCertAmt = I_Odd_Output[i][1]
	if(NoCertAmt.length == 0)
	{
		cell2.appendChild(NoCertAmt);
		tr.appendChild(cell2);	
	} 
	else
	{
		txtNoCert = document.createTextNode(NoCertAmt);
		cell2.appendChild(txtNoCert);
		//tr.style.align = 'center'
		tr.style.bgColor = '#c1cdc1';
		tr.appendChild(cell2);
	}
		
	var txtAmt =document.createElement("<input>");
	var cell3 =document.createElement("TD");
	var TAmt = I_Odd_Output[i][0]
	//alert("TAMOUNT"+TAmt);
	//parseInt(document.getElementById("lblTotalAmount").innerText) =TAmt
	//TAmt = TAmt+ TAmt
	//alert("SumAmt qw" +document.getElementById("lblTotalAmount").innerText)
	//var SumAmt ;
	//SumAmt = SumAmt + TAmt;
	//alert("SumAmt" +SumAmt)
	//SumAmt = parseInt(document.getElementById("lblTotalAmount").innerText)
	//alert("SumAmt" +SumAmt)
	
	//document.getElementById("lblError").innerText ="HUI"
	//SumAmt = parseInt(document.getElementById("lblTotalAmount").innerText)
	//parseInt(document.getElementById("lblTotalAmount").innerText) = SumAmt + TAmt	
	
	//document.getElementById("lblTotalAmount").rows(r).cells[2].innerText =TAmt
	
	//alert("SumAmt "+SumAmt)tblCertCal
	//document.getElementById("lblTotalAmount").innerText = SumAmt + TAmt
	
	if(TAmt.length == 0)
	{
		cell3.appendChild(txtAmt);
		//cell3.innerHTML = "&nbsp;"; 
		tr.style.bgColor = "#c1cdc1";
		tr.appendChild(cell3);	
	} 
	else
	{
		txtAmt = document.createTextNode(TAmt);
		cell3.appendChild(txtAmt);
		//tr.style.align = 'center'
		tr.style.bgColor = "#c1cdc1"
		tr.appendChild(cell3);
	}
		
		var cell4 =document.createElement("TD");
		var btn = document.createElement('<input  id ="d1" type="button" value="Delete" onclick="deleteRow(this.parentNode.parentNode.rowIndex)">')
		cell4.appendChild(btn)
		tr.appendChild(cell4);

		tbody.appendChild(tr);
		
		
	var cell5 =document.createElement("TD");
	var txtno =document.createElement("input");	
	txtno = document.createTextNode(i);
	cell5.appendChild(txtno);
	cell5.style.visibility='hidden'
	tr.style.bgColor = "#c1cdc1"         //'hidden'
	tr.appendChild(cell5);			
	tbody.appendChild(tr)
	///alert("END");
	
}
	//	alert("END1");
}


function getVal(perCert,rowindex)
{
try
  {
	//alert("getval IN ROW = " + perCert.parentNode.parentNode.rowIndex);
	//perCert.style.backgroundColor='blue';
	//perCert.style.backgroundColor='#c1cdc1';
	//alert("row IN DEX"+perCert)
	
	toggle(perCert,rowindex,"SET")
	parseInt(rowindex)
	rowindex = rowindex;
	//alert("row IN DEX :::"+rowindex)
	//tr.style.bgColor = "#c1cdc1"         //'hidden'
	
	//document.getElementById("lbl").value =  perCert.parentNode.parentNode.rowIndex
	//document.getElementById("lblError").innerText = "";
    //document.getElementById("txtMinCert1").innerText = perCert.cells[0].firstChild.nodeValue;
    document.getElementById("hdnRowNo").value = rowindex;
    document.getElementById("lblCertNO").innerText = perCert.cells[1].firstChild.nodeValue;
    document.getElementById("lblCertAmt").innerText = perCert.cells[2].firstChild.nodeValue;
    document.getElementById("txtTransferAmount").value = perCert.cells[3].firstChild.nodeValue;    
    document.getElementById("txtcusName").value =  perCert.cells[4].firstChild.nodeValue;
    document.getElementById("lblCusName").innerText = perCert.cells[5].firstChild.nodeValue;
    document.getElementById("txtCusID").value = perCert.cells[6].firstChild.nodeValue;
    
 	
	var list = document.getElementById("drpCrPayoutType")    
	list.options[list.selectedIndex].innerText = perCert.cells[7].firstChild.nodeValue;
	
	document.getElementById("txtCrPayouno").value = perCert.cells[8].firstChild.nodeValue;
    
	var list = document.getElementById("drpPracctype")    
	list.options[list.selectedIndex].innerText = perCert.cells[9].firstChild.nodeValue;
	document.getElementById("txtprncaccno").value = perCert.cells[10].firstChild.nodeValue;
    
	
	var list = document.getElementById("drprmname")    
	list.options[list.selectedIndex].innerText = perCert.cells[11].firstChild.nodeValue;

	
	document.getElementById("lblsalesid").innerText = perCert.cells[12].firstChild.nodeValue;
	document.getElementById("lblbrnachename").innerText = perCert.cells[13].firstChild.nodeValue;
	document.getElementById("txtbranchecode").value = perCert.cells[14].firstChild.nodeValue;

    var rownumber =  rown = document.getElementById("tblCertCal").rows
    var valAmt = 0 ;
   var currCertAmount = 0;
	//alert("rownsssssss"+ rownumber.length)
  var CertiNo;	
	for(i = 2 ; i < rownumber.length ; i++)
	{
		CertiNo = document.getElementById("tblCertCal").rows[i].cells[1].innerText
		
		if ( document.getElementById("lblCertNO").innerText  == CertiNo)
	  	{
	  	if (i == rowindex)
		{   
		  currCertAmount = parseFloat(replcomma(document.getElementById("tblCertCal").rows[i].cells[3].innerText))	
		}	
	  	valAmt = valAmt + parseFloat(replcomma(document.getElementById("tblCertCal").rows[i].cells[3].innerText))	
	  	}
	}	
	 //alert("rownsssssss val of amount"+ valAmt)
     var remaning = 0;
     remaning = valAmt - currCertAmount
     //alert("remaning"+remaning)
     
     
    //document.getElementById('lblRemAmount').innerHTML =   parseFloat(document.getElementById('lblCertAmt').innerHTML) - parseFloat(valAmt);
	//document.getElementById('lblCurrentAmt').innerHTML =  parseFloat(document.getElementById('lblRemAmount').innerHTML) - parseFloat(document.getElementById("txtTransferAmount").value0 ;
	if (valAmt == 0 )
	{
		document.getElementById('lblRemAmount').innerHTML = parseFloat(document.getElementById('lblRemAmount').innerHTML) +  parseFloat(replcomma(perCert.cells[3].firstChild.nodeValue));
		document.getElementById('lblCurrentAmt').innerHTML = parseFloat(document.getElementById('lblCurrentAmt').innerHTML) - parseFloat(replcomma(perCert.cells[3].firstChild.nodeValue));
    }
    else
    {
		document.getElementById('lblRemAmount').innerHTML =  remaning 
		document.getElementById('lblCurrentAmt').innerHTML =  parseFloat(document.getElementById('lblCertAmt').innerHTML) - remaning
    }
    
    //document.getElementById("lbl").value = rowindex;

    //alert("document.getElementById("lbl").value = " + rowindex)
    //alert(perCert.cells[4].firstChild.nodeValue)
    //setVal(perCert);
    //var txtMinCertAmt =document.createElement("<input>");
    //alert(txtMinCertAmt);
    //td.appendChild(txtMinCertAmt);
    	}
	catch(err)
  {
  txt="There was an error on this page.\n\n";
  txt+="Error description: " + err.description + "\n\n";
  txt+="Click OK to continue.\n\n";
  //alert(txt);
  }
}


function ClsRow()
{
  
  if  (document.getElementById("hiddenTransfer").value == "TRANSFER") 
  {
   document.getElementById('btnTrans').disabled = true;  
  }
  else
  {
   document.getElementById('btnTrans').disabled = false;  
  }
//document.getElementById("lblCertNO").innerText = "";
//'document.getElementById("lblCertAmt").value = "";	
//'document.getElementById("txtTransferAmount").value = "";
	var txtTransferAmount = document.getElementById("txtTransferAmount").value
	var lblCertAmt = document.getElementById("lblCertAmt").innerText
		if(parseFloat(replcomma(txtTransferAmount)) > parseFloat(replcomma(lblCertAmt)))
		{
		 document.getElementById('lblError').innerHTML = "Transfer amount should be less than cert amount";					
		 document.getElementById('btnsetValue').disabled = true;
		//document.getElementById('btnTrans').disabled = true;						MAY 18
		//document.getElementById('txtTransferAmount').focus()	
		return false;
		}
		else{   
		AddNewRow();
      }
}

function AddNewRow()
{
try
  {

	if (this.rowIndex = document.getElementById("hdnRowNo").value )
	{
		
	parseInt(document.getElementById("txtcusName").value)
	this.rowIndex = this.rowIndex
	
	//tr.style.bgColor = "#c1cdc1"         //'hidden'
	document.getElementById("hdnRowNo").value = ""
	//document.getElementById("lbl").value =  perCert.parentNode.parentNode.rowIndex
	//document.getElementById("lblError").innerText = "";
    //document.getElementById("txtMinCert1").innerText = perCert.cells[0].firstChild.nodeValue;
    
    document.getElementById("tblCertCal").rows[this.rowIndex].cells[1].innerText = document.getElementById("lblCertNO").innerText ;
    document.getElementById("tblCertCal").rows[this.rowIndex].cells[2].innerText = document.getElementById("lblCertAmt").innerText;
    document.getElementById("tblCertCal").rows[this.rowIndex].cells[3].innerText   = document.getElementById("txtTransferAmount").value 
    document.getElementById("tblCertCal").rows[this.rowIndex].cells[4].innerText   = document.getElementById("txtcusName").value  // perCert.cells[4].firstChild.nodeValue
    document.getElementById("tblCertCal").rows[this.rowIndex].cells[5].innerText = document.getElementById("lblCusName").innerText;
    document.getElementById("tblCertCal").rows[this.rowIndex].cells[6].innerText = document.getElementById("txtCusID").value; 
    
  	 
	var list = document.getElementById("drpCrPayoutType")    
	document.getElementById("tblCertCal").rows[this.rowIndex].cells[7].innerText = list.options[list.selectedIndex].innerText; 
	 
	document.getElementById("tblCertCal").rows[this.rowIndex].cells[8].innerText = document.getElementById("txtCrPayouno").value; 
   
	
	var list = document.getElementById("drpPracctype")    
	document.getElementById("tblCertCal").rows[this.rowIndex].cells[9].innerText = list.options[list.selectedIndex].innerText; 
	 
	document.getElementById("tblCertCal").rows[this.rowIndex].cells[10].innerText = document.getElementById("txtprncaccno").value; 
   
	var list = document.getElementById("drprmname")    
	document.getElementById("tblCertCal").rows[this.rowIndex].cells[11].innerText = list.options[list.selectedIndex].innerText; 

	 
	document.getElementById("tblCertCal").rows[this.rowIndex].cells[12].innerText  = document.getElementById("lblsalesid").innerText; 
	document.getElementById("tblCertCal").rows[this.rowIndex].cells[13].innerText = document.getElementById("lblbrnachename").innerText;
	document.getElementById("tblCertCal").rows[this.rowIndex].cells[14].innerText = document.getElementById("txtbranchecode").value;
	//alert("set on OLd")
	
	}
	else
	{
	//alert("set on NEW")
	
//alert("ADD SWAP")
var TblRowCount = tblCertCal.rows;
//alert("test"+TblRowCount)

var r = parseInt(TblRowCount.length)
r  = r -1 ;
//alert("NEW ROW ID Is "+r)
//alert("rrrr TblRowCount ::"+TblRowCount)
//var Amt = document.getElementById("tblCertCal").rows(r).cells[2].innerText  
//var CerNo = document.getElementById("tblCertCal").rows(r).cells[1].innerText  
//var perCertAmt = document.getElementById("tblCertCal").rows(r).cells[0].innerText  
//alert(Amt + CerNo + perCertAmt)
//Amt =12
//CerNo =1233
//perCertAmt =3333
//alert(Amt + CerNo + perCertAmt)
//if(Amt != "" && CerNo != "" && perCertAmt != "" )
//{

valAmount()				
if (document.getElementById("lblCertNO").innerText != "")
{

	if (document.getElementById("txtCusID").value != "")
	 {
	 
		if (document.getElementById("txtCrPayouno").value != "")
		{
		  if (document.getElementById("txtprncaccno").value != "")
			{		
				if(document.getElementById("lblbrnachename").innerText != "")
				 {
				  if (document.getElementById("lblsalesid").innerText != "")
					{
					  if (document.getElementById("txtTransferAmount").value != "")
					   {
							
							
							
							////document.getElementById("tblCertCal").;
							//alert(TblRowCount.length);
							var tbody = document.getElementById("tblCertCal").getElementsByTagName("tbody")[0];		
							//var rows = document.getElementById("tblCertCal")
							var tr = document.createElement("<TR ONCLICK='getVal(this,this.rowIndex);' >" );
							
							
							var cell0 =document.createElement("TD");
							var srNo = 0							
							srNo = TblRowCount.length
							srNo = srNo - 1 ;							
							var rowno = document.createTextNode(srNo);
							//cell1.style.visibility='hidden'
							cell0.appendChild(rowno);
							//cell3.innerHTML = "N";
							tr.appendChild(cell0);
							
							
							
							var cell1 =document.createElement("TD");
							//alert(document.getElementById("lblCertNO").innerText);
							//alert(document.getElementById("lblCertNO").innerText)
							var txtMinCertAmt2 = document.createTextNode(document.getElementById("lblCertNO").innerText);
							//alert("SSS"+txtMinCertAmt2);
							cell1.appendChild(txtMinCertAmt2);
							tr.appendChild(cell1);
							
							var cell2 =document.createElement("TD");
							//cell2.innerHTML = "N";
							var txtCertNo2 = document.createTextNode(document.getElementById("lblCertAmt").innerText);
							cell2.appendChild(txtCertNo2);
							tr.appendChild(cell2);
							
							var cell3 =document.createElement("TD");
							var txtAmt2 = document.createTextNode(document.getElementById("txtTransferAmount").value);
							cell3.appendChild(txtAmt2);
							//cell3.innerHTML = "N";
							tr.appendChild(cell3);
							
							
							var cell4 =document.createElement("TD");
							
							var txtcusName = document.createTextNode(document.getElementById("txtcusName").value);
							cell4.appendChild(txtcusName);
							//cell3.innerHTML = "N";
							tr.appendChild(cell4);
							
							if (document.getElementById("lblCusName").innerText == "") 
							{
								var cell5 =document.createElement("TD");
								var txtCustomerName = document.createTextNode("");
								cell5.appendChild(txtCustomerName);
								//cell3.innerHTML = "N";
								tr.appendChild(cell5);
							}
							else
							{
								
								var cell5 =document.createElement("TD");
								var txtCustomerName = document.createTextNode(document.getElementById("lblCusName").innerText);
								cell5.appendChild(txtCustomerName);
								//cell3.innerHTML = "N";
								tr.appendChild(cell5);
							}
							
							var cell6 =document.createElement("TD");
							//cell2.innerHTML = "N";
							var txtCustID = document.createTextNode(document.getElementById("txtCusID").value);
							cell6.appendChild(txtCustID);
							tr.appendChild(cell6);
							
							
							var cell7 =document.createElement("TD");
							//cell2.innerHTML = "N";
							var list = document.getElementById("drpCrPayoutType");		
							//alert(list.options[list.selectedIndex].text);
							var txtPayoutType = document.createTextNode(list.options[list.selectedIndex].text);
							cell7.appendChild(txtPayoutType);
							tr.appendChild(cell7);
							
							var cell8 =document.createElement("TD");
							//cell2.innerHTML = "N";
							var txtCrPayouNo = document.createTextNode(document.getElementById("txtCrPayouno").value);
							cell8.appendChild(txtCrPayouNo);
							tr.appendChild(cell8);
						
						
							var cell9 =document.createElement("TD");
							//cell2.innerHTML = "N";
							var list = document.getElementById("drpPracctype");
							//alert(list.options[list.selectedIndex].text);
							var txtPrincipalType = document.createTextNode(list.options[list.selectedIndex].text);
							cell9.appendChild(txtPrincipalType);
							tr.appendChild(cell9);
							
							var cell10 =document.createElement("TD");
							//cell2.innerHTML = "N";
							var txtPrincipalNo = document.createTextNode(document.getElementById("txtprncaccno").value);
							cell10.appendChild(txtPrincipalNo);
							tr.appendChild(cell10);
							
							
							var cell11 =document.createElement("TD");
							//cell2.innerHTML = "N";
							var list = document.getElementById("drprmname");
							//alert(list.options[list.selectedIndex].text);
							var txtSalesPersonName = document.createTextNode(list.options[list.selectedIndex].text);
							cell11.appendChild(txtSalesPersonName);
							tr.appendChild(cell11);
							
							var cell12 =document.createElement("TD");
							//cell2.innerHTML = "N";
							var txtSalesPersonId = document.createTextNode(document.getElementById("lblsalesid").innerText);
							cell12.appendChild(txtSalesPersonId);
							tr.appendChild(cell12);
							
							var cell13 =document.createElement("TD");
							//cell2.innerHTML = "N";
							var txtBranchName = document.createTextNode(document.getElementById("lblbrnachename").innerText);
							cell13.appendChild(txtBranchName);
							tr.appendChild(cell13);
							
							
							
							var cell14 =document.createElement("TD");
							//cell2.innerHTML = "N";
							var txtBranchID = document.createTextNode(document.getElementById("txtbranchecode").value);
							cell14.appendChild(txtBranchID);
							tr.appendChild(cell14);
						
							var cell15 =document.createElement("TD");
							var btn = document.createElement('<input type="button" value="Delete" onclick="deleteRow(this.parentNode.parentNode.rowIndex)">')
							cell15.appendChild(btn)
							tr.appendChild(cell15);
							
							tbody.appendChild(tr);
							//alert(tbody.appendChild(tr))
									
							//alert("tblCertCal.rows" + parseInt(TblRowCount.length));
							rowno  = parseInt(TblRowCount.length) 
							//alert("rowno 123"+rowno);
							//document.getElementById("lbl").value = parseInt(TblRowCount.length) -1;
							document.getElementById("lblError").innerText = ""
							
							//document.getElementById('btnTrans').disabled = true;  
							document.getElementById('btnsetValue').disabled = true;
							
						} // IF of Transfer amount
						else
						{
							document.getElementById("lblError").innerText = "Please enter valid transfer amount."
						}	
					  } // if sales ID validation
					  else
					  {
						document.getElementById("lblError").innerText = "Please select valid sales name."
					  }		
				   } // if Branche Name 
				   else
				   {
					document.getElementById("lblError").innerText = "Please select valid branch name."
				   }	
				} // if of principal account number
				else
				{
					document.getElementById("lblError").innerText = "Please enter valid pricipal account number."
				}	
		} // If OF crpayout NO validation
		
		else
		{
			document.getElementById("lblError").innerText = "Please enter valid payout number."
		}
	  } //IF OF customer ID validation
	  else
	  {
		document.getElementById("lblError").innerText = "Please enter valid custome name."
	  }	
	}
	else
	{
	document.getElementById("lblError").innerText = "Please select certificate."
	}
	}
	
	}  //SET on new
	catch(err)
  {
  txt="There was an error on this page.\n\n";
  txt+="Error description: " + err.description + "\n\n";
  txt+="Click OK to continue.\n\n";
  //alert(txt);
  }
}


function deleteRow(i)
{
try{
	
     document.getElementById('tblCertCal').deleteRow(i)
/*	document.getElementById("lblCertNO").innerTex =""
	document.getElementById("lblCertAmt").innerText =""
	document.getElementById("txtTransferAmount").value = ""
	document.getElementById("txtcusName").value = ""
	document.getElementById("lblCusName").innerText = ""
	document.getElementById("txtCusID").value = ""

	var list = document.getElementById("drprmname")    
	list.options[list.selectedIndex].innerText = ""
	
	var list = document.getElementById("drpCrPayoutType")    
	list.options[list.selectedIndex].innerText = ""
	document.getElementById("txtCrPayouno").value = ""
	
	var list = document.getElementById("drpPracctype")    
	list.options[list.selectedIndex].innerText = ""
	document.getElementById("txtprncaccno").value = ""


	
	document.getElementById("lblsalesid").innerText = ""
	document.getElementById("lblbrnachename").innerText = ""
	document.getElementById("txtbranchecode").value = ""
*/
    }
    catch(err)
  {
  txt="There was an error on this page.\n\n";
  txt+="Error description: " + err.description + "\n\n";
  txt+="Click OK to continue.\n\n";
  //alert(txt);
  }
}


 var previousRow;

 function toggle( i ,row,str){ 
 
	//alert("previousRow"+i)
	//alert("row"+row)
	previousRow = 1; 

	if(str == "SET")
	{
	  i.style.backgroundColor = 'pink';
	}
	else
	{
	  i.style.backgroundColor = 'red';
	}
	

	//var tableElem = document.getElementById("tblCertCal");
	//rowElem = tableElem.rows[previousRow];
	//rowElem.style.backgroundColor = "yellow";
	
	//var tableElem = document.getElementById("tblCertCal");
	//rowElem = tableElem.rows[i];
	//rowElem.style.backgroundColor= "red";

	//i.bgColor='#ffffff';      

	//i.bgColor='#91ccd8';
	 previousRow = row;

 } 
 
function setVal(rowno)
{
// var n = document.getElementById("lbl").value;
 var I_strAddOnAmt = document.getElementById("lblPerunit").value;
 //alert("I_strAddOnAmt "+I_strAddOnAmt)
  //alert("ROW NO"+rowno);
  rowno = rowno ;
 //alert("ROW NO"+rowno);
  
var Amt = document.getElementById("txtMinCert1").value
//'document.getElementById("tblCertCal").rows[rowno].cells[0].innerText;
var NoofCert = document.getElementById("txtCertNo1").value
//document.getElementById("tblCertCal").rows[rowno].cells[1].innerText;
//alert(Amt)
//alert(NoofCert)

var I_PerUnit;
I_PerUnit = parseInt(I_strAddOnAmt);
  
 I_strAddOnAmt = Amt/I_strAddOnAmt;
// alert("DECIMAL"+I_strAddOnAmt)
 intDecimal = InStr(I_strAddOnAmt, ".")
  var I_strMinAmt = document.getElementById("lblMinInvest").innerText
 
 //alert("I_strMinAmt"+I_strMinAmt)
 //alert("Amt"+Amt)

 	if (parseInt(Amt) < parseInt(I_strMinAmt))
 	{
 	 //alert("IN IF amount is less cant contitus"+Amt)
 	 document.getElementById('lblError').innerText = "Minimum investment amount is " + I_strMinAmt + ".Can not continue.";		
	return 0;
 	}
 	
    if ( I_strMinAmt == 0)
	{
		document.getElementById('lblError').innerText = "Minimum investment amount is 0.Can not continue.";		
		return 0;
	}

 
 //alert("intDecimal"+intDecimal)
 if (intDecimal > 0)
 {
 I_strMessage = "Nominal amount should be multiple of per unit equivalent amount" + I_PerUnit + ".Please, re-enter Nominal Amount."
 document.getElementById('lblError').innerText = I_strMessage;
 
 }
 else
 {
	//alert("IN ELSE")
	var percert = Amt * NoofCert
	var TotalAMount;
    //var  document.getElementById("lblMinInvest").value 
    
	
    
    //TotalAMount =0
 //TotalAMount =   TotalAMount + parseInt(percert);
 //alert("TotalAMount"+TotalAMount)
 
  //document.getElementById("lblTotalAmount").innerText = parseInt(document.getElementById("tblCertCal").rows[0].cells[0].innerText) + parseInt(document.getElementById("tblCertCal").rows[1].cells[0].innerText)
 
 document.getElementById("tblCertCal").rows[rowno].cells[0].innerText = document.getElementById("txtMinCert1").value
  
  //alert("PER CERT"+document.getElementById("tblCertCal").rows[rowno].cells[0].innerText)
  
 document.getElementById("tblCertCal").rows[rowno].cells[2].innerText = document.getElementById("txtAmt1").value
 
 //alert("AMOUT CERT "+document.getElementById("tblCertCal").rows[rowno].cells[2].innerText)
 
 document.getElementById("tblCertCal").rows[rowno].cells[1].innerText = document.getElementById("txtCertNo1").value
 //alert("TOTAL AMOUNT"+document.getElementById("tblCertCal").rows[rowno].cells[1].innerText) 
 
 document.getElementById("tblCertCal").rows[rowno].cells[2].innerText = percert;
 

 document.getElementById('lblError').innerText = "";
 
 
 }

}

function setVal1()
{
	var temprno = parseInt(document.getElementById("lbl").value)  
	//alert("setVal1 row no" + temprno)
	setVal(temprno)
}



function replcomma(amount)
{
	amount = amount.replace(",","")
	amount = amount.replace(",","")
	amount= amount.replace(",","")
	amount= amount.replace(",","")				
	return amount;
}
		
function isNumber(sText) {
if (sText=="") return false;
var ValidChars = "0123456789.,";
var IsNumber=true;
var Char;
var dotCnt = 0;

for (i = 0; i < sText.length && IsNumber == true; i++) 
{ 
Char = sText.charAt(i); 
if (Char==".") dotCnt = dotCnt +1;
if (ValidChars.indexOf(Char) == -1 || dotCnt>1) 
{
IsNumber = false;
}
}
return IsNumber;

}




function formatamount(amount)
		{						
			amount = amount.replace(",","")
			amount = amount.replace(",","")
			amount= amount.replace(",","")
			amount= amount.replace(",","")	
						
			amount = checkNotional(amount);
			amount = addCommas(amount);									
			//alert(amount);
			return amount;
		}
		
function checkNotional(notional)

{
//var rel_Amount = /([-+]?([0-9]*\.)?[0-9]+[K|M|B]*$)/i;     
var rel_Amount = /\d+(K$(?![K|M|B])|M$(?![K|M|B])|B$(?![K|M|B]))/i;
     
var rel_Char= /(K|M|B)/i;
     
var pos;
     
var number;
     
var rel_invalidChar = /[\#|\@|!|\&|\*|\%|\\|\+|\*|\^]/;
     
if (notional.search(rel_invalidChar) != -1){
        
return null;
     
}
    
        
if (notional.search(rel_Amount) != -1){

            
if ((notional.search('K') != -1) || (notional.search('k') != -1)){
               
pos = notional.search(rel_Char);
               
if(pos!=0){
                    
number = notional.substring(0,pos);
                    
number = number * 1000;
               
}else{
                    
//number = 1000;
                    
return null;
               
}
               
//return number;
                 
return number;
            
}
            
if ((notional.search('M') != -1) || (notional.search('m') != -1)){
               
pos = notional.search(rel_Char);
               
if(pos!=0){
                    
number = notional.substring(0,pos);
                    
number = number * 1000000;
               
}else{
                    
//number = 1000000;
                    
return null;
               
}
               
return number;
            
}
            
if ((notional.search('B') != -1) || (notional.search('b') != -1)){
               
pos = notional.search(rel_Char);
                
if(pos!=0){
                   
number = notional.substring(0,pos);
                   
number = number * 1000000000;
               
}else{
                   
                   
//number = 1000000000;
                   
if (notional.search(/[A-Z]/i) != -1)
                    
return null;
                   
return null;
                
}
               
return number;
            
}
        
}else{
            
if (notional.search(/[A-Z]/i) != -1)
                
return null;
            
return notional;
        
}

}

function addCommas(nStr)
{

	nStr += '';

	x = nStr.split('.');

	x1 = x[0];

	x2 = x.length > 1 ? '.' + x[1] : '';

	var rgx = /(\d+)(\d{3})/;

	while (rgx.test(x1)) {
	
	x1 = x1.replace(rgx, '$1' + ',' + '$2');

	}

	return x1 + x2;

}

function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null;
    if (navigator.userAgent.indexOf("MSIE")>=0)
        { 
        var strName="Msxml2.XMLHTTP";
        if(navigator.appVersion.indexOf("MSIE 5.5")>=0)
            {
                strName="Microsoft.XMLHTTP";
            } 
        try
            { 
                objXmlHttp=new ActiveXObject(strName);
                objXmlHttp.onreadystatechange=handler;
                return objXmlHttp;
            } 
        catch(e)
            { 
                alert("Error. Scripting for ActiveX might be disabled");
                return;
            } 
    } 
    if (navigator.userAgent.indexOf("Mozilla")>=0)
        {
        objXmlHttp=new XMLHttpRequest();
        objXmlHttp.onload=handler;
        objXmlHttp.onerror=handler;
        return objXmlHttp;
    }
} 



function GetRMBranch()
{
		
		if (document.getElementById('txtbranchecode').value != "")
		{
		var  id= document.getElementById('txtbranchecode').value
        var url="AjaxTransCert.aspx?BranchCode=" + id +"&rnd="+MathRandom();
        xmlHttp=GetXmlHttpObject(stateChanged);
        xmlHttp.open("GET", url , true);
        xmlHttp.send(null);
        }
        else
        {
        document.getElementById("lblbrnachename").innerHTML = "";
        }
} 


function stateChanged() 
{ 
	document.getElementById('lblError').innerHTML = "";
	var codeArray;
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {
           var str=xmlHttp.responseText;
           codeArray = str.split('+');          
           if(codeArray[0] != "")
           {
				document.getElementById('lblbrnachename').innerText=codeArray[0];				
           }	
           else
           {
			document.getElementById('lblbrnachename').innerText = "";
			document.getElementById('lblError').innerHTML = "Branche id is not vaild";			
           }			
           	//alert(codeArray[1]);
           //if(codeArray[1] != "")
           //{
		     //	document.getElementById('lblError').innerHTML = codeArray[1];
           //}
           //else
           //{
			//document.getElementById('lblError').innerHTML = "";
           //}
        }
} 

function GetActype3()
{

		var  id=document.getElementById('txtCrPayouno').value
        var url="AjaxTransCert.aspx?AcType=" + id +"&rnd="+MathRandom();
        xmlHttp=GetXmlHttpObject(AcType3stateChanged);
        xmlHttp.open("GET", url , true);
        xmlHttp.send(null);
} 
      

function AcType3stateChanged() 
{ 
document.getElementById('lblError').innerHTML = "";
document.getElementById('btnsetValue').disabled = false; 
//document.getElementById('btnTrans').disabled = false;  18MAY

var codeArray;
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
      var str=xmlHttp.responseText;     
     codeArray = str.split('+'); 
     str = codeArray[0];
    if (str == "")
    {
		document.getElementById('lblError').innerText="Please enter valid payout account number";
		document.getElementById('btnsetValue').disabled = true;
		//document.getElementById('btnTrans').disabled = true; 
    }
    else if (str == "N")
    {
		if (document.getElementById('txtHChkBestCbo').value != 'True')
        {
		document.getElementById('lblError').innerText="";
		}
		document.getElementById('hdnAcType3').value=document.getElementById('drpCrPayoutType').value
    }
    else
    {
		if (document.getElementById('txtHChkBestCbo').value != 'True')
        {
		document.getElementById('lblError').innerText="";
		}
		document.getElementById('drpCrPayoutType').value=str;
		document.getElementById('hdnAcType3').value=str;
    }
    }
    
} 


function GetActype4()
{

		var  id=document.getElementById('txtprncaccno').value
        var url="AjaxTransCert.aspx?AcType=" + id +"&rnd="+MathRandom();
        xmlHttp=GetXmlHttpObject(AcType4stateChanged);
        xmlHttp.open("GET", url , true);
        xmlHttp.send(null);
} 
      

function AcType4stateChanged() 
{ 
document.getElementById('lblError').innerHTML = "";
document.getElementById('btnsetValue').disabled = false; 
//document.getElementById('btnTrans').disabled = false;  //18MAY

var codeArray;
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
      var str=xmlHttp.responseText;     
     codeArray = str.split('+'); 
     str = codeArray[0];
    if (str == "")
    {
		document.getElementById('lblError').innerText="Please enter valid payout account number";
		document.getElementById('btnsetValue').disabled = true;
		//document.getElementById('btnTrans').disabled = true; MAY 18
    }
    else if (str == "N")
    {
		if (document.getElementById('txtHChkBestCbo').value != 'True')
        {
		document.getElementById('lblError').innerText="";
		}
		document.getElementById('hdnAcType3').value=document.getElementById('drpPracctype').value
    }
    else
    {
		if (document.getElementById('txtHChkBestCbo').value != 'True')
        {
		document.getElementById('lblError').innerText="";
		}
		document.getElementById('drpPracctype').value=str;
		document.getElementById('hdnAcType3').value=str;
    }
    }
    
} 

//Added by Snehal on 11-Jan-2011
function ValidateCustAccId()
{
	var  CustId=document.getElementById('txtCusID').value
	var  ProductId=document.getElementById('lblPid').innerText
    var url="AjaxTransCert.aspx?CustomerId=" + CustId +"&ProductId=" + ProductId +"&rnd="+MathRandom();
    xmlHttp=GetXmlHttpObject(CustIdStateChanged);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
}

function CustIdStateChanged()
{
	document.getElementById('lblError').innerHTML = "";
	var codeArray;
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
           var str=xmlHttp.responseText;
           codeArray = str.split('+'); 
		   str = codeArray[0];
           if(str == "")
           {
				document.getElementById('lblError').innerHTML = "Please assign MAN/SCA number to customer " + document.getElementById('lblCusName').innerText;	
				document.getElementById('btnsetValue').disabled = true;
				return false;
           }	
           else
           {
				ClsRow();		
           }			
    }
}
//End