/*******************************************************************************
 * @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 1.0.0 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
 * Available via the MIT or new BSD license.
 * see: http://github.com/jrburke/requirejs for details
 */
/*******************************************************************************
 * @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
 ******************************************************************************/
/*

 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 1.0.0 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
 Available via the MIT or new BSD license.
 see: http://github.com/jrburke/requirejs 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(m,l){typeof define==="function"&&define.amd?define("orion/Deferred",[],l):typeof exports==="object"?module.exports=l():(m.orion=m.orion||{},m.orion.Deferred=l())})(this,function(){function m(){for(var f;f=i.shift()||a.shift();)f();b=!1}function l(f,j){(j?a:i).push(f);b||(b=!0,j?setTimeout(m,0):m())}function k(a){return function(){a.apply(null,arguments)}}function h(){}function e(){var a=Error("Cancel");a.name="Cancel";return a}function d(){function a(){for(var c;c=g.shift();){var f=c.deferred,
b=n==="resolved"?"resolve":"reject";if(typeof c[b]==="function")try{var d=c[b](j);d&&typeof d.then==="function"?(f.cancel=d.cancel||h,d.then(k(f.resolve),k(f.reject),f.progress)):f.resolve(d)}catch(e){f.reject(e)}else f[b](j)}}var j,n,g=[],c=this;this.reject=function(b){n||(n="rejected",j=b,g.length&&l(a));return c.promise};this.resolve=function(b){n||(n="resolved",j=b,g.length&&l(a));return c.promise};this.progress=function(a){n||g.forEach(function(g){g.progress&&g.progress(a)});return c.promise};
this.cancel=function(){n||c.reject(e())};this.then=function(c,j,b){var c={resolve:c,reject:j,progress:b,deferred:new d},e=c.deferred,i=this.cancel.bind(this),h=function(){l(function(){(e.cancel===h?i:e.cancel)()},!0)};e.cancel=h;j=e.promise;j.cancel=function(){e.cancel()};g.push(c);n&&l(a,!0);return j};this.promise={then:this.then,cancel:this.cancel}}var i=[],a=[],b=!1;d.all=function(a,j){function b(a,g){i||(e[a]=g,--c===0&&h.resolve(e))}function g(a,g){if(!i){if(j)try{b(a,j(g));return}catch(c){g=
c}h.reject(g)}}var c=a.length,e=[],i=!1,h=new d;h.then(null,function(){i=!0;a.forEach(function(a){a.cancel&&a.cancel()})});c===0?h.resolve(e):a.forEach(function(a,c){a.then(b.bind(null,c),g.bind(null,c))});return h.promise};d.when=function(a,j,b,g){var c;if(!(a&&typeof a.then==="function"))c=new d,c.resolve(a),a=c.promise;return a.then(j,b,g)};return d});
define("orion/xhr",["orion/Deferred"],function(m){function l(k,h,e,d){var i=typeof e.response!=="undefined"?e.response:e.responseText,a;try{a=e.status}catch(b){a=0}k={args:h,response:i,responseText:typeof i==="string"?i:null,status:a,url:k,xhr:e};if(typeof d!=="undefined")k.error=d;return k}return function(k,h,e){var e=e||{},d=arguments.length>3&&arguments[3]?arguments[3]:new XMLHttpRequest,i=new m,a=e.headers||{},b=e.log||!1,f;typeof a["X-Requested-With"]==="undefined"&&(a["X-Requested-With"]="XMLHttpRequest");
if(typeof e.data!=="undefined"&&(k==="POST"||k==="PUT"))f=e.data;if(typeof e.responseType==="string")d.responseType=e.responseType;d.onprogress=function(a){a.xhr=d;i.progress(a)};d.onreadystatechange=function(){if(d.readyState===4){var a=l(h,e,d),c=d.status;200<=c&&c<400?i.resolve(a):(b&&typeof console!=="undefined"&&console.log(Error(d.statusText)),i.reject(a))}};try{d.open(k,h,!0);if(typeof e.timeout==="number")if(typeof d.timeout==="number")d.timeout=e.timeout,d.addEventListener("timeout",function(){i.reject(l(h,
e,d,"Timeout exceeded"))});else{var j=setTimeout(function(){i.reject(l(h,e,d,"Timeout exceeded"))},e.timeout);i.then(clearTimeout.bind(null,j),clearTimeout.bind(null,j))}Object.keys(a).forEach(function(g){d.setRequestHeader(g,a[g])});d.send(f)}catch(n){i.reject(l(h,e,d,n))}return i.promise}});
define("orion/webui/littlelib",["require"],function(){function m(a,b){b||(b=document);return b.querySelectorAll(a)}function l(a,b){var f=a.compareDocumentPosition(b);return a===b||Boolean(f&16)}function k(a){if(a.tabIndex>=0)return a;if(a.hasChildNodes())for(var b=0;b<a.childNodes.length;b++){var f=k(a.childNodes[b]);if(f)return f}return null}function h(a){if(a.tabIndex>=0)return a;if(a.hasChildNodes())for(var b=a.childNodes.length-1;b>=0;b--){var f=h(a.childNodes[b]);if(f)return f}return null}function e(a,
b){if(a.nodeType===3){var f=d.exec(a.nodeValue);f&&f.length>1&&a.parentNode.replaceChild(document.createTextNode(b[f[1]]||f[1]),a)}if(a.hasChildNodes())for(f=0;f<a.childNodes.length;f++)e(a.childNodes[f],b)}var d=/\$\{([^\}]+)\}/,i=[];return{$:function(a,b){b||(b=document);return b.querySelector(a)},$$:m,$$array:function(a,b){return Array.prototype.slice.call(m(a,b))},node:function(a){var b=a;typeof a==="string"&&(b=document.getElementById(a));return b},contains:l,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:k,lastTabbable:h,stop:function(a){window.document.all?a.keyCode=0:(a.preventDefault(),a.stopPropagation())},processTextNodes:e,addAutoDismiss:function(a,b){i.length===0&&document.addEventListener("click",function(a){for(var j=[],b=0;b<i.length;b++){for(var g=i[b].excludeNodes,c=i[b].dismiss,e=!1,d=!0,h=0;h<
g.length;h++)if((e=document.compareDocumentPosition(document,g[h])!==1)&&l(g[h],a.target)){d=!1;break}d&&(c(),e=document.compareDocumentPosition(document,g[h])!==1);e&&j.push(i[b])}i=j},!0);i.push({excludeNodes:a,dismiss:b})},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 m(a){for(var c=0,b;b=a[c];c++)b(i)}function l(){var g=a,c=b;d&&(g.length&&(a=[],m(g)),f.resourcesDone&&c.length&&(b=[],m(c)))}function k(){d||(d=!0,n&&clearInterval(n),l())}function h(b){d?b(i):a.push(b);return h}var e=typeof window!=="undefined"&&window.document,d=!e,i=e?document:null,a=[],b=[],f=requirejs||require||{},j=f.resourcesReady,n;if("resourcesReady"in f)f.resourcesReady=function(a){j&&j(a);a&&l()};e&&(document.addEventListener?(document.addEventListener("DOMContentLoaded",
k,!1),window.addEventListener("load",k,!1)):window.attachEvent&&(window.attachEvent("onload",k),self===self.top&&(n=setInterval(function(){try{document.body&&(document.documentElement.doScroll("left"),k())}catch(a){}},30))),document.readyState==="complete"&&k());h.withResources=function(a){d&&f.resourcesDone?a(i):b.push(a);return h};h.version="1.0.0";h.load=function(a,c,b,j){j.isBuild?b(null):h(b)};return h});
define("mixloginstatic/manageOpenids",["orion/xhr","orion/webui/littlelib","domReady!"],function(m,l){function k(b){if(confirm("Are you sure you want to remove "+b+" from the list of your external accounts?")){for(var e=a.properties.openid.split("\n"),g="",c=0;c<e.length;c++)e[c]!==b&&(g+=e[c]+"\n");a.properties.openid=g;m("PUT",a.Location,{data:JSON.stringify(a),headers:{"Orion-Version":"1"},timeout:15E3}).then(function(){f(a.Location)},function(a){console.error(a.error)})}}function h(a){i!==a&&
(f(a),i=a)}function e(a){a!==""&&a!==null&&window.open("../mixlogin/manageopenids/openid?openid="+encodeURIComponent(a),"openid_popup","width=790,height=580")}function d(a,b,g){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=g;b.setAttribute("aria-labelledby","addExternalAccount "+a);b.appendChild(c);return b}var i,a,b,f;b=function(b){a=b;b=document.createElement("table");b.classList.add("manageOpenIdsTable");
l.node("openidList").appendChild(b);if(a.properties&&a.properties.openid){var e=a.properties.openid?a.properties.openid.split("\n"):[];if(e.length>0){var g=document.createElement("thead");g.classList.add("navTableHeading");b.appendChild(g);var c=document.createElement("tr");g.appendChild(c);var d=document.createElement("td");d.classList.add("navColumn");d.innerHTML="<h2>External Id</h2>";c.appendChild(d)}for(g=0;g<e.length;g++){var f=e[g];if(f!==""){c=document.createElement("tr");c.classList.add(g%
2===0?"lightTreeTableRow":"darkTreeTableRow");c.classList.add("manageOpenIdRow");c.style.verticalAlign="baseline";b.appendChild(c);d=document.createElement("td");d.classList.add("navColumn");c.appendChild(d);var h=document.createElement("span");h.title=f;d.appendChild(h);d=document.createTextNode(f.length>70?f.substring(0,65)+"...":f);h.appendChild(d);d=document.createElement("td");d.classList.add("navColumn");c.appendChild(d);c=document.createElement("a");c.classList.add("removeOpenId");c.id="remlink"+
g;c.innerHTML="Remove";c.style.visibility="hidden";c.title="Remove "+f;d.appendChild(c);c.addEventListener("click",function(a){k(a)}.bind(this,f))}}}};f=function(a){m("GET",a,{headers:{"Orion-Version":"1"},timeout:15E3}).then(function(a){b(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;m("PUT",a.Location,{data:JSON.stringify(a),headers:{"Orion-Version":"1"},timeout:15E3}).then(function(){f(a.Location)},function(a){console.error(a.error)})};window.addEventListener("hashchange",function(){h(window.location.hash.substring(1))});h(window.location.hash.substring(1));m("GET","../mixlogin/manageopenids").then(function(a){a=JSON.parse(a.response).map(function(a){return d(a.Name,a.Image,e.bind(null,a.Url))});a.push(d("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(" "))})})});