<div id="rightBox">
	<table border="0" cellpadding="0" cellspacing="0" class="rightBox_table">
		<tr>
			<td><img src="/files/contentBoxTop.jpg" alt="" width="690" height="16"/></td>
		</tr>
		<tr>
			<td valign="top" style="background-image: url(/files/contentBoxMiddle.jpg); width: 690px; height: 547px; background-position: center top; background-repeat: no-repeat;">
				<div id="rightBox_content">
					<div class="content_title">Nowa wiadomość</div>
					<br/>
					<?php
						if(isset($form_success))
						{
							if($form_success)
								echo '<p class="info_box">Wiadomość została wysłana.<p>';
							else
								echo '<p class="info_box">Wystapił bład(y).<p>';								
						}
					?>
					<form action="/tickets/add" id="add_ticket" name="add_ticket" method="post">
						<input type="hidden" name="add_ticket" value="1"/>
						<table id="hor-minimalist-b" style="width:100%">
								<!-- ODBIORCA -->
								<?php
									echo '<input type="hidden" name="user_id" value="'.$user_account['id'].'">';
								?>
								<tr><td width="140">DO</td>
									<td>
										<select name="odbiorca" style="width:150px;">
											<?php
												foreach($odbiorcy as $key=>$value)
												{
													echo '<option value="'.$value->account_id.'"';
														if(isset($form_data['odbiorca']))
														{
															if($form_data['odbiorca'] == $value->account_id)
																echo ' selected="selected" ';
														} 
													echo '>'.$value->name.'</option>';													
												} 
											?>
										</select>	
									</td>
								</tr>
								<!-- TEMAT -->
								<tr><td>Temat</td><td><input id="temat" type="text" value="<?php if(isset($form_data['odbiorca'])) echo $form_data['temat']; ?>" name="temat" />
									<span id="temat_error" class="error_info">
									<?php
										if(isset($errros['temat']))
										{
											echo $errros['temat'];										
										}
									?>
									</span>
								</td></tr>
								
								<!-- PRIORYTET -->
								<tr><td>Prioretet</td>
									<td>
										<select name="priorytet" style="width:150px;">
											<?php
												foreach($priorytety as $key=>$value)
												{
													echo '<option value="'.$value->id.'"';
														if(isset($form_data['priorytet']))
														{
															if($form_data['priorytet'] == $value->id)
																echo ' selected="selected" ';
														} 													
													echo '>'.$value->nazwa.'</option>';													
												} 
											?>											
										</select>	
									</td>
								</tr>
								
								<!-- KATEGORIA -->
								<tr><td>Kategoria</td>
									<td>
										<select name="kategoria" style="width:150px;">
											<?php
												foreach($kategorie as $key=>$value)
												{
													echo '<option value="'.$value->id.'"';
														if(isset($form_data['kategoria']))
														{
															if($form_data['kategoria'] == $value->id)
																echo ' selected="selected" ';
														} 													
													echo' >'.$value->nazwa.'</option>';													
												} 
											?>											
										</select>										
									</td>
								</tr>
								
								<!-- STATUS -->
								<tr><td>Status</td>
									<td>
										<select name="status" style="width:150px;">
											<?php
												foreach($statusy as $key=>$value)
												{
													if($value->id == 2)
														continue;
													echo '<option value="'.$value->id.'"';
														if(isset($form_data['status']))
														{
															if($form_data['status'] == $value->id)
																echo ' selected="selected" ';
														}													
													echo '>'.$value->nazwa.'</option>';													
												} 
											?>											
										</select>												
									</td>
								</tr>
								
								<!-- WIADOMOSC -->
								<tr><td valign="top">Wiadomość</td>
								<td><textarea id="wiadomosc" cols="1" rows="1" name="wiadomosc" style="border: 1px solid black; overflow: hidden; width: 100%; height: 142px; text-align: left;"><?php if(isset($form_data['wiadomosc'])) echo $form_data['wiadomosc']; ?></textarea>
								<br/>
									<span id="wiadomosc_error" class="error_info">
										<?php
											if(isset($errros['wiadomosc']))
											{
												echo $errros['wiadomosc'];										
											}
										?>
									</span>	
								</tr>
								
								<!-- ZALACZNIK -->
								<tr>
									<td valign="top">Załącznik</td>
									<td>
										<script type="text/javascript" src="/files/js/jquery-1.3.2.min.js"></script>
										<script type="text/javascript" src="/files/js/jquery.uploadify.v2.1.0.min.js"></script>
										<script type="text/javascript" src="/files/js/swfobject.js"></script>
										<script type="text/javascript">
											
											
											function validateWiadomosc()
											{
												isValid = true;
												if(jQuery.trim($("#wiadomosc").val()) == '')
													{
														$('#wiadomosc_error').text("Pole wiadomosc nie może być puste");
														isValid = false;
													}	
													else
													{
														$('#wiadomosc_error').text("");
													}											
												return isValid;
											}
											function validateTemat()
											{
												isValid = true;
												if(jQuery.trim($("#temat").val()) == '')
													{
														$('#temat_error').text("Pole temat nie może być puste");
														isValid = false;
													}
												else
													{
														$('#temat_error').text("");
													}																				
												return isValid;												
											}
											
							
											
											
											$(document).ready(function() {
												    var upload 		= false;
													var file_number = 0; 
													var currentDateTime = currentDateTime();
													$("#add_ticket").submit(function() {
														
														if(!validateTemat() || !validateWiadomosc())
															return false;
														
														if (!upload) {
															return true;
														}
														else {
															$('#uploadify').uploadifyUpload();
															return false;
														}
													})
												
													function addFileToList(id,filename)
													{
														elem = "<input type='hidden' id="+id+" name='files[]' value='"+currentDateTime+filename+"'/>";							
														var htmlStr = $("#files").html();
      													$("#files").html(htmlStr+elem);
														file_number++;
	
													}
													
													$("#wiadomosc").focus(function () {
												         $('#temat_error').text("");
												    });
													$("#wiadomosc").blur(function () {
												       validateWiadomosc();
												    });	
														
													$("#temat").focus(function () {
												         $('#wiadomosc_error').text("");
												    });
													$("#temat").blur(function () {
												       validateTemat();
												    });														
																								

													
													function clearFileList()
													{
														var htmlStr = $("#files").html();
      													$("#files").html('');
														file_number = 0;
													} 
													
													function currentDateTime()
													{
														var dteNow = new Date();
														
														var day = dteNow.getDate()
														var month = dteNow.getMonth()+1;
														var year = dteNow.getFullYear();
														var hour = dteNow.getHours();
														var minute= dteNow.getMinutes();
														var second = dteNow.getSeconds();
														return year+'.'+month+'.'+day+'_'+hour+':'+minute+':'+second+'__';
				
													}
													
												$("#uploadify").uploadify({
													'uploader'       : '/files/uploadify/uploadify.swf',
													'script'         : '/files/uploadify/uploadify.php',
													'checkScript'	 : '/files/uploadify/check.php',  
													'cancelImg'      : '/files/uploadify/cancel.png',
													'buttonText'	 : 'Select Files', 
													'folder'         : '/files/uploads',
													'queueID'        : 'fileQueue',
													'sizeLimit'		 : '1024000',
										            'onError'   : 		function (a, b, c, d) {
														                 if (d.status == 404)
														                    alert('Could not find upload script');
																		 else if (d.type === "HTTP")
														                   alert('error '+d.type+": "+d.status);
														                 else if (d.type ==="File Size")
														                   alert(c.name+' '+d.type+' Limit:+Math.round(d.sizeLimit/1024)');
														                 else
														                   alert('error '+d.type+": "+d.text);             
														              },													
													'scriptData' 	 : {'filename_prefix':currentDateTime},
													'onClearQueue'	 : function(a) {clearFileList(); upload = false;},
													'onSelect'		 : function(a,b,c){upload = true;},
					         						'onComplete'	 : function(a, b, c, d, e){ addFileToList(b,c.name);},  
         											'onAllComplete'  : function(event,data){  
																			upload = false;
            							  									$("form#add_ticket").submit();
         																},  													
													'auto'           : false,
													'multi'          : true
												});
											});
										</script>
											<div id="fileQueue"></div>
											<div id="files"></div>
											<input type="file" name="uploadify" id="uploadify" />
											<a class="anuluj_upload_form" href="javascript:jQuery('#uploadify').uploadifyClearQueue()">Anuluj</a>																				
									</td>
								</tr>
							
								<tr><td colspan="2" style="border-bottom:0px;">
										<div class="ticket_menu_item"><a href="/tickets">Anuluj</a></div>
										<input class="ticket_menu_item" type="image" id="submit_add_ticket" value="Wyślij" />
									</td>
								</tr>
							</tbody>
						</table>	
					</form>														
				</div>
			</td>
		</tr>
	</table>
</div>									