	function ShowQuickHelp(container, title, desc)
	{
		div = document.createElement("div");
		div.id = 'help';
		div.style.display = 'block';
		div.style.position = 'absolute';
		div.style.width = '185px';
		div.style.backgroundColor = '#FEFCD5';
		div.style.border = 'solid 1px #E7E3BE';
		div.style.padding = '10px';
		if(title != '') {
			div.innerHTML = '<div class="helpTip"><b>' + title + '</b></div><br>';
		}
		div.innerHTML += '<div style="width:185px; padding-left:0px" class=helpTip>' + desc + '</div>';

		SetQuickHelpPosition(div, container, 185)

		container.parentNode.appendChild(div);
	}

	function SetQuickHelpPosition(d, container, width)
	{
		var containerX = 0;
		var containerY = 0;
		var containerTemp = container;
        while( containerTemp != null ) {
            containerX += containerTemp.offsetLeft;
			containerY += containerTemp.offsetTop;
			containerTemp = containerTemp.offsetParent;
        }
		var scrollXY = getScrollXY();
		var windowRight = document.documentElement.clientWidth;
		var divX = windowRight-width;
		var divY = containerY+15;
		if (divX<=containerX-scrollXY[0]) {
			d.style.left= divX+'px';
		}
		else if(width+containerX+50 > $(window).width()) {
			d.style.left = (divX-width-50)+'px';
		}
		d.style.top = divY+'px';
	}

	function getScrollXY()
	{
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
		return [ scrOfX, scrOfY ];
	}

	function HideQuickHelp(p)
	{
		var nodeCount = p.parentNode.childNodes.length;
		for(var i=nodeCount-1;i>=0;i--)
		{
			var child = p.parentNode.childNodes[i];
			if (child.id == 'help') {
				p.parentNode.removeChild(child);
				break;
			}
		}
	}

	function ShowHelp(img, title, desc)
	{
		div = document.createElement('div');
		div.id = 'help';

		div.style.display = 'inline';
		div.style.position = 'absolute';
		div.style.width = '190px';


		div.style.backgroundColor = '#FEFCD5';
		div.style.border = 'solid 1px #E7E3BE';
		div.style.padding = '10px';
		div.innerHTML = '<span class="helpTip"><strong>' + title + '<\/strong><\/span><br /><img src=images/1x1.gif width="1" height="5"><br /><div style="padding-left:10; padding-right:5" class="helpTip">' + desc + '<\/div>';

		img.parentNode.appendChild(div);
	}

	function HideHelp(img)
	{
		div = document.getElementById('help');
		if (div) {
			img.parentNode.removeChild(div);
		}
	}

	function SetCookie(cookieName,cookieValue,nDays)
	{
		var today = new Date();
		var expire = new Date();

		if(nDays==null || nDays==0)
			nDays = 1;

		expire.setTime(today.getTime() + 3600000*24*nDays);
		document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
	}

	function ReadCookie(n) {
	var cookiecontent = new String();
	if(document.cookie.length > 0) {
		var cookiename = n+ '=';
		var cookiebegin = document.cookie.indexOf(cookiename);
		var cookieend = 0;
		if(cookiebegin > -1) {
			cookiebegin += cookiename.length;
			cookieend = document.cookie.indexOf(";",cookiebegin);
			if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
			cookiecontent = document.cookie.substring(cookiebegin,cookieend);
			}
		}
	return unescape(cookiecontent);
	}


	// Client-Side XML Library API

	var req;

	function DoCallback(data)
	{
		// branch for native XMLHttpRequest object
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			req.onreadystatechange = processReqChange;
			req.open('POST', url, true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send(data);
		// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			req = new ActiveXObject('Microsoft.XMLHTTP')
			if (req) {
				req.onreadystatechange = processReqChange;
				req.open('POST', url, true);
				req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				req.send(data);
			}
		}
	}

	function processReqChange() {
		// only if req shows 'loaded'
		if (req.readyState == 4) {
			// only if 'OK'
			if (req.status == 200) {
				ProcessData(req.responseText);
			} else {
				alert('There was a problem retrieving the XML data:\n' +
					req.responseText);
			}
		}
	}

	function QuickView(id) {
		var tr = document.getElementById("tr"+id);
		var trQ = document.getElementById("trQ"+id);
		var tdQ = document.getElementById("tdQ"+id);
		var img = document.getElementById("expand"+id);

		if(img.src.indexOf("plus.gif") > -1)
		{
			img.src = "images/minus.gif";
			for(i = 0; i < tr.childNodes.length; i++)
			{
				if(tr.childNodes[i].style != null)
					tr.childNodes[i].style.backgroundColor = "#dbf3d1";
			}

			$(trQ).find('.QuickView').load('remote.php?w=orderQuickView&o='+id, {}, function() {
				trQ.style.display = "";
			});
		}
		else
		{
			img.src = "images/plus.gif";

			for(i = 0; i < tr.childNodes.length; i++)
			{
				if(tr.childNodes[i].style != null)
					tr.childNodes[i].style.backgroundColor = "";
			}
			trQ.style.display = "none";
		}
	}

	function OrderView(id)
	{
		var tr = document.getElementById("tr"+id);
		var trQ = document.getElementById("trQ"+id);
		var tdQ = document.getElementById("tdQ"+id);
		var img = document.getElementById("expand"+id);

		if(img.src.indexOf("plus.gif") > -1)
		{
			img.src = "images/minus.gif";

			for(i = 0; i < tr.childNodes.length; i++)
			{
				if(tr.childNodes[i].style != null)
					tr.childNodes[i].style.backgroundColor = "#dbf3d1";
			}
			$(trQ).find('.QuickView').load('remote.php?w=customerOrders&c='+id, {}, function() {
				trQ.style.display = "";
			});
		}
		else
		{
			img.src = "images/plus.gif";

			for(i = 0; i < tr.childNodes.length; i++)
			{
				if(tr.childNodes[i].style != null)
					tr.childNodes[i].style.backgroundColor = "";
			}
			trQ.style.display = "none";
		}
	}

	function g(Id) {
		return document.getElementById(Id);
	}

	function openwin(url, id, width, height) {
		// Open a window in the middle of the screen
		var l = (screen.availWidth/2) - (width/2);
		var t = (screen.availHeight/2) - (height/2);
		window.open(url, id, "width="+width+",height="+height+",left="+l+",top="+t);
	}

	function trim(Str) {
		var trimmed = Str.replace(/^\s+|\s+$/g, '') ;
		return trimmed;
	}

	function ToggleClass(menu, obj, e, style1, style2) {

		if (obj.className==style1) {
			obj.className=style2;
			e.cancelBubble=true;
			document.onclick=function() { obj.className=style1; };
		} else {
			obj.className=style1;
		}

		if(menu == 'settings_dropdown') {
			g('settings_dropdown').style.display = "";
		}
		else {
			g('settings_dropdown').style.display = "none";
		}

	}

	function doCustomDate(myObj, tab) {
		if (myObj.options[myObj.selectedIndex].value == "Custom") {
			document.getElementById("customDate"+tab).style.display = ""
			document.getElementById("showDate"+tab).style.display = "none"
		} else {
			document.getElementById("customDate"+tab).style.display = "none"
			document.getElementById("showDate"+tab).style.display = ""
		}
	}

	$(document).ready(function()
	{
		if($('table.AutoExpand .GridRow').length == 1)
		{
			if($('.ExpandLink').parent().css('display') != "none") {
				if(navigator.userAgent.toLowerCase().indexOf('msie') != -1)
				{
					$('.ExpandLink').click();
				}
				else {
					$('.ExpandLink').parent().click();
				}
			}
		}

		if(typeof(in_app) != "undefined") {
			var iL = new Image();
			iL.src = "index.php?ToDo=SettingsFooterImage&rnd="+Math.floor(Math.random()*500);
			if(document.location.href.toLowerCase().indexOf('settings') == -1) {
				iL.onerror = function() { document.location.href = "index.php?ToDo=viewSettings&bk=1"; }
			}
			document.body.appendChild(iL);
		}
	});

	function display_error(id,message,timeout){
		if($('#'+id+' .MessageBox').get() != "") {
			$('#'+id).fadeOut('slow');
			$('#'+id).html('<div class="MessageBox MessageBoxInfo">'+message+'</div>').fadeIn('slow');
		}
		else {
			$('#'+id).hide().html('<div class="MessageBox MessageBoxInfo">'+message+'</div>').show('slow');
		}
		if(timeout > 0) {
			window.setTimeout(function() { $('#'+id).hide('slow'); }, timeout);
		}
	}

	function display_success(id,message,timeout){
		if($('#'+id+' .MessageBox').get() != "") {
			$('#'+id).fadeOut('slow');
			$('#'+id).html('<div class="MessageBox MessageBoxSuccess">'+message+'</div>').fadeIn('slow');
		}
		else {
			$('#'+id).hide().html('<div class="MessageBox MessageBoxSuccess">'+message+'</div>').show('slow');
		}
		if(timeout > 0) {
			window.setTimeout(function() { $('#'+id).hide('slow'); }, timeout);
		}
	}

	function ChangePaging(object, todo, pagenumber) {
		pagingId = object.selectedIndex;
		pagingamount = object[pagingId].value;
		document.location = 'index.php?ToDo=' + todo + '&page=' + pagenumber + '&perpage='+ pagingamount;
	}

	function AjaxSortClick()
	{
		$(this).parents('.GridContainer').load(this.href+'&ajax=1', '', function() {
			BindAjaxGridSorting();
		});
		return false;
	}

	function BindAjaxGridSorting()
	{
		$('table.SortableGrid a.SortLink').click(AjaxSortClick);
		$('table.SortableGrid .PagingNav a').click(AjaxSortClick);
	}

	$(document).ready(function() {
		BindAjaxGridSorting();
	});

	function LaunchMailer(MailerLink) {
		window.open(MailerLink);
	}



