import DBase;	//Importing Database functionality
public var header:GUISkin;	//Used for formatting
public var content:GUISkin;	//Used for formatting
var username: String;
var error: String;

function Start () {
	if(PlayerPrefs.GetInt("PlayerScore") == 0){
		Application.LoadLevel(0);
	}
	username = "Enter your name";
	error = ""+PlayerPrefs.GetInt("PlayerScore")+" pts | ";		
}

function Update () {

}

function OnGUI(){
	GUI.skin = header;	//Setting up the GUI Skin.
	GUI.color = Color.black;	//Setting font color to black
	//Title
	GUI.Label(Rect(100,70,950,100),"History..");
	
	content.label.alignment = TextAnchor.MiddleLeft;
	GUI.skin = content;
	GUI.Label(Rect(410,130,950,100),""+error);
	//Menu Items
	username = GUI.TextField(Rect(120,160,280,40),username,75);
	
	//If the user clicks on submit a new score is added to the database
	if(GUI.Button(Rect(120,210,150,40),"Submit")){
		if(username.Length != 0){
			var db = new DBase();	//Initializing the database
			db.addScore(username, PlayerPrefs.GetInt("PlayerScore"));	//Adding the score to the databae
			Application.LoadLevel(0);	//Load the main menu
		}else{
			error = ""+PlayerPrefs.GetInt("PlayerScore")+" pts | Please enter a valid name";
		}
	}
	
	//If cancel is clicked, nothing happens
	if(GUI.Button(Rect(290,210,150,40),"Cancel")){
		Application.LoadLevel(0);	//The user is redirected to the main menu
	}
	
	content.label.alignment = TextAnchor.UpperCenter;
}