 
//$(function() {
//
//    $("#divTable td").load(HOLA);
//})

function resizeDiv(){
	var count = 0;
	var count2 = 0;
	
	var svgTags = document.querySelectorAll('#divFlow svg');
	var element = document.getElementById("divFlow");

	for (var i = 0; i < svgTags.length; i++) {
		var svgTag = svgTags[i];
		var c = document.createElement('canvas');
		var at = svgTag.getAttribute("style");
		svgTag.parentNode.insertBefore(c, svgTag);
		var div = document.createElement('div');
		div.appendChild(svgTag);
		c.setAttribute('style', at);
		canvg(c, div.innerHTML);
	}
	
	$('div #divFlow .ui-diagram-element').each(function() {
		count = count +1;
		});
	
	$('canvas').each(function() {
		if ($(this).attr('width') == '102' ||  $(this).attr('width') == '101' || $(this).attr('width') == '103'){
			count2 = count2 + 1;
		}
			
		});
	
	$('#diagramFlow').each(function() {
//		style="height:1200px"
//			if ($(this).html() === '') {
//			    $(this).attr('style', 'height:' + (count * 65) + 'px; '+'width: 100%');  
			    $(this).attr('style', 'height:' + (count * 40) + 'px; '+'width:' + (400 + (count2 * 200)) + 'px');  
//			    $(this).attr('style', 'width:' + (150 + (count2 * 142)) + 'px'); 
//				}
			});
}

function resizeDivSiga(){
	var count = 0;
	var count2 = 0;
	
	var svgTags = document.querySelectorAll('#divSiga svg');
	var element = document.getElementById("divSiga");

	for (var i = 0; i < svgTags.length; i++) {
		var svgTag = svgTags[i];
		var c = document.createElement('canvas');
		var at = svgTag.getAttribute("style");
		svgTag.parentNode.insertBefore(c, svgTag);
		var div = document.createElement('div');
		div.appendChild(svgTag);
		c.setAttribute("style", at);
		canvg(c, div.innerHTML);
	}
	
	$('div #divSiga .ui-diagram-element').each(function() {
		if (count%5===0){
			count2 = count2 + 1;
		}
		count = count +1;
		
	});
	
//	$('canvas').each(function() {
//		if ($(this).attr('heigt') == '180'){
//			count2 = count2 + 1;
//		}
//			
//		});
//	
	$('#diagramSiga').each(function() {
//		style="height:1200px"
//			if ($(this).html() === '') {
//			    $(this).attr('style', 'height:' + (count * 65) + 'px; '+'width:' + '1000px');  
		if($(window).width() < 500){
			 $(this).attr('style', 'height:' + ($(window).height()-250) + 'px; '+'width:' + ($(window).width() -10) + 'px');  
		}else {
			 $(this).attr('style', 'height:' + (count2 * 130) + 'px; '+'width:' + '1000px');  
		}
//			    $(this).attr('style', 'height:' + (count * 65) + 'px; '+'width:' + (350 + (count2 * 210)) + 'px');  
//			    $(this).attr('style', 'width:' + (150 + (count2 * 142)) + 'px'); 
//				}
			});
	
	
}
function removeAll(){
    
    var myNode = document.getElementById("divSigaNpe");
    myNode.innerHTML = '';
};

