

//POP UP//


 //OPENS & CLOSES DIVS BASED ON ID//
 
 function OpenDiv(obj) {
            ShowBackgroundDiv()
            ShowNav(obj);

         }


   function CloseDiv(obj){
            HideBackgroundDiv()
            document.getElementById(obj).style.display = "none";
         }

// Center Div on Screen  
function CenterDiv(DivObject)
{
    //POSITION IN CENTER OF SCREEN
    var iLeft, iTop, iTotalWidth, iTotalHeight, iScrollOffsetX, iScrollOffsetY; 

    iTotalWidth = (window.opera ? window.innerWidth : document.documentElement.clientWidth);  
    iTotalHeight = (window.opera ? window.innerHeight : document.documentElement.clientHeight);    
    iScrollOffsetX = document.documentElement.scrollLeft;
    iScrollOffsetY = document.documentElement.scrollTop;    

    DivObject.style.display = "block";

    iLeft = (iTotalWidth / 2) + iScrollOffsetX - (DivObject.clientWidth / 2);
    iTop = (iTotalHeight / 2) + iScrollOffsetY - (DivObject.clientHeight / 2);       

    DivObject.style.left = iLeft + "px"; 
    DivObject.style.top = iTop + "px";          
}

function ParentCenterDiv(DivObject)
{
    //POSITION IN CENTER OF SCREEN
    var iLeft, iTop, iTotalWidth, iTotalHeight, iScrollOffsetX, iScrollOffsetY; 

    iTotalWidth = (parent.window.opera ? parent.window.innerWidth : parent.document.documentElement.clientWidth);  
    iTotalHeight = (parent.window.opera ? parent.window.innerHeight : parent.document.documentElement.clientHeight);    
    iScrollOffsetX = parent.document.documentElement.scrollLeft;
    iScrollOffsetY = parent.document.documentElement.scrollTop;    

    DivObject.style.display = "block";

    iLeft = (iTotalWidth / 2) + iScrollOffsetX - (DivObject.clientWidth / 2);
    iTop = (iTotalHeight / 2) + iScrollOffsetY - (DivObject.clientHeight / 2);       

    DivObject.style.left = iLeft + "px"; 
    DivObject.style.top = iTop + "px";          
}

// Creates Dim Black Background Div
function ShowBackgroundDiv()
{
    var divBackground = document.getElementById("_divBackground");
    var ifBackground = document.getElementById("_ifBackground");
    var iScrollOffsetX = (window.opera ? 0 : document.documentElement.scrollLeft);
    var iScrollOffsetY = (window.opera ? 0 : document.documentElement.scrollTop); 

    if (divBackground == null)
    {
        divBackground = document.createElement('DIV');
        divBackground.id = '_divBackground';    
        divBackground.style.zIndex = 100000;
        divBackground.style.backgroundColor = "#AAAAAA";
        divBackground.style.opacity = 0.5;
        divBackground.style.filter = "alpha(opacity=50)";
        divBackground.style.position = "absolute";
        document.body.appendChild(divBackground);
    }

    if (document.all && !window.opera && ifBackground == null)
    {
        ifBackground = document.createElement('IFRAME');
        ifBackground.id = '_ifBackground';    
        ifBackground.style.zIndex = 99999;
        ifBackground.style.backgroundColor = "#AAAAAA";
        ifBackground.style.opacity = 0.5;
        ifBackground.style.filter = "alpha(opacity=50)";
        ifBackground.style.position = "absolute"; 
        document.body.appendChild(ifBackground);      
    }
    
    divBackground.style.width = (document.documentElement.scrollWidth ? document.documentElement.scrollWidth : document.width) + "px";
    divBackground.style.height = ReturnMaxHeight() + "px";
    divBackground.style.left = iScrollOffsetX + "px";
    divBackground.style.top = "0px";
    divBackground.style.overflow = "hidden";
    divBackground.style.display = "block";  
    

    if (ifBackground != null)
    {
        ifBackground.style.width = (document.width ? document.width : document.documentElement.clientWidth) + "px";
        ifBackground.style.height = (document.height ? document.height : document.documentElement.clientHeight) + "px";    
        ifBackground.style.left = iScrollOffsetX + "px";
        ifBackground.style.top = iScrollOffsetY + "px";    
        ifBackground.style.display = "block";  
    }
}

