var path = "http://localhost/mldc/";

//var path = "http://www.merolagani.com/new/";

function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  theForm[z].checked = theElement.checked;
	  }
     }
    }
function checkUncheckAll2(theElement, cname) {
    var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
     if(theForm[z].type == 'checkbox' && theForm[z].name == cname){
	  theForm[z].checked = theElement.checked;
	  }
    }
   }
function ShowHideDiv(divname, status)
{
	var obj = GetID(divname);
	obj = obj.style;
	obj.display = status;		
	return false;
}

function DoSubmit(frm, fncname, txt, notext, msgdivid)
{	
	txt = txt || 'Loading...';
	msgdivid = msgdivid || 'i_msgbox';
	notext = notext || false;
	frmid = frm.id;
	
	ShowLoading(msgdivid,txt,notext);	
	fncname = 'xajax_' + fncname + '(xajax.getFormValues(frm), frmid)';
          eval(fncname);
          
	return false;		
}
function ShowLoading(id,txt,notxt)
{
	 id = id || "i_msgbox"; 
	 txt = txt || "&nbsp;&nbsp;Loading...";
	 notxt = notxt || false;
	 var obj = GetID(id);
	 
	 if(obj)
	 {	
	 	if(!notxt)
		{
			obj.innerHTML = '<center><font size="1" color="gray">'+txt+'</font>  <img src="'+path+'images/loading.gif" title="Please try again if this takes too long" alt="Communicating with server..."/></center>';
			
		}
		else
		{
			obj.innerHTML = '<center><img src="'+path+'images/loading.gif" title="Please try again if this takes too long" alt="Communicating with server..."/></center>';
		}
		
	 }

}
function GetID(var1)
{
	return document.getElementById(var1);
}
function CallServerFunction(func, msgdivid, txt, confirmation)
{
	confirmation = confirmation || "";
	txt = txt || 'Loading...';
	msgdivid = msgdivid || 'i_msgbox';
	if(confirmation!="")
	{
		if(!confirm(confirmation))
			return false;
	}
	
	ShowLoading(msgdivid, txt);
	func = 'xajax_'+func;
	eval(func);
}

function getValue(obj)
{
	return document.getElementById(obj).value;
}

