<?php
// Google Org Chart supervisor - RJM Programming - Copyright 2013
// Would prefer to use tree structure, next time
if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== false) {
    if (strpos($_SERVER['QUERY_STRING'], 'nojwin') === false) {
     if ($_SERVER['QUERY_STRING'] == "") {
      header("Location: ./Google_OrgChart.php?rand=" . rand() . "&nojwin=" . rand());
      //exit;
     } else {
      header("Location: ./Google_OrgChart.php?rand=" . rand() . "&nojwin=" . rand() . "&" . $_SERVER['QUERY_STRING']);
      //exit;
     }
    }
}
$istrue="true";
$pref = "";
$suff = "";
$done = "";
$psuff="";
if (isset($_GET['nojwin']) || isset($_GET['nojwinyes']) || isset($_POST['nojwin']) || isset($_POST['nojwinyes'])) {
$psuff="nojwin";
}
if (isset($_POST['nojwinyes'])) {
$istrue="false";
$njthreesuff="<input type=hidden value=" . rand() . " name=nojwinyes></input>";
$njtwosuff="nojwin=" . rand();
$njsuff="&nojwin=" . rand();
$psuff="nojwin";
} else if (isset($_GET['nojwinyes'])) {
$istrue="false";
$njthreesuff="<input type=hidden value=" . rand() . " name=nojwinyes></input>";
$njtwosuff="nojwin=" . rand();
$njsuff="&nojwin=" . rand();
$psuff="nojwin";
} else {
$njsuff="";
if (strpos($_SERVER['QUERY_STRING'], "nojwin") !== false) $njsuff="&nojwin=" . rand();
$njtwosuff="";
if (strpos($_SERVER['QUERY_STRING'], "nojwin") !== false) $njtwosuff="nojwin=" . rand();
$njthreesuff="";
}
if (strpos($istrue,"true") !== false && strpos($_SERVER['QUERY_STRING'], "nojwin") !== false) {
$njthreesuff="<input type=hidden value=" . rand() . " name=nojwinyes></input>";
} else {
$fpos = strstr($_SERVER['QUERY_STRING'], "next=");
if (isset($_POST['next'])) {
$istrue="false";
  $fh = fopen(str_replace(".php", $psuff . ".htm", __FILE__), "w");
  fwrite($fh, str_replace("&gt;",">",str_replace("&lt;","<",urldecode($_POST['next']))) . "\n");
  fclose($fh);
  $done = "y";
  header("Location: ./Google_OrgChart" . $psuff . ".htm?rand=" . rand() . $njsuff);
  //exit;
  $pref = "!--";
  $suff = "--";
} else if ($fpos !== false) {
$istrue="false";
  $fh = fopen(str_replace(".php", $psuff . ".htm", __FILE__), "w");
  fwrite($fh, str_replace("&gt;",">",str_replace("&lt;","<",urldecode(str_replace("next=","",$fpos)))) . "\n");
  fclose($fh);
  header("Location: ./Google_OrgChart" . $psuff . ".htm?rand=" . rand() . $njsuff);
  //exit;
  $pref = "!--";
  $suff = "--";
} else if (isset($_POST['next'])) {
$istrue="false";
  $fh = fopen(str_replace(".php", $psuff . ".htm", __FILE__), "w");
  fwrite($fh, str_replace("&gt;",">",str_replace("&lt;","<",urldecode($_POST['next']))) . "\n");
  fclose($fh);
  header("Location: ./Google_OrgChart" . $psuff . ".htm?rand=" . rand() . $njsuff);
  //exit;
  $pref = "!--";
  $suff = "--";
} else if (isset($_GET['next'])) {
$istrue="false";
  $fh = fopen(str_replace(".php", $psuff . ".htm", __FILE__), "w");
  fwrite($fh, str_replace("&gt;",">",str_replace("&lt;","<",urldecode($_GET['next']))) . "\n");
  fclose($fh);
  header("Location: ./Google_OrgChart" . $psuff . ".htm?rand=" . rand() . $njsuff);
  //exit;
  $pref = "!--";
  $suff = "--";
}
}
echo "<" . $pref . "html>";
?>
  <head><meta charset="utf-8"/> 
    <title>Google Org Chart Interface - RJM Programming - September, 2017</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=0.5, maximum-scale=4, user-scalable=yes" />
    <script type='text/javascript' src='//www.rjmprogramming.com.au/gchartgen.js?x=<?php echo rand(); ?>'></script>
    <script type='text/javascript' src='//www.google.com/jsapi'></script>
    <script type='text/javascript'>
      var dw="";
      var couldbe=false, prename='', lastname='',lastmanager='',lasttooltip='',lastlevel=-1,istack=0, stack=location.search.split('stack=')[1] ? eval('[' + decodeURIComponent(location.search.split('stack=')[1].split('&')[0]).replace(/\+/g,' ') + ']') : [];
      var ourprefix=location.search.split('prefix=')[1] ? decodeURIComponent(location.search.split('prefix=')[1].split('&')[0]).replace(/\+/g,' ') : '';
      var ourperson=location.search.split('person=')[1] ? decodeURIComponent(location.search.split('person=')[1].split('&')[0]).replace(/\+/g,' ') : 'Person';
      var ourmanagement=location.search.split('management=')[1] ? decodeURIComponent(location.search.split('management=')[1].split('&')[0]).replace(/\+/g,' ') : 'Management';
      var ourpeople=location.search.split('people=')[1] ? decodeURIComponent(location.search.split('people=')[1].split('&')[0]).replace(/\+/g,' ') : 'people';
      var ourjt='', ourjobtitle=location.search.split('jobtitle=')[1] ? decodeURIComponent(location.search.split('jobtitle=')[1].split('&')[0]).replace(/\+/g,' ') : 'Job Title';
      var ourjobtitles=location.search.split('jobtitles=')[1] ? decodeURIComponent(location.search.split('jobtitles=')[1].split('&')[0]).replace(/\+/g,' ') : '';
      var ourprejobtitles=location.search.split('jobpretitles=')[1] ? decodeURIComponent(location.search.split('jobpretitles=')[1].split('&')[0]).replace(/\+/g,' ') : '';
      var ournickname=location.search.split('nickname=')[1] ? decodeURIComponent(location.search.split('nickname=')[1].split('&')[0]).replace(/\+/g,' ') : 'Nickname';
      var rest=" \n /" + "/ , lvl2 ";
        var ilvl=1, donex=""; //, iname;
        var lvl1p="";
        var lvl=1;
        var howmanytop="-1", howmany="-1", name, manager, tooltip; //, ht;
        var pmanager="", answeringto="";
        var lvltext="", prevlvltext="", comma="", tcomma="", psofar=";";
        
    
   var curprompt=location.search.split('prompt=')[1] ? decodeURIComponent(decodeURIComponent(location.search.split('prompt=')[1].split('&')[0])) : "Level " + lvl + " Management Level: How many people?";
   var oktoproceed=-1, forceit=false, vsinfo=" x ";
   var xpnum=1, vsxpnum=-1; // done here at supervisor
   var allowed=<?php echo $istrue; ?>; // done here at supervisor
   var nojwinextra=""; // done here at supervisor
<?php
   echo "\n var jpsuff='" . $psuff . "'; \n";
  if (!isset($_POST['data'])) {
  echo "
   if (document.URL.indexOf('nojwin') == -1 && navigator.userAgent.match(/iPhone|iPad/i)) {
     if (document.URL.indexOf('?') == -1) {
       location.href=document.URL.split('#')[0] + '?nojwin=Q';
     } else {
       location.href=document.URL.split('#')[0] + '&nojwin=Q';
     }
   }
   ";
  }
