function confirmAction(question, yesUrl, noUrl)
{
    var handleYes = function()
    {
        //user confirms the deletion of this item;
        //this method would perform that deletion;
        //when ready, hide the SimpleDialog:
        this.hide();
        window.location = yesUrl;
    };
    var handleNo = function()
    {
        //user cancels item deletion; this method
        //would handle the cancellation of the
        //process.
        //when ready, hide the SimpleDialog:
        this.hide();
        window.location = noUrl;
    };
    var handleCancel = function()
    {
        //user cancels item deletion; this method
        //would handle the cancellation of the
        //process.
        //when ready, hide the SimpleDialog:
        this.hide();
    };
    var confirmButtons = [
        { text:"Yes", handler:handleYes },
        { text:"No", handler:handleNo },
        { text:"Cancel", handler:handleCancel }
    ];

    mySimpleDialog = new YAHOO.widget.SimpleDialog("dlg", {
        width: "20em",
        fixedcenter: true,
        modal: true,
        visible: false,
        draggable: false
    });
    mySimpleDialog.setHeader("Attention!");
    mySimpleDialog.setBody(question);
    mySimpleDialog.cfg.setProperty("icon",YAHOO.widget.SimpleDialog.ICON_WARN);
    mySimpleDialog.cfg.queueProperty("buttons", confirmButtons);
    mySimpleDialog.render(document.body);
    mySimpleDialog.show();
}


function confirmDelete(question, yesUrl)
{
    var handleYes = function()
    {
        //user confirms the deletion of this item;
        //this method would perform that deletion;
        //when ready, hide the SimpleDialog:
        this.hide();
        window.location = yesUrl;
    };
    var handleCancel = function()
    {
        //user cancels item deletion; this method
        //would handle the cancellation of the
        //process.
        //when ready, hide the SimpleDialog:
        this.hide();
    };
    var confirmButtons = [
        { text:"Yes", handler:handleYes },
        { text:"Cancel", handler:handleCancel }
    ];

    mySimpleDialog = new YAHOO.widget.SimpleDialog("dlg", { 
        width: "20em",
        fixedcenter: true,
        modal: true,
        visible: false,
        draggable: false
    });
    mySimpleDialog.setHeader("Attention!");
    mySimpleDialog.setBody(question);
    mySimpleDialog.cfg.setProperty("icon",YAHOO.widget.SimpleDialog.ICON_WARN);
    mySimpleDialog.cfg.queueProperty("buttons", confirmButtons);
    mySimpleDialog.render(document.body);
    mySimpleDialog.show(); 
}

function emailExists(names)
{
    var nameArr = names.split("~");
    var out = "";
    // Instantiate a Panel from script
    var myPanel = new YAHOO.widget.Panel("panel1",
        {
            width: "600px",
            visible: true,
            draggable: true,
            close: true,
            fixedcenter: true,
            modal: true
        }
    );
    out = out + "Creating a second (or fifth) account causes considerable difficulty for Crossroads staff and  ";
    out = out + "volunteers. If you already have an account, do NOT create a new account. Instead, please ";
    out = out + "request your password (or <a href='send/37'>contact support</a>) to log into your existing account.<br><br> ";
    out = out + "The list below details all of the accounts that already exist for the email address you entered.<br><br>";   
    out = out + "<table border='0' cellpadding='0'>";
    for (var i=0; i<nameArr.length; i++) {
        out = out + "<tr><td>" + nameArr[i] + "</td><td><a href=\"javascript: sendEmailInfo('" + nameArr[i] + "', 'login', '');\">Login</a>&nbsp;|&nbsp;<a href=\"javascript: sendEmailInfo('" + nameArr[i] + "', 'reset', '')\">Reset Password</a></td></tr>"; 
    }
    out = out + "</table>";
    out = out + "<br><a id='hide' href='javascript: void(null);'><span>Continue</span></a> creating new account.";
    myPanel.setHeader("Already Have An Account?");
    myPanel.setBody(out);
    myPanel.render(document.body);
    myPanel.show();
    YAHOO.util.Event.addListener("hide", "click", myPanel.hide, myPanel, true);
}


function sendEmailInfo(name, condition, referringpage)
{
    var url;
    if (condition == 'login') {
        url = "/index.php?action=viewpage&filepath=site/login.php&login=" + escape(name) + "&referringpage=" + escape(referringpage);
    } else {
        url = "/index.php?action=viewpage&filepath=pages/recoverPassword/actEmailPassword.php&username=" + escape(name);
    }
    window.location = url;
}


function emailExistsForGoGive(names, act)
{
    var nameArr = names.split("~");
    var out = "";
    // Instantiate a Panel from script
    var myPanel = new YAHOO.widget.Panel("panel1",
        {
            width: "600px",
            visible: true,
            draggable: true,
            close: true,
            fixedcenter: true,
            modal: true
        }
    );
    out = out + "It looks like you've got a crossroads.net account. To keep things neat and tidy, ";
    out = out + "please login to your existing account (or request your password if you've forgotten it). ";
    out = out + "<a href='send/37'>Ask for help</a> if you're having trouble. <br><br>";
    out = out + "The following accounts match-up with the email address you entered.<br><br>";   
    out = out + "<table border='0' cellpadding='0'>";
    for (var i=0; i<nameArr.length; i++) {
        out = out + "<tr><td>" + nameArr[i] + "</td><td><a href=\"javascript: sendEmailInfo('" + nameArr[i] + "', 'login','" +  act + "');\">Login</a>&nbsp;|&nbsp;<a href=\"javascript: sendEmailInfo('" + nameArr[i] + "', 'reset', '')\">Reset Password</a></td></tr>"; 
    }
    out = out + "</table>";
    out = out + "<br><a id='hide' href='javascript: void(null);'><span>Continue</span></a> without logging in.";
    myPanel.setHeader("Already Have An Account?");
    myPanel.setBody(out);
    myPanel.render(document.body);
    myPanel.show(); 
    YAHOO.util.Event.addListener("hide", "click", myPanel.hide, myPanel, true);
}


function setUpdate()
{
    var update = document.editForm.update;
    var answered = document.editForm.answered;
    var cfn = document.editForm.x_first_name.value;
    var cln = document.editForm.x_last_name.value;
    var ofn =  document.editForm.fn.value;
    var oln =  document.editForm.ln.value;
    var question = "The name you entered <b>" + ofn + " " + oln + "</b> has been changed to <b>" + cfn + " " + cln + "</b> on this form. ";
    question = question + "Would you like us to update the name, address and email on your crossroads.net account with the information you've entered here? ";
    question = question + "(If you're using someone else's credit card to make a donation, please click &quot;No&quot;.)";

    var handleYes = function() {
        update.value = "1";
        answered.value = "1";
        this.hide();
    };
    var handleNo = function() {
        update.value = "0";
        answered.value = "1";
        this.hide();
    };
    var confirmButtons = [
        { text:"Yes", handler:handleYes },
        { text:"No", handler:handleNo }
    ];

    mySimpleDialog = new YAHOO.widget.SimpleDialog("dlg", {
        width: "40em",
        fixedcenter: true,
        modal: true,
        visible: false,
        draggable: true
    });
    mySimpleDialog.setHeader("Attention!");
    mySimpleDialog.setBody(question);
    mySimpleDialog.cfg.setProperty("icon",YAHOO.widget.SimpleDialog.ICON_WARN);
    mySimpleDialog.cfg.queueProperty("buttons", confirmButtons);
    mySimpleDialog.render(document.body);
    mySimpleDialog.show();
}