function resizeDivSigaNpe(){
	var count = 0;
	var count2 = 0;
	var countA1 = 0;
	var countA = 0;
	
	var svgTags = document.querySelectorAll('#divSigaNpe svg');
	var element = document.getElementById("divSigaNpe");
	
	for (var i = 0; i < svgTags.length; i++) {
		var svgTag = svgTags[i];
		var c = document.createElement('canvas');
		var at = svgTag.getAttribute("style");
		svgTag.parentNode.insertBefore(c, svgTag);
		var div = document.createElement('div');
		div.appendChild(svgTag);
		c.setAttribute("style", at);
		canvg(c, div.innerHTML);
	}
	
	$('div #divSigaNpe #diagramSigaNpe .ui-diagram-element').each(function() {
		if (count%5===0){
			count2 = count2 + 1;
		}
		count = count +1;
		
	});
	
	$('div #divSigaNpe #diagramSigaNpeAcre .ui-diagram-element').each(function() {
		if (countA1%4===0){
			countA = countA + 1;
		}
		countA1 = countA1 +1;
		
	});
	
//	$('canvas').each(function() {
//		if ($(this).attr('heigt') == '180'){
//			count2 = count2 + 1;
//		}
//			
//		});
//	
	$('#diagramSigaNpe').each(function() {
//		style="height:1200px"
//			if ($(this).html() === '') {
//			    $(this).attr('style', 'height:' + (count * 65) + 'px; '+'width:' + '1000px');  
var wwM = 0;
		if($(window).width() < 500){
                    wwM = ($(window).width() -10);
			$(this).attr('style', 'height:' + ($(window).height()-250) + 'px; '+'width:' + wwM + 'px');  
		}else {
                    wwM = 1000;
			$(this).attr('style', 'height:' + (count2 * 115) + 'px; '+'width:' + wwM +'px');  
		}
                
            var tbl = document.createElement('table');
            var nodeDiv = document.createElement('div');
            var nodeDiv2 = document.createElement('div');
           
            var text = document.createTextNode('MANDAMIENTO');
            var content = document.createElement('label');
            content.setAttribute('id','mandamientoId1');
            content.setAttribute('style','color: #6f6a6a;');
            content.appendChild(text);
            
            var text2 = document.createTextNode('FLUJO DE SEGUIMIENTO POR MANDAMIENTO');
            var content2 = document.createElement('label');
            content2.setAttribute('id','mandamientoId2');
            content2.setAttribute('style','color: #6f6a6a;');
            content2.appendChild(text2);
            
            var myNode = document.getElementById("diagramSigaNpe");
            
            nodeDiv.appendChild(content);
            nodeDiv2.appendChild(content2);
            
            tbl.style.width = '100%';
            tbl.setAttribute('border', '1');
            var tbdy = document.createElement('tbody');
            var tr = document.createElement('tr');
            var td = document.createElement('td');
            var td2 = document.createElement('td');
            td.appendChild(nodeDiv);
            td2.appendChild(nodeDiv2);
            
            td.setAttribute('style','width: '+((wwM/5) + 10)+'px; text-align: center;');
            td2.setAttribute('style','text-align: center;');
            tr.appendChild(td);
            tr.appendChild(td2);
            
            tbdy.appendChild(tr);
            
            tbl.appendChild(tbdy);
            myNode.appendChild(tbl);
            
            
            //myNode.innerHTML += '<h3>Hola que tal</h3>';
          
          //  $("#diagramSigaNpe").appendChild(label);
                
//			    $(this).attr('style', 'height:' + (count * 65) + 'px; '+'width:' + (350 + (count2 * 210)) + 'px');  
//			    $(this).attr('style', 'width:' + (150 + (count2 * 142)) + 'px'); 
//				}
	});
	$('#diagramSigaNpeAcre').each(function() {
//		style="height:1200px"
//			if ($(this).html() === '') {
//			    $(this).attr('style', 'height:' + (count * 65) + 'px; '+'width:' + '1000px'); 
var wwM = 0;
var wwMAcre = 0;
		if($(window).width() < 500){
                     wwM = ($(window).width() -10);
                     wwMAcre = wwM;
			$(this).attr('style', 'height:' + ($(window).height()-250) + 'px; '+'width:' + ($(window).width() -10) + 'px');  
		}else {
                     wwM = 810;
                     wwMAcre = ((1000-wwM)/2);
			$(this).attr('style', 'height:' + (countA * 115) + 'px; '+'width:' + wwM +'px');  
		}
//			    $(this).attr('style', 'height:' + (count * 65) + 'px; '+'width:' + (350 + (count2 * 210)) + 'px');  
//			    $(this).attr('style', 'width:' + (150 + (count2 * 142)) + 'px'); 
//				}


            var tbl = document.createElement('table');
            var nodeDiv = document.createElement('div');
            var nodeDiv2 = document.createElement('div');
           
            var text = document.createTextNode('RESERVA');
            var content = document.createElement('label');
            content.setAttribute('id','acreId1');
            content.setAttribute('style','color: #6f6a6a;');
            content.appendChild(text);
            
            var text2 = document.createTextNode('FLUJO DE SEGUIMIENTO POR RESERVA');
            var content2 = document.createElement('label');
            content2.setAttribute('id','acreId2');
            content2.setAttribute('style','color: #6f6a6a;');
            content2.appendChild(text2);
            
            var myNode = document.getElementById("diagramSigaNpeAcre");
            
            nodeDiv.appendChild(content);
            nodeDiv2.appendChild(content2);
            
            tbl.style.width = '100%';
            tbl.setAttribute('border', '1');
            var tbdy = document.createElement('tbody');
            var tr = document.createElement('tr');
            var td = document.createElement('td');
            var td2 = document.createElement('td');
            td.appendChild(nodeDiv);
            td2.appendChild(nodeDiv2);
            
            td.setAttribute('style','width: '+((wwM/4) + 10)+'px; text-align: center; ');
            td2.setAttribute('style','text-align: center;');
            tr.appendChild(td);
            tr.appendChild(td2);
            
            tbdy.appendChild(tr);
            
            tbl.appendChild(tbdy);
            myNode.appendChild(tbl);
            var styleNodeAcre = myNode.getAttribute('style');
            myNode.setAttribute('style',styleNodeAcre + ';left:'+wwMAcre+'px;');


	});
	
	
}

