function checkPageWidth() {
  pageContainerObj = document.getElementById("pageContainer");
  if ((typeof(pageContainerObj) == "object") && (pageContainerObj != null)) {
//     alert (pageContainerObj.offsetWidth);
     if (pageContainerObj.offsetWidth < 950) {
          pageContainerObj.style.width = "950px";
     }
  }
  window.onresize = restorePage;

}

function restorePage() {
         window.location.href = window.location.href;
}


function fnCloseSeatingPlanner() {
//alert ("closing seating planner");
         SeatingPlanWindowObject = null;
}

function fnSetSeatingPlanner(windowIn) {
//alert ("opening seating planner");
         SeatingPlanWindowObject = windowIn;
}

function fnCloseCardDesigner() {
//alert ("closing card designer");
         CardDesignWindowObject = null;
}

function fnSetCardDesigner(windowIn) {
//alert ("opening card designer");
         CardDesignWindowObject = windowIn;
}

function mousein(obj) {
         if (document.layers) {
             obj.backgroundColor = "mistyrose";
         } else {
             obj.style.borderColor = "maroon";
             obj.style.backgroundColor = "mistyrose";
         }
}

function mouseout(obj) {
         if (document.layers) {
             obj.backgroundColor = "pink";
         } else {
             obj.style.borderColor = "pink";
             obj.style.backgroundColor = "pink";
         }
}

var CardDesignWindowObject = null;
var SeatingPlanWindowObject = null;
var globalWindowObject;
var globalHTMLToWrite;
var platform = navigator.platform;

function writeToWindow() {
        // This function writes data in the global variable globalHTMLToWrite to the globalWindowObject
        // These must be global variables to allow for the activation of this method via a timer
        // Check to be sure that the window opener is set in case the window was not ready when it was
        // previously set
        if (!globalWindowObject.opener) {
           globalWindowObject.opener = window;
        }
        // Now write the window
        globalWindowObject.document.open();
        globalWindowObject.document.write(globalHTMLToWrite);
        globalWindowObject.document.close(); // close layout stream
}

function makeNewWindow(newWindowObject, address, name, htmlToWrite) {
        if (!newWindowObject || newWindowObject.closed) {
            var targetWidth;
            var targetHeight;
            var availWidth = screen.availWidth;
            var availHeight = screen.availHeight;
            if (availWidth < 800) {
              targetWidth = availWidth;
            } else {
              targetWidth = 800;
            }
            if (availHeight < 600) {
              targetHeight = availHeight;
            } else {
              targetHeight = 600;
            }
        var attributes = "width=" + targetWidth + ",height=" + targetHeight + ",dependent,resizable,scrollbars,title";
                newWindowObject = window.open(address,name,attributes);
                if (!newWindowObject) {
                    alert ("Could not open new window, please disable any new window blocker that may be active and try again.");
                    return;
                }
                if (!newWindowObject.opener) {
                        newWindowObject.opener = window;
                }
                if (htmlToWrite) {
                    globalWindowObject = newWindowObject;
                    globalHTMLToWrite = htmlToWrite;
                        // force small delay for IE to catch up
                        setTimeout("writeToWindow()", 50);
                }
        } else {
                // window is already open; bring to front
                newWindowObject.focus();
        }
        return newWindowObject;
}

function getSiblings() {
        var otherWindows = new Array();
        otherWindows[0] = CardDesignWindowObject;
        otherWindows[1] = SeatingPlanWindowObject;
        return otherWindows;
}

function goToSeatingPlanner() {
    SeatingPlanWindowObject = makeNewWindow(SeatingPlanWindowObject, "seatingPlan10.htm", "SeatingPlanWindow");
    if (CardDesignWindowObject && !CardDesignWindowObject.closed) {
//      updateCardDesignWindowObjectSiblings()l;
        CardDesignWindowObject.otherWindows = getSiblings();
    }
//    setTimeout("updateSeatingPlanWindowObjectSiblings()", 250);
}

function goToCardDesigner() {
    CardDesignWindowObject = makeNewWindow(CardDesignWindowObject, "card_design.php", "CardDesignWindow");
    if (SeatingPlanWindowObject && !SeatingPlanWindowObject.closed) {
//      updateSeatingPlanWindowObjectSiblings();
        SeatingPlanWindowObject.navigation.otherWindows = getSiblings();
    }
//    setTimeout("updateCardDesignWindowObjectSiblings()", 250);
}

