var retval = null

function test_showFields()
{
	//var myBody = document.getElementsByTagName("body")[0]
	//var myBodyElements = myBody.getElementsByTagName("p");
	//var myP = myBodyElements[1];
	//var myTextNode = document.createTextNode("world");
	//myP.appendChild(myTextNode);

	//var myBodyTables = myBody.getElementsByTagName("table");
	//var myTable
	//mytable     = mybody.getElementsByTagName("table")[0];

	//foreach (myTable in myBodyTables)
	//	alert(myTable.getAttribute("border"));
	
	//var lenTable = myBodyTables.length;
	//var sSum = new String("")

	//for(j=0; j<lenTable; j++)
	//{
	//	myTable = myBodyTables[j];
	//	sSum = myTable.getAttribute("summary");
	//	if (sSum == "QuoteGrid")
	//	{
	//		//alert(sSum);
	//		appendTableValues(myTable);
	//	}
	//}
	if (document.forms.length > 0) {
		for(i=0; i<document.forms[0].elements.length; i++) {
			if (document.forms[0].elements[i].type != "text" && document.forms[0].elements[i].type != "textarea" && document.forms[0].elements[i].type != "hidden" && document.forms[0].elements[i].type != "select-one" && document.forms[0].elements[i].type != "button")
				alert(document.forms[0].elements[i].type);
			if (document.forms[0].elements[i].type == "select-one")
			{
				alert(document.forms[0].elements[i].name);
				alert(document.forms[0].elements[i].id);
			}
		}
	}
}
// Search Job Popup
function CancelJobSearchPage() {
//	alert("Cancel");
//	test_showFields();
	window.returnValue=0;
	window.close();
	return true;
}

function SaveJobSearchPage() {
	if (document.getElementById("lstJobs").value == "") {
		alert("Job must be specified.");
		return false;
	} else {
		//alert(document.frmJobSearch.lstJobs.options[document.frmJobSearch.lstJobs.selectedIndex].text);
		alert(document.getElementById("lstJobs").value);
		window.returnValue=document.getElementById("lstJobs").value;
		window.close();
		return true;
	}
	return true;
}

function SearchJob() {
		//retval = window.open("/Employee/AdminJobSearch.aspx?Criteria=", "", "width=600px,height=200px");
		retval = window.showModalDialog("/Employee/AdminJobSearch.aspx?Criteria=", "", "width=600px,height=200px");
		alert(retval);
		if (retval == null) {
			//Canceled - x close button used
		} else if (retval > 0) {
			document.getElementById("txtJobSearch").value = retval;
		} else {
			//Canceled
		}


//		retval = window.showModalDialog("/Employee/AdminJobSearch.aspx?Criteria=", "", "dialogHeight:15;dialogWidth=40");
// + document.getElementById("txtJobSearch").value
//showModalDialog
//		if (retval == null) {
//			//Canceled - x close button used
//			if (document.getElementById(sCheck).checked == true) {
//				document.getElementById(sCheck).checked = false;
//			} else {
//				document.getElementById(sCheck).checked = true;
//			}
//		} else if (retval.QuoteID != 0) {
//			document.getElementById("txtHoldQuoteID").value = retval.QuoteID;
//			document.getElementById("txtHoldEmployeeID").value = retval.EmployeeID;
//			document.getElementById("txtHoldContractorID").value = retval.ContractorID;
//			frmQuote.submit();
//		} else {
//			//Canceled
//			if (document.getElementById(sCheck).checked == true) {
//				document.getElementById(sCheck).checked = false;
//			} else {
//				document.getElementById(sCheck).checked = true;
//			}
//		}
//	}
//
}



function ViewPostponedDates(iJobID) {
	retval = window.showModalDialog("/Employee/ViewPostponedDates.aspx?JobID=" + iJobID, "", "dialogHeight:20;dialogWidth=30");
	return false;
}
function appendTableValues(mytable) {
        // get the reference for the body
        //var mybody = document.getElementsByTagName("body")[0];

        // creates &lt;table&gt; and &lt;tbody&gt; elements
        //mytable     = document.createElement("table");
        //mytablebody = document.createElement("tbody");
		mytablebody = mytable.getElementsByTagName("tbody")[0];

		// remove existing rows		
		while( mytablebody.hasChildNodes() ) { mytablebody.removeChild( mytablebody.lastChild ); }
	
		
        // creating new cells
        var strI = new String("0")
        var strJ = new String("0")
        var strHTML = new String("")
        for(var j = 0; j < 2; j++) {
            // creates a &lt;tr&gt; element
            mycurrent_row = document.createElement("tr");

            for(var i = 0; i < 2; i++) {
                // creates a &lt;td&gt; element
                mycurrent_cell = document.createElement("td");
                // creates a Text Node
                //currenttext = document.createTextNode("cell is row " + j + ", column " + i);
                strI = i;
                strJ = j;
                strHTML = "<input name=\"txtGrid" + strJ + strI + "\" type=\"text\" maxlength=\"60\" id=\"txtGrid" + strJ + strI + "\" onkeypress=\"return noenter()\" style=\"width:150px;\" />";
				//alert(strHTML);
				strHTML = "Fill Grid cell: " + strJ + ", " + strI;
                currenttext = document.createTextNode(strHTML);
                // appends the Text Node we created into the cell &lt;td&gt;
                mycurrent_cell.appendChild(currenttext);
                // appends the cell &lt;td&gt; into the row &lt;tr&gt;
                mycurrent_row.appendChild(mycurrent_cell);
            }
            // appends the row &lt;tr&gt; into &lt;tbody&gt;
            mytablebody.appendChild(mycurrent_row);
        }

        // appends &lt;tbody&gt; into &lt;table&gt;
        mytable.appendChild(mytablebody);
        // appends &lt;table&gt; into &lt;body&gt;
        //mybody.appendChild(mytable);
        // sets the border attribute of mytable to 2;
        mytable.setAttribute("border","2");
    }

function getGridTable()
// This function returns the Grid table from the form
{
	var rtn = null;  // Return value - NULL if not found
	var myBody = document.getElementsByTagName("body")[0];    // The pages body
	var myBodyTables = myBody.getElementsByTagName("table");  // All the tables on the page
	var myTable								// Holds the individual tables.
	var lenTable = myBodyTables.length;		// The number of tables in the collection
	var sSum = new String("")				// For storing the Summary tag from the table
	for(j=0; j<lenTable; j++)
	{
		myTable = myBodyTables[j];
		sSum = myTable.getAttribute("summary");
		if (sSum == "QuoteGrid")
		{
			// Found the right table
			rtn = myTable;
			break;
		}
	}
	return rtn;
}