function getVars() {
    // ...
    var x = $(window).width(); 

    document.getElementById("dataForm:idPantalla").value = x;
//    document.getElementById("dataForm:idPantallaN").value = x;
}

function extender1() {
        this.cfg.seriesDefaults = {
            renderer:$.jqplot.LineRenderer,
            pointLabels: {show: true},
            
        	
        };
        this.cfg.seriesDefaults.rendererOptions = {
                showDataLabels: true
        }
    }  
    

function changueColorArrow() {
 	 
 		 
 		 $('path td').each(function() {
 			if ($(this).html() === '') {
 			    $(this).attr('style', 'display:none');  
 				}
 			});
 	 
 	}


function DeleteBlank() {
 	 
 		 
 		 $('#divTable td').each(function() {
 			if ($(this).html() === '') {
 			    $(this).attr('style', 'display:none');  
 				}
 			});
 	 
 	}
//var text = $('#divTable td').text();
// var comparingText = 'Liq'
//
// if(text == comparingText){
//       $('theDivID').css('background','#FFFFF');
// };

function exportChartInPDFF() {
	var docDefinition = {
		content : [ 'Diagrama de Tiempos estimados por dependencia', '\n', {
			image : $(PF('flowWV').exportAsImage()).attr('src'),
			width : 500,
			height : 300

		},

		]
	}
	pdfMake.createPdf(docDefinition).open();
	pdfMake.createPdf(docDefinition).download('primefaces-charts.pdf');
}

function exportChartInPDFL() {
	var docDefinition = {
		content : [ 'Diagrama de flujo estimado por dependencia', '\n', {
			image : $(PF('lineWV').exportAsImage()).attr('src'),
			width : 500,
			height : 300

		},

		]
	}
	pdfMake.createPdf(docDefinition).open();
	pdfMake.createPdf(docDefinition).download('primefaces-charts.pdf');
}


function exportChartInPDFT() {
	var docDefinition = {
		content : [ 'Tabla de Tiempos estimados por Dependencia', {
			image : $(PF('timeWV').exportAsImage()).attr('src'),
			width : 550,
			height : 300

		},

		]
	}
	pdfMake.createPdf(docDefinition).open();
	pdfMake.createPdf(docDefinition).download('primefaces-charts.pdf');
}

