var tipTimer
function instrument_td_mouse_out(td) {

//	if(!td){	var td = window.event.srcElement;}
	//var td = obj
	td.style.backgroundColor = td.style_backgroundColor
	td.style.color="#000000"
}

//on mouse over
function instrument_td_mouse_over(td) {
//	if(!td){var td = window.event.srcElement;}
	//var td = obj
	td.style_backgroundColor = td.style.backgroundColor
	td.style.backgroundColor="#CC0000"
	td.style.color="#ffffff"
}



function instrument_menu_hider(e,d,mtl) {
	//var dtl = new c_coordinates(d)
	var dtl = new c_topleft(d,0,0)
	var dl = dtl.left
	var dr = dl + d.clientWidth
	var dt = dtl.top
	var db = dt + d.clientHeight
//	alert("t: " + dt + " " + mtl.top + " " + db + "  "  + d.clientHeight)
	if (mtl.top <= dt || db <= mtl.top) {
//		alert("t: " + dt + " " + mtl.top + " " + db)
		d.style.visibility = 'hidden'
//		alert(db +","+mtl.top)

	}
	if (mtl.left < dl || dr <= mtl.left) {
//		alert("in l: " + dl + " " + mtl.left + " " + dr)
		d.style.visibility = 'hidden'
	}
}
function c_topleft(e,l,t,d) {
	this.left = l
	this.top = t
	while(e.offsetParent) {
	//	if (true == d) {trace.dmp(e.tagName + " " + e.offsetLeft + " " + e.offsetTop)}
		this.top += e.offsetTop
		this.left += e.offsetLeft
		e = e.offsetParent
	}
	if (e.x) {left += e.x; }
	if (e.y) {top += e.y}
}
function c_coordinates(caller, e) { 
	this.left = 0
	this.top = 0
	while(caller.offsetParent != null) {
		this.left += caller.offsetLeft
		this.top += caller.offsetTop
		caller = caller.offsetParent
	}
}
function showmenuie5(e ,param1_val,param2_val,param3_val,menu_name, symbol_val,lang){
	
	param1=param1_val
	param2=param2_val
	param3=param3_val
	symbol = symbol_val
	
	if (lang == "HE") document.getElementById("commands_instrumentname").innerHTML = "&nbsp;&nbsp;" + param3 + "&nbsp;&nbsp;"
	if (lang == "EN") document.getElementById("commands_instrumentname_EN").innerHTML = "&nbsp;&nbsp;" + param3 + "&nbsp;&nbsp;"

	window.clearTimeout(tipTimer)
	var targ;
	if (!e) var e = window.event

	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
		
		
	var caller_image;


	var vertical_overlapping = 2
	var horizontal_overlapping = 2	
	var topleft = new c_topleft(targ,0,0)
	var menu=document.getElementById(menu_name);
	
	menu.style.top=topleft.top
	menu.style.left=topleft.left -2
/*
	if(document.body.offsetWidth < (topleft.left + menu.clientWidth))
		menu.style.left= topleft.left - menu.clientWidth +15
		
	if (e.clientY < menu.clientHeight ) {
		menu.style.top = topleft.top + menu.clientHeight -10
		}
	else{
		menu.style.top = topleft.top -2
		}
*/		

	var m = menu
	m.caller = targ
	//e.instrument = instrument
	
	m.style.top = (parseInt(m.style.top.replace(/px$/,""),10) - m.clientHeight + targ.clientHeight + vertical_overlapping) + 'px'
	
	m.onmouseout = function(e) {
			if (!e) var e = window.event
			var src
			if (e.target) src = e.target
			else if (e.srcElement)  src = e.srcElement
			if (src.nodeType == 3) // defeat Safari bug
				src = src.parentNode
			

		if(e.offsetY)
			var mtl = new c_topleft(src, e.offsetX, e.offsetY)
		else 
			var mtl = new c_coordinates(src)// new c_topleft(src, 0,0)
//alert("top:" + mtl.top+ "  left:"+ mtl.left )
			while (src.tagName != "DIV") {
				if(src.parentElement)src = src.parentElement
				else if (src.parentNode) src = src.parentNode				
				}
			instrument_menu_hider(e,src,mtl)//(mtl,src)
		//	instrument_menu_hider1(e,src)
		}
		
	targ.onmouseout = function(e) {
			if (!e) var e = window.event
			if(e.offsetX)
				var mtl = new c_topleft( targ, e.offsetX, e.offsetY)
			 else
				var mtl = new c_coordinates(targ)
//			alert("top:" + mtl.top+ "  left:"+ mtl.left )

			if(e.tagName == "TD" ) {
				if(e.parentElement) e=e.parentElement
				else if(e.parentNode) e = e.parentNode
				}
			var d =menu
			instrument_menu_hider(e,d,mtl)//(mtl,d)
		//	instrument_menu_hider1(e,d)
		}

	menu.style.visibility="visible"

	//tipTimer=window.setTimeout("hidemenuie5('"+menu_name+"')",5000);
	return false

}
function instrument_clicked_EN(obj){
		var instrument_id = param1
		var feeder =  param2
		var name=param3		
		var symbol_local = symbol			

		var command
		if(obj.command) command = obj.command
		else {
			return;
		}	

		switch(command){
			case "instView": 			
					var url = "/Finance/Instrument/Instrument.asp?InstrumentID=" + instrument_id + "&Feeder=1&Lang=HE&Tab=1"
					document.location.href = url
				    break;
				   		
			case "instGraf": 					
					var url = "/Finance/Instrument/Instrument.asp?InstrumentID=" + instrument_id + "&Feeder=1&Lang=HE&Tab=2"
					document.location.href = url
				    break;
				    
			case "instNews": 					
					var url = "/Finance/Instrument/Instrument.asp?InstrumentID=" + instrument_id + "&Feeder=1&Lang=HE&Tab=4"
					document.location.href = url
				    break;    				    
			
			case "AddToPortfolio": 
					////var sURL = '/Finance/Portfolio/AddInstrumentOutside.asp?InstrumentID=' + instrument_id + 
					//			'&ticker=' + symbol + '&feeder=1'
					//var sURL = "/globessites/globes/Portfolio/Portfolio/ContentManager.aspx?popup_id=search&back=/globessites/globes/Portfolio/Portfolio/Portfolio.aspx"		
					//var sParams = "location=no,toolbar=no,menubar=no,status=yes,scrollbar=no, resizable=no, width=475,height=420"
					//var win = window.open(sURL, 'addInstrument', sParams);
					addInstrument_new(instrument_id,name,symbol_local,feeder);
				    break;				
			}	
}
function instrument_clicked(obj) {
		var instrument_id = param1
		var feeder =  param2
		var name=param3		
		var symbol_local = symbol			

		var command
		if(obj.command) command = obj.command
		else {
			return;
		}	

		switch(command){
			case "instView": 			
					var url = "/Finance/Instrument/Instrument.asp?InstrumentID=" + instrument_id + "&Feeder=0&Lang=HE&Tab=1"
					document.location.href = url
				    break;
				   		
			case "instGraf": 					
					var url = "/Finance/Instrument/Instrument.asp?InstrumentID=" + instrument_id + "&Feeder=0&Lang=HE&Tab=2"
					document.location.href = url
				    break;
				    
			case "instNews": 					
					var url = "/Finance/Instrument/Instrument.asp?InstrumentID=" + instrument_id + "&Feeder=0&Lang=HE&Tab=4"
					document.location.href = url
				    break;    
				    
			case "instRealtime": 					
					var url = "/Finance/Instrument/Instrument.asp?InstrumentID=" + instrument_id + "&Feeder=0&Lang=HE&Tab=1&rt=1"		
					document.location.href = url
				    break;			
				    ///serve/newstracker/form.asp?add=5201&from=1000169120&instrumentID=3721
			case "newstracker": 
					var url = "/serve/newstracker/form.asp?instrumentID=" + instrument_id
					document.location.href = url
				    break;				
			case "alerts": 
					var url = "/globessites/globes/alerts/alerts.aspx?Mode=Stock"
					document.location.href = url
				    break;				
			case "AddToPortfolio": 
					//var sURL = '/Finance/Portfolio/AddInstrumentOutside.asp?InstrumentID=' + instrument_id + 
						//		'&ticker=' + symbol + '&feeder=0'
					//var sURL = "/globessites/globes/Portfolio/Portfolio/ContentManager.aspx?popup_id=search&back=/globessites/globes/Portfolio/Portfolio/Portfolio.aspx"
					//var sParams = "location=no,toolbar=no,menubar=no,status=yes,scrollbar=no, resizable=no, width=475,height=420"
					//var win = window.open(sURL, 'addInstrument', sParams);
					addInstrument_new(instrument_id,escape(name),symbol_local,feeder)
				    break;	
			case "bank":			
				var url = "/Finance/Banks/BanksInstruments.asp?";				
				window.open( url + "&Instrument_ID=" + instrument_id							
							+ "&symbol=" + symbol_local ,"", "location=no,toolbar=no,menubar=no,status=yes,scrollbar=no, resizable=no, width=475,height=420")		
				break;			
			}	
}
