if (!window.qgcolor) { window.qgcolor = (function () {var qgcl = {register : function () {qgcl.attachDOMReadyEvent(qgcl.init);	qgcl.attachEvent(document, 'mousedown', qgcl.onDocumentMouseDown);qgcl.attachEvent(document, 'touchstart', qgcl.onDocumentTouchStart);qgcl.attachEvent(window, 'resize', qgcl.onWindowResize);},init : function () {if (qgcl.qgcolor.qgClass) {qgcl.qgcolor.installByClassName(qgcl.qgcolor.qgClass);}},tryInstallOnElements : function (elms, className) {var matchClass = new RegExp('(^|\\s)(' + className + ')(\\s*(\\{[^}]*\\})|\\s|$)', 'i');for (var i = 0; i < elms.length; i += 1) {if (elms[i].type !== undefined && elms[i].type.toLowerCase() == 'color') {if (qgcl.isColorAttrSupported) {continue;}}	var m;if (!elms[i].qgcolor && elms[i].className && (m = elms[i].className.match(matchClass))) {	var targetElm = elms[i];var optsStr = null;var dataOptions = qgcl.getDataAttr(targetElm, 'qgcolor');if (dataOptions !== null) {optsStr = dataOptions;} else if (m[4]) {optsStr = m[4];}var opts = {};if (optsStr) {try {opts = (new Function ('return (' + optsStr + ')'))();} catch(eParseError) {qgcl.warn('Error parsing qgcolor options: ' + eParseError + ':\n' + optsStr);}}	targetElm.qgcolor = new qgcl.qgcolor(targetElm, opts);}}},
isColorAttrSupported : (function () {	var elm = document.createElement('input');if (elm.setAttribute) {elm.setAttribute('type', 'color');if (elm.type.toLowerCase() == 'color') {return true;	}}return false;	})(),isCanvasSupported : (function () {var elm = document.createElement('canvas');return !!(elm.getContext && elm.getContext('2d'));	})(),fetchElement : function (mixed) {	return typeof mixed === 'string' ? document.getElementById(mixed) : mixed;},isElementType : function (elm, type) {return elm.nodeName.toLowerCase() === type.toLowerCase();},getDataAttr : function (el, name) {var attrName = 'data-' + name;	var attrValue = el.getAttribute(attrName);if (attrValue !== null) {return attrValue;}return null;},attachEvent : function (el, evnt, func) {if (el.addEventListener) {el.addEventListener(evnt, func, false);} else if (el.attachEvent) {el.attachEvent('on' + evnt, func);}},detachEvent : function (el, evnt, func) {	if (el.removeEventListener) {el.removeEventListener(evnt, func, false);	} else if (el.detachEvent) {el.detachEvent('on' + evnt, func);}	},_attachedGroupEvents : {},	attachGroupEvent : function (groupName, el, evnt, func) {	if (!qgcl._attachedGroupEvents.hasOwnProperty(groupName)) {qgcl._attachedGroupEvents[groupName] = [];	}qgcl._attachedGroupEvents[groupName].push([el, evnt, func]);qgcl.attachEvent(el, evnt, func);	},detachGroupEvents : function (groupName) {if (qgcl._attachedGroupEvents.hasOwnProperty(groupName)) {for (var i = 0; i < qgcl._attachedGroupEvents[groupName].length; i += 1) {var evt = qgcl._attachedGroupEvents[groupName][i];qgcl.detachEvent(evt[0], evt[1], evt[2]);}delete qgcl._attachedGroupEvents[groupName];}},attachDOMReadyEvent : function (func) {var fired = false;	var fireOnce = function () {if (!fired) {fired = true;	func();	}};if (document.readyState === 'complete') {setTimeout(fireOnce, 1);return;}if (document.addEventListener) {document.addEventListener('DOMContentLoaded', fireOnce, false);window.addEventListener('load', fireOnce, false);	} else if (document.attachEvent) {document.attachEvent('onreadystatechange', function () {if (document.readyState === 'complete') {document.detachEvent('onreadystatechange', arguments.callee);fireOnce();}
			})

window.attachEvent('onload', fireOnce);
if (document.documentElement.doScroll && window == window.top) {var tryScroll = function () {if (!document.body) { return; }try {document.documentElement.doScroll('left');	fireOnce();	} catch (e) {	setTimeout(tryScroll, 1);}};	tryScroll();}	}},	warn : function (msg) {	if (window.console && window.console.warn) {	window.console.warn(msg);}},	preventDefault : function (e) {	if (e.preventDefault) { e.preventDefault(); }	e.returnValue = false;	},captureTarget : function (target) {	if (target.setCapture) {qgcl._capturedTarget = target;	qgcl._capturedTarget.setCapture();}},	releaseTarget : function () {	if (qgcl._capturedTarget) {	qgcl._capturedTarget.releaseCapture();	qgcl._capturedTarget = null;	}},fireEvent : function (el, evnt) {if (!el) {	return;	}if (document.createEvent) {	var ev = document.createEvent('HTMLEvents');	ev.initEvent(evnt, true, true);	el.dispatchEvent(ev);} else if (document.createEventObject) {	var ev = document.createEventObject();	el.fireEvent('on' + evnt, ev);	} else if (el['on' + evnt]) { 	el['on' + evnt]();}},	classNameToList : function (className) {	return className.replace(/^\s+|\s+$/g, '').split(/\s+/);},hasClass : function (elm, className) {if (!className) {return false;	}		return -1 != (' ' + elm.className.replace(/\s+/g, ' ') + ' ').indexOf(' ' + className + ' ');	},setClass : function (elm, className) {var classList = qgcl.classNameToList(className);for (var i = 0; i < classList.length; i += 1) {	if (!qgcl.hasClass(elm, classList[i])) {elm.className += (elm.className ? ' ' : '') + classList[i];	}	}},unsetClass : function (elm, className) {var classList = qgcl.classNameToList(className);for (var i = 0; i < classList.length; i += 1) {	var repl = new RegExp('^\\s*' + classList[i] + '\\s*|' +'\\s*' + classList[i] + '\\s*$|' +'\\s+' + classList[i] + '(\\s+)','g');elm.className = elm.className.replace(repl, '$1');}},getStyle : function (elm) {return window.getComputedStyle ? window.getComputedStyle(elm) : elm.currentStyle;},setStyle : (function () {		var helper = document.createElement('div');
		var getSupportedProp = function (names) {
			for (var i = 0; i < names.length; i += 1) {if (names[i] in helper.style) {return names[i];}}};var props = {borderRadius: getSupportedProp(['borderRadius', 'MozBorderRadius', 'webkitBorderRadius']),boxShadow: getSupportedProp(['boxShadow', 'MozBoxShadow', 'webkitBoxShadow'])};return function (elm, prop, value) {switch (prop.toLowerCase()) {	case 'opacity':	var alphaOpacity = Math.round(parseFloat(value) * 100);	elm.style.opacity = value;elm.style.filter = 'alpha(opacity=' + alphaOpacity + ')';break;	default:elm.style[props[prop]] = value;	break;	}};})(),setBorderRadius : function (elm, value) {	qgcl.setStyle(elm, 'borderRadius', value || '0');},setBoxShadow : function (elm, value) {	qgcl.setStyle(elm, 'boxShadow', value || 'none');},
getElementPos : function (e, relativeToViewport) {var x=0, y=0;	var rect = e.getBoundingClientRect();	x = rect.left;	y = rect.top;	if (!relativeToViewport) {	var viewPos = qgcl.getViewPos();	x += viewPos[0];y += viewPos[1];}return [x, y];	},getElementSize : function (e) {return [e.offsetWidth, e.offsetHeight];},getAbsPointerPos : function (e) {	if (!e) { e = window.event; }	var x = 0, y = 0;	if (typeof e.changedTouches !== 'undefined' && e.changedTouches.length) {	x = e.changedTouches[0].clientX;	y = e.changedTouches[0].clientY;} else if (typeof e.clientX === 'number') {x = e.clientX;	y = e.clientY;	}return { x: x, y: y };	},getRelPointerPos : function (e) {if (!e) { e = window.event; }var target = e.target || e.srcElement;	var targetRect = target.getBoundingClientRect();var x = 0, y = 0;	var clientX = 0, clientY = 0;	if (typeof e.changedTouches !== 'undefined' && e.changedTouches.length) {clientX = e.changedTouches[0].clientX;		clientY = e.changedTouches[0].clientY;	} else if (typeof e.clientX === 'number') {clientX = e.clientX;	clientY = e.clientY;	}x = clientX - targetRect.left;	y = clientY - targetRect.top;	return { x: x, y: y };	},getViewPos : function () {	var doc = document.documentElement;	return [(window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0),	(window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0)];},getViewSize : function () {		var doc = document.documentElement;	return [(window.innerWidth || doc.clientWidth),	(window.innerHeight || doc.clientHeight),];},redrawPosition : function () {	if (qgcl.picker && qgcl.picker.owner) {	var thisObj = qgcl.picker.owner;var tp, vp;if (thisObj.fixed) {	tp = qgcl.getElementPos(thisObj.targetElement, true); 	vp = [0, 0]; 	} else {tp = qgcl.getElementPos(thisObj.targetElement); vp = qgcl.getViewPos(); }
var ts = qgcl.getElementSize(thisObj.targetElement); 
var vs = qgcl.getViewSize(); 
var ps = qgcl.getPickerOuterDims(thisObj); 
var a, b, c;
			switch (thisObj.position.toLowerCase()) {
				case 'left': a=1; b=0; c=-1; break;
				case 'right':a=1; b=0; c=1; break;
				case 'top':  a=0; b=1; c=-1; break;
				default:     a=0; b=1; c=1; break;
			}
			var l = (ts[b]+ps[b])/2;
			if (!thisObj.smartPosition) {
				var pp = [tp[a],tp[b]+ts[b]-l+l*c];
			} else {
				var pp = [
					-vp[a]+tp[a]+ps[a] > vs[a] ?
						(-vp[a]+tp[a]+ts[a]/2 > vs[a]/2 && tp[a]+ts[a]-ps[a] >= 0 ? tp[a]+ts[a]-ps[a] : tp[a]) :
						tp[a],
					-vp[b]+tp[b]+ts[b]+ps[b]-l+l*c > vs[b] ?
						(-vp[b]+tp[b]+ts[b]/2 > vs[b]/2 && tp[b]+ts[b]-l-l*c >= 0 ? tp[b]+ts[b]-l-l*c : tp[b]+ts[b]-l+l*c) :
						(tp[b]+ts[b]-l+l*c >= 0 ? tp[b]+ts[b]-l+l*c : tp[b]+ts[b]-l-l*c)
				];
			}

			var x = pp[a];		var y = pp[b];
			var positionValue = thisObj.fixed ? 'fixed' : 'absolute';
			var contractShadow =(pp[0] + ps[0] > tp[0] || pp[0] < tp[0] + ts[0]) &&	(pp[1] + ps[1] < tp[1] + ts[1]);
			qgcl._drawPosition(thisObj, x, y, positionValue, contractShadow);}},

	_drawPosition : function (thisObj, x, y, positionValue, contractShadow) {
		var vShadow = contractShadow ? 0 : thisObj.shadowBlur; 
		qgcl.picker.wrap.style.position = positionValue;
		qgcl.picker.wrap.style.left = x + 'px';
		qgcl.picker.wrap.style.top = y + 'px';
		qgcl.setBoxShadow(
			qgcl.picker.boxS,
			thisObj.shadow ?
				new qgcl.BoxShadow(0, vShadow, thisObj.shadowBlur, 0, thisObj.shadowColor) :
				null);
	},
	getPickerDims : function (thisObj) {
		var displaySlider = !!qgcl.getSliderComponent(thisObj);
		var dims = [
			2 * thisObj.insetWidth + 2 * thisObj.padding + thisObj.width +
				(displaySlider ? 2 * thisObj.insetWidth + qgcl.getPadToSliderPadding(thisObj) + thisObj.sliderSize : 0),
			2 * thisObj.insetWidth + 2 * thisObj.padding + thisObj.height +
				(thisObj.closable ? 2 * thisObj.insetWidth + thisObj.padding + thisObj.buttonHeight : 0)
		];
		return dims;
	},
	getPickerOuterDims : function (thisObj) {
		var dims = qgcl.getPickerDims(thisObj);
		return [
			dims[0] + 2 * thisObj.borderWidth,
			dims[1] + 2 * thisObj.borderWidth
		];
	},
	getPadToSliderPadding : function (thisObj) {
		return Math.max(thisObj.padding, 1.5 * (2 * thisObj.pointerBorderWidth + thisObj.pointerThickness));
	},
	getPadYComponent : function (thisObj) {
		switch (thisObj.mode.charAt(1).toLowerCase()) {
			case 'v': return 'v'; break;
		}
		return 's';
	},
	getSliderComponent : function (thisObj) {
		if (thisObj.mode.length > 2) {
			switch (thisObj.mode.charAt(2).toLowerCase()) {
				case 's': return 's'; break;
				case 'v': return 'v'; break;
			}
		}
		return null;
	},
	onDocumentMouseDown : function (e) {
		if (!e) { e = window.event; }
		var target = e.target || e.srcElement;
		if (target._qgclLinkedInstance) {
			if (target._qgclLinkedInstance.showOnClick) {
				target._qgclLinkedInstance.show();
			}
		} else if (target._qgclControlName) {
			qgcl.onControlPointerStart(e, target, target._qgclControlName, 'mouse');
		} else {
			if (qgcl.picker && qgcl.picker.owner) {
				qgcl.picker.owner.hide();
			}
		}
	},
	onDocumentTouchStart : function (e) {
		if (!e) { e = window.event; }
		var target = e.target || e.srcElement;

		if (target._qgclLinkedInstance) {
			if (target._qgclLinkedInstance.showOnClick) {
				target._qgclLinkedInstance.show();
			}
		} else if (target._qgclControlName) {
			qgcl.onControlPointerStart(e, target, target._qgclControlName, 'touch');
		} else {
			if (qgcl.picker && qgcl.picker.owner) {
				qgcl.picker.owner.hide();
			}
		}
	},
	onWindowResize : function (e) {
		qgcl.redrawPosition();
	},
	onParentScroll : function (e) {
		if (qgcl.picker && qgcl.picker.owner) {
			qgcl.picker.owner.hide();
		}
	},
	_pointerMoveEvent : {
		mouse: 'mousemove',
		touch: 'touchmove'
	},
	_pointerEndEvent : {
		mouse: 'mouseup',
		touch: 'touchend'
	},
	_pointerOrigin : null,
	_capturedTarget : null,
	onControlPointerStart : function (e, target, controlName, pointerType) {
		var thisObj = target._qgclInstance;
		qgcl.preventDefault(e);
		qgcl.captureTarget(target);
		var registerDragEvents = function (doc, offset) {
			qgcl.attachGroupEvent('drag', doc, qgcl._pointerMoveEvent[pointerType],
				qgcl.onDocumentPointerMove(e, target, controlName, pointerType, offset));
			qgcl.attachGroupEvent('drag', doc, qgcl._pointerEndEvent[pointerType],
				qgcl.onDocumentPointerEnd(e, target, controlName, pointerType));
		};
		registerDragEvents(document, [0, 0]);
		if (window.parent && window.frameElement) {
			var rect = window.frameElement.getBoundingClientRect();
			var ofs = [-rect.left, -rect.top];
			registerDragEvents(window.parent.window.document, ofs);
		}
		var abs = qgcl.getAbsPointerPos(e);
		var rel = qgcl.getRelPointerPos(e);
		qgcl._pointerOrigin = {
			x: abs.x - rel.x,
			y: abs.y - rel.y
		};
		switch (controlName) {
		case 'pad':
			switch (qgcl.getSliderComponent(thisObj)) {
			case 's': if (thisObj.hsv[1] === 0) { thisObj.fromHSV(null, 100, null); }; break;
			case 'v': if (thisObj.hsv[2] === 0) { thisObj.fromHSV(null, null, 100); }; break;
			}
			qgcl.setPad(thisObj, e, 0, 0);
			break;
		case 'sld':
			qgcl.setSld(thisObj, e, 0);
			break;
		}

		qgcl.dispatchFineChange(thisObj);
	},
	onDocumentPointerMove : function (e, target, controlName, pointerType, offset) {
		return function (e) {
			var thisObj = target._qgclInstance;
			switch (controlName) {
			case 'pad':
				if (!e) { e = window.event; }
				qgcl.setPad(thisObj, e, offset[0], offset[1]);
				qgcl.dispatchFineChange(thisObj);
				break;

			case 'sld':
				if (!e) { e = window.event; }
				qgcl.setSld(thisObj, e, offset[1]);
				qgcl.dispatchFineChange(thisObj);
				break;
			}
		}
	},
	onDocumentPointerEnd : function (e, target, controlName, pointerType) {
		return function (e) {
			var thisObj = target._qgclInstance;
			qgcl.detachGroupEvents('drag');
			qgcl.releaseTarget();
			qgcl.dispatchChange(thisObj);
		};
	},
	dispatchChange : function (thisObj) {
		if (thisObj.valueElement) {
			if (qgcl.isElementType(thisObj.valueElement, 'input')) {
				qgcl.fireEvent(thisObj.valueElement, 'change');
			}
		}
	},
	dispatchFineChange : function (thisObj) {
		if (thisObj.onFineChange) {
			var callback;
			if (typeof thisObj.onFineChange === 'string') {
				callback = new Function (thisObj.onFineChange);
			} else {
				callback = thisObj.onFineChange;
			}
			callback.call(thisObj);
		}
	},
	setPad : function (thisObj, e, ofsX, ofsY) {
		var pointerAbs = qgcl.getAbsPointerPos(e);
		var x = ofsX + pointerAbs.x - qgcl._pointerOrigin.x - thisObj.padding - thisObj.insetWidth;
		var y = ofsY + pointerAbs.y - qgcl._pointerOrigin.y - thisObj.padding - thisObj.insetWidth;
		var xVal = x * (360 / (thisObj.width - 1));
		var yVal = 100 - (y * (100 / (thisObj.height - 1)));
		switch (qgcl.getPadYComponent(thisObj)) {
		case 's': thisObj.fromHSV(xVal, yVal, null, qgcl.leaveSld); break;
		case 'v': thisObj.fromHSV(xVal, null, yVal, qgcl.leaveSld); break;
		}
	},
	setSld : function (thisObj, e, ofsY) {
		var pointerAbs = qgcl.getAbsPointerPos(e);
		var y = ofsY + pointerAbs.y - qgcl._pointerOrigin.y - thisObj.padding - thisObj.insetWidth;

		var yVal = 100 - (y * (100 / (thisObj.height - 1)));

		switch (qgcl.getSliderComponent(thisObj)) {
		case 's': thisObj.fromHSV(null, yVal, null, qgcl.leavePad); break;
		case 'v': thisObj.fromHSV(null, null, yVal, qgcl.leavePad); break;
		}
	},
	_vmlNS : 'qgcl_vml_',
	_vmlCSS : 'qgcl_vml_css_',
	_vmlReady : false,
	initVML : function () {
		if (!qgcl._vmlReady) {
			var doc = document;
			if (!doc.namespaces[qgcl._vmlNS]) {
				doc.namespaces.add(qgcl._vmlNS, 'urn:schemas-microsoft-com:vml');
			}
			if (!doc.styleSheets[qgcl._vmlCSS]) {
				var tags = ['shape', 'shapetype', 'group', 'background', 'path', 'formulas', 'handles', 'fill', 'stroke', 'shadow', 'textbox', 'textpath', 'imagedata', 'line', 'polyline', 'curve', 'rect', 'roundrect', 'oval', 'arc', 'image'];
				var ss = doc.createStyleSheet();
				ss.owningElement.id = qgcl._vmlCSS;
				for (var i = 0; i < tags.length; i += 1) {
					ss.addRule(qgcl._vmlNS + '\\:' + tags[i], 'behavior:url(#default#VML);');
				}
			}
			qgcl._vmlReady = true;
		}
	},
	createPalette : function () {
		var paletteObj = {
			elm: null,
			draw: null
		};
		if (qgcl.isCanvasSupported) {
			var canvas = document.createElement('canvas');
			var ctx = canvas.getContext('2d');
			var drawFunc = function (width, height, type) {
				canvas.width = width;
				canvas.height = height;
				ctx.clearRect(0, 0, canvas.width, canvas.height);
				var hGrad = ctx.createLinearGradient(0, 0, canvas.width, 0);
				hGrad.addColorStop(0 / 6, '#F00');
				hGrad.addColorStop(1 / 6, '#FF0');
				hGrad.addColorStop(2 / 6, '#0F0');
				hGrad.addColorStop(3 / 6, '#0FF');
				hGrad.addColorStop(4 / 6, '#00F');
				hGrad.addColorStop(5 / 6, '#F0F');
				hGrad.addColorStop(6 / 6, '#F00');
				ctx.fillStyle = hGrad;
				ctx.fillRect(0, 0, canvas.width, canvas.height);
				var vGrad = ctx.createLinearGradient(0, 0, 0, canvas.height);
				switch (type.toLowerCase()) {
				case 's':
					vGrad.addColorStop(0, 'rgba(255,255,255,0)');
					vGrad.addColorStop(1, 'rgba(255,255,255,1)');
					break;
				case 'v':
					vGrad.addColorStop(0, 'rgba(0,0,0,0)');
					vGrad.addColorStop(1, 'rgba(0,0,0,1)');
					break;
				}
				ctx.fillStyle = vGrad;
				ctx.fillRect(0, 0, canvas.width, canvas.height);
			};
			paletteObj.elm = canvas;
			paletteObj.draw = drawFunc;
		} else {
			qgcl.initVML();
			var vmlContainer = document.createElement('div');
			vmlContainer.style.position = 'relative';
			vmlContainer.style.overflow = 'hidden';

			var hGrad = document.createElement(qgcl._vmlNS + ':fill');
			hGrad.type = 'gradient';
			hGrad.method = 'linear';
			hGrad.angle = '90';
			hGrad.colors = '16.67% #F0F, 33.33% #00F, 50% #0FF, 66.67% #0F0, 83.33% #FF0'

			var hRect = document.createElement(qgcl._vmlNS + ':rect');
			hRect.style.position = 'absolute';
			hRect.style.left = -1 + 'px';
			hRect.style.top = -1 + 'px';
			hRect.stroked = false;
			hRect.appendChild(hGrad);
			vmlContainer.appendChild(hRect);

			var vGrad = document.createElement(qgcl._vmlNS + ':fill');
			vGrad.type = 'gradient';
			vGrad.method = 'linear';
			vGrad.angle = '180';
			vGrad.opacity = '0';

			var vRect = document.createElement(qgcl._vmlNS + ':rect');
			vRect.style.position = 'absolute';
			vRect.style.left = -1 + 'px';
			vRect.style.top = -1 + 'px';
			vRect.stroked = false;
			vRect.appendChild(vGrad);
			vmlContainer.appendChild(vRect);

			var drawFunc = function (width, height, type) {
				vmlContainer.style.width = width + 'px';
				vmlContainer.style.height = height + 'px';

				hRect.style.width =
				vRect.style.width =
					(width + 1) + 'px';
				hRect.style.height =
				vRect.style.height =
					(height + 1) + 'px';

				hGrad.color = '#F00';
				hGrad.color2 = '#F00';

				switch (type.toLowerCase()) {
				case 's':
					vGrad.color = vGrad.color2 = '#FFF';
					break;
				case 'v':
					vGrad.color = vGrad.color2 = '#000';
					break;
				}
			};
			
			paletteObj.elm = vmlContainer;
			paletteObj.draw = drawFunc;
		}

		return paletteObj;
	},


	createSliderGradient : function () {

		var sliderObj = {
			elm: null,
			draw: null
		};

		if (qgcl.isCanvasSupported) {
			var canvas = document.createElement('canvas');
			var ctx = canvas.getContext('2d');
			var drawFunc = function (width, height, color1, color2) {
				canvas.width = width;
				canvas.height = height;

				ctx.clearRect(0, 0, canvas.width, canvas.height);

				var grad = ctx.createLinearGradient(0, 0, 0, canvas.height);
				grad.addColorStop(0, color1);
				grad.addColorStop(1, color2);

				ctx.fillStyle = grad;
				ctx.fillRect(0, 0, canvas.width, canvas.height);
			};
			sliderObj.elm = canvas;
			sliderObj.draw = drawFunc;
		} else {
			qgcl.initVML();

			var vmlContainer = document.createElement('div');
			vmlContainer.style.position = 'relative';
			vmlContainer.style.overflow = 'hidden';

			var grad = document.createElement(qgcl._vmlNS + ':fill');
			grad.type = 'gradient';
			grad.method = 'linear';
			grad.angle = '180';

			var rect = document.createElement(qgcl._vmlNS + ':rect');
			rect.style.position = 'absolute';
			rect.style.left = -1 + 'px';
			rect.style.top = -1 + 'px';
			rect.stroked = false;
			rect.appendChild(grad);
			vmlContainer.appendChild(rect);

			var drawFunc = function (width, height, color1, color2) {
				vmlContainer.style.width = width + 'px';
				vmlContainer.style.height = height + 'px';

				rect.style.width = (width + 1) + 'px';
				rect.style.height = (height + 1) + 'px';

				grad.color = color1;
				grad.color2 = color2;
			};
			
			sliderObj.elm = vmlContainer;
			sliderObj.draw = drawFunc;
		}

		return sliderObj;
	},
	leaveValue : 1<<0,
	leaveStyle : 1<<1,
	leavePad : 1<<2,
	leaveSld : 1<<3,
	BoxShadow : (function () {
		var BoxShadow = function (hShadow, vShadow, blur, spread, color, inset) {
			this.hShadow = hShadow;
			this.vShadow = vShadow;
			this.blur = blur;
			this.spread = spread;
			this.color = color;
			this.inset = !!inset;
		};
		BoxShadow.prototype.toString = function () {
			var vals = [
				Math.round(this.hShadow) + 'px',
				Math.round(this.vShadow) + 'px',
				Math.round(this.blur) + 'px',
				Math.round(this.spread) + 'px',
				this.color
			];
			if (this.inset) {
				vals.push('inset');
			}
			return vals.join(' ');
		};
		return BoxShadow;
	})(),


	qgcolor : function (targetElement, options) {
		this.value = null; // initial HEX color. To change it later, use methods fromString(), fromHSV() and fromRGB()
		this.valueElement = targetElement; // element that will be used to display and input the color code
		this.styleElement = targetElement; // element that will preview the picked color using CSS backgroundColor
		this.required = true; // whether the associated text <input> can be left empty
		this.refine = true; // whether to refine the entered color code (e.g. uppercase it and remove whitespace)
		this.hash = false; // whether to prefix the HEX color code with # symbol
		this.uppercase = true; // whether to uppercase the color code
		this.onFineChange = null; // called instantly every time the color changes (value can be either a function or a string with javascript code)
		this.activeClass = 'qgcolor-active'; // class to be set to the target element when a picker window is open on it
		this.minS = 0; // min allowed saturation (0 - 100)
		this.maxS = 100; // max allowed saturation (0 - 100)
		this.minV = 0; // min allowed value (brightness) (0 - 100)
		this.maxV = 100; // max allowed value (brightness) (0 - 100)

		this.hsv = [0, 0, 100]; // read-only  [0-360, 0-100, 0-100]
		this.rgb = [255, 255, 255]; // read-only  [0-255, 0-255, 0-255]

		this.width = 181; // width of color palette (in px)
		this.height = 121; // height of color palette (in px)
		this.showOnClick = true; // whether to display the color picker when user clicks on its target element
		this.mode = 'HSV'; // HSV | HVS | HS | HV - layout of the color picker controls
		this.position = 'bottom'; // left | right | top | bottom - position relative to the target element
		this.smartPosition = true; // automatically change picker position when there is not enough space for it
		this.sliderSize = 12; // px
		this.crossSize = 4; // px
		this.closable = false; // whether to display the Close button
		this.closeText = 'Close';
		this.buttonColor = '#000000'; // CSS color
		this.buttonHeight = 18; // px
		this.padding = 12; // px
		this.backgroundColor = '#FFFFFF'; // CSS color
		this.borderWidth = 1; // px
		this.borderColor = '#BBBBBB'; // CSS color
		this.borderRadius = 1; // px
		this.insetWidth = 1; // px
		this.insetColor = '#BBBBBB'; // CSS color
		this.shadow = true; // whether to display shadow
		this.shadowBlur = 15; // px
		this.shadowColor = 'rgba(0,0,0,0.2)'; // CSS color
		this.pointerColor = '#4C4C4C'; // px
		this.pointerBorderColor = '#FFFFFF'; // px
                this.pointerBorderWidth = 1; // px
                this.pointerThickness = 1; // px
		this.zIndex = 1000;
		this.container = null; // where to append the color picker (BODY element by default)


		for (var opt in options) {if (options.hasOwnProperty(opt)) {this[opt] = options[opt];}}
		this.hide = function () {if (isPickerOwner()) {	detachPicker();	}};
		this.show = function () {		drawPicker();	};
		this.redraw = function () {	if (isPickerOwner()) {	drawPicker();}	};
		this.importColor = function () {
			if (!this.valueElement) {
				this.exportColor();
			} else {
				if (qgcl.isElementType(this.valueElement, 'input')) {
					if (!this.refine) {
						if (!this.fromString(this.valueElement.value, qgcl.leaveValue)) {
							if (this.styleElement) {
								this.styleElement.style.backgroundImage = this.styleElement._qgclOrigStyle.backgroundImage;
								this.styleElement.style.backgroundColor = this.styleElement._qgclOrigStyle.backgroundColor;
								this.styleElement.style.color = this.styleElement._qgclOrigStyle.color;
							}
							this.exportColor(qgcl.leaveValue | qgcl.leaveStyle);
						}
					} else if (!this.required && /^\s*$/.test(this.valueElement.value)) {
						this.valueElement.value = '';
						if (this.styleElement) {
							this.styleElement.style.backgroundImage = this.styleElement._qgclOrigStyle.backgroundImage;
							this.styleElement.style.backgroundColor = this.styleElement._qgclOrigStyle.backgroundColor;
							this.styleElement.style.color = this.styleElement._qgclOrigStyle.color;
						}
						this.exportColor(qgcl.leaveValue | qgcl.leaveStyle);
					} else if (this.fromString(this.valueElement.value)) {
					} else {
						this.exportColor();
					}
				} else {
					this.exportColor();
				}
			}
		};


		this.exportColor = function (flags) {
			if (!(flags & qgcl.leaveValue) && this.valueElement) {
				var value = this.toString();
				if (this.uppercase) { value = value.toUpperCase(); }
				if (this.hash) { value = '#' + value; }
				if (qgcl.isElementType(this.valueElement, 'input')) {
					this.valueElement.value = value;
				} else {
					this.valueElement.innerHTML = value;
				}
			}
			if (!(flags & qgcl.leaveStyle)) {
				if (this.styleElement) {
					this.styleElement.style.backgroundImage = 'none';
					this.styleElement.style.backgroundColor = '#' + this.toString();
					this.styleElement.style.color = this.isLight() ? '#000' : '#FFF';
				}
			}
			if (!(flags & qgcl.leavePad) && isPickerOwner()) {
				redrawPad();
			}
			if (!(flags & qgcl.leaveSld) && isPickerOwner()) {
				redrawSld();
			}
		};


		// h: 0-360
		// s: 0-100
		// v: 0-100
		//
		this.fromHSV = function (h, s, v, flags) { // null = don't change
			if (h !== null) {
				if (isNaN(h)) { return false; }
				h = Math.max(0, Math.min(360, h));
			}
			if (s !== null) {
				if (isNaN(s)) { return false; }
				s = Math.max(0, Math.min(100, this.maxS, s), this.minS);
			}
			if (v !== null) {
				if (isNaN(v)) { return false; }
				v = Math.max(0, Math.min(100, this.maxV, v), this.minV);
			}

			this.rgb = HSV_RGB(
				h===null ? this.hsv[0] : (this.hsv[0]=h),
				s===null ? this.hsv[1] : (this.hsv[1]=s),
				v===null ? this.hsv[2] : (this.hsv[2]=v)
			);

			this.exportColor(flags);
		};


		// r: 0-255
		// g: 0-255
		// b: 0-255
		//
		this.fromRGB = function (r, g, b, flags) { // null = don't change
			if (r !== null) {
				if (isNaN(r)) { return false; }
				r = Math.max(0, Math.min(255, r));
			}
			if (g !== null) {
				if (isNaN(g)) { return false; }
				g = Math.max(0, Math.min(255, g));
			}
			if (b !== null) {
				if (isNaN(b)) { return false; }
				b = Math.max(0, Math.min(255, b));
			}

			var hsv = RGB_HSV(
				r===null ? this.rgb[0] : r,
				g===null ? this.rgb[1] : g,
				b===null ? this.rgb[2] : b
			);
			if (hsv[0] !== null) {
				this.hsv[0] = Math.max(0, Math.min(360, hsv[0]));
			}
			if (hsv[2] !== 0) {
				this.hsv[1] = hsv[1]===null ? null : Math.max(0, this.minS, Math.min(100, this.maxS, hsv[1]));
			}
			this.hsv[2] = hsv[2]===null ? null : Math.max(0, this.minV, Math.min(100, this.maxV, hsv[2]));

			// update RGB according to final HSV, as some values might be trimmed
			var rgb = HSV_RGB(this.hsv[0], this.hsv[1], this.hsv[2]);
			this.rgb[0] = rgb[0];
			this.rgb[1] = rgb[1];
			this.rgb[2] = rgb[2];

			this.exportColor(flags);
		};


		this.fromString = function (str, flags) {
			var m;
			if (m = str.match(/^\W*([0-9A-F]{3}([0-9A-F]{3})?)\W*$/i)) {

				if (m[1].length === 6) {
					// 6-char notation
					this.fromRGB(
						parseInt(m[1].substr(0,2),16),
						parseInt(m[1].substr(2,2),16),
						parseInt(m[1].substr(4,2),16),
						flags
					);
				} else {
					// 3-char notation
					this.fromRGB(
						parseInt(m[1].charAt(0) + m[1].charAt(0),16),
						parseInt(m[1].charAt(1) + m[1].charAt(1),16),
						parseInt(m[1].charAt(2) + m[1].charAt(2),16),
						flags
					);
				}
				return true;

			} else if (m = str.match(/^\W*rgba?\(([^)]*)\)\W*$/i)) {
				var params = m[1].split(',');
				var re = /^\s*(\d*)(\.\d+)?\s*$/;
				var mR, mG, mB;
				if (
					params.length >= 3 &&
					(mR = params[0].match(re)) &&
					(mG = params[1].match(re)) &&
					(mB = params[2].match(re))
				) {
					var r = parseFloat((mR[1] || '0') + (mR[2] || ''));
					var g = parseFloat((mG[1] || '0') + (mG[2] || ''));
					var b = parseFloat((mB[1] || '0') + (mB[2] || ''));
					this.fromRGB(r, g, b, flags);
					return true;
				}
			}
			return false;
		};


		this.toString = function () {
			return (
				(0x100 | Math.round(this.rgb[0])).toString(16).substr(1) +
				(0x100 | Math.round(this.rgb[1])).toString(16).substr(1) +
				(0x100 | Math.round(this.rgb[2])).toString(16).substr(1)
			);
		};


		this.toHEXString = function () {
			return '#' + this.toString().toUpperCase();
		};


		this.toRGBString = function () {
			return ('rgb(' +
				Math.round(this.rgb[0]) + ',' +
				Math.round(this.rgb[1]) + ',' +
				Math.round(this.rgb[2]) + ')'
			);
		};


		this.isLight = function () {
			return (
				0.213 * this.rgb[0] +
				0.715 * this.rgb[1] +
				0.072 * this.rgb[2] >
				255 / 2
			);
		};


		this._processParentElementsInDOM = function () {
			if (this._linkedElementsProcessed) { return; }
			this._linkedElementsProcessed = true;
			var elm = this.targetElement;
			do {
				var currStyle = qgcl.getStyle(elm);
				if (currStyle && currStyle.position.toLowerCase() === 'fixed') {
					this.fixed = true;
				}
				if (elm !== this.targetElement) {
					if (!elm._qgclEventsAttached) {
						qgcl.attachEvent(elm, 'scroll', qgcl.onParentScroll);
						elm._qgclEventsAttached = true;
					}
				}
			} while ((elm = elm.parentNode) && !qgcl.isElementType(elm, 'body'));
		};

		function RGB_HSV (r, g, b) {
			r /= 255;
			g /= 255;
			b /= 255;
			var n = Math.min(Math.min(r,g),b);
			var v = Math.max(Math.max(r,g),b);
			var m = v - n;
			if (m === 0) { return [ null, 0, 100 * v ]; }
			var h = r===n ? 3+(b-g)/m : (g===n ? 5+(r-b)/m : 1+(g-r)/m);
			return [
				60 * (h===6?0:h),
				100 * (m/v),
				100 * v
			];
		}


		function HSV_RGB (h, s, v) {
			var u = 255 * (v / 100);
			if (h === null) {
				return [ u, u, u ];
			}
			h /= 60;
			s /= 100;
			var i = Math.floor(h);
			var f = i%2 ? h-i : 1-(h-i);
			var m = u * (1 - s);
			var n = u * (1 - s * f);
			switch (i) {
				case 6:
				case 0: return [u,n,m];
				case 1: return [n,u,m];
				case 2: return [m,u,n];
				case 3: return [m,n,u];
				case 4: return [n,m,u];
				case 5: return [u,m,n];
			}
		}


		function detachPicker () {
			qgcl.unsetClass(THIS.targetElement, THIS.activeClass);
			qgcl.picker.wrap.parentNode.removeChild(qgcl.picker.wrap);
			delete qgcl.picker.owner;
		}


		function drawPicker () {
			THIS._processParentElementsInDOM();

			if (!qgcl.picker) {
				qgcl.picker = {
					owner: null,
					wrap : document.createElement('div'),
					box : document.createElement('div'),
					boxS : document.createElement('div'), // shadow area
					boxB : document.createElement('div'), // border
					pad : document.createElement('div'),
					padB : document.createElement('div'), // border
					padM : document.createElement('div'), // mouse/touch area
					padPal : qgcl.createPalette(),
					cross : document.createElement('div'),
					crossBY : document.createElement('div'), // border Y
					crossBX : document.createElement('div'), // border X
					crossLY : document.createElement('div'), // line Y
					crossLX : document.createElement('div'), // line X
					sld : document.createElement('div'),
					sldB : document.createElement('div'), // border
					sldM : document.createElement('div'), // mouse/touch area
					sldGrad : qgcl.createSliderGradient(),
					sldPtrS : document.createElement('div'), // slider pointer spacer
					sldPtrIB : document.createElement('div'), // slider pointer inner border
					sldPtrMB : document.createElement('div'), // slider pointer middle border
					sldPtrOB : document.createElement('div'), // slider pointer outer border
					btn : document.createElement('div'),
					btnT : document.createElement('span') // text
				};

				qgcl.picker.pad.appendChild(qgcl.picker.padPal.elm);
				qgcl.picker.padB.appendChild(qgcl.picker.pad);
				qgcl.picker.cross.appendChild(qgcl.picker.crossBY);
				qgcl.picker.cross.appendChild(qgcl.picker.crossBX);
				qgcl.picker.cross.appendChild(qgcl.picker.crossLY);
				qgcl.picker.cross.appendChild(qgcl.picker.crossLX);
				qgcl.picker.padB.appendChild(qgcl.picker.cross);
				qgcl.picker.box.appendChild(qgcl.picker.padB);
				qgcl.picker.box.appendChild(qgcl.picker.padM);

				qgcl.picker.sld.appendChild(qgcl.picker.sldGrad.elm);
				qgcl.picker.sldB.appendChild(qgcl.picker.sld);
				qgcl.picker.sldB.appendChild(qgcl.picker.sldPtrOB);
				qgcl.picker.sldPtrOB.appendChild(qgcl.picker.sldPtrMB);
				qgcl.picker.sldPtrMB.appendChild(qgcl.picker.sldPtrIB);
				qgcl.picker.sldPtrIB.appendChild(qgcl.picker.sldPtrS);
				qgcl.picker.box.appendChild(qgcl.picker.sldB);
				qgcl.picker.box.appendChild(qgcl.picker.sldM);

				qgcl.picker.btn.appendChild(qgcl.picker.btnT);
				qgcl.picker.box.appendChild(qgcl.picker.btn);

				qgcl.picker.boxB.appendChild(qgcl.picker.box);
				qgcl.picker.wrap.appendChild(qgcl.picker.boxS);
				qgcl.picker.wrap.appendChild(qgcl.picker.boxB);
			}

			var p = qgcl.picker;
			var displaySlider = !!qgcl.getSliderComponent(THIS);
			var dims = qgcl.getPickerDims(THIS);
			var crossOuterSize = (2 * THIS.pointerBorderWidth + THIS.pointerThickness + 2 * THIS.crossSize);
			var padToSliderPadding = qgcl.getPadToSliderPadding(THIS);
			var borderRadius = Math.min(
				THIS.borderRadius,
				Math.round(THIS.padding * Math.PI)); 
			var padCursor = 'crosshair';
			p.wrap.style.clear = 'both';
			p.wrap.style.width = (dims[0] + 2 * THIS.borderWidth) + 'px';
			p.wrap.style.height = (dims[1] + 2 * THIS.borderWidth) + 'px';
			p.wrap.style.zIndex = THIS.zIndex;
			p.box.style.width = dims[0] + 'px';
			p.box.style.height = dims[1] + 'px';
			p.boxS.style.position = 'absolute';
			p.boxS.style.left = '0';
			p.boxS.style.top = '0';
			p.boxS.style.width = '100%';
			p.boxS.style.height = '100%';
			qgcl.setBorderRadius(p.boxS, borderRadius + 'px');
			p.boxB.style.position = 'relative';
			p.boxB.style.border = THIS.borderWidth + 'px solid';
			p.boxB.style.borderColor = THIS.borderColor;
			p.boxB.style.background = THIS.backgroundColor;
			qgcl.setBorderRadius(p.boxB, borderRadius + 'px');
			p.padM.style.background =
			p.sldM.style.background =
				'#FFF';
			qgcl.setStyle(p.padM, 'opacity', '0');
			qgcl.setStyle(p.sldM, 'opacity', '0');
			p.pad.style.position = 'relative';
			p.pad.style.width = THIS.width + 'px';
			p.pad.style.height = THIS.height + 'px';
			p.padPal.draw(THIS.width, THIS.height, qgcl.getPadYComponent(THIS));
			p.padB.style.position = 'absolute';
			p.padB.style.left = THIS.padding + 'px';
			p.padB.style.top = THIS.padding + 'px';
			p.padB.style.border = THIS.insetWidth + 'px solid';
			p.padB.style.borderColor = THIS.insetColor;
			p.padM._qgclInstance = THIS;
			p.padM._qgclControlName = 'pad';
			p.padM.style.position = 'absolute';
			p.padM.style.left = '0';
			p.padM.style.top = '0';
			p.padM.style.width = (THIS.padding + 2 * THIS.insetWidth + THIS.width + padToSliderPadding / 2) + 'px';
			p.padM.style.height = dims[1] + 'px';
			p.padM.style.cursor = padCursor;
			p.cross.style.position = 'absolute';
			p.cross.style.left =
			p.cross.style.top =
				'0';
			p.cross.style.width =
			p.cross.style.height =
				crossOuterSize + 'px';
			p.crossBY.style.position =
			p.crossBX.style.position =
				'absolute';
			p.crossBY.style.background =
			p.crossBX.style.background =
				THIS.pointerBorderColor;
			p.crossBY.style.width =
			p.crossBX.style.height =
				(2 * THIS.pointerBorderWidth + THIS.pointerThickness) + 'px';
			p.crossBY.style.height =
			p.crossBX.style.width =
				crossOuterSize + 'px';
			p.crossBY.style.left =
			p.crossBX.style.top =
				(Math.floor(crossOuterSize / 2) - Math.floor(THIS.pointerThickness / 2) - THIS.pointerBorderWidth) + 'px';
			p.crossBY.style.top =
			p.crossBX.style.left =
				'0';
			p.crossLY.style.position =
			p.crossLX.style.position =
				'absolute';
			p.crossLY.style.background =
			p.crossLX.style.background =
				THIS.pointerColor;
			p.crossLY.style.height =
			p.crossLX.style.width =
				(crossOuterSize - 2 * THIS.pointerBorderWidth) + 'px';
			p.crossLY.style.width =
			p.crossLX.style.height =
				THIS.pointerThickness + 'px';
			p.crossLY.style.left =
			p.crossLX.style.top =
				(Math.floor(crossOuterSize / 2) - Math.floor(THIS.pointerThickness / 2)) + 'px';
			p.crossLY.style.top =
			p.crossLX.style.left =
			THIS.pointerBorderWidth + 'px';
			p.sld.style.overflow = 'hidden';
			p.sld.style.width = THIS.sliderSize + 'px';
			p.sld.style.height = THIS.height + 'px';
			p.sldGrad.draw(THIS.sliderSize, THIS.height, '#000', '#000');
			p.sldB.style.display = displaySlider ? 'block' : 'none';
			p.sldB.style.position = 'absolute';
			p.sldB.style.right = THIS.padding + 'px';
			p.sldB.style.top = THIS.padding + 'px';
			p.sldB.style.border = THIS.insetWidth + 'px solid';
			p.sldB.style.borderColor = THIS.insetColor;
			p.sldM._qgclInstance = THIS;
			p.sldM._qgclControlName = 'sld';
			p.sldM.style.display = displaySlider ? 'block' : 'none';
			p.sldM.style.position = 'absolute';
			p.sldM.style.right = '0';
			p.sldM.style.top = '0';
			p.sldM.style.width = (THIS.sliderSize + padToSliderPadding / 2 + THIS.padding + 2 * THIS.insetWidth) + 'px';
			p.sldM.style.height = dims[1] + 'px';
			p.sldM.style.cursor = 'default';
			p.sldPtrIB.style.border =
			p.sldPtrOB.style.border =
			THIS.pointerBorderWidth + 'px solid ' + THIS.pointerBorderColor;
			p.sldPtrOB.style.position = 'absolute';
			p.sldPtrOB.style.left = -(2 * THIS.pointerBorderWidth + THIS.pointerThickness) + 'px';
			p.sldPtrOB.style.top = '0';
			p.sldPtrMB.style.border = THIS.pointerThickness + 'px solid ' + THIS.pointerColor;

			p.sldPtrS.style.width = THIS.sliderSize + 'px';
			p.sldPtrS.style.height = sliderPtrSpace + 'px';

			function setBtnBorder () {
				var insetColors = THIS.insetColor.split(/\s+/);
				var outsetColor = insetColors.length < 2 ? insetColors[0] : insetColors[1] + ' ' + insetColors[0] + ' ' + insetColors[0] + ' ' + insetColors[1];
				p.btn.style.borderColor = outsetColor;
			}
			p.btn.style.display = THIS.closable ? 'block' : 'none';
			p.btn.style.position = 'absolute';
			p.btn.style.left = THIS.padding + 'px';
			p.btn.style.bottom = THIS.padding + 'px';
			p.btn.style.padding = '0 15px';
			p.btn.style.height = THIS.buttonHeight + 'px';
			p.btn.style.border = THIS.insetWidth + 'px solid';
			setBtnBorder();
			p.btn.style.color = THIS.buttonColor;
			p.btn.style.font = '12px sans-serif';
			p.btn.style.textAlign = 'center';
			try {
				p.btn.style.cursor = 'pointer';
			} catch(eOldIE) {
				p.btn.style.cursor = 'hand';
			}
			p.btn.onmousedown = function () {
				THIS.hide();
			};
			p.btnT.style.lineHeight = THIS.buttonHeight + 'px';
			p.btnT.innerHTML = '';
			p.btnT.appendChild(document.createTextNode(THIS.closeText));
			redrawPad();
			redrawSld();
			if (qgcl.picker.owner && qgcl.picker.owner !== THIS) {
				qgcl.unsetClass(qgcl.picker.owner.targetElement, THIS.activeClass);
			}
			qgcl.picker.owner = THIS;
			if (qgcl.isElementType(container, 'body')) {
				qgcl.redrawPosition();
			} else {
				qgcl._drawPosition(THIS, 0, 0, 'relative', false);
			}
			if (p.wrap.parentNode != container) {
				container.appendChild(p.wrap);
			}
			qgcl.setClass(THIS.targetElement, THIS.activeClass);
		}


		function redrawPad () {
			switch (qgcl.getPadYComponent(THIS)) {
			case 's': var yComponent = 1; break;
			case 'v': var yComponent = 2; break;
			}
			var x = Math.round((THIS.hsv[0] / 360) * (THIS.width - 1));
			var y = Math.round((1 - THIS.hsv[yComponent] / 100) * (THIS.height - 1));
			var crossOuterSize = (2 * THIS.pointerBorderWidth + THIS.pointerThickness + 2 * THIS.crossSize);
			var ofs = -Math.floor(crossOuterSize / 2);
			qgcl.picker.cross.style.left = (x + ofs) + 'px';
			qgcl.picker.cross.style.top = (y + ofs) + 'px';
			switch (qgcl.getSliderComponent(THIS)) {
			case 's':
				var rgb1 = HSV_RGB(THIS.hsv[0], 100, THIS.hsv[2]);
				var rgb2 = HSV_RGB(THIS.hsv[0], 0, THIS.hsv[2]);
				var color1 = 'rgb(' +
					Math.round(rgb1[0]) + ',' +
					Math.round(rgb1[1]) + ',' +
					Math.round(rgb1[2]) + ')';
				var color2 = 'rgb(' +
					Math.round(rgb2[0]) + ',' +
					Math.round(rgb2[1]) + ',' +
					Math.round(rgb2[2]) + ')';
				qgcl.picker.sldGrad.draw(THIS.sliderSize, THIS.height, color1, color2);
				break;
			case 'v':
				var rgb = HSV_RGB(THIS.hsv[0], THIS.hsv[1], 100);
				var color1 = 'rgb(' +
					Math.round(rgb[0]) + ',' +
					Math.round(rgb[1]) + ',' +
					Math.round(rgb[2]) + ')';
				var color2 = '#000';
				qgcl.picker.sldGrad.draw(THIS.sliderSize, THIS.height, color1, color2);
				break;
			}
		}
		function redrawSld () {
			var sldComponent = qgcl.getSliderComponent(THIS);
			if (sldComponent) {
				switch (sldComponent) {
				case 's': var yComponent = 1; break;
				case 'v': var yComponent = 2; break;
				}
				var y = Math.round((1 - THIS.hsv[yComponent] / 100) * (THIS.height - 1));
				qgcl.picker.sldPtrOB.style.top = (y - (2 * THIS.pointerBorderWidth + THIS.pointerThickness) - Math.floor(sliderPtrSpace / 2)) + 'px';
			}
		}
		function isPickerOwner () {return qgcl.picker && qgcl.picker.owner === THIS;}
		function blurValue () {	THIS.importColor();}
		if (typeof targetElement === 'string') {
			var id = targetElement;
			var elm = document.getElementById(id);
			if (elm) {
				this.targetElement = elm;
			} else {
				qgcl.warn('Could not find target element with ID \'' + id + '\'');
			}
		} else if (targetElement) {
			this.targetElement = targetElement;
		} else {
			qgcl.warn('Invalid target element: \'' + targetElement + '\'');
		}
		if (this.targetElement._qgclLinkedInstance) {
			qgcl.warn('Cannot link qgcolor twice to the same element. Skipping.');
			return;
		}
		this.targetElement._qgclLinkedInstance = this;
		this.valueElement = qgcl.fetchElement(this.valueElement);
		this.styleElement = qgcl.fetchElement(this.styleElement);
		var THIS = this;
		var container =
			this.container ?
			qgcl.fetchElement(this.container) :
			document.getElementsByTagName('body')[0];
		var sliderPtrSpace = 3;

		if (qgcl.isElementType(this.targetElement, 'button')) {
			if (this.targetElement.onclick) {
				var origCallback = this.targetElement.onclick;
				this.targetElement.onclick = function (evt) {
					origCallback.call(this, evt);
					return false;
				};
			} else {
				this.targetElement.onclick = function () { return false; };
			}
		}
		if (this.valueElement) {
			if (qgcl.isElementType(this.valueElement, 'input')) {
				var updateField = function () {
					THIS.fromString(THIS.valueElement.value, qgcl.leaveValue);
					qgcl.dispatchFineChange(THIS);
				};
				qgcl.attachEvent(this.valueElement, 'keyup', updateField);
				qgcl.attachEvent(this.valueElement, 'input', updateField);
				qgcl.attachEvent(this.valueElement, 'blur', blurValue);
				this.valueElement.setAttribute('autocomplete', 'off');
			}
		}
		if (this.styleElement) {
			this.styleElement._qgclOrigStyle = {
				backgroundImage : this.styleElement.style.backgroundImage,
				backgroundColor : this.styleElement.style.backgroundColor,
				color : this.styleElement.style.color
			};
		}
                
if (this.value) {this.fromString(this.value) || this.exportColor();} else {this.importColor();	}}};
qgcl.qgcolor.qgClass = 'qgcolor';qgcl.qgcolor.installByClassName = function (className) {var inputElms = document.getElementsByTagName('input');var buttonElms = document.getElementsByTagName('button');qgcl.tryInstallOnElements(inputElms, className);qgcl.tryInstallOnElements(buttonElms, className);};qgcl.register();return qgcl.qgcolor;})(); }







           function save_item(nod){            
                     document.getElementById('save_items').value = nod;
                     jQuery(document).ready(function () {
                      jQuery(function ($) {
                        var folldd = '../wp-content/plugins/quotegenerator/includes/save_items.php';
                        $.post(folldd, $("#frmsave").serialize());
                       });
                      });
                     alert("The Item has been saved!");
                     window.location.href = "options-general.php?page=quotegenerator&links=items";
            }
	    function save_select(){            
                     jQuery(document).ready(function () {
                      jQuery(function ($) {
                        var folldd = '../wp-content/plugins/quotegenerator/includes/save_select.php';
                        $.post(folldd, $("#frmsave").serialize());
                       });
                      });
                     alert("The Item has been saved!");
                     window.location.href = "options-general.php?page=quotegenerator&links=items";
            }
	    
            function ret_item(){                   
                     window.location.href = "options-general.php?page=quotegenerator&links=items";
            }
            function del_item(nod){
                     //document.getElementById('delete_item').value = nod;
                     jQuery(document).ready(function () {
                      jQuery(function ($) {
                        var folldd = '../wp-content/plugins/quotegenerator/includes/delete_item.php';
                        $.post(folldd, {deleteitem: nod} );
                       });
                      });
                     alert("The Item has been deleted!");
                     window.location.href = "options-general.php?page=quotegenerator&links=items";
            }
	    
	    function save_item2(nod){            
                     document.getElementById('save_items').value = nod;
		     var ttl = document.getElementById('operand').value;
		     var mxq="";
		     var spts="";
		     var nxq="";
		     for(var x=1; x<=parseInt(ttl); x++){
			if (document.getElementById('qname'+x).value!="") {
			     nxq += document.getElementById('qname'+x).value+"!!!";
			}else{
			     nxq += "Item"+x+"!!!";
			}
			if (document.getElementById('qvalue'+x).value!="") {
			     mxq += document.getElementById('qvalue'+x).value+"!!!";
			}else{
			     mxq += "50!!!";
			}
			if (document.getElementById('svalue'+x).value!="") {
			     spts += document.getElementById('svalue'+x).value+"!!!";
			}else{
			     spts += "1!!!";
			}
		     }
		     document.getElementById('field_1').value += "!!!"+nxq.slice(0, -3);
		     document.getElementById('field_3').value = 0;
		     document.getElementById('field_4').value = mxq.slice(0, -3); //str = str.slice(0, -1);
		     document.getElementById('field_5').value = spts.slice(0, -3);
		     
                     jQuery(document).ready(function () {
                      jQuery(function ($) {
                        var folldd = '../wp-content/plugins/quotegenerator/includes/save_items.php';
                        $.post(folldd, $("#frmsave").serialize());
                       });
                      });
                     alert("The Item has been saved!");
                     window.location.href = "options-general.php?page=quotegenerator&links=items";
            }
	    function scan_item(){
		if (document.getElementById('field_40').value != "") {
		    nod = document.getElementById('field_40').value;
                     jQuery(document).ready(function () {
                      jQuery(function ($) {
                        var folldd = '../wp-content/plugins/quotegenerator/includes/scan_item.php';
                        $.post(folldd, {formula: nod}, function(data, status){
			    //alert("Data: " + data + "\nStatus: " + status);
			    alert("We scan the formula from left to right, processing each operand and operator in order.\n\nPlease type the maximum quantity and step.");
			    document.getElementById('field_40').value = data;
			    document.getElementById('field_40').readOnly = true;
			    var res_num = data.split("@@@@");
			    var tbody = '';
                            var theader = '&nbsp; The basic slider is horizontal and has a single handle that can be moved with the mouse. The customer will drag a handle to select a numeric value.<br><table class="tbl1">';
                                 for(var u=1; u<=parseInt(res_num[1]); u++){
                                       tbody += '<tr><td>Value'+u+' Name: <input type="text" name="qname'+u+'" id="qname'+u+'" value="" style="width:180px;"/></td>';
                                       tbody += '<td>Maximum Value: <input type="text" name="qvalue'+u+'" id="qvalue'+u+'" value="" style="width:80px;"/></td>'
                                       tbody += '<td>Step: <input type="text" name="svalue'+u+'" id="svalue'+u+'" value="" style="width:60px;" /></td></tr>'
                                }
                            var tfooter = '</table><input type="hidden" name="operand" id="operand" value="'+parseInt(res_num[1])+'" />';
                            document.getElementById('formtable').innerHTML = theader + tbody + tfooter;
			    document.getElementById("sbutton3").style.display = "none";
			    document.getElementById("sbutton4").style.display = "table-row";
			    document.getElementById("sqd").style.display = "none";

			} );
                       });
                      });
                     //alert("The Item has been deleted!");
                     //window.location.href = "options-general.php?page=quotegenerator&links=items";
		}else{
		    alert("Please type the formula!");
                     
		}
            }
            function save_itm(nod){
                     document.getElementById('save_items').value = nod;
		     var submit_itemx = '{ save_items : "'+nod+'", idn'+nod+' : "'+document.getElementById('idn'+nod).value+'",';
		     var boxx ='';
		     if(document.getElementById('field_'+nod+'_40')){	
			var forml = document.getElementById('field_'+nod+'_40').value;
			var res_num = forml.split("@@@@");
			boxx = document.getElementById('field_'+nod+'_23').value;
		     }
		    
		     for(var x=1; x<=40; x++){
			
			if (x==1 && boxx == 6) {
                            for(var x1=0; x1<=parseInt(res_num[1]); x1++){
                                var qfl = document.getElementById('field_'+nod+'_1_'+x1).value;
				submit_itemx += 'field_'+nod+'_1_'+x1+' : "'+qfl+'",';
                            }
			
			}else if (x==4 && boxx == 6) {
                            for(var x1=0; x1<parseInt(res_num[1]); x1++){
                                var qfl = document.getElementById('field_'+nod+'_4_'+x1).value;
				submit_itemx += 'field_'+nod+'_4_'+x1+' : "'+qfl+'",';
                            }
			
			}else if (x==5 && boxx == 6) {
                            for(var x1=0; x1<parseInt(res_num[1]); x1++){
                                var qfl = document.getElementById('field_'+nod+'_5_'+x1).value;
				submit_itemx += 'field_'+nod+'_5_'+x1+' : "'+qfl+'",';
                            }    
			
			}else if (x==1 && boxx == 4) {
			    submit_itemx += 'field_'+nod+'_'+x+' : "'+document.getElementById('field_'+nod+'_'+x).value+'",';
			    submit_itemx += 'field_'+nod+'_'+x+'a : "'+document.getElementById('field_'+nod+'_'+x+'a').value+'",';
			    submit_itemx += 'field_'+nod+'_'+x+'b : "'+document.getElementById('field_'+nod+'_'+x+'b').value+'",';
			    
			}else if (x==4 && boxx == 4) {
			    submit_itemx += 'field_'+nod+'_'+x+' : "'+document.getElementById('field_'+nod+'_'+x).value+'",';
			    submit_itemx += 'field_'+nod+'_'+x+'b : "'+document.getElementById('field_'+nod+'_'+x+'b').value+'",';
				
			}else if (x==1 && boxx == 5) {
			    submit_itemx += 'field_'+nod+'_'+x+' : "'+document.getElementById('field_'+nod+'_'+x).value+'",';
			    submit_itemx += 'field_'+nod+'_'+x+'a : "'+document.getElementById('field_'+nod+'_'+x+'a').value+'",';
			    submit_itemx += 'field_'+nod+'_'+x+'b : "'+document.getElementById('field_'+nod+'_'+x+'b').value+'",';
			    submit_itemx += 'field_'+nod+'_'+x+'c : "'+document.getElementById('field_'+nod+'_'+x+'c').value+'",';
			}else if (x==4 && boxx == 5) {
			    submit_itemx += 'field_'+nod+'_'+x+' : "'+document.getElementById('field_'+nod+'_'+x).value+'",';
			    submit_itemx += 'field_'+nod+'_'+x+'b : "'+document.getElementById('field_'+nod+'_'+x+'b').value+'",';
			    submit_itemx += 'field_'+nod+'_'+x+'c : "'+document.getElementById('field_'+nod+'_'+x+'c').value+'",';
			}else if (document.getElementById('field_'+nod+'_'+x)) {
			    submit_itemx += 'field_'+nod+'_'+x+' : "'+document.getElementById('field_'+nod+'_'+x).value+'",';
			    
			}else{
			    submit_itemx += 'field_'+nod+'_'+x+': "",';
			}
		     }
		     
		     submit_itemx = submit_itemx.substring(0, submit_itemx.length - 1);
		     submit_itemx += "}";

		     //alert(submit_itemx);
		     eval("var dataz = "+submit_itemx+";");

                     jQuery(document).ready(function () {
                      jQuery(function ($) {
                        var folldd = '../wp-content/plugins/quotegenerator/includes/save_item.php';
                        //$.post(folldd, $("#frmsave").serialize());
			$.post(folldd, dataz);
                       });
                      });
                     alert("The Item has been saved!");
                     window.location.href = "options-general.php?page=quotegenerator&links=items";
            }
            
            function save_paypal(){
                     alert("This feature is only available to paid accounts.")
            }
	    function set_paypal(){
		if (document.getElementById('ppc11').value!=0) {
		    document.getElementById('ppc1').value = document.getElementById('ppc11').value;
		}
	    		
	    }
	    function save_order(){
		     alert("This feature is only available to paid accounts.");
            }

	    
	    function save_time(nod){
		alert("This feature is only available to paid accounts.")
            }
            
            function showhelp(nod) {
                var evtn = "none";
                if (nod==1) {
                    evtn = "block";
                }else{
                    evtn = "none";
                }
                 document.getElementById("helps").style.display = evtn;

            }
	    function downlds() {
	      var nodes = document.getElementById('downld').value;
	      if(nodes!='0'){
		jQuery(document).ready(function () {
                      jQuery(function ($) {
                        var folldd = '../wp-content/plugins/quotegenerator/includes/download_item.php';
                        $.post(folldd, {ditem: nodes} );
                       });
                      });
                     alert("The data has been saved!");
                     window.location.href = "options-general.php?page=quotegenerator&links=items";
	      }
	    }
            function save_disct(){
		  var nod1=document.getElementById('totam').value;
		  var nod2=document.getElementById('totdics').value;
		  var nod3=document.getElementById('totammin').value;
                     jQuery(document).ready(function () {
                      jQuery(function ($) {
                        var folldd = '../wp-content/plugins/quotegenerator/includes/save_opt.php';
                        $.post(folldd, {d1: nod1, d2: nod2, d3: nod3} );
                       });
                      });
                     alert("The data has been saved!");
                     window.location.href = "options-general.php?page=quotegenerator&links=items";
            }
	    
	    function showim(nod) {
		var nnn="simg"+nod;
                if (nod>0) {
                    document.getElementById(nnn).style.display = "block";
                }
                 

            }
	    function dimg(nod) {
		var nnn="simg"+nod;
                if (nod>0) {
                    document.getElementById(nnn).style.display = "none";
                }
                 

            }
	    
	    function setdisc(nod) {
                     document.getElementById("setdiscount"+nod).style.display = "table-row";
            }
	    
	    
	    
	    
	    
	   function selectid0() {
		
		var formula = document.getElementById('field_23').value;
		var intype = document.getElementById('field_22').value;
		var t_array= new Array('Formula #1 (Amount = Price * Quantity)','Formula #2 (Additional Charge = Price% * Subtotal) or (Discount = -Price% * Subtotal)','Formula #3 (Additional Charge = Price * Total Quantity)','Formula #4 (Amount = Price * Quantity1 * Quantity2)','Formula #5 (Amount = Price * Quantity1 * Quantity2 * Quantity3)','Formula #6 (Amount = Your Formula)');
		var selects = document.getElementById('field_23');

		while(selects.options.length > 0){ selects.remove(0);}
		for (var i = 0; i<t_array.length; i++){
	                if(i==0 || i==3 || i==4|| i==5){    // Formula #1 #4 #5 #6
	                   var opt = document.createElement('option');
                           opt.value = i+1;
                           opt.innerHTML = t_array[i];
                           selects.appendChild(opt);
	                }
                }
		
		
		        document.getElementById("field_2").style.display = "block";
		        document.getElementById("field_3").style.display = "block";
			document.getElementById("field_4").style.display = "block";
			document.getElementById("field_5").style.display = "block";
			document.getElementById("field_6").style.display = "block";
			document.getElementById("field_23").style.display = "block";
			document.getElementById("sqd").style.display = "table-row";
			document.getElementById("f40").style.display = "none";
		        document.getElementsByClassName('tradd')[0].style.display = 'table-row';
		        document.getElementsByClassName('tradd')[1].style.display = 'table-row';
		        document.getElementsByClassName('tradd')[2].style.display = 'table-row';
			document.getElementById("tradd3").style.display  = 'none';
			document.getElementById("sbutton3").style.display = "none";
			document.getElementById("sbutton4").style.display = "none";
			
		
		if (intype == 1 ) { // select box
		    
		    document.getElementById("opt1").style.display = "table-row";
		    document.getElementById("opt2").style.display = "block";
		    document.getElementById("sbutton1").style.display = "none";
		    document.getElementById("sbutton2").style.display = "table-row";
		    
		    document.getElementById("field_4").style.display = "none";
		    document.getElementById("field_5").style.display = "none";
		    document.getElementById("sqd").style.display = "none";
		    

		    
		    
		    while(selects.options.length > 0){  selects.remove(0);}
		    for (var i = 0; i<t_array.length; i++){
	                if(i==1 || i==2){    // Formula #2, #3
	                   var opt = document.createElement('option');
                           opt.value = i+1;
                           opt.innerHTML = t_array[i];
                           selects.appendChild(opt);
	                }
                    }
			    
		    
		    
		}else if (intype == 4){ // input independent
		    
		    while(selects.options.length > 0){  selects.remove(0); }
		    for (var i = 0; i<t_array.length; i++){
	                if(i==0 || i==3 || i==4){    // Formula #1 #4 #5
	                   var opt = document.createElement('option');
                           opt.value = i+1;
                           opt.innerHTML = t_array[i];
                           selects.appendChild(opt);
	                }
                    }
		    
		}else{
		    document.getElementById("opt1").style.display = "none";
		    document.getElementById("opt2").style.display = "none";
		    document.getElementById("opt3").style.display = "none";
		    document.getElementById("opt4").style.display = "none";
		    document.getElementById("opt5").style.display = "none";
		    document.getElementById("sbutton1").style.display = "table-row";
		    document.getElementById("sbutton2").style.display = "none";
		    
		        
		    
		    if (intype == 3){ // Header
			document.getElementById("field_2").style.display = "none";
			document.getElementById("field_3").style.display = "none";
			document.getElementById("field_4").style.display = "none";
			document.getElementById("field_5").style.display = "none";
			document.getElementById("field_6").style.display = "none";
			document.getElementById("field_23").style.display = "none";
			document.getElementById('field_23').value=="1";
			document.getElementById("sqd").style.display = "none";
			
		    }else if (intype == 2){ // Input Box
		     
		      while(selects.options.length > 0){  selects.remove(0); }
		      for (var i = 0; i<t_array.length; i++){
	                if(i==0 || i==3 || i==4|| i==5){    // Formula #1 #4 #5 #6
	                   var opt = document.createElement('option');
                           opt.value = i+1;
                           opt.innerHTML = t_array[i];
                           selects.appendChild(opt);
	                }
                      }
		    
		    }else if (intype == 0){ // Check Box
			document.getElementById("field_4").style.display = "none";
			document.getElementById('field_4').value=="1";
			document.getElementById("field_5").style.display = "none";
			document.getElementById('field_5').value=="1";
			document.getElementById("sqd").style.display = "none";
			
			while(selects.options.length > 0){                
                          selects.remove(0);
                        }
		        for (var i = 0; i<1; i++){
   	                   var opt = document.createElement('option');
                           opt.value = i+1;
                           opt.innerHTML = t_array[i];
                           selects.appendChild(opt);
                        }
			
		    }
                     
		}
		
		 if (formula == 4) {
		     document.getElementById("add_qty2").style.display = "block";
		     document.getElementById("add_qty3").style.display = "none";
		     document.getElementById("add_name1").style.display = "block";
		     document.getElementById("add_name2").style.display = "block";
		     document.getElementById("add_name3").style.display = "none";
		 }else if (formula == 5) {
		     document.getElementById("add_qty2").style.display = "block";
		     document.getElementById("add_qty3").style.display = "block";
		     document.getElementById("add_name1").style.display = "block";
		     document.getElementById("add_name2").style.display = "block";
		     document.getElementById("add_name3").style.display = "block";
		 }else{
                     document.getElementById("add_qty2").style.display = "none";
		     document.getElementById("add_qty3").style.display = "none";
		     document.getElementById("add_name1").style.display = "none";
		     document.getElementById("add_name2").style.display = "none";
		     document.getElementById("add_name3").style.display = "none";
		 }
            } 
	    
	    
	    
	    
 
	    
	    
	    
	    function selectid() {
		
		var formula = document.getElementById('field_23').value;
		var intype = document.getElementById('field_22').value;
		var t_array= new Array('Formula #1 (Amount = Price * Quantity)','Formula #2 (Additional Charge = Price% * Subtotal) or (Discount = -Price% * Subtotal)','Formula #3 (Additional Charge = Price * Total Quantity)','Formula #4 (Amount = Price * Quantity1 * Quantity2)','Formula #5 (Amount = Price * Quantity1 * Quantity2 * Quantity3)','Formula #6 (Amount = Your Formula)');
		var selects = document.getElementById('field_23');
		
		        document.getElementById("field_2").style.display = "block";
		        document.getElementById("field_3").style.display = "block";
			document.getElementById("field_4").style.display = "block";
			document.getElementById("field_5").style.display = "block";
			document.getElementById("field_23").style.display = "block";
			document.getElementById("sqd").style.display = "table-row";
			document.getElementById("f40").style.display = "none";
		        document.getElementsByClassName('tradd')[0].style.display = 'table-row';
		        document.getElementsByClassName('tradd')[1].style.display = 'table-row';
		        document.getElementsByClassName('tradd')[2].style.display = 'table-row';
			document.getElementById("tradd3").style.display  = 'none';
			document.getElementById("sbutton3").style.display = "none";
			document.getElementById("sbutton4").style.display = "none";
			
		
		if (intype == 1 ) {
		    document.getElementById("opt1").style.display = "table-row";
		    document.getElementById("opt2").style.display = "block";
		    document.getElementById("sbutton1").style.display = "none";
		    document.getElementById("sbutton2").style.display = "table-row";
		    document.getElementById("field_4").style.display = "none";
		    document.getElementById("field_5").style.display = "none";
		    document.getElementById("sqd").style.display = "none";

		    
		    	    
		    		    
		}else{
		    document.getElementById("opt1").style.display = "none";
		    document.getElementById("opt2").style.display = "none";
		    document.getElementById("opt3").style.display = "none";
		    document.getElementById("opt4").style.display = "none";
		    document.getElementById("opt5").style.display = "none";
		    document.getElementById("sbutton1").style.display = "table-row";
		    document.getElementById("sbutton2").style.display = "none";
		    
		        
		    
		    if (intype == 3){
			document.getElementById("field_2").style.display = "none";
			document.getElementById("field_3").style.display = "none";
			document.getElementById("field_4").style.display = "none";
			document.getElementById("field_5").style.display = "none";
			document.getElementById("field_23").style.display = "none";
			document.getElementById('field_23').value=="1";
			document.getElementById("sqd").style.display = "none";
		    }else if (intype == 0){
			document.getElementById("field_4").style.display = "none";
			document.getElementById('field_4').value=="1";
			document.getElementById("field_5").style.display = "none";
			document.getElementById('field_5').value=="1";
			document.getElementById("sqd").style.display = "none";
			
		    }
                     
		}
		
		 if (formula == 4) {
		     document.getElementById("add_qty2").style.display = "block";
		     document.getElementById("add_qty3").style.display = "none";
		     document.getElementById("add_name1").style.display = "block";
		     document.getElementById("add_name2").style.display = "block";
		     document.getElementById("add_name3").style.display = "none";
		 }else if (formula == 5) {
		     document.getElementById("add_qty2").style.display = "block";
		     document.getElementById("add_qty3").style.display = "block";
		     document.getElementById("add_name1").style.display = "block";
		     document.getElementById("add_name2").style.display = "block";
		     document.getElementById("add_name3").style.display = "block";
		 }else if (formula == 6) {
		     document.getElementById("add_qty2").style.display = "none";
		     document.getElementById("add_qty3").style.display = "none";
		     document.getElementById("add_name1").style.display = "none";
		     document.getElementById("add_name2").style.display = "none";
		     document.getElementById("add_name3").style.display = "none";
		     document.getElementById("field_3").style.display = "none";
		     document.getElementById("field_4").style.display = "none";
		     document.getElementById("field_5").style.display = "none";
		     
		     document.getElementById("f40").style.display = "block";
		     document.getElementsByClassName('tradd')[0].style.display = 'none';
		     document.getElementsByClassName('tradd')[1].style.display = 'none';
		     document.getElementsByClassName('tradd')[2].style.display = 'none';
		     document.getElementById("tradd3").style.display  = 'table-row';
		     
		     document.getElementById("sbutton3").style.display = "table-row";
		     document.getElementById("sbutton2").style.display = "none";
		     document.getElementById("sbutton1").style.display = "none";
		     
		 }else{
                     document.getElementById("add_qty2").style.display = "none";
		     document.getElementById("add_qty3").style.display = "none";
		     document.getElementById("add_name1").style.display = "none";
		     document.getElementById("add_name2").style.display = "none";
		     document.getElementById("add_name3").style.display = "none";
		 }
            }
	    
	    
	    
	    function addopt(nod) {
		if (document.getElementById('field_22').value=="1") {
		    document.getElementById("opt"+nod).style.display = "block";

		}else{

                     
		}
            }
	    function showdisc(nod) {
                     document.getElementById("dtable"+nod).style.display = "block";
            }
	    function showdes(nod) {
                     document.getElementById("destable"+nod).style.display = "block";
            }
	    
    
	    
	    //--------- Orders -----------------------
	    function cloz(node){
               document.getElementById("shwordord").style.display = "none";
               document.getElementById("tabs3ord").style.display = "none";
               document.getElementById("mainord").style.display = "block";
	       var ssbb="orders";
		if (node==1) {
		    ssbb="orders";
		}else{
		    ssbb="invoices";
		}
	       document.calendar.action = "options-general.php?page=quotegenerator&links="+ssbb+"&rowid=0&sent=no";
               document.calendar.method = "POST";
               document.calendar.submit()
	       
            }

            $("div").click(function() {
              var divHtml = $("#printable").html();
              var editableText = $("<textarea />");
              editableText.val(divHtml);
              $("#printable").replaceWith(editableText);
              editableText.focus();
            });
  
            $(editableText).blur(function() {
              var html = $("#printable").val();// Preserve the value of textarea
              var viewableText = $("<div>");// create a dynamic div
              viewableText.html(html);
              $("#printable").replaceWith(viewableText);
            });

            function printf(){
              alert("This feature is only available to paid accounts.");
  
            }
            function emailf(){
               alert("This feature is only available to paid accounts.");
            }

            function send_order(node){
		 alert("This feature is only available to paid accounts.");
            }
	    function invoice(){
                   alert("This feature is only available to paid accounts.");
            }
	    function save_invoice(){
                   alert("This feature is only available to paid accounts.");
            }
	    function showhelps(nod) {
                     document.getElementById(nod).style.display = "block";
            }
	    function closehelps(nod) {
                     document.getElementById(nod).style.display = "none";
            }
            

	    function save_calname(){
   		     alert("This feature is only available to paid accounts.");
            }
	    
	    
	    
	    
