// Global variables
var xMousePos = 0; // Horizontal position of the mouse on the screen
var yMousePos = 0; // Vertical position of the mouse on the screen
var windowsize = null;
var isIE = true;
var container_client_id = null;

// Global error handler, works only in IE and FF
window.onerror = function(msg, url, line) {
	try {
		if (msg == "Error loading script" && url == "http://www.google-analytics.com/ga.js" && line == "1") {
			return;
		}

		$.ajax({
			type: "POST",
			url: "/UiService.asmx/LogError",
			data: "{'Message': '" + msg + "', 'Url': '" + url + "', 'Line': '" + line + "' }",
			contentType: "application/json; charset=utf-8",
			dataType: "json"
		});
	} catch (exc) { }
	return false;
}



// get mouse position
if (document.layers) { // Netscape
	document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
	document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
	document.onmousemove = captureMousePosition;
}

function captureMousePosition(e) {
	if (!e) { e = window.event; }
	if (!e || (typeof (e.pageX) != 'number' && typeof (e.clientX) != 'number')) { xMousePos = 0; yMousePos = 0; }

	if (document.layers) {
		if (e) {
			xMousePos = e.pageX;
			yMousePos = e.pageY;
		}
	}
	else if (document.all && document.body) {
		xMousePos = e.clientX + document.documentElement.scrollLeft;
		yMousePos = e.clientY + document.documentElement.scrollTop;
	}
	else if (document.getElementById) {
		if (e) {
			//xMousePos = e.pageX + window.pageXOffset;
			//yMousePos = e.pageY + window.pageYOffset;
			if (document.body == null || document.documentElement == null) {
				xMousePos = 0;
				yMousePos = 0;
			}
			else {
				xMousePos = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
				yMousePos = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
			}
		}
	}

	capturePageDimensions();
}

function capturePageDimensions() {
	if (document.body) {
		var xScroll, yScroll;

		if (window.innerHeight && window.scrollMaxY) {
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}

		var wWidth, wHeight;
		if (self.innerHeight) {	// all except Explorer
			wWidth = self.innerWidth;
			wHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			wWidth = document.documentElement.clientWidth;
			wHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			wWidth = document.body.clientWidth;
			wHeight = document.body.clientHeight;
		}

		// for small pages with total height less then height of the viewport
		if (yScroll < wHeight) {
			pageHeight = wHeight;
		} else {
			pageHeight = yScroll;  //+ 50;
		}

		// for small pages with total width less then width of the viewport
		if (xScroll < wWidth) {
			pageWidth = wWidth;
		} else {
			pageWidth = xScroll;
		}

		var sLeft, sTop;
		if (window.pageXOffset) {
			sLeft = window.pageXOffset;
			sTop = window.pageYOffset;
		}
		else if (document.documentElement) {
			sLeft = document.documentElement.scrollLeft;
			sTop = document.documentElement.scrollTop;
		}
		else if (document.body) {
			sLeft = document.body.scrollLeft;
			sTop = document.body.scrollTop;
		}

		if (!windowsize) {
			windowsize = {
				width: pageWidth,
				height: pageHeight,
				windowWidth: wWidth,
				windowHeight: wHeight,
				scrollTop: sTop,
				scrollLeft: sLeft
			}
		} else {
			windowsize.width = pageWidth;
			windowsize.height = pageHeight;
			windowsize.windowWidth = wWidth;
			windowsize.windowHeight = wHeight;
			windowsize.scrollTop = sTop;
			windowsize.scrollLeft = sLeft;
		}
	}
}

function getStyle(element, style) {
	var value = element.style[style];
	if (!value) {
		if (document.defaultView && document.defaultView.getComputedStyle) {
			var css = document.defaultView.getComputedStyle(element, null);
			value = css ? css.getPropertyValue(style) : null;
		} else if (element.currentStyle) {
			value = element.currentStyle[style];
		}
	}

	return value;
}

function Hover(item, hover, cssclass) {
	if (hover) {
		if (!containsCssClass(item, cssclass)) {
			addCssClass(item, cssclass);
		}
	}
	else {
		removeCssClass(item, cssclass);
	}
}