function editGrid()
{
	var myTable = getGridTable();
	var strQuery = new String("");		// Holds the query string for the EditGrid page

	// Get all the rows in the table
	myRows = mytablebody.getElementsByTagName("tr");
	for (i=0;i<myRows.length;i++)
	{
		//loop through the rows
		myRow = myRows[i];
		myCells = myRow.getElementsByTagName("td");
		for (j=0;j<myCells.length;j++)
		{
			//loop through the cells in the row
			myCell = myCells[j];
			myceltext=myCell.childNodes[0];
			//alert(myceltext.data);
			strQuery = strQuery + "&g0" + i + "0" + j + "=" + myceltext.data;
		}
	}

	// first item element of the childNodes list of mycel
	//myceltext=mycel.childNodes[0];

	//alert(myceltext.data);
	// content of currenttext is the data content of myceltext
	//currenttext=document.createTextNode(myceltext.data);
	//mybody.appendChild(currenttext);
	
	// Call the Edit Grid popup
	retval = window.showModalDialog("/Employee/EditGrid.aspx?JobID=2" + strQuery, "dialogHeight:15;dialogWidth=30");

}
function GetQuoteScreenValues() 
{
	this.QuoteTitle = "Quote Title";
	this.Notes = "Notes";
	this.ItemHeader = "Header";
	this.QuoteBody = "";
	this.GridValues = "";
	return this;
}
function HBPrintPreview(DesignMode, BaseURL, BaseHTML)
{
	var sQuote = new String("");

	// Header
	sQuote = '<TABLE width="100%" border=0 valign=top>\n\r';

	// H&B Logo
	sQuote = sQuote + '<TR><TD valign=top width="50%"><IMG border=0 src="/images/QuoteLogo.gif" height="96" width="300" alt="H&B Products"></TD>';
	sQuote = sQuote + '<TD rowspan=2 width="10%">&nbsp;</TD>';
	// Grid
	sQuote = sQuote + '<TD rowspan=2 valign=top align=left width="40%">' + document.getElementById("ftbGridValues").value + '</TD>';
	sQuote = sQuote + '</TR>\n\r';
	// Header Info
	sQuote = sQuote + '<TR><TD valign="top">\n\r';

	sQuote = sQuote + '<TABLE width="100%">';
	sQuote = sQuote + '<TR>';
	sQuote = sQuote + '<TD colspan=2>&nbsp;</TD>';
	sQuote = sQuote + '</TR>\n\r';

	// Project (JobName)
	sQuote = sQuote + '<TR>';
	sQuote = sQuote + '<TD width="10%" valign=top class="QuoteHeaderLabel">PROJECT:&nbsp;</TD>';
	sQuote = sQuote + '<TD width="90%" class="QuoteHeader"><B>' + document.getElementById("txtJobName").value + '</B>';
	sQuote = sQuote + '</TD>';
	sQuote = sQuote + '</TR>\n\r';

	// Location
	var sLocation = document.getElementById("txtLocation").value;
	if (sLocation != "") {
		sQuote = sQuote + '<TR>';
		sQuote = sQuote + '    <TD width="10%" valign=top class="QuoteHeaderLabel">LOCATION:&nbsp;</TD>';
		sQuote = sQuote + '    <TD width="90%" class="QuoteHeader">' + sLocation + '</TD>';
		sQuote = sQuote + '</TR>\n\r';
	}
	
	// Notes
	var sNotes = document.getElementById("txtNotes").value;
	if (sNotes != "") {
		sQuote = sQuote + '<TR>';
		sQuote = sQuote + '    <TD width="10%" valign=top class="QuoteHeaderLabel">NOTES:&nbsp;</TD>';
		sQuote = sQuote + '    <TD width="90%" class="QuoteHeader">' + sNotes + '</TD>';
		sQuote = sQuote + '</TR>\n\r';
	}

	// Architect Name
	var sArchitectName = document.getElementById("txtArchitectName").value;
	if (sArchitectName != "") {
		sQuote = sQuote + '<TR>';
		sQuote = sQuote + '    <TD width="10%" valign=top class="QuoteHeaderLabel">ARCHITECT:&nbsp;</TD>';
		sQuote = sQuote + '    <TD width="90%" class="QuoteHeader">' + sArchitectName + '</TD>';
		sQuote = sQuote + '</TR>\n\r';
	}

	// Engineer Name
	var sEngineerName = document.getElementById("txtEngineerName").value;
	if (sEngineerName != "") {
		sQuote = sQuote + '<TR>';
		sQuote = sQuote + '    <TD width="10%" valign=top class="QuoteHeaderLabel">ENGINEER:&nbsp;</TD>';
		sQuote = sQuote + '    <TD width="90%" class="QuoteHeader">' + sEngineerName + '</TD>';
		sQuote = sQuote + '</TR>\n\r';
	}

	// Bid Date
	sQuote = sQuote + '<TR>';
	sQuote = sQuote + '<TD width="10%" valign=top class="QuoteHeaderLabel">BID DATE:&nbsp;</TD>';
	sQuote = sQuote + '<TD width="90%" class="QuoteHeader">' + document.getElementById("txtBidDate").value + '</TD>';
	sQuote = sQuote + '</TR>\n\r';

	// DrawingDate
	var sDrawingDate = document.getElementById("txtDrawingDate").value;
	if (sDrawingDate != "") {
		sQuote = sQuote + '<TR>';
		sQuote = sQuote + '    <TD width="10%" valign=top class="QuoteHeaderLabel">D DATE:&nbsp;</TD>';
		sQuote = sQuote + '    <TD width="90%" class="QuoteHeader">' + sDrawingDate + '</TD>';
		sQuote = sQuote + '</TR>\n\r';
	}
		
	// Quote Number
	var sQuoteNumber = document.getElementById("txtQuoteNumber").value;
	if (sQuoteNumber != "") {
		sQuote = sQuote + '<TR>';
		sQuote = sQuote + '    <TD width="10%" valign=top class="QuoteHeaderLabel">QUOTE&nbsp;#:&nbsp;</TD>';
		sQuote = sQuote + '    <TD width="90%" class="QuoteHeader">' + sQuoteNumber + '</TD>';
		sQuote = sQuote + '</TR>\n\r';
	}
		
	// Quoted By
	var sQuotedBy = document.getElementById("txtQuotedBy").value;
	if (sQuotedBy != "") {
		sQuote = sQuote + '<TR>';
		sQuote = sQuote + '    <TD width="10%" valign=top class="QuoteHeaderLabel">SALESMAN:&nbsp;</TD>';
		sQuote = sQuote + '    <TD width="90%" class="QuoteHeader">' + sQuotedBy;
		// Contractor TakeOff (Takeoff)
		var sTakeOff = document.getElementById("txtTakeOff").value;
		if (sTakeOff == "True")
		{
			sQuote = sQuote + '<BR>Contractor Take Off&nbsp;';
		}
		sQuote = sQuote + '</TD></TR>\n\r';
	}
	else {
		// Contractor TakeOff (Takeoff)
		var sTakeOff = document.getElementById("txtTakeOff").value;
		if (sTakeOff == "True")
		{
		sQuote = sQuote + '<TR>';
		sQuote = sQuote + '    <TD width="10%" valign=top class="QuoteHeaderLabel">&nbsp;</TD>';
		sQuote = sQuote + '    <TD width="90%" class="QuoteHeader">Contractor Take Off&nbsp;';
		sQuote = sQuote + '</TD></TR>\n\r';
		}
	}
		
	sQuote = sQuote + '</TABLE>';
	
	sQuote = sQuote + '</TD></TR>';
	sQuote = sQuote + '</TABLE>';


    sQuote = sQuote + '<BR>';
    sQuote = sQuote + '<TABLE width="100%" valign=top>'
    sQuote = sQuote + '<TR><TD valign=top>';

	sQuote = sQuote + BaseHTML.replace(/~ PAGE BREAK ~/g, '&nbsp;');

	sQuote = sQuote + '</TD></TR>';
	sQuote = sQuote + '</TABLE>';

	printWindow = window.open('','','toolbars=no,scrollbars=yes,resizable=yes,menubar=yes,width=950,height=550,left=0,top=0');
	printWindow.document.open();
	printWindow.document.write("<html><head><link rel='stylesheet' href='" + DesignMode + "' type='text/css' />" + ((BaseURL != '') ? "<base href='" + BaseURL + "' />" : "") + "</head><body>" + sQuote + "</body></html>");
	printWindow.document.close();	
	
	//FTB_API["ftbQuoteBody"].Focus();
}

function InsertText(textToInsert) 
{
		FTB_API["ftbQuoteBody"].InsertHtml(textToInsert);
		//document.getElementById("ftbQuoteBody").InserHtml("TEST");
	return false;
	//FTB_API['control_body'].InsertHtml(textToInsert);
}
// Quote Edit Fill Grid
function FillGrid() {
	retval = window.showModalDialog("/Employee/FillGrid.aspx?JobID=" + document.getElementById("lstJobs").value, "", "dialogHeight:15;dialogWidth=30");
	//retval = window.open("/Employee/FillGrid.aspx?JobID=" + document.getElementById("lstJobs").value, "", "dialogHeight:15;dialogWidth=30");
	if (retval == null) {
		//Canceled
	} else if (retval.CancelPressed) {
		//Canceled
	} else {
		FTB_API["ftbGridValues"].SetHtml("");
		FTB_API["ftbGridValues"].InsertHtml(FormatGrid(retval.GridArray));
		FTB_API["ftbQuoteBody"].Focus();
	}
}

function FormatGrid(sGrid) {
	var sTable = new String("");
	var sFontStart = new String("<FONT size=1>");
	var sFontEnd = new String("</FONT>");
	var aAll = new Array();
	var aSheet = new Array();
	var aFan = new Array();
	var ctrAll = 0;
	var ctrSheet = 0;
	var ctrFan = 0;
	var ctr = 0;
	
	while (sGrid.length > 1) {
		switch (sGrid.charAt(1)) {
		case "A":
			aAll[ctrAll] = sGrid.substring(2, sGrid.indexOf("|", 2));
			ctrAll = ctrAll + 1;
			sGrid = sGrid.substring(sGrid.indexOf("|", 2));
			break
		case "S":
			aSheet[ctrSheet] = sGrid.substring(2, sGrid.indexOf("|", 2));
			ctrSheet = ctrSheet + 1;
			sGrid = sGrid.substring(sGrid.indexOf("|", 2));
			break
		case "F":
			aFan[ctrFan] = sGrid.substring(2, sGrid.indexOf("|", 2));
			ctrFan = ctrFan + 1;
			sGrid = sGrid.substring(sGrid.indexOf("|", 2));
			break
		}
	}
	sTable = "<TABLE border=1><TR><TD align=center><B>Sheet</B></TD><TD align=center><B>Fan</B></TD><TD align=center><B>All</B></TD></TR>"
	while (ctr < ctrAll || ctr < ctrSheet || ctr < ctrFan || ctr < 8) {
		sTable = sTable + "<TR>"
		if (ctr < ctrSheet)
			sTable = sTable + "<TD valign=top>" + sFontStart + aSheet[ctr] + sFontEnd + "</TD>";
		else
			sTable = sTable + "<TD width='125' valign=top>&nbsp;</TD>";
		
		if (ctr < ctrFan)
			sTable = sTable + "<TD valign=top>" + sFontStart + aFan[ctr] + sFontEnd + "</TD>";
		else
			sTable = sTable + "<TD width='125' valign=top>&nbsp;</TD>";

		if (ctr < ctrAll)
			sTable = sTable + "<TD valign=top>" + sFontStart + aAll[ctr] + sFontEnd + "</TD>";
		else
			sTable = sTable + "<TD width='125' valign=top>&nbsp;</TD>";
			
		sTable = sTable + "</TR>"
		ctr = ctr + 1;
	}
	
	sTable = sTable + "</TABLE>"
	return sTable
}

