// JScript File
var aMasterControls = new Array;
var iMasterControlsIndex = 0;
var iMaxHeight = 0;

var CPT_MOVETOBOTTOM = 1;
var CPT_EXPANDTOBOTTOM = 2;
var CPT_EXPANDTORIGHT = 3;

var bInit = false;
var iInterval = 0;
var POPUPMEDIUMPARMS = "dialogHeight:500px;dialogWidth:600px;scroll:yes;help:no;status:no;center:yes;";

function ReadyStateChangeHandler()
{
    if ((document.readyState == "interactive") || (document.readyState == "complete"))
    {
        iInterval = window.setInterval(ForceEvent, 100);
    }                
}

function ForceEvent()
{
    if (bInit && (iInterval != 0))
    {
        window.clearInterval(iInterval);
        iInterval = 0;
    }
    if (!bInit)
    {
        RepositionControls0();
    }
}  

//document.onreadystatechange = ReadyStateChangeHandler;


function MasterControl(sControlID, iControlPositionType, iMinHeight)
{
    this.ControlID = sControlID;
    this.ControlPositionType = iControlPositionType;
    this.MinHeight = iMinHeight;
    aMasterControls[iMasterControlsIndex++] = this;
}

function RepositionControls0()
{
    var cTables;      
    var jCount;
    var oHTMLCtl;
    
    cTables = document.getElementsByTagName("table");
    for(jCount = 0; jCount < cTables.length; jCount++)
    {
        oHTMLCtl = cTables[jCount];
        if (oHTMLCtl.id.search("NOSELECT") >= 0)
        {
            oHTMLCtl.onselectstart = OnSelect;
        }
    }
    document.body.style.overflowX = "hidden"; 
    document.body.onresize = RepositionControls;    
    RepositionControls();
    bInit = true;
}    

var bAllowSelect = true;

function OnSelect()
{
    var bResult = (bAllowSelect || 
                   (window.event.srcElement.tagName.toUpperCase() == "INPUT") ||
                   (window.event.srcElement.tagName.toUpperCase() == "TEXTAREA") ||
                   (window.event.srcElement.id.toUpperCase().search("HTMEDITOR") >= 0));                                           
    return bResult;
}


function RepositionControls()
{
    iMaxHeight = document.body.clientHeight;
    DoReposition();
    if (typeof MasterResize == "function")
        MasterResize();
    if (typeof ChildResize == "function")
        ChildResize();    
}

function GetInputControl(controlID)
{
    return GetControlByTagAndId("input", controlID);
}

function GetAnchorControl(controlID)
{
    return GetControlByTagAndId("a", controlID);
}

function GetMultiLineInputControl(controlID)
{
    return GetControlByTagAndId("textarea", controlID);
}

function GetLabelControl(controlID)
{
    return GetControlByTagAndId("span", controlID);
}    

function GetDropDownControl(controlID)
{
    return GetControlByTagAndId("select", controlID);
}    

function GetDivControl(controlID)
{
    return GetControlByTagAndId("div", controlID);
}

function GetTableControl(controlID)
{
    return GetControlByTagAndId("table", controlID);
}
function GetImageControl(controlID)
{
    return GetControlByTagAndId("img", controlID);
}
function GetTableCellControl(controlID)
{
    return GetControlByTagAndId("td", controlID);
}
function GetControlByTagAndId(tagID, controlID)
{
    var iCount;
    var oHTMLCtl;
    var cControls = document.getElementsByTagName(tagID);

    if (cControls)
    {             
        for(iCount = 0; iCount < cControls.length; iCount++)
        {
            oHTMLCtl = cControls[iCount];            
            if (oHTMLCtl.id.search(controlID) >= 0)
                return oHTMLCtl;
        }
    }
    return undefined;
}
function setStatusDisplay(str)
{
    window.status = str;
    return true;
}
function cancelQuote()
{    
    if(confirm("Are you sure you wish to cancel this quote?"))
    {
        var hdnContext= GetInputControl("hdnContext");
        location.href = "desktopHome.aspx?source=qcancel&context=" + hdnContext.value;
    }
    return false;
}
function DoReposition()
{
    var iCount, jCount;
    var oCtl, oHTMLCtl;
    var cDivs;

    cDivs = document.getElementsByTagName("div");
    
    if (cDivs)
    {     
        for(iCount = 0; iCount < aMasterControls.length; iCount++)
        {
            oCtl = aMasterControls[iCount];
            
            for(jCount = 0; jCount < cDivs.length; jCount++)
            {
                oHTMLCtl = cDivs[jCount];
                if (oHTMLCtl.id.search(oCtl.ControlID) >= 0)
                {
                    switch(oCtl.ControlPositionType)
                    {
                        case CPT_MOVETOBOTTOM:
                            oHTMLCtl.style.pixelTop = iMaxHeight - oHTMLCtl.style.pixelHeight;
                            if ((iMaxHeight <= 0) || (iMaxHeight > oHTMLCtl.style.pixelTop))
                                iMaxHeight = oHTMLCtl.style.pixelTop;
                            break;
                        case CPT_EXPANDTOBOTTOM:                            
                            oHTMLCtl.style.pixelHeight = ((iMaxHeight - oHTMLCtl.style.pixelTop) > oCtl.MinHeight) ? (iMaxHeight - oHTMLCtl.style.pixelTop) : oCtl.MinHeight;
                            break;                                
                        case CPT_EXPANDTORIGHT:
                            oHTMLCtl.style.pixelWidth = document.body.clientWidth - oHTMLCtl.style.pixelLeft;
                            break;                                                                
                    }
                }        
            }
        }    
    }    
}    



