function f000000002ACOI_JS(result)
{
	if(result.error != null)
	{
		alert(result.error);
		return;
	}
	
	document.getElementById("f000000002ACOI").innerHTML = result.value;
	
	var selBuySell = document.getElementById("SessionVariable0000-00001G-SVI");
	var divFundList = document.getElementById("fundList");
	var divCustomerFundList = document.getElementById("customerFundList");
	
	if(selBuySell.options[selBuySell.selectedIndex].value == "A")
	{
		divFundList.style.display = "";
		divCustomerFundList.style.display = "none";
	}
	else
	{
		divFundList.style.display = "none";
		divCustomerFundList.style.display = "";
	}
}


function f0000000028COI_JS(result)
{
	if(result.error != null)
	{
	alert(result.error);
	return;
	}
	document.getElementById("f0000000028COI").innerHTML = result.value;
}

function getFundInfo()
{
	var tmpXmlObj = new ActiveXObject("MSXML.DOMDocument");
	var selFundList = document.getElementById("SessionVariable0000-00001F-SVI");
	var selBuySell = document.getElementById("SessionVariable0000-00001G-SVI");
	var txtFundQuantity = document.getElementById("SessionVariable0000-00001H-SVI");
	var txtFundPrice = document.getElementById("SessionVariable0000-00001T-SVI");
	var txtFundAmount = document.getElementById("SessionVariable0000-00001I-SVI");
	var txtMinShare= document.getElementById("txtMinShare");
	
	var tdFundBuyPrice = document.getElementById("tdFundBuyPrice");
	var tdFundSellPrice = document.getElementById("tdFundSellPrice");
	
	if(selFundList.options[selFundList.selectedIndex].value != "0")
	{
		clearAjaxParameters();
		addParameterToXml("SessionVariable0000-00001F-SVI",selFundList.options[selFundList.selectedIndex].value);
		addParameterToXml("SessionVariable0000-00001G-SVI",selBuySell.options[selBuySell.selectedIndex].value);

		if (!tmpXmlObj.loadXML(GtpCmsWeb.Default.FuncExecuteAjaxObjectWithParameters('GTPCMS_AFE_GET_FUND_INFO_BY_FUND_ID','FundInfo',xmlObj.xml).value)) 
		{
			alert("Xml Hatasi: " + tmpXmlObj.parseError.reason);
			return;
		}
		
		//alert(tmpXmlObj.xml);
		var xmlNodeList = tmpXmlObj.documentElement.selectSingleNode("List");
		if (xmlNodeList.childNodes.length>0)
		{
			tdFundBuyPrice.innerHTML = tmpXmlObj.selectSingleNode("NewDataSet/List/AlisFiyati").text;
			tdFundSellPrice.innerHTML = tmpXmlObj.selectSingleNode("NewDataSet/List/SatisFiyati").text;
			txtFundQuantity.value = parseInt(tmpXmlObj.selectSingleNode("NewDataSet/List/MinPay").text);
			txtMinShare.value = tmpXmlObj.selectSingleNode("NewDataSet/List/MinPay").text;
			
			
			if(selBuySell.options[selBuySell.selectedIndex].value =="S")  
			{
				
				txtFundPrice.value = tmpXmlObj.selectSingleNode("NewDataSet/List/SatisFiyati").text;
				var fundCode = selFundList.options[selFundList.selectedIndex].value;
				var selCustomerAvailableFundStock = document.getElementById("customerAvailableFundStock");
				
				for(i=0;i<selCustomerAvailableFundStock.options.length;i++)
				{
					if(selCustomerAvailableFundStock.options[i].value == fundCode)
					{ 
						txtFundQuantity.value = parseFloat(selCustomerAvailableFundStock.options[i].text);
					}
				}
			}
			else	
			{
				txtFundPrice.value = tmpXmlObj.selectSingleNode("NewDataSet/List/AlisFiyati").text;
			}
		}


		txtFundAmount.value = (parseFloat(txtFundPrice.value) * parseFloat(txtFundQuantity.value)).toFixed(2);
				
		var tmpXmlObj = null;
	}
	else
	{
		tdFundBuyPrice.innerHTML = "";
		tdFundSellPrice.innerHTML = "";
		txtFundQuantity.value = "0";
		txtFundPrice.value = "0"
		txtFundAmount.value = "0";
		txtMinShare.value = "0";
		return;
	}
}

