/*  Copyright 2009 Google Inc.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
var popupManager={};popupManager.constants={darkCover:"popupManager_darkCover_div",darkCoverStyle:["position:absolute;","top:0px;","left:0px;","padding-right:0px;","padding-bottom:0px;","background-color:#000000;","opacity:0.5;","-moz-opacity:0.5;","filter:alpha(opacity=0.5);","z-index:10000;","width:100%;","height:100%;"].join(""),openidSpec:{identifier_select:"http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select",namespace2:"http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0"}};popupManager.getWindowInnerSize=function(){var a=0;var c=0;var b=null;if("innerWidth" in window){a=window.innerWidth;c=window.innerHeight}else{if(("BackCompat"===window.document.compatMode)&&("body" in window.document)){b=window.document.body}else{if("documentElement" in window.document){b=window.document.documentElement}}if(b!==null){a=b.offsetWidth;c=b.offsetHeight}}return[a,c]};popupManager.getParentCoords=function(){var a=0;var b=0;if("screenLeft" in window){a=window.screenLeft;b=window.screenTop}else{if("screenX" in window){a=window.screenX;b=window.screenY}}return[a,b]};popupManager.getCenteredCoords=function(a,c){var f=this.getWindowInnerSize();var e=this.getParentCoords();var d=e[0]+Math.max(0,Math.floor((f[0]-a)/2));var b=e[1]+Math.max(0,Math.floor((f[1]-c)/2));return[d,b]};popupManager.darkenScreen=function(){var a=window.document.getElementById(window.popupManager.constants.darkCover);if(!a){a=window.document.createElement("div");a.id=window.popupManager.constants.darkCover;a.setAttribute("style",window.popupManager.constants.darkCoverStyle);window.document.body.appendChild(a)}a.style.visibility="visible"};popupManager.createPopupOpener=(function(a){var i=null;var j=null;var g=this;var n=("shouldEncodeUrls" in a)?a.shouldEncodeUrls:true;var f=function(t){return(n?encodeURIComponent(t):t)};var o=("identifier" in a)?f(a.identifier):this.constants.openidSpec.identifier_select;var r=("identity" in a)?f(a.identity):this.constants.openidSpec.identifier_select;var e=("namespace" in a)?f(a.namespace):this.constants.openidSpec.namespace2;var d=(("onOpenHandler" in a)&&("function"===typeof(a.onOpenHandler)))?a.onOpenHandler:this.darkenScreen;var c=(("onCloseHandler" in a)&&("function"===typeof(a.onCloseHandler)))?a.onCloseHandler:null;var l=("returnToUrl" in a)?a.returnToUrl:null;var s=("realm" in a)?a.realm:null;var q=("opEndpoint" in a)?a.opEndpoint:null;var h=("extensions" in a)?a.extensions:null;var b=function(u){var t="";for(key in u){t+=["&",key,"=",f(u[key])].join("")}return t};var k=function(){var v="&";var u=null;var t=null;if((null===q)||(null===l)){return}if(q.indexOf("?")===-1){v="?"}u=f(l);t=[q,v,"openid.ns=",e,"&openid.mode=checkid_setup","&openid.claimed_id=",o,"&openid.identity=",r,"&openid.return_to=",u].join("");if(s!==null){t+="&openid.realm="+f(s)}if(h!==null){t+=b(h)}t+="&openid.ns.ui="+encodeURIComponent("http://specs.openid.net/extensions/ui/1.0");t+="&openid.ui.mode=popup";return t};var m=function(){return(!j||j.closed)};var p=function(){if(m()){j=null;var t=window.document.getElementById(window.popupManager.constants.darkCover);if(t){t.style.visibility="hidden"}if(c!==null){c()}if((null!==i)){window.clearInterval(i);i=null}}};return{popup:function(u,v){var t=k();if(d!==null){d()}var w=g.getCenteredCoords(u,v);j=window.open(t,"","width="+u+",height="+v+",status=1,location=1,resizable=yes,left="+w[0]+",top="+w[1]);i=window.setInterval(p,80);return true}}});