/**

 * @author alexanderia_lover

 * @copyright 2007

 */





// creating ajax object



	if (window.ActiveXObject) {

	

	 xmlHttp2 = new ActiveXObject("Msxml2.XMLHTTP");

	}

	else  {

	

	 xmlHttp2 = new XMLHttpRequest();

	}

	

	

	

	///////////////////////////////////////Portfolios functions///////////////////////////////////////////



	

	

	/////////////////////////////////buy Form//////////////////////////////



function buy_stock(port_id)   

	{



		xmlHttp2.open("GET","portajax/buyForm.php?port_id="+port_id, true);

		xmlHttp2.onreadystatechange = buy_stockHandler;

		xmlHttp2.send(null);			

			

	}

	

	function buy_stockHandler()

		{

			if (xmlHttp2.readyState == 2)

				{

				document.getElementById("showDiv").innerHTML="<img src='images/ajax-loader.gif' alt='loading..' />"

				}

			

			if (xmlHttp2.readyState == 4) 

				{ 

				document.getElementById("showDiv").innerHTML=xmlHttp2.responseText;

				}	

		}		

		

	

/////////////////////////////////////////////////////////////////////////////////////////

function excute_buy(port_id) //excuting the buy proccess

		{

			

		if(CheckAddStocks())	

		{

this.port_id = port_id;

var quantity2 = document.form1.quantity.value;			

this.ruters= document.getElementById("ruters").value;

this.last_price= document.getElementById("last_price").value;

xmlHttp2.open("GET","portajax/excuteBuy.php?port_id="+port_id+"&ruters="+ruters+"&quantity="+quantity2+"&last_price="+last_price,true);

xmlHttp2.onreadystatechange = excute_buyHandler;

xmlHttp2.send(null);			

		}

						

		}

	

	

	function excute_buyHandler()

		{

			if (xmlHttp2.readyState == 2)

				{

				document.getElementById("showDiv").innerHTML="<img src='images/ajax-loader.gif' alt='loading..' />"

				}

			if (xmlHttp2.readyState == 4) 

				{ 

				document.getElementById("showDiv").innerHTML=xmlHttp2.responseText;

				port_Desc(port_id);

				}	

		}		

			

		

	/////////////////////////////////sell Form//////////////////////////////



function sell_stock(port_id)   

	{





		xmlHttp2.open("GET","portajax/sellForm.php?port_id="+port_id, true);

		xmlHttp2.onreadystatechange = sell_stockHandler;

		xmlHttp2.send(null);			

			

	}

	

	function sell_stockHandler()

		{

			

			if (xmlHttp2.readyState == 2)

				{

				document.getElementById("showDiv").innerHTML="<img src='images/ajax-loader.gif' alt='loading..' />"

				}			

			if (xmlHttp2.readyState == 4) 

				{ 

				document.getElementById("showDiv").innerHTML=xmlHttp2.responseText;

				}	

		}		

		

/////////////////////////////////////////////////////////////////////////////////////////



function excute_sell(port_id) //excuting the buy proccess

		{

			

			if(checkSellFrm())

			{

var quantity2 = document.form1.quantity.value;			

this.port_id = port_id;

this.ruters= document.getElementById("ruters").value;

this.last_price= document.getElementById("last_price").value;



xmlHttp2.open("GET","portajax/excuteSell.php?port_id="+port_id+"&ruters="+ruters+"&quantity="+quantity2+"&last_price="+last_price,true);

xmlHttp2.onreadystatechange = excute_sellHandler;

xmlHttp2.send(null);			

			}

			

		}

	

	function excute_sellHandler()

		{

			

			if (xmlHttp2.readyState == 2)

				{

				document.getElementById("showDiv").innerHTML="<img src='images/ajax-loader.gif' alt='loading..' />"

				}			

			if (xmlHttp2.readyState == 4) 

				{ 

				document.getElementById("showDiv").innerHTML=xmlHttp2.responseText;

				port_Desc(port_id);

				}	

		}		

		

		

	/////////////////////////////////portfolio description//////////////////////////////



function port_Desc(port_id,page)   

	{

		xmlHttp2.open("GET","portajax/port_desc.php?port_id="+port_id+"&page="+page, true);

		xmlHttp2.onreadystatechange = port_DescHandler;

		xmlHttp2.send(null);			

			

	}

	

	function port_DescHandler()

		{

			

			if (xmlHttp2.readyState == 2)

				{

				document.getElementById("portDesc").innerHTML="<img src='images/ajax-loader.gif' alt='loading..' />"

				}			

			if (xmlHttp2.readyState == 4) 

				{ 

				document.getElementById("portDesc").innerHTML=xmlHttp2.responseText;

				}	

		}		

	///////////////////////////////////////Portfolios transactions///////////////////////////////////////////



function show_transactions(port_id,page)   //show transactions

	{



		xmlHttp2.open("GET","portajax/transactions.php?port_id="+port_id+"&page="+page, true);

		xmlHttp2.onreadystatechange = show_transactionsHandler;

		xmlHttp2.send(null);			

			

	}

	

	function show_transactionsHandler()

		{

			if (xmlHttp2.readyState == 2)

				{

				document.getElementById("showDiv").innerHTML="<img src='images/ajax-loader.gif' alt='loading..' />"

				}			

			if (xmlHttp2.readyState == 4) 

				{ 

				document.getElementById("showDiv").innerHTML=xmlHttp2.responseText;

				}	

		}		

 