function fillFundCombo()
{
	clearAjaxParameters();
	var selFundList = document.getElementById("SessionVariable0000-00001F-SVI");
	var selBuySell = document.getElementById("SessionVariable0000-00001G-SVI");
	var txtFundQuantity = document.getElementById("SessionVariable0000-00001H-SVI");
	var tdFundBuyPrice = document.getElementById("tdFundBuyPrice");
	var tdFundSellPrice = document.getElementById("tdFundSellPrice");

	var tmpXmlObj = new ActiveXObject("MSXML.DOMDocument");
	var nodeListName = "List";
	
	if(selBuySell.options[selBuySell.selectedIndex].value =="S") 
	{
		if (!tmpXmlObj.loadXML(GtpCmsWeb.Default.FuncExecuteAjaxObjectWithParameters('GTPCMS_AFE_GET_CUSTOMER_AVAILABLE_FUND_STOCK','FundList [Customer Available Fund Stock as Xml]',xmlObj.xml).value)) 
		{
			alert("Xml Hatasi: " + tmpXmlObj.parseError.reason);
			return;
		}
		
		var xmlNodeList = tmpXmlObj.documentElement.selectNodes(nodeListName);	
		var selCustomerAvailableFundStock = document.getElementById("customerAvailableFundStock");
		
		for(i=0;i<selCustomerAvailableFundStock.options.length;i++)
		{
			selCustomerAvailableFundStock.options[i] = null;
			i=-1;
		}
		
		for(i=0;i<xmlNodeList.length;i++)
		{
			var xmlNode = xmlNodeList[i];
			var fundCode = xmlNode.childNodes[0].text;
			var quantity = xmlNode.childNodes[2].text;
			selCustomerAvailableFundStock.options[selCustomerAvailableFundStock.options.length] = new Option(quantity,fundCode);
		}
	}
	else
	{
		if (!tmpXmlObj.loadXML(GtpCmsWeb.Default.FuncExecuteAjaxObjectWithParameters('GTPCMS_AFE_GET_FUND_LIST','FundList [GetAllFundsBySessionVariableId as Xml]',xmlObj.xml).value)) 
		{
			alert("Xml Hatasi: " + tmpXmlObj.parseError.reason);
			return;
		}
		nodeListName = "List1";
	}
	
	for(i=0;i<selFundList.options.length;i++)
	{
		selFundList.options[i] = null;
		i=-1;
	}

	selFundList.options[selFundList.options.length] = new Option("Seciniz","0");
	
	var xmlNodeList = tmpXmlObj.documentElement.selectNodes(nodeListName);

	for(i=0;i<xmlNodeList.length;i++)
	{
		var xmlNode = xmlNodeList[i];
		var fundCode = xmlNode.childNodes[0].text;
		var fundName = xmlNode.childNodes[1].text;
		selFundList.options[selFundList.options.length] = new Option(fundName,fundCode);
	}
	
	tdFundBuyPrice.innerHTML = "";
	tdFundSellPrice.innerHTML = "";
	txtFundQuantity.value = "";

	var tmpXmlObj = null;
}