// Fill Grid functions
function SaveFillGrid() {
	var sHoldValues = new String("")
	if (document.getElementById("chkAll").checked == true) {
		sHoldValues = gridFanValues + gridSheetValues.substring(1) + gridValues.substring(1)
		window.returnValue=new FillGridData(sHoldValues, false)
	} else if (document.getElementById("chkFan").checked == true) {
		sHoldValues = gridFanValues + gridValues.substring(1)
		window.returnValue=new FillGridData(sHoldValues, false)
	} else if (document.getElementById("chkSheet").checked == true) {
		sHoldValues = gridSheetValues + gridValues.substring(1)
		window.returnValue=new FillGridData(sHoldValues, false)
	} else {
			return false;
		}

	window.close()
	return true;
}

function CancelFillGrid() {
	window.returnValue=new FillGridData(gridCancelValues, true);
	window.close();
	return true;
}

function FillGridData(gridArray, bCancelPressed) {
	//This first item of the array [0] is blank - ignore it
	this.GridArray = gridArray
	this.CancelPressed = bCancelPressed
	return this
}


// Job Checkout functions
function CancelJobCheckoutPage() {
	window.returnValue=new CheckoutData(0, 0, 0);
	window.close();
	return true;
}

function SaveJobCheckoutPage() {
	if (document.getElementById("lstEmployee").value == "") {
		alert("Employee must be specified.");
		return false;
	} else if (document.getElementById("lstContractor").value == "") {
		alert("Contractor must be specified.");
		return false;
	} else {
		window.returnValue=new CheckoutData(document.getElementById("txtID").value, document.getElementById("lstEmployee").value, document.getElementById("lstContractor").value)
		window.close();
		return true;
	}
	return true;
}

function OKJobCheckoutPage() {
	window.returnValue=new CheckoutData(document.getElementById("txtID").value, 0, 0)
	window.close();
	return true;
}

function CheckoutData(QuoteID, EmpID, ContID) {
	this.QuoteID = QuoteID
	this.EmployeeID = EmpID
	this.ContractorID = ContID
	return this
}

// Job Folder Checkout
function JobFolderCheckoutClick(iID, iDefaultSalesID) {
	var sCheck = new String("chkCheckout" + iID)
	var sSales = new String("lstSales" + iID)
	var sContractor = new String("lstContractor" + iID)
	var sIsChecked = new String("")
	var sID = new String(iID)

	if (document.getElementById(sCheck) == null) {
		//alert("Null Checkbox.");
	}
	else {
		if (document.getElementById(sCheck).checked == true) {
			sIsChecked = "Y";
		}
		else {
			sIsChecked = "N";
		}
		retval = window.showModalDialog("/Employee/AdminJobCheckout.aspx?ID=" + sID + "&CHK=" + sIsChecked, "", "dialogHeight:15;dialogWidth=30");
		if (retval == null) {
			//Canceled - x close button used
			if (document.getElementById(sCheck).checked == true) {
				document.getElementById(sCheck).checked = false;
			} else {
				document.getElementById(sCheck).checked = true;
			}
		} else if (retval.QuoteID != 0) {
			document.getElementById("txtHoldQuoteID").value = retval.QuoteID;
			document.getElementById("txtHoldEmployeeID").value = retval.EmployeeID;
			document.getElementById("txtHoldContractorID").value = retval.ContractorID;
			frmQuote.submit();
		} else {
			//Canceled
			if (document.getElementById(sCheck).checked == true) {
				document.getElementById(sCheck).checked = false;
			} else {
				document.getElementById(sCheck).checked = true;
			}
		}
	}

}

// Awarded To functions
function CancelAwardedToPage() {
	window.returnValue=new AwardedToData(0, 0);
	window.close();
	return true;
}

function SaveAwardedToPage() {
	if (document.getElementById("lstContractor").value == "") {
		alert("Contractor must be specified.");
		return false;
	} else {
		window.returnValue=new AwardedToData(document.getElementById("txtID").value, document.getElementById("lstContractor").value)
		window.close();
		return true;
	}
	return true;
}

function OKAwardedToPage() {
	window.returnValue=new AwardedToData(document.getElementById("txtID").value, 0, 0)
	window.close();
	return true;
}

function AwardedToData(QuoteID, ContID) {
	this.QuoteID = QuoteID
	this.ContractorID = ContID
	return this
}

// Awarded To Checkout
function AwardedToClick(iID) {
	var sCheck = new String("chkAwarded" + iID)
	var sContractor = new String("lstContractor" + iID)
	var sIsChecked = new String("")
	var sID = new String(iID)

	if (document.getElementById(sCheck) == null) {
		//alert("Null Checkbox.");
	}
	else {
		if (document.getElementById(sCheck).checked == true) {
			sIsChecked = "Y";
		}
		else {
			sIsChecked = "N";
		}
		retval = window.showModalDialog("/Employee/AdminAwardedTo.aspx?ID=" + sID + "&CHK=" + sIsChecked, "", "dialogHeight:15;dialogWidth=40");
		if (retval == null) {
			//Canceled - x close button used
			if (document.getElementById(sCheck).checked == true) {
				document.getElementById(sCheck).checked = false;
			} else {
				document.getElementById(sCheck).checked = true;
			}
		} else if (retval.QuoteID != 0) {
			//alert (retval.QuoteID);
			document.getElementById("txtHoldAwardedToQuoteID").value = retval.QuoteID;
			document.getElementById("txtHoldAwardedToContractorID").value = retval.ContractorID;
			frmQuote.submit();
		} else {
			//Canceled
			if (document.getElementById(sCheck).checked == true) {
				document.getElementById(sCheck).checked = false;
			} else {
				document.getElementById(sCheck).checked = true;
			}
		}
	}

}


// Check that a template has been selected
function CheckTemplate() {
	if (document.getElementById("lstTemplates").value == "") {
		alert("Template must be specified when adding a quote.");
		return false;
	} else {
		return true;
	}
}

// For Printing page breaks - finds the top of the image on the page
function findTop(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curtop += obj.offsetTop
		}
	}
	return curtop;
}