// Creates Dim Black Background Div
function ParentShowBackgroundDiv()
{
    var divBackground = parent.document.getElementById("_divBackground");
    var ifBackground = parent.document.getElementById("_ifBackground");
    var iScrollOffsetX = (window.opera ? 0 : parent.document.documentElement.scrollLeft);
    var iScrollOffsetY = (window.opera ? 0 : parent.document.documentElement.scrollTop); 

    if (divBackground == null)
    {
        divBackground = parent.document.createElement('DIV');
        divBackground.id = '_divBackground';    
        divBackground.style.zIndex = 100000;
        divBackground.style.backgroundColor = "#AAAAAA";
        divBackground.style.opacity = 0.5;
        divBackground.style.filter = "alpha(opacity=50)";
        divBackground.style.position = "absolute";
        parent.document.body.appendChild(divBackground);
    }

    if (document.all && !window.opera && ifBackground == null)
    {
        ifBackground = parent.document.createElement('IFRAME');
        ifBackground.id = '_ifBackground';    
        ifBackground.style.zIndex = 99999;
        ifBackground.style.backgroundColor = "#AAAAAA";
        ifBackground.style.opacity = 0.5;
        ifBackground.style.filter = "alpha(opacity=50)";
        ifBackground.style.position = "absolute"; 
        parent.document.body.appendChild(ifBackground);      
    }
    
    divBackground.style.width = (parent.document.documentElement.scrollWidth ? parent.document.documentElement.scrollWidth : parent.document.width) + "px";
    divBackground.style.height = ParentReturnMaxHeight() + "px";
    divBackground.style.left = iScrollOffsetX + "px";
    divBackground.style.top = "0px";
    divBackground.style.overflow = "hidden";
    divBackground.style.display = "block";  
    

    if (ifBackground != null)
    {
        ifBackground.style.width = (parent.document.width ? parent.document.width : parent.document.documentElement.clientWidth) + "px";
        ifBackground.style.height = (parent.document.height ? parent.document.height : parent.document.documentElement.clientHeight) + "px";    
        ifBackground.style.left = iScrollOffsetX + "px";
        ifBackground.style.top = iScrollOffsetY + "px";    
        ifBackground.style.display = "block";  
    }
}

// Finds The Maximum Height of Screen
function ReturnMaxHeight()
{
    var iReturn = document.documentElement.scrollHeight;

    if (document.documentElement.clientHeight > iReturn) iReturn = document.documentElement.clientHeight;
    if (document.documentElement.height > iReturn) iReturn = document.documentElement.height;
    if (document.height > iReturn) iReturn = document.height;
    if (document.body.clientHeight > iReturn) iReturn = document.body.clientHeight;
    if (window.innerHeight > iReturn) iReturn = window.innerHeight;
    
    if (document.documentElement.scrollHeight > document.documentElement.clientHeight) iReturn = document.documentElement.clientHeight;
    
    return (iReturn > 2000 ? 2000 : iReturn);  //CAP THE HEIGHT AT 2000, OTHERWISE IE ALLOCATES A LOT OF MEMORY FOR THE DIV
}

