// Attach Amuso's SDK if it's not loaded yet if( typeof amusosdk === 'undefined' ) { amusosdk_url = "http://www.amuso.com"; amusosdk_templates = ["challenge", "home"]; // amusosdk_templates = ["challenge"]; document.write(""); } function externalPayment(url){ var iframe = document.getElementById('iframe'); if (iframe) iframe.src = url; document.getElementById('overtrivia').style.display = 'block'; document.getElementById('container').style.opacity = 0.2; document.getElementById('container').onmouseover = "#"; } function callFlash(transaction_ref){ getFlashMovie("amusoTrivia").externalCommand("payment", transaction_ref); } function open_div(){ var iframe = document.getElementById('iframe'); if (iframe) iframe.src = remoteUrl; document.getElementById('overtrivia').style.display = 'block'; document.getElementById('container').style.opacity = 0.2; document.getElementById('container').onmouseover = "#"; } function close_div(){ document.getElementById('container').style.opacity = 1; document.getElementById('overtrivia').style.display = 'none'; } var conf = { "APIKey": gigyaAPIKey, "enabledProviders": "facebook,myspace" }; function Connect(provider) { var params = { "callback": onConnect, "provider": provider }; gigya.services.socialize.login(conf,params); } //connect via web function webConnect(provider) { var params = { "callback": onWebConnect, "provider": provider }; gigya.services.socialize.login(conf,params); } function onConnect(response) { if (response.status=='OK') { var provider = response.user.loginProvider; gigya.services.socialize.getUserInfo(conf); if (provider=='facebook'){ var string = 'UID=' + encodeURIComponent(response.user.UID) + '&signature=' + encodeURIComponent(response.signature) + '×tamp=' + response.timestamp + '&birthdate=' + response.user.birthYear + '-' + response.user.birthMonth + '-' + response.user.birthDay + '&alias=' + response.user.identities.facebook.nickname + '&providerUID=' + response.user.identities.facebook.providerUID + '&photoURL=' + response.user.identities.facebook.photoURL; } else if (provider=='myspace'){ var string = 'UID=' + encodeURIComponent(response.user.UID) + '&signature=' + encodeURIComponent(response.signature) + '×tamp=' + response.timestamp + '&birthdate=' + response.user.birthYear + '-' + response.user.birthMonth + '-' + response.user.birthDay + '&alias=' + response.user.identities.myspace.nickname + '&providerUID=' + response.user.identities.myspace.providerUID + '&photoURL=' + response.user.identities.myspace.thumbnailURL; } formSend(provider, string); } else { //handle errors alert("An error has occurred!\n" + "Error details: " + response.statusMessage + '\n' + "In method: " + response.operation); } } function onWebConnect(response) { if (response.status=='OK') { var provider = response.user.loginProvider; gigya.services.socialize.getUserInfo(conf); if (provider=='facebook') { var string = 'UID=' + encodeURIComponent(response.user.UID) + '&signature=' + encodeURIComponent(response.signature) + '×tamp=' + response.timestamp + '&birthdate=' + response.user.birthYear + '-' + response.user.birthMonth + '-' + response.user.birthDay + '&alias=' + response.user.identities.facebook.nickname + '&providerUID=' + response.user.identities.facebook.providerUID + '&photoURL=' + response.user.identities.facebook.photoURL; } else if (provider=='myspace') { var string = 'UID=' + encodeURIComponent(response.user.UID) + '&signature=' + encodeURIComponent(response.signature) + '×tamp=' + response.timestamp + '&birthdate=' + response.user.birthYear + '-' + response.user.birthMonth + '-' + response.user.birthDay + '&alias=' + response.user.identities.myspace.nickname + '&providerUID=' + response.user.identities.myspace.providerUID + '&photoURL=' + response.user.identities.myspace.photoURL; } formWebSend(string); } else { //handle errors alert("An error has occurred!\n" + "Error details: " + response.statusMessage + '\n' + "In method: " + response.operation); } } function getFlashMovie(movieName) { var isIE = navigator.appName.indexOf("Microsoft") != -1; return (isIE) ? window[movieName] : document[movieName]; } function formSend(provider, text) { getFlashMovie("amusoTrivia").externalCommand("login", provider, text); } function formWebSend(text) { document.getElementById('from_gygia').value = text; document.getElementById('loginSubmit').submit(); } function popup(url) { mywindow = window.open (url, "trivia_popup","location=1,status=1,scrollbars=1, width=600,height=450"); } function pleaseCloseWindow() { } function urlParams(name) { return amusosdk.getURLParams(name); } function inviterLiveOpen(sessionid, shareurl, timeleft, user, sessionconfigid, partnerid) { var url = shareurl + "?sid=" + sessionid + "&timeleft=" + timeleft + "&scid=" + sessionconfigid + "&pi=" + partnerid; url = "http://www.amuso.com/inviterLive?invite_url=" + encodeURIComponent(url); popup( url ); } var triviajs = new function () { // Protect 'this' object. var self = this; var currency = {USD:"$", AUD:"$", EUR:"€", GBP:"£"}; var BASE_URL = "http://www.amuso.com"; // User datatype: this.User = function() { this.idHash = false; this.partnerId = false; this.partnerHash = false; this.nick = false; this.amount = false; this.imagePrefix = false; this.imageLink = false; this.anonymous = true; this.wallet = { amount: 0 , currency: false , points: 0 }; }; // Games datatype this.Game = function() { this.id = false; this.categoryId = false; this.categoryName = false; this.entryFee = false; this.waitTime = false; this.gameType = false; // cash / free this.kind = false; // 'session' / 'tournament' this.minPlayers = false; this.maxPlayers = false; this.startAt = false; this.minAmount = false; this.amount = true; this.currency = false; this.currencySymbol = false; this.period = false; this.players = []; }; // Reloads all page ifremes pointing amuso site. this.checkAmusoIframes = function triviajs_checkAmusoIframes() { var iframes = document.getElementsByTagName('iframe'); for ( var i in iframes ) { var ifr = iframes[i]; if( ifr && ifr.getAttribute && ifr.getAttribute("src") && ifr.getAttribute("src").match(/\.amuso\.com/) ) { var newurl = ifr.getAttribute("src") + (ifr.getAttribute("src").indexOf("?") == -1 ? "?" : "&" ) + "nc=" + Math.floor(Math.random()*100001); ifr.setAttribute("src", newurl ); } } }; // PopUp maker var mywindow = false; this.popup = function triviajs_popup(url, w, h) { if( typeof w !== 'number' ) w = 600; if( typeof h !== 'number' ) h = 450; if( mywindow && typeof mywindow.close === "function" ) mywindow.close(); mywindow = window.open (url, "trivia_popup","location=1,status=1,scrollbars=1, width="+w+",height="+h); } // Refresh userpanel info this.checkAmusoSiteDiv = function triviajs_checkAmusoSiteDiv() { var e = document.getElementById('userpanel'); if( e ) { amusosdk.ajax.recieve(BASE_URL + "/web/userInfoArea", "GET", function (req) { var p = e.parentNode; var n = document.createElement("DIV"); n.setAttribute("id","userpanel"); n.innerHTML = req.responseText; p.replaceChild( n, e ); } ); } }; // Send external command to flash self.sendFlashCommand = function triviajs_sendFlashCommand(command) { var f = getFlashMovie("amusoTrivia"); if( typeof f != 'undefined' && f ) try { f.externalCommand(command); } catch (e) { }; }; // Flash helper function to trigger widgetUserInfo event this.widgetUserInfo = function triviajs_widgetUserInfo() { if(amusosdk) amusosdk.triggerEvent(amusosdk, "widgetUserInfo", false); }; this.getMyInfoCB = function triviajs_getMyInfoCB(xmlreq, extra) { if( !xmlreq ) return false; var us = xmlreq.responseXML.documentElement.getElementsByTagName('user')[0]; var user = new self.User(); if( !us ) { user.alias = "Guest"; user.anonymous = true; user.wallet.amount = 0; if( xmlreq.responseXML.documentElement.getElementsByTagName('currency')[0] ) user.wallet.currency = xmlreq.responseXML.documentElement.getElementsByTagName('currency')[0].firstChild.data; } else { if( us.getElementsByTagName('user_id')[0] ) user.idHash = us.getElementsByTagName('user_id')[0].firstChild.data; if( us.getElementsByTagName('image_prefix')[0] ) user.imagePrefix = us.getElementsByTagName('image_prefix')[0].firstChild.data; if( us.getElementsByTagName('image_link')[0] ) user.imageLink = us.getElementsByTagName('image_link')[0].firstChild.data; if( us.getElementsByTagName('alias')[0] ) user.alias = us.getElementsByTagName('alias')[0].firstChild.data; user.anonymous = false; var wl = us.getElementsByTagName('wallet')[0]; if( wl ) { if( wl.getElementsByTagName('amount')[0] ) user.wallet.amount = parseFloat( wl.getElementsByTagName('amount')[0].firstChild.data ); if( wl.getElementsByTagName('currency')[0] ) user.wallet.currency = wl.getElementsByTagName('currency')[0].firstChild.data; if( wl.getElementsByTagName('points')[0] ) user.wallet.points = parseInt( wl.getElementsByTagName('points')[0].firstChild.data ); } } extra.getMyInfoCB.call(window, user, extra); }; this.getMyInfo = function triviajs_getMyInfo(cbfun) { amusosdk.ajax.recieve( BASE_URL + "/outerGame/getTrivia", "FPOST", self.getMyInfoCB, false, false, cbfun); }; // Lobby functions var lobbyLastData = false; var lobbyGames = 0; var lobbynewDataFlag = false; this.getLobbyCB = function triviajs_getLobbyCB(xmlreq, extra) { var allGames = []; if( !xmlreq ) extra.getLobbyCB.call(window, allGames) var gameCurrency = xmlreq.responseXML.documentElement.getElementsByTagName('currency')[0].firstChild.data; var types = ['session', 'tournament']; // For all kind of games (XML tags) for(var t = 0 ; t < types.length; t++ ) { // Get all games of this kind var gm = xmlreq.responseXML.documentElement.getElementsByTagName(types[t]); for( var i=0; i < gm.length; i++) { var game = new self.Game(); // Get their info: game.kind = types[t]; if( gm[i].getElementsByTagName('config_id')[0] ) game.id = gm[i].getElementsByTagName('config_id')[0].firstChild.data; if( gm[i].getElementsByTagName('category_id')[0] ) game.categoryId = gm[i].getElementsByTagName('category_id')[0].firstChild.data; if( gm[i].getElementsByTagName('category_name')[0] ) game.categoryName = gm[i].getElementsByTagName('category_name')[0].firstChild.data; if( gm[i].getElementsByTagName('entry_fee')[0] ) game.entryFee = gm[i].getElementsByTagName('entry_fee')[0].firstChild.data ; if( gm[i].getElementsByTagName('wait_time')[0] ) game.waitTime = gm[i].getElementsByTagName('wait_time')[0].firstChild.data; if( gm[i].getElementsByTagName('min_players')[0] ) game.minPlayers = gm[i].getElementsByTagName('min_players')[0].firstChild.data; if( gm[i].getElementsByTagName('max_players')[0] ) game.maxPlayers = gm[i].getElementsByTagName('max_players')[0].firstChild.data; if( gm[i].getElementsByTagName('start_at')[0] ) game.startAt = gm[i].getElementsByTagName('start_at')[0].firstChild.data; if( gm[i].getElementsByTagName('min_amount')[0] ) game.minAmount = gm[i].getElementsByTagName('min_amount')[0].firstChild.data; if( gm[i].getElementsByTagName('amount')[0] ) game.amount = gm[i].getElementsByTagName('amount')[0].firstChild.data; if( game.kind == "tournament" && gm[i].getElementsByTagName('type')[1] && gm[i].getElementsByTagName('type')[1].firstChild.data.toLowerCase() != "cash" && gm[i].getElementsByTagName('type')[1].firstChild.data.toLowerCase() != "points" ) game.gameType = gm[i].getElementsByTagName('type')[1].firstChild.data.toLowerCase(); else if( gm[i].getElementsByTagName('type')[0] ) game.gameType = gm[i].getElementsByTagName('type')[0].firstChild.data.toLowerCase(); game.currency = gameCurrency; game.currencySymbol = ( typeof currency[gameCurrency] != 'undefined' ? currency[gameCurrency] : gameCurrency); // Get their players: var pl = gm[i].getElementsByTagName('player'); for( var ii=0; ii < pl.length; ii++) { var player = new self.User(); if( pl[ii].getElementsByTagName('user_id')[0] ) player.idHash = pl[ii].getElementsByTagName('user_id')[0].firstChild.data; if( pl[ii].getElementsByTagName('image_prefix')[0] ) player.imagePrefix = pl[ii].getElementsByTagName('image_prefix')[0].firstChild.data; if( pl[ii].getElementsByTagName('image_link')[0] ) player.imageLink = pl[ii].getElementsByTagName('image_link')[0].firstChild.data; game.players.push( player ); } allGames.push( game ); } } ret = extra.getLobbyCB.call(window, allGames, extra); }; this.getLobby = function triviajs_getLobby(cbfun, partner) { amusosdk.ajax.recieve( BASE_URL + "/outerGame/getLobby" + ( typeof partner === 'string' ? "?partner_hash=" + partner : "" ), "FPOST", self.getLobbyCB, false, false, cbfun); }; this.getFullLobby = function triviajs_getFullLobby( partner ) { cbfun = {getLobbyCB: function(d) { lobbyLastData = d; lobbynewDataFlag = true; } }; self.getLobby(cbfun, partner); }; this.timedLobbyAutoUpdate = function timedLobbyAutoUpdate() { var templates = false; var div = false; var ms = (new Date()).getTime(); var gap = self.getTimeGap(); if(lobbyLastData) { for(var g=0; g < lobbyLastData.length; g++) { var start = 0; start = Math.round( (lobbyLastData[g].startAt - ms - gap) / 1000 ); if( start <= 0 ) start = "soon"; else start += " sec."; var prize = ( lobbyLastData[g].players.length >= lobbyLastData[g].minPlayers || lobbyLastData[g].kind == 'tournament' ? lobbyLastData[g].amount : lobbyLastData[g].minAmount ); if( !prize || prize == 0 || lobbyLastData[g].gameType == "free" ) prize = "none"; else prize = lobbyLastData[g].currencySymbol + " " + prize; var existing = document.getElementById("gameTime" + lobbyLastData[g].kind+lobbyLastData[g].id) if( typeof existing != 'undefined' && existing ) { existing.innerHTML = start; if( lobbynewDataFlag ) { document.getElementById("gamePlayers" + lobbyLastData[g].kind+lobbyLastData[g].id).innerHTML = lobbyLastData[g].players.length; document.getElementById("gamePrize" + lobbyLastData[g].kind+lobbyLastData[g].id).innerHTML = prize; } } else { if( !templates ) templates = amusosdk.getTemplate("home"); if( !div ) div = document.getElementById('lobby-container'); lobbyGames++; var daily = ""; var ribbon = ""; if(lobbyLastData[g].kind == "tournament" ) { daily = "
daily
"; ribbon = "daily"; } if(lobbyLastData[g].kind == "tournament" && lobbyLastData[g].gameType == "weekly" ) { daily = "
weekly
"; ribbon = "weekly"; } var newGame = document.createElement("DIV"); var extraClass = (lobbyGames % 2 == 0 ? " margin" : "" ) + (lobbyLastData[g].kind == "tournament" ? " daily " + ribbon : ""); div.appendChild(newGame); newGame.setAttribute("class", "lobby-box" + extraClass); newGame.setAttribute("className", "lobby-box" + extraClass ); newGame.setAttribute("id", "game"+lobbyLastData[g].kind+lobbyLastData[g].id); var rootURL = (typeof triviajs_gameURL == 'undefined' ? location.href : triviajs_gameURL ); var data = { id:lobbyLastData[g].id, link: rootURL + ( rootURL.indexOf("?") == -1 ? "?" : "&") + "scid="+lobbyLastData[g].id, categoryName:lobbyLastData[g].categoryName, kind:lobbyLastData[g].kind, prize:prize, start:start, daily:daily, fee:( lobbyLastData[g].gameType == "free" || lobbyLastData[g].entryFee <= 0 ? "Free" : lobbyLastData[g].currencySymbol + " " + lobbyLastData[g].entryFee ), nPlayers:lobbyLastData[g].players.length, baseurl:BASE_URL }; var html = amusosdk.fillTemplate( templates["lobbyGame"], data ); newGame.innerHTML = html; } } if( lobbynewDataFlag ) lobbynewDataFlag = false; } }; var srvTimeDelta = 0; this.srvTimeCB = function triviajs_srvTimeCB(xmlreq, extra) { var srvTimeTrep = (new Date()).getTime(); var srvTimeSrep = parseInt( xmlreq.responseXML.documentElement.getElementsByTagName('time')[0].firstChild.data, 10); var d = srvTimeTrep - extra.srvTimeTreq; var c = srvTimeTrep - (srvTimeSrep + d*0.5) ; if( 0 == srvTimeDelta ) srvTimeDelta = c; else srvTimeDelta = (srvTimeDelta*0.9+c*0.1); if (--extra.times > 0) { window.setTimeout( function() { triviajs.srvTime( extra.times ); }, 1000); } }; this.srvTime = function triviajs_srvTime(times) { if(typeof times !== 'number' ) times = 4; var extra = {times: times, srvTimeTreq: (new Date()).getTime() }; amusosdk.ajax.recieve( BASE_URL + "/outerGame/getMsTime", "FPOST", self.srvTimeCB, false, false, extra); }; this.getTimeGap = function triviajs_getTimeGap() { return srvTimeDelta; }; function paintFeedsCB(xmlreq, extra) { if( !xmlreq ) return false; if( xmlreq.responseXML.documentElement.getElementsByTagName('error')[0] ) return false; var html = ""; var feeds = xmlreq.responseXML.documentElement.getElementsByTagName("node"); for( var i=0; i < feeds.length; i++) { var alias = feeds[i].getElementsByTagName('alias')[0].firstChild.data; var img = feeds[i].getElementsByTagName('img')[0].firstChild.data; var desc = feeds[i].getElementsByTagName('description')[0].firstChild.data; desc = desc.substring( desc.indexOf( "won ") + 4 ); desc = desc.substring( 0, desc.toLowerCase().indexOf( "this week") -1 ); html += "\n\"\"

