/*******************************************************************************************/
// Populate data to dataArray array
function TypesFields(p_Type, p1, p2, p3, p4, p5, p6, p7, p8, p9) {
	this.Feeder = p1; 
	this.ExchangeID = p2; 
	this.PortfolioType = p3; 
	this.TypeID = p4;
	this.WhatType = p5;
	this.TypeName_EN = p6;
	this.TypeName_HE = p7;
	this.InstrumentID = p8;
	this.IndexMode = p9;
}
/*******************************************************************************************/
function emptyCombo(oCombo) {
	// Empty types combo
	oCombo.selectedIndex = 0;	
	while (oCombo.length > 1) {
		oCombo.options[1] = null;
	}	
}
/*******************************************************************************************/
function populateCombo(Feeder, PortfolioType, Lang, TypeID, bFromPortfolio) {
	var oCombo = document.frmSearch.cboTypes;
	emptyCombo(oCombo);
	oCombo.options[0] = (sLang == "HE") ? new Option("--- הכל ---", -1) : new Option("--- All ---", -1);
	oCombo.selectedIndex = 0;	

	var bState = false;
	var idx = 1;
	
	for (var i = 0; i < typesArray.length; i++) {
		if(typesArray[i].Feeder == Feeder) {
			oCombo.options[idx] = (sLang == "HE") ? new Option(typesArray[i].TypeName_HE, i) : new Option(typesArray[i].TypeName_EN, i);
			if (typesArray[i].TypeID == TypeID) oCombo.selectedIndex = idx;
			idx++;
		}
	}
}
/*******************************************************************************************/
function PopulateExchangesCombo(Feeder, PortfolioType, ExchangeID, Lang) {
	// Populate types combo	
	if (exchangesArray) {
		EmptyCombo(window.cboExchanges);
		idx = 0;	
		PortfolioType = parseInt(PortfolioType)
		for (var i = 0; i < exchangesArray.length; i++) {
			if (isNaN(PortfolioType) || (Feeder == exchangesArray[i].Feeder)) {
				if (Lang == "EN")
					window.cboExchanges.options[idx] = new Option(exchangesArray[i].ExchangeName_EN, i)
				else
					window.cboExchanges.options[idx] = new Option(exchangesArray[i].ExchangeName_HE, i);		                      
			
				if (exchangesArray[i].ExchangeID == ExchangeID)
					window.cboExchanges.selectedIndex = idx;	
				idx = idx + 1;	
			}		
		}
	}	
}
//added by Elina
/*******************************************************************************************/
function addInstrument1(instrumentID, name, symbol, feeder, portfolioID) { 
	var iPortfolioID = (""+portfolioID != "undefined") ? portfolioID : "";
//	var sURL = 'http://localhost/GlobesSites/Globes/Portfolio/Portfolio/AddInstrument.aspx?InstrumentID=' + instrumentID + 
//			   '&name=' + name + '&ticker=' + symbol + '&feeder=' + feeder + 
//			   '&portfolioID=' + iPortfolioID
	var sURL = '/GlobesSites/Globes/Portfolio/Portfolio/ContentManager.aspx?popup_id=buysale&Instrument_id=' + instrumentID + 
			   '&nameheb=' + escape(name)+ '&feeder=' + feeder + '&backTo=newPortfolio'

	var sParams = 'location=no,toolbar=no,menubar=no,status=yes,scrollbar=yes, resizable , width=475,height=420, left=' + 
			  	  (screen.width-350)/2 + ',top=' + (screen.height-220)/2
	var win = window.open(sURL, 'addInstrument', sParams);
}

/*******************************************************************************************/
function addInstrument(instrumentID, name, symbol, feeder, portfolioID) {
	var iPortfolioID = (""+portfolioID != "undefined") ? portfolioID : "";
	var sURL = '/Finance/Portfolio/AddInstrumentOutside.asp?InstrumentID=' + instrumentID + 
			   '&name=' + name + '&ticker=' + symbol + '&feeder=' + feeder + 
			   '&portfolioID=' + iPortfolioID
	var sParams = 'toolbar=no, width=350, height=220, status=no, scrollbars=yes, resizable=yes, left=' + 
			  	  (screen.width-350)/2 + ',top=' + (screen.height-220)/2
	var win = window.open(sURL, 'addInstrument', sParams);
}

