﻿var timeoutID             = null;
var ssDropDown            = new ssDropDown();
ssDropDown.source='iip_up_upload';
ssDropDown.dropDownID     	= "ssStockSearch";
ssDropDown.typeID         	= 6;
ssDropDown.showNameOnSelect  	= false;
ssDropDown.onItemSelected 	= IipUpSearchComplete;
var IipUpSearchType = "listsearch";
var IipObjRow 		  = null;


function IipUpUploadSaveClick() 
{
	TabsUpdateCurrent(GetControlParameters("TabControlLevel1", "SAVE"),true);
}

function IipUpStockSearch(sender)
{
	IipObjRow = sender.parentNode.parentNode.parentNode;
	ssDropDown.searchStringID = sender.id;
}

function IipUpSearchComplete(type, search, name, stockid) 
{
	document.getElementById(ssDropDown.searchStringID).value = unescape(search);
	document.getElementById("Row_StockID"+IipObjRow.id).value = unescape(stockid);
	var cb = document.getElementById("Row_StockID"+IipObjRow.id);

	IipObjRow.className = "RowColorPos";
	IipGetStockInfo(stockid);
	if(unescape(stockid)!='')
	{
		cb.disabled = false;
		cb.checked = true;
	}
	else
	{
		cb.disabled = true;
		cb.checked = false;
	}
}

function IipUpSearchStockOnBlur(sender)
{
	if (document.getElementById(ssDropDown.searchStringID).value =="")
	{
		var cb = document.getElementById("AddRow_StockID"+IipObjRow.id);

		cb.checked = false;
		cb.disabled = true;

		IipObjRow.className = "RowColorNeg";
		var cells = IipObjRow.cells;

		//cells[0].innerHTML = '&nbsp;';
	
		for (var i=2; i<cells.length-1; i++) //cells
		{
			cells[i].innerHTML = '&nbsp;';	
		}	
		cells[6].title = '';
	}	
}

function IipGetStockInfo(StockID) 
{
	SSService.GetStockInfo(StockID,61,"|",IipUpdateStockInfo_CallBack);
}

function IipUpdateStockInfo_CallBack(response) 
{		
	if (response.error != null) return; 
	if (!IipObjRow) return;
	var data = response.value;  
	if (data == null) return;
	var arr = data.split("|");

	var cells = IipObjRow.cells;
	//cells[0].innerHTML = arr[0];
	for (var i=2; i<cells.length-1; i++) //cells
	{
		if(arr[i-1]=='')
			cells[i].innerHTML = '&nbsp;';	
		else
			cells[i].innerHTML = arr[i-1];	
	}
	cells[6].title = arr[6];
}

function IipUpdateStartAdvSearch(index, value, isSingleSearch){
    if (isSingleSearch == undefined || isSingleSearch ==false) {
		IipObjRow = document.getElementById("Row_SearchName" + index).parentNode.parentNode.parentNode;
		ssDropDown.searchStringID = "Row_SearchName" + index;
		ShowDialog('iip_user_portfolio_stock_search', GetControlParameters('iip_user_portfolio_details') + 'GridIndexParams=' + index + '&tbSearch=' + value, null, null, 750);
		IipUpSearchType = "listsearch";
	} else {
		var elem = document.getElementById("Symbol");
		ShowDialog('iip_user_portfolio_stock_search', GetControlParameters('iip_user_portfolio_details') + '&GridIndexParams=0'  + '&tbSearch=' + elem.value, null, null, 750);
		IipUp_stockSearch.searchStringID = "Symbol";
		IipUpSearchType = "stocksearch";
	}
}

function IipUpdateStartAdvSearchSelected(index, value, stock_id) {
    if (confirm('Do you realy want to select '+value)) {
        Dialog.hide();
        if (IipUpSearchType == "listsearch") {
            IipUpSearchComplete(ssDropDown.typeID, value, "", stock_id);
        } else {
            IipUp_StockSearchRenderItem(IipUp_stockSearch.typeID, value, "");

        }
    }
}








































//