


var url = window.location.href;
var testMode = (url.indexOf('http') == -1);
var imageRoot = '/new_includes/';
if (testMode)
	imageRoot = '';

var instanceObjects = {};
var InstanceContainer =
        {
            Init : function()
            {
	            this.hasBeenInit = true;
            },
            GetInstance : function(id)
            {
	            return instanceObjects[id];
            },
            RegisterInstance : function(selector)
            {
	            if (!this.hasBeenInit)
	            {
		            this.Init();
	            }
	            instanceObjects[selector.id] = selector;
            },
            FireEvent : function(id, event)
            {
	            if (arguments.length > 2)
		            this.GetInstance(id)[event](arguments[2]);
	            else
		            this.GetInstance(id)[event]();
            },
            FireEventAsync : function(id, event, delay)
            {
	            var args = '';
	            if (arguments.length > 3)
	            {
		            args = ", '" + arguments[3] + "'";
	            }
	            setTimeout("try{InstanceContainer.FireEvent('" + id + "', '"
	                    + event + "'" + args + ");}catch(e){}", delay);
            }
        };

function getIEVersionNumber()
{
	var ua = navigator.userAgent;
	var MSIEOffset = ua.indexOf("MSIE ");

	if (MSIEOffset == -1)
	{
		return 0;
	}
	else
	{
		return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";",
		        MSIEOffset)));
	}
}

function gup(name)
{
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(window.location.href);
	if (results == null)
		return "";
	else
		return results[1];
}

function FormatCurrency(AmountNumber, withDollarSign)
{
	var amount = Math.round(AmountNumber * 100) / 100;
	amount = amount.toFixed(2);

	var delimiter = ","; // replace comma if desired
	var a = amount.split('.', 2);
	var d = a[1];
	var i = parseInt(a[0]);
	if (isNaN(i))
	{
		return '';
	}
	var minus = '';
	if (i < 0)
	{
		minus = '-';
	}
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while (n.length > 3)
	{
		var nn = n.substr(n.length - 3);
		a.unshift(nn);
		n = n.substr(0, n.length - 3);
	}
	if (n.length > 0)
	{
		a.unshift(n);
	}
	n = a.join(delimiter);
	if (d.length < 1)
	{
		amount = n;
	}
	else
	{
		amount = n + '.' + d;
	}
	amount = minus + amount;
	return ((withDollarSign) ? "$" : "") + amount;
}

function bindJSON(elementToBind, dataIslandAttrName, jsonObject) 
{
	var elements = elementToBind.getElementsByTagName("*");
	for (var i=0; i < elements.length; i++)
	{
		var element = elements[i];
		var attributeNames = new Array();
		if ( dataIslandAttrName instanceof Array )
		{
		    for (var itr=0; itr<dataIslandAttrName.length; itr++)
		    {
		        attributeNames.push(dataIslandAttrName[itr]);
		    }
		}
		else
		{
		    attributeNames.push(dataIslandAttrName);
		}
		
	    for (var attribNameItr=0; attribNameItr<attributeNames.length; attribNameItr++)
	    {
			try
			{
				var val = element.getAttribute(attributeNames[attribNameItr]);
				if (val!=null && val != 'undefined')
				{
					var propertyToSet = 'innerHTML';
					var splitAttr = val.split(':');
					var objToSet = element;
					for (var j=1; j<splitAttr.length; j++)
					{
						propertyToSet = splitAttr[j-1];
						val = splitAttr[j];
						
						if (j!=(splitAttr.length-1)) {
							objToSet = objToSet[propertyToSet];}
					}
					
					if (val.split('(').length>1) {
						objToSet[propertyToSet] = jsonObject[val.split('(')[0]]();}
					else {
						objToSet[propertyToSet] = jsonObject[val];}
					bindJSON(element, attributeNames[attribNameItr], jsonObject);
				}
				
			}
			catch (e)
			{
			}
	    }
	}
}


function AreImagesComplete(element)
{
	if (element.nodeName.toLowerCase()=='img')
	{
		if (!element.complete)
		{
			return false;
		}
	}
	else
	{
		var children = element.childNodes;
		for (var j=0; j<children.length; j++)
		{
			if (!AreImagesComplete(children[j]))
			{
				return false;
			}
		}
	}

	return true;
}