function getDataUri(url, callback) {
	var image = new Image();
	
	image.onload = function () {
		var canvas = document.createElement('canvas');
		canvas.width = this.naturalWidth; // or 'width' if you want a special/scaled size
		canvas.height = this.naturalHeight; // or 'height' if you want a special/scaled size
		
		canvas.getContext('2d').drawImage(this, 0, 0);
		
		// Get raw image data
		callback(canvas.toDataURL('image/png').replace(/^data:image\/(png|jpg);base64,/, ''));
		
		// ... or get as Data URI
//		callback(canvas.toDataURL('image/png'));
	};
	
	image.src = url;
}
////--------------------------------
function genTableTimePDF() {
	
	getDataUri('/VEA/resources/images/HeaderReportes0.jpeg', function(dataUri) {
		 
	var element = document.getElementById("divTable");
	
    html2canvas(element).then(function(canvas) {
    	allowTaint: true
    	var base64image = canvas.toDataURL("image/png");
    	var base64imageHeader = dataUri;
//    	var base64imageHeader = Base64.encode('http://localhost:8080/SIGA/resources/images/HeaderReportes.jpeg');
    	//var base64imageHeader = toDataURL("http://localhost:8080/SIGA/resources/images/HeaderReportes.jpeg");
//	    getDataUri('http://localhost:8080/SIGA/resources/images/HeaderReportes.jpeg', function(dataUri) {
//	    	base64imageHeader = dataUri;
//	    });
//    
    	base64imageHeader = dataUri;
    		   // console.log('RESULT:', dataUrl)
    		 
    	
    	var doc = new jsPDF("p", "mm", "a4", true);
    	doc.setFontSize(15);
    	doc.addImage(base64imageHeader, 'JPEG', 15, 5, 175, 18, '','FAST' );
    	
        doc.text(15, 28, $('#idtitletime').text());
        doc.addImage(base64image, 'JPEG', 25, 33, 140, 230, '','FAST' );
//    	doc.output('datauri');
      //  doc.output('dataurlnewwindow2'); ////////////////////////////
//        window.open(doc.output('datauri'));
//        doc.output('save', 'generated.pdf');
//        doc.save();
        doc.save('TableTimeDGA.pdf');
//        doc.save(doc.output('datauristring'),'TableTime');
//        window.open(doc.output('datauri'));
//        doc.output('save', hola1.pdf);
//        window.stop();
//    	doc.save('test.pdf');
//    	window.open(base64image , "_blank");
	

    
    
    });
	 });
 }
function genChartSigaPDF() {
	
	getDataUri('/VEA/resources/images/HeaderReportes0.jpeg', function(dataUri) {
		 
		var element = document.getElementById("divSiga");
		
	    html2canvas(element).then(function(canvas) {
	    	allowTaint: true
	    	var base64image = canvas.toDataURL("image/png");
	    	var base64imageHeader = dataUri;
//	    	var base64imageHeader = Base64.encode('http://localhost:8080/SIGA/resources/images/HeaderReportes.jpeg');
	    	//var base64imageHeader = toDataURL("http://localhost:8080/SIGA/resources/images/HeaderReportes.jpeg");
//		    getDataUri('http://localhost:8080/SIGA/resources/images/HeaderReportes.jpeg', function(dataUri) {
//		    	base64imageHeader = dataUri;
//		    });
	//    
	    	base64imageHeader = dataUri;
	    		   // console.log('RESULT:', dataUrl)
	    		 
	    	var h = ($('#diagramSiga').css('height').replace('px','') / (2 * 3.779528));
	    	var doc = new jsPDF("l", "mm", "a4", true);
	    	doc.setFontSize(15);
	    	doc.addImage(base64imageHeader, 'JPEG', 55, 5, 175, 18, '','FAST' );
	    	doc.text(10, 28, $('#idtitlesiga').text());
//	        doc.text(10, 50, 'Diagrama de Tiempos estimados por dependencia');
	        doc.addImage(base64image, 'JPEG', 25, 40, 185, h, '','FAST' );
//	    	doc.output('datauri');
//	        doc.output('dataurlnewwindow2');
	        doc.save('ChartSigaDGA.pdf');
//	        doc.output('save', hola1.pdf);
//	        window.stop();
//	    	doc.save('test.pdf');
//	    	window.open(base64image , "_blank");
		

	    
		
		
		});
	});
}

function genChartSigaNpePDF() {
	
	getDataUri('/VEA/resources/images/HeaderReportes0.jpeg', function(dataUri) {
		 
		var element = document.getElementById("divSigaNpe");
		
	    html2canvas(element).then(function(canvas) {
	    	allowTaint: true
	    	var base64image = canvas.toDataURL("image/png");
	    	var base64imageHeader = dataUri;
	    	base64imageHeader = dataUri;
	    		 
	    	var h = ($('#diagramSigaNpe').css('height').replace('px','') / (2 * 3.779528));
	    	var doc = new jsPDF("l", "mm", "a4", true);
	    	doc.setFontSize(15);
	    	doc.addImage(base64imageHeader, 'JPEG', 55, 5, 175, 18, '','FAST' );
	    	doc.text(10, 28, $('#idtitlesiganpe').text());
	        doc.addImage(base64image, 'JPEG', 25, 40, 185, h, '','FAST' );
	        doc.save('ChartSigaNpeDGA.pdf');
		
		});
	});
}

