<?php
  include ("wizard_initialize.php");
  //print "<pre style=\"text-align:right;\">";		
  //echo "wiz common_top start menu_row_cache =";		
  //print_r($menu_row_cache);		
  //print "</pre>";		
?>
<!DOCTYPE html>
<html>
<head>
<meta id="viewport" name="viewport" content="width=device-width">
<meta charset="utf-8">

<?php
$wStep = array("Select Template",                   // step one
               "Build Menu",                        // step two
               "Select Title and Images",           // step three
               "Mo Stuff L8r",                      // step four
               "DONE");                             // step five
echo "<title> Breeze Website builder Template Wizard: Step " .
     $wizard_template_page . " - " .
     $wStep[$wizard_template_page-1] .
     "</title>"
?>

<meta name="author" content="bruceknarr, davecoury" >
<meta name="Keywords" content="breeze template wizard">
<meta name="Description" content="Breeze Website builder Template Wizard">
<meta name="msapplication-TileImage" content="/TileImage.png">
<meta name="application-name" content="Template Wizard">
<meta name="msapplication-TileColor" content="#006699">
<meta http-equiv="imagetoolbar" content="no">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<link rel="icon" href="images/favicon.ico" type="image/ico">
<link rel="stylesheet" href="css/wizard.css" type="text/css">

<?php
  if (LOCAL_MODE) echo "<link rel='stylesheet' href='css/lert.css' type='text/css'>\n";
  switch ($wizard_template_page) {
    case 1:
      echo "<link rel='stylesheet' href='css/wizard_step_1_checkbox.css' type='text/css'>\n";
      echo "<link rel='stylesheet' href='css/wizard_step_1_thumbnail.css' type='text/css'>\n";
      echo "<link rel='stylesheet' href='css/wizard_step_1_lightbox.css' type='text/css'>\n";
      echo "<link rel='stylesheet' href='css/wizard_step_1_rotate.css' type='text/css'>\n";
      echo "<script src='js/jquery.min.js'></script>\n";
	  echo "<script src='js/wizard_step_1.js'></script>\n";
      break;
    case 2:
      echo "<link rel='stylesheet' href='css/wizard_step_2_editor.css' type='text/css'>\n";
      echo "<script src='js/jquery.min.js'></script>\n";
      echo "<script language='javascript' type='text/javascript' src='js/wizard_step_2.js'></script>\n";
      break;
    case 3:
      echo "<link rel='stylesheet' href='css/wizard_step_3_editor.css' type='text/css'>\n";
      echo "<script language='javascript' type='text/javascript' src='js/trim.js'></script>\n";
      echo "<script language='javascript' type='text/javascript' src='js/wizard_step_3.js'></script>\n";
      include ("setup_site_intro_head_code.html");
    case 4:
    case 5:
  }
  if (LOCAL_MODE) echo "<script language='javascript' type='text/javascript' src='js/lert.js'></script>\n";
  echo "<script language='javascript' type='text/javascript'>\n";
  echo "var pg_num=".$wizard_template_page.";\n";
  echo "var local_pages=".WIZARD_STEPS.";</script>\n";
?>
<script language='javascript' type='text/javascript' src='js/wizard_post.js'></script>

<style>
  @font-face {
    font-family: Andy;
    src: url(ttf/andyb.ttf)  format("truetype");
  }

  @media only screen and (max-width:480px) {
    .thumbholder {display:none;}
    #info h3.smartphone {display:block;}
  }

  #wizard_steps_enu .template_step label:hover,
  #wizard_steps_enu .template_step label.active_<?php echo $wizard_template_page ?> {
                font-size: 180%;
                   cursor: pointer
  }

  #wizard_steps_enu .template_step label.active_<?php echo $wizard_template_page ?> {
                    color: #f00;
  }
</style>

