/*******************************************************************************
 * @license
 * Copyright (c) 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 * 
 * Contributors: IBM Corporation - initial API and implementation
 ******************************************************************************/

/*******************************************************************************
 * @license
 * Copyright (c) 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

/*******************************************************************************
 * @license
 * Copyright (c) 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 *
 * Contributors: IBM Corporation - initial API and implementation
 *******************************************************************************/

/**
 * @license RequireJS domReady 2.0.1 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
 * Available via the MIT or new BSD license.
 * see: http://github.com/requirejs/domReady for details
 */

/*

 Copyright (c) 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors: IBM Corporation - initial API and implementation

 Copyright (c) 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors: IBM Corporation - initial API and implementation

 Copyright (c) 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors: IBM Corporation - initial API and implementation
 RequireJS domReady 2.0.1 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
 Available via the MIT or new BSD license.
 see: http://github.com/requirejs/domReady for details

 Copyright (c) 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors: IBM Corporation - initial API and implementation

 Copyright (c) 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors:
 IBM Corporation - initial API and implementation
*/
(function(g,k){typeof define==="function"&&define.amd?define("orion/Deferred",k):typeof exports==="object"?module.exports=k():(g.orion=g.orion||{},g.orion.Deferred=k())})(this,function(){function g(){for(var b;b=f.shift();)b();e=!1}function k(b){f.push(b);e||(e=!0,setTimeout(g,0))}function m(b){return function(){b.apply(void 0,arguments)}}function j(){function b(){for(var a;a=n.shift();){var c=a.deferred,p=i==="fulfilled"?"resolve":"reject";if(typeof a[p]==="function")try{var d=(0,a[p])(h),b=d&&(typeof d===
"object"||typeof d==="function")&&d.then;if(typeof b==="function")if(d===c.promise)c.reject(new TypeError);else{var l=d.cancel;typeof l==="function"?c._protected(f).parentCancel=l.bind(d):delete c._protected(f).parentCancel;b.call(d,m(c.resolve),m(c.reject),m(c.progress))}else c.resolve(d)}catch(e){c.reject(e)}else c[p](h)}}function a(a){delete p.parentCancel;i="rejected";h=a;n.length&&k(b)}function d(o){function l(a){return function(c){f||(f=!0,a(c))}}var f=!1;delete p.parentCancel;try{var e=o&&
(typeof o==="object"||typeof o==="function")&&o.then;if(typeof e==="function")if(o===c)a(new TypeError);else{i="assumed";var g=o&&o.cancel;if(typeof g!=="function"){var m=new j,o=m.promise;try{e(m.resolve,m.reject,m.progress)}catch(q){m.reject(q)}g=o.cancel;e=o.then}h=o;e.call(o,l(d),l(a));p.parentCancel=g.bind(o)}else i="fulfilled",h=o,n.length&&k(b)}catch(r){l(a)(r)}}function l(){var c=p.parentCancel;if(c)delete p.parentCancel,c();else if(!i)c=Error("Cancel"),c.name="Cancel",a(c)}var h,i,n=[],c=
this,p={};Object.defineProperty(this,"_protected",{value:function(a){if(a!==f)throw Error("protected");return p}});this.resolve=function(a){i||d(a);return c};this.reject=function(h){i||a(h);return c};this.progress=function(a){i||n.forEach(function(c){if(c.progress)try{c.progress(a)}catch(h){}});return c.promise};this.cancel=function(){p.parentCancel?setTimeout(l,0):l();return c};this.then=function(a,h,d){a={resolve:a,reject:h,progress:d,deferred:new j};n.push(a);a.deferred._protected(f).parentCancel=
c.promise.cancel.bind(c);(i==="fulfilled"||i==="rejected")&&k(b);return a.deferred.promise};this.promise={then:c.then,cancel:c.cancel}}var f=[],e=!1;j.all=function(b,a){function d(a,d){n||(i[a]=d,--h===0&&c.resolve(i))}function l(h,i){if(!n){if(a)try{d(h,a(i));return}catch(b){i=b}c.reject(i)}}var h=b.length,i=[],n=!1,c=new j;c.then(void 0,function(){n=!0;b.forEach(function(a){a.cancel&&a.cancel()})});h===0?c.resolve(i):b.forEach(function(a,c){a.then(d.bind(void 0,c),l.bind(void 0,c))});return c.promise};
j.when=function(b,a,d,l){var h;if(!(b&&typeof b.then==="function"))h=new j,h.resolve(b),b=h.promise;return b.then(a,d,l)};return j});
define("orion/xhr",["orion/Deferred"],function(g){function k(g,j,f,e){var b=typeof f.response!=="undefined"?f.response:f.responseText,a;try{a=f.status}catch(d){a=0}g={args:j,response:b,responseText:typeof b==="string"?b:null,status:a,url:g,xhr:f};if(typeof e!=="undefined")g.error=e;return g}return function(m,j,f){var f=f||{},e=arguments.length>3&&arguments[3]?arguments[3]:new XMLHttpRequest,b=new g,a=f.headers||{},d=f.log||!1,l;typeof a["X-Requested-With"]==="undefined"&&(a["X-Requested-With"]="XMLHttpRequest");
if(typeof f.data!=="undefined"&&(m==="POST"||m==="PUT"))l=f.data;var h=!1,i=!1;b.promise.then(void 0,function(a){h=!0;!i&&a instanceof Error&&a.name==="Cancel"&&e.abort()});e.onabort=function(){i=!0;if(!h){var a=Error("Cancel");a.name="Cancel";b.reject(a)}};e.onload=function(){var a=k(j,f,e);200<=e.status&&e.status<400?b.resolve(a):(b.reject(a),d&&typeof console!=="undefined"&&console.log(Error(e.statusText)))};e.onerror=function(){var a=k(j,f,e);b.reject(a);d&&typeof console!=="undefined"&&console.log(Error(e.statusText))};
e.onprogress=function(a){a.xhr=e;b.progress(a)};try{e.open(m,j,!0);if(typeof f.responseType==="string")e.responseType=f.responseType;if(typeof f.timeout==="number")if(typeof e.timeout==="number")e.timeout=f.timeout,e.addEventListener("timeout",function(){b.reject(k(j,f,e,"Timeout exceeded"))});else{var n=setTimeout(function(){b.reject(k(j,f,e,"Timeout exceeded"))},f.timeout);b.promise.then(clearTimeout.bind(null,n),clearTimeout.bind(null,n))}Object.keys(a).forEach(function(c){e.setRequestHeader(c,
a[c])});e.send(l||null)}catch(c){b.reject(k(j,f,e,c))}return b.promise}});
define("orion/util",[],function(){var g=navigator.userAgent,k=g.indexOf("MSIE")!==-1||g.indexOf("Trident")!==-1?document.documentMode:void 0,m=parseFloat(g.split("Firefox/")[1]||g.split("Minefield/")[1])||void 0,j=g.indexOf("Opera")!==-1,f=parseFloat(g.split("Chrome/")[1])||void 0,e=g.indexOf("Safari")!==-1&&!f,b=parseFloat(g.split("WebKit/")[1])||void 0,a=g.indexOf("Android")!==-1,d=g.indexOf("iPad")!==-1,g=g.indexOf("iPhone")!==-1,l=d||g,h=navigator.platform.indexOf("Mac")!==-1,i=navigator.platform.indexOf("Win")!==
-1,n=navigator.platform.indexOf("Linux")!==-1;return{formatMessage:function(a){var h=arguments;return a.replace(/\$\{([^\}]+)\}/g,function(a,c){return h[(c<<0)+1]})},createElement:function(a,h){return a.createElementNS?a.createElementNS("http://www.w3.org/1999/xhtml",h):a.createElement(h)},isIE:k,isFirefox:m,isOpera:j,isChrome:f,isSafari:e,isWebkit:b,isAndroid:a,isIPad:d,isIPhone:g,isIOS:l,isMac:h,isWindows:i,isLinux:n,platformDelimiter:i?"\r\n":"\n"}});
define("orion/webui/littlelib",["orion/util"],function(g){function k(a,d){d||(d=document);return d.querySelectorAll(a)}function m(a){if(a.tabIndex>=0)return a;if(a.hasChildNodes())for(var d=0;d<a.childNodes.length;d++){var b=m(a.childNodes[d]);if(b)return b}return null}function j(a){if(a.tabIndex>=0)return a;if(a.hasChildNodes())for(var d=a.childNodes.length-1;d>=0;d--){var b=j(a.childNodes[d]);if(b)return b}return null}function f(a,d){if(a.nodeType===3){var b=e.exec(a.nodeValue);b&&b.length>1&&d(a,
b)}if(a.hasChildNodes())for(b=0;b<a.childNodes.length;b++)f(a.childNodes[b],d)}var e=/\$\{([^\}]+)\}/,b=null;return{$:function(a,b){b||(b=document);return b.querySelector(a)},$$:k,$$array:function(a,b){return Array.prototype.slice.call(k(a,b))},node:function(a){var b=a;typeof a==="string"&&(b=document.getElementById(a));return b},contains:function(a,b){if(!a||!b)return!1;if(a===b)return!0;var e=a.compareDocumentPosition(b);return Boolean(e&16)},bounds:function(a){a=a.getBoundingClientRect();return{left:a.left+
document.body.scrollLeft,top:a.top+document.body.scrollTop,width:a.width,height:a.height}},empty:function(a){for(;a.hasChildNodes();)a.removeChild(a.firstChild)},firstTabbable:m,lastTabbable:j,stop:function(a){if(window.document.all)a.keyCode=0;a.preventDefault&&(a.preventDefault(),a.stopPropagation())},processTextNodes:function(a,b){f(a,function(a,h){a.parentNode.replaceChild(document.createTextNode(b[h[1]]||h[1]),a)})},processDOMNodes:function(a,b){f(a,function(a,h){var i=b[h[1]];if(i){var n=document.createRange(),
c=h.index;n.setStart(a,c);n.setEnd(a,c+h[0].length);n.deleteContents();n.insertNode(i)}})},addAutoDismiss:function(a,d){function e(a){b.forEach(function(b){var n=!1,c=b.excludeNodes.some(function(b){return document.body.contains(b)?(n=!0,b.contains(a.target)):!1});if(n&&!c)try{b.dismiss()}catch(d){typeof console!=="undefined"&&console&&console.error(d&&d.message)}});b=b.filter(function(a){return a.excludeNodes.some(function(a){return document.body.contains(a)})})}b===null&&(b=[],document.addEventListener("click",
e,!0),g.isIOS&&document.addEventListener("touchend",function(a){function b(){a.target.removeEventListener("click",b)}a.touches.length===0&&a.target.addEventListener("click",b)},!1));b.push({excludeNodes:a,dismiss:d})},KEY:{BKSPC:8,TAB:9,ENTER:13,ESCAPE:27,SPACE:32,PAGEUP:33,PAGEDOWN:34,END:35,HOME:36,LEFT:37,UP:38,RIGHT:39,DOWN:40,INSERT:45,DEL:46}}});
define("domReady",[],function(){function g(){if(!b){b=!0;f&&clearInterval(f);var h=d;if(b&&h.length){d=[];var i;for(i=0;i<h.length;i+=1)h[i](a)}}}function k(h){b?h(a):d.push(h);return k}var m,j,f,e=typeof window!=="undefined"&&window.document,b=!e,a=e?document:null,d=[];if(e){if(document.addEventListener)document.addEventListener("DOMContentLoaded",g,!1),window.addEventListener("load",g,!1);else if(window.attachEvent){window.attachEvent("onload",g);j=document.createElement("div");try{m=window.frameElement===
null}catch(l){}j.doScroll&&m&&window.external&&(f=setInterval(function(){try{j.doScroll(),g()}catch(a){}},30))}document.readyState==="complete"&&g()}k.version="2.0.1";k.load=function(a,b,d,c){c.isBuild?d(null):k(d)};return k});
define('built-manageOpenids.js',["orion/xhr","orion/webui/littlelib","domReady!"],function(g,k){function m(b){if(confirm("Are you sure you want to remove "+b+" from the list of your external accounts?")){for(var i=a.properties.openid.split("\n"),d="",c=0;c<i.length;c++)i[c]!==b&&(d+=i[c]+"\n");a.properties.openid=d;g("PUT",a.Location,{data:JSON.stringify(a),headers:{"Orion-Version":"1"},timeout:15E3}).then(function(){l(a.Location)},function(a){console.error(a.error)})}}function j(a){b!==a&&
(l(a),b=a)}function f(a){a!==""&&a!==null&&window.open("../mixlogin/manageopenids/openid?openid="+encodeURIComponent(a),"openid_popup","width=790,height=580")}function e(a,b,d){var c=document.createElement("img");c.className="loginWindow";c.id=c.alt=c.title=a;c.src=b;b=document.createElement("a");b.className="loginWindow";b.onclick=d;b.setAttribute("aria-labelledby","addExternalAccount "+a);b.appendChild(c);return b}var b,a,d,l;d=function(b){a=b;var d=k.node("openidList");d.childNodes.length&&d.removeChild(d.childNodes[0]);
b=document.createElement("table");b.classList.add("manageOpenIdsTable");d.appendChild(b);if(a.properties&&a.properties.openid){for(var d=a.properties.openid?a.properties.openid.split("\n"):[],e=d.length-1;e>=0;e--)d[e]===""&&d.splice(e,1);if(d.length){e=document.createElement("thead");e.classList.add("navTableHeading");b.appendChild(e);var c=document.createElement("tr");e.appendChild(c);var f=document.createElement("td");f.classList.add("navColumn");f.innerHTML="<h2>External Id</h2>";c.appendChild(f)}for(e=
0;e<d.length;e++){var g=d[e],c=document.createElement("tr");c.classList.add(e%2===0?"lightTreeTableRow":"darkTreeTableRow");c.classList.add("manageOpenIdRow");c.style.verticalAlign="baseline";b.appendChild(c);f=document.createElement("td");f.classList.add("navColumn");c.appendChild(f);var j=document.createElement("span");j.title=g;f.appendChild(j);f=document.createTextNode(g.length>70?g.substring(0,65)+"...":g);j.appendChild(f);f=document.createElement("td");f.classList.add("navColumn");c.appendChild(f);
c=document.createElement("a");c.classList.add("removeOpenId");c.id="remlink"+e;c.innerHTML="Remove";c.style.visibility="hidden";c.title="Remove "+g;f.appendChild(c);c.addEventListener("click",function(a){m(a)}.bind(this,g))}}};l=function(a){g("GET",a,{headers:{"Orion-Version":"1"},timeout:15E3}).then(function(a){d(JSON.parse(a.response))},function(a){console.error(a.error)})};window.handleOpenIDResponse=function(b){for(var d=a.properties.openid?a.properties.openid.split("\n"):[],e=0;e<d.length;e++)if(d[e]===
b)return;a.properties.openid?a.properties.openid+="\n"+b:a.properties.openid=b;g("PUT",a.Location,{data:JSON.stringify(a),headers:{"Orion-Version":"1"},timeout:15E3}).then(function(){l(a.Location)},function(a){console.error(a.error)})};window.addEventListener("hashchange",function(){j(window.location.hash.substring(1))});j(window.location.hash.substring(1));g("GET","../mixlogin/manageopenids").then(function(a){a=JSON.parse(a.response).map(function(a){return e(a.Name,a.Image,f.bind(null,a.Url))});
a.push(e("Mozilla Persona","../mixloginstatic/images/persona.png",alert.bind(null,"To link your account with a Persona, set your Orion email address above to match your Persona email address.")));var b=document.getElementById("newOpenId");a.forEach(function(a){b.appendChild(a);b.appendChild(document.createTextNode(" "))})})});