var Room = IR.GetPage("Rooms");
var Lights = IR.GetPage("Lighting");
var Holder = IR.GetPopup("RoomItemHolder").GetItem("Item 1");
var ListLight = Lights.GetItem("Rooms");
var Lightslist = Lights.GetItem("Item 8");
var popuppage = IR.GetPopup("ListRooms");
var click = popuppage.GetItem("delete");
var nameclick = popuppage.GetItem("Name");

// The allowed options for room names 
var RoomsList = [
   "LivingRoom",
   "Kitchen",
   "BathRoom",
   "BedRoom",
   "Attic",
   "ChildrenRoom",
   "PlayRoom",
   "Hallway",
   "FrontYard",
   "BackYard", 
   "livingroom",
   "kitchen",
   "bathroom",
   "bedroom",
   "attic",
   "childrensroom",
   "playroom",
   "hallway",
   "frontyard",
   "backyard",
   "Living Room",
   "living room",
   "childrens room",  
   "Cellar",
   "cellar",
   "bath room",
   "bed room",
   "Play Room",
   "play room",
   "Bath Room",
   "Bed Room",
   "Speelkamer",
   "speelkamer"
   ];

// Function is called when adding a room
function AddRoom()
{ 
   var Name = Room.GetItem("Roomname").Text;
   var testerror = "Please use the correct syntax";
   var countsname = 0;

for (var i = 0; i < RoomsList.length; i++)
{
   // IR.Log(i);
   if(Name == RoomsList[i])
   {
      //IR.Log(Name);
      countsname = 1;
      i = RoomsList.length;
      UpdateList(Name);  
      // Holder.Text = Name;
   }         
}    

if(countsname == 1)
{
   //IR.Log("correcte afhandeling");
} 
else 
{
   Room.GetItem("Roomname").Text = "";
   //addMelding("Error", testerror);
   addMelding("Melding", testerror);
}
   // IR.Log(Name + " " + Value);

  // UpdateList(Name, Value);
   
  // IR.Log(Name);
  // Room.GetItem("Roomname").Text = "";
  // Room.GetItem("Roomnumber").Text = ""; 
  
}  

function UpdateList(Name)
{
   var Listname = Room.GetItem("Rooms");
  
   Listname.CreateItem(Count, 2, {Text: Name});
   ListLight.CreateItem(Count, 2, {Text: Name});
   
   Count += 1;
   Room.GetItem("Roomname").Text = "";    
}


function ClearList()
{
   var List =  Room.GetItem("Rooms");
    
   List.Clear();
   ListLight.Clear();
   IR.HideAllPopups();
        
}


