var NoteOnceArray = new Array();
var NoteOnceBasetypes = new Array();
var NoteOnceIsolatorTypes = new Array();

function StartOfPage(title) {
    PageStart = "<html>\n";
    PageStart += "<head>\n";
    PageStart += "<title>" + title + "</title>\n\n";
    PageStart += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n";
    PageStart += "</head>\n";
    PageStart += "<body bgcolor=\"#FFFFFF\" text=\"#000000\">\n";
    return(PageStart);
}

function FirstLineOfHeader(SideNote) {

    FirstLine = "  <tr>\n";
    theDate = new Date();
    aDate = theDate.getMonth() + "/" + theDate.getDate() + "/" + theDate.getFullYear();
    FirstLine += "  <td width = \"30%\"><b>" + aDate + "</b></td>\n";
    FirstLine += "  <td width = \"45%\">\n";
    FirstLine += "    <div align=\"center\"><b>KINETICS NOISE CONTROL, INC.</b></div>\n";
    FirstLine += "  </td>\n";
    FirstLine += "  <td width = \"35%\" align=\"right\"><b>";
    FirstLine += SideNote;
    FirstLine += "</b></td>\n";
    FirstLine += "  </tr>\n";
    FirstLine += "  <tr>\n";
    return(FirstLine);
}

function SecondLineOfHeader() {
    aTime = theDate.getHours() + ":" ;
    x = theDate.getMinutes();
    if(x < 10) x = "0" + x; 
    aTime += x;
    SecondLine = "  <td><b>" + aTime + "</b></td>\n";
    SecondLine += "  <td>\n";
    SecondLine += "    <div align=\"center\"><b>Mechanical Equipment Isolation Specification</b></div>\n";
    SecondLine += "  </td>\n";
    SecondLine += "  <td></td>\n";
    SecondLine += "  </tr>\n";
    return(SecondLine);
}

function SecondLineOfSpec(SpecType) {
    aTime = theDate.getHours() + ":" ;
    x = theDate.getMinutes();
    if(x.length == 1) x = "0" + x; 
    aTime += x;
    SecondLine = "  <td><b>" + aTime + "</b></td>\n";
    SecondLine += "  <td>\n";
    SecondLine += "    <div align=\"center\"><b>"+ SpecType + "</b></div>\n";
    SecondLine += "  </td>\n";
    SecondLine += "  <td></td>\n";
    SecondLine += "  </tr>\n";
    return(SecondLine);
}
function ThirdLineOfHeader() {
    ThirdLine = "  <tr>\n";
    ThirdLine += "  <td>&nbsp;</td>\n";
    ThirdLine += "  <td>\n";
    ThirdLine += "    <div align=\"center\"><b>Job # " +  Isoguide.txtJobNumber.value + " : " + Isoguide.txtJobName.value + "</b></div>\n";
    ThirdLine += "  </td>\n";
    ThirdLine += "  <td>&nbsp;</td>\n";
    ThirdLine += "  </tr>\n";
    return(ThirdLine);
}

function IsoguideHeader(title, SideNote) {
    IsoguideDocHeader = StartOfPage(title);
    IsoguideDocHeader += "<table width=\"100%\" border=\"0\">\n";
    IsoguideDocHeader += FirstLineOfHeader(SideNote);
    IsoguideDocHeader += SecondLineOfHeader();
    IsoguideDocHeader += ThirdLineOfHeader();
    return(IsoguideDocHeader);
}

function IsoguideEquipHeader() {
    IsoguideEquHeader = "  <tr>\n";
    IsoguideEquHeader += "    <td><b>General Project Information</b></td>\n";
    IsoguideEquHeader += "    <td>&nbsp;</td>\n";
    IsoguideEquHeader += "    <td>&nbsp;</td>\n";
    IsoguideEquHeader += "  </tr>\n";
    IsoguideEquHeader += "</table>\n";
    IsoguideEquHeader += "<hr>\n";
    return(IsoguideEquHeader);
}

