﻿function Softsmart_Dialog_Show(){
	window.onresize = Softsmart_Dialog_RecalcHeightWidth;
	window.onscroll = Softsmart_Dialog_RecalcHeightWidth;
	Softsmart_Dialog_RecalcHeightWidth();
	
	document.getElementById('Softsmart_Dialog_Background').className = 'Softsmart_Dialog_Background';
	document.getElementById('Softsmart_Dialog_Window').className = 'Softsmart_Dialog_Window';
}

function Softsmart_Dialog_Close(){
	window.onresize = null;
	
	var object = document.getElementById('Softsmart_Dialog_Background');
	object.className = 'Softsmart_Dialog_Hide';
	
	object = document.getElementById('Softsmart_Dialog_Window');
	object.className = 'Softsmart_Dialog_Hide';
}

function Softsmart_Dialog_RecalcHeightWidth(){
	var object = document.getElementById('Softsmart_Dialog_Background');
	object.style.height = Softsmart_Dialog_GetDocumentHeight() + "px";
	object.style.width = Softsmart_Dialog_GetDocumentWidth() + "px";
    object = document.getElementById('Softsmart_Dialog_Window');
    
	var left = (document.width ? document.width : document.body.offsetWidth);
	left = ((Softsmart_Dialog_GetDocumentWidth() - 640) / 2); if (left < 5){left = 5;}
	object.style.left = left + "px";
    
	var top = (Softsmart_Dialog_GetScrollTop() + 10);
	object.style.top = top + "px";
}

function Softsmart_Dialog_GetDocumentHeight(){
	var height = 0, scrollHeight, offsetHeight, docHeight, clientHeight;
    
	if (document.height){height = document.height;}
		
	if (document.body){
		if (document.body.scrollHeight){scrollHeight = document.body.scrollHeight;}
		if (document.body.offsetHeight){offsetHeight = document.body.offsetHeight;}
		if (scrollHeight && offsetHeight){height = Math.max(scrollHeight, offsetHeight);}
	}
    
	if (document.documentElement.scrollHeight){docHeight = document.documentElement.scrollHeight;}
	if (docHeight){height = Math.max(height, docHeight);}
    
	if (document.documentElement.clientHeight){clientHeight = document.documentElement.clientHeight;}
	if (clientHeight){height = Math.max(height, clientHeight);}

	return height;
}

function Softsmart_Dialog_GetDocumentWidth(){
	var width = 0, scrollWidth, offsetWidth;

	if (document.width){
		width = document.width + 20;
        
	} else if (document.body){
		if (document.body.scrollWidth){width = scrollWidth = document.body.scrollWidth;}
		if (document.body.offsetWidth){width = offsetWidth = document.body.offsetWidth;}
		if (scrollWidth && offsetWidth){width = Math.max(scrollWidth, offsetWidth);}
		
		width = width + 36;
	}

   return width - 21;
}		

function Softsmart_Dialog_GetScrollTop(){
	var scrollTop = document.body.scrollTop;

	if (scrollTop == 0){
		if (window.pageYOffset){
			scrollTop = window.pageYOffset;

		} else {
			scrollTop = ((document.body.parentElement) ? document.body.parentElement.scrollTop : 0);
		}
	}
	
	return scrollTop;
}
