function Popup(){
    this.blackout = document.createElement("div");
    Element.addClassName(this.blackout, "blackout");
    var browser_name = navigator.appName;
    if(browser_name == "Microsoft Internet Explorer")
	this.blackout.style.position = "absolute";
    this.popup_main = document.createElement("div");
    Element.addClassName(this.popup_main, "popup_main");
        
    this.popup_shad = document.createElement("div");
    this.popup_main.appendChild(this.popup_shad);
    Element.addClassName(this.popup_shad, "popup_shad");
    
    this.popup = document.createElement("div");
    Element.addClassName(this.popup,"popup");
    this.popup.setAttribute("id","popup");
    this.popup_shad.appendChild(this.popup);

    Element.hide(this.popup_main);
    Element.hide(this.blackout);
    
    var body = document.getElementsByTagName("body")[0];
    body.appendChild(this.blackout);
    body.appendChild(this.popup_main);
    this.isHidden = 1;
}

Popup.prototype.show = function(href, id)
{
    Element.update(this.popup,"");
    add=""
    params= window.location.search;
    if($('ticketsTable'))
    {
    x = getSelectedRowIndex();
    if((x>=0) && ((x+1)<$('ticketsTable').rows.length))
	if(params != "")
	    add = "%26selected_id="+$('ticketsTable').rows[x+1].id;
	else
	    add = "%3Fselected_id="+$('ticketsTable').rows[x+1].id;
    }
    params=params.replace("?","%3F").replace(/&/g,"%26");
    var r = new AjaxClient(href,
	{method: "post",
        parameters:"action=popup&id="+id+"&href="+window.location.pathname + params +add,
        onFailure: reportError,
//	onComplete: this.show1(this),
	evalScripts: true});
}

Popup.prototype.show1 = function(object)
{
    if(this.isHidden) 
	this.popup_main.style.top = document.body.scrollTop+document.body.clientHeight/4+"px";
    this.isHidden = 0;
    if(document.search)
    {
	sel = document.search['filter-expert']
	if(sel) sel.hide();
    }
    Element.show(this.popup_main);
    Element.show(this.blackout);
}

Popup.prototype.hide = function()
{
    this.isHidden = 1;
    Element.update(this.popup,"");
    if(document.search)
    {
	sel = document.search['filter-expert']
	if(sel) sel.show();
    }
    this.blackout.hide();
    this.popup_main.hide();
}

function popup_init() 
{
    window.popup = new Popup();
}

if (Ajax.getTransport()) {
    new FastInit(popup_init);
}

function selectRow(id)
{
    for(var x=0;x<$('ticketsTable').rows.length;x++)
    {
	if($('ticketsTable').rows[x].id == id)
	    $('ticketsTable').rows[x].style.backgroundColor="#FF0000";
	else
	    $('ticketsTable').rows[x].style.backgroundColor="";
    }
}

function selectNextRow()
{
    for(var x=0;x<$('ticketsTable').rows.length;x++)
    {
	if($('ticketsTable').rows[x].style.backgroundColor != "")
	{
	    if((x+1)<$('ticketsTable').rows.length) 
		$('ticketsTable').rows[x+1].style.backgroundColor="#FF0000";
	    $('ticketsTable').rows[x].remove();
	    break;
	}
    }
    return true;
}
function getSelectedRowIndex()
{
    for(var x=0;x<$('ticketsTable').rows.length;x++)
	if($('ticketsTable').rows[x].style.backgroundColor != "")
	    return x;
    return -1;
}