// Finds The Maximum Height of Screen
function ParentReturnMaxHeight()
{
    var iReturn = parent.document.documentElement.scrollHeight;

    if (parent.document.documentElement.clientHeight > iReturn) iReturn = parent.document.documentElement.clientHeight;
    if (parent.document.documentElement.height > iReturn) iReturn = parent.document.documentElement.height;
    if (parent.document.height > iReturn) iReturn = parent.document.height;
    if (parent.document.body.clientHeight > iReturn) iReturn = parent.document.body.clientHeight;
    if (parent.window.innerHeight > iReturn) iReturn = parent.window.innerHeight;
    
    if (parent.document.documentElement.scrollHeight > parent.document.documentElement.clientHeight) iReturn = parent.document.documentElement.clientHeight;
    
    return (iReturn > 2000 ? 2000 : iReturn);  //CAP THE HEIGHT AT 2000, OTHERWISE IE ALLOCATES A LOT OF MEMORY FOR THE DIV
}

// Hides background div as well as all popup divs
function HideBackgroundDiv()
{
    var divBackground = document.getElementById("_divBackground");
    var ifBackground = document.getElementById("_ifBackground");
    var divNote = document.getElementById("divNote");
    var divHelp = document.getElementById("divHelp");
    var divProduct = document.getElementById("divProduct");
    var divAddQues= document.getElementById("divAddQues");
    var divAddQues2= document.getElementById("divAddQues2");
    var divAssignScores= document.getElementById("divAssignScores");

    if (divBackground != null) divBackground.style.display = "none";
    if (ifBackground != null) ifBackground.style.display = "none";
    if (divNote != null) divNote.style.display = "none";
    if (divHelp != null) divHelp.style.display = "none";
    if (divProduct != null) divProduct.style.display = "none";
    if (divAddQues != null) divAddQues.style.display = "none";
    if (divAddQues2 != null) divAddQues2.style.display = "none";
    if (divAssignScores != null) divAssignScores.style.display = "none";
    
   
}

function HideParentBackgroundDiv()
{
    var divBackground = parent.document.getElementById("_divBackground");
    var ifBackground = parent.document.getElementById("_ifBackground");
    var divNote = document.getElementById("divNote");
    var divHelp = document.getElementById("divHelp");
    var divProduct = document.getElementById("divProduct");
    var divAddQues= document.getElementById("divAddQues");
    var divAddQues2= document.getElementById("divAddQues2");
    var divAssignScores= document.getElementById("divAssignScores");

    if (divBackground != null) divBackground.style.display = "none";
    if (ifBackground != null) ifBackground.style.display = "none";
    if (divNote != null) divNote.style.display = "none";
    if (divHelp != null) divHelp.style.display = "none";
    if (divProduct != null) divProduct.style.display = "none";
    if (divAddQues != null) divAddQues.style.display = "none";
    if (divAddQues2 != null) divAddQues2.style.display = "none";
    if (divAssignScores != null) divAssignScores.style.display = "none";  
}

// Opens Navigation Div
function ShowNav(id)
{
    
    if(document.getElementById(id).style.display == "block"){
        HideBackgroundDiv()
        }
    else{
        CenterDiv(document.getElementById(id));
        
    }
}

function PositionDiv(DivObject, PositionObject, BodyWidth, ShowOffset)