function IsoguideJobInfo() {
    IsoguideJobInfoCode = "<table width=\"100%\" border=\"0\">\n";
    IsoguideJobInfoCode += "  <tr >\n";
    IsoguideJobInfoCode += "    <td width=\"15%\"><b>Location</b></td>\n";
    IsoguideJobInfoCode += "    <td width=\"35%\">"+  Isoguide.Location.value +"</td>\n";
    IsoguideJobInfoCode += "    <td width=\"15%\"><b>Metric</b></td>\n";
    if(Isoguide.MetricSystem.checked == true) { 
        ch = "Yes";
    }
    else {
        ch = "No"
    }
    IsoguideJobInfoCode += "    <td width=\"35%\">" + ch + "</td>\n";
    IsoguideJobInfoCode += "  </tr>\n";
    IsoguideJobInfoCode += "  <tr>\n";
    IsoguideJobInfoCode += "    <td><b>Architect</b></td>\n";
    IsoguideJobInfoCode += "    <td>"+  Isoguide.Architect.value +"</td>\n";
    IsoguideJobInfoCode += "    <td><b>Last Revision</b></td>\n";
    IsoguideJobInfoCode += "    <td>"+  Isoguide.RevisionDate.value +"</td>\n";
    IsoguideJobInfoCode += "  </tr>\n";
    IsoguideJobInfoCode += "  <tr>\n";
    IsoguideJobInfoCode += "    <td><b>Engineer</b></td>\n";
    IsoguideJobInfoCode += "    <td>"+  Isoguide.Engineer.value +"</td>\n";
    IsoguideJobInfoCode += "    <td>&nbsp;</td>\n";
    IsoguideJobInfoCode += "    <td>&nbsp;</td>\n";
    IsoguideJobInfoCode += "  </tr>\n";
    IsoguideJobInfoCode += "  <tr>\n";
    IsoguideJobInfoCode += "    <td><b>Designer</b></td>\n";
    IsoguideJobInfoCode += "    <td>"+  Isoguide.Designer.value +"</td>\n";
    IsoguideJobInfoCode += "    <td>&nbsp;</td>\n";
    IsoguideJobInfoCode += "    <td>&nbsp;</td>\n";
    IsoguideJobInfoCode += "  </tr>\n";
    IsoguideJobInfoCode += "</table>\n";
    IsoguideJobInfoCode += "<br>";
    return(IsoguideJobInfoCode);
}    

    
function IsoguideEqDataRows() {  
    IsoguideEqHeader = "<hr>\n";
    IsoguideEqHeader = "<table width=\"100%\" border=\"0\">\n";

    IsoguideEqHeader += "  <tr>\n";
    IsoguideEqHeader += "    <td><b><font size=2>Tag</font></b></td>\n";
    IsoguideEqHeader += "   <td><b><font size=2>Equipment Type</font></b></td>\n";
    IsoguideEqHeader += "   <td><b><font size=2>HP or Other</font></b></td>\n";
    IsoguideEqHeader += "   <td><b><font size=2>Base/Isolator Type</font></b></td>\n";
    IsoguideEqHeader += "   <td><b><font size=2>Notes</font></b></td>\n";
    IsoguideEqHeader += "  </tr>\n";
    IsoguideEqHeader += "  <tr>\n";
    IsoguideEqHeader += "   <td>&nbsp;</td>\n";
    IsoguideEqHeader += "   <td><b><font size=2>Category</font></b></td>\n";
    IsoguideEqHeader += "   <td><b><font size=2>RPM</font></b></td>\n";
    IsoguideEqHeader += "   <td><b><font size=2>Min. Defl. In.</font></b></td>\n";
    IsoguideEqHeader += "   <td><b><font size=2>Span<font></b></td>\n";
    IsoguideEqHeader += "  </tr>\n";
    IsoguideEqHeader += "  <tr>\n";
    IsoguideEqHeader += "    <td><hr></td>\n";
    IsoguideEqHeader += "   <td><hr></td>\n";
    IsoguideEqHeader += "   <td><hr></td>\n";
    IsoguideEqHeader += "   <td><hr></td>\n";
    IsoguideEqHeader += "   <td><hr></td>\n";
    IsoguideEqHeader += "  </tr>\n";



    IsoguideEqData = "";
    for(R=0; R < Isoguide.equipmenttag.length; R++) {
        if(Isoguide.equipmenttag(R).value != "") {
            IsoguideEqData += "  <tr>\n";
            theType = new String();
            theType = Isoguide.equipmenttype(R).value;
            theType = theType.slice(0,40);
            IsoguideEqData += "  <td><font size=2>" + Isoguide.equipmenttag(R).value + "</font></td>\n";
            IsoguideEqData += "  <td><font size=2>" + theType + "</font></td>\n";
            IsoguideEqData += "  <td><font size=2>" + Isoguide.hidequipmenthp(R).value + "</font></td>\n";
            IsoguideEqData += "  <td><font size=2>" + Isoguide.hidequipmentbase(R).value +  " \/ " + Isoguide.hidequipmentisolatortype(R).value + "</font></td>\n";
            IsoguideEqData += "  <td><font size=2>" + Isoguide.hidequipmentnotes(R).value + "</font></td>\n";
            IsoguideEqData += "  </tr>\n";
            IsoguideEqData += "  <tr>\n";
            IsoguideEqData += "  <td>&nbsp;</td>\n";
            IsoguideEqData += "  <td><font size=2>" + Isoguide.equipmentcategory(R).value + "</font></td>\n";
            IsoguideEqData += "  <td><font size=2>" + Isoguide.hidequipmentrpm(R).value + "</font></td>\n";
            IsoguideEqData += "  <td><font size=2>" + Isoguide.hidequipmentdefl(R).value + "</font></td>\n";
			var spanVerbage = new String();
			spanVerbage = "ON GRADE";
			if(Isoguide.hidequipmentspan(R).value != "ON GRADE"){
				spanVerbage = Isoguide.hidequipmentspan(R).value;
				spanVerbage = spanVerbage.charAt(0);
				if(Isoguide.MetricSystem.checked == true){
					if(spanVerbage == "U"){
						spanVerbage = "UP TO 6.1 m";
					}

					else if(spanVerbage == "2"){
						spanVerbage = "6.1- 9.1 m";
					}
					else if(spanVerbage == "3"){
						spanVerbage = "9.1- 12.2 m";
					}
				}
				else{
					if(spanVerbage == "U"){
						spanVerbage = "Up to 20 FT.";
					}

					else if(spanVerbage == "2"){
						spanVerbage = "20- 30 FT.";
					}
					else if(spanVerbage == "3"){
						spanVerbage = "30 - 40 FT.";
					}
				}

			}
//            IsoguideEqData += "  <td><font size=2>" + Isoguide.hidequipmentspan(R).value + "</font></td>\n";
			IsoguideEqData += "  <td><font size=2>" + spanVerbage + "</font></td>\n";
            IsoguideEqData += "  </tr>\n";
        }
        else {
            break;
        }
    }
    IsoguideEqData += "</table>\n";
    Lines = IsoguideEqHeader + IsoguideEqData;
    return(Lines);
}

