<script type="text/javascript" src="javascript/modules/support.js"></script>
<script type="text/javascript">
    function deleteFile(File_id)
    {
		var articleId = $('articleId').value;
        new Ajax.Request( 'index.php?fuse=knowledgebase&action=KB_DeleteArticleAttachment&articleId=' + articleId +'&File_id=' + File_id,
		                  {		                    
                              onLoading     : function(request) {resetStatus(lang('Loading'))},                              
		                      onComplete    : showResponse
		                  }
		                );
    }
    
    function showResponse(originalRequest)
	{	    
	    var response = originalRequest.responseText;
	    var arrayFiles = response.split('|');	    
	    var html = "";
	    if (response != 0){
    	    for (var i = 0; i < arrayFiles.length - 1; i++){
    	        var arrayAttachment = arrayFiles[i].split('**');
    	        var filename = arrayAttachment[0];
    	        var fileid = arrayAttachment[1];
    	        html = html + "<tr><td><a href='index.php?fuse=knowledgebase&action=KB_GetAttachment&file_id="+ filekey +" target='_blank'>" + filename + "</a></td><td onclick='deleteFile('"+ filename +"','"+ fileid + "')' style='cursor:hand'><b><u>[l]Delete[/l]</u></b></td></tr>";
    	    }
	    }else{
    	        html = html + "<tr><td colspan='2'>&nbsp;</td></tr>";	        
	    }
        unsetStatus(lang('Loaded'), 1000);
        window.location.reload( false );		                                 	    
	}

</script>

