
/* Merged Plone Javascript file
 * This file is dynamically assembled from separate parts.
 * Some of these parts have 3rd party licenses or copyright information attached
 * Such information is valid for that section,
 * not for the entire composite file
 * originating files are separated by - filename.js -
 */

/* - smartprint.js - */
// http://www.montesquiu.cat/portal_javascripts/smartprint.js?original=1
var in_progres=false;var $j=jQuery.noConflict();
function cleanupContent(node){var arr=node.getElementsByTagName('div');for(var i=0;i<arr.length;i++){var classname=arr[i].className;if(classname.indexOf('documentActions')!=-1||classname.indexOf('documentByLine')!=-1){arr[i].parentNode.removeChild(arr[i])}}
var arr=node.getElementsByTagName('p');for(var i=0;i<arr.length;i++){if(arr[i].id=='link-presentation'){arr[i].parentNode.removeChild(arr[i])}}
var arr=node.getElementsByTagName('div');for(var i=0;i<arr.length;i++){if(arr[i].id=='smartprint'){arr[i].parentNode.removeChild(arr[i])}}}
function getContentElement(){var el=$j('#content');if(!el[0])
el=$j('#region-content');if(!el[0])
alert('No DOM node with id "region-content" or "content" found');return el}
function openControl(){if(!$j('#smartprint')[0]){var divContent=getContentElement().clone(true);if(!divContent){alert('Error: the element with id=content could not be found!');return}
var newdiv=document.createElement('div');newdiv.id='smartprint';getContentElement().append(newdiv)} else{if(in_progres){alert('Conversion in progres...please wait');return}
closeControl()}}
function closeControl(){$j('#smartprint').remove()}
function showResponse(request){if($j('#smartprint'))
$j('#smartprint')[0].innerHTML=request.responseText}
function smartPrintSelection(url,template){openControl();var url=url+'/'+template;var r=$j.ajax({url:url,type:'GET',complete:showResponse})}
function startConversion(url){var divContent=getContentElement().clone(true);if(!divContent){alert('Error: the element with id=content could not be found!');return}
divContent=divContent[0]
cleanupContent(divContent);$j('#smartprint-html')[0].value=divContent.innerHTML
var postBody=$j('#smartprint-selection-form').serialize();in_progres=true;var r=$j.ajax({url:url+'/sp_progres',type:'GET',asynchronous:false,complete:showResponse});var r2=$j.ajax({url:url+'/smartPrintConvert',type:'POST',asynchronous:true,data:postBody,requestHeaders:['content-type','application/x-www-form-urlencoded'],complete: function(request){in_progres=false;closeControl();if(request.status==200){var filename=request.responseText;document.location=url+'/smartPrintDeliver?filename='+encodeURIComponent(filename)} else{var status=request.status;alert('Conversion failed (Error code: '+status+')')}},onFailure: function(request){in_progres=false;var status=request.status;alert('Conversion failed (Error code: '+status+')');closeControl()}})}


/* - pdfaction.js - */
// http://www.montesquiu.cat/portal_javascripts/pdfaction.js?original=1
function continuaConversionPDF(dic,url){openControl();var html=getContentElement().clone(true);if(!html){alert('Error: No se ha podido determinar el HTML a transformar');return}
html=html[0]
cleanupContent(html);var converter_name='zopyx.smartprintng.converters.default';var format=dic['format'];var options={};options['stylesheet']=dic['stylesheet'];options['template']=dic['template'];var print_options={};print_options['column-count']=dic['column-count'];print_options['font-size']=dic['font-size'];print_options['orientation']=dic['orientation'];print_options['paper-size']=dic['paper-size'];in_progres=true;$j('#smartprint').append('<input type="hidden" name="html" id="smartprint-html" value="" />');$j('#smartprint-html').val(html.innerHTML);html=$j('#smartprint-html').serialize();$j('#smartprint-html').remove();var datos=html+'&converter_name='+converter_name+'&format='+format;for(var item in options){datos+='&options.'+item+':record='+options[item]}
for(var item in print_options){datos+='&print_options.'+item+':record='+print_options[item]}
datos+='&options.workchain:record=['
if(dic['removeImages']){datos+='"removeImages",'}
if(dic['removeLinks']){datos+='"removeLinks",'}
if(dic['addLinkList']){datos+='"addLinkList",'}
if(dic['breakIntoPages']){datos+='"breakIntoPages",'}
if(dic['removeReviewHistory']){datos+='"removeReviewHistory",'}
datos+=']'
var r=$j.ajax({url:url+'/sp_progres',type:'GET',asynchronous:false,complete:showResponse});var r2=$j.ajax({url:url+'/smartPrintConvert',type:'POST',asynchronous:true,data:datos,requestHeaders:['content-type','application/x-www-form-urlencoded'],complete: function(request){in_progres=false;closeControl();if(request.status==200){var filename=request.responseText;document.location=url+'/smartPrintDeliver?filename='+encodeURIComponent(filename)} else{var status=request.status;alert('Conversion failed (Error code: '+status+')')}},onFailure: function(request){in_progres=false;var status=request.status;alert('Conversion failed (Error code: '+status+')');closeControl()}})}
function conviertePDF(url){$j.ajax({url:url+'/get_options_pdf',type:'post',success: function(json){continuaConversionPDF(eval('('+json+')'),url)}})}