/* new_includes/javascript/detail/prodSelector...js */
String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/g, "");
}
String.prototype.ltrim = function()
{
	return this.replace(/^\s+/, "");
}
String.prototype.rtrim = function()
{
	return this.replace(/\s+$/, "");
}
function Left(str, n)
{
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
		return String(str).substring(0, n);
}
function Right(str, n)
{
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
	{
		var iLen = String(str).length;
		return String(str).substring(iLen, iLen - n);
	}
}
function basicAcsSort(thisObject, thatObject)
{
	if (thisObject > thatObject)
	{
		return 1;
	}
	else if (thisObject < thatObject)
	{
		return -1;
	}
	return 0;
}
function basicDescSort(thisObject, thatObject)
{
	if (thisObject > thatObject)
	{
		return -1;
	}
	else if (thisObject < thatObject)
	{
		return 1;
	}
	return 0;
}

var TimerQueue =
        {
            queue :new Array(),
            messages :new Array(),
            enabled :true,
            addTimer : function(timerID)
            {
	            if (this.enabled)
		            this.queue.push( {
		                time :new Date(),
		                id :timerID
		            })
            },
            dequeueTimer : function()
            {
	            if (!this.enabled)
		            return '';
	            var now = new Date();
	            var timerObj = this.queue.pop();
	            this.messages.push(timerObj.id + ' took '
	                    + (now.getTime() - timerObj.time.getTime()));
            },

            getAllMessage : function(deliminator)
            {
	            if (!this.enabled)
		            return '';
	            var queueLength = this.queue.length;
	            for ( var i = 0; i < queueLength; i++)
	            {
		            this.dequeueTimer();
	            }

	            var returnStr = '';
	            for ( var i = 0; i < this.messages.length; i++)
	            {
		            returnStr += this.messages[i];
	            }
	            this.queue = new Array();
	            this.messages = new Array();
	            return returnStr;
            }
        };

function PostForm(form, callback)
{
	try
	{
		var inputs = form.getElementsByTagName('input');
		var parameters = {};
		for ( var i = 0; i < inputs.length; i++)
		{
			var input = inputs[i];
			var type = input.getAttribute('type');
			if (!type)
				type = input.type;
			if (type != 'submit' && type != 'button')
			{
				var name = input.getAttribute('name');
				var value = input.getAttribute('value');
				if (!name)
					name = input.name;
				if (!value)
					value = input.value;
				parameters[name] = value;
			}
		}
		var selects = form.getElementsByTagName('select');
		for ( var i = 0; i < selects.length; i++)
		{
			var selectElement = selects[i];
			for ( var i = 0; i < selectElement.options.length; i++)
			{
				var option = selectElement.options[i];
				if (option.selected)
				{
					if (!parameters[selectElement.name])
						parameters[selectElement.name] = [];
					parameters[selectElement.name].push(option.value);
				}
			}
		}

		var action = form.getAttribute('action');
		if (!action)
			action = form.action;
		var request = new Ajax.Request(action, {
		    method :'post',
		    parameters :parameters,
		    onSuccess : function(transport)
		    {
			    var response = transport.responseText;
			    callback(response);
		    }.bind(this),
		    onFailure : function(transport)
		    {
			    var response = transport.statusText;
			    callback(response);
		    }.bind(this)
		});
	}
	catch (e)
	{
	}

	return false;
}

function GetElement(elementId)
{
	if (elementId.id)
	{
		return elementId;
	}
	else
		return document.getElementById(elementId);
}

