//-------------------------------------------------------------------------------------
// Contains JavaScript specific to the "trigger area" used to initiate a user/visitor 
// request for more information.
//-------------------------------------------------------------------------------------

window.onload = InitPage;

var moThisDialog = parent.document.getElementById("ReqInitFrame");	

//-------------------------------------------------------------------------------------
// Initializes the page; fires immediately after the browser loads page. 
//-------------------------------------------------------------------------------------
function InitPage() {

    //Hide Request Information/Free DVD box 3/24/3009.
    //$("Click2ReqBox").style.visibility = "hidden";
    //$("Click2ReqBox").style.display = "none";

    //Attach event handlers on specific page objects/elements.
//    AddEvt($("FirstName"),"focus", SetInputFieldHilite);
//    AddEvt($("FirstName"),"focus", SetInputHdr);
//    AddEvt($("FirstName"), "blur", SetInputFieldHilite);
//    AddEvt($("FirstName"), "blur", SetInputHdr);

//    AddEvt($("FirstNameHdr"), "mouseover", SetInputHdrHilite);
//    AddEvt($("FirstNameHdr"), "mouseout", SetInputHdrHilite);
//    AddEvt($("FirstNameHdr"), "click", SetInputHdr);

//    AddEvt($("LastName"), "focus", SetInputFieldHilite);
//    AddEvt($("LastName"), "focus", SetInputHdr);
//    AddEvt($("LastName"), "blur",  SetInputFieldHilite);
//    AddEvt($("LastName"), "blur",  SetInputHdr);

//    AddEvt($("LastNameHdr"), "mouseover", SetInputHdrHilite);
//    AddEvt($("LastNameHdr"), "mouseout", SetInputHdrHilite);
//    AddEvt($("LastNameHdr"), "click", SetInputHdr);

//    AddEvt($("ZipCode"), "focus", SetInputFieldHilite);
//    AddEvt($("ZipCode"), "focus", SetInputHdr);
//    AddEvt($("ZipCode"), "blur",  SetInputFieldHilite);
//    AddEvt($("ZipCode"), "blur",  SetInputHdr);

//    AddEvt($("ZipCodeHdr"), "mouseover", SetInputHdrHilite);
//    AddEvt($("ZipCodeHdr"), "mouseout", SetInputHdrHilite);
//    AddEvt($("ZipCodeHdr"), "click", SetInputHdr);

//    AddEvt($("Click2ReqTrigger"), "mouseover", SetActionImage);
//    AddEvt($("Click2ReqTrigger"), "mouseout", SetActionImage);
//    AddEvt($("Click2ReqTrigger"), "click", ShowReqInfoForm);

    AddEvt($("Click2ReqTrigger"), "mouseover", SetActionBorder);
    AddEvt($("Click2ReqTrigger"), "mouseout", SetActionBorder);
    AddEvt($("Click2ReqTrigger"), "click", ShowReqInfoForm);

    AddEvt($("Click2ChatTrigger"), "mouseover", SetActionBorder);
    AddEvt($("Click2ChatTrigger"), "mouseout", SetActionBorder);
    //AddEvt($("Click2ChatTrigger"), "click", ShowChatWindow);

    AddEvt($("Click2CallTrigger"), "mouseover", SetActionBorder);
    AddEvt($("Click2CallTrigger"), "mouseout", SetActionBorder);
    //AddEvt($("Click2CallTrigger"), "click", ShowReqInfoForm);

    AddEvt($("Click2AskTrigger"), "mouseover", SetActionBorder);
    AddEvt($("Click2AskTrigger"), "mouseout", SetActionBorder);
    AddEvt($("Click2AskTrigger"), "click", ShowReqAskForm);
    
    //If this object is contained within the "rightnav" DIV tag, show it.
    var oRightNav = parent.document.getElementById("rightnav");
    if (oRightNav) 
    {
		moThisDialog.style.visibility = "visible";
		moThisDialog.style.display = "inline";
    }
    
    
}

//-------------------------------------------------------------------------------------
// Adds/Removes highlighting for an action link.
//-------------------------------------------------------------------------------------
function SetActionHilite(e) {

	var evt = window.event || e;
	var oSrc = evt.srcElement || e.target;
	var sType = evt.type || e.type;

	oSrc.style.color = (sType == "mouseover" || sType == "focus") ? "orange" : "blue";
}

//-------------------------------------------------------------------------------------
// Adds/Removes highlighting for an action header.
//-------------------------------------------------------------------------------------
function SetInputHdrHilite(e) {

    var evt = window.event || e;
    var oSrc = evt.srcElement || e.target;
    var sType = evt.type || e.type;

    oSrc.style.color = (sType == "mouseover" || sType == "focus") ? "orange" : "blue";
}