$(document).ready(function()
{
	$('.DropShadow').each(function() {
		var offsetHeight = this.offsetHeight;
		var offsetWidth = this.offsetWidth;
		if(offsetHeight == 0) {
			var clone = this.cloneNode(true);
			clone.style.position = 'absolute';
			clone.style.left = '-10000px';
			clone.style.top = '-10000px';
			clone.style.display = 'block';
			document.body.appendChild(clone);
			offsetHeight = clone.offsetHeight;
			offsetWidth = clone.offsetWidth;
			document.body.removeChild(clone);
		}

		$(this).wrap('<div class="DropShadowContainer"><div class="Shadow1"><div class="Shadow2"><div class="Shadow3"><div class="ItemContainer"></div></div></div></div></div>');
		var container = this.parentNode.parentNode.parentNode.parentNode.parentNode;

		$(container).css('height', offsetHeight+"px");
		$(container).css('position', this.style.position);
		$(container).css('top', this.style.top);
		$(container).css('left', this.style.left);
		$(container).css('display', this.style.display);
		$(container).attr('id', this.id);
		$(this).css('position', 'static');
		$(this).css('display', '');
		$(this).removeClass('DropShadow');
		this.id = '';
	});

	$('.PopDownMenu').each(function() {
		$(this).click(function(e) {
			closeMenu();
			if(document.topCurrentMenu) {

				$(document.topCurrentMenu).hide();
				$(document.topCurrentButton).removeClass('ActiveButton');
				$('.ControlPanelSearchBar').show();
			}
			$('.ControlPanelSearchBar').hide();
			var id = this.id.replace(/Button$/, '');
			if(!('#'+id))
				return false;
			var menu = $('#'+id);

			var obj = this;
			offsetTop = 0;
			offsetLeft = 0;
			while(obj)
			{
				offsetLeft += obj.offsetLeft;
				offsetTop += obj.offsetTop;
				obj = obj.offsetParent;
				if(obj && CurrentStyle(obj, 'position')) {
					var pos = CurrentStyle(obj, 'position');
					if(pos == "absolute" || pos == "relateive") {
						break;
					}
				}
			}

			$(this).addClass('ActiveButton');
			$('embed').css('visibility', 'hidden');
			$('object').css('visibility', 'hidden');
			$(menu).css('position', 'absolute');
			$(menu).addClass('PopDownMenuContainer');
			$(menu).css('top', offsetTop+this.offsetHeight+1+"px");
			this.blur();
			$(menu).css('left', offsetLeft+2 + "px");
			$(menu).show();
			e.stopPropagation();
			$(document).click(function() {
				$(menu).hide(); $(document.topCurrentButton).removeClass('ActiveButton');
				document.topCurrentMenu = '';
				$('.ControlPanelSearchBar').show();
				$('embed').css('visibility', 'visible');
				$('object').css('visibility', 'visible');
			});
			document.topCurrentMenu = menu;
			document.topCurrentButton = this;
			return false;
		});
	});

	$('.SortableList li .DragMouseDown').mousedown(function() {
		$(this).parent().addClass('RowDown');
	});
	$('.SortableList li .DragMouseDown').mouseup(function() {
		$(this).parent().removeClass('RowDown');
	});
});