// Template Rename and Move Up & Down 
	function TemplateRename(iID, sName) {
		var sTemplate = new String()
		var sNewNameTag = new String("NewName" + iID)
		
		sTemplate = window.prompt('Enter new template name.',sName);
		if (sTemplate != null) {
			sTemplate = sTrim(sTemplate);
			if (sTemplate != '') {
				alert(document.getElementById(sNewNameTag).value);
				document.getElementById(sNewNameTag).value = sTemplate;
				alert(document.getElementById(sNewNameTag).value);
				//frmTemplate.submit();
			}
		}
		
	}

	function MoveUp (iItemNum, sType) {
		var sHeaderTag1 = new String("Header" + iItemNum)
		var sHeaderTag2 = new String("Header" + (iItemNum - 1))
		var sHeaderHold = new String("")
		var sDescTag1 = new String("Desc" + iItemNum)
		var sDescTag2 = new String("Desc" + (iItemNum - 1))
		var sDescHold = new String("")
		var sNoteTag1 = new String("Note" + iItemNum)
		var sNoteTag2 = new String("Note" + (iItemNum - 1))
		var sNoteHold = new String("")
		var sQuantityTag1 = new String("Quantity" + iItemNum)
		var sQuantityTag2 = new String("Quantity" + (iItemNum - 1))
		var sQuantityHold = new String("")
		var sPriceTag1 = new String("Price" + iItemNum)
		var sPriceTag2 = new String("Price" + (iItemNum - 1))
		var sPriceHold = new String("")
		var sLeadTimeTag1 = new String("LeadTime" + iItemNum)
		var sLeadTimeTag2 = new String("LeadTime" + (iItemNum - 1))
		var sLeadTimeHold = new String("")

		if (document.getElementById(sHeaderTag2) == null) {
			alert("First item.  Can not move up.");
		}
		else {
			sHeaderHold = document.getElementById(sHeaderTag1).value;
			document.getElementById(sHeaderTag1).value = document.getElementById(sHeaderTag2).value;
			document.getElementById(sHeaderTag2).value = sHeaderHold;

			sDescHold = document.getElementById(sDescTag1).value;
			document.getElementById(sDescTag1).value = document.getElementById(sDescTag2).value;
			document.getElementById(sDescTag2).value = sDescHold;

			if (sType == 'Quote') {
				sNoteHold = document.getElementById(sNoteTag1).value;
				document.getElementById(sNoteTag1).value = document.getElementById(sNoteTag2).value;
				document.getElementById(sNoteTag2).value = sNoteHold;

				sQuantityHold = document.getElementById(sQuantityTag1).value;
				document.getElementById(sQuantityTag1).value = document.getElementById(sQuantityTag2).value;
				document.getElementById(sQuantityTag2).value = sQuantityHold;

				sPriceHold = document.getElementById(sPriceTag1).value;
				document.getElementById(sPriceTag1).value = document.getElementById(sPriceTag2).value;
				document.getElementById(sPriceTag2).value = sPriceHold;

				sLeadTimeHold = document.getElementById(sLeadTimeTag1).value;
				document.getElementById(sLeadTimeTag1).value = document.getElementById(sLeadTimeTag2).value;
				document.getElementById(sLeadTimeTag2).value = sLeadTimeHold;
			}
		}
		return false;
	}

	function MoveDown (iItemNum, sType) {
		var sHeaderTag1 = new String("Header" + iItemNum)
		var sHeaderTag2 = new String("Header" + (iItemNum + 1))
		var sHeaderHold = new String("")
		var sDescTag1 = new String("Desc" + iItemNum)
		var sDescTag2 = new String("Desc" + (iItemNum + 1))
		var sDescHold = new String("")
		var sNoteTag1 = new String("Note" + iItemNum)
		var sNoteTag2 = new String("Note" + (iItemNum + 1))
		var sNoteHold = new String("")
		var sQuantityTag1 = new String("Quantity" + iItemNum)
		var sQuantityTag2 = new String("Quantity" + (iItemNum + 1))
		var sQuantityHold = new String("")
		var sPriceTag1 = new String("Price" + iItemNum)
		var sPriceTag2 = new String("Price" + (iItemNum + 1))
		var sPriceHold = new String("")
		var sLeadTimeTag1 = new String("LeadTime" + iItemNum)
		var sLeadTimeTag2 = new String("LeadTime" + (iItemNum + 1))
		var sLeadTimeHold = new String("")

		if (document.getElementById(sHeaderTag2) == null) {
			alert("Last item.  Can not move down.");
		}
		else {
			sHeaderHold = document.getElementById(sHeaderTag1).value;
			document.getElementById(sHeaderTag1).value = document.getElementById(sHeaderTag2).value;
			document.getElementById(sHeaderTag2).value = sHeaderHold;

			sDescHold = document.getElementById(sDescTag1).value;
			document.getElementById(sDescTag1).value = document.getElementById(sDescTag2).value;
			document.getElementById(sDescTag2).value = sDescHold;

			if (sType == 'Quote') {
				sNoteHold = document.getElementById(sNoteTag1).value;
				document.getElementById(sNoteTag1).value = document.getElementById(sNoteTag2).value;
				document.getElementById(sNoteTag2).value = sNoteHold;

				sQuantityHold = document.getElementById(sQuantityTag1).value;
				document.getElementById(sQuantityTag1).value = document.getElementById(sQuantityTag2).value;
				document.getElementById(sQuantityTag2).value = sQuantityHold;

				sPriceHold = document.getElementById(sPriceTag1).value;
				document.getElementById(sPriceTag1).value = document.getElementById(sPriceTag2).value;
				document.getElementById(sPriceTag2).value = sPriceHold;

				sLeadTimeHold = document.getElementById(sLeadTimeTag1).value;
				document.getElementById(sLeadTimeTag1).value = document.getElementById(sLeadTimeTag2).value;
				document.getElementById(sLeadTimeTag2).value = sLeadTimeHold;
			}
		}
		return false;
	}

// Showcase Code
	function MakeShow (sImage, sTitle, sDesc, iWidth, iHeight) {
		this.image = new Image(iWidth, iHeight)
		this.source = sImage
		this.title = sTitle
		this.desc = sDesc
		this.height = iHeight
		this.width = iWidth
	}
	
	function PreLoadImage(iNdx) {
		if (iNdx < 0 || iNdx > iMaxIndex) {
			return false
		} else if (aShowcase[iNdx].image.src == '') {
			aShowcase[iNdx].image.src = aShowcase[iNdx].source
			return true
		}
	}

    // Showcase Initialize function - now created in the Header file
	/*function Initialize () {
		// IF EOF (i.e. no records in database)
		//aShowcase[0] = new MakeShow('../images/CommingSoon.jpg', 'Comming Soon', 'The showcase should be up soon to display the sucessful jobs performed by H&B Products.', 200, 180) 
		//iMaxIndex = 0
		// ELSE
		aShowcase[0] = new MakeShow('../images/Showcase_001.jpg', 'Acme Computing', 'The new air conditioning unit installed at Acme Computing utilizing the new Loren Cook QMX mixed Flow fan provided greater efficiency with cost savings on utility bills.  It is projected that the new system will pay for itself within 5 years.', 110, 168) 
		aShowcase[1] = new MakeShow('../images/Fan.jpg', 'QMX Mixed Flow Fan', 'Loren Cook Company introduces the QMX Mixed Flow Fan.  High efficiency mixed flow wheel - Continuously welded steel housing with Lorenized powder coating - Welded aerodynamic straightening vanes - Integral inlet and outlet collars for slip fit duct connections - Adjustable motor plate utilizing threaded studs for positive belt tensioning - Heavy duty ball or roller bearings with extended lube lines - Belt guard - Lifting lugs - Adjustable mounting feet.', 123, 141) 
		aShowcase[2] = new MakeShow('../images/Showcase_001.jpg', 'One More Page', 'The new air conditioning unit installed at Acme Computing utilizing the new Loren Cook QMX mixed Flow fan provided greater efficiency with cost savings on utility bills.  It is projected that the new system will pay for itself within 5 years.', 110, 168) 
		iMaxIndex = 2
		PreLoadImage(0)
		Showcase(0)
	}
	*/
	
	function Showcase(iNextPrev) {
		iShowIndex = iShowIndex+iNextPrev
		if (iShowIndex < 0) {
			iShowIndex = iMaxIndex
		} else if (iShowIndex > iMaxIndex) {
			iShowIndex = 0
		}
		document.getElementById('ShowcaseTitle').innerHTML = aShowcase[iShowIndex].title
		document.getElementById('ShowcaseDesc').innerHTML = aShowcase[iShowIndex].desc
		document.ShowcaseImage.src = aShowcase[iShowIndex].source
		document.ShowcaseImage.width = aShowcase[iShowIndex].width
		document.ShowcaseImage.height = aShowcase[iShowIndex].height
		if (iMaxIndex == 0) {		//only one page
			document.PageBottom.useMap = "#OnePage"
		} else {
			var oImgBottom = document.PageBottom
			switch (iShowIndex) {
				case 0:				//First Page
					oImgBottom.src = "../images/PageBottomNext.gif"
					oImgBottom.useMap = "#NextPageOnly"
					PreLoadImage(iShowIndex+1)
					break
				case iMaxIndex:		//Last Page
					oImgBottom.src = "../images/PageBottomPrev.gif"
					oImgBottom.useMap = "#PrevPageOnly"
					break
				default:
					oImgBottom.src = "../images/PageBottomPrevNext.gif"
					oImgBottom.useMap = "#PrevNextPage"
					PreLoadImage(iShowIndex+1)
					break
			}
		}
		return false;
	}

// End Showcase Code

// Form Custom Validation

function ValidateShowcase (source, args)
{
    args.IsValid = true;
	if (document.frmShowcase.filUpload.value == "" && document.frmShowcase.txtGraphics.value == "") {
        args.IsValid = false;
	}
}

function ValidateWhatsNew (source, args)
{
    args.IsValid = true;
	if (document.frmWhatsNew.filUpload.value == "" && document.frmWhatsNew.txtGraphics.value == "") {
        args.IsValid = false;
	}
}

function ValidateWhatsNewExpDate (source, args)
{
    args.IsValid = true;
	if (document.frmWhatsNew.txtExpirationDate.value == "" && document.frmWhatsNew.chkExpires.checked) {
        args.IsValid = false;
	}
}

function ValidateUserPassword (source, args)
{
    args.IsValid = true;
	if (document.frmUsers.txtPassword.value != document.frmUsers.txtConfirm.value) {
        args.IsValid = false;
	}
}

function ValidateUserNewPassword (source, args)
{
    args.IsValid = true;
	if (document.frmUsers.txtNewPassword.value != document.frmUsers.txtNewConfirm.value) {
        args.IsValid = false;
	}
}

function ValidateChangePassword (source, args)
{
    args.IsValid = true;
	if (document.frmChangePassword.txtNewPassword.value != document.frmChangePassword.txtNewConfirm.value) {
        args.IsValid = false;
	}
}

function ValidateUserCompany (source, args)
{
	var sName = new String(document.frmUsers.NewCompanyName.value)
    args.IsValid = true;
    
	if (!document.frmUsers.NewCompanyName.value) {
		args.IsValid = false;
	}
	else {
		if ((sName == "Select Company") || (sName.length < 1)) {
			args.IsValid = false;
		}
	}
}

