﻿function PresentBusyDialog() {
    DivDialog.ShowModalDialog('BusyDialog');
}

function ShowMessage(message) {
    Event.observe(window, 'load', PresentModalDialog);
    document.getElementById("MessagePanel").innerHTML = message; 
}

function PresentModalDialog() {
    DivDialog.ShowModalDialog('MessageDialog');
}

function CloseMessagePanel() {
    DivDialog.CloseDialog();
}

function ShowScreenIFrame(){
    var dde = document.documentElement || document.body;
    var screenIFrame = document.getElementById("ScreenIFrame");
    if(!screenIFrame){
        screenIFrame = document.createElement("iframe");            
        screenIFrame.id = "ScreenIFrame";               
    }
    screenIFrame.style.backgroundColor = "#ffffff";
    screenIFrame.style.position = "absolute"; 
    screenIFrame.style.filter = "alpha(opacity=50)";
    screenIFrame.style.opacity = 0.5;    
    screenIFrame.style.mozOpacity = 0.5;
    screenIFrame.zIndex = 99;	                 
    screenIFrame.display="block";
    screenIFrame.style.width = (dde.scrollWidth > dde.clientWidth ? dde.scrollWidth : dde.clientWidth) - 5 + "px";
    screenIFrame.style.height = (dde.scrollHeight > dde.clientHeight ? dde.scrollHeight : dde.clientHeight) - 5 + "px";
    screenIFrame.style.top = 0;
    screenIFrame.style.left = 0;
    document.body.appendChild(screenIFrame);    
 }

function HideScreenIFrame(){
    var screenIFrame = document.getElementById("ScreenIFrame");   
    if(screenIFrame){
        screenIFrame.style.width = 0;
        screenIFrame.style.height = 0;
        screenIFrame.style.top = 0;
        screenIFrame.style.left = 0;
    }
} 

function HideIFrameBySelf()
{    
    if(window.parent){
        window.parent.HideScreenIFrame();
   } 
    return false;
}

function LocatePopupWindow(popupWin,dialogWidth,dialogHeight){
    popupWin.style.position = "absolute";
   	popupWin.style.display = "block";
	popupWin.style.zIndex = 100;  
    
    if(!dialogWidth)
        var dialogWidth = popupWin.offsetWidth;
    if(!dialogHeight) 
        var dialogHeight = popupWin.offsetHeight;
        
    var dde = document.documentElement;    
    var windowWidth; var windowHeight; var scrollLeft; var scrollTop;   
    if (window.innerWidth){    
        windowWidth = window.innerWidth;    
        windowHeight = window.innerHeight;    
        scrollLeft = window.pageXOffset;    
        scrollTop = window.pageYOffset;
    }else{    
        windowWidth = dde.offsetWidth;    
        windowHeight = dde.offsetHeight;    
        scrollLeft = dde.scrollLeft;    
        scrollTop = dde.scrollTop;    
    }
   
    dialogLeft = scrollLeft + ((windowWidth - dialogWidth)/2);
    dialogTop = scrollTop + ((windowHeight - dialogHeight)/2); 
    
    popupWin.style.width = dialogWidth + "px";
	popupWin.style.height = dialogHeight + "px";	
	popupWin.style.left = dialogLeft + "px";
    popupWin.style.top = dialogTop + "px";
}

function IFrameDialog(){}

IFrameDialog._showDialog = function(url,dialogWidth,dialogHeight){
    var popupWindow = document.getElementById("popupWindow");
    if(popupWindow) return;    
    
	var popupWin = document.createElement("div");
	popupWin.id = "popupWindow";
	popupWin.className = "PopupWindow";
	GenerateConsoleBar(popupWin,'');
	GenerateBodyPanel(popupWin, url);	
	LocatePopupWindow(popupWin,dialogWidth,dialogHeight);	
	document.body.appendChild(popupWin);
	
	document.getElementById("bodyPanel").src = url;
}

IFrameDialog.ShowModalDialog = function(url,dialogWidth,dialogHeight){
    ShowScreenIFrame();
	IFrameDialog._showDialog(url,dialogWidth,dialogHeight);
}