function IsoguideEquipmentExplaination() {
    IsoguideEquipmentExplain = "<hr>\n";
    IsoguideEquipmentExplain +="<table width=\"100%\" border=\"0\">\n";
    IsoguideEquipmentExplain +="  <tr>\n";
    IsoguideEquipmentExplain +="   <td><b>Base Types:</b></td>\n";
    IsoguideEquipmentExplain +="   <td><b>Isolator Types:</b></td>\n";
    IsoguideEquipmentExplain +="  </tr>\n";
    IsoguideEquipmentExplain +="  <tr>\n";
    IsoguideEquipmentExplain +="   <td>A. No base, isolators attached directly to equipment (Note17)</td>\n";
    IsoguideEquipmentExplain +="   <td>1. Pad, rubber, or glass fiber (Notes 20 and 21)</td>\n";
    IsoguideEquipmentExplain +="  </tr>\n";
    IsoguideEquipmentExplain +="  <tr>\n";
    IsoguideEquipmentExplain +="   <td>B. Structural steel rails or base (Note 28 and 29)</td>\n";
    IsoguideEquipmentExplain +="   <td>2. Rubber floor isolator or hanger (Notes 20 and 25)</td>\n";
    IsoguideEquipmentExplain +="  </tr>\n";
    IsoguideEquipmentExplain +="  <tr>\n";
    IsoguideEquipmentExplain +="   <td>C. Concrete inertia base (Note 30)</td>\n";
    IsoguideEquipmentExplain +="   <td>3. Spring floor isolator or hanger (Notes 22, 23, and 25)</td>\n";
    IsoguideEquipmentExplain +="  </tr>\n";
    IsoguideEquipmentExplain +="  <tr>\n";
    IsoguideEquipmentExplain +="   <td>D. Curb-mounted base (Note 31)</td>\n";
    IsoguideEquipmentExplain +="   <td>4. Restained spring isolator (Nots 22 and 24)</td>\n";
    IsoguideEquipmentExplain +="  </tr>\n";
    IsoguideEquipmentExplain +="  <tr>\n";
    IsoguideEquipmentExplain +="   <td>&nbsp;</td>\n";
    IsoguideEquipmentExplain +="   <td>5. Thrust restraint (Notes 26)</td>\n";
    IsoguideEquipmentExplain +="  </tr>\n";
    IsoguideEquipmentExplain +="  <tr>\n";
    IsoguideEquipmentExplain +="   <td>* See Attachment for notes and specifications</td>\n";
    IsoguideEquipmentExplain +="   <td>&nbsp;</td>\n";
    IsoguideEquipmentExplain +="  </tr>\n";
    IsoguideEquipmentExplain +="</table>\n";
    return(IsoguideEquipmentExplain);
}    
    
