var handleSubmit = function() {
    this.submit();
};     
var handleCancel = function() {
    this.cancel();
};        



function passwordDialog() {
    YAHOO.util.Dom.removeClass("passwordDialog", "yui-pe-content");
    var thisStatus = YAHOO.util.Dom.get('resp');
    
    var handleSubmit = function() {
        this.submit();
        thisStatus.innerHTML = "<img src=/images/ajax-loader.gif>";
    };
    var handleSuccess = function(o) {
        thisStatus.innerHTML = o.responseText;
    };

    mDialog = new YAHOO.widget.Dialog("passwordDialog", 
        { fixedcenter: true,
                    visible: false,
                    width: "25em",
                    close: true,
                    constraintoviewport : true,
                    buttons : [ { text:"Submit", handler:handleSubmit }, { text:"Cancel", handler:handleCancel, isDefault:true } ]
        });      
    mDialog.callback = { success: handleSuccess };
        
    mDialog.render();
    YAHOO.util.Event.addListener("showPassDialog", "click", mDialog.show, mDialog, true);            
}




function portalDialog() {
    YAHOO.util.Dom.removeClass("portalDialog", "yui-pe-content");
    pDialog = new YAHOO.widget.Dialog("portalDialog", 
        { fixedcenter: true,
                    visible: false,
                    close: true,
                    draggable: true,
                    constraintoviewport : true,
                    modal: true
        } );
    pDialog.render();
    YAHOO.util.Event.addListener("showPDialog", "click", pDialog.show, pDialog, true);     
}




function serverDialog() {
    /* new server set up */
    YAHOO.util.Dom.removeClass("serverDialog", "yui-pe-content");
    var handleSubmit = function() {
        this.submit();
        var thisStatus = YAHOO.util.Dom.get('serverStatus');
        thisStatus.innerHTML = "<img src=/images/ajax-loader.gif>";
    };
    var handleSuccess = function(o) {
        alert(o.responseText);
    };
    sDialog = new YAHOO.widget.Dialog("serverDialog", 
        { fixedcenter: true,
                    visible: false,
                    close: true,
                    draggable: true,
                    constraintoviewport : true,
                    buttons : [ { text:"Submit", handler:handleSubmit }, { text:"Cancel", handler:handleCancel, isDefault:true } ]
        });      
    sDialog.callback = { success: handleSuccess };        
    sDialog.render();
    
    YAHOO.util.Event.addListener("showSDialog", "click", sDialog.show, sDialog, true);   
}



/*
function cfDialog() {
    YAHOO.util.Dom.removeClass("cfDialog", "yui-pe-content");
    var handleSubmit = function() {
        this.submit();
    };
    var handleSuccess = function(o) {
        alert(o.responseText);
    };
    sDialog = new YAHOO.widget.Dialog("cfDialog", 
        { fixedcenter: true,
                    visible: false,
                    close: true,
                    draggable: true,
                    constraintoviewport : true,
                    buttons : [ { text:"Submit", handler:handleSubmit }, { text:"Cancel", handler:handleCancel, isDefault:true } ]
        });      
    sDialog.callback = { success: handleSuccess };        
    sDialog.render();
    
    YAHOO.util.Event.addListener("showCFDialog", "click", sDialog.show, sDialog, true);   
}
*/



function phoneDialog() {
    YAHOO.util.Dom.removeClass("phoneDialog", "yui-pe-content");
    pDialog = new YAHOO.widget.SimpleDialog("phoneDialog", 
        { fixedcenter: true,
                    width: "200px",
                    visible: false,
                    close: true,
                    draggable: true,
                    constraintoviewport : true,
                    buttons: [ { text:"Close", handler: function(){this.hide();}, isDefault:true }] 
        });    
    pDialog.render();  
    YAHOO.util.Event.addListener("showPhoneDialog", "click", pDialog.show, pDialog, true);   
}