<script type="text/javascript" language="JavaScript">
  function ignoreEnterKey(ev,th) {
      var key;
      if(window.event) {
          key = window.event.keyCode; // IE
      } else {
          key = ev.which; // FF+
      }
      if (key == 13) th.blur();
      return (key != 13);
  }

  function is_done() {
    if (typeof frmWebsiteType.elements["template"] != "undefined") {
      if ((frmWebsiteType.elements["template"].value!="") && (frmWebsiteType.elements["visited_steps"].value==="7")) {
        document.getElementById('done').className ='enabled';
        document.getElementById('done_wrapper').setAttribute('title','');
      }
    }
    else {
      document.getElementById('done').className ='disabled';
      document.getElementById('done_wrapper').setAttribute('title','DISABLED');
    }
  }
  function is_template() { //if template was selected, enable all of the steps to click on for browsing. If page one, enable the 'next' button.
    if (pg_num==1){ //Disable the first page next button by default
      document.getElementById('next_btn').setAttribute('for','')
      document.getElementById('next_btn').className = 'float_r disabled';
    }
    if (typeof frmWebsiteType.elements["template"] != "undefined") {
      if (frmWebsiteType.elements["template"].value!=""){  //If a template has been selected, enable all of the steps PLUS the 'next' button:
        var setId;
        for (var i=1; i<=local_pages; i++) {
          setId='template_step'+i.toString();
          document.getElementById(setId).className = 'template_step';
          setId='pg_num'+i.toString();
          document.getElementById(setId).setAttribute('for','goto_page_'+i.toString())
        }
        //Enable the 'next button for page one
        if (pg_num==1){
          document.getElementById('next_btn').setAttribute('for','goto_page_2')
          document.getElementById('next_btn').className = 'float_r';
        }
      }
    }
  }

  <?php
    switch ($wizard_template_page) {
      case 2:
        echo "\nvar EDITING_FAILED = -1;\n";
        echo "var cached_new_row=null;\n\n";
      case 3:
        echo "\nvar EDITING_TRUE = 1;\n";
        echo "var EDITING_FALSE = 0;\n";
        echo "var edit_mode=EDITING_FALSE;\n";
        echo "var edit_mode_node=null;\n";
        echo "var invalid = false;\n";
        echo "var unassigned_image = false;\n";
        echo "var image_collection = [];\n";
        break;
    }
    echo "var LOCAL_MODE = " . (LOCAL_MODE?"true":"false") . ";\n";
  ?>
</script>
</head>

<?php
  
  echo "<body id='bodyID' class='bodyCLASS'";
  switch ($wizard_template_page) {
    case 1:
      if($wtf_set) echo " onLoad='updateButtonIDs();is_done();is_template();'";
      break;
    case 2:
      echo " onLoad='initialize_editor(); update_selects(); cache_new_row();is_done();is_template(); get_oc_session_vars();'";
      break;
    case 3:
      echo " onLoad='Init(); enum_images();update_selects();is_done();is_template();assign_unassigned_images()'";
      break;
  }
  echo ">\n";
  echo "<form name='frmWebsiteType' method='post' enctype='multipart/form-data' id='frmTemplateSelections' action='setup_site.php'";
//  echo ($wizard_template_page==="3")?" onsubmit='return assign_unassigned_images();'>\n":">\n";//run this in case user selects the title (no selection) to define as 'upload_only'
  echo ($wizard_template_page==="3")?">\n":">\n";
  for ($i=1; $i<=WIZARD_STEPS; $i++) {
    echo "  <input type='submit' name='submit".$i."' id='goto_page_".$i."' class='hidden' value='submit' formaction='wizard_step_".$i.".php'>\n";
  }
  if ($wizard_template_page==="3") {
    echo "  <input type='submit' name='submitall' id='upload' class='hidden' value='submit' formaction='upload.php'>\n";
    echo "  <input type='submit' name='submitall' id='delete' class='hidden' value='submit' formaction='delete.php'>\n";
  }
  echo "  <input type='submit' name='submitall' id='local_content_check' class='hidden' value='submit' formaction='local_content_check.php'>\n";
  echo "  <input type='submit' name='submitall' id='wizard_menu' class='hidden' value='submit' formaction='wizard_menu.php'>\n";
  echo "  <input type='submit' name='submitall' id='wizard_submit' class='hidden' value='submit' formaction='setup_site.php'>\n";
  echo "  <input type='submit' name='submitall' id='wizard_delete_all' class='hidden' value='submit' formaction='delete_all_pages.php'>\n"
