//initialize the game database with name of the game
var numberUnlock = 1;

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("Tournament1", 1)
    localStorage.setItem("Tournament2", 0)
    localStorage.setItem("Tournament3", 0)
    localStorage.setItem("Tournament4", 0)
    
    
    localStorage.setItem("Car1", 1)
    localStorage.setItem("Car2", 0)
    localStorage.setItem("Car3", 0)
    
    localStorage.setItem("Car4", 0)
    localStorage.setItem("Car5", 0)
    localStorage.setItem("Car6", 0)
    
    localStorage.setItem("Car7", 0)
    localStorage.setItem("Car8", 0)
    localStorage.setItem("Car9", 0)
    
    localStorage.setItem("Car10", 0)
    localStorage.setItem("Car11", 0)
    localStorage.setItem("Car12", 0)
    
    localStorage.setItem("GameUnlock", 0)
    localStorage.setItem("CarUnlock", 0)
    
    
}



function getStorageItem(pKey) {
    if(localStorage.getItem(pKey) != undefined)
        return localStorage.getItem(pKey)
    else {
        if(pKey=="Tournament1") {
            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);
}



function getCarStorageItem(pKey) {
    if(localStorage.getItem(pKey) != undefined)
        return localStorage.getItem(pKey)
    else {
        if(pKey=="Car1") {
            localStorage.setItem("pKey",1);   
            return 1;
        } else {
            localStorage.setItem(pKey,0);   
        }
        
        return 0;
    }
}