//-------------Calendar --------------------------------------------------------	    

function cadd(){
	alert("This feature is only available to paid accounts.");
}

function cdelet(){
	alert("This feature is only available to paid accounts.");    
}

function csave(){
    alert("This feature is only available to paid accounts.");
}

function caddev(){
   if (document.getElementById("evvt").checked) {
	document.calendar.ev.value = "Closed";
	document.getElementById("timeline").style.display = "none";
   }else{
        document.calendar.ev.value = "";
	document.getElementById("timeline").style.display = "table-row";
   }
   
    
}



function copennew(){
     var nmb3 = document.calendar.monthh.options[document.calendar.monthh.selectedIndex].text; //monthname
     document.calendar.monthname.value = document.calendar.monthh.options[document.calendar.monthh.selectedIndex].text;
     var monn = document.calendar.monthh.value;
     var yyer = document.calendar.yearr.value;
     
     document.calendar.action = "options-general.php?page=quotegenerator&links=calend&monthh="+monn+"&yearr="+yyer+"&monthname="+nmb3;
     document.calendar.method = "POST";
     document.calendar.submit();
}

	    
function cshownew(nod) {
    if (nod==1) {
	document.getElementById("cal_contr").style.display = "block";
	document.getElementById("editev").style.display = "none";
	document.getElementById("langsettings").style.display = "none";
	document.getElementById("calend_settings").style.display = "none";
    }else if (nod==2) {
	document.getElementById("editev").style.display = "block";
	document.getElementById("cal_contr").style.display = "none";
	document.getElementById("langsettings").style.display = "none";
	document.getElementById("calend_settings").style.display = "none";
    }else if (nod=='calend_settings') {
	document.getElementById("editev").style.display = "none";
	document.getElementById("cal_contr").style.display = "none";
	document.getElementById("langsettings").style.display = "none";
	document.getElementById("calend_settings").style.display = "block";
    }else if (nod=='langsettings') {
	document.getElementById("editev").style.display = "none";
	document.getElementById("cal_contr").style.display = "none";
	document.getElementById("langsettings").style.display = "block";
	document.getElementById("calend_settings").style.display = "none";
    }
     
}










