﻿function are_cookies_enabled() {
    var cookieEnabled = (navigator.cookieEnabled) ? true : false;
    if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled) {
        document.cookie = "testcookie";
        cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
    }
    return (cookieEnabled);
}

var isEnabled = are_cookies_enabled();
var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
if (sPage != 'noCookiesHolding.htm' && isEnabled == false) {
        window.location.href = '/noCookiesHolding.htm';
}

$.fn.centerInClient = function(options) {
	var opt = {
		forceAbsolute: false,
		container: window,
		completeHandler: null,
		minX: 0,
		minY: 0 
	};

	$.extend(opt, options);

	return this.each(function(i) {
		var elem = $(this);
		var jWin = $(opt.container);
		var isWin = opt.container == window;

		var el = elem.find(".checkoutPopupFrame");
		if (el.length == 0) {
			el = elem.find(".popupFrame");
			if (el.length == 0) {
				el = elem;
			}
		}

		if (opt.forceAbsolute) {
			if (isWin)
				el.appendTo("body");
			else
				el.appendTo(jWin.get(0));
		}

		var ie6Offset = 0;
		if ($.browser.msie && $.browser.version == "6.0") {
			el.css("position", "absolute");
			ie6Offset = el.parent().offset().left;
		}
		else {
			el.css("position", "fixed");
		}
		var heightFudge = isWin ? 2.0 : 1.8;

		el.stop(true, false);

		var x = (isWin ? jWin.width() : jWin.width()) / 2 - el.width() / 2;
		var y = (isWin ? jWin.height() : jWin.height()) / 2 - el.height() / 2;

		var left = (x < opt.minX ? opt.minX : x) + jWin.scrollLeft() - ie6Offset;
		var top = (y < opt.minY ? opt.minY : y);

		if (opt.animate)
			el.animate({ 'left': left, 'top': top }, 100);
		else {
			el.css("left", left);
			el.css("top", top);
		}

		if (opt.completeHandler)
			opt.completeHandler(this);
	});
}

function fnDynamicCentering(elementId) {
    $('#' + elementId).centerInClient();
    $(document).ready(function() {
        $('#' + elementId).centerInClient();
    });

    $(window).resize(function() {
        $('#' + elementId).centerInClient({ animate: true });
    });

    $(window).scroll(function() {
    $('#' + elementId).centerInClient({ animate: true });
    });
}