function SwapContent(id) {
	var contentholder = $get("contentdiv");
	var contentinnerholder = $get("contentinnerdiv");
	var itema = $get("theme_large_" + id);
	var items = contentinnerholder.getElementsByTagName('div');
	var itemb = items[0];
	if (itema.id != itemb.id) {
		itema.style.display = "block";
		itemb.style.display = "none";
		contentholder.appendChild(itemb);
		contentinnerholder.appendChild(itema);
	}
}

function Swap(itemid, container, css) {
	if (jQuery("#" + container).children("." + css).length == 0) { return; }
	if (jQuery("#" + container).children("." + css)[0].id == itemid) { return; }
	jQuery("#" + container).children("." + css).removeClass(css);
	jQuery("#" + itemid).addClass(css);
}

function Colapse(ctrl, id, style) {
	var div = $get(id);
	if (div.style.display == "none") {
		div.style.display = "block";
		Hover(ctrl, false, style);
	}
	else {
		div.style.display = "none";
		Hover(ctrl, true, style);
	}
}

// watermark focus
function waterMark_Validate(obj) {
	if (obj.value == obj.getAttribute("ovalue")) {
		obj.value = '';
	}
}

function waterMark_focus(obj) {
	if (obj.value == obj.getAttribute("ovalue")) {
		obj.value = '';
	}
}

function waterMark_BlurChild(childObj, obj) {
	if (childObj.value == childObj.getAttribute("ovalue")) {
		childObj.value = '';
	}
}

function waterMark_Blur(obj, parentObj) {
	if (parentObj) {
		if (parentObj.value == parentObj.getAttribute("ovalue") && obj.value != obj.getAttribute("ovalue")) {
			if (obj.value == '') {
				obj.value = obj.getAttribute("ovalue");
			}
		}
	}
	else {
		if (obj.value != obj.getAttribute("ovalue")) {
			if (obj.value == '') {
				obj.value = obj.getAttribute("ovalue");
			}
		}
	}
}

function maxLimitLength(obj) {
	var maxlength = obj.getAttribute("maxLength")
	if (obj.value.length >= maxlength) {
		obj.value = obj.value.substring(0, maxlength);
	}
}