function popup(url, height, width, scrollbars)
{
	var left = (screen.width-parseInt(width))/2;
	var top = (screen.height-parseInt(height))/2;
	var newwindow=window.open(url,'name','height='+height+',width='+width+',scrollbars='+scrollbars+',left='+left+',top='+top+',resizable=true');
	if (window.focus) {newwindow.focus()}
}
function selectChange(value, div1, div2)
{
          
          if (value == div1) {
                    ShowHideDiv(div1, '');
                    ShowHideDiv(div2, 'none');
          } else if (value == div2) {
                    ShowHideDiv(div1, 'none');
                    ShowHideDiv(div2, '');
          } else {
                    ShowHideDiv(div1, 'none');
                    ShowHideDiv(div2, 'none');
          }
          
         
}
function closediv(divname, task, closer) {
	ShowHideDiv(divname, task);
	
	closer = closer || "close";
	var obj = document.getElementById(closer);
	
	if (task == "none") {
	     obj.innerHTML = "<font size='1'><a href=\"javascript:void(null);\" onClick=\"closediv('"+divname+"', '', '"+closer+"')\" title=\"Show\">[+]</a></font></span>";
	} else if (task == "") {
	     obj.innerHTML= "<font size='1'><a href=\"javascript:void(null);\" onClick=\"closediv('"+divname+"', 'none', '"+closer+"')\" title=\"Hide\">[x]</a></font></span>";
	}

}
function remove_details(id) {
	
	document.getElementById('n').value = parseInt(id)-1;
	ShowHideDiv(id, 'none');
}
function add_details() {
	var n = parseInt(getValue('n'));
	var x = n+1;
	var text = "<table>"
        +" <tr> "
         +" <td align='center' width='30px;'> <div style='width:30px;'> "+x+" </div> </td> "
         +"  <td align='center' width='188px'> <input type='text' name='trade"+n+"' id='trade"+n+"' style='width:150px' /> </td> "
         +" <td align='center' width='188px'> <input type='text' name='strt"+n+"' id='strt"+n+"' style='width:150px' /> </td> "
         +" <td align='center' width='188px'> <input type='text' name='end"+n+"' id='end"+n+"' style='width:148px' /> </td> "
         +" <td align='center' width='188px'> <input type='text' name='shares"+n+"' id='shares"+n+"' style='width:147px' /> </td> "
         +" <td align='center' width='188px'> <input type='text' name='holder"+n+"' id='holder"+n+"' style='width:150px' /> </td> "
         +" <td width='30px' align='center'><div style='width:20px;'>&nbsp;</div></td></table> "
         +" <div id='"+x+"' style='display:none;'> </div>";
	
	ShowHideDiv(n, '');
	
	document.getElementById(n).innerHTML = text;
	document.getElementById('n').value = x;	
	
}
function mrktReference()
{
	var action = document.getElementById('action').value;
      var price = document.getElementById('price').value;

	if (action == "buy") {
	document.getElementById('text').value="An order to buy equity shares at the current available market price. This order will be filled at the current market price, provided there is enough trading volume to process a given trade. ";
	} else if (action == "sell") {
	document.getElementById('text').value="An order to sell equity shares at the current available market price. This order will be filled at the current market price, provided there is enough trading volume to process a trade.";
	} else if (action == "short_sell"){
	document.getElementById('text').value="An order to short sell equity shares at the current available market price. In a short sale, you essentially borrow shares from your broker and sell them on the market, in the hope that the share price will decrease. If it does, you can buy the shares back in the open market and return them to your broker, pocketing the difference between the (higher) sale price and the (lower) purchase price. This order will be filled at the current market price, provided there is enough trading volume to process your trade. ";
	} else {
	document.getElementById('text').value='An order to cover a short position in your portfolio by repurchasing shares at the current market price. To complete a profitable short sale, you need to first short sell a stock, and then (with any luck) repurchase the shares on the open market at a lower price. When you repurchase the shares, this is called "covering" your short sell and, therefore, the trade is called "buy to cover". ';
}
}
function limitReference()
{
	var action = document.getElementById('action').value;
      var price = document.getElementById('price').value;

	if (action == "buy") {
	document.getElementById('text').value="An order to buy equity shares at a specified price, or better. Buy-limit orders can be used to specify the maximum price that an investor is willing to pay for equity shares, and will be executed only once that price (or a better one) is available.";
	} else if (action == "sell") {
	document.getElementById('text').value="An order to sell equity shares at a specified price, or better. Sell-limit orders can be used to specify a minimum price for which you are willing to sell equity shares, and will be executed only once that price (or a better one) is available. They can be useful if you have a target selling price in mind but are unable to frequently monitor your portfolio. ";
	} else if (action == "short_sell"){
	document.getElementById('text').value="An order to short sell equity shares at a specified price, or better. Sell-short limit orders can be used to specify a minimum price for which you are willing to short sell equity shares, and will be executed only once that price (or a better one) is available. ";
	} else {
	document.getElementById('text').value='An order to cover a short position in your portfolio by repurchasing shares, but only once a specified price, or better, has been reached. This order can be entered to set up an automatic cover of your short position once a stock\'s price has fallen to your target covering price. A buy-to-cover limit is useful if you have a target price in mind but are unable to frequently monitor your portfolio.';
}
}
function stopReference()
{
	var action = document.getElementById('action').value;
      var price = document.getElementById('price').value;

	if (action == "buy") {
	document.getElementById('text').value="An order to buy equity shares once a specified price level is breached. This type of order can be used by momentum traders who wish to buy shares in a company only once the stock price has moved upwards past a threshold level (such as a 200 day moving average), indicating upward momentum that is expected to continue. ";
	} else if (action == "sell") {
	document.getElementById('text').value='Also known as a "stop-loss order", a sell stop is an order to sell equity shares once a specified price level has been breached. With this type of order, you specify a "stop price", which will trigger an automatic sale of your shares once a stock\'s price falls to the stop price or lower. This can be useful as a safety net, limiting your potential losses to the difference between the purchase price and stop price. ';
	} else if (action == "short_sell"){
	document.getElementById('text').value="An order to short sell equity shares once a specified price level is breached. This type of order can be used by momentum traders who wish to short sell shares in a company only once the stock price has moved downwards past a threshold level (such as a 200 day moving average), indicating a downward momentum that is expected to continue. ";
	} else {
	document.getElementById('text').value="Similar to a sell-stop order, this order type will exit your position automatically once a specified loss level is reached. In a buy-to-cover stop order, you specify a maximum price that, when reached, triggers a covering purchase of your shorted shares. Remember: in a short sale trade, the higher the price moves after your short sale, the greater your losses. ";
}
}	
 
function skipstep()
{
	document.getElementById('form').innerHTML = "<div id='success'> Your portfolio entry is now complete. You can not <a href='view_portfolio.php'>view your portfolio</a>, or <a href='edit_entries.php'>edit this entry</a> or <a href='sell_portfolio.php'>sell shares</a>.</div>";
	window.location = 'view_portfolio.php';
}
	


