// modified the expandcollapse script for use with Rico - 5/14/07
// This function is called from the function below "openLayer"
// It doesn't just hide/show the hidden layer, it takes the x.y adjustments that were passed on your cfm page and "moves" the
// popup layer accordingly.

function RicoexpandCollapse(theobj, callingdiv,topadjust,leftadjust){
            // the following if statement JUST tests if the browser is IE4 or above.  The property "document.all" ONLY exists for IE
            if(document.all){
                adjustForIEscroll = document.body.scrollTop;
            }else{
                adjustForIEscroll = 0;
            }
            // end test for IE
    
    var currobj = document.getElementById(callingdiv);

    //RicoUtil.toViewportPosition() is a function contained in ricoCommon.js I believe....
    var currloc = RicoUtil.toViewportPosition(currobj);
    
    var element = document.getElementById(theobj);
    element.style.visibility = (element.style.visibility == "hidden") ? "visible" : "hidden";
    element.style.display = (element.style.display == "none") ? "block" : "none";
    element.style.top = (parseInt(currloc.y) + adjustForIEscroll + parseInt(topadjust));
    //alert('Y='+parseInt(currloc.y) + '  Scrolltop= '+document.body.scrollTop + ' Div top= '+ element.style.top);
    
    element.style.left = (currloc.x + parseInt(leftadjust));
    
}

// FUNTION: openLayer(objtarget, objcaller,theurl,objhtml,passVariable,topadjust,leftadjust)
// DATE: 5/27/08
// AUTHOR: Mike Zielinski
// FILES NEEDED: prototype.js,rico.js,ricoCommon.js,ricoDragDrop.js,popUpLayer.js
// REQUIRED VARIABLES:
// objtarget = the ID of the hidden div that you want to show
// objcaller = the name of the div that your button is within (you need this div so the browser can determine the x,y coordinates to place the hidden
//                  div when it appears...
// theurl = the name of the coldfusion (or other code page) that you want to run and return... can not be a htm page since this javascript is
//                  "posting" information to it.  htm pages do not run any code... usually this will be a cfm page.
// objhtml = this is the div tag WITHIN your objtarget div tag - everything within this div tag will be replaced with the results of your cfm page
// passVariable = this is the id or whatever information you need to pass to the cfm page
// topadjust = this is the number in pixels you want to offset the popup layer vertically  (positive moves the layer down, negative numbers move up)
// leftadjust = this is the number in pixels you want to offset the popup layer horizontally (positive moves the layer right, negative numbers move left)

// below is the funtion that you will call from your webpage via javascript....

function openLayer(objtarget, objcaller,theurl,objhtml,passVariable,passVariable2,topadjust,leftadjust){
        // the next two lines just test to make sure a number was passed from your webpage - if not, then the adjustment numbers are set to zero
        if(topadjust == undefined || topadjust == 9999){topadjust = document.body.scrollTop}
        
        if(leftadjust == undefined){leftadjust = 0}
        // The next line calls the function at the top of this page, which hides/shows the popup layer and moves it by the pixels you specified 
        // on your cfm page
        RicoexpandCollapse(objtarget, objcaller,topadjust,leftadjust);
        
        var obj = document.getElementById(objhtml);
        
        // passed_variable is the variable that will be available on the cfm code page
        // so the actual page called might look something like:  mycfmpage.cfm?passed_variable=2543
        // On your cfm code page (mycfmpage.cfm), you can reference the passed_variable in your query
         var theopts = '?passed_variable='+passVariable+'&passed_variable2='+passVariable2;
        
        // this is the funtion that actually "calls" your cfm code page.  This function is stored in I believe
        // it is ricoCommon.js javascript file
        new Ajax.Request(theurl+theopts, {method: 'post', onSuccess: function(transport) {
            // if the function successfully calls and executes the cfm page, then the results are placed in the div tag you specified.
            
            obj.innerHTML = transport.responseText;
            
            // innnerHTML is a command in javascript that tells the browser to replace everything between the beginning and the ending
            // div tag specified... So say you had a div tag like the following:  <div ID="thisTag">text goes here</div>
            // you could replace all the html between the opening and closing div tags by writing:
            // document.getElementById('thisTag').innerHTML = 'My new text to go between the divs';
        }
        });    
        
}

function closePopUpLayer(theobj){
         var obj = document.getElementById(theobj);
         obj.style.visibility = 'hidden';
         obj.style.display = 'none';
}

