/**
 * @desc oncall load iframe
 */
function loadIframe(id, rooturl, itemid, stypepage) {
    
    // scroll to top of the page
    window.scrollBy(-10000,-10000);  
    
    // show iframe
    getId('iframe').style.display = 'block';   
            
    // calc page sizes        
    var aPageSize = getPageSize();        
    var iHeightIframe = aPageSize[1]      // depending on height of page set height of iframe
    
    // first load iframe 
    getId(id).innerHTML = "<iframe id=overlayMidContainer name=overlayMidContainer src= " + rooturl + "iframe/image_preview.php?itemid="+ itemid +"&stypepage="+ stypepage +" frameborder=0></iframe>";

    // now set height of the iframe element overlayMidContainer
    getId('overlayMidContainer').style.height = iHeightIframe + 'px';
}

/**
 * @desc oncall closes iframe
 */
function closeIframe() {
    // hide iframe     
    getId('iframe').style.display = 'none';  
                                          
    // remove de iframe
    var iframe = document.getElementById('overlayMidContainer');
    iframe.parentNode.removeChild(iframe); 
}




/**
 * @desc this is a lightbox function
 * @desc calculate page sizes
 * @return array [pageWidth,pageHeight,windowWidth,windowHeight]
 */
function getPageSize(){
    
    var xScroll, yScroll;
    
    if (window.innerHeight && window.scrollMaxY) {    
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    
    var windowWidth, windowHeight;
    if (self.innerHeight) {    // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }    
    
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else { 
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){    
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }


    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
    return arrayPageSize;
}

