
function addStockInvestmentLog() {}



addStockInvestmentLog.init = function()
{
	var div = document.createElement("div");
	div.innerHTML = "<div style='position:absolute;width:416px;height:318px;background-color:white;border:2px #6D6D6D solid;display:none;left:0px;top:0px;' ></div>";
	
	addStockInvestmentLog.mainDiv = div.childNodes[0];
	
	var sb = new Array;
	sb.push ("<div id='eventDiv' onmousedown='addStockInvestmentLog.fDragging(this, event, true);' ><table width=100% border=0 cellspacing=0 cellpadding=0 ><tr>");
	sb.push ("<td  width=300 height=21 class='floatDivTop'><span id='addStockInvestmentLog_title' style='padding-left:5px;font-size:12px;font-weight:bold;'>市场雷达[运行中]</span></td>");
	sb.push ("<td class='floatDivTop'><div align=right><img src='");
	sb.push ("../images/hqwt/close_a.gif' onmouseover=\"this.src='../images/hqwt/close_b.gif'\" onmouseout=\"this.src='../images/hqwt/close_a.gif'\" onmousedown=\"this.src='../images/hqwt/close_c.gif'\" onmouseup=\"this.src='../images/hqwt/close_b.gif'\"  border=0 onclick='addStockInvestmentLog.hiddenDiv()' style='cursor:hand;' /></div></td></tr></table></div>");
	sb.push ("<div style='width:412;height:274;background-color:#ffffff;overflow-x:hidden;overflow-y:auto'><table width='412' bgcolor='#ffffff' border='0' cellspacing='0' cellpadding='0' id='addStockInvestmentLogTable' ><tbody><tr><td>标题：<input type='text' name='addStockInvestmentLogTitle' id='addStockInvestmentLogTitle' size=40 onkeydown='addStockInvestmentLog.myonkeydownForMarkText()'/></td></tr><tr><td><textarea id='addStockInvestmentLogTextAreaID' rows=17 cols=65 onkeydown='addStockInvestmentLog.myonkeydownForMarkText()'></textarea></td></tr></tbody></table></div><table  width='412' border='0' bgcolor='#CCCCCC' cellspacing='0' cellpadding='0' height='30'><tr><td align='right'><input type='button' id='closeBtn'  value='确定' onClick='addStockInvestmentLog.addInvestmentLog()'/>&nbsp;&nbsp;<input type='button' id='closeBtn'  value='取消' onClick='addStockInvestmentLog.hiddenDiv()'/></td></tr></table>");
	addStockInvestmentLog.mainDiv.innerHTML = sb.join("");
	document.body.appendChild (addStockInvestmentLog.mainDiv);
	addStockInvestmentLog.insertList = false;
}

addStockInvestmentLog.fDragging = function (obj, e, limit)
{ 
    if(!e) e=window.event;
     
    obj=addStockInvestmentLog.mainDiv;
    var x=parseInt(obj.style.left); 
    var y=parseInt(obj.style.top); 
     
    var x_=e.clientX-x; 
    var y_=e.clientY-y; 
     
    if(document.addEventListener)
    { 
        document.addEventListener('mousemove', inFmove, true); 
        document.addEventListener('mouseup', inFup, true);
        window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP); 
    } 
    else if(document.attachEvent)
    { 
        document.attachEvent('onmousemove', inFmove); 
        document.attachEvent('onmouseup', inFup); 
        obj.setCapture ();
    } 
     
    
    inFstop(e);     
    inFabort(e) 
    
    function inFmove(e)
    { 
        var evt; 
        if(!e)e=window.event; 
         
        if(limit)
        { 
            var op=obj.parentNode; 
            var opX=parseInt(op.style.left); 
            var opY=parseInt(op.style.top); 
             
            if((e.clientX-x_)<0)
            {
                return false; 
            }
            else if((e.clientX-x_+obj.offsetWidth+opX)>(opX+op.offsetWidth))
            {
                return false;
            }
             
            if(e.clientY-y_<0){
                return false; 
            }
            else if((e.clientY-y_+obj.offsetHeight+opY)>(opY+op.offsetHeight)){
                return false; 
            }
        } 
         
        obj.style.left=e.clientX-x_+'px'; 
        obj.style.top=e.clientY-y_+'px'; 
         
        inFstop(e); 
    } // shawl.qiu script 
    
    function inFup(e)
    { 
        var evt; 
        if(!e)e=window.event; 
         
        if(document.removeEventListener)
        { 
            document.removeEventListener('mousemove', inFmove, true); 
            document.removeEventListener('mouseup', inFup, true);
            window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
        }
         else if(document.detachEvent)
        { 
            document.detachEvent('onmousemove', inFmove); 
            document.detachEvent('onmouseup', inFup); 
            obj.releaseCapture ();
        } 
         
        inFstop(e); 
    } // shawl.qiu script 

    function inFstop(e)
    { 
        if(e.stopPropagation) return e.stopPropagation(); 
        else return e.cancelBubble=true;             
    } // shawl.qiu script 
    
    function inFabort(e)
    { 
        if(e.preventDefault) return e.preventDefault(); 
        else return e.returnValue=false; 
    } // shawl.qiu script 
} 

