<? global $vis_language; ?>
<section  class="container m-t-md">
<div class="row">
      <div class="col-md-12">
            <section class="panel shadow-none">
			 <div class="panel-heading b-b"> <h4 class="panel-title1"><? echo $vis_language['TXTADDTOPIC']; ?></h4></div></div>
            <div class="panel-body">
					<div class="col-md-12">
					  <div class="wrapper">
						  <div class="row m-b-sm">
							<label class="col-sm-2 control-label"><? echo $vis_language['TXTTOPICTITLE']; ?></label>
                            <div class="col-sm-8"><input type="text" class="form-control input-sm" name="vis_forum_title" id="vis_forum_title" onblur="set_topic_url()"></div>
							 <input type="hidden" name="vis_topic_url" id="vis_topic_url" value=""/>
						  </div>
						  <div class="row m-b-sm">
							<label class="col-sm-2 control-label"><? echo $vis_language['TXTMESSAGE']; ?></label>
							<div class="col-sm-8"><textarea name="vis_topic_content" id="vis_new_topic_content" class="form-control"><?php if(isset($signature) && $signature!='') echo $signature; ?></textarea></div>
						  </div>
						  <div class="row m-b-sm">
						     <label class="col-sm-2 control-label"><? echo $vis_language['TXTPOSTTOPICIN']; ?></label>
							 <div class="col-sm-8"> 
								<select name="vis_forum" id="vis_forum" class="form-control input-sm<?=(!is_mobile())?' selectpicker':'';?>" 
								<?=(count($forum_category)>10 && !is_mobile())?' data-live-search="true"':'';?>>
								<? for($i=0;$i<count($forum_category);$i++)
								   { 
									
									   echo '<optgroup label="'.$forum_category[$i]['category_name'].'">';
									   for($j=0;$j<count($forum_list[$i]);$j++)
									   { 
										   $forumIdSelect = ($forumId==$forum_list[$i][$j]['forum_id'])?"selected='selected'":"";
											echo '<option '.$forumIdSelect.' value="'.$forum_list[$i][$j]['forum_id'].'">'.$forum_list[$i][$j]['forum_title'].'</option>';
									   } 
									   echo '</optgroup>'; 
								   } ?></select>
							 </div>
						  </div>
						  <div class="row m-b-sm">
                            <label class="col-sm-2 control-label"><? echo $vis_language['TXTATTACHFILES']; ?></label>
								<div class="col-sm-2 m-t">
                                  <span class="btn btn-link link btn_upload_file vis_font_size_none text-primary" id="vis_attach_file"><?= $vis_language['TXTATTACHFILE']; ?> <input class="form-control" type="file" id="fileupload1"></span>
                                  <div style="display:none;" id="vis_attachments"></div>
                             </div>
						  </div>			  

                          <div class="row m-b-sm">
								 <label for="Message" class="col-sm-2 control-label"></label>
								 <div id="vis_new_attachments1" class="col-sm-8 p-l-none"></div>
                          </div>

						  <div class="row m-b-sm">
                            <label for="Password" class="col-sm-2 control-label"><? echo $vis_language['TXTIMGVERIFY']; ?></label>
                            <div class="col-sm-8">

									<div class="col-sm-10">	
									  <img src="<?= VIS_PATH_TEMPLATE ?>get_captcha.php?clr=<? echo str_replace("#",'',VIS_THEME_COLOR); ?>" alt="" id="captcha" class="col-sm-4"/>
									  <div id="refresh" class="col-sm-3 m-t link"><i class="vh vh-lg vh-refresh"></i> <? echo $vis_language['TXTREFRESH']; ?></div>
									</div> 
                              <input type="text" class="form-control input-sm" name="captchacode"  id="captchacode" autocomplete="off"/>
                            </div>
                          </div>

					  <div class="line line-dashed b-b line-lg pull-in"></div>
					  </div> <!-- /.wrapper -->
					</div> <!-- /.col-md-12 -->

					<div class="col-lg-offset-2 col-lg-8 m-b-lg">
                                            <button type="submit" id="btn_submit_atricle" class="btn btn-primary" onclick="submit_form();"><? echo $vis_language['TXTADD']; ?></button>
						  
						  <input type="hidden" name="vis_parent_type" value="9" />					  

						  <input type="hidden" id="vis_forum_id" name="vis_forum_id" value="<? echo $operation['vis_category_id']; ?>" />

					</div>
            </div>
          </section>
        </div>
	 </div>
	 