{

    var iBodyWidth = BodyWidth, iBodyHeight = 0; 

    var iLef = 0, iTop = 0, iTotalWidth = 0, iTotalHeight = 0, iScrollOffsetX = 0, iScrollOffsetY = 0; 

    var iPositionObjHeight = 0, iPositionObjWidth = 0, iPositionObjX = 0, iPositionObjY = 0;



    iBodyHeight = 30; 

    

    iTotalWidth = document.documentElement.clientWidth;  

    iTotalHeight = document.documentElement.clientHeight;    

    iScrollOffsetX = (window.opera ? 0 : (window.pageXOffset ? window.pageXOffset : document.documentElement.scrollLeft));

    iScrollOffsetY = (window.opera ? 0 : (window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop)); 

    

    iPositionObjHeight = (PositionObject.clientHeight ? PositionObject.clientHeight : PositionObject.height);

    iPositionObjWidth = (PositionObject.clientWidth ? PositionObject.clientWidth : PositionObject.width);    

   
   

    if ((iTotalWidth - ((iPositionObjX - iScrollOffsetX) + iPositionObjWidth)) < iBodyWidth) 

    {           

        iLeft = iPositionObjX - ((ShowOffset ? iBodyWidth + 5 : 0));	//POSITION IS ON RIGHT EDGE, SHOW DIV TO THE LEFT         

    } 

    else 

    { 

        iLeft = iPositionObjX + (ShowOffset ? iPositionObjWidth : 900);	//SHOW DIV TO THE RIGHT 

    } 

    

    if (iLeft + iBodyWidth + 20 > iTotalWidth)

    {        

        iLeft = iTotalWidth - iBodyWidth - 20 + iScrollOffsetX;        

    } 

   

    //MOVE THE DIV OFF THE SCREEN AND SHOW IT SO WE CAN GET ITS DIMENSIONS

    DivObject.style.left = "-10000px"; 

    DivObject.style.top = "-10000px";    

    DivObject.style.display = "block";   

    iBodyHeight = DivObject.clientHeight;    

       

    var bIsDownOK = ((iPositionObjY + iBodyHeight) < (iTotalHeight));

    var bIsUpOK = ((iPositionObjY - iBodyHeight) > 0);



    if (!bIsDownOK && !bIsUpOK) 

    {   

        iTop = iPositionObjY - (iBodyHeight / 2);	//SHOW IN THE MIDDLE, DOWN AND UP WOULD CUT IMAGE 

    } 

    else if (bIsDownOK || !bIsUpOK) 

    {

        iTop = iPositionObjY + iPositionObjHeight + (ShowOffset ? 0 : 2);	//SHOW DIV DOWN 

    } 

    else 

    {               

        iTop = iPositionObjY - iBodyHeight - (ShowOffset ? 0 : 2);	//POSITION IS TOO FAR DOWN, SHOW DIV UP 

    }    

    

    iTop += iScrollOffsetY;  

   

    if(!document.all)   

    {

        iLeft += "px";

        iTop += "px";

        iBodyWidth += "px";

    }

            

    //NEED TO SHOW THE DIV BEFORE WE GET THE CLIENT HEIGHT

    DivObject.style.left = iLeft; 

    DivObject.style.top = iTop; 

    DivObject.style.width = iBodyWidth; 

}



function CenterDiv(DivObject)

{

    //POSITION IN CENTER OF SCREEN

    var iLeft, iTop, iTotalWidth, iTotalHeight, iScrollOffsetX, iScrollOffsetY; 

    

    iTotalWidth = (window.opera ? window.innerWidth : document.documentElement.clientWidth);  

    iTotalHeight = (window.opera ? window.innerHeight : document.documentElement.clientHeight);    

    iScrollOffsetX = (window.pageXOffset ? window.pageXOffset : document.documentElement.scrollLeft);

    iScrollOffsetY = (window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop); 	

    

    //MOVE THE DIV OFF THE SCREEN AND SHOW IT SO WE CAN GET ITS DIMENSIONS

    DivObject.style.left = "-10000px"; 

    DivObject.style.top = "-10000px";

    DivObject.style.display = "block";

                            

    iLeft = (iTotalWidth / 2) + iScrollOffsetX - (DivObject.clientWidth / 2);

    iTop = (iTotalHeight / 2) + iScrollOffsetY - (DivObject.clientHeight / 2);       



    DivObject.style.left = iLeft + "px"; 

    DivObject.style.top = iTop + "px";          

}



function CenterDivInsideObject(DivObject, ContainerObject)

{

    var iLeft, iTop, iTotalWidth, iTotalHeight, iScrollOffsetX, iScrollOffsetY; 

    

    iTotalWidth = ContainerObject.clientWidth;  

    iTotalHeight = ContainerObject.clientHeight;    

    iScrollOffsetX = ContainerObject.scrollLeft;

    iScrollOffsetY = ContainerObject.scrollTop; 	

    

    DivObject.style.display = "block";

                            

    iLeft = (iTotalWidth / 2) + iScrollOffsetX - (DivObject.clientWidth / 2);

    iTop = (iTotalHeight / 2) + iScrollOffsetY - (DivObject.clientHeight / 2);       



    DivObject.style.left = iLeft + "px"; 

    DivObject.style.top = iTop + "px";  

}

