﻿(function($) {
	// change position of popup window area because of IE6 problems with position:fixed
	$(document).ready(function() {
		var mainform = $("#aspnetForm");
		var div1 = $("div [class*='popupwrapper']");
		if (div1.length > 0 && mainform.length == 1) {
			div1.detach();
			mainform.append(div1);
		}
	});
})(jQuery);

(function($) 
{   
    $(document).ready(function() {
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        var showPopup = function showPopup()
        {
            $(document).ready(function() 
	        {
		        $(".socialiconPopupArea").hover(function(){
			        $(".socialiconPopup", this).toggleClass("show");
		        });
	        });
        };

	    if (prm) {
		    prm.add_endRequest(function (sender, args) { showPopup(); });
	    }
        showPopup();
    });
})(jQuery);

$(document).ready(function() {
	sIFR.replace(sifr, {
		selector: '#content h1'
		, wmode: 'transparent'
		, css: ['.sIFR-root {color: #54301a; font-size: 24px;}']
	});

	sIFR.replace(sifr, {
		selector: '#content h2'
		, wmode: 'transparent'
		, css: ['a { color: #54301a; text-decoration: none; }', 'a:hover { color: #54301a; text-decoration: underline; }', '.sIFR-root { text-transform: uppercase; color: #54301a; font-size: 16px;}']
	});
});

$(document).ready(function() {
	$("#fnc_page .fndList ul > li").mouseover(function() {
		var nameItem = $(this).attr("id").substr(6);
		$("#fnc_page .fndList ul > li").removeClass("fn01_select fn02_select fn03_select fn04_select fn05_select");
		$(this).addClass("fn0" + nameItem + "_select");
		$(".fndDescriptionContent > span").hide();
		$("#fundDetails0" + nameItem).show();
	});
});

var _hiddenElements = null;
var _openedToolTip = null;

function __customPostBack(eventTarget, eventArgument, submitButtonId) {
	if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
		theForm.__EVENTTARGET.value = eventTarget;
		theForm.__EVENTARGUMENT.value = eventArgument;
		var submitButton = document.getElementById(submitButtonId);
		if (submitButton != null) {
			if (submitButton.style.display != 'none') {
				submitButton.focus();
			}
			submitButton.click();
		}
	}
}

var sliderMapping = [];
function SearchSliderPostback(id, lv, rv) {
	document.getElementById(sliderMapping[id].min).value = lv;
	document.getElementById(sliderMapping[id].max).value = rv;
	__doPostBack(sliderMapping[id].max, '');
}

// Registers a onHide method for a modalpopup panel to avoid flickering when exiting a page
function RegisterOnModalPopupHide(behaviourID) {
	$find(behaviourID).add_hidden(function(source, args) {
		obj = document.getElementById(source._PopupControlID);
		if (obj)
			obj.style.display = 'none';
	});
}

// Toggles multiple checkboxes for given name, depending on the checked state of the given object
var toggleMultipleCheckboxes = function(obj, name) {
	$("input[name='" + name + "']").attr("checked", obj.checked);
}

/* Find the position of an element */
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft, curtop];
}

function setInvisible(elementID) {
	obj = document.getElementById(elementID);
	obj.style.visibility = 'hidden';
	popupClose();
}

function setCollapsed(elementID) {
	obj = document.getElementById(elementID);
	if (obj)
		obj.style.display = 'none';
}


// sets a given object in the dom visible/invisible. 
function toggleVisible(elementID, anchorElementID) {
	var curleft = curtop = 0;

	var anchor = document.getElementById(anchorElementID);
	if (anchor.offsetParent) {
		do {
			curleft += anchor.offsetLeft;
			curtop += anchor.offsetTop;
		} while (anchor = anchor.offsetParent);
	}

	obj = document.getElementById(elementID);
	obj.style.top = curtop + 'px';
	obj.style.left = (curleft + 20) + 'px';
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';

	if (_openedToolTip != null && _openedToolTip != obj)
		_openedToolTip.style.visibility = "hidden";

	if (obj.style.visibility == 'visible') {
		popupOpen(obj);
	}
	else {
		popupClose();
	}

	_openedToolTip = obj;
}

function toggleVisibleUp(elementID, anchorElementID) {
	var curleft = curtop = 0;

	var anchor = document.getElementById(anchorElementID);
	if (anchor.offsetParent) {
		do {
			curleft += anchor.offsetLeft;
			curtop += anchor.offsetTop;
		} while (anchor = anchor.offsetParent);
	}

	obj = document.getElementById(elementID);
	obj.style.top = (curtop - obj.offsetHeight) + 'px';
	obj.style.left = (curleft) + 'px';
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';

	if (_openedToolTip != null && _openedToolTip != obj)
		_openedToolTip.style.visibility = "hidden";

	if (obj.style.visibility == 'visible') {
		popupOpen(obj);
	}
	else {
		popupClose();
	}

	_openedToolTip = obj;
}

function CallPrint(strid) {
	var prtContent = document.getElementById(strid);
	var WinPrint =
	window.open('', '', 'left=2,top=2,width=350,height=200,toolbar=0,scrollbars=1,status=0');
	var txthtml = prtContent.innerHTML;
	var txtcss1 = '<link rel="stylesheet" href="/css/print.css" media="all" /></head><body>';
	var txtinit = '<html><head>';
	var txtend = '</body></html>';
	WinPrint.document.write(txtinit + txtcss1 + txthtml + txtend);
	WinPrint.document.close();
	WinPrint.focus();
	WinPrint.print();
	WinPrint.close();
}

