<?php
session_start();
if($_SESSION['logInSucces'] == NULL){
	?><script type="text/javascript">window.location.href="index"</script><?
}
?>
			<div class="content-box">
				<div class="content-config">
					<div class="header-conf">
						<p>Novo Episodio</p>
					</div>

					<div class="conteudo-config">
						<div class="input-group">
							<span>TMDB ID Série</span>
							<input type="text" class="idSerie" placeholder="Digite o id da Série">
						</div>
						<div class="input-group">
							<span>Temporada</span>
							<input type="number" class="temporada" placeholder="Digite a Temporada">
						</div>
						<div class="input-group">
							<span>Numero episodio</span>
							<input type="number" class="epi" placeholder="Digite a Temporada">
						</div>
						<div class="input-group">
							<span>Link 1</span>
							<input type="text" class="link" placeholder="Link do Video DUB">
						</div>
						<div class="input-group">
							<span>Link 2</span>
							<input type="text" class="vidLinkLEG" placeholder="Link do Video LEG">
						</div>


						<div class="input-group">
							<span>Servidor 1</span>
							<div class="option-radio">
  								<input type="radio" name="lang" id="lang" checked="checked"  value="0"> <p>Padrao</p>
  								<input type="radio" name="lang" id="lang"   value="1"> <p>One Drive</p>
  							
  								<input type="radio" name="lang" id="lang"   value="2"> <p>Iframe</p>
							</div>
						</div>
						<div class="input-group">
							<span>Servidor 2</span>
							<div class="option-radio">
  								<input type="radio" name="lang2" id="lang2" checked="checked"  value="0"> <p>Padrao</p>
  								<input type="radio" name="lang2" id="lang2"   value="1"> <p>One Drive</p>
  								<input type="radio" name="lang2" id="lang2"   value="2"> <p>Iframe</p>
							</div>
						</div>

						<div class="input-group">
							<button class="cad-success">Adicionar Episodio</button>
						</div>
					</div>
				</div>
			</div>	
			<div class="testeAPI"></div>
			<script type="text/javascript">
				$('.cad-success').click(function(){
					var idSerie = $('.idSerie').val();
					var temp  	= $('.temporada').val();
					var ep  	= $('.epi').val();
					var link  	= $('.link').val();
					var vidLinkLEG  	= $('.vidLinkLEG').val();
					var lang  = $('#lang:checked').val();
					var lang2  = $('#lang2:checked').val();

					if(idSerie != ''){
						$('.idSerie').css('border','1px solid rgba(0,0,0,.3)');
						if(temp != ''){
							$('.temporada').css('border','1px solid rgba(0,0,0,.3)');
							if(ep != ''){$('.epi').css('border','1px solid rgba(0,0,0,.3)');
									
									$('.loading').css('display','block');
									$('.loading').css('opacity','1');
									//POST
									$.ajax({
									  type: "POST",
									  url: 'function/api.php?action=addEp',
									  data: {
									  	'idSerie' : idSerie,
									  	'temp' : temp,
									  	'ep' : ep,
									  	'link' : link,
									  	'vidLinkLEG' : vidLinkLEG,
										'gdrive' : lang,
										'gdrive2' : lang2
										},
									  success: function(data,status){
									  	console.log(data);
									  	$('.loading').css('display','none');
										$('.loading').css('opacity','0');
										  	if(data == 'E1'){
										  		$('.loading').css('display','none');
												$('.loading').css('opacity','0');
										  		$('.status').css('display','block');
									  			$('.status').css('color','white');
									  			$('.status').css('background','rgba(215,50,50,1)');
										  		$('.status p').html('Episodio Já Existente.');
										  		status_close();
										  	}else if(data == 'S1'){
										  		$('.loading').css('display','none');
												$('.loading').css('opacity','0');
										  		$('.status').css('display','block');
										  		$('.status').css('color','white');
									  			$('.status').css('background','rgba(50,215,50,1)');
										  		$('.status p').html('Adicionado Com Sucesso.');
										  		
										  		status_close();
										  	}
									  },
									  
									});
									//POST
								
								}else{
								$('.epi').css('border','1px solid red');
							}
						}else{
							$('.temporada').css('border','1px solid red');
						}
					}else{

						$('.idSerie').css('border','1px solid red');
					}
				});
			</script>