function IsoguideEndHtml() {
    IsoguideEnd = "</body>\n";
    IsoguideEnd += "</html>\n";
    return(IsoguideEnd);
}

function IsoguideReport() {
    NoteParser();
// Equipment Report    
    if(Isoguide.chkEquipmentReport.checked == true) {
        IsoguideDocHeader = IsoguideHeader("IsoGuide Equipment Report", "Equipment");
        IsoguideDocHeader += IsoguideEquipHeader();
        IsoguideDocHeader += IsoguideJobInfo();
        IsoguideDocHeader += IsoguideEqDataRows();
        IsoguideDocHeader += IsoguideEquipmentExplaination();
        IsoguideDocHeader += IsoguideEndHtml();
        theReport = IsoguideDocHeader;
        OpenBrowser(theReport, "Equip");
    }
// Notes Report    
    atitle = "IsoGuide Equipment Notes Report";
    theNotesRows = StartOfPage(atitle);
    theNotesRows = IsoguideHeader(atitle, "Equipment Notes");
    theNotesRows += "</table>\n";
    theNotesRows += "<br>";
    theNotesRows += WriteTheNotes();
    theNotesRows += IsoguideEndHtml();
    theReport = theNotesRows;

    OpenBrowser(theReport, "Notes");

// Spec Report
    if(Isoguide.Spec(0).checked == false) {
        SpecType = "Short Specifacation";
        atitle = "IsoGuide Equipment Spec Report";
        SpecNotes = StartOfPage(atitle);
        SpecNotes += "<table width=\"100%\" border=\"0\">\n";
        SpecNotes += FirstLineOfHeader("Spec");
        if(Isoguide.Spec(2).checked == true) {
            SpecType = "Long Specifacation";
        }
        SpecNotes += SecondLineOfSpec(SpecType)
        SpecNotes += "</table>\n";
        SpecNotes += IsoguideSpec();
        theReport = SpecNotes;
		OpenBrowser(theReport, "Spec");
    }
    

    
}

