/*========== newsletter.js ==========*/
var NewsLetter={};

NewsLetter.viewopcionalMails=function(valor,mails){
	
	if(valor==1){
		$('mails').style.display ='none';
	}else{
		if(mails!=""){
			$('mails').style.display ='block';
			$('mailspruebas').value=mails;
		}
		else{
			$('mails').style.display ='block';
			$('mailspruebas').value="";
		}
	}
}

NewsLetter.newListMails=function(){

			$('mailspruebas').style.display ='block';
			$('mailspruebas').value="";
			$('mailstitle').style.display ='block';
		
	
}

NewsLetter.confirmarSpooler=function(){
	return confirm('¿Desea eliminar este mail?');
}

NewsLetter.popupImagesNL=function(){	
	window.open(
		//'/admin/image_admin?js_handler=popupHandlerNL',
		'/admin/image_admin?js_handler=NewsLetter.popupHandlerNL',
		'aaqqimgloader',
		'width=600,height=400,scrollbars=yes'
	);
	
	return;
}

NewsLetter.popupHandlerNL=function(val, url){		
		$('imagen').value = val;
		$('preview').src = $('url_images').value+'/images/newsletter/'+val;
		//$('preview').src = '/images/newsletter/'+val;
}

NewsLetter.mostrar=function(valor){
		if(valor==1){
		$('newsletter').style.display ='block';
		}
		else
		{
		$('newsletter').style.display ='none';	
		}
}

NewsLetter.attachAnother=function(){
   
   if (!$defined(NewsLetter.attachAnother.count)) {
      NewsLetter.attachAnother.count = 1;
   }
   
   if (NewsLetter.attachAnother.count++ == 5) {
      alert('No se pueden agregar más archivos adjuntos.');
      return;
   }
   
   
   
   var el = new Element('input', {
      'type': 'file',
      'name': 'nl_attach[]'
   });
   
   $('attached_files').adopt(el);
};

NewsLetter.deleteAttach=function(id,name) {
   
   if (!$defined(NewsLetter.attachAnother.count)) {
      NewsLetter.attachAnother.count = 1;
   }
   
   if (!confirm('Quitar y eliminar el archivo adjunto '+name+'?')) {
      return;
   }
   
   // ajax call
   
   var el_id = 'attached_'+id;

   if ($defined($(el_id))) {
      
      $(el_id).empty();
      $(el_id).appendText('Eliminando...');
      
   }
   
   Ajax.NLDestroyAttach(id, function(response){
            
      // dispose element
      
      var el_id = 'attached_'+id;
   
      if ($defined($(el_id))) {
         
         if (response.done) {
            $(el_id).dispose();
         }
         else {
            $(el_id).empty();
            $(el_id).appendText('No se pudo eliminar el archivo.');
            
         }
      }
   
   });
   
   
}