function getElementsByClassName(oElm, strTagName, strClassName) {
	var arrElements = (strTagName == "*" && oElm.all) ? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for (var i = 0; i < arrElements.length; i++) {
		oElement = arrElements[i];
		if (oRegExp.test(oElement.className)) {
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

function DisableExpressButton(btn, redirect) {
	if (redirect == null) {
		redirect = true;
	}
	var href = btn.getAttribute("href");

	if (href) { // button is allready disabled
		btn.setAttribute("xhref", href);

		btn.removeAttribute("href");
		Hover(btn, true, 'btndisabled');

		if (href && redirect)
			window.location = href;
	}

	var onclick = btn.getAttribute("onclick");

	if (onclick) { // button is allready disabled
		if (btn.getAttribute("onclick"))
			btn.setAttribute("xonclick", btn.getAttribute("onclick"));

		btn.removeAttribute("onclick");
		Hover(btn, true, 'btndisabled');
	}

}

function EnableExpressButton(btn) {

	btn.disabled = 0;
	var xhref = btn.getAttribute("xhref");

	if (xhref) { // button is allready enabled
		if (xhref) {
			btn.setAttribute("href", xhref);
			btn.removeAttribute("xhref");
		}
		Hover(btn, false, 'btndisabled');
	}

	var xonclick = btn.getAttribute("xonclick");

	if (xonclick) { // button is allready enabled
		if (xonclick) {
			btn.setAttribute("onclick", xonclick);
			btn.removeAttribute("xonclick");
		}
		Hover(btn, false, 'btndisabled');
	}
}

function EditContent(url) {
	window.open(url, 'contenteditor', 'width=1024,height=768,scrollbars=yes,toolbar=no,location=no,resizable=yes');
}

function DisplayContentButtons(show) {
	var items = getElementsByClassName(document, "cite", "admincmseditbutton");

	if (show) {
		for (var i = 0; i < items.length; i++) {
			removeCssClass(items[i], "cmsedithide");
		}
		$get("cmshidebutton").style.display = "block";
		$get("cmsshowbutton").style.display = "none";
	}
	else {
		for (var i = 0; i < items.length; i++) {
			if (!containsCssClass(items[i], "cmsedithide")) {
				addCssClass(items[i], "cmsedithide");
			}
		}
		$get("cmsshowbutton").style.display = "block";
		$get("cmshidebutton").style.display = "none";
	}

	document.cookie = "cmsiseb=" + show + "; path=/"
}

function ForceJavaUpload() {
	var url = window.location.toString();

	if (url.indexOf('?') > 0) {
		window.location = url + "&java=true";
	}
	else {
		window.location = url + "?java=true";
	}
}

// Trick to show validation callout when validation is invalid (bug in Ajax toolkit)
function TriggerValidationCallout(validationGroup) {
	try {
		if ((typeof (Page_Validators) != "undefined") && (Page_Validators != null)) {
			var i;
			for (i = 0; i < Page_Validators.length; i++) {
				var val = Page_Validators[i];
				if (val.validationGroup == validationGroup) {
					ValidatorValidate(val, validationGroup);
					if (!val.isvalid) {
						var x = val.controltovalidate;
						if ((x != null) && x != 'undefined') {
							var controlX = $get(x);
							if (controlX && controlX.disabled == false) {
								controlX.focus();
								return false;
							}
						}
					}
				}
			}
		}
		return true;
	}
	catch (error) {
		// do not block possible postback, because of js error  
		return true;
	}
}

function CheckValidationForControl(control, validationGroup) {
	try {
		if ((typeof (Page_Validators) != "undefined") && (Page_Validators != null) && control) {
			var i;
			for (i = 0; i < Page_Validators.length; i++) {
				var val = Page_Validators[i];
				if (val.validationGroup == validationGroup && val.getAttribute('controlToValidate') == control.id) {
					ValidatorValidate(val, validationGroup);
					if (!val.isvalid) {
						return false;
					}
				}
			}
		}
		return true;
	}
	catch (error) {
		// do not block possible postback, because of js error  
		return true;
	}
}

//----------------------------------------------------------------------
//  modified methods and functions copied from microsoft ajax library
//----------------------------------------------------------------------
function addCssClass(element, className) {
	if (!containsCssClass(element, className)) {
		if (element.className === '') {
			element.className = className;
		}
		else {
			element.className += ' ' + className;
		}
	}
}

function containsCssClass(element, className) {
	return Array.contains(element.className.split(' '), className);
}

function removeCssClass(element, className) {
	var currentClassName = ' ' + element.className + ' ';
	var index = currentClassName.indexOf(' ' + className + ' ');
	if (index >= 0) {
		element.className = (currentClassName.substr(0, index) + ' ' +
            currentClassName.substring(index + className.length + 1, currentClassName.length)).trim();
	}
}

var $get = function(id, element) {

	if (!element) return document.getElementById(id);
	if (element.getElementById) return element.getElementById(id);

	var nodeQueue = [];
	var childNodes = element.childNodes;
	for (var i = 0; i < childNodes.length; i++) {
		var node = childNodes[i];
		if (node.nodeType == 1) {
			nodeQueue[nodeQueue.length] = node;
		}
	}

	while (nodeQueue.length) {
		node = nodeQueue.shift();
		if (node.id == id) {
			return node;
		}
		childNodes = node.childNodes;
		for (i = 0; i < childNodes.length; i++) {
			node = childNodes[i];
			if (node.nodeType == 1) {
				nodeQueue[nodeQueue.length] = node;
			}
		}
	}

	return null;
}

Array.__typeName = 'Array';
Array.__class = true;

Array.add = Array.enqueue = function Array$enqueue(array, item) {
	array[array.length] = item;
}

Array.addRange = function Array$addRange(array, items) {
	array.push.apply(array, items);
}

Array.clear = function Array$clear(array) {
	array.length = 0;
}

Array.clone = function Array$clone(array) {
	if (array.length === 1) {
		return [array[0]];
	}
	else {
		return Array.apply(null, array);
	}
}

Array.contains = function Array$contains(array, item) {
	return (Array.indexOf(array, item) >= 0);
}

Array.dequeue = function Array$dequeue(array) {
	return array.shift();
}

Array.forEach = function Array$forEach(array, method, instance) {
	for (var i = 0, l = array.length; i < l; i++) {
		var elt = array[i];
		if (typeof (elt) !== 'undefined') method.call(instance, elt, i, array);
	}
}

Array.indexOf = function Array$indexOf(array, item, start) {
	if (typeof (item) === "undefined") return -1;
	var length = array.length;
	if (length !== 0) {
		start = start - 0;
		if (isNaN(start)) {
			start = 0;
		}
		else {
			if (isFinite(start)) {
				start = start - (start % 1);
			}
			if (start < 0) {
				start = Math.max(0, length + start);
			}
		}

		for (var i = start; i < length; i++) {
			if ((typeof (array[i]) !== "undefined") && (array[i] === item)) {
				return i;
			}
		}
	}
	return -1;
}

Array.insert = function Array$insert(array, index, item) {
	array.splice(index, 0, item);
}

Array.parse = function Array$parse(value) {
	if (!value) return [];
	var v = eval(value);
	if (!Array.isInstanceOfType(v)) throw Error.argument('value', Sys.Res.arrayParseBadFormat);
	return v;
}

Array.remove = function Array$remove(array, item) {
	var index = Array.indexOf(array, item);
	if (index >= 0) {
		array.splice(index, 1);
	}
	return (index >= 0);
}

Array.removeAt = function Array$removeAt(array, index) {
	array.splice(index, 1);
}

// String

String.__typeName = 'String';
String.__class = true;

String.prototype.endsWith = function String$endsWith(suffix) {
	return (this.substr(this.length - suffix.length) === suffix);
}

String.prototype.startsWith = function String$startsWith(prefix) {
	return (this.substr(0, prefix.length) === prefix);
}

String.prototype.trim = function String$trim() {
	return this.replace(/^\s+|\s+$/g, '');
}

String.prototype.trimEnd = function String$trimEnd() {
	return this.replace(/\s+$/, '');
}

String.prototype.trimStart = function String$trimStart() {
	return this.replace(/^\s+/, '');
}

String.format = function String$format(format, args) {
	return String._toFormattedString(false, arguments);
}

String.localeFormat = function String$localeFormat(format, args) {
	return String._toFormattedString(true, arguments);
}

String._toFormattedString = function String$_toFormattedString(useLocale, args) {
	var result = '';
	var format = args[0];

	for (var i = 0; ; ) {
		var open = format.indexOf('{', i);
		var close = format.indexOf('}', i);
		if ((open < 0) && (close < 0)) {
			result += format.slice(i);
			break;
		}
		if ((close > 0) && ((close < open) || (open < 0))) {
			if (format.charAt(close + 1) !== '}') {
				throw Error.argument('format', Sys.Res.stringFormatBraceMismatch);
			}
			result += format.slice(i, close + 1);
			i = close + 2;
			continue;
		}

		result += format.slice(i, open);
		i = open + 1;

		if (format.charAt(i) === '{') {
			result += '{';
			i++;
			continue;
		}

		if (close < 0) throw Error.argument('format', Sys.Res.stringFormatBraceMismatch);


		var brace = format.substring(i, close);
		var colonIndex = brace.indexOf(':');
		var argNumber = parseInt((colonIndex < 0) ? brace : brace.substring(0, colonIndex)) + 1;
		if (isNaN(argNumber)) throw Error.argument('format', Sys.Res.stringFormatInvalid);
		var argFormat = (colonIndex < 0) ? '' : brace.substring(colonIndex + 1);

		var arg = args[argNumber];
		if (typeof (arg) === "undefined" || arg === null) {
			arg = '';
		}

		if (arg.toFormattedString) {
			result += arg.toFormattedString(argFormat);
		}
		else if (useLocale && arg.localeFormat) {
			result += arg.localeFormat(argFormat);
		}
		else if (arg.format) {
			result += arg.format(argFormat);
		}
		else
			result += arg.toString();

		i = close + 1;
	}

	return result;
}

// Code for albumselection grayed-out existing and new
//**************************************************
function RadioButtonAlbum_click(clientIdPrefix) {
	var RadioNew = $get(clientIdPrefix + "RadioButtonNew");
	var dropdown = $get(clientIdPrefix + "DropDownListAlbums");
	var textbox = $get(clientIdPrefix + "InputNewAlbum");

	if ((RadioNew != null) && (RadioNew.checked)) {
		if (textbox) { textbox.disabled = false; }
		if (dropdown) { dropdown.disabled = true; }
	}
	else {
		if (textbox) { textbox.disabled = true; }
		if (dropdown) { dropdown.disabled = false; }
	}
}

function CheckRadioButtonNewAlbum(clientIdPrefix) {
	var RadioNew = $get(clientIdPrefix + "RadioButtonNew");

	if (RadioNew != null) {
		RadioNew.checked = true
	}
}

function CheckRadioButtonExistingAlbum(clientIdPrefix) {
	var RadioExisting = $get(clientIdPrefix + "RadioButtonExisting");

	if (RadioExisting != null) {
		RadioExisting.checked = true
	}
}

/* Onmouseover and onmouseout for rcHover */
function RCIn(item, prefix) {
	var el = jQuery(item);
	if (typeof (prefix) == "undefined") { prefix = "boxRc"; }
	el.find("." + prefix + "Topleft").css({ 'background-position': '0 -435px' });
	el.find("." + prefix + "Topright").css({ 'background-position': 'right -435px' });
	el.find("." + prefix + "Bottomleft").css("background-position", "0 -856px");
	el.find("." + prefix + "Bottomright").css("background-position", "right -856px");
}
function RCOut(item, prefix) {
	if (containsCssClass(item, "selected")) { return; }
	var el = jQuery(item);
	if (typeof (prefix) == "undefined") { prefix = "boxRc"; }
	el.find("." + prefix + "Topleft").css("background-position", "0 0");
	el.find("." + prefix + "Topright").css("background-position", "right 0");
	el.find("." + prefix + "Bottomleft").css("background-position", "0 -421px");
	el.find("." + prefix + "Bottomright").css("background-position", "right -421px");
}

function ResetRCAddIn(resetelement, prefix) {
	jQuery("." + resetelement + " div").each(function() {
		RCOut(this, prefix);
	});
	jQuery("." + resetelement + " li").each(function() {
		RCOut(this, prefix);
	});
}

function RCAddIn(item, prefix, resetelement) {
	if (resetelement) {
		ResetRCAddIn(resetelement, prefix);
	}
	var el = jQuery(item);
	if (typeof (prefix) == "undefined") { prefix = "boxRc"; }
	if (typeof (el.find("." + prefix + "Topleft")[0]) == "undefined") {
		var offset = 14;
		var varHeight = el[0].offsetHeight;
		var varWidth = el[0].offsetWidth;
		el.append("<span class='" + prefix + "Topleft'></span>");
		el.append("<span class='" + prefix + "Topright'></span>");
		el.append("<span class='" + prefix + "Bottomleft'></span>");
		el.append("<span class='" + prefix + "Bottomright'></span>");
		el.find("." + prefix + "Topleft").css({ 'height': varHeight - offset });
		el.find("." + prefix + "Topright").css({ 'height': varHeight - offset });
		el.find("." + prefix + "Topleft").css({ 'width': varWidth - offset });
		el.find("." + prefix + "Bottomleft").css({ 'width': varWidth - offset });
	}
	RCIn(item);
}

function jHover(item, hover, cssclass) {
	if (hover) {
		item.addClass(cssclass);
	}
	else {
		item.removeClass(cssclass);
	}
}

function getEl() {
	var ev = arguments[0] || window.event,
    origEl = ev.target || ev.srcElement;
	return origEl;
}

function GetQueryVariable(qv) {

	var val = queryget(qv);
	if (val.length > 0)
		return "&" + qv + "=" + val;
	else
		return '';
}

function GoToDesignSelection(aObj) {

	var occ = queryget("occ");
	var des = queryget("des");

	if (occ.length > 0)
		occ = "occ=" + occ;

	if (des.length > 0)
		des = "&des=" + des;

	var prefix = "";
	if (occ.length > 0 || des.length > 0)
		prefix = ((aObj.href.length > 0 && aObj.href.indexOf('?') == -1) ? "?" : "&");

	document.location.href = aObj.href + prefix + occ + des;

	return false;
}


function CheckOptions(dialogdataid, messageid) {
	var href = getEl().parentNode.href;
	var item = jQuery("#" + messageid);

	jHover(item, false, "txtRed");

	var selection = "";
	jQuery("input", jQuery("#" + dialogdataid)).each(function() {
		if (this.checked) {
			selection = this.value;
		}
	});

	if (selection.length == 0) {
		jHover(item, true, "txtRed");
		return false;
	}

	// redirect
	window.location = href + "?prd=" + selection;

	return false;
}

function PopupRequired(url) {

	var pt = queryget("pt");
	var wpc = queryget("wpc");
	var occ = queryget("occ");
	var des = queryget("des");

	// pt and wpc parameters are required
	if (pt.length > 0 && wpc.length > 0) {
		pt = "?pt=" + pt;
		wpc = "&wpc=" + wpc;
		// check optional parameters
		if (occ.length > 0)
			occ = "&occ=" + occ;

		if (des.length > 0)
			des = "&des=" + des;

		// redirect
		window.location = url + pt + wpc + occ + des;

		return false;
	}
	else {
		return true;
	}
}

function queryget(name) {
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(window.location.href.replace("%20", " "));
	if (results == null)
		return "";
	else
		return results[1];
}

function GetCookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return "";
}

function SetCookie(c_name, value) {
	document.cookie = c_name + "=" + escape(value) + ";path=/";
}

/* -- long loading dialog -- */
var loadingdialog = {
	show: function(e) {
		var layerback = jQuery("#layerback");
		var layertop = jQuery("#layertop");
		var layeriframe = jQuery("#layeriframe");
		if (layerback.length == 0) {
			layerback = jQuery("<div id='layerback' style='filter: alpha(opacity=0);'></div>");
			jQuery("#" + container_client_id).append(layerback);
			if (isIE6) {
				layeriframe = jQuery("<iframe id='layeriframe' style='position:absolute;top:0px;left:0px;z-index:199;filter:alpha(opacity=60);' frameBorder='0' scrolling='no'></iframe>");
				layeriframe.attr("src", iframesrc);
				layerback.append(layeriframe);
			}
			layertop = jQuery("<div id='layertop' class='longloadingdialog'></div>");
			jQuery.ajax({
				type: "POST",
				url: "/UiService.asmx/GetDialogContent",
				data: " {Mnemonic: 'ProductEditor.LongLoadingText' }",
				contentType: "application/json; charset=utf-8",
				dataType: "json",
				success: function(msg, status, raw) {
					if (!(msg == null && raw.status == 0))
						layertop.html(msg.d);
				}
			});
			jQuery("#" + container_client_id).append(layertop);

			this.resizeTimer = null;
			jQuery(window).resize(function(e) {
				captureMousePosition(e);
				if (this.resizeTimer)
					clearTimeout(this.resizeTimer);
				this.resizeTimer = setTimeout(loadingdialog.position, 10);
			});

			layerback.fadeTo("fast", 0.4);
		}
		layerback.show(); //.fadeTo("fast", 0.4);
		layertop.fadeIn("fast");
		layerback.data("active", true);
		this.position(e);
	},

	close: function(e) {
		jQuery("#layertop").fadeOut("fast");
		var layerback = jQuery("#layerback");
		layerback.hide().data("active", false);
	},

	position: function(e) {
		if (this.resizeTimer)
			clearTimeout(this.resizeTimer);
		var layerback = jQuery("#layerback");
		if (layerback.length && layerback.data("active")) {
			var win = jQuery(window);

			layerback.css({ height: win.height() + win.scrollTop(), width: win.width() });

			if (jQuery("#layeriframe").length) {
				jQuery("#layeriframe").css({ width: win.width(), height: win.height() + win.scrollTop() });
			}
			var layertop = jQuery("#layertop");
			var l = (parseInt(win.width()) / 2) - (parseInt(layertop[0].clientWidth) / 2);
			var t = (parseInt(win.height()) / 2) + win.scrollTop() - (parseInt(layertop[0].clientHeight) / 2);

			layertop.css({ left: l, top: t });
		}
	}
}

// used in loginbox (contentTag and registration page)
function AutoCompleteSaveForm() {
	if (isIE && !isOOS) {
		window.external.AutoCompleteSaveForm(document.forms['aspnetForm']);
	}
}

// used in loginbox (contentTag and registration page)
function LoginItemChanged() {
	if (typeof (LoginEnableButton) != "undefined") {
		LoginEnableButton();
	}
}