var uploadError = [
         //php error code 1
         'Error: File size exceeded the allowed 512MB',
         //php error code 2
         'Error: File size exceeded the allowed 512MB',
         //php error code 3
         'Error: The file was only partially uploaded',
         //php error code 4
         'Error: No file was uploaded',
         //blank because there is no php error code 5 for some reason
         '',
         //php error code 6
         'Error: Folder missing',
         //php error code 7
         'Error: Error writing to the server',
         //php error code 8
         'Error: Error in configuration of server'
];

var functionPage = "";

//checks if we are using the content library or the resource center and sets the function page appropriately
if (document.URL.toLowerCase().search('content-library.php') > 0 || document.URL.toLowerCase().search('cms.php') > 0) {
	functionPage = 'functions-content_library';
}
else {
	functionPage = 'functions-resource_center';
}

/*
 * function to open the add category popup
 */
function showAddCategoryFancyBox(elcId) {
	$.fancybox({
		'zoomSpeedIn'		: 300, 
		'zoomSpeedOut'		: 300, 
		'overlayShow'		: true, 
		'hideOnOverlayClick': false, 
		'hideOnContentClick': false,
		'width'				: 300,
		'height'			: 400,
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'href'				: functionPage+'.php?action=addcategorypopup&elcId='+elcId
	});
}

/*
 * function to open the add file popup
 */
function showAddFileFancyBox(elcId) {
	$.fancybox({
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 610,
		'height'			: 410,
                'autoScale'			: false,
		'autoDimensions'	: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'href'				: functionPage+'.php?action=addfilepopup&elcId='+elcId
	});
}

/*
 * function to open the add text popup
 */
function showAddTextFancyBox(elc) {
	$.fancybox({
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 300,
		'height'			: 400,
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'href'				: functionPage+'.php?action=addtextpopup&elcId='+elc
	});
}

/*
 * function to open the add blog  popup
 */
function showAddBlogFancyBox(elc) {
	$.fancybox({
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 300,
		'height'			: 400,
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'href'				: functionPage+'.php?action=addblogpopup&elcId='+elc
	});
}

/*
 * function to open the add faq popup
 */
function showAddFaqFancyBox() {
	$.fancybox({
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 300,
		'height'			: 400,
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'href'				: functionPage+'.php?action=addfaqpopup'
	});
}

/*
 * function to open the add practice popup
 */
function showAddPracticeFancyBox() {
	$.fancybox({
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 300,
		'height'			: 400,
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'href'				: functionPage+'.php?action=addpracticepopup'
	});
}

/*
 * function to open the update file popup
 */
function showUpdateFileFancyBox(fileId,queryString,elcId) {
	$.fancybox({
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 300,
		'height'			: 400,
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'scrolling'			: 'no',
		'type'				: 'ajax',
		'href'				: functionPage+'.php?action=updatefilepopup&id='+fileId+"&elcId="+elcId,
		'ajax'				: {cache:false,type:'post',data:queryString}
	});
}

/*
 * function to open the content library popup
 */
function showContentLibraryFancyBox() {
	$.fancybox({
			'zoomSpeedIn'		: 300, 
			'zoomSpeedOut'		: 300, 
			'overlayShow'		: true, 
			'hideOnOverlayClick': false, 
			'hideOnContentClick': false,
			'width'				: 1100,
			'height'			: 520,
			'autoScale'			: false,
			'autoDimensions'	: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'href'				: 'content-library.php?cl=true&popup=0'
	});
}

/*
 * function to open the content library popup
 */
function showContentLibraryFancyBox(elc) {
	$.fancybox({
			'zoomSpeedIn'		: 300, 
			'zoomSpeedOut'		: 300, 
			'overlayShow'		: true, 
			'hideOnOverlayClick': false, 
			'hideOnContentClick': false,
			'width'				: 1100,
			'height'			: 520,
			'autoScale'			: false,
			'autoDimensions'	: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'href'				: 'content-library.php?cl=true&popup=0&elcId='+elc
	});
}

