//initialize the game database with name of the game


function initializeDB() {
    // Crafty.storage.open('SoccerFling');
    console.log("db is initialized or opened");
    if(typeof(Storage)!=="undefined")
      {
      // Yes! localStorage and sessionStorage support!
      // Some code.....
        // alert("can storage")
        localStorage.setItem("isLocalStorageCreated", false)

        createLocalStorage()
        // alert("local storage and sessionStorage supports"+ localStorage.getItem("isLocalStorageCreated"))
      }
    else
      {
      // Sorry! No web storage support..
      alert("no web storage support")
      }
}

function createLocalStorage() {
    //1 means unlocked, 0 means locked 
    if(localStorage.getItem("isLocalStorageCreated")) return;
    localStorage.setItem("isLocalStorageCreated", true)
    // alert("local storage initialized")
    localStorage.setItem("Arcade1", 1)
    localStorage.setItem("Arcade2", 0)
    localStorage.setItem("Arcade3", 0)
    localStorage.setItem("Arcade4", 0)
    localStorage.setItem("Arcade5", 0)
    localStorage.setItem("Arcade6", 0)
    localStorage.setItem("Arcade7", 0)
    localStorage.setItem("Arcade8", 0)
    localStorage.setItem("Arcade9", 0)
    localStorage.setItem("Arcade10", 0)

    // //here 1 means unlocked the level 0 means locked level, and 1,2,3,4,5 means 1-puzzle 1 unlocked, 2- puzzle 1&2 unlocked etc.,
    localStorage.setItem("Challenge1", 1)
    localStorage.setItem("Challenge2", 0)
    localStorage.setItem("Challenge3", 0)
    localStorage.setItem("Challenge4", 0)
    localStorage.setItem("Challenge5", 0)
    localStorage.setItem("Challenge6", 0)
    localStorage.setItem("Challenge7", 0)
    localStorage.setItem("Challenge8", 0)
    localStorage.setItem("Challenge9", 0)
    localStorage.setItem("Challenge10", 0)

    console.log("local storage created ", localStorage.getItem("arcade1"))
}

function getStorageItem(pKey) {
//    alert(localStorage.getItem(pKey))
    // alert(pKey)
    // alert("pkey is ", pKey)
    if(localStorage.getItem(pKey) != undefined)
        return localStorage.getItem(pKey)
    else {
        if(pKey=="Arcade1" || pKey == "Challenge1") {
            localStorage.setItem(pKey,1);   
            return 1;
        } else {
            localStorage.setItem(pKey,0);   
        }
        
        return 0;
    }
}

function setStorageItem(pKey, pValue) {
    if(localStorage.getItem(pKey) < pValue)
        localStorage.setItem(pKey, pValue);
}




