﻿
     function addSymbol2PO(el,sy)
     {
        addSymbol2PO(el,sy,true)
     }
     
     function addSymbol2WL(el,sy)
     {
        addSymbol2WL(el,sy,true)
     }
     
     function addSymbol2AL(el,sy)
     {
        addSymbol2AL(el,sy,true)
     }
       
     function addSymbol2PO(el,sy,hide)
     {           
        fillDiv("/UsersUtils/mkPOMenu.ashx",sy,el);
        if (hide)
            el.style.display = "none";
     }
     
     function addSymbol2WL(el,sy,hide)
     {    
        fillDiv("/UsersUtils/mkWLMenu.ashx",sy,el);
        if (hide) 
            el.style.display = "none";
     }
     
     function addSymbol2AL(el,sy,hide)
     {  
        open4Alerts = sy; // e complicat :) !!  se deschide fereastra de alerte doar daca trece pe aici !
        fillDiv("/UsersUtils/mkALMenu.ashx",sy,el);
        if (hide)
            el.style.display = "none";
     }
     
    var xmlHttp

    var open4Alerts = "-";

    function fillDiv(str,symbol,el)
    { 
        var x = (findPosX(el)-50)+"px";
        var y = (findPosY(el)-50)+"px"; 
        
        var div = document.getElementById("spanXML");
        div.style.display = "block";
        div.style.top=y;
        div.style.left=x;  
        
        xmlHttp=GetXmlHttpObject()
        if (xmlHttp==null)
        {
            alert ("Browser does not support HTTP Request")
            return
        } 
        
        var url=str;
        url=url+"?s="+symbol;
        url=url+"&sid="+Math.random();
        xmlHttp.onreadystatechange=stateChanged ;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    }

    function hideAdding()
    {
        el = document.getElementById("tbMeniu");   
        el.style.display = "none";
    }
    
    function hideSpanXML()
    { 
        document.getElementById("spanXML").style.display = "none";
        document.getElementById("spanXML").innerHTML= "";
    }
    
    function stillSpanXML()
    { 
        document.getElementById("spanXML").style.display = "block"; 
    }
    
    function stateChanged() 
    { 
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {  
            document.getElementById("spanXML").innerHTML =xmlHttp.responseText   
            
            if (open4Alerts != "-" )
                if (xmlHttp.responseText.indexOf("login") < 0) 
                    {
                        document.getElementById("spanXML").style.display = "none";
                        alerte = window.open("/users/AlertDetail.aspx?s="+open4Alerts,"","width=1000,height=500,resizable=1,menubar=1,toolbar=1,location=1,directories=1,scrollbars=1");
                    }
            
            open4Alerts = "-"; //siguranta ca urmatorul apel nu vine pentru alerte (neaparat) !
        } 
    }  

    function GetXmlHttpObject()
    {
        var xmlHttp=null;
        try
        {
            // Firefox, Opera 8.0+, Safari
            xmlHttp=new XMLHttpRequest();
        }
        catch (e)
        {
            // Internet Explorer
            try
            {
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e)
            {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
        return xmlHttp;
    }
    
     function findPosX(obj)
        {
	        var curleft = 0;
	        if (obj.offsetParent)
	        {
		        while (obj.offsetParent)
		        {
			        curleft += obj.offsetLeft
			        obj = obj.offsetParent;
		        }
	        }
	        else if (obj.x)
		        curleft += obj.x;
	        return curleft;
        }

    function findPosY(obj)
        {
	        var curtop = 0;
	        if (obj.offsetParent)
	        {
		        while (obj.offsetParent)
		        {
			        curtop += obj.offsetTop
			        obj = obj.offsetParent;
		        }
	        }
	        else if (obj.y)
		        curtop += obj.y;
	        return curtop;
        }
  
     function showTable(e,s) 
     {    
            afis(findPosX(e),findPosY(e),s);
     }
     
    function afis(x,y,s)
    {    
        if (s != "")
            createMenu(s);
            
        el = document.getElementById("tbMeniu");   
         
        el.style.left = (x+9)+"px";
        el.style.top = (y-2)+"px";
         
        el.style.display = "block";
    }
    
    function stilTable()
    {   
        el = document.getElementById("tbMeniu");   
        el.style.display = "block";
    }  
    
    function hideTable()
    {
        el = document.getElementById("tbMeniu");   
        el.style.display = "none";
    }

//////////

    function addSendSymbol2PO()
    {
        var sens;
        sens = 1;
        if (document.getElementById("rdSens2").checked )
            sens = -1;
            
        openOP( document.getElementById("ddPoLists").value ,
                document.getElementById("spSymbol").innerHTML,
                sens,
                document.getElementById("txtPoPrice").value,
                document.getElementById("txtPoQuantity").value,
                document.getElementById("txtPoCommis").value,
                document.getElementById("txtPoData").value);
                
        hideSpanXML(); 
    }
    
    var PortfolioWindow;
    function openOP(l,s,t,p,q,c,d)
    {
        PortfolioWindow = window.open("/UsersUtils/Add2Portfolio.ashx?s="+s+"&t="+t+"&p="+p+"&q="+q+"&c="+c+"&d="+d+"&l="+l,"Add2Portfolio","width=1024,height=600,resizable=1,menubar=1,toolbar=1,location=1,directories=1,scrollbars=1");
    }
    
//////////
    
    function addSendSymbol2WL()
    { 
        openWL((document.getElementById("ddWlLists").selectedIndex+1),document.getElementById("spSymbol").innerHTML);
        hideSpanXML();
    }

    var WatchlistWindow;
    function openWL(l,s)
    {
        WatchlistWindow = window.open("/Users/Watchlist.aspx?s="+s+"&l="+l,"Watchlist","width=1024,height=600,resizable=1,menubar=1,toolbar=1,location=1,directories=1,scrollbars=1");
    }
 
//////////
 
    window.onunload = function() 
    {
        CheckWindow();
    }
      
    function CheckWindow()
    {
        if (WatchlistWindow != null)
                WatchlistWindow.close();
        if (PortfolioWindow != null)
                PortfolioWindow.close();
    }
    
    // sunt definite in web controlul "addMenuControl.ascx"
    var vadd2po = document.getElementById("hAdd2PO").value;
    var vadd2wl = document.getElementById("hAdd2WL").value;
    var vadd2al = document.getElementById("hAdd2AL").value;
    
    function createMenu(s)
    {
        var menu="<a href='javascript:;'>";
        menu+="<table class='tbAddTo' >";
        menu+="<tr>";
        menu+="<td > ";
        menu+="<div onclick=\"addSymbol2PO(this,'"+s+"')\" >..&nbsp;"+vadd2po+"</div></td></tr>";
        menu+="<tr>";
        menu+="<td  > ";
        menu+="<div onclick=\"addSymbol2WL(this,'"+s+"')\" > &nbsp;&nbsp;&nbsp;"+vadd2wl+"</div></td></tr>";
        menu+="<tr>";
        menu+="<td > ";
        menu+="<div onclick=\"addSymbol2AL(this,'"+s+"')\" > &nbsp;&nbsp;&nbsp;"+vadd2al+"</div></td></tr>";
        menu+="</table></a>"; 
        
        document.getElementById("tbMeniu").innerHTML = menu;
    }
    
    var helpWindow;
    function showAddHint( l)
    { 
          helpWindow = window.open("/Help/"+l+"/HintPortofoliu.html","","width=350,height=390") ;
    }      
    