IFrameDialog.ShowDialog = function(url,dialogWidth,dialogHeight){
    IFrameDialog._showDialog(url,dialogWidth,dialogHeight);
}

IFrameDialog.CloseDialog = function() {    
	var popupWin = parent.document.getElementById("popupWindow");
	parent.document.body.removeChild(popupWin);
	HideScreenIFrame();
}

function GenerateConsoleBar(obj,winName) {
	var html = "<div style=\"text-align:right;height:24px;background-color:#fff;\">";
	html += "<input type='button' onclick='IFrameDialog.CloseDialog();' style='margin:1px 5px 1px 0;' value='X' /></div>";
	obj.innerHTML += html;
}

function GenerateBodyPanel(obj,src) {
	var html = "<iframe name=\"bodyPanel\" id=\"bodyPanel\" frameborder=\"0\" scrolling=\"no\" class=\"bodyPanel\"></iframe>";
	obj.innerHTML += html;
}

function SetParentDivWidth(width){
    var popupWin = parent.document.getElementById("popupWindow");
	if(popupWin){
	    popupWin.style.width = width;
	}
}

function DivDialog(){}

DivDialog.CurrentDialogId = "";

DivDialog._showDialog = function(divId,dialogWidth,dialogHeight){
    var dde = document.documentElement;
    var windowWidth; var windowHeight; var scrollLeft; var scrollTop; 
    var popupWindow = document.getElementById(divId);
    LocatePopupWindow(popupWindow,dialogWidth,dialogHeight);
    DivDialog.CurrentDialogId = divId; 
}

DivDialog.ShowModalDialog = function(divId,dialogWidth,dialogHeight){
    ShowScreenIFrame();     
    DivDialog._showDialog(divId,dialogWidth,dialogHeight);      
}

DivDialog.ShowDialog = function(divId,dialogWidth,dialogHeight){
    DivDialog._showDialog(divId,dialogWidth,dialogHeight);
}

DivDialog.CloseDialog = function(){
    var popupWindow = document.getElementById(DivDialog.CurrentDialogId);
    if(popupWindow) 
        popupWindow.style.display = "none";
    HideScreenIFrame();
}


function WinDialog(){}

WinDialog.ShowModalDialog =  function(url,width,height)
{      
    var x = parseInt(screen.width / 2.0) - (width / 2.0);  
    var y = parseInt(screen.height / 2.0) - (height / 2.0); 
    var isMSIE= (navigator.appName == "Microsoft Internet Explorer");  
    if (isMSIE) {           
        retval = window.showModalDialog(url, window, "dialogWidth:"+width+"px; dialogHeight:"+height+"px; dialogLeft:"+x+"px; dialogTop:"+y+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  ); 
       } else { 
        var win = window.open(url, "InternetRadio", "top=" + y + ",left=" + x + ",scrollbars=" + scrollbars + ",dialog=yes,modal=yes,dependance=yes,width=" + width + ",height=" + height + ",resizable=no" ); 
        eval('try { win.resizeTo(width, height); } catch(e) { }'); 
        win.onblur = win.focus; 
        win.focus();             
    } 
}

WinDialog.ShowDialog = function(url,width,height,scrollbars)
{      
    var x = parseInt(screen.width / 2.0) - (width / 2.0);  
    var y = parseInt(screen.height / 2.0) - (height / 2.0); 

    var win = window.open(url, "InternetRadio", "top=" + y + ",left=" + x + ",scrollbars=" + scrollbars + ",dialog=yes,modal=yes,dependance=yes,width=" + width + ",height=" + height + ",resizable=yes" ); 
    eval('try { win.resizeTo(width, height); } catch(e) { }'); 
    win.focus();             
}

WinDialog.OpenFixedWin = function(address, winname, height, width, scrollbars,resizeable) {
	var iHeight = height;
	var iWidth = width;
	var iLeft = (screen.width - iWidth)/2;
	var iTop = (screen.height- iHeight)/2;
	var iScrollbars = scrollbars;
	var iResizeable = resizeable;
	if(iScrollbars == null || iScrollbars=="") iScrollbars = "yes";
	var feature = "left="+iLeft+",top="+iTop+",fullscreen=0,width= " + iWidth + ",height=" + iHeight +",toolbar=no, menubar=no, scrollbars=" + iScrollbars + ", resizable=" + iResizeable+ ", location=no, status=yes";
	var win =window.open(address,winname,feature);	
	win.focus();
	win = null;
}