var ctlD1;
var ctlD2;
var ctlD3;
var ctlDA;
var ctlHR;
var ctlVR;
var ctlBody;
var ctlBodyHeight;
var ctlBodyWidth;
var ctlHRHeight;
var ctlVRWidth;
var ctlHid1;
var ctlHid2;
var minWidth = 10;
var minHeight = 20;


function GetSplitElements()
{
    ctlHid1 = GetInputControl("hidOriginalHeight");
    ctlHid2 = GetInputControl("hidOriginalWidth");
    ctlBodyHeight = GetInputControl("hidBodyHeight");
    ctlBodyWidth = GetInputControl("hidBodyWidth");
    ctlHRHeight = GetInputControl("hidHRHeight");
    ctlVRWidth = GetInputControl("hidVRWidth");
    ctlD1 = GetDivControl("d001");
    ctlD2 = GetDivControl("d002");
    ctlD3 = GetDivControl("d003");
    ctlDA = GetDivControl("d00a");
    ctlHR = GetDivControl("hr");
    ctlVR = GetDivControl("vr");
    ctlBody = GetDivControl("pnlBody");
}

function swapTabBG(sID,bOnOff)
{    
    var obj = GetTableCellControl(sID);
    
    // Swap BG of non-active tab
    if(obj.className != 'igStyleTabOn')
    {
        if(bOnOff == 0)
        {
            obj.className = 'igStyleTabOff_0'
        }
        else
        {
            obj.className = 'igStyleTabOff_1'
        }
          
    }
}
function activateTabClick(sID)
{
    var obj = GetTableCellControl(sID);
    
    // Only allow non-active tab to be clickable
    if(obj.className != 'igStyleTabOn')
    {
        obj.className = 'igStyleTabOn';
        
        var id = new String(); 
        var idx = new Number();
        id = sID;       
        idx = Number(id.substr(id.length-1,1));
        
        for(i = 1; i < 5; i++)
        {          
            if(i == idx)
            {                
                if(GetDivControl('tab'+i+'Txt'))
                {
                    GetDivControl('tab'+i+'Txt').className = 'igStyleTabTxt_1';
                    GetDivControl('tabAreaDiv'+i).className = 'itemShow';
                }
            }
            else
            {      
                if(GetTableCellControl('tab'+i))
                {
                    GetTableCellControl('tab'+i).className = 'igStyleTabOff_0';
                    if(GetDivControl('tab'+i+'Txt'))
                    {
                        GetDivControl('tab'+i+'Txt').className = 'igStyleTabTxt_0';
                        GetDivControl('tabAreaDiv'+i).className = 'itemHide';
                    }
                }
            }            
        }                                                 
    }
}


    function Reconnect()
	{    
		var msg = new String();   
		msg = 'Hello...Are you still there?';   
		msg = msg + '\n\nYour current session is about to expire.  For the security of your book of business, Warner Pacific sessions automatically end after 30 minutes of inactivity.';   
		msg = msg + '\n\nYour current session will expire in 2 minutes, at ' + getTimeSessionExpires() + '.';   
		msg = msg + '\n\nIf you wish to continue your current Warner Pacific session, please select the Ok button to renew your session.';   
		msg = msg + '\n\nIf you wish to log off now, please select the Cancel button.';   

		if (confirm(msg))   
		{       
			var now = new Date();       
			var action = new Boolean();       
			action = (g_dttmSessionExpires > now);       
			if (action == true)       
			{           
				window.status = 'Link to Server Refreshed!';           
				var img = new Image(1,1);           
				img.src = 'Reconnect.aspx';       
			}       
			else       
			{           
				location.href='logout.aspx?out=true';       
			}   
		}   
		else   
		{       
			location.href='logout.aspx?out=true';   
		}
	}
	function getTimeSessionExpires()
	{     
		g_dttmSessionExpires = new Date(Date.parse(Date()) + 120000);    
		var dttmSessionExpiresHour = g_dttmSessionExpires.getHours();    
		var dttmSessionExpiresMinute = g_dttmSessionExpires.getMinutes();    
		var strMeridianIndicator = 'AM';    
		if (dttmSessionExpiresHour >= 12)    
		{        
			strMeridianIndicator = 'PM';    
		}    
		if (dttmSessionExpiresHour == 0)    
		{        
			dttmSessionExpiresHour = 12;    
		}    
		else if (dttmSessionExpiresHour > 12)    
		{        
			dttmSessionExpiresHour = (dttmSessionExpiresHour - 12);    
		}    
		if (dttmSessionExpiresMinute < 10)     
		{        
			dttmSessionExpiresMinute = '0' + dttmSessionExpiresMinute;    
		}    
		var strDisplayTime = dttmSessionExpiresHour + ':' + dttmSessionExpiresMinute + ' ' + strMeridianIndicator;    
		
		return strDisplayTime;
	}