/*******************************************************************************************/
function SearchData(oCombo) {try {
	function getElementsByName(name) {try {
		var a = document.getElementsByName(name)
		if (a.length == 0) {a[0] = new Object()}
		return a
	} catch(ex) {alert("elementsByName(" + name + ")")}}
	if (((oCombo.options[oCombo.selectedIndex].value != -1) && (iSearchIdxInst == 1)) || 
	   (((oCombo.options[oCombo.selectedIndex].value != -1) || (getElementsByName("name_or_symbol")[0].value != "")) && (iSearchIdxInst == 0))) {
		if (oCombo.options[oCombo.selectedIndex].value != -1) {
			var idx = oCombo.options[oCombo.selectedIndex].value;
			getElementsByName("TypeID")[0].value = typesArray[idx].TypeID;
			getElementsByName("WhatType")[0].value = typesArray[idx].WhatType;	
			getElementsByName("IdxInstrumentID")[0].value = typesArray[idx].InstrumentID;	
		}
		else {
			getElementsByName("TypeID")[0].value = "";
			getElementsByName("WhatType")[0].value = "";	
			getElementsByName("IdxInstrumentID")[0].value = "";	
		}
		getElementsByName("strToSearch")[0].value = (iSearchIdxInst == 0) ? document.getElementsByName("name_or_symbol")[0].value : "";
		getElementsByName("SearchIdxInst")[0].value = iSearchIdxInst;
		getElementsByName("DataPayed")[0].value = "";
		getElementsByName("Field")[0].value = 3;
		getElementsByName("Direction")[0].value = 1;
		getElementsByName("NumPage")[0].value = 1;
		getElementsByName("frmSearch")[0].submit();
	}
	else {
		if (iSearchIdxInst == 0) {
			if (sLang == "HE")
				alert("בחר(י) סוג נייר ערך או שם חברה/סימול")
			else	
				alert("Select Group or Paper Name/Symbol")
		}		
	}	
}catch(ex) {alert('searchdata\n' + ex.description)}}
/*******************************************************************************************/
function GoToPage(NumPage) {
	window.frmSearch.DataPayed.value = DataPayed;
	window.frmSearch.NumPage.value = NumPage;
	window.frmSearch.submit();
}
/*******************************************************************************************/
function SortList(Field, Direction) {
	document.frmSearch.DataPayed.value = DataPayed;
	document.frmSearch.Field.value = Field;
	document.frmSearch.Direction.value = Direction;
	document.frmSearch.NumPage.value = 1;
	document.frmSearch.submit();
}
/*******************************************************************************************/
function RefreshList() {
	window.frmSearch.DataPayed.value = "yes";
	window.frmSearch.submit();
}
/*******************************************************************************************/
function ChangeLang(lang) {
	window.frmSearch.Lang.value = lang; 
	window.frmSearch.submit();
}
/*******************************************************************************************/

function ViewPage3(page, width, height) {
	window.open(page, 'PopUp4', 'location=no,toolbar=no,menubar=no,status=no,width=' + width + ',height=' + height +',scrollbars=no,resizable=yes,left=' + (screen.width-width)/2 + ',top=0' );
}
function ViewPage2(page, width, height) {
	window.open(page, 'PopUp4', 'location=no,toolbar=no,menubar=no,status=yes,width=' + width + ',height=' + height +',scrollbars=yes,resizable=yes,left=' + (screen.width-width)/2 + ',top=0' );
}
function ViewPage(page, width, height) {
	PopUp = window.open(page, 'PopUp', 'location=no,toolbar=no,menubar=no,status=yes,width=' + width + ',height=' + height +',scrollbars=yes,resizable=yes,left=' + (screen.width-width)/2 + ',top=' + (screen.height-height)/2);
} 
function LS(letter) {

	if(window.document.frmSearch.Lang.value == 'EN')
	{
			document.getElementById("name_or_symbol").value = letter
			var oSelectObj = document.getElementById("cboTypes")
			if (oSelectObj.length > 0) {SearchData(oSelectObj)}
			else 
			{
				alert("Please wait for the page to load");
				//document.location.reload();
			}
			//g.header.menu.search.finance(g)
	}
	else
	{
		try {	
			
		/*	var sWhere = 'ta'
			if(querystring("id") != "")
			{
				var sID = querystring("id");
				if(sID == 4)sWhere = 'ny'
			}
			getSearch_TA_NY(g,sWhere,letter);
		*/
			getSearch_all(g, letter);

		} catch(e) {
		/*
			var oSelectObj = document.getElementById("cboTypes")
			if (oSelectObj.length > 0) {SearchData(oSelectObj)}
			else 
			{
				alert("Please wait for the page to load");
				document.location.reload();
			}
		*/
		}
	}
}

