function moneyBizStock(){
	
	var iTra =document.getElementById('TRASACTION').value;
	var length=document.getElementById('max').value;
	var iStockPrice=document.getElementById('txtStocprice').value;
	var iStockQty=document.getElementById('txtStocqty').value;
	
	//alert(iStartCash);
	var sCompanyname=document.getElementById('COMPANY_NAME').value;
	var sCompCode=document.getElementById('COMPANY_ID').value;
	var iPortfolioId=0;
	var status=0;
	for (var i=1; i<=length; i++ )
	{
		if(document.getElementById('portfolioid_'+i).checked==true){
			iPortfolioId=document.getElementById('portfolioid_'+i).value;
			var iStartCash=document.getElementById('CASH_'+i).value;
			//alert(iStartCash);
			var qty =document.getElementById(iPortfolioId).value;
			status=1;
		} 
	}

	
    if(status==0) {
		document.getElementById('buy_sell_error').innerHTML = 'Please select The Portfolio. ';
		//alert("Please The Portfolio");
		return false;
   } else if(iStockQty=='') {
		document.getElementById('buy_sell_error').innerHTML = 'Stock Quantity Cannot Be valid. ';
		
		//alert("Stock Quantity Cannot Be valid");
		return false;
   } else if(iStockQty==0) {
			document.getElementById('buy_sell_error').innerHTML = 'Stock Quantity Cannot Be zero. ';
		
   } else {
	   //adding_stock.php?height=470&width=540&companycode="+escape(company_code)+"&companyname="+escape(company_list[2])+"&profileid="+escape(company_list[4])+"&search_key="+escape(company_list[3])+"&location=t
	   //alert("stockre.php?tra="+iTra+"&stockqty="+iStockQty+"&stockprice="+iStockPrice+"&starcash="+iStartCash+"&companycode="+sCompCode+"&profileid="+iPortfolioId+"&companyname="+escape(sCompanyname));
	   //var x = new RemoteProcedure("stockre.php?tra="+iTra+"&stockqty="+iStockQty+"&stockprice="+iStockPrice+"&starcash="+iStartCash+"&companycode="+sCompCode+"&profileid="+iPortfolioId+"&companyname="+escape(sCompanyname), buy_response, show_patience);
	   if (document.getElementById("submitSell")) {
			document.getElementById("submitSell").disabled = true;
		 }
            if(isInteger(iStockQty)) {
	    var x = new RemoteProcedure("stockre.php?tra="+iTra+"&stockqty="+iStockQty+"&stockprice="+iStockPrice+"&starcash="+iStartCash+"&companycode="+sCompCode+"&profileid="+iPortfolioId+"&companyname="+escape(sCompanyname), buy_response, show_patience);
            } else {
			  if (document.getElementById("submitSell")) {
					 document.getElementById("submitSell").disabled = false;
				}
              document.getElementById('buy_sell_error').innerHTML = 'Please Enter valid Quantity. ';
             }
	 
	 
   }
   document.getElementById('buy_sell_error').style.display = 'block';
   return true;
 }

function buy_response(resp) {
    var response = resp.responseText;
	//alert(response);
	var str = response.split(',');
	if (str[0] == 'change') {
		document.getElementById('buy_sell_error').innerHTML = 'Price has changed to '+ str[1];
        document.getElementById('txtStocprice').value =str[1];
		 if (document.getElementById("submitSell")) {
					 document.getElementById("submitSell").disabled = false;
				}
    } else if (str[0] == 'error_buy'){
		if(str[2]==0) {
			document.getElementById('buy_sell_error').innerHTML = "You can't buy more shares";
		} else {
		   document.getElementById('buy_sell_error').innerHTML = "Not enough cash. But you can buy "+ str[2]+" shares";
		}
		 if (document.getElementById("submitSell")) {
					 document.getElementById("submitSell").disabled = false;
				}
	} else  if (str[0] == 'error_sell'){
		document.getElementById('buy_sell_error').innerHTML = "You can't sell  more than "+ str[2]+" shares";
		 if (document.getElementById("submitSell")) {
					 document.getElementById("submitSell").disabled = false;
				}
	} else {
		window.location= "portfolio.php?portfolioid="+str[1];
	}
	document.getElementById('buy_sell_error').style.display = 'block';
}

function show_patience() {}

function openWindiow(url) {
	tb_show(null,"from_moneybiz.php?cid="+iCid+"&amp;height=230&amp;width=500", false);
}