function ValidateOrderCompany (source, args)
{
	var sName = new String(document.frmSearch.NewCompanyName.value)
    args.IsValid = true;
	if (!document.frmSearch.NewCompanyName.value) {
		args.IsValid = false;
	}
	else {
		if ((sName == "Select Company") || (sName.length < 1)) {
			args.IsValid = false;
		}
	}
}

function ValidateOrderCompanyAdd (source, args)
{
	var sName = new String(document.frmSearch.NewCompanyNameAdd.value)
    args.IsValid = true;
	if (!document.frmSearch.NewCompanyNameAdd.value) {
		args.IsValid = false;
	}
	else {
		if ((sName == "Select Company") || (sName.length < 1)) {
			args.IsValid = false;
		}
	}
}

function ValidateJob (source, args)
{
	var sName = new String(document.frmQuote.NewJobName.value)
	args.IsValid = true;
	if (!document.frmQuote.NewJobName.value) {
		args.IsValid = false;
	}
	else {
		if ((sName == "Select Job") || (sName.length < 1)) {
			args.IsValid = false;
		}
	}
}

// End Form Custom Validation

// Function called from header when any page loads.
// This is now built in the header file
/* function Initialize(sErr) {
	if (document.forms.length > 0) {
		for(i=0; i<document.forms[0].elements.length; i++) {
			if (document.forms[0].elements[i].type == "text") {
				document.forms[0].elements[i].focus()
				break
			}
		}	
	}
	if (sErr != "") {
		alert(sErr)
	}
}
*/

function LoadImage(sPath, sName) {
	try {
		this.name = sName
		this.ImageOff = new Image()
		this.ImageOff.src = sPath+sName+"Up.jpg"
		this.ImageOn = new Image()
		this.ImageOn.src = sPath+sName+"Over.jpg"
	} catch(er){}
}

function SetImage(oImg, iNdx, bOn) {
	try {
		if (bOn) {
			oImg.src = aimgMenu[iNdx].ImageOn.src
		} else {
			oImg.src = aimgMenu[iNdx].ImageOff.src
		}
	} catch(er){}
}

function sTrim(sString) {
	try {
		sString = sString.replace( /^\s+/g, "" );// strip leading
		return sString.replace( /\s+$/g, "" );// strip trailing
	} catch(er){}
	return sString
}

function confirm_delete(sType, sKey) {
	var msg = "Delete " + sType + " " + sKey + "?";

	return confirm(msg);
}

function bCheckLogin(oFrm) {
	try {
		// Get the UserID and Password values
		var sUserID = new String(oFrm.UserID.value)
		var sPassword = new String(oFrm.Password.value)
		// Trim Leading and Ending spaces
		sUserID = sTrim(sUserID)
		sPassword = sTrim(sPassword)
		// Check to see if either are blank
		if (sUserID == '' || sPassword == '') {
			// Replace User ID with it's trimmed value 
			oFrm.UserID.value = sUserID
			// Clear the password
			oFrm.Password.value = ''
			// Display the error message
			alert('Invalid User ID or Password.\nPlease try again.')
			// Set focus to the first blank one
			if (sUserID == '') {
				oFrm.UserID.focus()
			} else {
				oFrm.Password.focus()
			}
			// Do NOT submit the form
			return false
		}
	} catch(er){}
	// If they were not blank or there was an error
	// in the function, then submit the form.
	// Data will be re-checked at the server.
	return true
} // bCheckForm

/// Launches the DatePicker page in a popup window, 
/// passing a JavaScript reference to the field that we want to set.

/// <param name="strField">String. The JavaScript reference to the field that we want to set, 
/// in the format: FormName.FieldName 
/// Please note that JavaScript is case-sensitive.</param>

function calendarPicker(strField, strValue)
{
	window.open('/DatePicker.aspx?field=' + strField + '&value=' + strValue, 'calendarPopup', 'width=250,height=190,resizable=yes');
}


try {
	var aimgMenu = new Array()

	aimgMenu[1]= new LoadImage("/images/", "MenuAboutUs")
	aimgMenu[2]= new LoadImage("/images/", "MenuProducts")
	aimgMenu[3]= new LoadImage("/images/", "MenuShowcase")
	aimgMenu[4]= new LoadImage("/images/", "MenuContact")
	aimgMenu[5]= new LoadImage("/images/", "MenuWhatsNew")
	aimgMenu[6]= new LoadImage("/images/", "MenuBidList")
	aimgMenu[7]= new LoadImage("/images/", "MenuOrders")
	aimgMenu[8]= new LoadImage("/images/", "MenuJobs")
} catch(er){}

//Functions to allow user to specify a new Company, new Job, or a new Marketing Program
	function NewCompany(oFrm) {
		var sCompany = new String()
		var sLstComp = new String()
		sCompany = window.prompt('Enter new company name.','')
		if (sCompany != null) {
		   sCompany = sTrim(sCompany)
		   if (sCompany != '') {
			var iCompanies = oFrm.lstCompany.length;
			for (var x = 1; x < iCompanies; x++) {
				sLstComp = oFrm.lstCompany.options[x].text
				if (sLstComp.toLowerCase() == sCompany.toLowerCase()) {
					iCompanies = x
				}
			}
			if (iCompanies == oFrm.lstCompany.length) {
				oFrm.lstCompany.options[iCompanies] = new Option(sCompany, -1);
			}
			oFrm.NewCompanyName.value = sCompany
			oFrm.lstCompany.selectedIndex = iCompanies
		   }
		}
	}

	function NewCompanyAdd(oFrm) {
		var sCompany = new String()
		var sLstComp = new String()
		sCompany = window.prompt('Enter new company name.','')
		if (sCompany != null) {
		   sCompany = sTrim(sCompany)
		   if (sCompany != '') {
			var iCompanies = oFrm.lstCompanyAdd.length;
			for (var x = 1; x < iCompanies; x++) {
				sLstComp = oFrm.lstCompanyAdd.options[x].text
				if (sLstComp.toLowerCase() == sCompany.toLowerCase()) {
					iCompanies = x
				}
			}
			if (iCompanies == oFrm.lstCompanyAdd.length) {
				oFrm.lstCompanyAdd.options[iCompanies] = new Option(sCompany, -1);
			}
			oFrm.NewCompanyNameAdd.value = sCompany
			oFrm.lstCompanyAdd.selectedIndex = iCompanies
		   }
		}
	}

	function NewMarket(oFrm) {
		var sMarketName = new String()
		var sLstMarket = new String()
		sMarketName = window.prompt('Enter new marketing program.','')
		if (sMarketName != null) {
		   sMarketName = sTrim(sMarketName)
		   if (sMarketName != '') {
			var iMarket = oFrm.lstMarket.length;
			for (var x = 1; x < iMarket; x++) {
				sLstMarket = oFrm.lstMarket.options[x].text
				if (sLstMarket.toLowerCase() == sMarketName.toLowerCase()) {
					iMarket = x
				}
			}
			if (iMarket == oFrm.lstMarket.length) {
				oFrm.lstMarket.options[iMarket] = new Option(sMarketName, -1);
			}
			oFrm.NewMarketName.value = sMarketName
			oFrm.lstMarket.selectedIndex = iMarket
		   }
		}
	}

	function NewJob(oFrm) {
		var sJob = new String()
		var sLstJob = new String()
		sJob = window.prompt('Enter new job name.','')
		if (sJob != null) {
		   sJob = sTrim(sJob)
		   if (sJob != '') {
			var iJobs = oFrm.lstJobs.length;
			for (var x = 1; x < iJobs; x++) {
				sLstJob = oFrm.lstJobs.options[x].text
				if (sLstJob.toLowerCase() == sJob.toLowerCase()) {
					iJobs = x
				}
			}
			if (iJobs == oFrm.lstJobs.length) {
				oFrm.lstJobs.options[iJobs] = new Option(sJob, -1);
			}
			oFrm.NewJobName.value = sJob
			oFrm.lstJobs.selectedIndex = iJobs
		   }
		}
	}

	function NewJobAdd(oFrm) {
		var sJob = new String()
		var sLstJob = new String()
		sJob = window.prompt('Enter new job name.','')
		if (sJob != null) {
		   sJob = sTrim(sJob)
		   if (sJob != '') {
			var iJobs = oFrm.lstJobsAdd.length;
			for (var x = 1; x < iJobs; x++) {
				sLstJob = oFrm.lstJobsAdd.options[x].text
				if (sLstJob.toLowerCase() == sJob.toLowerCase()) {
					iJobs = x
				}
			}
			if (iJobs == oFrm.lstJobsAdd.length) {
				oFrm.lstJobsAdd.options[iJobs] = new Option(sJob, -1);
			}
			alert (sJob)
			oFrm.NewJobNameAdd.value = sJob
			oFrm.lstJobsAdd.selectedIndex = iJobs
		   }
		}
	}

	function SetCompName(oFrm, oComp) {
		oFrm.NewCompanyName.value = oComp.options[oComp.selectedIndex].text
	}

	function SetCompNameAdd(oFrm, oComp) {
		oFrm.NewCompanyNameAdd.value = oComp.options[oComp.selectedIndex].text
	}
	
	function SetMarketName(oFrm, oMarket) {
		oFrm.NewMarketName.value = oMarket.options[oMarket.selectedIndex].text
	}

	function SetJobName(oFrm, oJob) {
		oFrm.NewJobName.value = oJob.options[oJob.selectedIndex].text
	}
	
	function SetJobNameAdd(oFrm, oJob) {
		oFrm.NewJobNameAdd.value = oJob.options[oJob.selectedIndex].text
	}
	
