// the full window dimensions array's function
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-17; //remove the scroll bar width
        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;
}

//faster & shorter function that get only the window width
//to save CPU usage waste & improve performances  
//         
function GetWindowWidth() 
{
    var xScroll;
    if (window.innerHeight && window.scrollMaxY) {	
        xScroll = document.body.scrollWidth;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
    }
    var windowWidth;
    if (self.innerHeight) {	// all except Explorer
        windowWidth = self.innerWidth;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
    }
    var getPageWidth;
    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){	
        getPageWidth = windowWidth;
    } else {
        getPageWidth = xScroll;
    }
    return getPageWidth;
}

// This function shows a transparent mask with the window dimensions
function ShowMask(el, status){
	
	var PageDimensions = GetPageSize();
	document.getElementById(el).style.height = PageDimensions[1]+'px';
	document.getElementById(el).style.width = PageDimensions[0]+'px';
	document.getElementById(el).style.display= status; //opens a transparent gray mask under the div.
	/*
	if (typeof(window.top.FR04.FR05.FR_ANEXO0) == "object")
	{
		if (typeof(window.top.FR04.FR05.FR_ANEXO0.ShowGreyMask) == "function")
		{
	*/
	if (typeof(showAdditionalGreyMask) == "boolean")
	{
		if (showAdditionalGreyMask)
			window.top.FR04.FR05.FR_ANEXO0.ShowGreyMask(status);
	}
	/*
		}
	}
	*/
}

/*
    place dialog in the center of the screen;
    TO USE THIS FUNCTION- PLEASE SET THE DIALOG POSITION TO FIXED for !IE6 !!!!!
    Please call js/CFramework/browserDetection.js before calling this file, in order to receieve 
    the Browser Object
*/ 
function CenterDialog(dialogId){
    var dialog = document.getElementById(dialogId);
    var PageDimensions = GetPageSize();
    dialog.style.left = PageDimensions[2]/2-dialog.offsetWidth/2;
    if (self.innerHeight) {	// all except Explorer
        dialog.style.top = PageDimensions[3]/2-dialog.offsetHeight/2;
    }
}

function ResizeWindow(el,contentWidth){
    var divPagamento = document.getElementById(el);
    var windowWidth = GetWindowWidth();
    if(windowWidth<=contentWidth){
        divPagamento.style.width = contentWidth+'px';
    }else{
        divPagamento.style.width = 100+'%';   
    }
}
