﻿// Javascript for modal dialog
function ShowModalDialog(prefix) {
    var dialogContent = $('div#' + prefix + 'dialog-modal');   
    var width = 'auto';
    var height = 'auto';
    var resizable = false;
    if (($.browser.msie) && ($.browser.version == "6.0")) {      
        width = ($(window).width() / 2.5);
        height = ($(window).height() / 3);
        resizable = true;
    }
    dialogContent.dialog({
        modal: true,
        resizable: resizable,
        width: width,
        height: height,
        close: function() {
            $("div#" + prefix + "dialog-modal-content").html('');
        }
    });
    
    RecenterDialog();

}

function DialogContentLoadedCallBack(prefix) {

	if (typeof DialogLoaded == 'function') {
		DialogLoaded();
	}

	RecenterDialog(prefix);

}

function RecenterDialog(prefix) {
	$('div#' + prefix + 'dialog-modal').dialog("option", "position", 'center');
}

$(document).ready(function () {
	$('.showHideToggle').click(function () {
		var current = $(this);

		// for non checkboxes, put the content next to the header
		if (current.next('.showHideContentPlaceHolder').length > 0) {
			current.next('.showHideContentPlaceHolder').toggle();
		}
		// for checkboxes, a span is put in between
		else if (current.next().next('.showHideContentPlaceHolder').length > 0) {
			current.next().next('.showHideContentPlaceHolder').toggle();
		}

		// check wether to toggle css classes for openheader_new
		if (current.hasClass('openheader_new') || current.hasClass('closedheader_new')) {
			current.toggleClass('closedheader_new');
			current.toggleClass('openheader_new');
		}

		// check wether to toggle css classes for openheader2
		if (current.hasClass('openheader2') || current.hasClass('closedheader2')) {
			current.toggleClass('closedheader2');
			current.toggleClass('openheader2');
		}

	});

	$(".popupflashview").click(function () {
		var currenthref = this.href;

		$('div#dialog-modal-flashviewer').dialog({
			modal: true,
			resizable: false,
			width: 830,
			height: 580,
			open: function (event, ui) {
				var fp = new FlexPaperViewer(
					'/Scripts/flexpaper/FlexPaperViewer',
					'viewerPlaceHolder',
					{ config: {
						key: '@fa6b70dba2949b35c84$2e58d3a7b534ad17570',
						SwfFile: currenthref,
						Scale: 0.6,
						ZoomTransition: 'easeOut',
						ZoomTime: 0.5,
						ZoomInterval: 0.2,
						FitPageOnLoad: false,
						FitWidthOnLoad: true,
						PrintEnabled: true,
						FullScreenAsMaxWindow: false,
						ProgressiveLoading: false,
						MinZoomSize: 0.2,
						MaxZoomSize: 5,
						SearchMatchAll: true,
						InitViewMode: 'Portrait',
						ViewModeToolsVisible: true,
						ZoomToolsVisible: true,
						NavToolsVisible: true,
						CursorToolsVisible: true,
						SearchToolsVisible: true,
						localeChain: 'en_US'
					}
					});
			}
		});

		return false;
	});
});


//// should copy below code into New.aspx
//$(function () {

//	$('#upload-add').click(function () {

//		var template = $('#hide-uploads-template').children().first();
//		var templateInput = template.children('input');
//		var templateQueue = template.children('.uploadifyQueue');

//		var list = $('#uploads-list');

//		var numberOfUploads = list.children().length;

//		var newInputId = templateInput.attr("id") + (numberOfUploads + 1);
//		var newQueueId = templateQueue.attr("id") + (numberOfUploads + 1);

//		var cloned = template.clone();
//		var clonedInput = cloned.children('input');
//		var clonedQueue = cloned.children('.uploadifyQueue');

//		clonedInput.attr("id", newInputId);
//		clonedQueue.attr("id", newQueueId);

//		cloned.appendTo(list);

//		initUploadify(clonedInput, clonedQueue);
//	});

//});

//function initUploadify(inputElement, queueElement) {

//	var uploaderSwfLocation = $('[name=uploaderSwfLocation]').val();
//	var uploaderAction = $('[name=uploaderAction]').val();
//	var cancelImage = $('[name=cancelImage]').val();

//	var queueId = queueElement.attr("id");

//	inputElement.uploadify({
//		'uploader': uploaderSwfLocation,
//		'script': uploaderAction,
//		'cancelImg': cancelImage,
//		//'multi': true,
//		'auto': true,
//		'queueID': queueId,
//		'removeCompleted': false
//	});
//}