<script>

	$('#refresh').click(function() {  
			change_captcha();
	 });

	function change_captcha()
	 {
	 	document.getElementById('captcha').src="<?= VIS_PATH_TEMPLATE ?>get_captcha.php?clr=<? echo str_replace("#",'',VIS_THEME_COLOR); ?>&rnd=" + Math.random();
	 }

 var curr_stamp=0;
  function submit_form() {
    if(curr_stamp==0 || (curr_stamp < (Date.now()-10000))){
        curr_stamp = Date.now();
        $.ajax({
           url: 'index.php',
           data: {'vis_module':"forums", 'vis_operation':"add_topic", 'vis_domain_id':<? echo VIS_DOMAIN;?>, 'vis_forum':$("#vis_forum").val(), 'vis_forum_title':$("#vis_forum_title").val(), 'vis_topic_url':$("#vis_topic_url").val(), 'vis_attachments':$("#vis_attachments").html(),'vis_forum_topic_post_area':$("#vis_new_topic_content").val() , 'captchacode':$("#captchacode").val()},
           type: "POST",
           dataType: "json",
           success: function(data) { 
               if(data.vis_submitted=='true')
               {
                   $(window).scrollTop(0);
                   $("#vis_submit_msg_div").show(); $("#vis_submit_msg_div").html("<?= $vis_language['MSGSUCCOPRT'];?>");
                   setTimeout(function(){window.location = "index.php?/forums/forums"}, 500);

               } else if(data.vis_submitted=='True'){
                   $(window).scrollTop(0);
                   $("#vis_submit_err_div").show(); $("#vis_submit_err_div").html(data.vis_msg);
                   setTimeout(function(){window.location = "index.php?/forums/forums"}, 1000);

               } else {
                   $(window).scrollTop(0);
                   $("#vis_submit_err_div").show(); $("#vis_submit_err_div").html(data.vis_msg);
                   setTimeout(function(){$("#vis_submit_err_div").hide();},10000);
               }	 
           }
       });
    }
}

	function vis_remove_attachment(attach_id){
	 $.ajax({
        url: 'index.php',
        data: {'vis_module':"ticket", 'vis_operation':"remove_attachment", 'vis_attachment_id':attach_id },
        type: "POST",
        success: function(data) {  }
    });
   }

	$(function () {
		var url = 'index.php?vis_module=ticket&vis_operation=upload_file&vis_parent_type=9';
		$('#fileupload1').fileupload({
			url: url,
			done: function (e, data) {
			$("#vis_new_attachments1").append(data.result);
			}
		});

	});
  <? if(!defined('VIS_HEAD_MENU_HTML_EDITOR') || VIS_HEAD_MENU_HTML_EDITOR==1) { ?>    
	$(function(){
		$('#vis_new_topic_content').redactor({
			buttonSource: true,
            minHeight: 180, // pixels
            maxHeight: 180,
            imageUpload: "index.php?vis_tmpst="+new Date().getTime()+"&vis_module=ticket&vis_operation=upload_file&vis_static_area=editor_image_upload",
            imageUploadParam: 'files',            
            focus: true,
            plugins: ['source'],
			deniedTags: ['html', 'head', 'link', 'body', 'meta', 'script','applet']
		});
	});
  <? } ?>
	function set_topic_url(){
       var title = document.getElementById('vis_forum_title').value;
       title = title.replace(/[&\/\\#,+()$@^!`=;|~%.'":*?<>{}]/g, '');
       var url = title.trim().replace(/ +(?=)/g,"-");
       document.getElementById('vis_topic_url').value=url;
   }
	 </script>

<script src="<? echo VIS_PATH_SCRIPT; ?>file-upload/jquery.ui.widget.js"></script>
<script src="<? echo VIS_PATH_SCRIPT; ?>file-upload/jquery.fileupload.js"></script>
<script src="<?= VIS_PATH_SCRIPT; ?>file-input/bootstrap-filestyle.min.js"></script>
