﻿function resizeIframeToFitContent(iframe) {
    // This function resizes an IFrame object
    // to fit its content.
    var heightIframe;
    if (document.getElementById(iframe.id).contentDocument) {
        heightIframe = document.getElementById(iframe.id).contentDocument.body.scrollHeight;
    }
    else if (document.getElementById(iframe.id).Document) {
        heightIframe = document.getElementById(iframe.id).Document.body.scrollHeight;
    }
    iframe.height = heightIframe;
}
function displayHello(userName, nbPoints, nbCredits) {
    if (loadMiniverse == "8") {
        window.location = "/"; //if sign up page
    }
    else {
        var tabSayHello = document.getElementById("ctl00_tabHello");
        var helloUserArea = document.getElementById("ctl00_helloUser");
        //var pointsUserArea = document.getElementById("ctl00_pointsUser");
        //var creditsUserArea = document.getElementById("ctl00_creditsUser");
        tabSayHello.style.display = "block";
        helloUserArea.innerHTML = "Hello " + userName + "!";
        //pointsUserArea.innerHTML = nbPoints;
        //creditsUserArea.innerHTML = nbCredits;
        document.getElementById("ctl00_profileBtn").style.display = "inline";
        if (loadMiniverse == "1") {
            if (document.all) {
                if (document.getElementById('gamePP').contentWindow.updateLogUser != undefined) {
                    document.getElementById('gamePP').contentWindow.updateLogUser();
                }
            }
            else {
                if (document.getElementById('gamePP').contentDocument.defaultView.updateLogUser != undefined) {
                    document.getElementById('gamePP').contentDocument.defaultView.updateLogUser();
                }
            }
        }
    }
}
function displayGbuy() {
    var tabSayHello = document.getElementById("ctl00_tabHello");
    tabSayHello.style.display = "none";
    document.getElementById("ctl00_profileBtn").style.display = "none";
    if (loadMiniverse == "1") {
        if (document.all) {
            if (document.getElementById('gamePP').contentWindow.updateLogUser != undefined) {
                document.getElementById('gamePP').contentWindow.updateLogOffUser();
            }
        }
        else {
            if (document.getElementById('gamePP').contentDocument.defaultView.updateLogUser != undefined) {
                document.getElementById('gamePP').contentDocument.defaultView.updateLogOffUser();
            }
        }
    }
    //innerUnityPrompt.innerHTML = innerHtmlDoc;
}

function processBuy(nbCredits,nbPoints) {
    var pointsUserArea = document.getElementById("ctl00_pointsUser");
    var creditsUserArea = document.getElementById("ctl00_creditsUser");
    if(pointsUserArea.innerHTML-nbPoints>=0)pointsUserArea.innerHTML = pointsUserArea.innerHTML - nbPoints;
    if (creditsUserArea.innerHTML - nbCredits >= 0) creditsUserArea.innerHTML = creditsUserArea.innerHTML - nbCredits;
}
function processBuyCredits(nbCredits) {
    var creditsUserArea = document.getElementById("ctl00_creditsUser");
    creditsUserArea.innerHTML = Math.round(creditsUserArea.innerHTML) + Math.round(nbCredits);
}
function turnOffGame() {
    if (loadMiniverse == "1") document.getElementById("gamePP").src = "Game.aspx"; 
    else window.location = "/";
}
function registerGame() {
        window.location = "SignUp.aspx";
}
function reloadMiniverseMenu(subMenuArg) {
    if (loadMiniverse == "1" || loadMiniverse == "7") {
        var argToAdd = "";
        if (loadMiniverse == "7") {
            argToAdd = "?buyItem=1" + subMenuArg.replace('?','&');
        }
        else {
            if (subMenuArg != "") {
                argToAdd = subMenuArg;
            }
        }
        
        if (document.all) {
            document.getElementById('MenuMiniverse').contentWindow.location.href = rootAppMiniverse + "ItemMall.aspx" + argToAdd;
        }
        else {
            document.getElementById('MenuMiniverse').contentDocument.defaultView.location.href = rootAppMiniverse + "ItemMall.aspx" + argToAdd; ;
        }
    }
}
function reloadPageMenu(rootApp) {
    if (loadMiniverse == "0") { window.location = rootApp; }
    //send the info to log out if load miniverse ==1
}
// Unconditional reload
function reloadPage(rootApp)
{
    window.location = rootApp;
}
function itemUpdateCallGame() {
    if (loadMiniverse == "1") {
        if (document.all) {
            document.getElementById('gamePP').contentWindow.updateItemUser();
        } 
        else {
        document.getElementById('gamePP').contentDocument.defaultView.updateItemUser();
        }
    }
}
function clanUpdateCallGame(memberId) {
    if (loadMiniverse == "1") {
        if (document.all) {
            document.getElementById('gamePP').contentWindow.updateClanUser(memberId);
        }
        else {
            document.getElementById('gamePP').contentDocument.defaultView.updateClanUser(memberId);
        }
    }
}
function resizeIframePayment(height,width) {
    
    if (document.all) {
        document.getElementById('MenuMiniverse').contentWindow.document.getElementById('paymentZongIframe').setAttribute("height", height);
        document.getElementById('MenuMiniverse').contentWindow.document.getElementById('paymentZongIframe').setAttribute("width", width);
    }
    else {
        document.getElementById('MenuMiniverse').contentDocument.defaultView.document.getElementById('paymentZongIframe').setAttribute("height", height);
        document.getElementById('MenuMiniverse').contentDocument.defaultView.document.getElementById('paymentZongIframe').setAttribute("width", width);
    }
}
function setFocusLogin() {
    if (document.all) {
        document.getElementById('loginPP').contentWindow.document.getElementById('login').focus();
    }
    else {
        document.getElementById('loginPP').contentDocument.defaultView.document.getElementById('login').focus();
    }
}