// ========== SIDEBAR BUTTONS
// This code creates the sidebar buttons that appear on the right side of each page.
// If any individual button needs to be disabled, comment all code under the separated button
// code only.

var locServer=window.location.href.indexOf("localhost")!=-1;
var devServer=window.location.href.indexOf("dev-documentation")!=-1;
var stgServer=window.location.href.indexOf("stg-documentation")!=-1;
var tstServer=window.location.href.indexOf("tst-documentation")!=-1;

$('body').append('<div id="Sidebar" class="sidebar">' +

// Was This Helpful
// '<a href="#" class="sidebarBtn" id="helpful" title="Was this helpful?" onclick="showWTH()">' +
	// '<i class="glyphicon glyphicon-question-sign"></i>&nbsp;&nbsp;&nbsp;&nbsp;Helpful?</a>' +
//	'<img class="sidebar-icon" src="/resources/img/icons/white/help.png" />&nbsp;&nbsp;&nbsp;&nbsp;Helpful?</a>' +

//Collapse
// '<a href="#" id="collapse" title="Collapse/Expand all sections" onclick="CollapseSections()">' +
	// '<i class="glyphicon glyphicon-play"></i>&nbsp;&nbsp;&nbsp;&nbsp;Collapse</a>' +
	// '<i class="glyphicon glyphicon-play"></i>&nbsp;&nbsp;&nbsp;&nbsp;Collapse</a>' +

// Feedback
'<a href="#" class="sidebarBtn" id="feedback" title="Give us your feedback" onclick="openFeedback()">' +
	// '<i class="glyphicon glyphicon-comment"></i>&nbsp;&nbsp;&nbsp;&nbsp;Feedback</a>' +
	'<img class="sidebar-icon" src="/resources/img/icons/white/feedback.png" />&nbsp;&nbsp;&nbsp;&nbsp;Feedback</a>' +

// Print
'<a href="#" class="sidebarBtn" id="print" title="Print current page" onclick="window.print()">' +
	// '<i class="glyphicon glyphicon-print"></i>&nbsp;&nbsp;&nbsp;&nbsp;Print</a>' +
	'<img class="sidebar-icon" src="/resources/img/icons/white/printer.png" />&nbsp;&nbsp;&nbsp;&nbsp;Print</a>' +

// Live Chat
'<a href="#" class="sidebarBtn" id="chat" title="Chat with a live representative">' +
	// '<i class="glyphicon glyphicon-user"></i>&nbsp;&nbsp;&nbsp;&nbsp;Chat</a>' +
	'<img class="sidebar-icon" src="/resources/img/icons/white/chat.png" />&nbsp;&nbsp;&nbsp;&nbsp;Chat</a>' +

'</div>');

// if (!devServer && !stgServer && !tstServer){
// 	$('#Sidebar').append('<a href="#" class="sidebarBtn" id="helpful" title="Was this helpful?" onclick="showWTH()">' +
// 	// '<i class="glyphicon glyphicon-question-sign"></i>&nbsp;&nbsp;&nbsp;&nbsp;Helpful?</a>' +
// 	'<img class="sidebar-icon" src="/resources/img/icons/white/help.png" />&nbsp;&nbsp;&nbsp;&nbsp;Helpful?</a>');
// }


// Create white border around slidebar buttons
$('.sidebarBtn').css('border-color','white');
$('.sidebarBtn').css('border-style','solid');
$('.sidebarBtn').css('border-width','1px');


var showPdfButtonTitle = "View PDF  ";
$.get("manual.pdf")
    .done(function() { 
		// exists code 
		// console.log("PDF exists");
		$('#Sidebar').append('<a href="#" class="sidebarBtn" id="pdfButton" title="View PDF" onclick="showPDF()">' +
		// '<i class="glyphicon glyphicon-question-sign"></i>&nbsp;&nbsp;&nbsp;&nbsp;Helpful?</a>' +
		'<img class="sidebar-icon" src="/resources/img/icons/white/pdf-64.png" />&nbsp;&nbsp;&nbsp;&nbsp;' + showPdfButtonTitle + '</a>');
		$('#pdfButton').css('top', '220px');
    }).fail(function() { 
		// not exists code
		// console.log("PDF does not exist");
	})

// var pdfFilesDirectory = window.location.href;
// console.log(pdfFilesDirectory);

// // get auto-generated page 
// $.ajax({url: pdfFilesDirectory}).then(function(html) {
//     // create temporary DOM element
//     var document = $(html);

//     // find all links ending with .pdf 
//     document.find('a[href$=.pdf]').each(function() {
//         var pdfName = $(this).text();
//         var pdfUrl = $(this).attr('href');

// 		// do what you want here 
// 		console.log(pdfName);
//     })
// });


var fileExt = ".pdf";
var dir = "window.location.href";
// console.log(dir + "\n" + fileExt);
// $.ajax({

// 	url: dir,
// 	success: function (data) {
// 		console.log(data);
// 	   $("#fileNames").html('<ul>');

// 		$(data).find("a:contains(" + fileExt + ")").each(function () {
// 			$("#fileNames").append( '<li>'+$(this).text()+'</li>');
// 			console.log($(this).text());
// 		});
// 		$("#fileNames").append('</ul>');
// 	}
// });

var files;
$.ajax({
	url: dir,
	success: function (data) {
		console.log(data);
	}
});