" + alias + "

won " + desc + "

So can you

"; } document.getElementById("winners-feed-list").innerHTML = html; return true; }; this.paintFeeds = function triviajs_paintFeeds() { // amusosdk.ajax.recieve( BASE_URL + "/ajaxservices/getFeeds", "FPOST", paintFeedsCB, false, false, {}); }; var challengeWin = false; var challengeScid = ''; this.getChallengeScid = function triviajs_getChallengeScid() { return challengeScid; } function openChallengeCB(xmlreq, extra) { var tpl = amusosdk.getTemplate("challenge"); var users = ""; var pages = 0; var pagination = ""; challengeScid = "" + extra.sid + "" + xmlreq.responseText.substring(xmlreq.responseText.indexOf("") + 8, xmlreq.responseText.indexOf("") + 9 ) var challengers = xmlreq.responseXML.documentElement.getElementsByTagName('users')[0]; if(challengers) challengers = challengers.getElementsByTagName('node'); if( !challengers[0] ) { users = "

No challengers at this time.

"; } else { for( var i=0; i < challengers.length; i++) { var idHash = challengers[i].getElementsByTagName('user_id')[0].firstChild.data; var image = "http://" + challengers[i].getElementsByTagName('image_link')[0].firstChild.data + "-sq4040.jpg"; var user = challengers[i].getElementsByTagName('alias')[0].firstChild.data; var tplData = { idHash:idHash, user:user, image:image, title:"Challenge " + user + "!" }; if( i % 10 == 0 ) users += "
"; users += amusosdk.fillTemplate( tpl["challengeUser"], tplData ); if( i % 10 == 9 ) users += "
"; } if( i % 10 != 9 ) users += ""; pages = Math.floor(i/10) + 1; if( pages > 2 ) { for(i=1; i <= pages; i++) { pagination += "" + i + ""; } if ( pagination != "" ) pagination = "
  • Prev
  • " + pagination + "
  • Next
  • "; } } var data = { challengers:users, user:extra.user, scid:extra.scid, url:extra.url, partner:extra.partner, pagination:pagination, pages:pages, server:BASE_URL, alias:extra.alias, sid:extra.sid }; var html = amusosdk.fillTemplate( tpl["challengePage"], data ); challengeWin = window.open ("", "triviaChallenge","location=0,status=0,menubar=0,resizable=1,width=600,height=450"); challengeWin.document.write( html ); }; this.openChallenge = function triviajs_openChallenge(user, scid, url, partner, alias, sid) { if( challengeWin && typeof challengeWin.close === "function" ) challengeWin.close(); amusosdk.ajax.recieve( BASE_URL + "/ajaxservices/getChallengablePlayers?scid=" + scid, "FPOST", openChallengeCB, false, false, {user:user, scid:scid, url:url, partner:partner, alias:alias, sid:sid}); }; this.closeChallenge = function triviajs_closeChallenge() { if( challengeWin && typeof challengeWin.close === "function" ) challengeWin.close(); challengeWin = false; }; function paintTournamentTopCB(xmlreq, extra) { if( !xmlreq ) return false; if( xmlreq.responseXML.documentElement.getElementsByTagName('error')[0] ) return false; var templates = amusosdk.getTemplate('home'); var html = ""; var root = xmlreq.responseXML.documentElement.getElementsByTagName("tournamentTop")[0]; for( var i=0; i < root.childNodes.length; i++) { var tournament = root.childNodes[i]; var name = tournament.getElementsByTagName('name')[0].firstChild.data; var phpDate = tournament.getElementsByTagName('end_at')[0].firstChild.data; var endDate = phpDate.substring(8,10) + "-" + phpDate.substring(5,7) + "-" + phpDate.substring(0,4) + " " + phpDate.substring(11); if( extra.wanted[name] && extra.wanted[name] > 0 ) { var html = ""; var topPlayers = tournament.getElementsByTagName('top')[0].getElementsByTagName('node'); for( var ii=0; ii 0 ) { if ( max < num ) max = num; wanted[el] = num; } else wanted[el] = 1; } } if(found > 0) { var templates = amusosdk.getTemplate("home"); var css = document.createElement("STYLE"); css.setAttribute("type", "text/css"); div.insertBefore(css, div.firstChild) if (css.styleSheet) css.styleSheet.cssText = amusosdk.fillTemplate(templates["topRankingCss"], {baseurl:BASE_URL}); else css.appendChild(document.createTextNode(amusosdk.fillTemplate(templates["topRankingCss"], {baseurl:BASE_URL}) ) ); self.paintTournamentTop(wanted, max); } } // Full lobby (if exists): var div = document.getElementById('lobby-container'); if( div ) { // Fill css info var templates = amusosdk.getTemplate("home"); var css = document.createElement("STYLE"); css.setAttribute("type", "text/css"); div.appendChild(css); if (css.styleSheet) css.styleSheet.cssText = amusosdk.fillTemplate( templates["lobbyBox"], {baseurl:BASE_URL} ); else css.appendChild(document.createTextNode( amusosdk.fillTemplate( templates["lobbyBox"], {baseurl:BASE_URL} ) )); // Get info and start timers self.getFullLobby(); window.setInterval(self.timedLobbyAutoUpdate, 250); window.setInterval(self.getFullLobby, 7000); } }; }; // End of triviajs object // ATTACH OBSERVED EVENTS/MESSAGES ON WEB PAGE after amusosdk is loaded: function amusosdk_init() { // If we are NOT in amuso.com attach iframe checker function to widgetUserInfo message (from flash) // If we are in amuso.com attach userinfo div refresher to widgetUserInfo message if( location.href.match(/\.amuso\.com/) ) amusosdk.addEvent(amusosdk, "widgetUserInfo", triviajs.checkAmusoSiteDiv ); else amusosdk.addEvent(amusosdk, "widgetUserInfo", triviajs.checkAmusoIframes ); // Attach flash notifier to pageUnload message amusosdk.addEvent(amusosdk, "pageUnLoad", function() { triviajs.sendFlashCommand("unload"); } ); // Attach triviajs initializer to pageLoad event amusosdk.addEvent(amusosdk, "pageLoad", triviajs.init ); };