<?xml version="1.0" encoding="UTF-8" ?>
<klip>
   <identity>
      <title>
         API - Actions.Window
      </title>
   </identity>

   <locations>
      <icon>
         http://www.klipfolio.com/static/klips/klipfolio/sample_icon.png
      </icon>
      <banner>
         http://www.klipfolio.com/static/klips/klipfolio/sample_banner.png   
      </banner>
   </locations>

   <klipscript>
      <![CDATA[

function onLoad()
 {
	// Add a Button
         Actions.Button.show("Log in");
         Actions.Button.onClick = showLogin;

 	// Add a Stack named "Login"
 	var stack = Actions.Window.addStack("Login");
 	// Set the title for the window's title bar
 	stack.title = "Log in to the server";
 	
 	// Add a Page named "Server" to "Login" Stack
 	var page = stack.addPage("Server");
 	// Add text to the Page
 	page.addText("Enter the server address (use 'klipfolio' for this example)");
 	// Add a textfield called 'gServerField'
 	gServerField = page.addTextField();
 	// No back button
 	page.back = ""; 
 	// Assign a handler function to Next button
 	page.onNext = checkServer;
 	
 	// Add another Page named "UserName" to "Login" Stack
 	page = stack.addPage("Username");
 	page.addText("Enter your user name and password");
 	gUserField = page.addTextField();
 	gPassField = page.addTextField();
 	// Display "Server" in Back button
 	page.back = "Server";
 	// Display "Log In" in Next button
 	page.next = "Log In";
 	page.onNext = verifyUser;
 	
 }

function showLogin() 
  {
	// Open window with 'Login' stack on Server page
	Actions.Window.show("Login", "Server");
  }
 function onRefresh()
 {
 	// ...
 	// Show the login stack on the server page
 	Actions.Window.show("Login", "Server"); 
 	// ...
 	return true;
 }
 
 function checkServer(page)
 {
 	var server = gServerField.value;
 	// Check to see if 'klipfolio' was entered as server name
 	if(server == "klipfolio")
 	{
 		return true; // Proceed to the login page
 	}
 	else
 	{
 		page.setError("Invalid server URL, please try again");
 		return false; // Don't proceed to the next page
 	}
 }
 
 function verifyUser(page)
 {
 	page.setError("Invalid user name or password, please try again");
 }
      ]]> 
   </klipscript>
</klip>
