var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t,o,r,n,i,s,a,c="",u=0;for(e=Base64._utf8_encode(e);u>2,i=(3&t)<<4|o>>4,s=(15&o)<<2|r>>6,a=63&r,isNaN(o)?s=a=64:isNaN(r)&&(a=64),c=c+this._keyStr.charAt(n)+this._keyStr.charAt(i)+this._keyStr.charAt(s)+this._keyStr.charAt(a);return c},_utf8_encode:function(e){e=e.replace(/\r\n/g,"\n");for(var t="",o=0;or?t+=String.fromCharCode(r):r>127&&2048>r?(t+=String.fromCharCode(r>>6|192),t+=String.fromCharCode(63&r|128)):(t+=String.fromCharCode(r>>12|224),t+=String.fromCharCode(r>>6&63|128),t+=String.fromCharCode(63&r|128))}return t}},OAUTH={popup:null,callback:null,authz_code:null,access_token:null,refresh_token:null,token_expires_in:null,init:function(e){OAUTH.options=$.extend(OAUTH.options,e);try{window.addEventListener("message",OAUTH.receiveMessage,!1)}catch(t){window.attachEvent("message",OAUTH.receiveMessage)}},login:function(e){var t=500,o=300,r=$(document).width()/2-t/2,n=$(document).height()/2-o/2;features=[],features.push("title="+OAUTH.guid()),features.push("width="+t),features.push("height="+o),features.push("left="+r),features.push("top="+n),features.push("scrollbars=1"),features.push("location=1,toolbar=0"),features=features.join(","),id=OAUTH.guid(),url=OAUTH.options.base_url+"/ms_oauth/oauth2/endpoints/"+OAUTH.options.service_profile+"/authorize?response_type=code&client_id="+OAUTH.options.client_id+"&redirect_uri="+OAUTH.options.redirect_uri+"&scope=UserProfileATG.me";try{OAUTH.popup=window.open(url,id,features),OAUTH.callback=e,OAUTH.popupMonitor()}catch(i){}},popupMonitor:function(){try{OAUTH.popup.closed?OAUTH.popupInterval&&(clearInterval(OAUTH.popupInterval),OAUTH.popupInterval=null):OAUTH.popupInterval||(OAUTH.popupInterval=setInterval(OAUTH.popupMonitor,100))}catch(e){}},receiveMessage:function(e){e.data.auth_code&&(OAUTH.authz_code=e.data.auth_code,OAUTH.get_token(OAUTH.callback))},get_new_token:function(e){if(OAUTH.refresh_token){var t=OAUTH.options.base_url+"/ms_oauth/oauth2/endpoints/"+OAUTH.options.service_profile+"/tokens?grant_type=refresh_token&client_id="+OAUTH.options.client_id+"&redirect_uri="+OAUTH.options.redirect_uri+"&refresh_token="+OAUTH.refresh_token+"&scope=UserProfileATG.me",o=Base64.encode(OAUTH.options.client_id+":"+OAUTH.options.client_secret);$.ajax({url:t,type:"POST",dataType:"json",crossDomain:!0,contentType:!1,headers:{Authorization:"Basic "+o},success:function(t){t.access_token&&(OAUTH.access_token=t.access_token,OAUTH.refresh_token=t.refresh_token,OAUTH.token_expires_in=t.expires_in,e(t))},error:function(t,o,r){e("Request failed: "+o)}})}else e({error:"No refresh token available"})},get_token:function(e){var t=OAUTH.options.base_url+"/ms_oauth/oauth2/endpoints/"+OAUTH.options.service_profile+"/tokens?grant_type=authorization_code&redirect_uri="+OAUTH.options.redirect_uri+"&code="+OAUTH.authz_code+"&client_id="+OAUTH.options.client_id+"&scope=UserProfileATG.me",o=Base64.encode(OAUTH.options.client_id+":"+OAUTH.options.client_secret);$.ajax({url:t,type:"POST",dataType:"json",crossDomain:!0,contentType:!1,headers:{Authorization:"Basic "+o},success:function(t){t.access_token&&(OAUTH.access_token=t.access_token,OAUTH.refresh_token=t.refresh_token,OAUTH.token_expires_in=t.expires_in,e(t))},error:function(t,o,r){e("Request failed: "+o)}})},get_login_status:function(e){OAUTH.callback=e;var t=OAUTH.options.base_url+"/ms_oauth/oauth2/endpoints/"+OAUTH.options.service_profile+"/authorize?response_type=code&client_id="+OAUTH.options.client_id+"&redirect_uri="+OAUTH.options.redirect_uri+"&scope=UserProfileATG.me",o=OAUTH.guid();$("