function OpenBrowser(theHtml, WindowName) {
    newWindow = window.open("", WindowName, "status,scrollbars,resizable,menubar,toolbar,height=430,width=790,top=0,left=0");
    if(!newWindow.opener) {
        newWindow.opener = window;
    }
    newWindow.document.write(theHtml);
    newWindow.focus();
    newWindow.document.close();
}

function NoteParser() {
    var theNotes = new String();
	var theIsolatorType = new String();
	var theEquipmentBase = new String();
    var anArrayOfNotes;
    var anArrayOfIsolatorType;
    var anArrayOfEquipmentBase;
    for(R=0; R < Isoguide.equipmenttag.length; R++) {
        if(Isoguide.equipmenttag(R).value == "") break;
        if(theNotes != "") theNotes += ",";
        if(theIsolatorType != "") theIsolatorType += ",";
        if(theEquipmentBase != "") theEquipmentBase += ",";

		theNotes += Isoguide.hidequipmentnotes(R).value;
		theIsolatorType += Isoguide.hidequipmentisolatortype(R).value;
		theEquipmentBase += Isoguide.hidequipmentbase(R).value;
    }
	
    anArrayOfNotes = theNotes.split(",");
    anArrayOfIsolatorType = theIsolatorType.split(",");
    anArrayOfEquipmentBase = theEquipmentBase.split(",");
// NoteOnceBasetypes = new Array();
// NoteOnceIsolatorTypess = new Array();

	msg = "";
    anArrayOfNotes.sort();
    NoteOnceArray.length = 0;
    NoteOnceArray[0] = anArrayOfNotes[0];
    if(anArrayOfNotes.length > 1) {
        for(X=1; X < anArrayOfNotes.length; X++) {
			if(anArrayOfNotes[X] != anArrayOfNotes[X - 1]) {
                NoteOnceArray[NoteOnceArray.length] = anArrayOfNotes[X];
            }
        }
    }
//////////////////
    anArrayOfIsolatorType.sort();
    NoteOnceIsolatorTypes.length = 0;
    NoteOnceIsolatorTypes[0] = anArrayOfIsolatorType[0];
    if(anArrayOfIsolatorType.length > 1) {
        for(X=1; X < anArrayOfIsolatorType.length; X++) {
			if(anArrayOfIsolatorType[X] != anArrayOfIsolatorType[X - 1]) {
                NoteOnceIsolatorTypes[NoteOnceIsolatorTypes.length] = anArrayOfIsolatorType[X];
            }
        }
    }
//////////////////////////////
    anArrayOfEquipmentBase.sort();
    NoteOnceBasetypes.length = 0;
    NoteOnceBasetypes[0] = anArrayOfEquipmentBase[0];
    if(anArrayOfEquipmentBase.length > 1) {
        for(X=1; X < anArrayOfEquipmentBase.length; X++) {
			if(anArrayOfEquipmentBase[X] != anArrayOfEquipmentBase[X - 1]) {
                NoteOnceBasetypes[NoteOnceBasetypes.length] = anArrayOfEquipmentBase[X];
            }
        }
    }
/////////////////////////////////////
	for(L =0; L < NoteOnceIsolatorTypes.length; L++){
		if(NoteOnceIsolatorTypes[L] == "1"){
			NoteOnceArray[NoteOnceArray.length] = "20";
			NoteOnceArray[NoteOnceArray.length] = "21";
		}
		else if(NoteOnceIsolatorTypes[L] == "2"){
			NoteOnceArray[NoteOnceArray.length] = "20";
			NoteOnceArray[NoteOnceArray.length] = "25";
		}
		else if(NoteOnceIsolatorTypes[L] == "3"){
			NoteOnceArray[NoteOnceArray.length] = "22";
			NoteOnceArray[NoteOnceArray.length] = "23";
			NoteOnceArray[NoteOnceArray.length] = "25";
		}
		else if(NoteOnceIsolatorTypes[L] == "4"){
			NoteOnceArray[NoteOnceArray.length] = "22";
			NoteOnceArray[NoteOnceArray.length] = "24";
		}
		else if(NoteOnceIsolatorTypes[L] == "5"){
			NoteOnceArray[NoteOnceArray.length] = "26";
		}

	}

	for(L =0; L < NoteOnceBasetypes.length; L++){
		if(NoteOnceBasetypes[L] == "A"){
			NoteOnceArray[NoteOnceArray.length] = "17";
		}
		else if(NoteOnceBasetypes[L] == "B"){
			NoteOnceArray[NoteOnceArray.length] = "28";
			NoteOnceArray[NoteOnceArray.length] = "29";
		}
		else if(NoteOnceBasetypes[L] == "C"){
			NoteOnceArray[NoteOnceArray.length] = "30";
		}
		else if(NoteOnceBasetypes[L] == "D"){
			NoteOnceArray[NoteOnceArray.length] = "31";
		}
	}
	if(Isoguide.chkPipingReport.checked == true){
		NoteOnceArray[NoteOnceArray.length] = "PI";
	}
	NoteOnceArray.sort();
	
}