//-------------------------------------------------------------------------------------
// Displays the appropriate image and changes border color for an action image.
//-------------------------------------------------------------------------------------
function SetActionImage(e) {

    var evt = window.event || e;
    var oSrc = evt.srcElement || e.target;
    var sType = evt.type || e.type;

    if (sType == "mouseover") {
        oSrc.src = "../ReqInfo/Images/ConsoleActionOn.jpg";
        if (oSrc.id == "Click2ReqTrigger") {
            $("Click2ReqImg").style.borderColor = "orange"
        }
    }
    else if (sType == "mouseout") {
        oSrc.src = "../ReqInfo/Images/ConsoleActionOff.jpg";
        if (oSrc.id == "Click2ReqTrigger") {
            $("Click2ReqImg").style.borderColor = "rgb(213,210,206)";
        }
    }
}

//-------------------------------------------------------------------------------------
// Changes the color of the border for a action image.
//-------------------------------------------------------------------------------------
function SetActionBorder(e) {

    var evt = window.event || e;
    var oSrc = evt.srcElement || e.target;
    var sType = evt.type || e.type;

    if (sType == "mouseover") {
        //if (oSrc.id != "Click2ReqTrigger") {
            $("Click2ReqTrigger").style.borderColor = "rgb(213,210,206)"
        //}
        oSrc.style.borderColor = "orange";
    }
    else if (sType == "mouseout") {
        //if (oSrc.id != "Click2ReqTrigger") {
            oSrc.style.borderColor = "rgb(213,210,206)";
        //}
    }
}

//-------------------------------------------------------------------------------------
// Hides or displays the field header.
//-------------------------------------------------------------------------------------
function SetInputHdr(e) {

    var evt = window.event || e;
    var oSrc = evt.srcElement || e.target;
    var sType = evt.type || e.type;
    
    var sName = "";

    if (oSrc.tagName == "LABEL") {
        oSrc.style.visibility = "hidden";
        var i = oSrc.id.indexOf("Hdr");
        sName = oSrc.id.substr(0, i);
        $(sName).focus();
    }
    else {
        if (sType == "focus") {
            sName = oSrc.id + "Hdr"
            $(sName).style.visibility = "hidden";
        }
        else if (sType == "blur") {
            sName = oSrc.id + "Hdr"
            if (oSrc.value.length == 0) {
                $(sName).style.visibility = "visible";
            }
        }
    }  
}

//-------------------------------------------------------------------------------------
// Adds/Removes highlighting for an action header.
//-------------------------------------------------------------------------------------
function SetInputHdrHilite(e) {

    var evt = window.event || e;
    var oSrc = evt.srcElement || e.target;
    var sType = evt.type || e.type;

    oSrc.style.color = (sType == "mouseover") ? "orange" : "rgb(140,140,140)";
}

//-------------------------------------------------------------------------------------
// Displays the "Request Information" iframe.
//-------------------------------------------------------------------------------------
function ShowChatWindow(e) {

    if ($("InstSvcStatus").src.indexOf("Offline") > 0) {
        alert("Need to get email window to show");
    }
    else {
        ShowInstantServiceChatWindow();
    }

}