?>

  <header>
    <div id="logo">
      <img alt="Breeze Website Builder Logo"
           src="images/wizard_header_logo.png"
           style="text-align: center;" />
    </div> <!-- END logo -->

    <div id="head_title">
      TEMPLATE WIZARD
    </div> <!-- END head_title -->

    <div id="wizard_steps">
      <div id="wizard_steps_label">
       <span>Wizard Steps</span>
      </div>
<?php
  $string1 = "      <ul id='wizard_steps_enu'>\n";
  $template_step='template_step';
  for ($i=1; $i<=WIZARD_STEPS; $i++) {
    $string1 .= "    	<li id='template_step".$i."' class='$template_step'>\n";
    //For first page, make all other steps inactive (If the template has been selected, they will be reactivated on load):
    if ($wizard_template_page==1){
      $template_step='template_step_inactive';
    }
    $string1 .= "<label id='pg_num".$i."'  class='active_".$i;
    if ($wizard_template_page > $i) $string1 .=  " completed";
    $string1 .= "'>".$i."</label></li>\n";
  }
  $string1 .= "      </ul> <!-- END wizard_steps_enu -->\n";
  print $string1;
?>

    </div> <!-- END wizard_steps -->

<?php

  include ("get_image_label_list.php");

  echo str_pad("", 4) . "<div id='cached_data'>\n";
  echo str_pad("", 6) . "<div id='done_wrapper' title='DISABLED'>\n";
  echo str_pad("", 8) . "<div id='done' class='disabled' onclick='checkForContent();'>I'm Done</div>\n";
  echo str_pad("", 6) . "</div> <!-- END done_wrapper -->\n";
  if (!empty($site_title)) echo str_pad("", 6) . "<div class='page_3_text'><b>TITLE:</b> ".$site_title."</div>\n";
  if (!empty($tagline)) echo str_pad("", 6) . "<div class='page_3_text'><b>TAG:</b> ".$tagline."</div>\n";
  if (!empty($site_title) || !empty($tagline)) echo str_pad("", 6) . "<br>\n";
  if (!empty($cached_user_images) && is_array($cached_user_images)) {

    // include image db query for chached images here and in wizard_step_3
    $image_tags = get_image_tag_list ();
    echo str_pad("", 6) . "<div id='user_images'>\n";
    foreach ($cached_user_images as $key => $val) {
      $file_url = USERS_IMAGE_FOLDER . $val['file_name'];
      echo str_pad("", 8) . "<figure><img src='$file_url' />\n";
      echo str_pad("", 10) . "<figcaption>" . $image_tags[$val['image_tag']] . "</figcaption></figure>\n";
    }
    echo str_pad("", 6) . "</div> <!-- END user_images -->\n";
  }

  if (!empty($menu_row_cache) && is_array($menu_row_cache)) {
    echo str_pad("", 6) . "<div id='menu_selected'>\n";
    echo str_pad("", 8) . "<span><b>MENU</b></span>\n";
    foreach ($menu_row_cache as $key => $val) {
    echo str_pad("", 10) . "<div class='menu_item'>" . $val['link_text'] . "</div>\n";
 //   echo'key='.$key.'  val='.$val.'\n';
    }
    echo str_pad("", 6) . "</div> <!-- END menu_selected -->\n";
  }
  if (!empty($wizard_template_ID_previous)) {
    echo str_pad("", 4) . "<div class='template_selected'\n";
    echo str_pad("", 12) . "id='template_selected" . $wizard_template_ID_previous . "'>\n";
    echo str_pad("", 6) . "<span>\n";
    echo str_pad("", 8) . "<img src='".TEMPLATE_IMAGE_FOLDER."tn/" . $wizard_template_tn . "'\n";
    echo str_pad("", 13) . "alt='Template Thumbnail " . $wizard_template_ID_previous . "' />\n";
    echo str_pad("", 6) . "</span>\n";
    echo str_pad("", 4) . "</div> <!-- END template_selected" . $wizard_template_ID_previous . "-->\n";
  }
  echo str_pad("", 4) . "</div> <!-- END cached_data -->\n";
?>
    <div id="wizard_help">
      <a href="#HELP" onClick="window.open('http://breezewebsitebuilder.com/docs/wizard/help_wiz.html#wizard_step<?php echo $wizard_template_page; ?>', 'Help', 'scrollbars=1,resizable=1,status=0,toolbar=0,menubar=0,location=0,height=700,width=800'); return false;"></a>
    </div>
    