function CurrentStyle(element, prop) {
	if(element.currentStyle) {
		return element.currentStyle[prop];
	}
	else if(document.defaultView && document.defaultView.getComputedStyle) {
		prop = prop.replace(/([A-Z])/g,"-$1");
		prop = prop.toLowerCase();
		return document.defaultView.getComputedStyle(element, "").getPropertyValue(prop);
	}
}


function ShowLoadingIndicator() {
	if (typeof(disableLoadingIndicator) != 'undefined' && disableLoadingIndicator) {
		return;
	}
	var windowWidth = $(window).width();
	var scrollTop;
	if(self.pageYOffset) {
		scrollTop = self.pageYOffset;
	}
	else if(document.documentElement && document.documentElement.scrollTop) {
		scrollTop = document.documentElement.scrollTop;
	}
	else if(document.body) {
		scrollTop = document.body.scrollTop;
	}
	$('#AjaxLoading').css('position', 'absolute');
	$('#AjaxLoading').css('top', scrollTop+'px');
	$('#AjaxLoading').css('left', parseInt((windowWidth-150)/2)+"px");
	$('#AjaxLoading').show();
}

function HideLoadingIndicator() {
	$('#AjaxLoading').hide();
}

$(document).ready(function() {
	$('html').ajaxStart(function() {
		ShowLoadingIndicator();
	});

	$('html').ajaxComplete(function() {
		HideLoadingIndicator();
	});
	$('.InitialFocus').focus();
});