//	function DisplayFields(oFrm) {
//		alert(oFrm.lstCompany.value+' : '+oFrm.NewCompanyName.value)
//		return false
//	}
//End New Company Functions

	function ViewTrackingURL(oFrm, oNum) {
		if (oFrm.lstTrucking.value == "") {
			alert("Cannot load tracking URL.  No trucking company was selected.");
		}
		else if (oNum == "") {
			alert("Cannot load tracking URL.  No tracking number has been entered.");
		}
		else {
			features = "toolbar=no,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=700,height=500,top=25,left=10";
			loc = "/Admin/TrackingURL.aspx?ID=" + oFrm.lstTrucking.value + "&trk=" + oNum;
			window.open (loc, "Tracking", features);
		}
	}
	
	function OLD_ViewTrackingURL(oFrm) {
		if (oFrm.lstTrucking.value == "") {
			alert("Cannot load tracking URL.  No trucking company was selected.");
		}
		else if (oFrm.txtShipTrackingNum.value == "") {
			alert("Cannot load tracking URL.  No tracking number has been entered.");
		}
		else {
			features = "toolbar=no,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=700,height=500,top=25,left=10";
			loc = "/Admin/TrackingURL.aspx?ID=" + oFrm.lstTrucking.value + "&trk=" + oFrm.txtShipTrackingNum.value;
			window.open (loc, "Tracking", features);
		}
	}
	
  //************ General Utility Functions **********************//

function sEncode(s_qstr) {
/* 
* Description:	Encodes a string to be used in an address query string.
*
* Inputs:		s_qstr		- Query string to encode
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.17.2004	Created
*/
	var re = /\+/g;						// Create RegExp to look for plus sign.
	s_qstr = escape(s_qstr)				// Escape the string
	s_qstr = s_qstr.replace(re, '%2B');	// Replace any remaining '+' with '%2B'
	return(s_qstr)						// Return the new string
} // sEncode

function sLtrim(s_val) {
/* 
* Description:	Trim leading spaces from the specified string
*
* Inputs:		s_val		- String to trim
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.17.2004	Created
*/
	var reg_exp = /^\s+/g
	return s_val.replace(reg_exp, '') // trim leading spaces
}

function sRtrim(s_val) {
/* 
* Description:	Trim trailing spaces from the specified string
*
* Inputs:		s_val		- String to trim
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.17.2004	Created
*/
	var reg_exp = /\s+$/g
	return s_val.replace(reg_exp, '') // trim trailing spaces
}

function sTrim(s_val) {
/* 
* Description:	Trim leading and trailing spaces from the specified string
*
* Inputs:		s_val		- String to trim
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.17.2004	Created
*/
	return (sRtrim(sLtrim(s_val)))
}
/********************************
* Select Submit Javascript
*********************************/
function CopyValuesToHiddenField(o_frm, s_select) {
	var s_vals = sReturnSelected(o_frm, s_select);
	//alert(s_vals);
	o_frm.SelectedValues.value = s_vals;
	return true;
}

function CompanySelectAll() {
	document.getElementById("chkShowOrders").checked = true;
	document.getElementById("chkShowSheets").checked = true;
	document.getElementById("chkShowFans").checked = true;
	document.getElementById("chkShowArchitects").checked = true;
	document.getElementById("chkShowEngineers").checked = true;
	document.getElementById("chkShowInactive").checked = true;
    return false;
}
function CompanyClearAll() {
	document.getElementById("chkShowOrders").checked = false;
	document.getElementById("chkShowSheets").checked = false;
	document.getElementById("chkShowFans").checked = false;
	document.getElementById("chkShowArchitects").checked = false;
	document.getElementById("chkShowEngineers").checked = false;
	document.getElementById("chkShowInactive").checked = false;
    return false;
}


/********************************
* Select Class Javascript
*********************************/
function CheckSelectFocus(o_ctrl, s_ctrl_available, s_ctrl_selected) {
/* 
* Description:	Determines if the entire select control has lost focus.
*				If it has the two list boxes are un-highlighted.
*
* Inputs:		o_ctrl				- Control that lost focus
*				s_ctrl_available	- Name of the Available select list
*				s_ctrl_selected		- Name of the Selected select list
*
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.08.2004	Created
*/
	// If the current active control does not have the same ID as the
	// control that lost focus, then un-highlight the 2 select lists.
	if (document.activeElement.id != o_ctrl.id) {
		o_ctrl.form.item(s_ctrl_available).selectedIndex = -1
		o_ctrl.form.item(s_ctrl_selected).selectedIndex = -1
	}
} // CheckSelectFocus

function AvailableSelected(o_frm, s_ctrl_available, s_ctrl_selected, i_direction) {
/* 
* Description:	Move an item between the Available and Selected list boxes
*
* Inputs:		o_frm				- Form containing the controls
*				s_ctrl_available	- Name of the Available select list
*				s_ctrl_selected		- Name of the Selected select list
*				i_direction			- Direction to move the selected item
*										1 = Move item from Available to Selected
*										0 = Move item from Selected to Available
*
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.08.2004	Created
*/
	var o_ctrl_from			// Select list where the item is coming from
	var o_ctrl_to			// Select list where the item is moving to
	var i_id				// ID of the item being moved


	// Set the From and To controls based on which direction the item is moving
	if (i_direction < 1) {
		o_ctrl_from = o_frm.item(s_ctrl_selected)
		o_ctrl_to = o_frm.item(s_ctrl_available)
	} else {
		o_ctrl_from = o_frm.item(s_ctrl_available)
		o_ctrl_to = o_frm.item(s_ctrl_selected)
	}
	// Get the index of the selected item
	var i_selected = o_ctrl_from.selectedIndex
	// If an item is highlighted in the From list then continue
	if (i_selected >= 0) {
		// If the direction is going from the Available list to the Selected list,
		// then we may need to do extra processing the deal with the "All" selection
		if (i_direction > 0) {
			// Get the ID of the selected item
			i_id = parseInt(o_ctrl_from.options[i_selected].id)
			if (i_id == 0) {
				// If the item selected is the "All" selection, then we need to
				// clear all other items before moving it into the Selected list.
				ClearList(o_ctrl_to, o_ctrl_from)
			} else if (o_ctrl_to.options.length > 0) {
				// Otherwise if the Selected list already has the "All" selection,
				// then we need to remove that item from the "Selected" list.
				i_id = parseInt(o_ctrl_to.options[0].id)
				if (i_id == 0) {
					// This is the only case where one item move into the Selected
					// list at the same time that an item moves to the Available list.
					iMoveOneValue(o_ctrl_to, o_ctrl_from, 0)
					// We also need to increment the index of the selected item
					// because it has moved down one position after the "All"
					// selection was inserted at the top of the list.
					i_selected = i_selected + 1
				}
			}
		}
		// Move the selected item and hightlight it.
		o_ctrl_to.selectedIndex = iMoveOneValue(o_ctrl_from, o_ctrl_to, i_selected)

		// If the bottom item was moved over then ...
		if (i_selected >= o_ctrl_from.options.length) {
			if (i_selected == 0) {
				// If there are no items left in the From list then remove the highlight
				o_ctrl_from.selectedIndex = -1
			} else {
				// Otherwise set the highlight to the last item in the list
				o_ctrl_from.selectedIndex = o_ctrl_from.options.length-1
			}
		} else {
			// Highlight the item that WAS under the item that moved
			o_ctrl_from.selectedIndex = i_selected
		}
	}
} //AvailableSelected

function SetOptionObj(o_option_obj_1, o_option_obj_2) {
/* 
* Description:	Set one option (or option object) to be the
*				same as another option (or option object).
*
* Inputs:		o_option_obj_1		- Option (or option object) to receive the values
*				o_option_obj_2		- Option (or option object) containing the values
*
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.08.2004	Created
*/
	o_option_obj_1.text = o_option_obj_2.text		// assign the text property
	o_option_obj_1.value = o_option_obj_2.value		// assign the value property
	o_option_obj_1.id = o_option_obj_2.id			// assign the id property
} // SetOptionObj

function OptionObj(o_option) {
/* 
* Description:	Creates an option object that contains the 3 main properties
*				we need to create an actual select list option.
*
* Inputs:		o_option		- Option (or option object) containing the values
*
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.08.2004	Created
*/
	this.text = o_option.text		// assign the text property
	this.value = o_option.value		// assign the value property
	this.id = o_option.id			// assign the id property
} // OptionObj