////--------------------------------

function genChartLinePDF() {
	
	getDataUri('/VEA/resources/images/HeaderReportes0.jpeg', function(dataUri) {
		 
	var element = document.getElementById("divLine");
	
    html2canvas(element).then(function(canvas) {
    	allowTaint: true
    	var base64image = canvas.toDataURL("image/png");
    	var base64imageHeader = dataUri;
//    	var base64imageHeader = Base64.encode('http://localhost:8080/SIGA/resources/images/HeaderReportes.jpeg');
    	//var base64imageHeader = toDataURL("http://localhost:8080/SIGA/resources/images/HeaderReportes.jpeg");
//	    getDataUri('http://localhost:8080/SIGA/resources/images/HeaderReportes.jpeg', function(dataUri) {
//	    	base64imageHeader = dataUri;
//	    });
//    
    	base64imageHeader = dataUri;
    		   // console.log('RESULT:', dataUrl)
    		 
    	
    	var doc = new jsPDF("l", "mm", "a4", true);
    	doc.setFontSize(15);
    	doc.addImage(base64imageHeader, 'JPEG', 55, 5, 175, 18, '','FAST' );
    	doc.text(10, 28, $('#idtitleline').text());
//        doc.text(10, 50, 'Diagrama de Tiempos estimados por dependencia');
        doc.addImage(base64image, 'JPEG', 15, 40, 190, 100, '','FAST' );
//    	doc.output('datauri');
//        doc.output('dataurlnewwindow2');
        doc.save('ChartLineDGA.pdf');
//        doc.output('save', hola1.pdf);
//        window.stop();
//    	doc.save('test.pdf');
//    	window.open(base64image , "_blank");
	

    
    
    });
	 });
 }


//BUENO
function genTableTimePDFww() {
	
	
	var element = document.getElementById("divTable");
	
	html2canvas(element).then(function(canvas) {
		allowTaint: true
		var base64image = canvas.toDataURL("image/png");
	var doc = new jsPDF("p", "mm", "a4", true);
	doc.setFontSize(15);
	doc.text(10, 20, 'Tabla de tiempos estimados por dependencia');
	doc.addImage(base64image, 'JPEG', 10, 30, 180, 200, '','FAST' );
//    	doc.output('datauri');
	doc.output('dataurlnewwindow');
//    	doc.save('test.pdf');
//    	window.open(base64image , "_blank");
	
	
	
	
	});
}

function genChartFlowPDF() {

	
	getDataUri('/VEA/resources/images/HeaderReportes0.jpeg', function(dataUri) {
		 
		var svgTags = document.querySelectorAll('#divFlow svg');
		var element = document.getElementById("divFlow");

		for (var i = 0; i < svgTags.length; i++) {
			var svgTag = svgTags[i];
			var c = document.createElement('canvas');
			var at = svgTag.getAttribute("style");
			svgTag.parentNode.insertBefore(c, svgTag);
			var div = document.createElement('div');
			div.appendChild(svgTag);
			c.setAttribute("style", at);
			canvg(c, div.innerHTML);
		}
		html2canvas(element, {
			scale : 3,
			allowTaint : true
		}).then(function(canvas) {
			allowTaint : true
			var base64image = canvas.toDataURL("image/png");
			var base64imageHeader = dataUri;
			var h = ($('#diagramFlow').css('height').replace('px','') / (2 * 3.779528));
	    	base64imageHeader = dataUri;
			var doc = new jsPDF("p", "mm", "a4", true);
//			window.open(base64image, "_blank");
	    	doc.setFontSize(15);
	    	doc.addImage(base64imageHeader, 'JPEG', 15, 5, 175, 18, '','FAST' );
	    	doc.text(10, 28, $('#idtitleflow').text());
//	        doc.text(10, 50, 'Diagrama de flujo de operaciones');
	        doc.addImage(base64image, 'JPEG', 10, 33, 180, h, '','FAST' );
//	    	doc.output('datauri');
//	        doc.output('dataurlnewwindow2');
	        doc.save('ChartFlowDGA.pdf');
	        
		});
		
//		var element = document.getElementById("divTable");
//		
//	    html2canvas(element).then(function(canvas) {
//	    	allowTaint: true
//	    	var base64image = canvas.toDataURL("image/png");
//	    	var base64imageHeader = dataUri;
//	    	base64imageHeader = dataUri;
//	    	
//	    	var doc = new jsPDF("p", "mm", "a4", true);
//	    	doc.setFontSize(15);
//	    	doc.addImage(base64imageHeader, 'JPEG', 15, 5, 175, 30, '','FAST' );
//	        doc.text(10, 50, 'Tabla de tiempos estimados por dependencia');
//	        doc.addImage(base64image, 'JPEG', 15, 55, 180, 200, '','FAST' );
//	        doc.output('dataurlnewwindow2');
//		
//
//	    
//	    
//	    });
//	    
	    
	    
	    
		 });
	
	
//	var svgTags = document.querySelectorAll('#divFlow svg');
//	var element = document.getElementById("divFlow");
//
//	for (var i = 0; i < svgTags.length; i++) {
//		var svgTag = svgTags[i];
//		var c = document.createElement('canvas');
//		var at = svgTag.getAttribute("style");
//		svgTag.parentNode.insertBefore(c, svgTag);
//		var div = document.createElement('div');
//		div.appendChild(svgTag);
//		c.setAttribute("style", at);
//		canvg(c, div.innerHTML);
//	}
//	html2canvas(element, {
//		scale : 3,
//		allowTaint : true
//	}).then(function(canvas) {
//
//		var base64image = canvas.toDataURL("image/png");
//		var doc = new jsPDF("p", "mm", "a4", true);
////		window.open(base64image, "_blank");
//    	doc.setFontSize(15);
//        doc.text(10, 20, 'Diagrama de flujo de operaciones');
//        doc.addImage(base64image, 'JPEG', 10, 30, 180, 200, '','FAST' );
////    	doc.output('datauri');
//        doc.output('dataurlnewwindow');
//        
//	});
}


