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