function SortOptions(o_ctrl) {
/* 
* Description:	Sort options in a select list control based on the IDs of the options.
*
* Inputs:		o_ctrl		- Select list control
*
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.08.2004	Created
*/

	var i_ndx
	var i_options = o_ctrl.length
	// If there are fewer than 2 options, then there is no need to sort
	if (i_options < 2) {
		return
	}
	// Create an array to hold the options from the select list
	var ao_options = new Array(i_options-1)
	// Load the array with options from the select list
	for (i_ndx = 0; i_ndx < i_options; i_ndx++) {
		ao_options[i_ndx] = new OptionObj(o_ctrl.options[i_ndx])
	}
	// Sort the array using the ID property
	ao_options.sort(function(o_opt1, o_opt2){
		if (parseInt(o_opt1.id) < parseInt(o_opt2.id)){
			return -1;
		} else {
			return 1;
		}
	});
	// Repopulate the select list with the sorted array
	for (i_ndx = 0; i_ndx < i_options; i_ndx++) {
		SetOptionObj(o_ctrl.options[i_ndx], ao_options[i_ndx])
	}
} // SortOptions

function iMoveOneValue(o_ctrl_from, o_ctrl_to, i_selected) {
/* 
* Description:	Performs the phisical move of one option from one select list to another 
*				select list and places it in the correct position within the list
*
* Inputs:		o_ctrl_from		- Select list where the item exists
*				o_ctrl_to		- Select list where the item will be moved to
*				i_selected		- Index of the item being moved
*
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.08.2004	Created
*/

	var i_ndx
	var i_ret_ndx
	// Get the values of the item being moved
	var o_option = new OptionObj(o_ctrl_from.options[i_selected])
	var i_id = parseInt(o_option.id)
	// Remove the item from the "From" list
	o_ctrl_from.options[i_selected] = null;
	// Get the length of the "To" list
	i_ndx = o_ctrl_to.options.length
	// Add the item as the last item in the "To" list
	o_ctrl_to.options[i_ndx] = new Option();
	// Move each item in the list down one possition until you reach the
	// position where the new item should exist, or you reach the top of the list
	for (; i_ndx >= 0; i_ndx--) {
		if (i_ndx==0 || parseInt(o_ctrl_to.options[i_ndx-1].id) < i_id) {
			// If we have reached the position where the new 
			// item should exist, or the top of the list.
			SetOptionObj(o_ctrl_to.options[i_ndx], o_option)
			i_ret_ndx = i_ndx	// Set the index where the item was inserted
			i_ndx = -1			// Force an exit of the FOR loop
		} else {
			// Otherwise, move the current option down one possition
			SetOptionObj(o_ctrl_to.options[i_ndx], o_ctrl_to.options[i_ndx-1])
		}
	}
	return (i_ret_ndx) // Return the index where the item was inserted
} // iMoveOneValue
	
function ClearList(o_ctrl_from, o_ctrl_to) {
/* 
* Description:	Move all items from one select list to another select list
*
* Inputs:		o_ctrl_from		- Select list where the items exist
*				o_ctrl_to		- Select list where the items will be moved to
*
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.08.2004	Created
*/
	// If there are items in the list then clear them out
	if (o_ctrl_from.options.length > 0) {
		if (o_ctrl_from.options.length ==1) {
			// If there is only one item, then just move it (faster)
			iMoveOneValue(o_ctrl_from, o_ctrl_to, 0)
		} else {
			// While the "From" list has items
			while (o_ctrl_from.options.length > 0) {
				// Create a new option in the "To" list
				o_ctrl_to.options[o_ctrl_to.options.length] = new Option();
				// Move the last item in the "From" list to the "To" list
				SetOptionObj(o_ctrl_to.options[o_ctrl_to.options.length-1], o_ctrl_from.options[o_ctrl_from.options.length-1])
				// Delete the item from the "From" list
				o_ctrl_from.options[o_ctrl_from.options.length-1] = null
			}
			// Sort the items in the "To" list
			SortOptions(o_ctrl_to)
		}
	}
} // ClearList
		
function ClearAll(o_frm, s_ctrl_available, s_ctrl_selected) {
/* 
* Description:	Button pressed to Clear all items from the Selected list
*
* Inputs:		o_frm				- Form containing the controls
*				s_ctrl_available	- Name of the Available select list
*				s_ctrl_selected		- Name of the Selected select list
*
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.08.2004	Created
*/
	var o_ctrl_from = o_frm.item(s_ctrl_selected)	// Selected listbox
	var o_ctrl_to = o_frm.item(s_ctrl_available)	// Available listbox
	ClearList(o_ctrl_from, o_ctrl_to)				// Clear Selected listbox

	// Scroll Available listbox to the top and un-highlight any selected item
	ScrollTopUnselect(o_ctrl_to)
} // ClearAll

function RestoreDefaults(o_frm, s_ctrl_available, s_ctrl_selected, b_all) {
/* 
* Description:	Button pressed to Restore Default items to the Selected list
*
* Inputs:		o_frm				- Form containing the controls
*				s_ctrl_available	- Name of the Available select list
*				s_ctrl_selected		- Name of the Selected select list
*				b_all				- The "All" selection is the default
*
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.08.2004	Created
*/
	var o_ctrl_from = o_frm.item(s_ctrl_available)	// Available listbox
	var o_ctrl_to = o_frm.item(s_ctrl_selected)		// Selected listbox
	
	// Clear all items out of the Selected listbox
	ClearList(o_ctrl_to, o_ctrl_from)
	
	// If the "All" selection is the default then move it into the Selected listbox
	if (b_all == true) {
		if (o_ctrl_from.options.length > 0) {
			if (parseInt(o_ctrl_from.options[0].id) == 0) {
				iMoveOneValue(o_ctrl_from, o_ctrl_to, 0)
			}
		}
	} else {
		// Otherwise walk through each item in the Available listbox
		for (var i_ndx = o_ctrl_from.options.length-1; i_ndx >= 0; i_ndx--) {
			// If the ID of the option is an odd number, then it is a default item
			if ((parseInt(o_ctrl_from.options[i_ndx].id)%2) > 0) {
				// Create a new option in the Selected listbox
				o_ctrl_to.options[o_ctrl_to.options.length] = new Option()
				// Move the option from the Available listbox to the Selected listbox
				SetOptionObj(o_ctrl_to.options[o_ctrl_to.options.length-1], o_ctrl_from.options[i_ndx])
				// Delete the item that was moved from the Available listbox
				o_ctrl_from.options[i_ndx] = null
			}
		}
		// Sort all values in the Selected listbox
		SortOptions(o_ctrl_to)
	}
	// Scroll both listboxes to the top and un-highlight any selected item(s)
	ScrollTopUnselect(o_ctrl_from)
	ScrollTopUnselect(o_ctrl_to)
} //RestoreDefaults

function ScrollTopUnselect(o_select) {
/* 
* Description:	Scroll a listbox to the top and un-highlight any selected item
*
* Inputs:		o_select		- The listbox to scroll
*
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.08.2004	Created
*/

	// If the list has too few items to require a scroll bar
	// then just remove focus from the list 
	if (o_select.options.length <= o_select.size) {
		o_select.selectedIndex = -1
	} else {
		// Set focus to the top item in the list to force it to scroll up
		o_select.selectedIndex = 0
		// Unselect the items in the list after 10 miliseconds
		// This gives the listbox enough time to react to the previous
		// setting and scroll to the top.
		window.setTimeout('document.'+o_select.form.name+'.'+o_select.name+'.selectedIndex=-1',10)
	}
} // ScrollTopUnselect
	
function SetSelectedFromString(o_frm, s_ctrl_available, s_ctrl_selected, s_ids) {
/* 
* Description:	Use a comma delimited string of values to set the list of Selected items
*
* Inputs:		o_frm				- Form containing the controls
*				s_ctrl_available	- Name of the Available select list
*				s_ctrl_selected		- Name of the Selected select list
*				s_ids				- Comma delimited string of values
*
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.08.2004	Created
*/

	var o_ctrl_from = o_frm.item(s_ctrl_available)	// Available listbox
	var o_ctrl_to = o_frm.item(s_ctrl_selected)		// Selected listbox

	// Clear all items out of the Selected listbox
	ClearList(o_ctrl_to, o_ctrl_from)

	// Append and prepend commas to the string to aid in the search process
	s_ids = ','+s_ids+','
	// Walk through each item in the Available listbox
	for (var i_ndx = o_ctrl_from.length-1; i_ndx >= 0; i_ndx--) {
		// If the current item has a value in the list then move it to the Selected listbox
		if (s_ids.indexOf(','+o_ctrl_from.options[i_ndx].value+',') >=0) {
			// Create a new option in the Selected listbox
			o_ctrl_to.options[o_ctrl_to.options.length] = new Option()
			// Move the option from the Available listbox to the Selected listbox
			SetOptionObj(o_ctrl_to.options[o_ctrl_to.options.length-1], o_ctrl_from.options[i_ndx])
			// Delete the item that was moved from the Available listbox
			o_ctrl_from.options[i_ndx] = null
		}
	}
	// Sort all values in the Selected listbox
	SortOptions(o_ctrl_to)

	// Scroll both listboxes to the top and un-highlight any selected item(s)
	ScrollTopUnselect(o_ctrl_from)
	ScrollTopUnselect(o_ctrl_to)
} // SetSelectedFromString