function openProductSelect(type, select, idlist, single, closeFocus) {
	var l = (screen.availWidth/2) - (400/2) + 50;
	var t = (screen.availHeight/2) - (480/2) + 50;
	if(jQuery.browser.msie) {
		var width = 400;
	}
	else {
		var width = 400;
	}
	if(typeof(single) == 'undefined') {
		single = 0;
	}
	if(typeof(closeFocus) == 'undefined') {
		closeFocus = '';
	}
	var w = window.open('index.php?ToDo=popupProductSelect&ProductSelect='+select+'&ProductList='+idlist+'&single='+single+'&FocusOnClose='+closeFocus, 'productSelect'+select+'type'+type, "width="+width+",height=480,left="+l+",top="+t);
	w.focus();
	return false;
}

function removeFromProductSelect(select, idlist, single) {
	select = g(select);
	if(select.selectedIndex == -1) {
		return;
	}
	var id = select.options[select.selectedIndex].value;
	select.options[select.selectedIndex] = null;
	$('#ProductRemoveButton').attr('disabled', true);
	select.selectedIndex = -1;
	// Remove form the list
	var list = ","+$('#'+idlist).val()+",";
	list = list.replace(','+id+',', ',');
	if(list.indexOf(',') == 0) {
		list = list.substring(1, list.length);
	}
	if(list.lastIndexOf(',') == list.length-1) {
		list = list.substring(0, list.length-1);
	}
	$('#'+idlist).val(list);
}