addStockInvestmentLog.mouseDownDiv = function()
{
	//var div = addStockInvestmentLog.mainDiv;
	var div=document.getElementById("eventDiv");
  var evt = BrowserCompatible.getEvent();
	
  if(div && evt && evt.button == 1)
  {
		addStockInvestmentLog.status = "dragger";
		addStockInvestmentLog.draggerLeft = BrowserCompatible.getEventX(evt);
		addStockInvestmentLog.draggerTop = BrowserCompatible.getEventY(evt);
		div.style.cursor = "move";
		div.setCapture ();
	}
	
}

addStockInvestmentLog.mouseUpDiv = function()
{
  //var div = addStockInvestmentLog.mainDiv;
  var div=document.getElementById("eventDiv");
	var evt = BrowserCompatible.getEvent();
  
  if(div && evt)
  {
		div.releaseCapture ();
		addStockInvestmentLog.status = "normal";
		div.style.cursor = "default";
	}
	
}

addStockInvestmentLog.mouseMoveDiv = function()
{
	var div = addStockInvestmentLog.mainDiv;
	//var div=document.getElementById("eventDiv");
	var evt = BrowserCompatible.getEvent();
	
	if (div && addStockInvestmentLog.status == "dragger")
	{
		var x = BrowserCompatible.getEventX(evt) - parseInt(addStockInvestmentLog.draggerLeft);
		var y = BrowserCompatible.getEventY(evt) - parseInt(addStockInvestmentLog.draggerTop);
		
		addStockInvestmentLog.draggerLeft = BrowserCompatible.getEventX(evt);
		addStockInvestmentLog.draggerTop = BrowserCompatible.getEventY(evt);
		
		var left = parseInt(div.style.left)+x;
		var top = parseInt(div.style.top)+y;
		
		if(left < 0) left = 0;
		if(top < 0) top = 0;
		if(left > (parseInt(document.body.clientWidth) - 416)) left = parseInt(document.body.clientWidth) - 416;
		if(top > (parseInt(document.body.clientHeight) - 318)) top = parseInt(document.body.clientHeight) - 318
		
		div.style.left = left;
		div.style.top  = top;
	}
}

addStockInvestmentLog.displayDiv = function (zqjc,stockid)
{
	
	addStockInvestmentLog.stockID = stockid;
  document.getElementById ("addStockInvestmentLog_title").innerHTML = "撰写投资日志 - "+zqjc+"("+stockid.substring(2,8)+")";
 	addStockInvestmentLog.mainDiv.style.left = (parseInt(document.body.clientWidth) - 428) / 2;
	addStockInvestmentLog.mainDiv.style.top  = (parseInt(document.body.clientHeight) - 328) / 2;
 
	addStockInvestmentLog.mainDiv.style.display = "";
	document.getElementById ("addStockInvestmentLogTitle").focus();
	document.onkeydown=null;
	
}



addStockInvestmentLog.hiddenDiv = function()
{
	document.onkeydown = keyDownForyinhe;
	act();
	document.getElementById ("addStockInvestmentLogTextAreaID").value = "";
	document.getElementById ("addStockInvestmentLogTitle").value = "";
  addStockInvestmentLog.mainDiv.style.display = "none";
}

addStockInvestmentLog.addInvestmentLog = function ()
{
		var title = document.getElementById ("addStockInvestmentLogTitle").value;
		
		if(title == "")
		{
			alert("请填写标题");
			document.getElementById ("addStockInvestmentLogTitle").focus();
			return;
		}
		
		var content = document.getElementById("addStockInvestmentLogTextAreaID").value;
		var date = new Date();
		var logValue = title+"<log>"+content+"<log>"+date.getTime()+"<log>"+addStockInvestmentLog.stockID;
		var logValueList = getCookie(addStockInvestmentLog.stockID+"_InvestmentLog");
		
		if(logValueList != "")
		{
					logValueList += "<loglist>";
		}
		
		logValueList += logValue;
		
		setCookie(addStockInvestmentLog.stockID+"_InvestmentLog",logValueList);
		
		//插入当前列表
		if(addStockInvestmentLog.insertList)
		{
				stockInvestmentLogList.addLog(logValue);
		}
		
		addStockInvestmentLog.hiddenDiv();
}

addStockInvestmentLog.deleteMarkText = function ()
{
		setCookie(addStockInvestmentLog.stockID+"_InvestmentLog","");
		addStockInvestmentLog.hiddenDiv();	
}

addStockInvestmentLog.myonkeydownForMarkText = function(e)
{
	if(e==null)
	  e=BrowserCompatible.getEvent(e);
	  
	var keycode=BrowserCompatible.getKeyCode(e);
	
	if(keycode==27)
	{
	  try
	  {
	    BrowserCompatible.fireKeyEvent(e);
	  }catch(E){}
	  
	  addStockInvestmentLog.hiddenDiv();
	}
}