//BUENO
function genChartFlowPDFww() {

	var svgTags = document.querySelectorAll('#divFlow svg');
	var element = document.getElementById("divFlow");

	for (var i = 0; i < svgTags.length; i++) {
		var svgTag = svgTags[i];
		var c = document.createElement('canvas');
		var at = svgTag.getAttribute("style");
		svgTag.parentNode.insertBefore(c, svgTag);
		var div = document.createElement('div');
		div.appendChild(svgTag);
		c.setAttribute("style", at);
		canvg(c, div.innerHTML);
	}
	html2canvas(element, {
		scale : 3,
		allowTaint : true
	}).then(function(canvas) {

		var base64image = canvas.toDataURL("image/png");
		var doc = new jsPDF("p", "mm", "a4", true);
//		window.open(base64image, "_blank");
    	doc.setFontSize(15);
        doc.text(10, 20, 'Diagrama de flujo de operaciones');
        doc.addImage(base64image, 'JPEG', 10, 30, 180, 200, '','FAST' );
//    	doc.output('datauri');
        doc.output('dataurlnewwindow');
        
	});
}





function genChartFlowIMG() {
	
	var svgTags = document.querySelectorAll('#divFlow svg');
	
	var element = document.getElementById("divFlow");
	
	for (var i=0; i<svgTags.length; i++) {
	    var svgTag = svgTags[i];
		
	    var c = document.createElement('canvas');
	    var at = svgTag.getAttribute("style");
	    svgTag.parentNode.insertBefore(c, svgTag);
	    var div = document.createElement('div');
	    div.appendChild(svgTag);
	    c.setAttribute("style", at);
	    canvg(c, div.innerHTML);
	}
	
    	html2canvas(element, 
    			{
    		scale: 3,
    		allowTaint : true
    		}
).then(function(canvas) {

    	var base64image = canvas.toDataURL("image/png");
        window.open().document.write('<head></script></head><img src="' + base64image + '" style="max-width: 75%; max-height: 75%;" /><script type="text/javascript">window.stop();</script>');
 	});
 }

function genTableTimeIMG() {
	
	
	var element = document.getElementById("divTable");
	
    html2canvas(element).then(function(canvas) {
	allowTaint: true
	var base64image = canvas.toDataURL("image/png");
//    var win = window;
    window.open().document.write('<head></script></head><img src="' + base64image + '" style="max-width: 75%; max-height: 75%;" /><script type="text/javascript">window.stop();</script>');
    });
 }

