/*******************************************************************************
 * @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
 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(i,j){typeof define==="function"&&define.amd?define("orion/Deferred",j):typeof exports==="object"?module.exports=j():(i.orion=i.orion||{},i.orion.Deferred=j())})(this,function(){function i(){for(var h;h=f.shift()||a.shift();)h();b=!1}function j(h,e){(e?a:f).push(h);b||(b=!0,e?setTimeout(i,0):i())}function l(a){return function(){a.apply(null,arguments)}}function m(){}function g(){var a=Error("Cancel");a.name="Cancel";return a}function c(){function a(){for(var d;d=k.shift();){var h=d.deferred,
b=n==="resolved"?"resolve":"reject";if(typeof d[b]==="function")try{var c=d[b](e);c&&typeof c.then==="function"?(h.cancel=c.cancel||m,c.then(l(h.resolve),l(h.reject),h.progress)):h.resolve(c)}catch(g){h.reject(g)}else h[b](e)}}var e,n,k=[],d=this;this.reject=function(b){n||(n="rejected",e=b,k.length&&j(a));return d.promise};this.resolve=function(b){n||(n="resolved",e=b,k.length&&j(a));return d.promise};this.progress=function(a){n||k.forEach(function(e){e.progress&&e.progress(a)});return d.promise};
this.cancel=function(){n||d.reject(g())};this.then=function(e,b,g){var e={resolve:e,reject:b,progress:g,deferred:new c},f=e.deferred,i=!1,l=function(){i||(i=!0,j(function(){var a=f.cancel===l?d.cancel:f.cancel;typeof a==="function"&&a()},!0))};f.cancel=l;k.push(e);n&&j(a,!0);return f.promise};this.promise=Object.create(Object.prototype,{then:{value:d.then},cancel:{get:function(){return d.cancel},set:function(a){d.cancel=a}}})}var f=[],a=[],b=!1;c.all=function(a,e){function b(a,e){f||(g[a]=e,--d===
0&&i.resolve(g))}function k(a,d){if(!f){if(e)try{b(a,e(d));return}catch(k){d=k}i.reject(d)}}var d=a.length,g=[],f=!1,i=new c;i.then(null,function(){f=!0;a.forEach(function(a){a.cancel&&a.cancel()})});d===0?i.resolve(g):a.forEach(function(a,e){a.then(b.bind(null,e),k.bind(null,e))});return i.promise};c.when=function(a,e,b,k){var d;if(!(a&&typeof a.then==="function"))d=new c,d.resolve(a),a=d.promise;return a.then(e,b,k)};return c});
define("orion/xhr",["orion/Deferred"],function(i){function j(i,j,g,c){var f=typeof g.response!=="undefined"?g.response:g.responseText,a;try{a=g.status}catch(b){a=0}i={args:j,response:f,responseText:typeof f==="string"?f:null,status:a,url:i,xhr:g};if(typeof c!=="undefined")i.error=c;return i}return function(l,m,g){var g=g||{},c=arguments.length>3&&arguments[3]?arguments[3]:new XMLHttpRequest,f=new i,a=g.headers||{},b=g.log||!1,h;typeof a["X-Requested-With"]==="undefined"&&(a["X-Requested-With"]="XMLHttpRequest");
if(typeof g.data!=="undefined"&&(l==="POST"||l==="PUT"))h=g.data;c.onprogress=function(a){a.xhr=c;f.progress(a)};c.onreadystatechange=function(){if(c.readyState===4){var a=j(m,g,c),e=c.status;200<=e&&e<400?f.resolve(a):(b&&typeof console!=="undefined"&&console.log(Error(c.statusText)),f.reject(a))}};try{c.open(l,m,!0);if(typeof g.responseType==="string")c.responseType=g.responseType;if(typeof g.timeout==="number")if(typeof c.timeout==="number")c.timeout=g.timeout,c.addEventListener("timeout",function(){f.reject(j(m,
g,c,"Timeout exceeded"))});else{var e=setTimeout(function(){f.reject(j(m,g,c,"Timeout exceeded"))},g.timeout);f.then(clearTimeout.bind(null,e),clearTimeout.bind(null,e))}Object.keys(a).forEach(function(e){c.setRequestHeader(e,a[e])});c.send(h)}catch(n){f.reject(j(m,g,c,n))}return f.promise}});
define("orion/webui/littlelib",[],function(){function i(a,b){b||(b=document);return b.querySelectorAll(a)}function j(a,b){var h=a.compareDocumentPosition(b);return a===b||Boolean(h&16)}function l(a){if(a.tabIndex>=0)return a;if(a.hasChildNodes())for(var b=0;b<a.childNodes.length;b++){var h=l(a.childNodes[b]);if(h)return h}return null}function m(a){if(a.tabIndex>=0)return a;if(a.hasChildNodes())for(var b=a.childNodes.length-1;b>=0;b--){var h=m(a.childNodes[b]);if(h)return h}return null}function g(a,
b){if(a.nodeType===3){var h=c.exec(a.nodeValue);h&&h.length>1&&b(a,h)}if(a.hasChildNodes())for(h=0;h<a.childNodes.length;h++)g(a.childNodes[h],b)}var c=/\$\{([^\}]+)\}/,f=[];return{$:function(a,b){b||(b=document);return b.querySelector(a)},$$:i,$$array:function(a,b){return Array.prototype.slice.call(i(a,b))},node:function(a){var b=a;typeof a==="string"&&(b=document.getElementById(a));return b},contains:j,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:l,lastTabbable:m,stop:function(a){window.document.all?a.keyCode=0:(a.preventDefault(),a.stopPropagation())},processTextNodes:function(a,b){g(a,function(a,e){a.parentNode.replaceChild(document.createTextNode(b[e[1]]||e[1]),a)})},processDOMNodes:function(a,b){g(a,function(a,e){var n=b[e[1]];if(n){var k=document.createRange(),d=e.index;k.setStart(a,d);k.setEnd(a,
d+e[0].length);k.deleteContents();k.insertNode(n)}})},addAutoDismiss:function(a,b){f.length===0&&document.addEventListener("click",function(a){for(var e=[],b=0;b<f.length;b++){var k=f[b].dismiss,d=!1,c;if(f[b].excludeNodes.every(function(e){return e&&(d=document.compareDocumentPosition(document,e)!==1)&&j(e,a.target)?(c=e,!1):!0})){try{k()}catch(g){typeof console!=="undefined"&&console&&console.error(g&&g.message)}d=document.compareDocumentPosition(document,c)!==1}d&&e.push(f[b])}f=e},!0);f.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 i(){if(!f){f=!0;g&&clearInterval(g);var e=b;if(f&&e.length){b=[];var c;for(c=0;c<e.length;c+=1)e[c](a)}}}function j(e){f?e(a):b.push(e);return j}var l,m,g,c=typeof window!=="undefined"&&window.document,f=!c,a=c?document:null,b=[];if(c){if(document.addEventListener)document.addEventListener("DOMContentLoaded",i,!1),window.addEventListener("load",i,!1);else if(window.attachEvent){window.attachEvent("onload",i);m=document.createElement("div");try{l=window.frameElement===
null}catch(h){}m.doScroll&&l&&window.external&&(g=setInterval(function(){try{m.doScroll(),i()}catch(a){}},30))}document.readyState==="complete"&&i()}j.version="2.0.1";j.load=function(a,b,c,d){d.isBuild?c(null):j(c)};return j});
define('built-manageOpenids.js',["orion/xhr","orion/webui/littlelib","domReady!"],function(i,j){function l(e){if(confirm("Are you sure you want to remove "+e+" from the list of your external accounts?")){for(var b=a.properties.openid.split("\n"),c="",d=0;d<b.length;d++)b[d]!==e&&(c+=b[d]+"\n");a.properties.openid=c;i("PUT",a.Location,{data:JSON.stringify(a),headers:{"Orion-Version":"1"},timeout:15E3}).then(function(){h(a.Location)},function(a){console.error(a.error)})}}function m(a){f!==a&&
(h(a),f=a)}function g(a){a!==""&&a!==null&&window.open("../mixlogin/manageopenids/openid?openid="+encodeURIComponent(a),"openid_popup","width=790,height=580")}function c(a,b,c){var d=document.createElement("img");d.className="loginWindow";d.id=d.alt=d.title=a;d.src=b;b=document.createElement("a");b.className="loginWindow";b.onclick=c;b.setAttribute("aria-labelledby","addExternalAccount "+a);b.appendChild(d);return b}var f,a,b,h;b=function(b){a=b;b=document.createElement("table");b.classList.add("manageOpenIdsTable");
j.node("openidList").appendChild(b);if(a.properties&&a.properties.openid){var c=a.properties.openid?a.properties.openid.split("\n"):[];if(c.length>0){var g=document.createElement("thead");g.classList.add("navTableHeading");b.appendChild(g);var d=document.createElement("tr");g.appendChild(d);var f=document.createElement("td");f.classList.add("navColumn");f.innerHTML="<h2>External Id</h2>";d.appendChild(f)}for(g=0;g<c.length;g++){var h=c[g];if(h!==""){d=document.createElement("tr");d.classList.add(g%
2===0?"lightTreeTableRow":"darkTreeTableRow");d.classList.add("manageOpenIdRow");d.style.verticalAlign="baseline";b.appendChild(d);f=document.createElement("td");f.classList.add("navColumn");d.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");d.appendChild(f);d=document.createElement("a");d.classList.add("removeOpenId");d.id="remlink"+
g;d.innerHTML="Remove";d.style.visibility="hidden";d.title="Remove "+h;f.appendChild(d);d.addEventListener("click",function(a){l(a)}.bind(this,h))}}}};h=function(a){i("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 c=a.properties.openid?a.properties.openid.split("\n"):[],f=0;f<c.length;f++)if(c[f]===b)return;a.properties.openid?a.properties.openid+="\n"+b:a.properties.openid=
b;i("PUT",a.Location,{data:JSON.stringify(a),headers:{"Orion-Version":"1"},timeout:15E3}).then(function(){h(a.Location)},function(a){console.error(a.error)})};window.addEventListener("hashchange",function(){m(window.location.hash.substring(1))});m(window.location.hash.substring(1));i("GET","../mixlogin/manageopenids").then(function(a){a=JSON.parse(a.response).map(function(a){return c(a.Name,a.Image,g.bind(null,a.Url))});a.push(c("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(" "))})})});