//-------------------------------------------------------------------------------------
// Contains JavaScript specific to clicking the "Request Information" link to display
// the related form.
//-------------------------------------------------------------------------------------

window.onload = InitReqInfoPage;

var bTestMode = false;

var bIE = (navigator.appName.toString().indexOf("Explorer") > 0) ? true : false;

var bIE8CompatMode = (document.documentMode) ? true : false;

//-------------------------------------------------------------------------------------
// Browser independent (IE, FF) helper function to return a reference to the specified 
// iFrame element. 
//-------------------------------------------------------------------------------------
function $ff(sFrame, bParent) {

    try 
    {
		//IE
		if (bParent)
		{
			return parent.document.frames[sFrame];
		}
		else
		{
			return document.frames[sFrame];
		}
	}
	catch(e)
	{
		//FF
		if (bParent)
		{
			return parent.document.getElementById(sFrame);
		}
		else
		{
			return document.getElementById(sFrame);
		}
	}
}

//-------------------------------------------------------------------------------------
// Get specified cookie value.
//-------------------------------------------------------------------------------------
function GetCookie(sCookies, sName, sDefault) {
	
	if (sCookies == null) return sDefault;

	var iStart = sCookies.indexOf(sName + "=");
	var iEnd;

	if (iStart == -1) {
		// Cookie name not found.
		return sDefault;
	}
	else {
		// Parse out the cookie value.
		iStart = sCookies.indexOf("=", iStart) + 1;
		iEnd   = sCookies.indexOf(";", iStart);
		
		if (iEnd == -1) iEnd = sCookies.length;
		
		return sCookies.substring(iStart, iEnd);
	}		
}

//-------------------------------------------------------------------------------------
// Fires after pages is fully loaded and rendered.
//-------------------------------------------------------------------------------------
function InitReqInfoPage() {
    
    //Testing.
//    try {
//        if ((bTestMode) && (location.toString().indexOf("testpage.asp") > 0 )) {
//            document.getElementById("ReqInfoBox").style.visibility = "visible";
//        }
//    }
//    catch(e){}
   

	//If appropriate, display the Request Initiation frame.	
	//if (document.getElementById("rightnav"))
	//{
		try
		{
			//Show the iframe.
			var oReqInitFrame = parent.document.getElementById("ReqInitFrame");
			oReqInitFrame.style.visibility = "visible";
			oReqInitFrame.style.display    = "inline";
		}
		catch(e) {}
	//}
	
	//If it hasn't already been displayed, display the overlay/popover frame.
	var sCookieName = "OverlayDisplayed";
    var sOverlayDisplayed = GetCookie(document.cookie, sCookieName, "");
    //alert("Cookie Value = " + sOverlayDisplayed);

    //Overlay can be disabled or enabled via the following flag.
    //*** 11/7/2008 *** DAN Overlay disabled per request from Zee LaFon at Streamline.
    var bShowOverlay = false;

    if ((bShowOverlay) && (sOverlayDisplayed != "YES"))
    {
		//Set cookie so overlay/popover not displayed again.
		SetCookie(document, sCookieName, "YES");

		//Display overlay/popover.
		try
		{
			//Hide the iframe.
			var oReqOverlayFrame = parent.document.getElementById("ReqOverlayFrame");
			oReqOverlayFrame.style.visibility = "visible";
			oReqOverlayFrame.style.display    = "inline";
		}
		catch(e) {}
	}

}

//-------------------------------------------------------------------------------------
// Set specified cookie value.
//-------------------------------------------------------------------------------------
function SetCookie(doc, sName, sValue) {

	//Save cookie to expire after one year.
	var oDate = new Date();
	oDate.setYear(oDate.getYear() + 1);
	doc.cookie = sName + "=" + sValue + ";expires=" + oDate;
	
	//Save cookie without specific expiration, which means the cookie expires after 
	//browser session ends.
	//doc.cookie = sName + "=" + sValue + "; "; //Session cookie
}

//-------------------------------------------------------------------------------------
// Displays the Request Information forms's iframe.
//-------------------------------------------------------------------------------------
function ShowReqInfoForm()	{

	//Get reference to the frame containing the dialog/form.
	var oReqInfoFrame = $ff("ReqInfoFrame", true);
	
	var bModal = true;
	
	var oReqInfoBox = document.getElementById("ReqInfoBox");
	
	var iLeft = document.getElementById("container").offsetLeft;
	iLeft += (bIE && !bIE8CompatMode) ?  oReqInfoBox.offsetLeft + 50 : 30;
	
	if (bIE && !bIE8CompatMode) {
	    var iTop = oReqInfoBox.offsetTop + document.getElementById("main").offsetTop;
	}
	else {
	    var iTop = document.getElementById("ReqInfoTriggerImg").offsetTop - 140;
	}
	
	//alert("Container.offsetLeft = " + document.getElementById("container").offsetLeft);
	//alert("oReqInfoBox.offsetLeft = " + oReqInfoBox.offsetLeft);
	//alert("oReqInfoBox.offsetTop = " + oReqInfoBox.offsetTop);
	        
	//alert("bIE = " + bIE + ", iLeft = " + iLeft + ", iTop = " + iTop);
	
	//Display the popup form.
	if (bIE) {
	    try 
	    {
		    //IE
		    oReqInfoFrame.Show(iLeft, iTop, "", "", "", bModal);
	    }
	    catch(ee) {}
	}
	else {
		try 
		{
			//FF
			oReqInfoFrame.contentWindow.Show(iLeft, iTop, "", "", "", bModal);
		}
		catch(ee) {}
	}

}

