/********************************************************************* * * Dynamic website agreement dialog functions * Country: Korea * Language: English * Version 1.0 * Code dependancies: dialogCore.js/jsp * Author: Oliver Ammann * **********************************************************************/ // Add loadlistener for initDialog function addLoadListener(initDialog); // Preload app images to improve preformance preLoad('/content/images/kr/modules/common/dots.gif', '/content/images/kr/modules/transitionPage/loading_sequence1.gif'); /** * Function: initDialog() * Calls the create dialog function when the anchor with unique * id "agreement" is clicked */ function initDialog() { var agreement = document.getElementById("agreement"); agreement.onclick = createDialog; return true; } /** * Function: createDialog() * Dynamically creates the custom dialog using the dom * CSS classes referenced by this code are in amadeus_apps.css */ function createDialog() { var body = document.getElementsByTagName("body")[0]; var pageDimensions = getPageDimensions(); var viewportSize = getViewportSize(); if (viewportSize[1] > pageDimensions[1]) { pageDimensions[1] = viewportSize[1]; } var dropSheet = document.createElement("div"); dropSheet.setAttribute("id", "dropSheet"); dropSheet.style.position = "absolute"; dropSheet.style.left = "0"; dropSheet.style.top = "0"; dropSheet.style.width = pageDimensions[0] + "px"; dropSheet.style.height = pageDimensions[1] + "px"; body.appendChild(dropSheet); try { // Creates IFrame element, which will sit behind the dialog div // This is required to stop form controls from showing through in IE // if the dialog happens to sit above such an element. // Form elements in IE are rendered by the OS and therefore have // a z-index of infinity. Iframes are also treated as an OS element // and can therefore be manipulated to cover the form elements. var dialogIframe = document.createElement("iframe"); dialogIframe.className = "dIframe"; dialogIframe.setAttribute("frameborder", "0"); dialogIframe.setAttribute("border", "0"); dialogIframe.setAttribute("id", "frameId"); dialogIframe.tabIndex = '-1'; dialogIframe.style.visibility = "hidden"; dialogIframe.style.position = "absolute"; // Create dialog parent div var dialog = document.createElement("div"); dialog.className = "customDialog"; dialog.style.visibility = "hidden"; dialog.style.position = "absolute"; // Create dialog title and append to dialog var dialogTitle = document.createElement("h1"); dialogTitle.appendChild(document.createTextNode("Website Agreement ")); dialog.appendChild(dialogTitle); // Create dialog main message paragraph and append to dialog var dialogMessage = document.createElement("p"); dialogMessage.appendChild(document.createTextNode("Please indicate your acceptance of the Website" + "Agreement and acknowledge that you have read American's" + "Privacy Policy.")); dialog.appendChild(dialogMessage); // Create optin checkbox and attach the doUpdateState function, which will // be used to track the checkbox state when a user checks or unchecks it var dialogCheckBox = document.createElement("input"); dialogCheckBox.className = "leftSpace"; dialogCheckBox.setAttribute("type", "checkbox"); dialogCheckBox.setAttribute("id", "privacy"); attachEventListener(dialogCheckBox, "click", function(e) { return doUpdateState("privacyState") }, false); // create hidden form field, which will store the current checkbox state var dialogCheckBoxState = document.createElement("input"); dialogCheckBoxState.setAttribute("type", "hidden"); dialogCheckBoxState.setAttribute("id", "privacyState"); dialogCheckBoxState.setAttribute("value", "false"); // Create anchor 1 which will link to the web site agreement. We also attach // the popup function to the anchor, which displays the link in a popup var dialogAnchor1 = document.createElement("a"); dialogAnchor1.setAttribute("href", "#"); dialogAnchor1.appendChild(document.createTextNode("Website Agreement ")); attachEventListener(dialogAnchor1, "click", function(e) { return doPopUp("/intl/kr/footer_en/websiteAgreementPU.jsp", "500", "500", "y") }, false); // Create anchor 2 which will link to the privacy policy. We also attach // the popup function to the anchor, which displays the link in a popup var dialogAnchor2 = document.createElement("a"); dialogAnchor2.setAttribute("href", "#"); dialogAnchor2.appendChild(document.createTextNode("Privacy Policy ")); attachEventListener(dialogAnchor2, "click", function(e) { return doPopUp("/intl/kr/footer_en/privacyPU.jsp", "500", "500", "y") }, false); // Create the acceptance message, incorporating the anchors and checkbox // we created above. Append this message to the parent dialog var dialogMessage2 = document.createElement("p"); dialogMessage2.appendChild(document.createTextNode("I accept the ")); dialogMessage2.appendChild(dialogAnchor1); dialogMessage2.appendChild(document.createTextNode("and have read American's ")); dialogMessage2.appendChild(dialogAnchor2); dialogMessage2.appendChild(document.createTextNode(" *")); dialogMessage2.appendChild(dialogCheckBox); dialogMessage2.appendChild(dialogCheckBoxState); dialog.appendChild(dialogMessage2); // Create button container and continue and cancel buttons. Attach the // dialogClick function, which will handle the button click event // Append buttons to the button container and then the button container // to the dialog var dialogBtnContainer = document.createElement("p"); var dialogButton1 = document.createElement("input"); dialogButton1.className = "customDialogCold"; dialogButton1.setAttribute("type", "button"); dialogButton1.setAttribute("value", "Cancel"); attachEventListener(dialogButton1, "click", dialogClick, false); var dialogButton2 = document.createElement("input"); dialogButton2.className = "customDialogHot"; dialogButton2.setAttribute("type", "button"); dialogButton2.setAttribute("value", "Continue"); attachEventListener(dialogButton2, "click", dialogClick, false); dialogBtnContainer.appendChild(dialogButton2); dialogBtnContainer.appendChild(dialogButton1); dialog.appendChild(dialogBtnContainer); // Add the Iframe and dialog to the dom body body.appendChild(dialogIframe); body.appendChild(dialog); // Gets scrolling position used for dialog positioning var scrollingPosition = getScrollingPosition(); // Position the dialog and iframe at the relevent position dialog.style.left = scrollingPosition[0] + parseInt(viewportSize[0] / 2) - parseInt(dialog.offsetWidth / 2) + "px"; dialog.style.top = scrollingPosition[1] + parseInt(viewportSize[1] / 2) - parseInt(dialog.offsetHeight / 2) + "px"; dialog.style.visibility = "visible"; dialogIframe.style.left = scrollingPosition[0] + parseInt(viewportSize[0] / 2) - parseInt(dialogIframe.offsetWidth / 2) + "px"; dialogIframe.style.top = scrollingPosition[1] + parseInt(viewportSize[1] / 2) - parseInt(dialogIframe.offsetHeight / 2) + "px"; dialogIframe.style.visibility = "visible"; // Set focus to the continue button dialogButton2.focus(); } catch(error) { // Remove our dropsheet if an error occurs during DOM element creation dropSheet.parentNode.removeChild(dropSheet); return true; } return false; } /** * Function: dialogClick(event) * This function determines what action needs to be taken * depending on which element generated the event */ function dialogClick(event) { if (typeof event == "undefined") { event = window.event; } var target = getEventTarget(event); while (target.nodeName.toLowerCase() != "input") { target = target.parentNode; } var value = target.getAttribute("value"); var isChecked = document.getElementById('privacyState').value; // Gets checkbox state // If event occured on the cancel button close the dialog and remove dropsheet // If event occured on the continue button check if the check box has been checked // If checkbox is checked remove the opt in text and UI nodes, replace with processing // message and submit multi-city form. If checkbox is not checked alert user by // highlighting the opt in message and inhibit form submission if (value == "Cancel") { var dialog = target; while (dialog.className != "customDialog") { dialog = dialog.parentNode; } closeDialog(dialog, 'dropSheet'); closeIframe(); } else if (isChecked == "true" && value == "Continue") { var dialog = target; while (dialog.className != "customDialog") { dialog = dialog.parentNode; } removeChildNodes(dialog); attachProgressToElement(dialog, 'waitMsg', 'We are processing your request, please wait ...', '#6C6C6D') setTimeout(function() { document.mcf.submit(); closeDialog(dialog, 'dropSheet');closeIframe(); dialog=null}, 1000); } else if (value == "Continue") { var dialog = target; while (dialog.className != "customDialog") { dialog = dialog.parentNode; } dialog.style.color = "#cc0000"; } return true; }