function frmMutualFundOrderSubmit(resultView)
{
		var selFundList = document.getElementById("SessionVariable0000-00001F-SVI");
		var selBuySell = document.getElementById("SessionVariable0000-00001G-SVI");
		var txtFundQuantity = document.getElementById("SessionVariable0000-00001H-SVI");
		var txtFundPrice = document.getElementById("SessionVariable0000-00001T-SVI");
		var txtFundAmount = document.getElementById("SessionVariable0000-00001I-SVI");
		var tblPreviewForm = document.getElementById("tblPreviewForm");
		var tblOrderForm = document.getElementById("tblOrderForm");
		var frmMutualFundOrder  = document.getElementById("frmMutualFundOrder");
		var txtPassword = document.getElementById("SessionVariable0000-00007X-SVI");
		var txtMinShare = document.getElementById("txtMinShare");
		
		var tdPreviewFundName = document.getElementById("tdPreviewFundName");
		var tdPreviewBuySell = document.getElementById("tdPreviewBuySell");
		var tdPreviewPrice = document.getElementById("tdPreviewPrice");
		var tdPreviewQuantity = document.getElementById("tdPreviewQuantity");
		var tdPreviewAmount = document.getElementById("tdPreviewAmount");
		var btnPreview = document.getElementById("btnPreview");
		var btnShowOrder = document.getElementById("btnShowOrder");
		
		if(selFundList.options[selFundList.selectedIndex].value == "0")
		{
			alert("Lutfen bir fon seciniz.")
			return;
		}

		if((txtFundQuantity.value == "0") || (txtFundQuantity.value == ""))
		{
			alert("Lutfen pay adedini giriniz.")
			return;
		}
		
		if((txtFundQuantity.value == "0") || (txtFundQuantity.value == ""))
		{
			alert("Lutfen pay adedini giriniz.")
			return;
		}
		
		if(!checkNumber(txtFundQuantity.value))
		{
			alert("Lutfen pay adedini kontrol ediniz.");
			return;
		}

		if(!checkNumber(txtFundPrice.value))
		{
			alert("Lutfen tutari kontrol ediniz.");
			return;
		}

		// Fon miktari minumum miktara gore yuvarlaniyor.
		var rnd = parseInt(txtFundQuantity.value / txtMinShare.value) * txtMinShare.value;
		txtFundQuantity.value = rnd;
		calcFundAmount();
		
		if((txtFundAmount.value == "0") || (txtFundAmount.value == ""))
		{
			alert("Lutfen tutari giriniz.")
			return;
		}
		
		if (resultView == "preview")
		{
				tblPreviewForm.style.display = "";
				tblOrderForm.style.display = "none";
				btnPreview.style.display = "none";
				btnShowOrder.style.display = "";


				tdPreviewFundName.innerHTML = selFundList.options[selFundList.selectedIndex].text;
				tdPreviewBuySell.innerHTML = selBuySell.options[selBuySell.selectedIndex].value;
				tdPreviewQuantity.innerHTML = txtFundQuantity.value;
				tdPreviewPrice.innerHTML = txtFundPrice.value;
				tdPreviewAmount.innerHTML = txtFundAmount.value;
		}
		else
		{
			if(txtPassword.value == "")
			{
				alert("Lutfen sifrenizi giriniz.");
				return;
			}
			frmMutualFundOrder.submit();
		}
}

function showOrderForm()
{
	var btnShowOrder = document.getElementById("btnShowOrder");
	var tblPreviewForm = document.getElementById("tblPreviewForm");
	var tblOrderForm = document.getElementById("tblOrderForm");
	var btnPreview = document.getElementById("btnPreview");
	
	tblPreviewForm.style.display = "none";
	btnShowOrder.style.display = "none";
	
	tblOrderForm.style.display = "";
	btnPreview.style.display = "";
}


function popUpEquityInfo(equityName)
{
	var url;
	url="default.aspx?page=I_Hisse_Detaylar&equity="+equityName;

	if(equityName=='')alert("Hisse Detayini Görüntüleyebilmek için Hisse seçimi yapmalisiniz.");
		else return PopItUpReturn(url,570,201,1)
}

function popUpTradeLimit(limitType)
{
	var url;
	url="default.aspx?page=Islem_Limiti&processType=TradeLimit&limitType="+limitType;
	if(limitType == "") limitType= "Hisse"
	return PopItUpReturn(url,340,160,1)
}

function popUpEmirDurum(reference)
{
	var url;
	url="default.aspx?page=I_Emir_Durum_Izleme&reference="+reference;
	return PopItUpReturn(url,340,50,1)
}

