var pageName = 0;
var pageURL = 1;
var pageTarget = 2;
var defaultContentPane = 'content';
var loadingMessage = '<center><span class="Loading">Loading... Please Wait.</span></center>';
var isText = 1;
var isVariable = 0;

var pages = [
                ['Home','home.html',defaultContentPane],
                ['Featured Plans','featured.asp',defaultContentPane],
                ['About Us','aboutus.html',defaultContentPane],
                ['Our Services','services.html',defaultContentPane],
                ['About Our Plans','aboutplans.html',defaultContentPane],
                ['Fee Schedule','fees.html',defaultContentPane],
                ['Contact Us','contact.html',defaultContentPane],
                ['Order Status','status.asp',defaultContentPane],
                ['Gallery','gallery.asp',defaultContentPane]
            ];


//----------------------------------------------------------
// createButtons() - Creates the button control
// inputs: tartgetDiv - Target for Button Display
// outputs: none
//----------------------------------------------------------
function createButtons(targetDiv) {
    if (pages.length > 0) 
    {
        var buttonPaneContent = '<table>';

        var x = 0;
        for (x = 0; x < pages.length; x++) 
        {
            buttonPaneContent += '  <tr>';
            buttonPaneContent += '      <td class="linktd"><div id="' + pages[x][1] + '" class="hidden"><img src="images/arrow.gif" alt="-->" /></div></td>';
            buttonPaneContent += '      <td class="linktd"><a href="#" onclick="changeButton(pages,\'' + pages[x][1] + '\',\'' + pages[x][2] + '\');">' + pages[x][0] + '</a></td>';
            buttonPaneContent += '  </tr>';
        }

        buttonPaneContent += '</table>'

        refreshContent(targetDiv,buttonPaneContent);
        changeButton(pages, pages[0][1], pages[0][2]);
    }
} // createButtons()


//----------------------------------------------------------
// changeButton() - Changes the tab control
// inputs:  buttonArray - Array of Buttons
//          button - Button to activate
//          target - Content Target
// outputs: none
//----------------------------------------------------------
function changeButton(buttonArray, button, target) {
    var x = 0;
    for (x = 0; x < buttonArray.length; x++)
    {
        if (document.getElementById(buttonArray[x][1]) != null) 
        {
            hideObjectById(buttonArray[x][1],true);
        }
    }

    hideObjectById(button, false);
    changeContent(button,'',target);

} // changeButton()


//----------------------------------------------------------
// changeContent() - Changes the content
// inputs:  contentURL - URL to fetch
//          contentParameters - Parameters for URL
//          target - Content Target
// outputs: none
//----------------------------------------------------------
function changeContent(contentURL, contentParameters, target) {
    refreshContent(target, loadingMessage);

    var ajaxRequest = new Ajax(contentURL, '?' + contentParameters, handleContentResponse);
    ajaxRequest.addCallbackParam(target, isText);
    ajaxRequest.addCallbackParam(escape(contentURL + contentParameters), isText);
    ajaxRequest.request();
} // changeContent()


//----------------------------------------------------------
// handleContentResponse() - Handles the ajax response to a get XSL request
// inputs:  ajaxRequest - Ajax request object
//			target - Content Target
// outputs: none
//----------------------------------------------------------
function handleContentResponse(ajaxRequest, target) {
        refreshContent(target, ajaxRequest.responseText);
} // handleContentResponse()


//----------------------------------------------------------
// hideObjectById() - hides or shows a target object by id
// inputs:	ID - ID of object to hide (or show)
//			bool - true for hide, false for show
// outputs: none
//----------------------------------------------------------
function hideObjectById(ID, bool) {
    object = document.getElementById(ID);
    hideObject(object, bool)
} // hideObjectById


//----------------------------------------------------------
// hideObject() - hides or shows a target object
// inputs:	object - object to hide (or show)
//			bool - true for hide, false for show
// outputs: none
//----------------------------------------------------------
function hideObject(object, bool) {
    if (bool) {
        object.style.display = 'none';
    }
    else {
        object.style.display = 'block';
    }
} // hideObject


//---------------------------------------------------------- 
// refreshContent() - Updates the content of a div
// inputs:	div - div to target 
//			content - content to replace
// outputs: none
//---------------------------------------------------------- 
function refreshContent(div,content)
{
	document.getElementById(div).innerHTML = content;
} // refreshContent()


//----------------------------------------------------------
// Ajax() - Minimal Ajax request object.
// inputs:	url - the url to query
//			params - querystring parameters and/or post data
//			callback - external function to return to
// outputs: none		
//----------------------------------------------------------
function Ajax(url, params, callback) {
    if (!url) {
        alert('Missing URL');
        return;
    }

    //if (!callback)
    //{
    // alert('No callback function');
    //}

    this.url = url;
    this.params = params;
    this.callback = callback;
    this.getMethod = true;
    this.async = true;
    this.callbackParams = [];
    this.callbackParamsType = [];

    this.create();

    if (this.req) {
        var $this = this
        this.req.onreadystatechange = function() {
            if ($this.req.readyState == 4) {
                if ($this.req.status != 200) {
                    if ($this.req.status != 0) {
                        var errorDetail = $this.req.responseText
                        errorDetail = errorDetail.replace(/<style/gi, '<div style="display: none;" ');
                        errorDetail = errorDetail.replace(/<\/style/gi, '</div');
                        alert('An AJAX call failed with status: ' + $this.req.status + '.  Refreshing your browser will most likely resolve the issue.  Detail:' + errorDetail);
                    }
                }
                else {
                    if ($this.callback) {
                        var additionalParams = '';
                        if ($this.callbackParams.length > 0) {
                            for (var i = 0; i < $this.callbackParams.length; i++) {
                                additionalParams += ',';

                                if ($this.callbackParamsType[i] = 1) {
                                    additionalParams += '\'';
                                }

                                additionalParams += $this.callbackParams[i];

                                if ($this.callbackParamsType[i] = 1) {
                                    additionalParams += '\'';
                                }
                            }
                        }
                        eval('$this.callback ($this.req' + additionalParams + ')');
                    }
                }
            }
        }
    }
    else {
        alert('Your browser does not support AJAX!');
    }
}

//----------------------------------------------------------
Ajax.prototype.request = function() {
    // work around for "caching" issues
    var dummy = 'dummy=' + new Date().getTime();
    if ((this.getMethod && (!this.params || (this.params == ''))) || !this.getMethod) {
        dummy = '?' + dummy
    }
    else {
        dummy = '&' + dummy
    }

    if (this.getMethod) {
        this.req.open('GET', this.url + this.params + dummy, this.async);
        this.req.send(null);
    }
    else {
        this.req.open('POST', this.url + dummy, this.async);
        this.req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        this.req.setRequestHeader("Content-length", this.params.length);
        this.req.setRequestHeader("Connection", "close");
        this.req.send(this.params);
    }
}

//----------------------------------------------------------
Ajax.prototype.setAsync = function(async) {
    this.async = async;
}

//----------------------------------------------------------
Ajax.prototype.setGetMethod = function(getMethod) {
    this.getMethod = getMethod;
}

//----------------------------------------------------------
Ajax.prototype.addCallbackParam = function(param, type) {
    this.callbackParams.push(param);
    this.callbackParamsType.push(type);
}

//----------------------------------------------------------
Ajax.prototype.create = function() {
    if (window.XMLHttpRequest) {
        this.req = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) { // for IE5 and IE6
        this.req = new ActiveXObject('Microsoft.XMLHTTP');
    }
} // Ajax()