function genChartSigaIMG() {
	
	
	var element = document.getElementById("divSiga");
	
	html2canvas(element).then(function(canvas) {
		allowTaint: true
		var base64image = canvas.toDataURL("image/png");
//    var win = window;
	window.open().document.write('<head></script></head><img src="' + base64image + '" style="max-width: 75%; max-height: 75%;" /><script type="text/javascript">window.stop();</script>');
	});
}

function genChartSigaNpeIMG() {
	
	
	var element = document.getElementById("divSigaNpe");
	
	html2canvas(element).then(function(canvas) {
		allowTaint: true
		var base64image = canvas.toDataURL("image/png");
//    var win = window;
	window.open().document.write('<head></script></head><img src="' + base64image + '" style="max-width: 75%; max-height: 75%;" /><script type="text/javascript">window.stop();</script>');
	});
}

function genTableLineIMG() {
	
	
	var element = document.getElementById("divLine");
	
    html2canvas(element).then(function(canvas) {
	allowTaint: true
	var base64image = canvas.toDataURL("image/png");
//    var win = window;
    window.open().document.write('<head></script></head><img src="' + base64image + '" style="max-width: 75%; max-height: 75%;" /><script type="text/javascript">window.stop();</script>');
    });
 }





function genChartFlowPDF2() {

	var svgTags = document.querySelectorAll('#frmFlow svg');
	var element = document.getElementById("frmFlow");

	for (var i = 0; i < svgTags.length; i++) {
		var svgTag = svgTags[i];
		var c = document.createElement('canvas');
		var at = svgTag.getAttribute("style");
		svgTag.parentNode.insertBefore(c, svgTag);
		var div = document.createElement('div');
		div.appendChild(svgTag);
		c.setAttribute("style", at);
		canvg(c, div.innerHTML);
	}
	html2canvas(element, {
		scale : 3,
		allowTaint : true
	}).then(function(canvas) {

		var base64image = canvas.toDataURL("image/png");
		window.open(base64image, "_blank");
	});
}


// BUENO TABLE_TIME1
function genPDF() {
	
	
	var element = document.getElementById("frmTime");
	
    html2canvas(element).then(function(canvas) {
    	allowTaint: true
    	var base64image = canvas.toDataURL("image/png");
    	var doc = new jsPDF();
    	doc.setFontSize(40);
        doc.text(30, 20, 'Hello world!');
        doc.addImage(base64image, 'JPEG',20,20);
    	doc.output('datauri');
//    	doc.save('test.pdf');
//    	window.open(base64image , "_blank");
	

    
    
    });
 }


//BUENO TABLE_TIME3
function genPDF31() {
	
	
	var element = document.getElementById("frmTime");
	
    html2canvas(element).then(function(canvas) {
    	allowTaint: true
    	var base64image = canvas.toDataURL("image/png");
    	var doc = new jsPDF();
    	doc.setFontSize(40);
        doc.text(30, 20, 'Hello world!');
        doc.addImage(base64image, 'JPEG',20,20);
//    	doc.output('datauri');
//    	var string2 = doc.output('datauri');
//    	var string = doc.output('datauristring');
//        var file = doc.output('blob');
//        doc.append('mypdf',file);
//    	var iframe = "<iframe width='100%' height='100%' src='" + string2 + "'></iframe>"
        doc.output('dataurlnewwindow');
//    	window.open(file, "_self");
//    	window.document.write(iframe);
//    	var x = window.open();
//    	x.document.open();
//    	x.document.write(iframe);
//    	x.document.close();
    	
//    	doc.save('test.pdf');
//    	window.open(base64image , "_blank");
	

    
    
    });
 }


//BUENO TABLE_TIME2
function genPDF7() {
	
	
	var element = document.getElementById("frmTime");
	
    html2canvas(element).then(function(canvas) {
    	allowTaint: true
    	var base64image = canvas.toDataURL("image/png");
//    window.open(base64image , "_blank");
    
    window.open().document.write('<img src="' + base64image + '" />');
    	
//    var doc = new jsPDF();
//    	doc.setFontSize(40);
//        doc.text(30, 20, 'Hello world!');
//        doc.addImage(base64image, 'JPEG',20,20);
//    	doc.output('datauri');
    	
//    	doc.save('test.pdf');
//    	window.open(base64image , "_blank");
	

    
    
    });
 }



