 var planlist = new Object();
 var visited = false;
 var model =   '';
 var modelName = '';
 var visitedwin = null;
 visitedlist = new Object();

 function noErrorMessages () { return true; }
 window.onerror = noErrorMessages;

function writePlanwin(model,modelName) {
  var items;
  
// Header  
  planwin.frames[0].document.writeln('<body background=bricksfaded2.jpg text="#000066">');
  planwin.frames[0].document.writeln('<table width=100%><tr><th><font size="+1">'+modelName+'</font></th><th><img src='+model+'_tn.gif></th><th>Kappus Construction, Inc.<p><img src="../phonehome.png"></th></tr></table>');
  planwin.frames[0].document.writeln('</body>');
  planwin.frames[0].document.close();
  planwin.frames[1].document.writeln('<head>');
  planwin.frames[1].document.writeln('<script language=javascript>');

// Main window  
  planwin.frames[2].document.writeln('<center><img src="'+model+'.gif"></center>');
  planwin.frames[2].document.close();
  planwin.frames[1].document.writeln('function modelView(view,mod) {');
  planwin.frames[1].document.writeln('if (view==\'plan\') mod = mod + \'_plan.gif\';');
  planwin.frames[1].document.writeln('else if (view==\'spec\') mod = mod + \'_spec.html\';');
  planwin.frames[1].document.writeln('else if (view==\'elev\') mod = mod + \'.gif\';');
  planwin.frames[1].document.writeln('parent.frames[2].document.clear();');
  planwin.frames[1].document.writeln('parent.frames[2].document.writeln(\'<body bgcolor="#ccddff">\')');  
  planwin.frames[1].document.writeln('if (view==\'spec\') parent.frames[2].document.location= mod');
  planwin.frames[1].document.writeln('else parent.frames[2].document.writeln(\'<center><img src="\'+mod+\'"></center>\')');
//  planwin.frames[1].document.writeln('parent.frames[2]document.writeln(\'</body>\')');
  planwin.frames[1].document.writeln('parent.frames[2].document.close();');
  planwin.frames[1].document.writeln('parent.opener.visitedwin.focus();');
  planwin.frames[1].document.writeln('return true; }');

  // Sidebar
  planwin.frames[1].document.writeln('</script>');
  planwin.frames[1].document.writeln('</head>');
  planwin.frames[1].document.writeln('<body background=bricksfaded2.jpg text="#000066">');
  planwin.frames[1].document.writeln('<center>');
  planwin.frames[1].document.writeln('<script>parent.frames[2].document.clear();</script>');
  planwin.frames[1].document.writeln('<form><input TYPE="button" VALUE="  Elevation   " onClick="javascript:modelView(\'elev\',\''+model+'\');"><br><br>');
  planwin.frames[1].document.writeln('<input TYPE="button" VALUE="  Floor Plan  " onClick="javascript:modelView(\'plan\',\''+model+'\');"><br><br>');
  planwin.frames[1].document.writeln('<input TYPE="button" VALUE="Specification" onClick="javascript:modelView(\'spec\',\''+model+'\');"></form>');
  planwin.frames[1].document.writeln('<script>parent.frames[2].document.body.bgColor=\'#ccddff\'</script>');
  planwin.frames[1].document.writeln('</center>');
  planwin.frames[1].document.writeln('</body>');
  planwin.frames[1].document.close();
  planwin.document.title = '"'+modelName+'"';
  planwin.focus();

  // Window navigation quicklist
  if (!visited) {
    visited = true;
    visitedwin.document.writeln('<head><title>Model Window Selector</title></head>');
    visitedwin.document.writeln('<body background="bricksfaded2.jpg" text="#000066">');
    visitedwin.document.writeln('<font face="tahoma" size="-1"><b>Window Selector:&nbsp;&nbsp;</b></font>');
    visitedwin.document.writeln('<a onClick="opener.focus();" style="cursor:hand"><font face="tahoma" size="-1">Main</font></a>');
    for (items in visitedlist)      //in case nav window was closed before and is now being reopened
      visitedwin.document.writeln('<a onClick="if (!opener.planlist[\''+items+'\'].closed) { opener.planlist[\''+items+'\'].focus(); window.focus();} else alert(\''+items+' window closed - please reopen from Main.\');" style="cursor:hand"><font face="tahoma" size="-1"> | '+items+'</font></a>');
  }
  if (!visitedlist[modelName]) {
    visitedwin.document.writeln('<a onClick="if (!opener.planlist[\''+modelName+'\'].closed) { opener.planlist[\''+modelName+'\'].focus(); window.focus();} else alert(\''+modelName+' window closed - please reopen from Main.\');" style="cursor:hand"><font face="tahoma" size="-1"> | '+modelName+'</font></a>');
    visitedlist[modelName] = true;
  }
  
  visitedwin.focus();
    
  return true;
 }

function openPlans(a,b) {  

  planlist[b]=window.open('planframes.html',a,'width=800,height=550,top=110,menubar=no,location=no,resizable=yes,status=yes');
  planwin = planlist[b];
  if (!planwin.opener) planwin.opener = self;
  model = a;
  modelName = b;
  
  // Allow page time to load before trying to write to it
  setTimeout("writePlanwin(model,modelName)",1000);
  clearTimeout();
  
  if (visited && visitedwin.closed) visited = false;
  if (!visited) { 
    visitedwin = window.open('visited.html','VISWIN','width=640,height=100,left=0,top=0,menubar=no,resizable=no,scrollbars=no,location=no,status=no,toolbar=no,fullscreen=no'); 
    visitedwin.resizeTo(640,50);
    visitedwin.opener = this;
  }  

  return true;
}

function cleanup() {
  var childwin;
  if (visited) visitedwin.close();
  for (childwin in planlist) {
    planlist[childwin].close();
  }
  return true;
}