/*
function updateCardDesignWindowObjectSiblings() {
        if (!CardDesignWindowObject) {
                setTimeout("updateCardDesignWindowObjectSiblings()", 50);
        }
        if (CardDesignWindowObject.ready) {
                CardDesignWindowObject.otherWindows = getSiblings();
        } else {
                setTimeout("updateCardDesignWindowObjectSiblings()", 50);
        }
}

function updateSeatingPlanWindowObjectSiblings() {
        if ((!SeatingPlanWindowObject) || (!SeatingPlanWindowObject.navigation) || (!SeatingPlanWindowObject.navigation.ready)) {
                setTimeout("updateSeatingPlanWindowObjectSiblings()", 50);

        } else {
                SeatingPlanWindowObject.navigation.otherWindows = getSiblings();
        }
}
*/

// Functions to implement AJAX
// threadsafe asynchronous XMLHTTPRequest code
function ajaxSend(url, callback, type, data){


// we use a javascript feature here called "inner functions"
// using these means the local variables retain their values after the outer function
// has returned. this is useful for thread safety, so
// reassigning the onreadystatechange function doesn't stomp over earlier requests.


     function ajaxBindCallback(){
          if (ajaxRequest.readyState == 4) {
               if (ajaxRequest.status == 200) {
                    if (ajaxCallback){
                         window.clearTimeout(ajaxRequest.timer);
                         ajaxCallback(ajaxRequest.responseText);
                    } else {
                         alert('no callback defined');
                    }
               } else {
                    alert("There was a problem retrieving the xml data:\n" + ajaxRequest.status + ":\t" + ajaxRequest.statusText + "\n" + ajaxRequest.responseText);
               }
          }
     }


     // use a local variable to hold our request and callback until the inner function is called...
     var ajaxRequest = null;
     var ajaxCallback = callback;
     var ajaxData = data;
     var ajaxType = type;


     // bind our callback then hit the server...
     if (window.XMLHttpRequest) {
          // moz et al
          ajaxRequest = new XMLHttpRequest();
          ajaxRequest.onreadystatechange = ajaxBindCallback;
          ajaxRequest.open(ajaxType, url, true);
          if (type == 'POST') {
               ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
          }
          ajaxRequest.send(ajaxData);
     } else if (window.ActiveXObject) {
          // ie
          ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
          if (ajaxRequest) {
               ajaxRequest.onreadystatechange = ajaxBindCallback;
               ajaxRequest.open(ajaxType, url, true);
               if (type == 'POST') {
                    ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
               }
               ajaxRequest.send(ajaxData);
          }
     } else {
          // Ajax is not supported
          return false;
     }
     ajaxRequest.timer = setTimeout("abortRequest", 10000);
     return true;
}

function abortRequest(){
     if (window.location.hostname == "concerto") {
          alert("Request timed out");
     }
     ajaxRequest.abort();

}

function ajaxErrorReportCompleted(response) {
     // If development system, show error, otherwise end silently
     if (window.location.hostname == "concerto") {
          alert(response);
     }
}

// Functions to capture and report JavaScript errors
function reportError(message, fileLocation, lineNo) {
//     alert ("Error message = " + message + "\r\nFile = " + fileLocation + "\r\nLine Number = " + lineNo);
     var data = "message=" + message + "&location=" + fileLocation + "&lineNo=" + lineNo + "&platform=" + platform;
//     alert (data);
     if (location.hostname == "concerto") {
          ajaxSend("/meteortech/adornaments/errorReport.php", ajaxErrorReportCompleted, "POST", data);
     } else {
          ajaxSend("/errorReport.php", ajaxErrorReportCompleted, "POST", data);
     }
     return true;
}

function addEvent(elm, evType, fn, useCapture) {
     // cross-browser event handling for IE5+, NS6+ and Mozilla/Gecko
     // By Scott Andrew
//     alert ("Adding event " + fn);
     if (elm.addEventListener) {
          elm.addEventListener(evType, fn, useCapture);
          return true;
     } else if (elm.attachEvent) {
          var r = elm.attachEvent('on' + evType, fn);
          return r;
     } else {
          elm['on' + evType] = fn;
     }
}

window.onerror = reportError;

// Error test - inject an error
//window_height.style = 1;