function popupOpen(popup) {
	if (!isIE6)
		return;

	if (_hiddenSelectboxes != null) {
		// show hidden selectboxes
		menuShowHiddenSelectBoxes();
	}

	if (_hiddenElements != null) {
		for (var i = 0; i < _hiddenElements.length; i++) {
			_hiddenElements[i].style.visibility = "visible";
		}
	}


	// get all direct submenu items
	var subItems = popup.getElementsByTagName("div");

	// get all select boxes on the page
	var selectboxes = document.getElementsByTagName("select");

	// check if any of this selectboxes if overlapped by a 
	// submenu item.
	_hiddenElements = new Array();
	for (var i = 0; i < selectboxes.length; i++) {
		var selectBox = selectboxes[i];

		for (var k = 0; k < subItems.length; k++) {
			var li = subItems[k];

			if (elementOverlapsObject(li, selectBox)) {
				_hiddenElements.push(selectBox);
				break;
			}
		}
	}

	// hide all dropdown boxes
	//_hiddenSelectboxes = selectboxes;

	// hide all overlapped dropdown boxes
	for (var i = 0; i < _hiddenElements.length; i++) {
		_hiddenElements[i].style.visibility = "hidden";
	}
}

function popupClose() {
	if (_hiddenElements == null)
		return;

	for (var i = 0; i < _hiddenElements.length; i++) {
		_hiddenElements[i].style.visibility = "visible";
	}

	_hiddenElements = null;
}

function equalizeHeight(group) {
	var max = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if (thisHeight > max) { max = thisHeight; }
	});
	group.height(max);
}

function posComoinvestri() {
	equalizeHeight($('.col320, .col380, .col250'));
	var top = 0;
	var ch = 0;
	$('#comoinvestri').parent().children().each(function() {
		ch = ch + $(this).height();
	});
	top = $('#comoinvestri').parent().height() - ch;
	if (top > 0) { $('#comoinvestri').css('margin-top', top + 'px'); }
	$('#comoinvestri').show();
}

var moveDataBuilderItem = function(e, ui) {
	var movedFieldName = ui.item.attr('id');
	var prevField = ui.item.prev();

	var data = "method=move&mf=" + movedFieldName
	if (prevField) {
		data = data + "&pf=" + prevField.attr('id');
	}
	$.post("/DataBuilderHttpHandler.axd", data, null, "text");
	enableSaveReportField();
}

var removeDataBuilderItem = function(ui) {

	var movedFieldName = ui.parent().attr('id');
	var data = "method=remove&mf=" + movedFieldName;

	$.post("/DataBuilderHttpHandler.axd", data, null, "text");
	enableSaveReportField();
}


function JPMeetingOnLoad(iframe) {
	//	if(iframe.contentDocument)
	//		iframe.style.height = '1350px';
	//	else
	//		iframe.style.height = '1350px';
}


/* subtitles */
function refreshMediaPopup(divID, file, height, width, mediaID, language, captionState, availableLanguages, captionSize) {
	$('#' + divID + 'vplayer').empty();

	var displayOptions;


	if (availableLanguages.length > 0)
		displayOptions = '&plugins=../swf/mediaplayer/v5/captions.swf&captions.back=true&dock=false&captions.state=' + captionState;
	else
		displayOptions = '';

	var languages = availableLanguages.split(',');

	var captions = '';
	for (i = 0; i < languages.length; i++) {
		captions += 'subtitle.axd?parameters=' + mediaID + '_' + languages[i];
		if (i + 1 < languages.length) captions += ",";
	}

	$('#' + divID + 'vplayer').flash({
		swf: '../swf/mediaplayer/player.swf?skin=../swf/mediaplayer/glow.zip' + displayOptions + '',
		height: height,
		width: width,
		allowfullscreen: true,
		allowscriptaccess: 'always',
		flashvars: { 'autostart': true,
			'file': file,
			'captions.files': captions,
			'captions.fontSize': captionSize
		}
	});

	$('#' + divID + 'vplayer').flash(function () {
		try {
			initPlayerCallbacks(this);
		} catch (e) { }
	});

	/* generate the subtitle dock */

	if (availableLanguages.length > 0) {
		var dock = '<ul id="subtitleDock" class="menu_dock_language" style="width: ' + width + 'px">'
								+ '<li class="subtitle">Subtitles:</li>';

		for (i = 0; i < languages.length; i++) {
			var info = languages[i].trim().split('-');

			var country = '';
			var lang = '';

			if ((info[0] != null) && (info[1] != null)
				&& (info[0].toUpperCase() != info[1].toUpperCase())
				&& (languages[i] != 'en-GB')
				&& (languages[i] != 'sv-SE')) {
				lang = info[1].toUpperCase();
				country = ' (' + info[0].toUpperCase() + ')';
			}
			else {
				lang = info[0].toUpperCase();
			}

			//			dock += '<li><a href="#" OnClick="refreshMediaPopup(\''+ divID +'\',\''+file+'\','+height+','+width+','+mediaID+',\''+ languages[i] + '\',true,\''+availableLanguages+'\');" title="Display Subtitles">'+ lang + country +'</a></li>';
			dock += '<li><a href="#" OnClick="toggleCaption(this)" captionIndex="' + (i + 1) + '" player="' + divID + 'vplayer">' + lang + country + '</a></li>';
		}

		dock += '</ul>';
	}
	else
		dock = '';

	$('#' + divID + 'vplayer').append(dock);
}

function toggleCaption(sender) {
	var item = $(sender);
	if (item.hasClass("currentCaption")) {
		$('#' + item.attr('player') + ' object')[0].setCaptionChannel(0);
		item.toggleClass("currentCaption");
		return;
	}

	$('ul#subtitleDock a').removeClass('currentCaption');
	item.toggleClass("currentCaption");
	$('#' + item.attr('player') + ' object')[0].setCaptionChannel(item.attr('captionIndex'));

}