function ShowBackgroundDiv()

{

    var divBackground = document.getElementById("_divBackground");

    var ifBackground = document.getElementById("_ifBackground");

    var iScrollOffsetX = 0;

    var iScrollOffsetY = (window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop); 

    var iDivHeight = ReturnMaxHeight();



    if (divBackground == null)

    {

        divBackground = document.createElement('DIV');

        divBackground.id = '_divBackground';    

        divBackground.style.zIndex = 100000;

        divBackground.style.backgroundColor = "#AAAAAA";

        divBackground.style.opacity = 0.6;

        divBackground.style.filter = "alpha(opacity=60)";

        divBackground.style.position = "absolute";

        document.body.appendChild(divBackground);

    }



    if (document.all && !window.opera && ifBackground == null)

    {

        ifBackground = document.createElement('IFRAME');

        ifBackground.id = '_ifBackground';    

        ifBackground.style.zIndex = 99999;

        ifBackground.style.backgroundColor = "#AAAAAA";

        ifBackground.style.opacity = 0.6;

        ifBackground.style.filter = "alpha(opacity=60)";

        ifBackground.style.position = "absolute";  

        document.body.appendChild(ifBackground);      

    }

    

    if (iScrollOffsetY > 0 && (iScrollOffsetY - (iDivHeight / 2)) > 0) //IF THE PAGE IS SCROLLED, HAVE THE DIV COVER ABOVE AND BELOW IT EQUALLY

    {

        iScrollOffsetY = (iScrollOffsetY - (iDivHeight / 2));

    }

    else

    {

        iScrollOffsetY = 0;

    }

    

    divBackground.style.width = (document.documentElement.scrollWidth ? document.documentElement.scrollWidth : document.width) + "px";

    divBackground.style.height = iDivHeight + "px";

    divBackground.style.left = "0px";

    divBackground.style.top = iScrollOffsetY + "px";

    divBackground.style.display = "block";   

    

    if (ifBackground != null)

    {

        ifBackground.style.width = (document.width ? document.width : document.documentElement.clientWidth) + "px";

        ifBackground.style.height = (document.height ? document.height : document.documentElement.clientHeight) + "px";    

        ifBackground.style.left = "0px";

        ifBackground.style.top = iScrollOffsetY + "px";    

        ifBackground.style.display = "block";  

    }

}



function ReturnMaxHeight()

{

    var iReturn = document.documentElement.scrollHeight;

    

    if (document.documentElement.clientHeight > iReturn) iReturn = document.documentElement.clientHeight;

    if (document.documentElement.height > iReturn) iReturn = document.documentElement.height;

    if (document.height > iReturn) iReturn = document.height;

    if (document.body.clientHeight > iReturn) iReturn = document.body.clientHeight;

    if (window.innerHeight > iReturn) iReturn = window.innerHeight;

    

    return (iReturn > 2000 ? 2000 : iReturn);  //CAP THE HEIGHT AT 2000, OTHERWISE IE ALLOCATES A LOT OF MEMORY FOR THE DIV

}



//function HideBackgroundDiv()

//{

    //var divBackground = document.getElementById("_divBackground");

    //var ifBackground = document.getElementById("_ifBackground");

    

    //if (divBackground != null) divBackground.style.display = "none";

    //if (ifBackground != null) ifBackground.style.display = "none";  

//}


//TOGGLE SHOW HIDE
function toggle(showHideDiv, switchImgTag) {
        var ele = document.getElementById(showHideDiv);
        var imageEle = document.getElementById(switchImgTag);
        if(ele.style.display == "block") {
                ele.style.display = "none";
		       
        }
        else {
                ele.style.display = "block";
               
        }
}