/*
 * function to open the error popup
 */
function showErrorFancyBox(error) {
	strError = uploadError[error-1];
	$.fancybox({
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 300,
		'height'			: 400,
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'content'			: '<b>'+strError+'</b>',
		'onClosed'			: function() {location.assign(location.pathname);}
	});
}

/*
 * function to open content in a fancybox
 */
function showContentFancyBox(id,back,type,elc) {
	if (back=='elc' || back=="" || back=='cms') {
		functionPage = 'functions-content_library';
	}
      else if (back=='searchform') {
            functionPage = '/functions-resource_center';
      }
	else {
		functionPage = 'functions-resource_center';
	}

	switch (type) {
		case "video":
			$.fancybox({
				onComplete			: function() {flowplayer("player", "/cms/video-source/flowplayer-3.2.6.swf",{clip:{autoPlay:false,autoBuffering:false}});},
				'zoomSpeedIn'		: 300,
				'zoomSpeedOut'		: 300,
				'overlayShow'		: true,
				'hideOnOverlayClick': false,
				'hideOnContentClick': false,
				'width'				: 350,
				'height'			: 450,
				'autoScale'			: false,
				'autoDimensions'	: true,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'href'				: functionPage + '.php?action=getviewvideobox&fileId='+id+'&back='+back+'&elcId='+elc
			});
			break;
		case "audio":
			$.fancybox({
				onComplete			: function() {flowplayer("player", "/cms/video-source/flowplayer-3.2.6.swf",{plugins: {controls: {fullscreen: false,height: 30,autoHide: false}},clip:{autoPlay:false,autoBuffering:false}});},
				'href'				: functionPage+'.php?action=getviewaudiobox&fileId='+id+'&back='+back+'&elcId='+elc,
				'zoomSpeedIn'		: 300,
				'zoomSpeedOut'		: 300,
				'overlayShow'		: true,
				'hideOnOverlayClick': false,
				'hideOnContentClick': false,
				'width'				: 300,
				'height'			: 400,
				'autoScale'			: true,
				'autoDimensions'	: true,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
			break;
		case "image":
			$.fancybox({
				'href'				: functionPage+'.php?action=getviewimagebox&fileId='+id+'&back='+back+'&elcId='+elc,
				'zoomSpeedIn'		: 300,
				'zoomSpeedOut'		: 300,
				'overlayShow'		: true,
				'hideOnOverlayClick': false,
				'hideOnContentClick': false,
				'width'				: 300,
				'height'			: 400,
				'autoScale'			: true,
				'autoDimensions'	: true,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
			break;
		case "text":
			$.fancybox({
				'zoomSpeedIn'		: 300,
				'zoomSpeedOut'		: 300,
				'overlayShow'		: true,
				'hideOnOverlayClick': false,
				'hideOnContentClick': false,
				'width'				: 300,
				'height'			: 400,
				'autoScale'			: true,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'href'				: functionPage+'.php?action=getviewtextbox&fileId='+id+'&back='+back+'&elcId='+elc
			});
			break;
            case "blog":
			$.fancybox({
				'zoomSpeedIn'		: 300,
				'zoomSpeedOut'		: 300,
				'overlayShow'		: true,
				'hideOnOverlayClick': false,
				'hideOnContentClick': false,
				'width'				: 300,
				'height'			: 400,
				'autoScale'			: true,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'href'				: functionPage+'.php?action=getviewblogbox&fileId='+id+'&back='+back+'&elcId='+elc
			});
			break;
		case "faq":
			$.fancybox({
				'zoomSpeedIn'		: 300,
				'zoomSpeedOut'		: 300,
				'overlayShow'		: true,
				'hideOnOverlayClick': false,
				'hideOnContentClick': false,
				'width'				: 300,
				'height'			: 400,
				'autoScale'			: true,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',


				'href'				: functionPage+'.php?action=getviewfaqbox&fileId='+id+'&back='+back+'&elcId='+elc
			});
			break;
		case "practice":
			$.fancybox({
				'zoomSpeedIn'		: 300,
				'zoomSpeedOut'		: 300,
				'overlayShow'		: true,
				'hideOnOverlayClick': false,
				'hideOnContentClick': false,
				'width'				: 300,
				'height'			: 400,
				'autoScale'			: true,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'href'				: functionPage+'.php?action=getviewpracticebox&fileId='+id+'&back='+back+'&elcId='+elc
			});
			break;

	}
}

/*
 * function to open the view text popup
 */
function showTextFancyBox(id,back) {
	$.fancybox({
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 300,
		'height'			: 400,
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'href'				: functionPage+'.php?action=getviewtextbox&fileId='+id+'&back='+back
	});
}

/*
 * function to open the view blog popup
 */
function showBlogFancyBox(id,back) {
	$.fancybox({
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 300,
		'height'			: 400,
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'href'				: functionPage+'.php?action=getviewblogbox&fileId='+id+'&back='+back
	});
}

/*
 * function to open the view faq popup
 */
function showFaqFancyBox(id,back) {
	$.fancybox({
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 300,
		'height'			: 400,
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'href'				: functionPage+'.php?action=getviewfaqbox&fileId='+id+'&back='+back
	});
}

/*
 * function to open the view practice area popup
 */
function showPracticeFancyBox(id,back) {
	$.fancybox({
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 300,
		'height'			: 400,
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'href'				: functionPage+'.php?action=getviewpracticebox&fileId='+id+'&back='+back
	});
}

/*
 * function to open the view image popup
 */
function showImageFancyBox(id,back) {
	$.fancybox({
		'href'				: functionPage+'.php?action=getviewimagebox&fileId='+id+'&back='+back,
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 300,
		'height'			: 400,
		'autoScale'			: true,
		'autoDimensions'	: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});
}

/*
 * function to open the view audio popup
 */
function showAudioFancyBox(id,back) {
	$.fancybox({
		onComplete			: function() {flowplayer("player", "/cms/video-source/flowplayer-3.2.6.swf",{plugins: {controls: {fullscreen: false,height: 30,autoHide: false}},clip:{autoPlay:false,autoBuffering:false}});},
		'href'				: functionPage+'.php?action=getviewaudiobox&fileId='+id+'&back='+back,
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 300,
		'height'			: 400,
		'autoScale'			: true,
		'autoDimensions'	: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});
}

/*
 * function to open the view video popup
 */
function showVideoFancyBox(id,back) {
	$.fancybox({
		onComplete			: function() {flowplayer("player", "/cms/video-source/flowplayer-3.2.6.swf",{clip:{autoPlay:false,autoBuffering:false}});},
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 350,
		'height'			: 450,
		'autoScale'			: false,
		'autoDimensions'	: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'href'				: functionPage+'.php?action=getviewvideobox&fileId='+id+'&back='+back
	});
}

/*
 * function to open the view video popup
 */
function showUploadHelpFancyBox() {
	$.fancybox({
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 350,
		'height'			: 450,
		'autoScale'			: false,
		'autoDimensions'	: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'href'				: functionPage+'.php?action=getuploadhelpbox'
	});
}

/*
 * function to open the view video popup
 */
function showAddToElcCategoriesFancyBox(elc,fileId) {
	$.fancybox({
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 350,
		'height'			: 450,
		'autoScale'			: false,
		'autoDimensions'	: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'href'				: functionPage+'.php?action=getaddtoelccategories',
		'ajax'				: {cache:false,type:'post',data:'elc='+elc+'&fileId='+fileId}
	});
}

/*
 * function to open the add video to ckeditor popup
 */
function showUploadVideoToEditorFancyBox() {
	$.fancybox({
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 350,
		'height'			: 450,
		'autoScale'			: true,
		'autoDimensions'	: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'href'				: 'functions-resource_center.php?action=getuploadvideotoeditorbox'
	});
}

/*
 * function to open the add pdf/ppt to ckeditor popup
 */
function showUploadDocumentToEditorFancyBox() {
	$.fancybox({
		'zoomSpeedIn'		: 300,
		'zoomSpeedOut'		: 300,
		'overlayShow'		: true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width'				: 350,
		'height'			: 450,
		'autoScale'			: true,
		'autoDimensions'	: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'href'				: 'functions-resource_center.php?action=getuploaddocumenttoeditorbox'
	});
}

function addTheText(name,filepath,filetype,description,thumbnail,article) {
	var className = 'cke_show_borders';

	switch (filetype) {
		case "video":
			//put html into a variable just for ease of reading;
			
			var html = '';	
			html += '<img style="border:solid thin black;width:300px;height:225px;" src="'+thumbnail+'" class="flashmovie" id="'+filepath+'">';
			html += '</img>';

			CKEDITOR.instances.content.insertHtml(html);

			if (CKEDITOR.instances.content.getData().search('players.js')==-1) {
				CKEDITOR.instances.content.setData(CKEDITOR.instances.content.getData()+'<script type="text/javascript" src="/cms/js/players.js"></script>');
			}
			
			break;
		case "image":
			CKEDITOR.instances.content.insertHtml('<img src="'+filepath+'"/>');
			break;
		case "audio":
			var html = '';	
			html += '<img style="border:solid thin black;" src="/cms/files/thumbnails/audio_player.png" class="audioplayer" id="'+filepath+'">';
			html += '</img>';

			CKEDITOR.instances.content.insertHtml(html);

			if (CKEDITOR.instances.content.getData().search('players.js')==-1) {
				CKEDITOR.instances.content.setData(CKEDITOR.instances.content.getData()+'<script type="text/javascript" src="/cms/js/players.js"></script>');
			}
			break;
		case "document":
			CKEDITOR.instances.content.insertHtml('<a href="'+filepath+'" target="_blank">'+name+'</a>');
			break;
		case "text":
			var html = "";	
			html = article;
			CKEDITOR.instances.content.insertHtml(html);
			break;
            case "blog":
			var html = "";	
			html = article;
			CKEDITOR.instances.content.insertHtml(html);
			break;
		case "faq":
			var html = "";	
			html += "<div style='width:100%;height:auto;margin:5px;overflow:hidden;'>";
			html += "<div style='width:auto;height:auto;margin-right:10px;margin-bottom:10px;display:inline-block;'>";
			html += "<a href='"+filepath+"'>";
			html += "<img alt='Icon' src='"+thumbnail+"' style='padding:5px;margin:0px;border:none;'/>";
			html += "</a>";
			html += "</div>";
			html += "<div style='width:550px;display:inline-block;vertical-align:top;padding:5px;'>";
			html += "<nobr><b>Question:</b> "+name+"</nobr>";
			html += "<br>";
			html += "<b>Answer:</b> "+description;
			html += "<br>";	
			html += "</div></div>";
			CKEDITOR.instances.content.insertHtml(html);
			//CKEDITOR.instances.content.insertHtml('<img src="'+filepath+'"/>');
			break;
		case "practice":
			var html = "";	
			html += "<div style='width:100%;height:auto;margin:5px;overflow:hidden;'>";
			html += "<div style='width:auto;height:auto;margin-right:10px;margin-bottom:10px;display:inline-block;'>";
			html += "<a href='"+filepath+"'>";
			html += "<img alt='Icon' src='"+thumbnail+"' style='padding:5px;margin:0px;border:none;'/>";
			html += "</a>";
			html += "</div>";
			html += "<div style='width:550px;display:inline-block;vertical-align:top;padding:5px;'>";
			html += "<nobr><b>Practice Area:</b> "+name+"</nobr>";
			html += "<br>";
			html += "<b>Description:</b> "+description;
			html += "<br>";	
			html += "</div></div>";
			CKEDITOR.instances.content.insertHtml(html);
			//CKEDITOR.instances.content.insertHtml('<img src="'+filepath+'"/>');
			break;
	}
}