function WriteTheNotes(){
    NR = "<table width=\"100%\" border=0>";
    NR += NotesRows();
    NR += "</table>"
    return(NR);
}

function NotesRows() {
    var LastNoteNumber = "";
    var RightNote;
    if(Isoguide.MetricSystem.checked == true){
        RightNote = NotesMetricText;
    }
    else {
        RightNote = NotesEnglishText;
    }
    
    IsoguideEquipmentNotes = "";
    for(L=0; L < NoteOnceArray.length; L++) {
        for(F=0; F < NotesNoteNumber.length; F++) {
            theNote = NotesNoteNumber[F];
			theNote = theNote.slice(0,2);
            if(theNote == NoteOnceArray[L]) {
                IsoguideEquipmentNotes += "<tr>\n";
                IsoguideEquipmentNotes += "  <td valign = \"top\" width = \"5%\">\n";
                if(theNote != LastNoteNumber) {
                    IsoguideEquipmentNotes += theNote + "\n";  
                }
                IsoguideEquipmentNotes += "  </td>\n";
                IsoguideEquipmentNotes += "  <td width = \"95%\">\n";
                IsoguideEquipmentNotes += "   " + RightNote[F];
                IsoguideEquipmentNotes += "  </td>\n";
                IsoguideEquipmentNotes += "</tr>\n";
                LastNoteNumber = theNote;
            }
        }
    }
    return(IsoguideEquipmentNotes);

}

function IsoguideSpec(){
    var theNote = new String();
    var WhatSpec = "ISS";
    var SpecNotesArray = new Array();
    if(Isoguide.Spec(2).checked == true) {
        WhatSpec = "ILS";
    }
    if(Isoguide.MetricSystem.checked == false) {
        SpecNotesArray = NotesEnglishText;
    }
    else {
        SpecNotesArray = NotesMetricText;
    }
    
    SpecRows = "<table width = \"100%\">";
    for(SP=0; SP < NotesNoteNumber.length; SP++) {
        theNote = NotesNoteNumber[SP];
        theNote = theNote.slice(0,3);
        if(WhatSpec == theNote) {
            SpecRows += "   <tr>";
            SpecRows += "      <td>";
            SpecRows += "           " + SpecNotesArray[SP];
            SpecRows += "      </td>";
            SpecRows += "      </tr>";
            
        }
    }
    SpecRows += "</table>";
    return(SpecRows);
}
