/*
mObj = d.getElementsByTagName("body")[0].insertBefore(d.createElement("div"),document.body.firstChild);

*/

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Steve Chipman | http://slayeroffice.com/ */

// constants to define the title of the alert and button text.
var CONFIRM_TITLE = "Flash Cab";
var CONFIRM_BUTTON_OK_TEXT = "OK";
var CONFIRM_BUTTON_CANCEL_TEXT = "Cancel";

// over-ride the alert method only if this a newer browser.
// Older browser will see standard alerts
//if(document.getElementById) {
//  window.confirm = function(txt) {
//    createCustomConfirm(txt);
//  }
//}

function createCustomConfirm(txt, onOkClicked, onCancelClicked) {
    // shortcut reference to the document object
    d = document;

    // if the confirmModalContainer object already exists in the DOM, bail out.
    if (d.getElementById("confirmModalContainer")) return;

    // create the confirmModalContainer div as a child of the BODY element
    mObj = d.getElementsByTagName("body")[0].insertBefore(d.createElement("div"), null);
    mObj.id = "confirmModalContainer";
    // make sure its as tall as it needs to be to overlay all the content on the page
    mObj.style.height = document.documentElement.scrollHeight + "px";

    // create the DIV that will be the alert 
    alertObj = mObj.appendChild(d.createElement("div"));
    alertObj.id = "confirmBox";
    // MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
    if (d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
    // center the alert box
    alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth) / 2 + "px";
    alertObj.style.top = (d.documentElement.clientHeight - alertObj.offsetHeight) / 2 + "px";

    // create an H1 element as the title bar
    h1 = alertObj.appendChild(d.createElement("h1"));
    h1.appendChild(d.createTextNode(cabOrderSiteName ? cabOrderSiteName : CONFIRM_TITLE));

    // create a paragraph element to contain the txt argument
    msg = alertObj.appendChild(d.createElement("p"));
    msg.innerHTML = txt;

    buttonsContainer = alertObj.appendChild(d.createElement("div"));
    buttonsContainer.id = "confirmButtonsContainer";

    // create an anchor element to use as the confirmation button.
    obBtn = buttonsContainer.appendChild(d.createElement("a"));
    obBtn.id = "okBtn";
    obBtn.appendChild(d.createTextNode(CONFIRM_BUTTON_OK_TEXT));
    obBtn.href = "#";
    // set up the onclick event to remove the alert when the anchor is clicked
    obBtn.onclick = function () {
        removeCustomConfirm();
        if (onOkClicked) onOkClicked();
        return false;
    };

    // create an anchor element to use as the confirmation button.
    cancelBtn = buttonsContainer.appendChild(d.createElement("a"));
    cancelBtn.id = "cancelBtn";
    cancelBtn.appendChild(d.createTextNode(CONFIRM_BUTTON_CANCEL_TEXT));
    cancelBtn.href = "#";
    // set up the onclick event to remove the alert when the anchor is clicked
    cancelBtn.onclick = function () {
        removeCustomConfirm();
        if (onCancelClicked) onCancelClicked();
        return false;
    };
}

// removes the custom alert from the DOM
function removeCustomConfirm() {
    document.getElementsByTagName("body")[0].removeChild(document.getElementById("confirmModalContainer"));
}

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