function addReturnObject(s_name, s_value) {
/* 
* Description:	Creates a return object consisting of a name and value
*
* Inputs:		s_name				- Object name
*				s_value				- Object value
*
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.08.2004	Created
*/
	this.objName = s_name		// Assign the objName property
	this.objValue = s_value		// Assign the objValue property
} // addReturnObject
	
function ReturnSelected(o_frm, s_select, ao_return) {
/* 
* Description:	Returns the values in the selected listbox 
*				and closes the current window
*
* Inputs:		o_frm				- Form containing the control
*				s_select			- Name of the Selected listbox
*				ao_return			- Optional array of values to return
*
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.08.2004	Created
*/

	// If the optional Array was not sent, then we need to create it
	if (ReturnSelected.arguments.length < 3) {
		ao_return = new Array()
	}
	// Append an item to the array consisting of the listbox 
	// name and a comma delimited string of selected values.
	ao_return[ao_return.length]=new addReturnObject(s_select, sReturnSelected(o_frm, s_select))

	// Set the return value for the current dialog window
	window.returnValue = ao_return
	window.close() // Close the window
} //ReturnSelected

function sReturnSelected(o_frm, s_select) {
/* 
* Description:	Creates a comma delimited string of values for the options
*				in the specified select list.
*
* Inputs:		o_frm				- Form containing the control
*				s_select			- Name of the Selected listbox
*
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.08.2004	Created
*/

	var s_ret_lst = new String('')		// Init comma delimited string of values
	var o_ctrl = o_frm.item(s_select)	// Control containing the values
	// Walk through the select list and create the comma delimited string
	for (var i_ndx=0; i_ndx<o_ctrl.length; i_ndx++) {
		s_ret_lst=s_ret_lst+','+o_ctrl.options[i_ndx].value
	}
	
	// If there were values, we need to remove the 
	// first comma before returning the string.
	if (s_ret_lst!='') {
		s_ret_lst=s_ret_lst.substr(1)
	}
	return(s_ret_lst) // Return the comma delimited string of values
} //sReturnSelected

function CancelSelected() {
/* 
* Description:	Returns the null and closes the current window
*
* Inputs:		None
* Outputs:		None
* Globals:		None
* Return:		None
*
* History:
* 	Programmer		Date		Description of Changes
*	Gene Wachowski	11.08.2004	Created
*/
	// Set the return value for the current dialog window to null
	window.returnValue = null
	window.close() // Close the window
} // CancelSelected
		
function noenter() {
  return !(window.event && window.event.keyCode == 13); }

// FreeTextBox Code from Forum
// http://freetextbox.com/forums/thread/8127.aspx  


  
function swapColonToUnder(id){ 
// fix for different browser versions of id's generated by infragisitics    
	id = id.replace(/:/g,"_");
	return id;
}

function FTB_SetBorder(ftbname,status) {
	if(!FTB_API[ftbname])
		ftbname = swapColonToUnder(ftbname);
	editor = FTB_API[ftbname];
	editor.Focus();
	//if(isIE)
	//	var allTables = editor.designEditor.document.body.getElementsByTagName('TABLE');
	//else
		var allTables = editor.designEditor.document.getElementsByTagName('TABLE');
	for (i=0; i < allTables.length; i++) {
		var allTableCells = allTables[i].getElementsByTagName('TD');
		if (status == 'show' ) {
			if (allTables[i].style.borderLeft == ""||allTables[i].style.borderLeftLtyle == "none")
				allTables[i].style.borderLeft = '1px #bcbcbb dashed';
			if (allTables[i].style.borderRight == ""||allTables[i].style.borderRightStyle == "none")
				allTables[i].style.borderRight = '1px #bcbcbb dashed';
			if (allTables[i].style.borderTop == ""||allTables[i].style.borderTopStyle == "none")
				allTables[i].style.borderTop = '1px #bcbcbb dashed';
			if (allTables[i].style.borderBottom == ""||allTables[i].style.borderBottomStyle == "none")
				allTables[i].style.borderBottom = '1px #bcbcbb dashed';
			for (j=0;j<allTableCells.length;j++) {
				if (allTableCells[j].style.borderLeft == ""||allTableCells[j].style.borderLeftStyle == "none")
					allTableCells[j].style.borderLeft = '1px #bcbcbb dashed';
				if (allTableCells[j].style.borderRight == ""||allTableCells[j].style.borderRightStyle == "none")
					allTableCells[j].style.borderRight = '1px #bcbcbb dashed';
				if (allTableCells[j].style.borderTop == ""||allTableCells[j].style.borderTopStyle == "none")
					allTableCells[j].style.borderTop = '1px #bcbcbb dashed';
				if (allTableCells[j].style.borderBottom == ""||allTableCells[j].style.borderBottomStyle == "none")
					allTableCells[j].style.borderBottom = '1px #bcbcbb dashed';
			}
		}
		else {
			if ((allTables[i].style.borderLeft.toLowerCase() == '#bcbcbb 1px dashed')||(allTables[i].style.borderLeft.toLowerCase() == '1px dashed rgb(188, 188, 187)')) {
				allTables[i].style.borderLeft = '';
				allTables[i].style.borderLeftStyle = '';
				allTables[i].style.borderLeftColor = '';
				allTables[i].style.borderLeftWidth = '';
			}
			if ((allTables[i].style.borderRight.toLowerCase() == '#bcbcbb 1px dashed')||(allTables[i].style.borderRight.toLowerCase() == '1px dashed rgb(188, 188, 187)')) {
				allTables[i].style.borderRight = '';
				allTables[i].style.borderRightStyle = '';
				allTables[i].style.borderRightColor = '';
				allTables[i].style.borderRightWidth = '';
			}
			if ((allTables[i].style.borderTop.toLowerCase() == '#bcbcbb 1px dashed')||(allTables[i].style.borderTop.toLowerCase() == '1px dashed rgb(188, 188, 187)')) {
				allTables[i].style.borderTop = '';
				allTables[i].style.borderTopStyle = '';
				allTables[i].style.borderTopColor = '';
				allTables[i].style.borderTopWidth = '';
			}
			if ((allTables[i].style.borderBottom.toLowerCase() == '#bcbcbb 1px dashed')||(allTables[i].style.borderBottom.toLowerCase() == '1px dashed rgb(188, 188, 187)')) {
				allTables[i].style.borderBottom = '';
				allTables[i].style.borderBottomStyle = '';
				allTables[i].style.borderBottomColor = '';
				allTables[i].style.borderBottomWidth = '';
			}
			for(j=0;j<allTableCells.length;j++) {
				if ((allTableCells[j].style.borderLeft.toLowerCase() == '#bcbcbb 1px dashed')||(allTableCells[j].style.borderLeft.toLowerCase() == '1px dashed rgb(188, 188, 187)')) {
					allTableCells[j].style.borderLeft = '';
					allTableCells[j].style.borderLeftStyle = '';
					allTableCells[j].style.borderLeftColor = '';
					allTableCells[j].style.borderLeftWidth = '';
				}
				if ((allTableCells[j].style.borderRight.toLowerCase() == '#bcbcbb 1px dashed')||(allTableCells[j].style.borderRight.toLowerCase() == '1px dashed rgb(188, 188, 187)')) {
					allTableCells[j].style.borderRight = '';
					allTableCells[j].style.borderRightStyle = '';
					allTableCells[j].style.borderRightColor = '';
					allTableCells[j].style.borderRightWidth = '';
				}
				if ((allTableCells[j].style.borderTop.toLowerCase() == '#bcbcbb 1px dashed')||(allTableCells[j].style.borderTop.toLowerCase() == '1px dashed rgb(188, 188, 187)'))
				{
					allTableCells[j].style.borderTop = '';
					allTableCells[j].style.borderTopStyle = '';
					allTableCells[j].style.borderTopColor = '';
					allTableCells[j].style.borderTopWidth = '';
				}
				if ((allTableCells[j].style.borderBottom.toLowerCase() == '#bcbcbb 1px dashed')||(allTableCells[j].style.borderBottom.toLowerCase() == '1px dashed rgb(188, 188, 187)'))
				{
					allTableCells[j].style.borderBottom = '';
					allTableCells[j].style.borderBottomStyle = '';
					allTableCells[j].style.borderBottomColor = '';
					allTableCells[j].style.borderBottomWidth = '';
				}
			}
		}
	}
}

function FTB_GuideLines(ftbname)
{
	if(!FTB_API[ftbname])ftbname = swapColonToUnder(ftbname);
		editor = FTB_API[ftbname];
		editor.Focus();
		if (editor.guidelines) {
			FTB_SetBorder(ftbname, 'hide');
			editor.guidelines=false;
		} else {
			FTB_SetBorder(ftbname, 'show');
			editor.guidelines=true;
	}
}

// End FreeTextBox from forum -- Toggle Table Borders
