//////////////////////////////////////////
//                                      //
//            WIZARD MANAGER            //
//                                      //
//////////////////////////////////////////


WizardManager.numberOfPages = 3;
WizardManager.pages = null;
WizardManager.prevPageElem = null
WizardManager.pageIndex = -1; 

function WizardManager () 
{
}

WizardManager.showCurrentPage = function()
{
  if(WizardManager.pages == null)
  {
    WizardManager.pages = WizardManager.createPageArray();
    WizardManager.createFlagPage();
  }
  var value = System.getRefreshTextFieldElem().value;
  WizardManager.pageIndex = parseInt(value == "" ? 0 : value);
  WizardManager.showPage();
}

WizardManager.selectLanguage = function (language)
{
  System.getLanguageTextFieldElem().value = language;
  System.changeHomeIconTitle();
  WizardManager.nextPage();  
}

WizardManager.nextPage = function () 
{
  WizardManager.pageIndex = WizardManager.pageIndex + 1;
  WizardManager.showPage();
}

WizardManager.prevPage = function () 
{
  WizardManager.pageIndex = WizardManager.pageIndex - 1;
  WizardManager.showPage();
}

WizardManager.showPage = function()
{  
  if(WizardManager.pageIndex < WizardManager.numberOfPages && WizardManager.pageIndex >= 0)
  {
    if(WizardManager.prevPageElem != null)
    {
      WizardManager.prevPageElem.style.display = "none";
    }
    
    if(WizardManager.pageIndex == 1)
    {
      WizardManager.createWelcomePage();
    }

    var pageElem = WizardManager.pages[WizardManager.pageIndex];
    pageElem.style.display = "";
    System.getRefreshTextFieldElem().value = WizardManager.pageIndex;
    WizardManager.prevPageElem = pageElem;
    
    if(WizardManager.pageIndex == WizardManager.numberOfPages-1)
    {
      Menu.init();
    }
  }
}

WizardManager.createFlagPage = function()
{
  var str = "";
  str += "<table border=0 cellpadding=0 cellspacing=0 width=280 height=200>";
  
  str += "<tr><td width=100% class=\"wizardLogoTitlePanel\" align=center>";
  str += "MEDIASKOP 2007";
  str += "</td></tr>"; 
    
  str += "<tr><td colspan=2><img src=\"img/spacer.gif\" style=\"width:100%;height:3px;\"></td></tr>"
  
  str += "<tr height=100%><td>";  
  str += "<table border=0 cellpadding=0 cellspacing=0 class=\"wizardPage0Table\" style=\"width:100%;height:100%;\"><tr>"   
  for(var i=0; i<system.languages.length;i++)
  {
    var language = system.languages[i];
    str += "<td style=\"padding:1px;\" align=center>";
    str += "<img src=\""+language.imagePath+"\" class=\"flagImg\" title=\""+language.desc+"\" onclick=\"WizardManager.selectLanguage('"+language.name+"');\" >";
    str += "</td>";
  }  
  str += "</tr></table></td></tr>";  
 
  str += "<tr bgcolor=\"#1E1916\">";
  str += "<td width=100%><img src=\"img/logo.gif\" style=\"width:180px;height:29px;\"></td>";  
  str += "</tr>";
  
  str += "</table>";
  document.getElementById("flagPanel").innerHTML = str;
}

WizardManager.createWelcomePage = function()
{
  var language = system.getLanguage();

  var str = "";
  str += "<table border=0 cellpadding=0 cellspacing=0 width=400 height=250 align=center></tr>";
  str += "<td colspan=2 width=100% class=\"wizardTitlePanel\">";
  str += "<p class=\"wizardTitleSLO\">"+language.welcomeTitle.toUpperCase()+"</p>";
  str += "</td></tr>";
  
  
  str += "<tr><td><img src=\"img/spacer.gif\" style=\"width:100%;height:3px;\"></td></tr>";
  str += "<tr height=100%><td colspan=2 width=100% class=\"wizardContentPanel\" valign=top>";
  str += "<div style=\"padding:5px;\">";
  str += "<p style=\"padding-left:5px;padding-right:5px;\">";
  str += language.welcomeText;
  str += "</p></div></td></tr>";
  
  str += "<tr bgcolor=\"#1E1916\">";
  str += "<td width=100%><img src=\"img/logo.gif\" style=\"width:180px;height:29px;\"></td>";
  str += "<td style=\"padding-right:5px;\">";
  str += "<table border=0 cellpadding=0 cellspacing=0 width=100% height=100%><tr>";
  str += "<td><img src=\"img/prev.gif\" style=\"width:22px;height:22px;cursor:pointer;\" onclick=\"WizardManager.prevPage();\"></td>";
  str += "<td><img src=\"img/spacer.gif\" style=\"width:5px;height:100%;\"></td>";
  str += "<td><img src=\"img/next.gif\" style=\"width:22px;height:22px;cursor:pointer;\" onclick=\"WizardManager.nextPage();\"></td>";
  str += "</tr></table></td>"; 
  
  
  str += "</tr></table>";
  document.getElementById("welcomePanel").innerHTML = str;
}

WizardManager.createPageArray = function()
{
  var arr = new Array();
  for(var i=0; i<WizardManager.numberOfPages; i++)
  {
    arr[i] = document.getElementById("page" + i);
  }
  return arr;
}