?>
   if (document.URL.indexOf('nojwin') != -1 || navigator.userAgent.match(/iPhone|iPad/i)) {
     nojwinextra="&nojwinyes=Y";
   }

      google.load('visualization', '1', {packages:['orgchart']});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Name');
        data.addColumn('string', 'Manager');
        data.addColumn('string', 'ToolTip');
        data.addRows([
          [{v:'Mike', f:'Mike<div style="color:red; font-style:italic">President</div>'}, '', 'The President'],
          [{v:'Jim', f:'Jim<div style="color:red; font-style:italic">Vice President</div>'}, 'Mike', 'VP'],
          ['Alice', 'Mike', ''],
          ['Bob', 'Jim', 'Bob Sponge'],
          ['Carol', 'Bob', '']
        ]);
        var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
        chart.draw(data, {allowHtml:true});
      }
      
      function documentwrite(huh) {
        if (allowed) {
        if (huh.replace("<html","") != huh) {
          //alert("dw=" + dw);
          dw = "";
        } else {
        var tt=huh.lastIndexOf("][");
        if (tt >= 0) {
        //alert(huh);
        dw = dw + huh.substring(eval(tt+1));
        } else {
        dw = dw+huh;
        }
        }
        lvltext = "";
        }
      }
      
      function documentwriteagain(huh) {
        if (allowed) {
        if (huh.replace("<html","") != huh) {
          //alert("dw=" + dw);
          dw = "";
        } else {
        var tt=huh.lastIndexOf("][");
        if (tt >= 0) {
        //alert("huh1=" + huh);
        dw = dw + huh.substring(eval(tt+1));
        } else {
        //alert("huh2=" + huh);
        dw = dw+huh;
        }
        }
        lvltext = "";
        }
      }
       
      function docwrite(huh) {
        var ojiis=document.getElementById('ourform');
        //if (curprompt.indexOf(': Nickname (optional') != -1) allowed=true;
        //if (forceit) allowed=true;
        //if (howmanytop == "0" && couldbe && curprompt.indexOf("Level ") == 0 && curprompt.indexOf(" Management Level: How many people?") != -1) {
        //  allowed=true;
        //}
        //if (allowed && document.getElementById('safarinext')) {
          //if (curprompt.indexOf("Level ") == 0 && curprompt.indexOf(" Management Level: How many people?") != -1) {
          //  allowed=true;
          //} else {
          //  allowed=false;
          //}
        //}        
        if (allowed && document.getElementById('safarinext') && !ojiis) {
        if (ojiis) {
        allowed=false;
        var iivs=document.getElementById('next');
        iivs.value = encodeURIComponent(huh.replace(/</g,'&lt;').replace(/>/g,'&gt;'));    // new encasing here
          ojiis.submit();
          } else {
          document.getElementById('safarinext').value=encodeURIComponent(huh.replace(/</g,'&lt;').replace(/>/g,'&gt;'));
          }
          //document.getElementById('safariform').submit();
        } else if (allowed) {
        var hh=huh.replace("<html>","");
        if (hh == huh) huh = "<html>" + huh;
        var iis=document.getElementById('next');
        iis.value = encodeURIComponent(huh.replace(/</g,'&lt;').replace(/>/g,'&gt;'));    // new encasing here
        //alert("here2 " + huh);
        var jiisa=document.getElementById('oura');
        jiisa.href = jiisa.href + encodeURIComponent(huh.replace(/</g,'&lt;').replace(/>/g,'&gt;'));   // new encasing here
        if (allowed) window.location = jiisa.href.replace('?','?' + (nojwinextra + '&').replace('&',''));
        var jiis=document.getElementById('ourform');
        //if (document.getElementById('safariform')) {
        //   jiis=document.getElementById('safariform');
        //   jiis.submit();
        //}
        if (allowed) jiis.submit();
        }
      }
     
      function doit() {
        var jiis=document.getElementById('submit');
        jiis.click();
      }
      
      
      function doanother(thislevel, thisone, pm, am, fromw) {
        //if (fromw != "" || pmanager != pm) alert(thislevel + " " + thisone + " " + pm + " " + am + " " + fromw);
        lvl=thislevel;
        ilvl=thisone;
        var offset = 0; //eval(thisone - 1);
        var prevname="";
        var sum=2;
        var newstuff="";
        var jname, jt, iname, ht;
        var faiap_iname=1, faiap_ht=1;
        var cbtlvl=1;
        var cbtname="";
        var cbtanswer = "", canloopok=true, mayloopok=true;

		if (am != '') answeringto = am;
		if (pm != '') pmanager = pm;

        if (thislevel > 2) {
          if (rest.replace(" lvl " + thislevel + " ","") == rest) {
            rest = rest + " \n /" + "/ , lvl" + thislevel + " ";
          }
        }
        while (mayloopok && howmanytop != "0" && sum == 2 && vsxpnum != 0) {
          //canloopok=true;
          sum = (thislevel + thisone);
          if (howmanytop <= 0) {
           if (document.URL.indexOf('nojwin') != -1) {
            if ((curprompt.indexOf("Level " + lvl) != -1 && curprompt.indexOf(" Management Level: How many people?") != -1) || "Level " + lvl + " Management Level: How many people?" == curprompt) {
              oktoproceed=0;
            } else if (oktoproceed >= 0) {
              oktoproceed++;
              document.getElementById('hprompt').value=encodeURIComponent("Level " + lvl + " Management Level: How many people?");
              break;
            }
            //document.title='here at ' + "Level " + lvl + " Management Level: How many people?";
            mayloopok=false;
            document.getElementById('hprompt').value=encodeURIComponent("Level " + lvl + " Management Level" + am + " - Person " + eval(faiap_iname - offset) + " of " + eval(faiap_ht - offset) + ": Name (mandatory)?");
            howmanytop=ourprompt("Level " + lvl + " Management Level: How many people?", "0");
            //if (curprompt == "" && lvl == 1) oktoproceed=0;
           } else {
            howmanytop=ourprompt("Level " + lvl + " Management Level: How many people?", "0");
           }
          }
          if (howmanytop == null) howmanytop="0";
          if (howmanytop == "0") {
          if (parent.document.getElementById('ocmore')) {
            parent.document.getElementById('ocmore').innerHTML+=' ' + lastname + ' ' + lasttooltip;
            lastname='';
            lasttooltip='';
          }
          }
          if (howmanytop != "0") {
            ht=howmanytop;
            for (iname=thisone; iname<=ht; iname++) {
            faiap_iname=iname;
            faiap_ht=ht;
            if (donex.replace(";" + lvl + "," + iname + ";") == donex) {
            donex = donex +  ";" + lvl + "!" + iname + ";";
        if (lvl == 1) {
          pmanager = '';
          answeringto = '';
        }
            jname = iname;
            jt = ht;
              howmany="-1";
              name="";
              while (name == "" && canloopok) {
                if (thisone == 1 || 1 == 1) {
                 if (iname == offset) {
                   offset = 0;
                 }
                 //name=prompt("Level " + lvl + " Management Level" + answeringto + " - Person " + eval(iname - offset) + " of " + eval(ht - offset) + ": Name (mandatory)?", "");
           if (document.URL.indexOf('nojwin') != -1) {
            //canloopok=false;
            if ((curprompt.indexOf(" Management Level" + am + " - Person " + eval(faiap_iname - offset) + " of " + eval(faiap_ht - offset) + ": Name (mandatory)?") != -1 && curprompt.indexOf("Level " + lvl + " Management Level") != -1) || "Level " + lvl + " Management Level" + am + " - Person " + eval(faiap_iname - offset) + " of " + eval(faiap_ht - offset) + ": Name (mandatory)?" == curprompt) {
              oktoproceed=0;
            } else if (oktoproceed >= 0) {
              oktoproceed++;
              document.getElementById('hprompt').value=encodeURIComponent("Level " + lvl + " Management Level" + am + " - Person " + eval(faiap_iname - offset) + " of " + eval(faiap_ht - offset) + ": Name (mandatory)?");
              if (vsxpnum == 0) break;
            } else if (curprompt == "") {
              oktoproceed=1;
              document.getElementById('hprompt').value=encodeURIComponent("Level " + lvl + " Management Level" + am + " - Person " + eval(faiap_iname - offset) + " of " + eval(faiap_ht - offset) + ": Name (mandatory)?");
              if (vsxpnum == 0) break;
           }
            mayloopok=false;
                 name=ourprompt("Level " + lvl + " Management Level" + am + " - Person " + eval(faiap_iname - offset) + " of " + eval(faiap_ht - offset) + ": Name (mandatory)?", "");
                 lastname=name;
           } else {
                 name=ourprompt("Level " + lvl + " Management Level" + am + " - Person " + eval(faiap_iname - offset) + " of " + eval(faiap_ht - offset) + ": Name (mandatory)?", "");
                 lastname=name;
           }
                } else {
                 //name=prompt("Level " + lvl + " Management Level" + answeringto + " - Person: Name (mandatory)?", "");
           if (document.URL.indexOf('nojwin') != -1) {
            if ((curprompt.indexOf(" Management Level" + am + " - Person: Name (mandatory)?") != -1 && curprompt.indexOf("Level " + lvl + " Management Level") != -1) || "Level " + lvl + " Management Level" + am + " - Person: Name (mandatory)?" == curprompt) {
              oktoproceed=0;
            } else if (oktoproceed >= 0) {
              oktoproceed++;
              document.getElementById('hprompt').value=encodeURIComponent("Level " + lvl + " Management Level" + am + " - Person: Name (mandatory)?");
              if (vsxpnum == 0) break;
            }
            mayloopok=false;
                 name=ourprompt("Level " + lvl + " Management Level" + am + " - Person: Name (mandatory)?", "");
                 lastname=name;
           } else {
                 name=ourprompt("Level " + lvl + " Management Level" + am + " - Person: Name (mandatory)?", "");
                 lastname=name;
           }
                }
                if (name == null) name="";
                if (prename != "") name=prename;  // new idea
                if (lvl == 1) lvl1p = name;
              }
		if (am != '') answeringto = am;
		if (pm != '') pmanager = pm;
              //if (name == "Alice") alert(name + " " + pmanager + " " + pm);
              var yes=tcomma + comma + "[";
              var lv=lvltext+yes;
              var dv=dw+yes;
              //lvltext=lvltext + tcomma + comma + "[";
              tcomma="";
              //alert(2);
              comma = ",";
           if (document.URL.indexOf('nojwin') != -1) {
            if ((curprompt.indexOf("Level " + lvl + " Management Level - ") != -1 && curprompt.indexOf(": Job Title (optional)?") != -1) || "Level " + lvl + " Management Level - " + name + ": Job Title (optional)?" == curprompt) {
              oktoproceed=0;
            } else if (oktoproceed >= 0) {
              oktoproceed++;
              document.getElementById('hprompt').value=encodeURIComponent("Level " + lvl + " Management Level - " + name + ": Job Title (optional)?");
              if (vsxpnum == 0) break;
            }
            mayloopok=false;
              manager=ourprompt("Level " + lvl + " Management Level - " + name + ": Job Title (optional)?", "");
           } else {
              manager=ourprompt("Level " + lvl + " Management Level - " + name + ": Job Title (optional)?", "");
           }
              if (manager == null) manager="";
              lastmanager=manager;
             
              if (thislevel > 1) { // || document.getElementById('safariform')) { // || 1 == 1) {
                if (manager == "") {
                newstuff = ",['" + name + "','" + pmanager + "', '"; 
           if (document.URL.indexOf('nojwin') != -1) {
            if ((curprompt.indexOf("Level " + lvl + " Management Level - ") != -1 && curprompt.indexOf(": Nickname (optional)?") != -1) || "Level " + lvl + " Management Level - " + name + ": Nickname (optional)?" == curprompt) {
              oktoproceed=0;
            } else if (oktoproceed >= 0) {
              oktoproceed++;
              document.getElementById('hprompt').value=encodeURIComponent("Level " + lvl + " Management Level - " + name + ": Nickname (optional)?");
              if (vsxpnum == 0) break;
            }
            mayloopok=false;
              tooltip=ourprompt("Level " + lvl + " Management Level - " + name + ": Nickname (optional)?", "");
           } else {
              tooltip=ourprompt("Level " + lvl + " Management Level - " + name + ": Nickname (optional)?", "");
           }
              if (tooltip == null) tooltip="";
              lasttooltip=tooltip;
              newstuff=newstuff + tooltip + "']";
                  rest = rest.replace(" \n /" + "/ , lvl" + thislevel + " ", newstuff + " \n /" + "/ , lvl" + thislevel + " ");
                } else {
                 newstuff = ",[" + "{v:'" + name + "', f:'" + name + '<' + 'div style="color:red; font-style:italic">' + manager + "<" + "/div>'}, '" + pmanager + "', '";
           if (document.URL.indexOf('nojwin') != -1) {
            if ((curprompt.indexOf("Level " + lvl + " Management Level - ") != -1 && curprompt.indexOf(": Nickname (optional)?") != -1) || "Level " + lvl + " Management Level - " + name + ": Nickname (optional)?" == curprompt) {
              oktoproceed=0;
            } else if (oktoproceed >= 0) {
              oktoproceed++;
              document.getElementById('hprompt').value=encodeURIComponent("Level " + lvl + " Management Level - " + name + ": Nickname (optional)?");
              if (vsxpnum == 0) break;
            }
            mayloopok=false;
              tooltip=ourprompt("Level " + lvl + " Management Level - " + name + ": Nickname (optional)?", "");
           } else {
              tooltip=ourprompt("Level " + lvl + " Management Level - " + name + ": Nickname (optional)?", "");
           }
              if (tooltip == null) tooltip="";
              lasttooltip=tooltip;
              newstuff=newstuff + tooltip + "']";
                  rest = rest.replace(" \n /" + "/ , lvl" + thislevel + " ", newstuff + " \n /" + "/ , lvl" + thislevel + " ");
               }
              } else {
              
              if (manager == "") {
                newstuff = "'" + name + "','" + pmanager + "', '"; 
                if (lvltext.replace(newstuff,"") == lvltext && dw.replace(newstuff,"") == dw && lv.replace("][","") == lv && dv.replace("][","") == dv) {
                  lvltext=lvltext + yes+newstuff;
           if (document.URL.indexOf('nojwin') != -1) {
            mayloopok=true;
            if ((curprompt.indexOf("Level " + lvl + " Management Level - ") != -1 && curprompt.indexOf(": Nickname (optional)?") != -1) || "Level " + lvl + " Management Level - " + name + ": Nickname (optional)?" == curprompt) {
              oktoproceed=0;
            } else if (oktoproceed >= 0) {
              oktoproceed++;
              document.getElementById('hprompt').value=encodeURIComponent("Level " + lvl + " Management Level - " + name + ": Nickname (optional)?");
              if (vsxpnum == 0) break;
            }
            mayloopok=false;
              tooltip=ourprompt("Level " + lvl + " Management Level - " + name + ": Nickname (optional)?", "");
           } else {
              tooltip=ourprompt("Level " + lvl + " Management Level - " + name + ": Nickname (optional)?", "");
           }
              if (tooltip == null) tooltip="";
              lasttooltip=tooltip;
              lvltext=lvltext + tooltip + "']";
                }
                if (dw == "") dw = lvltext; //alert("lvltext=" + lvltext);
              } else {
                newstuff = "{v:'" + name + "', f:'" + name + '<' + 'div style="color:red; font-style:italic">' + manager + "<" + "/div>'}, '" + pmanager + "', '";
                if (lvltext.replace(newstuff,"") == lvltext && dw.replace(newstuff,"") == dw && lv.replace("][","") == lv && dv.replace("][","") == dv) {
                  lvltext=lvltext + yes+newstuff;  
           if (document.URL.indexOf('nojwin') != -1) {
            if ((curprompt.indexOf("Level " + lvl + " Management Level - ") != -1 && curprompt.indexOf(": Nickname (optional)?") != -1) || "Level " + lvl + " Management Level - " + name + ": Nickname (optional)?" == curprompt) {
              oktoproceed=0;
            } else if (oktoproceed >= 0) {
              oktoproceed++;
              document.getElementById('hprompt').value=encodeURIComponent("Level " + lvl + " Management Level - " + name + ": Nickname (optional)?");
              if (vsxpnum == 0) break;
            }
            mayloopok=false;
              tooltip=ourprompt("Level " + lvl + " Management Level - " + name + ": Nickname (optional)?", "");
           } else {
              tooltip=ourprompt("Level " + lvl + " Management Level - " + name + ": Nickname (optional)?", "");
           }
              if (tooltip == null) tooltip="";
              lasttooltip=tooltip;
              lvltext=lvltext + tooltip + "']";
                } 
                if (dw == "") dw = lvltext; //alert("lvltext=" + lvltext);
              }
              }
              var xx="";
              while (howmany != "0") {
           if (document.URL.indexOf('nojwin') != -1) {
            if ((curprompt.indexOf("Level ") != -1 && curprompt.indexOf(": How many people answer directly to him/her?") != -1) || "Level " + lvl + " Management Level - " + name + ": How many people answer directly to him/her?" == curprompt) {
              oktoproceed=0;
            } else if (oktoproceed >= 0) {
              oktoproceed++;
              document.getElementById('hprompt').value=encodeURIComponent("Level " + lvl + " Management Level - " + name + ": How many people answer directly to him/her?");
              if (vsxpnum == 0) break;
            }
            mayloopok=false;
               howmany=ourprompt("Level " + lvl + " Management Level - " + name + ": How many people answer directly to him/her?", "0");
           } else {
               howmany=ourprompt("Level " + lvl + " Management Level - " + name + ": How many people answer directly to him/her?", "0");
           }
               if (howmany == null) howmany="0";   
          if (howmany == "0") {
          if (parent.document.getElementById('ocmore')) {
            parent.document.getElementById('ocmore').innerHTML+=' ' + lastname + ' ' + lasttooltip;
            lastname='';
            lasttooltip='';
          } else {
            mayloopok=true;
          }
          if (vsxpnum > 0) maploopok=true;   // new line
          }
          if (vsxpnum > 0) maploopok=true;   // new line
              if (lvl == 1 && iname == 1) {
              if (dw != "") xx=dw;
              documentwrite("<" + "html> ");
              documentwrite("<" + "head><meta charset='utf-8'/> ");
              documentwrite("<" + "script type='text/javascript' src='//www.rjmprogramming.com.au/gchartgen.js'><" + "/script> ");
              documentwrite("<" + "script type='text/javascript' src='//www.google.com/jsapi'><" + "/script> ");
              documentwrite("<" + "script type='text/javascript'> ");
              documentwrite("google.load('visualization', '1', {packages:['orgchart']}); ");
              documentwrite("google.setOnLoadCallback(drawChart); ");
              documentwrite("function drawChart() { ");
              documentwrite("var data = new google.visualization.DataTable(); ");
              documentwrite("data.addColumn('string', 'Name'); ");
              documentwrite("data.addColumn('string', 'Manager'); ");
              documentwrite("data.addColumn('string', 'ToolTip'); ");
              documentwrite("data.addRows([ ");
                             documentwrite(xx);
              }
               var hm=howmany;
               var hm3=iname;
               var pname=name;
               var plvl=lvl;
               var pilvl=ilvl;
               var pthisone = thisone;
               var pht=ht;
               var pat=answeringto;

               if (iname == ht) {
                  //documentwrite(lvltext);
                  documentwriteagain(lvltext);
                  if (howmany > 0) {
               //alert("Before howmany=" + howmany + " vs ht=" + ht + " Vs iname=" + iname+ " Vs howmanytop=" + howmanytop);            
                //alert("aFter lvl=" + lvl + " vs (iname+1)=" + (iname+1)); 
                var h=howmany;    
                howmanytop=howmany;
              pmanager = name;
              //thisone = 1;
              answeringto = " - Answering To " + name + " ";
                doanother((lvl+1), 1, name, answeringto, "2");
                howmany = h;
                 //howmany = hm;
                 iname = hm3;
                 faiap_iname=hm3;
                 name = pname;
                 ilvl = pilvl;
                 lvl = plvl;
                 thisone = pthisone;
                 ht = pht;
                 offset = eval(offset + 1*0);
                 answeringto = pat;
                if (prevname != "") name = prevname;
               //alert("After howmany=" + howmany + " vs ht=" + ht + " Vs iname=" + iname+ " Vs howmanytop=" + howmanytop);            
               } 
               //alert("not after lvl=" + lvl + " vs (iname+1)=" + (iname+1));  
               howmany = "0";          
               } else if (iname < ht && howmany > 0 && lvl == 1) {
              pmanager = name;
              //thisone = 1;
              answeringto = " - Answering To " + name + " ";
              cbtlvl=lvl+1;
              cbtname=name;
              cbtanswer = " - Answering To " + name + " ";
                howmanytop=howmany;
                   doanother((lvl+1), 1, name, answeringto, "3");
                 howmany = hm;
                 iname = hm3;
                 faiap_iname=hm3;
                 name = pname;
                 ilvl = pilvl;
                 lvl = plvl;
                 thisone = pthisone;
                 answeringto = pat;
                 ht = pht;
                 //offset = offset + 1;
               } else if (iname < ht && howmany > 0 && lvl > 1) {
               //alert("Before howmany=" + howmany + " vs ht=" + ht + " Vs iname=" + iname+ " Vs howmanytop=" + howmanytop);            
                //alert("aFter lvl=" + lvl + " vs (iname+1)=" + (iname+1));            
              pmanager = name;
              //thisone = 1;
              answeringto = " - Answering To " + name + " ";
                howmanytop=howmany;
                doanother((lvl+1), eval((iname+1)*0+1), name, answeringto, "4");
                 howmany = hm;
                 iname = hm3;
                 faiap_iname=hm3;
                 name = pname;
                 ilvl = pilvl;
                 lvl = plvl;
                 ht = pht;
                 thisone = pthisone;
                 answeringto = pat;
                 offset = eval(offset + 1*0);
                 if (cbtname != "") {
                 name = cbtname;
                 lvl = cbtlvl;
                 answeringto = cbtanswer;
                 }
               //alert("After howmany=" + howmany + " vs ht=" + ht + " Vs iname=" + iname+ " Vs howmanytop=" + howmanytop);            
               } else {
                  documentwriteagain(lvltext);
               }
  
               howmanytop=howmany;
               howmany="0";
               prevname = name;
              }
              //documentwrite(lvltext);


               //howmanytop="0";

            //iname = jname;
            //ht = jt;

              //lvl=lvl+1;
              tcomma = ",";
              comma = "";
              //pmanager = name;
              //thisone = 1;
              //answeringto = " - Answering To " + name + " ";
              prevlvltext = lvltext;
              lvltext = "";
            }
            //lvl=lvl+1;
          }
          }
        }
   var jk = 2, ijk;
        if (allowed && thislevel == 1 && thisone == 1 && dw != "") {
        //alert("here " + lvltext);
        while (rest.replace(" \n /" + "/ , lvl" + jk + " ","") != rest) {
           for (ijk=0; ijk<50; ijk++) {
             rest = rest.replace(" \n /" + "/ , lvl" + jk + " ","");
           }
           jk = jk+1;
        }
              documentwrite(lvltext + rest);
              documentwrite("]); ");
              documentwrite("var chart = new google.visualization.OrgChart(document.getElementById('chart_div')); ");
              documentwrite("chart.draw(data, {allowHtml:true}); ");
              documentwrite("} ");
              documentwrite("<" + "/script> ");
              documentwrite("<" + "/head> ");

              documentwrite("<" + "body> ");
              documentwrite("<" + "div id='chart_div'></div> ");
              if (document.URL.indexOf('nojwin') != -1) {
              documentwrite("<" + "a id=another target=_blank href='./Google_OrgChart.php?nojwin=Y' title='Another'>Another organizational chart<" + "/a> &nbsp;&nbsp;<a id='remail' title='To email a snapshot of this Google Chart click me.' style='display:inline;' href='MAILTO:fillin.email@address?subject=Google%20Chart%20Snapshot&body=" + encodeURIComponent(document.URL.replace(".php", jpsuff + ".htm")) +  "'>Email snapshot of Google Chart ...</a>");
              } else {
              documentwrite("<" + "a id=another target=_blank href='./Google_OrgChart.php' title='Another'>Another organizational chart<" + "/a> &nbsp;&nbsp;<a id='remail' title='To email a snapshot of this Google Chart click me.' style='display:inline;' href='MAILTO:fillin.email@address?subject=Google%20Chart%20Snapshot&body=" + encodeURIComponent(document.URL.replace(".php", jpsuff + ".htm")) +  "'>Email snapshot of Google Chart ...</a>");
			  }
              documentwrite("<" + "/body> ");
              documentwrite("<" + "/html> ");


        docwrite(dw);
        }
      }
      
      function ourprompt(one, two) {
        var retp=null, yourone=one, yourtwo=two;
        if (ourjt != '' && one.indexOf(' How many ') != -1) {
          if (parent.document.getElementById('ocmore')) {
            parent.document.getElementById('ocmore').innerHTML+=' ' + lastname + ' ' + lasttooltip + ' -&gt; <br>' + ourjt.split(';')[0];
          }
          ourjobtitles=ourjt;
          ourjt='';
        }
        if (yourone.indexOf('Job Title') != -1 && yourtwo == "" && ourjobtitles.split(';')[0] != "") yourtwo=ourjobtitles.split(';')[0];
        if ('Job Title' != ourjobtitle && istack >= stack.length && lastlevel >= 0 && yourone.indexOf('Job Title') != -1) {
        if ('Job Title' != ourjobtitle && yourone.indexOf('Job Title') != -1) {
         if (ourjobtitles.indexOf(';') != -1 && yourone.indexOf('Level ') != -1) {
          if (lastlevel != eval(yourone.split('evel ')[1].split(' ')[0])) {
            //if (lastlevel >= 0) ourjobtitles=ourjobtitles.replace(ourjobtitles.split(';')[0] + ';','');
            //lastlevel=eval(yourone.split('evel ')[1].split(' ')[0]);
          }
          yourone=yourone.replace('Job Title',ourjobtitles.split(';')[0]).replace('Job Title',ourjobtitles.split(';')[0]);
         } else { 
          yourone=yourone.replace('Job Title',ourjobtitle).replace('Job Title',ourjobtitle);
         }
        }
          retp=ourjobtitles.split(';')[0]; //prompt(ourprefix + yourone, two);
        } else if (istack >= stack.length) {
        if ('Job Title' != ourjobtitle && yourone.indexOf('Job Title') != -1) {
         if (ourjobtitles.indexOf(';') != -1 && yourone.indexOf('Level ') != -1) {
          if (lastlevel != eval(yourone.split('evel ')[1].split(' ')[0])) {
            //if (lastlevel >= 0) ourjobtitles=ourjobtitles.replace(ourjobtitles.split(';')[0] + ';','');
            //lastlevel=eval(yourone.split('evel ')[1].split(' ')[0]);
          }
          yourone=yourone.replace('Job Title',ourjobtitles.split(';')[0]).replace('Job Title',ourjobtitles.split(';')[0]);
         } else { 
          yourone=yourone.replace('Job Title',ourjobtitle).replace('Job Title',ourjobtitle);
         }
        }
        if ('Person' != ourperson) {
         if (ourjobtitles.split(';')[0] != "") {
          yourone=yourone.replace('Person',ourperson.replace('Subclassification',ourjobtitles.split(';')[0])).replace('Person',ourperson.replace('Subclassification',ourjobtitles.split(';')[0]));
         } else {
          yourone=yourone.replace('Person',ourperson).replace('Person',ourperson);
         }
        }
        if ('Management' != ourmanagement) {
         if (ourjobtitles.split(';')[0] != "") {
          yourone=yourone.replace('Management',ourmanagement.replace('Subclassification',ourjobtitles.split(';')[0])).replace('Management',ourmanagement.replace('Subclassification',ourjobtitles.split(';')[0])).replace('him/her',ourmanagement.replace('Subclassification',ourjobtitles.split(';')[0].toLowerCase())).replace('him/her',ourmanagement.replace('Subclassification',ourjobtitles.split(';')[0].toLowerCase()));
         } else {
          yourone=yourone.replace('Management',ourmanagement).replace('Management',ourmanagement).replace('him/her',ourmanagement.toLowerCase()).replace('him/her',ourmanagement.toLowerCase());
         }
        }
        if ('people' != ourpeople) {
         if (ourjobtitles.split(';')[0] != "") {
          yourone=yourone.replace('people',ourpeople.replace('subclassification',ourjobtitles.split(';')[0].toLowerCase())).replace('people',ourpeople.replace('subclassification',ourjobtitles.split(';')[0].toLowerCase()));
         } else {
          yourone=yourone.replace('people',ourpeople).replace('people',ourpeople);
         }
        }
        if ('Nickname' != ournickname) {
         if (ourjobtitles.split(';')[0] != "") {
          yourone=yourone.replace('Nickname',ournickname.replace('Subclassification',ourjobtitles.split(';')[0])).replace('Nickname',ournickname.replace('Subclassification',ourjobtitles.split(';')[0]));
         } else {
          yourone=yourone.replace('Nickname',ournickname).replace('Nickname',ournickname);
         }
        }
          //document.title=ourprejobtitles + ourprefix + yourone + ' = ' + yourtwo;
          if (document.getElementById('prompt')) {
           if ((ourprejobtitles + ourprefix + yourone).indexOf('<input ') != -1) {
            document.getElementById('prompt').value=(ourprejobtitles + ourprefix + yourone).split('<input ')[-1 + (ourprejobtitles + ourprefix + yourone).split('<input ').length];
            //document.getElementById('hprompt').value=encodeURIComponent(ourprejobtitles + ourprefix + yourone).split('<input ')[-1 + (ourprejobtitles + ourprefix + yourone).split('<input ').length];
           } else {
            document.getElementById('prompt').value=ourprejobtitles + ourprefix + yourone;
            //document.getElementById('hprompt').value=encodeURIComponent(ourprejobtitles + ourprefix + yourone);
           }
          }
          if (document.getElementById('val' + eval(0 + xpnum))) {
            document.getElementById('val' + eval(0 + xpnum)).value=yourtwo;
          }
          if (document.getElementById('hval' + eval(0 + xpnum))) {
            document.getElementById('hval' + eval(0 + xpnum)).value=encodeURIComponent(yourtwo);
          }
          if (1 == 2 && document.getElementById("safariform") && (ourprejobtitles + ourprefix + yourone).indexOf('Management Level - Dummy Name: How many people answer directly to ') != -1) {
		  if (vsxpnum > 0) {
		    vsinfo+='' + vsxpnum + ' ';
		    vsxpnum--;
		  }
          retp=prompt((ourprejobtitles + ourprefix + yourone).replace('Dummy Name: How many people','Name of person,How many people'), 'Firstname Lastname,' + yourtwo);
                   if (1 == 2 && retp == null) {
                     name='Firstname Lastname';
                     lastname=name;
                     retp='0';
                   } else if (1 == 2 && retp.replace('null','') == '') {
                     name='Firstname Lastname';
                     lastname=name;
                     retp='0';
                   } else if (('' + retp).indexOf(',') != -1) {
                     name=retp.split(',')[0];
                     lastname=name;
                     document.getElementById('hval' + eval(-1 + xpnum)).value=encodeURIComponent(name);
                     retp=retp.replace(lastname + ',','');
                   }
          } else if (1 == 2 && document.getElementById("safariform") && (ourprejobtitles + ourprefix + yourone).indexOf(' Firstname Lastname:') != -1) {
		  if (vsxpnum > 0) {
		    vsinfo+='' + vsxpnum + ' ';
		    vsxpnum--;
		  }
          retp=prompt((ourprejobtitles + ourprefix + yourone).replace('Firstname Lastname: How many people','Name of person,How many people'), 'Firstname Lastname,' + yourtwo);
                   if (1 == 2 && retp == null) {
                     name='FirstnameLastname';
                     lastname=name;
                     retp='0';
                   } else if (1 == 2 && retp.replace('null','') == '') {
                     name='FirstnameLastname';
                     lastname=name;
                     retp='0';
                   } else if (('' + retp).indexOf(',') != -1) {
                     name=retp.split(',')[0];
                     lastname=name;
                     document.getElementById('hval' + eval(-1 + xpnum)).value=encodeURIComponent(name);
                     retp=retp.replace(lastname + ',','');
                   }
          } else {
          if (psofar.indexOf((';' + ourprejobtitles + ourprefix + yourone + ';')) != -1) {
          retp=' ';
          } else {
		  if (vsxpnum > 0) {
		    vsinfo+='' + vsxpnum + ' ';
		    vsxpnum--;
		  }
          retp=prompt(ourprejobtitles + ourprefix + yourone, yourtwo);
          psofar+=ourprejobtitles + ourprefix + yourone + ";";
          }
          if (1 == 2 && (ourprejobtitles + ourprefix + yourone).indexOf(' Person') != -1 && (ourprejobtitles + ourprefix + yourone).indexOf('mandatory') != -1) {
                 if (document.getElementById("safariform")) {
                   if (1 == 2 && retp == null) {
                     retp='Dummy Name';
                   } else if (1 == 2 && retp.replace('null','') == '') {
                     retp='Dummy Name';
                   } else if (('' + retp).indexOf(',') != -1) {
                     name=retp.split(',')[0];
                     lastname=name;
                     document.getElementById('hval' + eval(-1 + xpnum)).value=encodeURIComponent(name);
                     retp=retp.replace(lastname + ',','');
                   }
                 }
          } else if (document.getElementById("safariform") && ('' + retp).indexOf(',') != -1) {
                     name=retp.split(',')[0];
                     lastname=name;
                     document.getElementById('hval' + eval(-1 + xpnum)).value=encodeURIComponent(name);
                     retp=retp.replace(lastname + ',','');
          }
          }
        } else if (stack[istack].replace('?','') == '') {
        if ('Job Title' != ourjobtitle && yourone.indexOf('Job Title') != -1) {
         if (ourjobtitles.indexOf(';') != -1 && yourone.indexOf('Level ') != -1) {
          if (lastlevel != eval(yourone.split('evel ')[1].split(' ')[0])) {
            //if (lastlevel >= 0) ourjobtitles=ourjobtitles.replace(ourjobtitles.split(';')[0] + ';','');
            //lastlevel=eval(yourone.split('evel ')[1].split(' ')[0]);
          }
          yourone=yourone.replace('Job Title',ourjobtitles.split(';')[0]).replace('Job Title',ourjobtitles.split(';')[0]);
         } else { 
          yourone=yourone.replace('Job Title',ourjobtitle).replace('Job Title',ourjobtitle);
         }
        }
        if ('Person' != ourperson) {
         if (ourjobtitles.split(';')[0] != "") {
          yourone=yourone.replace('Person',ourperson.replace('Subclassification',ourjobtitles.split(';')[0])).replace('Person',ourperson.replace('Subclassification',ourjobtitles.split(';')[0]));
         } else {
          yourone=yourone.replace('Person',ourperson).replace('Person',ourperson);
         }
        }
        if ('Management' != ourmanagement) {
         if (ourjobtitles.split(';')[0] != "") {
          yourone=yourone.replace('Management',ourmanagement.replace('Subclassification',ourjobtitles.split(';')[0])).replace('Management',ourmanagement.replace('Subclassification',ourjobtitles.split(';')[0])).replace('him/her',ourmanagement.replace('Subclassification',ourjobtitles.split(';')[0].toLowerCase())).replace('him/her',ourmanagement.replace('Subclassification',ourjobtitles.split(';')[0].toLowerCase()));
         } else {
          yourone=yourone.replace('Management',ourmanagement).replace('Management',ourmanagement).replace('him/her',ourmanagement.toLowerCase()).replace('him/her',ourmanagement.toLowerCase());
         }
        }
        if ('people' != ourpeople) {
         if (ourjobtitles.split(';')[0] != "") {
          yourone=yourone.replace('people',ourpeople.replace('subclassification',ourjobtitles.split(';')[0].toLowerCase())).replace('people',ourpeople.replace('subclassification',ourjobtitles.split(';')[0].toLowerCase()));
         } else {
          yourone=yourone.replace('people',ourpeople).replace('people',ourpeople);
         }
        }
        if ('Nickname' != ournickname) {
         if (ourjobtitles.split(';')[0] != "") {
          yourone=yourone.replace('Nickname',ournickname.replace('Subclassification',ourjobtitles.split(';')[0])).replace('Nickname',ournickname.replace('Subclassification',ourjobtitles.split(';')[0]));
         } else {
          yourone=yourone.replace('Nickname',ournickname).replace('Nickname',ournickname);
         }
        }
          //document.title=ourprejobtitles + ourprefix + yourone + ' = ' + yourtwo;
          if (document.getElementById('prompt')) {
           if ((ourprejobtitles + ourprefix + yourone).indexOf('<input ') != -1) {
            document.getElementById('prompt').value=(ourprejobtitles + ourprefix + yourone).split('<input ')[-1 + (ourprejobtitles + ourprefix + yourone).split('<input ').length];
            //document.getElementById('hprompt').value=encodeURIComponent(ourprejobtitles + ourprefix + yourone).split('<input ')[-1 + (ourprejobtitles + ourprefix + yourone).split('<input ').length];
           } else {
            document.getElementById('prompt').value=ourprejobtitles + ourprefix + yourone;
            //document.getElementById('hprompt').value=encodeURIComponent(ourprejobtitles + ourprefix + yourone);
           }
          }
          if (document.getElementById('val' + eval(0 + xpnum))) {
            document.getElementById('val' + eval(0 + xpnum)).value=yourtwo;
          }
          if (document.getElementById('hval' + eval(0 + xpnum))) {
            document.getElementById('hval' + eval(0 + xpnum)).value=encodeURIComponent(yourtwo);
          }
          if (1 == 2 && document.getElementById("safariform") && (ourprejobtitles + ourprefix + yourone).indexOf('Management Level - Dummy Name: How many people answer directly to ') != -1) {
		  if (vsxpnum > 0) {
		    vsinfo+='' + vsxpnum + ' ';
		    vsxpnum--;
		  }
          retp=prompt((ourprejobtitles + ourprefix + yourone).replace('Dummy Name: How many people','Name of person,How many people'), 'Firstname Lastname,' + yourtwo);
                   if (retp == null) {
                     name='Firstname Lastname';
                     lastname=name;
                     retp='0';
                   } else if (retp.replace('null','') == '') {
                     name='Firstname Lastname';
                     lastname=name;
                     retp='0';
                   } else if (('' + retp).indexOf(',') != -1) {
                     name=retp.split(',')[0];
                     lastname=name;
                     document.getElementById('hval' + eval(-1 + xpnum)).value=encodeURIComponent(name);
                     retp=retp.replace(lastname + ',','');
                   }
          } else if (1 == 2 && document.getElementById("safariform") && (ourprejobtitles + ourprefix + yourone).indexOf(' Firstname Lastname:') != -1) {
		  if (vsxpnum > 0) {
		    vsinfo+='' + vsxpnum + ' ';
		    vsxpnum--;
		  }
          retp=prompt((ourprejobtitles + ourprefix + yourone).replace('Firstname Lastname: How many people','Name of person,How many people'), 'Firstname Lastname,' + yourtwo);
                   if (1 == 2 && retp == null) {
                     name='FirstnameLastname';
                     lastname=name;
                     retp='0';
                   } else if (1 == 2 && retp.replace('null','') == '') {
                     name='FirstnameLastname';
                     lastname=name;
                     retp='0';
                   } else if (('' + retp).indexOf(',') != -1) {
                     name=retp.split(',')[0];
                     lastname=name;
                     document.getElementById('hval' + eval(-1 + xpnum)).value=encodeURIComponent(name);
                     retp=retp.replace(lastname + ',','');
                   }
          } else {
          if (psofar.indexOf((';' + ourprejobtitles + ourprefix + yourone + ';')) != -1) {
          retp=' ';
          } else {
          psofar+=ourprejobtitles + ourprefix + yourone + ";";
		  if (vsxpnum > 0) {
		    vsinfo+='' + vsxpnum + ' ';
		    vsxpnum--;
		  }
          retp=prompt(ourprejobtitles + ourprefix + yourone, yourtwo);
          }
          if ((ourprejobtitles + ourprefix + yourone).indexOf(' Person') != -1 && (ourprejobtitles + ourprefix + yourone).indexOf('mandatory') != -1) {
                 if (document.getElementById("safariform")) {
                   if (1 == 2 && retp == null) {
                     retp='Dummy Name';
                   } else if (1 == 2 && retp.replace('null','') == '') {
                     retp='Dummy Name';
                   } else if (('' + retp).indexOf(',') != -1) {
                     name=retp.split(',')[0];
                     lastname=name;
                     document.getElementById('hval' + eval(-1 + xpnum)).value=encodeURIComponent(name);
                     retp=retp.replace(lastname + ',','');
                   }
                 }
          } else if (document.getElementById("safariform") && ('' + retp).indexOf(',') != -1) {
                     name=retp.split(',')[0];
                     lastname=name;
                     document.getElementById('hval' + eval(-1 + xpnum)).value=encodeURIComponent(name);
                     retp=retp.replace(lastname + ',','');
          }
          }
          istack++;
        } else {
          retp=stack[istack]; //prompt(ourprefix + yourone, two);
          istack++;
        }
        if (istack >= stack.length && yourone.indexOf('(optional)') != -1) {
        //if (istack >= stack.length) alert(yourone + ' Versus ' + ourjobtitles.replace(ourjobtitles.split(';')[0] + ';',''));
              //alert(ourjobtitles + ' Vs ' + ourjobtitles.replace(ourjobtitles.split(';')[0] + ';',''));
        if (ourjobtitles.indexOf(';') != -1 && yourone.indexOf('Level ') != -1) {
              //alert(ourjobtitles + ' VS ' + ourjobtitles.replace(ourjobtitles.split(';')[0] + ';',''));
          if (lastlevel != eval((' ' + yourone).split('Level ')[1].split(' ')[0])) {
            if (lastlevel >= 0) {
              //alert(ourjobtitles + ' vs ' + ourjobtitles.replace(ourjobtitles.split(';')[0] + ';',''));
              ourjt=ourjobtitles.replace(ourjobtitles.split(';')[0] + ';','');
            }
            lastlevel=eval((' ' + yourone).split('Level ')[1].split(' ')[0]);
          }
        }
        }
        return retp;
      }
    </script>
  </head>

  <body>
    <div id='chart_div'></div>
    <form id='ourform' name='ourform' action='./Google_OrgChart.php' method='POST'>
    <input type="hidden" value="" name="next" id="next"></input><?php echo $njthreesuff; ?>
    <input type="submit" value="Submit" name="submit" id="submit" style="display: none;"></input>
    </form>
    <a id='oura' href='./Google_OrgChart.php?next=' style="display: none;">next</a>