function genPDF5() {
	
	
	var element = document.getElementById("frmFlow");
	
    html2canvas(element).then(function(canvas) {

    	var base64image = canvas.toDataURL("image/png");
    	var doc = new jsPDF();
    	doc.setFontSize(40);
        doc.text(30, 20, 'Hello world!');
        doc.addImage(base64image, 'JPEG',20,20);
    	doc.output('datauri');
//    	doc.save('test.pdf');
//    	window.open(base64image , "_blank");
	

    
    
    });
 }

function genPDF3() {
	
	
	var element = document.getElementById("frmTime");
//	var base64image;
	html2canvas(element).then(function(canvas) {

     var base64image = canvas.toDataURL("image/png");
//    	window.open(base64image , "_blank");
	
	
	
	
	var docDefinition = {
			content : [ 'Diagrama de Tiempos estimados por dependencia', '\n', {
				image : $(base64image).attr('src')
				,
				width : 550,
				height : 300
			},

			]
		}
	
	
	
	
		pdfMake.createPdf(docDefinition).open();
		pdfMake.createPdf(docDefinition).download('primefaces-charts.pdf');
	
	});
	
//
//	var element = document.getElementById("frmTime");
//	
//    html2canvas(element).then(function(canvas) {
//
//    	var base64image = canvas.toDataURL("image/png");
//    	window.open(base64image , "_blank");
//	

    
    
//    });
 }

// BUENO CHART_FLOW1
function genPDF2() {
	
//	computedToInline(element, true);
	var svgTags = document.querySelectorAll('#frmFlow svg');
	
	var element = document.getElementById("frmFlow");
	
//    var nodesToRecover = [];
//    var nodesToRemove = [];
//
//    var svgElem = $('#frmFlow').find('svg');
//
//    console.log(svgElem);
//
//    svgElem.each(function(index, node) {
//        var parentNode = node.parentNode;
//        var svg = parentNode.innerHTML;
//
//        var canvas = document.createElement('canvas');
//
//        canvg(canvas, svg);
//
//        nodesToRecover.push({
//            parent: parentNode,
//            child: node
//        });
//
//        parentNode.removeChild(node);
//
//        nodesToRemove.push({
//            parent: parentNode,
//            child: canvas
//        });
//
//        parentNode.appendChild(canvas);
//    });
	
	
	
	for (var i=0; i<svgTags.length; i++) {
	    var svgTag = svgTags[i];
//	    var serializer = new XMLSerializer();
//		var svgString = serializer.serializeToString(svgTag);
		
	    var c = document.createElement('canvas');
//	    c.width = svgTag.clientWidth;
//	    c.height = svgTag.clientHeight;
	    var at = svgTag.getAttribute("style");
	    svgTag.parentNode.insertBefore(c, svgTag);
//	    svgTag.parentNode.removeChild(svgTag);
	    var div = document.createElement('div');
	    div.appendChild(svgTag);
	    c.setAttribute("style", at);
	    canvg(c, div.innerHTML);
	}

	
//	var element = document.getElementById("frmFlow");
	
	
//	for (const attribute of ["width", "height"]) {
//	    for (const rect of element.querySelectorAll("svg ["+attribute+"]")) {
//	        rect.style[attribute] = "";
//	    }
//	}
//	
	
//    html2canvas(document.body).then(function(canvas) {
    	html2canvas(element, 
    			{
    		scale: 3,
//    		proxy: proxyURL,
    		allowTaint : true
    		}
    			
//    			{
//    		allowTaint: true,
//    	    useCORS: true,
//    	    onrendered: function(canvas) {
//    	      document.body.appendChild(canvas);
//    	    },
//    	    allowTaint: true,
//    	    taintTest: false,
//    	    useCORS: true
//    		logging: true,
//            profile: true,
//            useCORS: true,
//            allowTaint: true
//            }
).then(function(canvas) {

    	var base64image = canvas.toDataURL("image/png");
//    	window.open(base64image , "_blank");
    	window.open().document.write('<img src="' + base64image + '" />');
	
// 	html2canvas(document.body, {
//		onrendered: function (canvas) {
//			var img = canvas.toDataURL("image/png");
//			var doc = new  jsPDF();
//			doc.addImage(img, 'JPEG', 20, 20);
//			doc.save('test.pdf');
//			window.open(img);
//			}
 	});
 }