//-------------------------------------------------------------------------------------
// Displays the "Ask a Question" iframe.
//-------------------------------------------------------------------------------------
function ShowReqAskForm(e) {

    var evt = window.event || e;
    var oSrc = evt.srcElement || e.target;
    var sType = evt.type || e.type;

    //Get reference to the frame containing the trigger object.
    var oReqInitFrame = null;
    oReqInitFrame = $f("ReqInitFrame", true);

    //Get reference to the frame containing the dialog/form.
    var oReqFrame = null;
    oReqFrame = $f("ReqAskFrame", true);

    //If the window is already displayed, get outta here.
    //if (oReqFrame.IsVisible()) return;
    //if (oReqFrame.frameElement.style.visibility == "visible") return;

    //Get the containing object that drives the top position of the "window" to be displayed.
    var sReqInitContainer = $fAttr(oReqInitFrame, "ContainerBox");
    var oReqInitContainer = parent.window.document.getElementById(sReqInitContainer);

    //Get the containing object that drives the left position of the "window" to be displayed.
    var sReqInfoContainer = $fAttr(oReqFrame, "ContainerBox");
    var oReqInfoContainer = parent.window.document.getElementById(sReqInfoContainer);

    //Get the top position of the iframe object containing the trigger object.
    try {
        //IE
        var iReqInitTop = oReqInitFrame.frameElement.offsetTop;

        //Get the width and height of the "window" to be displayed. 
        var iReqInfoWidth = oReqFrame.document.body.offsetWidth;
        var iReqInfoHeight = oReqFrame.document.body.offsetHeight;
    }
    catch (ee) {
        //FF
        var iReqInitTop = oReqInitFrame.offsetTop;
        var iReqInitTop = 46;

        //Get the width and height of the "window" to be displayed.
        var iReqInfoWidth = oReqFrame.offsetWidth;
        var iReqInfoHeight = oReqFrame.offsetHeight;
    }


    //Set the left and top position of the "window" to be displayed.
    var iLeft = (oReqInfoContainer.offsetLeft + oReqInfoContainer.offsetWidth) - (iReqInfoWidth + 140);
    //var iTop = (oReqInitContainer.offsetTop + iReqInitTop + oSrc.offsetTop) - (iReqInfoHeight - 40);
    var iTop = (oReqInitContainer.offsetTop + iReqInitTop + 60);

    //See if the objects in the background should be inaccessible, effectively making the window
    //"modal" in nature.
    var bModal = ($fAttr(oReqFrame, "Modal") == "yes") ? true : false;

    //Display the popup form.
    try {
        //IE
        oReqFrame.Show(iLeft, iTop, bModal);
    }
    catch (ee) {
        //FF
        oReqFrame.contentWindow.Show(iLeft, iTop, bModal);
    }
}

//-------------------------------------------------------------------------------------
// Displays the "Request Information" iframe.
//-------------------------------------------------------------------------------------
function ShowReqInfoForm(e)	{

	var evt = window.event || e;
	var oSrc = evt.srcElement || e.target;
	var sType = evt.type || e.type;

	var sFirstName = $("FirstName").value;
	var sLastName  = $("LastName").value;
	var sZipCode   = $("ZipCode").value;
    
    //Get reference to the frame containing the trigger object.
    var oReqInitFrame = null;
	oReqInitFrame = $f("ReqInitFrame", true);
	
	//Get reference to the frame containing the dialog/form.
    var oReqFrame = null;
	oReqFrame = $f("ReqInfoFrame", true);
	
	//If the window is already displayed, get outta here.
	//if (oReqFrame.IsVisible()) return;
	//if (oReqFrame.frameElement.style.visibility == "visible") return;
	
	//Get the containing object that drives the top position of the "window" to be displayed.
	var sReqInitContainer = $fAttr(oReqInitFrame,"ContainerBox");
	var oReqInitContainer = parent.window.document.getElementById(sReqInitContainer);
	
	//Get the containing object that drives the left position of the "window" to be displayed.
	var sReqInfoContainer = $fAttr(oReqFrame,"ContainerBox");
	var oReqInfoContainer = parent.window.document.getElementById(sReqInfoContainer);

	//Get the top position of the iframe object containing the trigger object.
	try 
	{
		//IE
		var iReqInitTop = oReqInitFrame.frameElement.offsetTop;
		
		//Get the width and height of the "window" to be displayed. 
		var iReqInfoWidth  = oReqFrame.document.body.offsetWidth;
		var iReqInfoHeight = oReqFrame.document.body.offsetHeight;
	}
	catch(ee) 
	{
		//FF
		var iReqInitTop = oReqInitFrame.offsetTop;
		var iReqInitTop = 46;
		
		//Get the width and height of the "window" to be displayed. 
		var iReqInfoWidth  = oReqFrame.offsetWidth;
		var iReqInfoHeight = oReqFrame.offsetHeight;
	}
	
	
	//Set the left and top position of the "window" to be displayed.
	var iLeft = (oReqInfoContainer.offsetLeft + oReqInfoContainer.offsetWidth) - (iReqInfoWidth + 50); 
	var iTop  = (oReqInitContainer.offsetTop + iReqInitTop + oSrc.offsetTop) - (iReqInfoHeight - 40);
	
	//See if the objects in the background should be inaccessible, effectively making the window
	//"modal" in nature.
	var bModal = ($fAttr(oReqFrame, "Modal") == "yes") ? true : false;
	
	//Display the popup form.
	try 
	{
		//IE
		oReqFrame.Show(iLeft, iTop, sFirstName, sLastName, sZipCode, bModal);
	}
	catch(ee) 
	{
		//FF
		oReqFrame.contentWindow.Show(iLeft, iTop, sFirstName, sLastName, sZipCode, bModal);
	}
}