<script type='text/javascript'>
if (document.URL.indexOf('nojwin') != -1 || navigator.userAgent.match(/iPhone|iPad/i)) {
  //document.getElementById('pch1').innerHTML+='.';
  var xansis='x', hiddenbits='<input type="hidden" value="" name="next" id="safarinext"></input>';
  xpnum=1;
  var weirdcp=""
  curprompt='';
  if (document.URL.indexOf('?') != -1) {
    var pairing, argsare=document.URL.split('#')[0].split('?')[1].split('&');
    for (var iargsare=0; iargsare<argsare.length; iargsare++) {
      pairing=argsare[iargsare].split('=');
      if (('*' + pairing[0]).indexOf('*val') == -1 && ('*' + pairing[0]).indexOf('*prompt') == -1 && ('*' + pairing[0]).indexOf('*OK') == -1 && ('*' + pairing[0]).indexOf('*Cancel') == -1) {
       if (pairing[0] != 'next') hiddenbits+="<input type=hidden name=" + pairing[0] + " value='" + pairing[1] + "'></input>";
      } else if (('*' + pairing[0]).indexOf('*prompt') != -1) {
       curprompt=decodeURIComponent(decodeURIComponent(pairing[1]));
       weirdcp=pairing[1];
       //document.title=prename + ' ... ' + curprompt;
      }
    }
  }
  var prenexttolasta='', nexttolasta='',lasta='', lesssix='';
  while (xansis != '') {
   xansis=location.search.split('val' + xpnum + '=')[1] ? decodeURIComponent(decodeURIComponent(location.search.split('val' + xpnum + '=')[1].split('&')[0]).replace(/\+/g,' ')) : '';
   if (document.URL.indexOf('val' + xpnum + '=') != -1) {
     if (document.URL.indexOf('val' + eval(-3 + xpnum) + '=') != -1) {
       lesssix=decodeURIComponent(decodeURIComponent(document.URL.split('val' + eval(-3 + xpnum) + '=')[1].split('&')[0]));
     }
     if (nexttolasta != '') prenexttolasta=nexttolasta;
     if (lasta != '') nexttolasta=lasta;
     lasta=xansis;
     hiddenbits+="<input type=hidden name=val" + xpnum + " value='" + encodeURIComponent(xansis) + "'></input>";
     xpnum++;
     xansis='x';
   } else {
     xansis='';
   }
  }
  
  if ((nexttolasta + ' ').substring(0,1) >= '1' && (nexttolasta + ' ').substring(0,1) <= '9') {
   if ((lasta + ' ').substring(0,1) >= 'A') {
    if (curprompt.indexOf('Job') != -1 && curprompt.indexOf('Title') != -1) {
     prename=lasta;
    }
   }
  }
  if ((nexttolasta + ' ').substring(0,1) >= '1' && (nexttolasta + ' ').substring(0,1) <= '9') {
   if ((lasta + ' ').substring(0,1) >= 'A') {
    if (curprompt.indexOf('Job') != -1 && curprompt.indexOf('Title') != -1) {
     prename=lasta;
    }
   }
  }
  if ((prenexttolasta + ' ').substring(0,1) >= '1' && (prenexttolasta + ' ').substring(0,1) <= '9') {
   if ((nexttolasta + ' ').substring(0,1) >= 'A') {
    if (curprompt.indexOf('Nickname') != -1) {
     prename=nexttolasta;
    }
   }
  }
  if (curprompt.indexOf('many') != -1 && curprompt.indexOf('people') != -1) {
   if (curprompt.indexOf('answer') != -1 && curprompt.indexOf('directly') != -1) {
   if ((prenexttolasta + ' ').substring(0,1) >= 'A') {
     prename=prenexttolasta;
    } else if (weirdcp.indexOf('%253A%2520') != -1) {
     prename=weirdcp.split('%253A%2520')[0].split('20')[-1 + weirdcp.split('%253A%2520')[0].split('20').length];
    }
   }
  }
  if ((lasta + ' ') == '0 ') {
    if (curprompt.indexOf('Job') != -1 && curprompt.indexOf('Title') != -1) {
      if (curprompt.indexOf('Level ') != -1) {
      curprompt="Level " + eval(1 + curprompt.split("Level ")[1].split(" ")[0]) + " Management Level: How many people?";
      } else {
      curprompt="Level 2 Management Level: How many people?";
      }
      couldbe=true;
      if ((nexttolasta + ' ') == '0 ') forceit=true;
    }
  }
  if ((lasta + ' ').substring(0,1) >= '1' && (lasta + ' ').substring(0,1) <= '9') {
    if (curprompt.indexOf('Job') != -1 && curprompt.indexOf('Title') != -1 && lesssix != '') {
      if (curprompt.indexOf('Level ') != -1) {
      curprompt="Level " + eval(0 + curprompt.split("Level ")[1].split(" ")[0]) + " Management Level" + " - Answering To " + lesssix + " " + " - Person 1 of " + lasta + ": Name (mandatory)?";
      } else {
      curprompt="Level 1 Management Level" + " - Answering To " + lesssix + " " + " - Person 1 of " + lasta + ": Name (mandatory)?";
      }
    }
  }
  vsxpnum=xpnum;
  
  //if ((lasta + ' ').substring(0,1) >= '1' && (lasta + ' ').substring(0,1) <= '9') {
  //  location.href=document.URL.split('#')[0] + '&val' + xpnum + '=Dummy%20Name';
  //} else if (lasta.indexOf(',') != -1) {
  //  var newname=lasta.split(',')[0];
  //  hiddenbits=hiddenbits.replace(encodeURIComponent("Dummy Name"), encodeURIComponent(newname)).replace(encodeURIComponent(lasta),encodeURIComponent(lasta.replace(newname + ',','')));
  //}
  //if (document.URL.indexOf('nojwinyes=') != -1) { 
  //document.write("<form onsubmit=\" if (document.getElementById('val" + xpnum + "').value.replace('null','') != '') { if (decodeURIComponent(document.getElementById('prompt').value).indexOf(' For ') == 0) {  selecteventtwo(document.getElementById('val" + xpnum + "').value);  } else { selectevent(document.getElementById('val" + xpnum + "').value); } } else if (document.URL.indexOf('&data=') != -1) { location.href=document.URL; } else { this.style.display='none'; } xpnum++; return false; \" enctype='text/plain' style='display:none;position:absolute;top:70;left:2%;z-index:56;width:48%;background-color:orange;border:2px solid red;' id=safariform method=GET action=" + document.URL.split('#')[0].split('?')[0] + " readonly>" + hiddenbits + "<textarea style='width:96%;background-color:#eeeeee;' rows=5 id='prompt' readonly='readonly'></textarea><br><input type=hidden value='' name=val" + xpnum + " id=hval" + xpnum + "></input><input onkeypress=\"checkEnter(event);\" onblur=\" document.getElementById('h' + this.id).value=encodeURIComponent(this.value); \" style='width:50%;background-color:yellow;' type=text value='' id=val" + xpnum + "></input>&nbsp;&nbsp;<input style='float:right;width:25%;' type=submit value=OK name=OK id=OK></input>&nbsp;<input style='display:none;' type=submit value=Cancel name=Cancel id=Cancel></input>&nbsp;<input type=button value=Cancel id=bCancel onclick=\" document.getElementById('val" + xpnum + "').value='null'; document.getElementById('hval" + xpnum + "').value=encodeURIComponent('null'); this.style.display='none';  document.getElementById('Cancel').style.display='block'; document.getElementById('Cancel').click(); \"></input>&nbsp;</input></form>"); 
  //document.getElementById('pch1').innerHTML+='....';
  //} else {
  document.write("<form enctype='text/plain' style='display:block;position:absolute;top:20;left:2%;z-index:56;width:38%;background-color:orange;border:2px solid red;' id=safariform method=GET action=" + document.URL.split('#')[0].split('?')[0] + " readonly>" + hiddenbits + "<textarea style='width:96%;background-color:#eeeeee;' rows=5 id='prompt' readonly='readonly'></textarea><textarea style='display:none;width:96%;background-color:#eeeeee;' rows=5 id='hprompt' name='prompt' readonly='readonly'></textarea><br><input type=hidden value='' name=val" + xpnum + " id=hval" + xpnum + "></input><input onkeypress=\"checkEnter(event);\" onblur=\" document.getElementById('h' + this.id).value=encodeURIComponent(this.value); \" style='width:50%;background-color:yellow;' type=text value='' id=val" + xpnum + "></input>&nbsp;&nbsp;<input style='float:right;width:25%;' type=submit value=OK name=OK id=OK></input>&nbsp;<input style='display:none;' type=submit value=Cancel name=Cancel id=Cancel></input>&nbsp;<input type=button value=Cancel id=bCancel onclick=\" document.getElementById('val" + xpnum + "').value='null'; document.getElementById('hval" + xpnum + "').value=encodeURIComponent('null'); this.style.display='none';  document.getElementById('Cancel').style.display='block'; document.getElementById('Cancel').click(); \"></input>&nbsp;</input></form>"); 
  //document.getElementById('pch1').innerHTML+='..';
  //}
  if (document.getElementById('another')) {
    if (document.getElementById('another').href.indexOf('nojwin') == -1) {
     document.getElementById('another').href+='?nojwin=Y';
    }
  }
  if (document.getElementById('remail')) {
    document.getElementById('remail').href='MAILTO:fillin.email@address?subject=Google%20Chart%20Snapshot&body=' + encodeURIComponent(document.URL.split('#')[0]);
  }
}
</script>
    <script>
      setTimeout(doanother(1,1,'','',''), 2000);
    </script>
  </body>
<?php
echo "</html" . $suff . ">";
?>
