<%@ Page Language="C#" MasterPageFile="~/inner.Master" AutoEventWireup="true"
	CodeBehind="service.aspx.cs" Inherits="SedonaWeb.service_tickets.service" ValidateRequest="false" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ MasterType VirtualPath="~/inner.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphHead" runat="server">
	<style type="text/css">
	</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphContent" runat="server">
	<script type="text/javascript">

		function hide() {
			if (this.document.getElementById('CustomerCommentsDiv'))
				this.document.getElementById('CustomerCommentsDiv').style.display = "none";
			if (this.document.getElementById('ctl00_cphContent_FieldCommentsDiv'))
				this.document.getElementById('ctl00_cphContent_FieldCommentsDiv').style.display = "none";
			if (this.document.getElementById('ShowCommentsButton'))
				this.document.getElementById('ShowCommentsButton').style.display = "inline";
			if (this.document.getElementById('HideCommentsButton'))
				this.document.getElementById('HideCommentsButton').style.display = "none";
			if (this.document.getElementById('UploadDocumentDiv'))
				this.document.getElementById('UploadDocumentDiv').style.display = "none";

			if (this.document.getElementById('ServicePartsDiv'))
				this.document.getElementById('ServicePartsDiv').style.display = "none";
			if (this.document.getElementById('ShowPartsButton'))
				this.document.getElementById('ShowPartsButton').style.display = "inline";
			if (this.document.getElementById('HidePartsButton'))
				this.document.getElementById('HidePartsButton').style.display = "none";

			if (this.document.getElementById('DocumentDiv'))
				this.document.getElementById("DocumentDiv").style.display = "none";
			if (this.document.getElementById('ShowDocumentsButton'))
				this.document.getElementById('ShowDocumentsButton').style.display = "inline";
			if (this.document.getElementById('HideDocumentsButton'))
				this.document.getElementById('HideDocumentsButton').style.display = "none";
		}

		function Show(elementName) {
			hide();
			if (elementName == "AddComment") {
				this.document.getElementById('CustomerCommentsDiv').style.display = "inline-block";
				this.document.getElementById('ShowCommentsButton').style.display = "inline";
				this.document.getElementById('HideCommentsButton').style.display = "none";
			  $("#CommentTextBox").focus();
			}
			if (elementName == "UploadDocument") {
				this.document.getElementById('UploadDocumentDiv').style.display = "inline-block";
			}
			if (elementName == "ShowComments") {
				this.document.getElementById('CustomerCommentsDiv').style.display = "none";
				this.document.getElementById('ctl00_cphContent_FieldCommentsDiv').style.display = "inline-block";
				this.document.getElementById('ShowCommentsButton').style.display = "none";
				this.document.getElementById('HideCommentsButton').style.display = "inline";
			}
			if (elementName == "ShowParts") {
				this.document.getElementById('ServicePartsDiv').style.display = "inline-block";
				this.document.getElementById('ShowPartsButton').style.display = "none";
				this.document.getElementById('HidePartsButton').style.display = "inline";
			}
			if (elementName == "ShowDocuments") {
				this.document.getElementById("DocumentDiv").style.display = "inline-block";
				this.document.getElementById('ShowDocumentsButton').style.display = "none";
				this.document.getElementById('HideDocumentsButton').style.display = "inline";
			}
		}

		function SetText() {
			this.document.getElementById('<%= lblDocMsg.ClientID  %>').text = "Please Wait.";
		}

		function checkTextAreaMaxLength(textBox, e, length) {

			var mLen = textBox["MaxLength"];
			if (null == mLen)
				mLen = length;

			var maxLength = parseInt(mLen);
			if (!checkSpecialKeys(e)) {
				if (textBox.value.length > maxLength - 1) {
					if (window.event)//IE
						e.returnValue = false;
					else//Firefox
						e.preventDefault();
				}
			}
		}
		function checkSpecialKeys(e) {
			if (e.keyCode != 8 && e.keyCode != 46 && e.keyCode != 37 && e.keyCode != 38 && e.keyCode != 39 && e.keyCode != 40)
				return false;
			else
				return true;
		}
	
		function OnRequestStart(target, arguments) {
			if (arguments.get_eventTarget().indexOf("btnUpload") > -1) {
				arguments.set_enableAjax(false);
			}
		}

    function SetTicketTitle() {
      var jqTicketNumber = $("#TicketNumberField");
      if (jqTicketNumber.length == 0 || jqTicketNumber.html() == "") return;
      document.title = "Ticket #" + jqTicketNumber.html();
    }

		$(function() {
		  SetTicketTitle();
		});
	</script>
	<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
		<AjaxSettings>
			<telerik:AjaxSetting AjaxControlID="Panel1">
				<UpdatedControls>
					<telerik:AjaxUpdatedControl ControlID="Panel1" LoadingPanelID="radLoad" />
				</UpdatedControls>
			</telerik:AjaxSetting>
		</AjaxSettings>
	</telerik:RadAjaxManager>
	<asp:HiddenField ID="TicketServiceNumberHiddenField"  Value="" runat="server" />
	<%--<asp:Table CssClass="TableType1" ID="TopLinksTable" runat="server" Visible="true">
    <asp:TableRow>
        <asp:TableCell CssClass="TableCellAlignLeft">
            <asp:HyperLink ID="HyperLinkActiveTickets" NavigateUrl="./default.aspx" Text="View Active Tickets" runat="server" />
        </asp:TableCell><asp:TableCell CssClass="TableCellAlignCenter">
            <asp:HyperLink ID="HyperLinkInactiveTickets" NavigateUrl="./default.aspx?HIST=Y" Text="View Closed Tickets" runat="server" />
        </asp:TableCell><asp:TableCell CssClass="TableCellAlignRight">
            <asp:HyperLink ID="HyperLinkCreateNewTicket" NavigateUrl="./create.aspx" Text="Create New Ticket" runat="server" />
        </asp:TableCell></asp:TableRow>
 </asp:Table>--%>
	<asp:Table CssClass="TableType1" ID="TopMasterAccountLinks" runat="server" Visible="false">
		<asp:TableRow>
			<asp:TableCell CssClass="TableCellAlignLeft">
				<asp:HyperLink CssClass="" ID="Customer_HyperLink" NavigateUrl="~/customers/default.aspx" runat="server" Text="View Customer" />
			</asp:TableCell><asp:TableCell CssClass="TableCellAlignLeft">
				<asp:HyperLink CssClass="" ID="Printable_HyperLink" NavigateUrl="#" runat="server" Text="Printable Version" />
			</asp:TableCell></asp:TableRow></asp:Table><asp:Table ID="CustomerTable" CssClass="TableType1" runat="server">
		<asp:TableRow>
			<asp:TableCell ID="CustomerColumnHeader" CssClass="TableCellAlignLeft" Font-Bold="true" runat="server" Text="Customer:" />
			<asp:TableCell ID="SiteColumnHEader" CssClass="TableCellAlignLeft" Font-Bold="true" runat="server" Text="Site:" />
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell ID="CustomerNameField" Text="" CssClass="TableCellAlignLeft" runat="server" />
			<asp:TableCell ID="SiteNameField" Text="" CssClass="TableCellAlignLeft" runat="server" />
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell ID="CustomerAddress1Field" CssClass="TableCellAlignLeft" Text="" runat="server" />
			<asp:TableCell ID="SiteAddress1Field" CssClass="TableCellAlignLeft" Text="" runat="server" />
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell ID="CustomerAddress2Field" CssClass="TableCellAlignLeft" Text="" runat="server" />
			<asp:TableCell ID="SiteAddress2Field" CssClass="TableCellAlignLeft" Text="" runat="server" />
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell ID="CustomerAddress3Field" CssClass="TableCellAlignLeft" Text="" runat="server" />
			<asp:TableCell ID="SiteAddress3Field" CssClass="TableCellAlignLeft" Text="" runat="server" />
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell ColumnSpan="2" ID="MasterAccountField" CssClass="TableCellAlignLeft" Text="" runat="server">
				<asp:Label CssClass="MediumLabel" ID="MasterAccountLabel" runat="server" Text="Master Account: " Visible="false" />
				<asp:Label CssClass="SmallLabel" ID="MasterAccountText" runat="server" Text="" Visible="false" />
			</asp:TableCell></asp:TableRow></asp:Table><asp:Table ID="SystemTable" CssClass="TableType2" runat="server">
		<asp:TableRow>
			<asp:TableCell ID="SystemCustomerNumberHeader" CssClass="TableCellAlignRight" Font-Bold="true" runat="server" Text="System:" />
			<asp:TableCell ID="SystemCustomerNumberField" CssClass="TableCellAlignLeft" runat="server" Text="" />
			<asp:TableCell ID="SystemWarrentyHeader" CssClass="TableCellAlignRight" Font-Bold="true" runat="server" Text="Warranty:" />
			<asp:TableCell ID="SystemWarrantyField" CssClass="TableCellAlignLeft" runat="server" Text="" />
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell ID="SystemTypeCodeHeader" CssClass="TableCellAlignRight" Font-Bold="true" runat="server" Text="Type:" />
			<asp:TableCell ID="SystemTypeCodeField" CssClass="TableCellAlignLeft" runat="server" Text="" />
			<asp:TableCell ID="SystemExpiresHeader" CssClass="TableCellAlignRight" Font-Bold="true" runat="server" Text="Expires:" />
			<asp:TableCell ID="SystemExpiresField" CssClass="TableCellAlignLeft" runat="server" Text="" />
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell ID="SystemPanelHeader" CssClass="TableCellAlignRight" Font-Bold="true" runat="server" Text="Panel:" />
			<asp:TableCell ID="SystemPanelField" CssClass="TableCellAlignLeft" runat="server" Text="" />
			<asp:TableCell ID="SystemServiceLevelHeader" CssClass="TableCellAlignRight" Font-Bold="true" runat="server" Text="Service Level:" />
			<asp:TableCell ID="SystemServiceLevelField" CssClass="TableCellAlignLeft" runat="server" Text="" />
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell ID="SystemLocationHeader" CssClass="TableCellAlignRight" Font-Bold="true" runat="server" Text="Location:" />
			<asp:TableCell ID="SystemLocationField" CssClass="TableCellAlignLeft" runat="server" Text="" />
			<asp:TableCell ID="SystemNextInspectionHeader" CssClass="TableCellAlignRight" Font-Bold="true" runat="server" Text="Next Inspection:" />
			<asp:TableCell ID="SystemNextInspectionField" CssClass="TableCellAlignLeft" runat="server" Text="" />
		</asp:TableRow>
	</asp:Table>
	<asp:Table ID="TicketTable" CssClass="TableType1" runat="server">
		<asp:TableRow>
			<asp:TableCell CssClass="row-label" ID="TicketNumberHeader" runat="server" Text="Ticket Number:" />
			<asp:TableCell CssClass="TableCellAlignLeft" ID="TicketNumberField" runat="server" ClientIDMode="Static" Text="" />
			<asp:TableHeaderCell CssClass="TableCellAlignCenter" Width="60%" ID="CustomerCommentField" RowSpan="14" runat="server">
				<div id="CustomerCommentsDiv" style="display: none;">
					<asp:Label CssClass="MediumLabel" ID="CommentLabel" Text="Comment:" runat="server" />
					<asp:TextBox CssClass="TextArea" Columns="48" ID="CommentTextBox" Rows="6" runat="server" TextMode="MultiLine" ClientIDMode="Static" />
					<asp:Button CssClass="SmallButton" ID="SubmitButton" OnCommand="SubmitButton_OnClick" runat="server" Text="Submit" />
					<input type="button" class="SmallButton" id="CancelButton" value="Cancel" onclick="hideCommentControls();" />
					<asp:Label ID="lblCustCommentMsg" runat="server" ForeColor="Red" Text="" />
				</div>
				<div id="FieldCommentsDiv" style="display: inline-block;" runat="server">
					<asp:Label CssClass="MediumLabel" ID="CommentsLabel" Text="Comments Entered:" runat="server" />
					<br />
					<asp:TextBox CssClass="TextArea" Columns="48" ID="FieldCommentsTextBox" Rows="10" runat="server" TextMode="MultiLine" BackColor="LightGray" />
				</div>
				<div id="ServicePartsDiv" style="display: none;">
					<asp:Label CssClass="MediumLabel" ID="ServicePartsLabel" Text="Parts:" runat="server" />
					<telerik:RadGrid AllowPaging="false" AllowSorting="false" AutoGenerateColumns="false" CssClass="TextArea" ID="RadGridServiceParts" Width="420px" runat="server">
						<MasterTableView>
							<Columns>
								<telerik:GridBoundColumn DataField="Part_Code" HeaderText="Part #" UniqueName="Part_Code" ItemStyle-Width="20%" />
								<telerik:GridBoundColumn DataField="Part_Description" HeaderText="Description" UniqueName="Part_Description" ItemStyle-Width="40%" />
								<telerik:GridBoundColumn DataField="Location" HeaderText="Location" UniqueName="Location" ItemStyle-Width="40%" />
							</Columns>
						</MasterTableView>
					</telerik:RadGrid>
				</div>
				<div id="DocumentDiv" style="display: none;">
					<asp:Label CssClass="MediumLabel" ID="lblDocumentLabel" Text="Documents:" runat="server" />
					<br />
					<telerik:RadGrid AllowPaging="false" AllowSorting="false" AutoGenerateColumns="false" CssClass="TextArea" ID="rgUploadedDocuments" Width="420px" runat="server" OnNeedDataSource="rgUploadDocuments_OnNeedDataSource">
						<MasterTableView DataKeyNames="Document_Id">
							<Columns>
								<telerik:GridTemplateColumn HeaderText="Description" ItemStyle-Width="40%">
									<ItemTemplate>
										<asp:Label ID="lblUserDesc" runat="server" Text='<%# Eval("UserDescription").ToString().Length >20 ? Eval("UserDescription").ToString().Substring(0,20)+"..." : Eval("UserDescription") %>' />
									</ItemTemplate>
								</telerik:GridTemplateColumn>
								<%--  <telerik:GridBoundColumn DataField="UserDescription" HeaderText="Description" UniqueName="UserDescription" ItemStyle-Width="20%" />--%>
								<telerik:GridBoundColumn DataField="UploadDate" HeaderText="Uploaded Date" UniqueName="UploadDate" ItemStyle-Width="40%" />
								<%--  <telerik:GridButtonColumn ButtonType="LinkButton" CommandName="View" CommandArgument='<%Eval(Container.DataItem,"Document_Id") %>' Text="View" UniqueName="View" /> --%>
								<telerik:GridTemplateColumn>
									<ItemTemplate>
										<asp:LinkButton ID="lbDownload" runat="server" Text="View" CommandArgument='<%# Eval("Document_Id") %>'
											CommandName="View" OnCommand="rgUploadedDocuments_ItemCommand" />
									</ItemTemplate>
								</telerik:GridTemplateColumn>
							</Columns>
						</MasterTableView>
					</telerik:RadGrid>
				</div>
				<div id="UploadDocumentDiv" style="display: none;">
					<telerik:RadAjaxPanel ID="UploadDocsAjaxPanel" runat="server" ClientEvents-OnRequestStart="OnRequestStart"
						LoadingPanelID="radUpload">
						<asp:Label CssClass="MediumLabel" ID="lblUploadDocuments" Text="Upload Documents:"
							runat="server" />
						<asp:Label ID="lblFilesDocs" Text="Description" runat="server" />
						<asp:TextBox ID="txtFileDes" runat="server" MaxLength="50" /><br />
						<asp:FileUpload ID="fuDoc" runat="server" />&nbsp;&nbsp;
                        <asp:Label ID="Label12" Text="(File should not be over 1 megabyte)" runat="server" /><br />
						<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" /><br />
						<asp:Label ID="lblDocMsg" runat="server" Text="" ForeColor="Red" /><br />
						<telerik:RadAjaxLoadingPanel ID="radLoad" runat="server">
							Your Document is Uploading, Please Wait a Moment.
						</telerik:RadAjaxLoadingPanel>
					</telerik:RadAjaxPanel>
				</div>
			</asp:TableHeaderCell></asp:TableRow>
    <asp:TableRow>
			<asp:TableCell CssClass="row-label" ID="StatusHeader"  runat="server" Text="Status:" />
			<asp:TableCell CssClass="TableCellAlignLeft" ID="StatusField" runat="server" Text="" />
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell CssClass="row-label" ID="ProblemHeader"  runat="server" Text="Problem:" />
			<asp:TableCell CssClass="TableCellAlignLeft" ID="ProblemField" runat="server" Text="" />
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell CssClass="row-label" ID="PriorityHeader" runat="server" Text="Priority:" />
			<asp:TableCell CssClass="TableCellAlignLeft" ID="PriorityField" runat="server" Text="" />
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell CssClass="row-label" ID="ContactHeader" runat="server" Text="Contact:" />
			<asp:TableCell CssClass="TableCellAlignLeft" ID="ContactField" runat="server" Text="" />
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell CssClass="row-label" ID="PhoneHeader" runat="server" Text="Phone:" />
			<asp:TableCell CssClass="TableCellAlignLeft" ID="PhoneField" runat="server" Text="" />
		</asp:TableRow>
		<%--        <asp:TableRow>
            <asp:TableCell CssClass="TableCellAlignRight" ID="CustomerCommentsHeader" Font-Bold="true"
                runat="server" Text="Customer Comments:" />
            <asp:TableCell CssClass="TableCellAlignLeft" ID="CustomerCommentsField" runat="server"
                Text="" />
        </asp:TableRow>--%>
		<asp:TableRow>
			<asp:TableCell CssClass="row-label" ID="TechnicianHeader" runat="server" Text="Technician:" />
			<asp:TableCell CssClass="TableCellAlignLeft" ID="TechnicianField" runat="server" Text="" />
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell CssClass="row-label" ID="ScheduledForHeader" runat="server" Text="Scheduled For:" />
			<asp:TableCell CssClass="TableCellAlignLeft" ID="ScheduledForField" runat="server" Text="" />
		</asp:TableRow>
		<asp:TableRow ID="trDispatched">
			<asp:TableCell CssClass="row-label" ID="tcDispatchedLabel" runat="server" Text="Last Dispatched :" />
			<asp:TableCell CssClass="TableCellAlignLeft" ID="tcDispatchedText" runat="server" Text="" />
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell CssClass="row-label" ID="CreatedOnHeader" runat="server" Text="Created On:" />
			<asp:TableCell CssClass="TableCellAlignLeft" ID="CreatedOnField" runat="server" Text="" />
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell CssClass="row-label" ID="CreatedByHeader" runat="server" Text="Created By:" />
			<asp:TableCell CssClass="TableCellAlignLeft" ID="CreatedByField" runat="server" Text="" />
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell CssClass="row-label" ID="ResolutionHeader" runat="server" Text="Resolution:" />
			<asp:TableCell CssClass="TableCellAlignLeft" ID="ResolutionField" runat="server" Text="" />
		</asp:TableRow>
		<asp:TableRow>
			<asp:TableCell CssClass="row-label" ID="InvoiceNumberHeader" runat="server" Text="Invoice:" />
			<asp:TableCell CssClass="TableCellAlignLeft" ID="InvoiceNumberField" runat="server" Text="" />
		</asp:TableRow>
    <asp:TableRow ID="UserDef3Row" runat="server">
      <asp:TableCell Visible="False" CssClass="row-label" runat="server">Next Action:</asp:TableCell>
      <asp:TableCell Visible="False" CssClass="TableCellAlignLeft" runat="server">
        <asp:DropDownList ID="UserDef3DropDown" ClientIDMode="Static" DataTextField="Description" DataValueField="Id" runat="server" />
        <img class="hidden" src="/Customizable/progress-ring-smaller.gif" alt="Submitting ..." title="Submitting ..." /><br />
        <asp:HiddenField ID="UserDef3TicketId" ClientIDMode="Static" runat="server"></asp:HiddenField>
        <span id="UserDef3Result" class="hidden"></span>
      </asp:TableCell>
    </asp:TableRow>
	</asp:Table>
	<asp:Table CssClass="TableType1" ID="PartsAndComments" runat="server">
		<asp:TableRow>
			<asp:TableCell>
				<asp:Label CssClass="invoice_standard_label" ID="NoPartsText" runat="server" Text="No Parts" Visible="true" />
				<div id="HasPartsDiv" runat="server" visible="false">
					<input type="button" id="ShowPartsButton" onclick="Show('ShowParts');" class="MediumButton" style="display: inline;" value="Show Parts" />
					<input type="button" id="HidePartsButton" onclick="Show('ShowComments');" class="MediumButton" style="display: none;" value="Hide Parts" />
				</div>
			</asp:TableCell><asp:TableCell ID="tcAddComments" runat="server">
				<input type="button"  id="AddCommentButton" onclick="Show('AddComment');" value="Add Comment" class="MediumButton" />
			</asp:TableCell><asp:TableCell ID="tcShowComments" runat="server">
        <input type="button" id="ShowCommentsButton" onclick="Show('ShowComments');" class="MediumButton" style="display: none;" value="Show Comments" />
        <input type="button" id="HideCommentsButton" onclick="hide();" class="MediumButton" style="display: inline;" value="Hide Comments" />
			</asp:TableCell><asp:TableCell>
				<%--  <asp:Button ID="ShowDocumentsButton1" OnClientClick="return showDocuments();" class="MediumButton"  text="Show Documents" runat="server"  />--%>
				<asp:Panel ID="pnlDocButtons" runat="server">
					<input type="button" id="ShowDocumentsButton" onclick="Show('ShowDocuments');" class="MediumButton" style="display: inline;" value="Show Documents" />
					<input type="button" id="HideDocumentsButton" onclick="Show('ShowComments');" class="MediumButton" style="display: none;" value="Hide Documents" />
				</asp:Panel>
			</asp:TableCell><asp:TableCell>
			  <asp:Panel ID="pnlDocUploadButton" runat="server">
			    <input type="button"  id="UploadDocumentButton" onclick="Show('UploadDocument');" value="Upload Document" class="MediumButton" />
			  </asp:Panel>
			</asp:TableCell></asp:TableRow></asp:Table>

</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cphScripts" runat="server">
</asp:Content>