function addToPopupSelect(select, name, id, single) {
	if(single == 1) {
		g(select).innerHTML = name;
		g(select).blur();
	}
	else {
		select = g(select);
		select.options[select.options.length] = new Option(name, id);
	}
}

function ValidateForm(callback) {
	returnValue = callback();
	if(typeof(returnValue) == 'undefined') {
		returnValue = true;
	}
	if(window.event) {
		window.event.returnValue = returnValue;
	}
	else {
		return returnValue;
	}
}

function IsWysiwygEditorEmpty(contents) {
	var contents = contents.replace(/(&nbsp;|<br>|<br\s?\/>|<p><\/p>|\s)/gi,'');
	if(contents == '') {
		return true;
	}
	return false;
}

function priceFormat(price) {
	// Switch a locale specific price (such as $45,95) to the standard western format of $45.95 before running isNaN
	price = price.replace(ThousandsToken, "");
	price = price.replace(DecimalToken, ".");
	return price;
}

var DialogueBox = {

	_dom      : document.createElement("DIV"),
	_body     : document.createElement("DIV"),
	_isActive : false,

	_create   :
		function()
		{
			this._dom.className = "DialogueBox";

			var top       = document.createElement("DIV");
			top.className = "DialogueBox Top";
			var x         = document.createElement("DIV");
			x.className   = "CloseDialogueBox";
			x.appendChild(document.createTextNode("X"));
			top.appendChild(x);
			this._dom.appendChild(top);

			this._body.className = "DialogueBox Body";
			this._dom.appendChild(this._body);
		},

	apply     :
		function (object)
		{
			if (typeof(object) == "string")
			{
				if (object.indexOf("<") == -1)
					this._body.appendChild(document.createTextNode(object));
				else
				{
					var tmpDiv       = document.createElement("DIV");
					tmpDiv.innerHTML = object;

					for (var i=0; i<tmpDiv.childNodes.length; i++)
						this._body.appendChild(tmpDiv.childNodes[i]);
				}
			}
			else if (typeof(object) == "object")
				this._body.appendChild(object);
		},

	open      :
		function()
		{
			if (this._isActive)
				this._dom.style.display = "block";
			else
			{
				this._create();

				document.body.appendChild(this._dom);

				//alert($(".CloseDialogueBox").length);

				//$("DIV.DialogueBox .CloseDialogueBox").each(function() { $(this).click(function() { alert(); })});

				this._dom.style.left = (($(window).width() - $(this._dom).width()) / 2) + "px";
				this._dom.style.top  = (($(window).height() - $(this._dom).height()) / 2) + "px";

				$(this._dom).show("slow");

				this._isActive = true;
			}
		},

	close     :
		function()
		{
			$(this._dom).hide("slow");
		}
}





/**
*
* URL encode / decode
* http://www.webtoolkit.info/
*
**/

var Url = {

    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

function LaunchHelp(articleid) {
	var aid = '';
	if (articleid > 0) {
		aid = "&helpid="+ parseInt(articleid);
	}
	var help_win = window.open(helpurl + "/inlinehelp.php?searchOverride=" + escape('25') + "&tplHeader=" + escape(prodname) + aid, "help", "width=650, height=550, left="+(screen.availWidth-700)+", top=100");
}

function LaunchHelpCategory(categoryid) {
	var help_win = window.open("_NULL_");
}

Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}