function SetParentControlValue(controlId,controlValue){
    var input;var parentWin;
    if(window.dialogArguments)
        parentWin =  window.dialogArguments.parent;
    else if(window.opener)
        parentWin =  window.opener;
    else if(window.parent)
        parentWin =  window.parent;
    input = parentWin.document.getElementById(controlId); 
    if((input!=null) && (input!=undefined)){        
        input.value =  controlValue; input.focus();          
        if((typeof(input.onchange) == "function")){       
            input.onchange;
        }
    }
    return false; 
}

function CloseWindow(){
    window.close();
}

function CloseWindowAndReturnValue(rtnValue){
    window.returnValue = rtnValue;
    window.close();
    return false; 
}

function CloseWindowAndReload(buttonId) {
    var isMSIE= (navigator.appName == "Microsoft Internet Explorer");  
    if (isMSIE) {
        window.dialogArguments.parent.document.getElementById(buttonId).click();
    } else {
        window.opener.document.getElementById(buttonId).click();
    } 
    window.close();
    return false; 
}

function MovablePopup(){
    var popup_dragging = false;
    var popup_target;
    var popup_mouseX;
    var popup_mouseY;
    var popup_mouseposX;
    var popup_mouseposY;
    var popup_oldfunction;
    // ----- popup_mousedown -------------------------------------------------------
    function popup_mousedown(e)
    {
    var ie = navigator.appName == "Microsoft Internet Explorer";
    if ( ie && window.event.button != 1) return;
    if (!ie && e.button != 0) return;
    popup_dragging = true;
    popup_target = this['target'];
    popup_mouseX = ie ? window.event.clientX : e.clientX;
    popup_mouseY = ie ? window.event.clientY : e.clientY;
    if (ie)
    popup_oldfunction = document.onselectstart;
    else popup_oldfunction = document.onmousedown;
    if (ie)
    document.onselectstart = new Function("return false;");
    else document.onmousedown = new Function("return false;");
    }
    // ----- popup_mousemove -------------------------------------------------------
    function popup_mousemove(e)
    {
    if (!popup_dragging) return;
    var ie = navigator.appName == "Microsoft Internet Explorer";
    var element = document.getElementById(popup_target);
    var mouseX = ie ? window.event.clientX : e.clientX;
    var mouseY = ie ? window.event.clientY : e.clientY;
    element.style.left = (element.offsetLeft+mouseX-popup_mouseX)+'px';
    element.style.top = (element.offsetTop +mouseY-popup_mouseY)+'px';
    popup_mouseX = ie ? window.event.clientX : e.clientX;
    popup_mouseY = ie ? window.event.clientY : e.clientY;
    }
    // ----- popup_mouseup ---------------------------------------------------------
    function popup_mouseup(e)
    {
    if (!popup_dragging) return;
    popup_dragging = false;
    var ie = navigator.appName == "Microsoft Internet Explorer";
    var element = document.getElementById(popup_target);
    if (ie)
    document.onselectstart = popup_oldfunction;
    else document.onmousedown = popup_oldfunction;
    }
    // ----- popup_mousepos --------------------------------------------------------
    function popup_mousepos(e)
    {
    var ie = navigator.appName == "Microsoft Internet Explorer";
    popup_mouseposX = ie ? window.event.clientX : e.clientX;
    popup_mouseposY = ie ? window.event.clientY : e.clientY;
    }
    // ----- Attach Events ---------------------------------------------------------
    if (navigator.appName == "Microsoft Internet Explorer")
    document.attachEvent('onmousedown', popup_mousepos);
    else document.addEventListener('mousedown', popup_mousepos, false);
    if (navigator.appName == "Microsoft Internet Explorer")
    document.attachEvent('onmousemove', popup_mousemove);
    else document.addEventListener('mousemove', popup_mousemove, false);
    if (navigator.appName == "Microsoft Internet Explorer")
    document.attachEvent('onmouseup', popup_mouseup);
    else document.addEventListener('mouseup', popup_mouseup, false);
}