function getBondCalculatorResult()
{
	var basGun = document.getElementById("basGun");
	var basAy = document.getElementById("basAy");
	var basYil = document.getElementById("basYil");
	var bitGun = document.getElementById("bitGun");
	var bitAy = document.getElementById("bitAy");
	var bitYil = document.getElementById("bitYil");
	var tutar = document.getElementById("tutar").value;
	var vkg  = document.getElementById("vkg").value;
	var oran = document.getElementById("oran").value;
	
	basGun.options[basGun.selectedIndex].value;
	var tmpXmlObj = new ActiveXObject("MSXML.DOMDocument");
	
	clearAjaxParameters();
	
	addParameterToXml("basGun", basGun.options[basGun.selectedIndex].value);
	addParameterToXml("basAy", basAy.options[basAy.selectedIndex].value);
	addParameterToXml("basYil", basYil.options[basYil.selectedIndex].value);
	addParameterToXml("bitGun", bitGun.options[bitGun.selectedIndex].value);
	addParameterToXml("bitAy", bitAy.options[bitAy.selectedIndex].value);
	addParameterToXml("bitYil", bitYil.options[bitYil.selectedIndex].value);
	addParameterToXml("tutar", tutar);
	addParameterToXml("vkg", vkg);
	addParameterToXml("oran", oran);
	
	//var tmpDivSonuc = document.getElementById("tmpDvBondCalculatorResult");
	if (!tmpXmlObj.loadXML(GtpCmsWeb.Default.FuncExecuteAjaxObjectWithParameters('GET_BOND_CALCULATOR_VALUES','GetBondCalculatorValues',xmlObj.xml).value)) 
	{
		alert("Xml Hatasi: " + tmpXmlObj.parseError.reason);
		return;
	}
	alert("ok");
	var xmlNode  = tmpXmlObj.documentElement.selectSingleNode("NewDataSet/GET_BOND_CALCULATOR_VALUES");
	if(xmlNode.childNodes.length>0)
	{
		var tmpTutarSonuc = xmlNode.childNodes(0).text;
		var tmpFiyatSonuc = xmlNode.childNodes(1).text;
		var tmpOranSonuc  = xmlNode.childNodes(2).text;
		document.getElementById("tutarSonuc").value = tmpTutarSonuc;
		document.getElementById("fiyatSonuc").value = tmpFiyatSonuc;
		document.getElementById("oranSonuc").value  = tmpOranSonuc;
	}
	
	/*tmpDivSonuc.innerHTML = tmpResult;
	dvBondCalculatorResult.style.display = "none";
	tmpDivSonuc.style.display = "";*/
}


function calcFundAmount()
{
	var price = 0
	var amount = 0;
	
	var selBuySellList = document.getElementById("SessionVariable0000-00001G-SVI");
	var txtQuantity = document.getElementById("SessionVariable0000-00001H-SVI");
	var txtAmount  = document.getElementById("SessionVariable0000-00001I-SVI");
	var tdFundBuyPrice = document.getElementById("tdFundBuyPrice");
	var tdFundSellPrice = document.getElementById("tdFundSellPrice");
	
	var quantity = txtQuantity.value;
	
	if(selBuySellList.options[selBuySellList.selectedIndex].value == "S")
		price =  tdFundSellPrice.innerHTML;
	else
		price =  tdFundBuyPrice.innerHTML;
	
	if(price == "") price = 0;	
	
	amount = parseFloat(price) * parseFloat(quantity);
	if (isNaN (amount)) amount = 0;
	txtAmount.value = parseFloat(amount.toFixed(2));
}

function calcFundQuantity()
{
	var price = 0
	var amount = 0;
	
	var selBuySellList = document.getElementById("SessionVariable0000-00001G-SVI");
	var txtQuantity = document.getElementById("SessionVariable0000-00001H-SVI");
	var txtAmount  = document.getElementById("SessionVariable0000-00001I-SVI");
	var tdFundBuyPrice = document.getElementById("tdFundBuyPrice");
	var tdFundSellPrice = document.getElementById("tdFundSellPrice");
	
	var amount = txtAmount.value;
	
	if(selBuySellList.options[selBuySellList.selectedIndex].value == "S")
		price =  tdFundSellPrice.innerHTML;
	else
		price =  tdFundBuyPrice.innerHTML;
	
	if(price == "") price = 0;	
	
	quantity= parseFloat(amount) / parseFloat(price);
	if (isNaN (quantity)) quantity = 0;
	txtQuantity.value = parseFloat(quantity.toFixed(0));
}