var ProtoLite =
        {

            Browser : {
                IE :!!(window.attachEvent && !window.opera),
                Opera :!!window.opera,
                WebKit :navigator.userAgent.indexOf('AppleWebKit/') > -1,
                Gecko :navigator.userAgent.indexOf('Gecko') > -1
                        && navigator.userAgent.indexOf('KHTML') == -1,
                MobileSafari :!!navigator.userAgent
                        .match(/Apple.*Mobile.*Safari/)
            },

            Object : {
                Extend : function(destination, source)
                {
	                for ( var property in source)
		                destination[property] = source[property];
	                return destination;
                },
                CopyProperties : function(destination, source)
                {
	                for ( var property in source)
	                {
		                if (typeof source[property] != "function")
		                {
			                destination[property] = source[property];
		                }
	                }
	                return destination;
                },
                CopyFunctions : function(destination, source)
                {
	                for ( var property in source)
	                {
		                if (typeof source[property] == "function")
		                {
			                destination[property] = source[property];
		                }
	                }
	                return destination;
                },

                Clone : function(object)
                {
	                return this.Extend( {}, object);
                }
            },

            String : {
                capitalize : function(str)
                {
	                return str.charAt(0).toUpperCase()
	                        + str.substring(1).toLowerCase();
                },

                camelize : function(str)
                {
	                var parts = str.split('-'), len = parts.length;
	                if (len == 1)
		                return parts[0];

	                var camelized =
	                        str.charAt(0) == '-' ? parts[0].charAt(0)
	                                .toUpperCase()
	                                + parts[0].substring(1) : parts[0];

	                for ( var i = 1; i < len; i++)
		                camelized +=
		                        parts[i].charAt(0).toUpperCase()
		                                + parts[i].substring(1);

	                return camelized;
                }
            },

            Element : {
                getStyle : function(elementId, style)
                {
	                var element = GetElement(elementId);
	                style =
	                        style == 'float' ? 'cssFloat' : ProtoLite.String
	                                .camelize(style);
	                var value = element.style[style];

	                if (ProtoLite.Browser.IE)
	                {
		                if (!value && element.currentStyle)
			                value = element.currentStyle[style];

		                if (style == 'opacity')
		                {
			                if (value =
			                        (this.getStyle(elementId, 'filter') || '')
			                                .match(/alpha\(opacity=(.*)\)/))
				                if (value[1])
					                return parseFloat(value[1]) / 100;
			                return 1.0;
		                }

		                if (value == 'auto')
		                {
			                if ((style == 'width' || style == 'height')
			                        && (this.getStyle(elementId, 'display') != 'none'))
				                return element['offset' + this
				                        .capitalize(style)] + 'px';
			                return null;
		                }
		                return value;
	                }
	                else
	                {
		                if (!value)
		                {
			                var css =
			                        document.defaultView.getComputedStyle(
			                                element, null);
			                value = css ? css[style] : null;
		                }
	                }

	                if (style == 'opacity')
		                return value ? parseFloat(value) : 1.0;
	                return value == 'auto' ? null : value;
                },

                getOpacity : function(elementId)
                {
	                var element = GetElement(elementId);
	                return this.getStyle(element, 'opacity');
                },

                setOpacity : function(elementId, value)
                {
	                var element = GetElement(elementId);

	                if (ProtoLite.Browser.IE)
	                {
		                function stripAlpha(filter)
		                {
			                return filter.replace(/alpha\([^\)]*\)/gi, '');
		                }
		                var currentStyle = element.currentStyle;
		                if ((currentStyle && !currentStyle.hasLayout)
		                        || (!currentStyle && element.style.zoom == 'normal'))
			                element.style.zoom = 1;

		                var filter = this.getStyle(elementId, 'filter'), style =
		                        element.style;
		                if (value == 1 || value === '')
		                {
			                (filter = stripAlpha(filter)) ? style.filter =
			                        filter : style.removeAttribute('filter');
			                return element;
		                }
		                else if (value < 0.00001)
			                value = 0;
		                style.filter =
		                        stripAlpha(filter) + 'alpha(opacity='
		                                + (value * 100) + ')';
		                return element;
	                }
	                else
	                {
		                element.style.opacity =
		                        (value == 1 || value === '') ? ''
		                                : (value < 0.00001) ? 0 : value;
	                }
	                return element;
                }
            },

            Array : {
	            IndexOf : function(arr, item)
	            {
		            var i = 0;
		            var length = arr.length;
		            if (i < 0)
			            i = length + i;
		            for (; i < length; i++)
			            if (arr[i] === item)
				            return i;
		            return -1;
	            }
            }
        };