function databaseDialog() {
    YAHOO.util.Dom.removeClass("databaseDialog", "yui-pe-content");
    var handleSubmit = function() {
        this.submit();
        var thisStatus = YAHOO.util.Dom.get('serverStatus');
        thisStatus.innerHTML = "<img src=/images/ajax-loader.gif>";
    };
    var handleSuccess = function(o) {
        window.location.reload();
    };
    dDialog = new YAHOO.widget.Dialog("databaseDialog", 
        { fixedcenter: true,
                    visible: false,
                    close: true,
                    draggable: true,
                    constraintoviewport: true,
                    buttons : [ { text:"Submit", handler:handleSubmit }, { text:"Cancel", handler:handleCancel, isDefault:true } ]
        });      
    dDialog.callback = { success: handleSuccess };        
    dDialog.render();
    
    YAHOO.util.Event.addListener("showDBDialog", "click", dDialog.show, dDialog, true);   
}




function databaseUserDialog() {
    YAHOO.util.Dom.removeClass("databaseUserDialog", "yui-pe-content");
    var thisStatus = YAHOO.util.Dom.get('serverStatus');
    var handleSubmit = function() {
        this.submit();
        thisStatus.innerHTML = "<img src=/images/ajax-loader.gif>";
    };
    var handleSuccess = function(o) {
        window.location.reload();
    };
    var handleFailure = function(o) {
        thisStatus.innerHTML = o.responseText;
    };    
    dDialog = new YAHOO.widget.Dialog("databaseUserDialog", 
        { fixedcenter: true,
                    visible: false,
                    close: true,
                    width: "250px",
                    draggable: true,
                    constraintoviewport: true,
                    buttons : [ { text:"Submit", handler:handleSubmit }, { text:"Cancel", handler:handleCancel, isDefault:true } ]
        });      
    dDialog.callback = { success: handleSuccess, failure: handleFailure };        
    dDialog.render();
    
    YAHOO.util.Event.addListener("showDBUserDialog", "click", dDialog.show, dDialog, true);   
}


function pigeonDialog() {
    YAHOO.util.Dom.removeClass("pigeonDialog", "yui-pe-content");
    var handleSubmit = function() {
        this.submit();
    };
    var handleSuccess = function(o) {
        var result = o.responseText.split(":");
        var pigeonDomains = YAHOO.util.Dom.get("pigeonDomains");
        var el = document.createElement('a');
        el.href = "/pm/get/"+result[1];
        var elTN = document.createTextNode(result[0].toUpperCase());
        el.appendChild(elTN);
        pigeonDomains.appendChild(el);
    };
    dDialog = new YAHOO.widget.Dialog("pigeonDialog", 
        { fixedcenter: true,
                    width: "300px",
                    visible: false,
                    close: true,
                    draggable: true,
                    constraintoviewport : true,
                    buttons : [ { text:"Submit", handler:handleSubmit }, { text:"Cancel", handler:handleCancel, isDefault:true } ]
        });      
    dDialog.callback = { success: handleSuccess };        
    dDialog.render();
    
    YAHOO.util.Event.addListener("showPMDialog", "click", dDialog.show, dDialog, true);   
}




/* dialog to confirm deletion of server from acccount */
function deleteServerDialog() {
    YAHOO.util.Dom.removeClass("deleteServerDialog", "yui-pe-content");
    var handleSuccess = function(o) {
        window.location.href = "/ov";
        //history.back();
    };
    
    var dDialog = new YAHOO.widget.Dialog("deleteServerDialog", 
        { fixedcenter: true,
           visible: false,
           modal: false,
           width: "22em",
           buttons : [ { text:"Submit", handler:handleSubmit }, { text:"Cancel", handler:handleCancel, isDefault:true } ]
        });
    dDialog.callback = { success: handleSuccess };
    dDialog.render();

    YAHOO.util.Event.addListener("showServerDeleteDialog", "click", dDialog.show, dDialog, true);
    
}



