// trade_ticket.js 

function openTicket()
{
	// extract all possible arguments and
	// build a query atring
	var queryStr;

	if(arguments.length > 0)
		queryStr = "?";

	for(var i = 0; i < arguments.length; i++)
	{
		var str = arguments[i];
		arg = str.split('=');
		if(queryStr.indexOf('=') > -1)
			queryStr = queryStr + "&";
		switch (arg[0])
		{
			case "piId":
				this.piId = arg[1];
				queryStr = queryStr + "piId=" + arg[1];
				break;
			case "Code":
				this.Code = arg[1];
				queryStr = queryStr + "Code=" + arg[1];
				break;
			case "action":
				this.action = arg[1];
				queryStr = queryStr + "action=" + arg[1];
				break;
			case "popup":
				this.popup = arg[1];
				queryStr = queryStr + "popup=" + arg[1];
				break;
		}
	}

	if(this.window != false)
	{
		this.url = '/trade/ticket/';
		this.window.close();
	}
	
	if(arguments.length > 0)
		this.url = '/trade/ticket/' + queryStr;
	
	// open the ticket
	this.window = window.open(this.url,'',this.features);
	this.window.focus();
}

function closeTicket(ticket)
{
	ticket.opener.location.reload();
	ticket.close();
}

function fill_form(epic)
{
	if(window.form_init < 1)
	{
		alert("Please wait for the search\n results to finish loading");
	}
	else
	{
		document.quoteForm.Code.value = epic;
		document.quoteForm.submit();
	}
}

function Ticket()
{
	this.window		= false;
	this.url		= "/trade/ticket/";
	this.width		= 380;
	this.height		= 600;
	this.status		= 'no';
	this.resizable	= 'no';
	this.scrollbars	= 'no';
	this.features	= "width=" +  this.width + ",height=" + this.height + ",status=" + this.status + ",resizable=" + this.resizable +",scrollbars=" + this.scrollbars;
	this.open 		= openTicket;
	this.getQuote	= fill_form;
	this.close		= closeTicket;
}


function reloadMyAccount()
{
	parent.myAccountFrame.location.reload();
}


window.form_init = 0;
window.onload = function(){window.form_init = 1};

var Ticket = new Ticket;