function AssignDateList(TheData) {
   var mySplitRt = TheData.split("\n");
   x1=0;


  for(i = 0; i < mySplitRt.length; i++){
	   mySplitXt = mySplitRt[i].split(",");
	   if (mySplitXt.length == 5){
		   Cyy[x1] = mySplitXt[0];
		   Cmm[x1] = mySplitXt[1];
		   Cdd[x1] = mySplitXt[2];
		   if(mySplitXt[3] ==''){Ctt[x1]=''}else{Ctt[x1]= mySplitXt[3];}
		   Caa[x1] = mySplitXt[4];
		   x1++;}
   }

}

        
function getObj(objID){
    if (document.getElementById) {return document.getElementById(objID);}
    else if (document.all) {return document.all[objID];}
    else if (document.layers) {return document.layers[objID];}
    return true;
}

function checkClick(e) {
	e?evt=e:evt=event;
	CSE=evt.target?evt.target:evt.srcElement;
	if (CSE.tagName!='SPAN')	
	if (getObj('fc'))
		if (!isChild(CSE,getObj('fc')))
			getObj('fc').style.display='none';
}

function isChild(s,d) {
	while(s) {
		if (s==d) 
			return true;
		s=s.parentNode;
	}
	return false;
}

function Left(obj){
	var curleft = 0;
	if (obj.offsetParent)	{
		while (obj.offsetParent){
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function Top(obj){
	var curtop = 0;
	if (obj.offsetParent)	{
		while (obj.offsetParent){
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}



function lcs(ielem) {
	updobj=ielem;
	getObj('fc').style.left=Left(ielem)+'px';
	getObj('fc').style.top=Top(ielem)+ielem.offsetHeight+'px';
	getObj('fc').style.display='';
	
	// First check date is valid
	curdt=ielem.value;
	curdtarr=curdt.split('-');
	isdt=true;
	for(var k=0;k<curdtarr.length;k++) {
		if (isNaN(curdtarr[k]))
			isdt=false;
	}
	if (isdt&(curdtarr.length==3)) {
		ccm=curdtarr[1]-1;
		ccy=curdtarr[2];
		
		selectedd=parseInt ( curdtarr[0], 10 );
		selectedm=parseInt ( curdtarr[1]-1, 10 );
		selectedy=parseInt ( curdtarr[2], 10 );

		prepcalendar(curdtarr[0],curdtarr[1]-1,curdtarr[2]);
	}
}

function evtTgt(e){
	var el;
	if(e.target)el=e.target;
	else if(e.srcElement)el=e.srcElement;
	if(el.nodeType==3)el=el.parentNode; // defeat Safari bug
	return el;
}
function EvtObj(e){if(!e)e=window.event;return e;}
function cs_over(e) {
	evtTgt(EvtObj(e)).style.background='#FFFFFF';
}

function cs_out(e) {
	evtTgt(EvtObj(e)).style.background='#efefef';
}
function cs_click(e) {
	updobj.value=calvalarr[evtTgt(EvtObj(e)).id.substring(1,evtTgt(EvtObj(e)).id.length)];
	getObj('fc').style.display='block';
}



function f_cps(obj) {
	obj.style.background='#efefef';
	obj.style.font='10px Arial';
//	obj.style.color='#333333';
	obj.style.textAlign='left';
	obj.style.textDecoration='none';
	obj.style.border='1px solid #999999';
	obj.style.cursor='pointer';
}


function prepcalendar(hd,cm,cy,fll) {
	now=new Date();
	sd=now.getDate();
	td=new Date();
	td.setDate(1);
	td.setFullYear(cy);
	td.setMonth(cm);
	cd=td.getDay();
	var col='#000000';
	var pos=0;
        var s='';
        var x1 = 0;

        AssignDateList(DateList);
	var chekday='';
	getObj('mns').innerHTML=mn[cm]+'&nbsp;'+cy+'&nbsp;';
	marr=((cy%4)==0)?mnl:mnn;
	
	for(var d=1;d<=42;d++) {
		f_cps(getObj('v'+parseInt(d)));
		if ((d >= (cd -(-1)))&&(d<=cd-(-marr[cm]))) {
			dip=((d-cd < sd)&&(cm==sccm)&&(cy==sccy));
			htd=((hd!='')&&(d-cd==hd));
			getObj('v'+parseInt(d)).onclick=cs_click;
						
			col='#003300';
			
			// if today
			if (sccm == cm && sccd == (d-cd) && sccy == cy){
				col='#009900';
				getObj('v'+parseInt(d)).style.background='#CCCCCC';
			}
		
                        s='';
			
			for(pos=0;pos<Cyy.length; pos++){
			     if((Cdd[pos]==(d-cd) && Cmm[pos]==(cm+1) && Cyy[pos]==cy)){
				s+='<div style="background:#ff991d;margin:1px;padding:1px;">'+Ctt[pos]+' '+Caa[pos]+'</div>';

                                chekday = Caa[pos].toLowerCase().trim();
				
                                if (chekday == 'fully booked' || chekday == 'closed' || chekday == "not available") {
                                    col = '#f00f00';
                                    getObj('v'+d).innerHTML='&nbsp;';
			            getObj('v'+parseInt(d)).onmouseover=null;
			            getObj('v'+parseInt(d)).onmouseout=null;
			            getObj('v'+parseInt(d)).onclick=null;
			            getObj('v'+parseInt(d)).style.cursor='default';
                                    
                                }
				
				
				
			     }
			}
			if ( sccd > (d-cd) && sccm >= cm && sccy >= cy) {
                           getObj('v'+parseInt(d)).style.background='#bbbbbb';
                        }else{
                           getObj('v'+parseInt(d)).style.background='#efefef';
                        }
                        
			getObj('v'+parseInt(d)).style.color=col;
			getObj('v'+parseInt(d)).style.fontSize='10px';
                        getObj('v'+parseInt(d)).innerHTML = '<div style="font-size: 20px;">'+(d-cd)+'</div>'+s;
			col='#000000';
			calvalarr[d]=addnull(d-cd,cm-(-1),cy);
		     
		     }else {
			
			getObj('v'+d).innerHTML='&nbsp;';
			getObj('v'+parseInt(d)).onmouseover=null;
			getObj('v'+parseInt(d)).onmouseout=null;
			getObj('v'+parseInt(d)).onclick=null;
			getObj('v'+parseInt(d)).style.cursor='default';
		     }
	}
}


function upmonth(s){
	marr=((ccy%4)==0)?mnl:mnn;
	
	ccm+=s;
	if (ccm>=12)
	{
		ccm-=12;
		ccy++;
	}
	else if(ccm<0)
	{
		ccm+=12;
		ccy--;
	}
	ccm = ccm+1;
	if (ccm<10)ccm='0'+ccm;
	//alert(ccm+" "+ccy);
	
	window.location.href = "options-general.php?page=quotegenerator&links=calend&monthh="+ccm+"&yearr="+ccy+"&monthname="+mn[ccm-1];
}

function today() {
	updobj.value=addnull(now.getDate(),now.getMonth()+1,now.getFullYear());
	getObj('fc').style.display='none';
	prepcalendar('',NMONTHM,NYEARS);
}

function addnull(d,m,y){
	var d0='',m0='';
	if (d<10)d0='0';
	if (m<10)m0='0';
	
	return ''+d0+d+'-'+m0+m+'-'+y;
}