<form method="POST" action="index.php?fuse=knowledgebase&action=KB_SaveArticle" enctype="multipart/form-data">
    <table width="100%" cellpadding="0" cellspacing="0" border="0" >
        <tr>
            <td width="64%" valign="top">            
                <table style="width:100%;" cellpadding='0' border='0' cellspacing='0'>
            		<tr>
            			<td class='snapshot-header-left'></td>
            			<td class='snapshot-header'><span class='snapshot-header-text'>{ArticlesHeader}:</span></td>
            			<td class='snapshot-header' align="right">            
            			</td>
            			<td class='snapshot-header-right'></td>
            		</tr>
            	</table>                         
                <table width="100%" >
                    <tr>
                        <td width="1%" class="formLabel" valign="top" nowrap="true">[l]Categories[/l]{categoriesPopUp}:</td>
                        <td class="formField">
                            <input type="hidden" name="r_category[]" width="100" value="[lh]Category[/lh]" style="width:300px" />            
                            <select class=required name="category[]" multiple="multiple" size="8">
                                <!-- BEGIN DYNAMIC BLOCK: kbCategories -->
                                <option value="{catId}" {catSelected} >{catLabel}</option>
                                <!-- END DYNAMIC BLOCK: kbCategories -->
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <input type="hidden" id="articleId" name="articleId" value="{articleId}"> 
                        <td width="1%" class="formLabel">[l]Title[/l]:</td>
                        <td class="formField">
                            <input class=required type="text" name="title" width="100" value="{articleTitle}" style="width:300px" />
                            <input type="hidden" name="r_title" width="100" value="[lh]Title[/lh]" style="width:300px" />                
                        </td>
                    </tr>
                    <tr>
                        <td class="formLabel">[l]Author[/l]:</td>
                        <td class="formField">
                            <input type="text" class=required name="author" value="{articleAuthor}"style="width:300px" />
                            <input type="hidden" name="r_author" value="[lh]Author[/lh]"style="width:300px" />
                        </td>
                    </tr>
                    <tr>
                        <td class="formLabel">[l]Date Created[/l]:</td>
                        <td class="formField">
                            <input type="text" class="required" id="datecreated" name="datecreated" value="{articleDate}" style="width:300px" />
                            &nbsp;&nbsp;<img id="calButton" alt="" src="../images/dynCalendar.gif" style="cursor:pointer"/>
                            <script type="text/javascript">
                                Calendar.setup({
                                    inputField      : 'datecreated',
                                    ifFormat        : '{DATEFORMAT}',
                                    showsTime       : true,
                                    button          : 'calButton',
                                    weekNumbers     : false,
                                    step            : 1
                                });
                            </script>
                            <input type="hidden" name="r_datecreated" value="[lh]Date created[/lh]"style="width:300px" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" class="formField">&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="formField" valign="top" colspan="2">[l]<b>Excerpt:</b> Insert an excerpt of your article.[/l]<br>
                            <textarea id="excerpt" name="excerpt" cols="80" rows="3">{articleExcerpt}</textarea>
                        </td>
                    </tr>               
                    <tr>
                        <td class="formField" valign="top" colspan="2">[l]<b>Content[/l]:</b><br>       
                            <textarea id="content" name="content" cols="60" rows="12">{articleContent}</textarea>
                            <!-- BEGIN DYNAMIC BLOCK: richTextEditor -->
                            <script type="text/javascript">
                                showRichTextEditor("oContent", 600, '290px',
                                                    ['Undo','Redo','Hyperlink','JustifyLeft','JustifyCenter','JustifyRight','JustifyFull','Numbering','Bullets','|','LTR','RTL','XHTMLFullSource','StyleAndFormatting','TextFormatting','ListFormatting','BoxFormatting','ParagraphFormatting','CssText','|','FontName','FontSize','|','Bold','Italic','Underline','|','ForeColor','BackColor'
                                                    ],
                                                    "content",
                                                    "HTMLBody");
                            </script>
                            <!-- END DYNAMIC BLOCK: richTextEditor -->
                        </td>
                    </tr>
                    <!-- BEGIN DYNAMIC BLOCK: RelatedTopics -->
                    <tr>
                        <td class="formLabel" nowrap="true">
                            <b>[l]Related Articles[/l]</b>{articlesRelatedPopup}:</b><br>
                        </td>
                        <td class="formField">
                            <input type="text" name="relatedTopics" value="{relatedTopics}" size="50" />
                        </td>
                    </tr>
                    <!-- END DYNAMIC BLOCK: RelatedTopics -->                
                    <!-- BEGIN DYNAMIC BLOCK: attachfile -->
                    <TR>
                        <TD colspan=2><b>[l]Attach File:[/l]</b> {MAX FILE SIZE} {FILE_SIZE_POP_UP_STRING}<BR>
                            <div id="fileFieldsContainer"> 
                                <div id="fileFields_0" style="margin:2px 0 2px 0">
                                    <input type="file" value="" name="file_0" id="file_0"/> 
                                    <a style="visibility:hidden" href="#" onclick="javascript:remove(this);">[l]Delete[/l]</a> 
                                </div> 
                            </div>       
                        </TD>
                    </TR>        
                    <TR>
                        <TD colspan="2" align="left">
                            <a class='liveupdate' href="javascript:Clon('fileFields_0');">[l]Add a New File[/l]</a>
                        </TD>
                    </TR>        
                    <!-- END DYNAMIC BLOCK: attachfile -->
                    <!-- BEGIN DYNAMIC BLOCK: cantattachfile -->
                    <TR>
                        <TD colspan="2"><span style="color:red">{CANT_ATTACH_FILE}</span></TD>
                    </TR>
                    <!-- END DYNAMIC BLOCK: cantattachfile -->
                    
                    <!-- BEGIN DYNAMIC BLOCK: attachedFiles -->        
                    <TR>
                        <TD colspan=2><b>[l]Attached Files:[/l]</b> <BR>                  
                        </TD>
                    </TR>
                    <div id="attachedFiles">                
                        <!-- BEGIN DYNAMIC BLOCK: attachedFile-->
                        <tr>
                            <td><li style="list-style:none"><img src="templates/Raleigh/views/knowledgebase/images/icon_{fileExtension}.gif"></li>&nbsp;<a href="index.php?fuse=knowledgebase&action=KB_GetAttachment&file_id={File_id}" target="_blank">{Filename}</a></td>
                            <td onclick="deleteFile('{File_id}')" style="cursor:hand"><b><u>[l]Delete[/l]</u></b></td>
                        </tr>
                        <!-- END DYNAMIC BLOCK: attachedFile -->
                    </div>
                    <!-- END DYNAMIC BLOCK: attachedFiles -->                       
                    <!-- BEGIN DYNAMIC BLOCK: saveAsDraft -->                       
                    <tr>
                        <td class="formLabel" valign="top">
                    	    [l]Save article as draft[/l]:
                        </td>
                        <td class="formField">
                            <input type="checkbox" name="articleIsDraft" value="1" {isdraft}/>
                        </td>
                    </tr>
                    <!-- END DYNAMIC BLOCK: saveAsDraft -->                       
                    <!-- BEGIN DYNAMIC BLOCK: articleAccess -->        
                    <tr>
                        <td class="formLabel" nowrap="true">
                            <b>[l]Access[/l]:</b>
                        </td>
                        <td class="formField">
                            <select name="articleAccess">
                                <option value="{articleAccessValuePublic}" {articleAccessCheckedPublic} >[l]Public[/l]&nbsp;&nbsp;</option>
                                <option value="{articleAccessValueMembers}" {articleAccessCheckedMembers} >[l]Members-only[/l]&nbsp;&nbsp;</option>
                                <option value="{articleAccessValueStaff}" {articleAccessCheckedStaff} >[l]Staff-Only[/l]&nbsp;&nbsp;</option>
                            </select>
                            <!--
                            [l]Public[/l]&nbsp;<input type="radio" name="articleAccess" value="{articleAccessValuePublic}" {articleAccessCheckedPublic} />&nbsp;&nbsp;
                            [l]Members-only[/l]&nbsp;<input type="radio" name="articleAccess" value="{articleAccessValueMembers}" {articleAccessCheckedMembers} />&nbsp;&nbsp;
                            [l]Staff-Only[/l]&nbsp;<input type="radio" name="articleAccess" value="{articleAccessValueStaff}" {articleAccessCheckedStaff} />
                            -->
                        </td>
                    </tr>
                    <!-- END DYNAMIC BLOCK: articleAccess -->          
                    <!-- BEGIN DYNAMIC BLOCK: selectTicketTypes -->
                    <tr>
                        <td class="formLabel" valign="top">
                            <b>[l]Associate to a ticket type[/l]:</b>
                        </td>
                        <td class="formField">
                            <input type="checkbox" name="relateToTicketType" value="1" onclick="$('associatedTicketTypes').style.display = this.checked? '' : 'none'" {relateToTicketTypeChecked} />
                        </td>
                    </tr>
                    <tr id="associatedTicketTypes" style="display:{displayAssociatedTicketTypes}">
                        <td class="formLabel" valign="top">
                            <b>[l]Associated ticket types[/l]{relatedTicketTypesPopup}:</b>
                        </td>
                        <td class="formField">
                            <select name="relatedTicketTypes[]" multiple="true" size="5">
                                <!-- BEGIN DYNAMIC BLOCK: ticketTypes -->
                                <option value="{ticketTypeId}" {ticketTypeSelected} >{ticketTypeName}&nbsp;&nbsp;</option>
                                <!-- END DYNAMIC BLOCK: ticketTypes -->
                            </select>
                        </td>
                    </tr>
                    <!-- END DYNAMIC BLOCK: selectTicketTypes -->
                    <tr>
                        <td colspan="2" >
                            <input type="submit" class="button_large" value="[lh]Save Article[/lh]" onclick="check(form,form.elements.length);return false;"/>
                        </td>
                    </tr>        
                </table>
            </td>
            <td width="1%">&nbsp;</td>
            <td valign="top" width="35%" class="rowlabel">
                {articlesSidebar}            
            </td>    
        </tr>
    </table>
</form>
