var msgWin=null;
window.onbeforeunload = function()
{
    if (msgWin != null && msgWin != "undefined")
        msgWin.close();
}
function ShowTicketText(ticketId)
{
    var url=GetBaseUrl()+"/Ticket/ViewTicket.aspx?ticketID="+ticketId;
	msgWin=window.open(url,"TicketTextWin","width=950px, height=700px, top=10, left=10, scrollbars=1, status=0, menubar=0, toolbar=0, resizable=1");
	
	PassValues();
}
function LoadTicketConfirmation(ticketID, ticketFunctionID, edittype, occTicketId, noExtensionMessage)
{
    if ( noExtensionMessage != undefined && noExtensionMessage != null && noExtensionMessage != '')
    {
        var md=new ModalDialogue();
        md.Title='IRTH One Call';
        md.Text=noExtensionMessage;
        md.Show();
    }
    else
    {
        var url=GetBaseUrl()+"/Ticket/ViewTicket.aspx?ticketID="+ticketID+"&functionID="+ticketFunctionID+"&editType="+edittype+"&occTicketID="+occTicketId;
	    msgWin=window.open(url,"TicketWin","width=800px, height=500px, top=10, left=10, scrollbars=1, status=0, menubar=0, toolbar=0, resizable=1");
        PassValues();	
    }
}
function LoadTicketEdit(ticketID, ticketFunctionID, edittype, occTicketId, usePopup)
{

    if (usePopup) 
    {
        var url = GetBaseUrl() + "/Ticket/TicketEditing.aspx?ticketID=" + ticketID + "&functionID=" + ticketFunctionID + "&editType=" + edittype + "&occTicketID=" + occTicketId;
        msgWin = window.open(url, "TicketWin", "width=800px, height=500px, top=10, left=10, scrollbars=1, status=0, menubar=0, toolbar=0, resizable=1");
        PassValues();
    }
    else 
    {
        var url = GetBaseUrl() + "/Ticket/TicketCreation.aspx?ViewTicketID=" + ticketID + "&functionID=" + ticketFunctionID + "&editType=" + edittype + "&occTicketID=" + occTicketId;
        window.location = url;
    }
}
function ShowPositiveResponse(ticketId)
{
    var url=GetBaseUrl()+"/Ticket/PositiveResponse/EnterResponse.aspx?ticketID="+ticketId;
	msgWin=window.open(url,"ShowPositiveResponseWin","width=950px, height=700px, top=10, left=10, scrollbars=1, status=0, menubar=0, toolbar=0, resizable=1");
}

function EnterPositiveResponse(ticketId)
{
 var url=GetBaseUrl()+"/Ticket/ViewTicket.aspx?ticketID="+ticketId;
	msgWin=window.open(url,"TicketTextWin","width=950px, height=700px, top=10, left=10, scrollbars=1, status=0, menubar=0, toolbar=0, resizable=1");
}
function PassValues()
{
    try
    {//Need to try catch here because if the server gets recompiled by changing the web.config, or resetting iis
     // msgWin.document does not allow access here.
        if(msgWin.document.readyState != "complete")
	    {
		    tm=setTimeout("PassValues();",10);
		    return;
	    }
    	
	    msgWin.SetCameFromApp("true");
    }
    catch(e)
    {

    }
}
function CopyTicket(ticketID, ticketFunctionID)
{
    window.location = GetBaseUrl()+"/Ticket/TicketCreation.aspx?CopyFromTicketID="+ticketID;
}
function Refresh()
{
    var frm=document.forms[0]; 
    
    var dropDown = null;
	
	var count=0;
	for (var i=1;i<frm.elements.length;i++) 
	{ 
		var e = frm.elements[i]; 
		if (e.type !="hidden" && e.className !="hiddenItem") 
			continue;
	
		if(e.title=="hiddenRefreshSearch")
		    e.value = "1";
		else if (e.id.indexOf("hdnDropDown") > 0)
		    dropDown = e;
	}
	
	if (dropDown != null)
	    dropDown.fireEvent("onchange");
}