function querystring(key) {
				var b = location.href.replace(/\?/,"&").toLowerCase().indexOf("&" + key + "=")
				if (b < 0) {return ''}
				b += key.length + 2
				var e = location.href.indexOf("&",b)
				return location.href.substring(b,(e < b) ? location.href.length : e)
			}

function getSearch_TA_NY(g,iSearchID,letter)
{
		var query = letter;
		var cboType = selected_value("cboTypes")
		var newPortfolio = (self.location.href.toLowerCase().indexOf("globessites")>=0 || self.location.href.toLowerCase().indexOf("newportfolio=1")>0) ? 1 : 0
		location.href= g.url.fs + '/SearchResults.asp?t=' + (new Date().getTime() % 10000)
			+ '&strToSearch=' + escape(query)
			+ '&SearchIdxInst=0'
			+ '&Lang=HE'
			+ '&Field=3'
			+ '&Direction=1'
			+ '&WhatType=' + ((cboType > -1) ? g.header.menu.select_types[cboType].WhatType : "")
			+ '&TypeID=' + ((cboType > -1) ? g.header.menu.select_types[cboType].TypeID : "")
			+ '&NumPage=1'
			+ '&Feeder=' + ((iSearchID == 'ny') ? 1 : 0)
			+ '&WhatToSearch=' + query
			+ '&cboTypes=-' + cboType
			+ '&newPortfolio='+ newPortfolio
			+ '&id=' + ((iSearchID == 'ny') ? 4 : 3)

}
function getSearch_all(g,letter)
{
		var query = letter;
		location.href= g.url.fs + '/SearchResults.asp?t=' + (new Date().getTime() % 10000)
			+ '&strToSearch=' + escape(query)
			+ '&SearchIdxInst=0'
			+ '&Lang=HE'
			+ '&Field=3'
			+ '&Direction=1'
			+ '&WhatType=' +  querystring("whattype")
			+ '&TypeID=' + querystring("typeid")
			+ '&NumPage=1'
			+ '&Feeder=' + querystring("feeder")
			+ '&WhatToSearch=' + query
			+ '&newPortfolio=1'//+ newPortfolio
			+ '&id=' + querystring("id")

}

	
function LettersSearch(lang) {
	var letters;
	var desc;
	if (lang == "HE") {
		letters = "אבגדהוזחטיכלמנסעפצקרשת"
		desc = "<span dir='rtl' class='activePage6' style='font-weight:bold'>לניירות ערך נוספים בתחום:&nbsp;&nbsp;</span>"		
	}
	else {
			
		letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		//letters = "ZYXWVUTSRQPONMLKJIHGFEDCBA"
		desc = ""
	}
	var typeid = querystring("typeid")

	
	var strLetters = desc + "<span dir='rtl'>";
	for (var i = 0; i < letters.length; i++) {
		strLetters = strLetters + "<A href='javascript:LS(\"" + letters.charAt(i) + "\")' class=activePage6 style='text-decoration: none;'>" + letters.charAt(i) + "</A>&nbsp;&nbsp;"
	}
	strLetters = strLetters  + "</span>"

	try {
		document.getElementById("letters").innerHTML = strLetters;
	} catch (e) {}
}
