
if (document.getElementsByClassName) {
	var getElementsByClassName = function (className, tag, elm) {
		elm = elm || document;
		var elements = elm.getElementsByClassName(className),
			nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
			returnElements = [],
			current;
		for(var i=0, il=elements.length; i<il; i+=1){
			current = elements[i];
			if(!nodeName || nodeName.test(current.nodeName)) {
				returnElements.push(current);
			}
		}
		return returnElements;
	};
}
else if (document.evaluate) {
	var getElementsByClassName = function (className, tag, elm) {
		tag = tag || "*";
		elm = elm || document;
		var classes = className.split(" "),
			classesToCheck = "",
			xhtmlNamespace = "http://www.w3.org/1999/xhtml",
			namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
			returnElements = [],
			elements,
			node;
		for(var j=0, jl=classes.length; j<jl; j+=1){
			classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
		}
		try	{
			elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
		}
		catch (e) {
			elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
		}
		while ((node = elements.iterateNext())) {
			returnElements.push(node);
		}
		return returnElements;
	};
}
else {
	var getElementsByClassName = function (className, tag, elm) {
		tag = tag || "*";
		elm = elm || document;
		var classes = className.split(" "),
			classesToCheck = [],
			elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
			current,
			returnElements = [],
			match;
		for(var k=0, kl=classes.length; k<kl; k+=1){
			classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
		}
		for(var l=0, ll=elements.length; l<ll; l+=1){
			current = elements[l];
			match = false;
			for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
				match = classesToCheck[m].test(current.className);
				if (!match) {
					break;
				}
			}
			if (match) {
				returnElements.push(current);
			}
		}
		return returnElements;
	};
}

function $c(className, tag, elm)
{
	return getElementsByClassName(className, tag, elm);
}

function $()
{
	var
		ret = [],
		len = arguments.length;
	for (var i = 0; (i < len); i++) {
		var element = arguments[i];
		if (typeof element === "string") {
			element = document.getElementById(element);
		}
		if (arguments.length === 1) {
			return element;
		}
		ret.push(element);
	}
	return ret;
}

function getElementsByClass(searchClass,node,tag)
{
	node = (node || document);
	tag = (tag || "*");
	var
		elements = node.getElementsByTagName(tag),
		len = elements.length,
		pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)"),
		classElements = [];
	for (i = 0, j = 0; (i < len); i++) {
		if (pattern.test(elements[i].className)) {
			classElements[j++] = elements[i];
		}
	}
	return classElements;
}

if (!document.getElementsByTagAndClassName) {
	document.getElementsByTagAndClassName = function(tagName, className) {
		tagName = (tagName || "*");
		var children = document.getElementsByTagName(tagName) || document.all;
		if (className === null) {
			return children;
		}
		var
			ret = [],
			len = children.length;
		for (var i = 0; (i < len); ++i) {
			var
				child = children[i],
				classNames = child.className.split(" "),
				zen = classNames.length;
			for (var j = 0; (j < zen); ++j) {
				if (classNames[j] === className) {
					ret.push(child);
					break;
				}
			}
		}

		return ret;
	};
}

function extend(subClass, superClass)
{
	var func = function() {};
	func.prototype = superClass.prototype;
	subClass.prototype = new func();
	subClass.prototype.constructor = subClass;
}

String.prototype.trim = function() {
	return this.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
};

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

Array.prototype.unique = function() {
	var
		distinct = [],
		maximum = (this.length - 1);
	for (var i = 0, k = 0; (i <= maximum); i++) {
		var len = distinct.length
		// j should increment all the way up to l
		for (var j = 0; (this[i] !== distinct[j]) && (j < len); j++ );
		// if it hasn't, this one's a duplicate
		if (j === len) {
			distinct[k++] = this[i];
		}
	}
	return distinct;
};

Array.prototype.last = function() {
	return this[this.length - 1];
};

function in_array(needle, haystack, strict)
{
	for (var key in haystack) {
		if ((!strict && haystack[key] == needle) || (!!strict && haystack[key] === needle)) {
			return true;
		}
	}
	return false;
}

function array_key_exists(needle, haystack, strict)
{
	for (var key in haystack) {
		if ((!strict && key == needle) || (!!strict && key === needle)) {
			return true;
		}
	}
	return false;
}

function hideSelectOptions( className, exceptions)
{
	var
		selects = document.getElementsByClassName(className),
		exceptions = exceptions || [],
		len = selects.length;
	for (var i = 0; (i < len); ++i) {
		var
			options = selects[i].getElementsByTagName("option"),
			zen = options.length;
		for (var j = 0; (j < zen); ++ j) {
			with (options[j]) {
				if (!value) { // ignore header options
					continue;
				}
				className = "hidden";
				if (in_array( getAttribute("table_name"), exceptions, true )) {
					className = null;
				}
			}
		}
	}
}

if (!window.addClassName) {
	addClassName = function(el, cls) {
		if (hasClassName(el, cls )) {
			return;
		}
		if (el.className === "") {
			el.className = cls;
		} else {
			el.className += (" " + cls);
		}
	};
}

if (!window.removeClassName) {
	removeClassName = function(el, cls) {
		if (!hasClassName(el, cls)) {
			return;
		}
		var
			classNames = el.className.split(" "),
			len = classNames.length;
		for (var i = 0; (i < len); ++i) {
			if (classNames[i] === "" || classNames[i] === cls || classNames[i].match( new RegExp("\\b" + cls + "\\b") )) {
				delete classNames[i];
			}
		}
		el.className = classNames.join(" ").trim();
	};
}

if (!window.hasClassName) {
	hasClassName = function(el, cls) {
		return el.className.match( new RegExp("\\b" + cls + "\\b") );
	};
}

if (!window.toggleClassName) {
	toggleClassName = function(el, cls) {
		if (hasClassName(el, cls)) {
			removeClassName(el, cls);
		} else {
			addClassName(el, cls);
		}
	};
}

if (!window.addEvent) {
	function addEvent(target, event, handler)
	{
		if (typeof event === "string") {
			event = [event];
		}
		var length = event.length;
		if (target.attachEvent) {
			for (var i = 0; i < length; i++) {
				target[ "e" + event[i] + handler ] = handler;
				var _event = event[i];
				target[ event[i] + handler ] = function(_e, i) {
					if (typeof target[ "e" + _event + handler ] === "function") {
						target[ "e" + _event + handler ](_e, i)
					}
				};
				target.attachEvent("on" + event[i], target[ event[i] + handler ]);
			}
		} else {
			for (var i = 0; i < length; i++) {
				target.addEventListener(event[i], handler, false);
			}
		}
	}
}
if (!window.removeEvent) {
	function removeEvent(target, event, handler)
	{
		if (typeof event === "string") {
			event = [event];
		}
		var length = event.length;
		if (target.attachEvent) {
			for (var i = 0; i < length; i++) {
				target[ "e" + event[i] + handler ] = null;
				target[ event[i] + handler ] = null;
				target.detachEvent("on" + event[i], target[ event[i] + handler ]);
			}
		} else {
		for (var i = 0; i < length; i++) {
			target.removeEventListener(event[i], handler, false);
		}
		}
	}
}

function XBrowserAddEvent(target, event, handler)
{
	if (target.addEventListener) {
		target.addEventListener(event, handler, false);
	} else if (target.attachEvent) {
		target.attachEvent("on" + event, handler);
	} else {
		target["on" + event] = handler;
	}
}

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != "function") {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		};
	}
}

function cancelEvent(e)
{
	//e.cancelBubble is supported by IE - this will kill the bubbling process.
	e.cancelBubble = true;
	e.returnValue = false;

	//e.stopPropagation works only in Firefox.
	if (e.stopPropagation) {
		e.stopPropagation();
		e.preventDefault();
	}
}

function setOpacity( el, op)
{
	if (op === 100) { // IE support
		with (el.style) {
			opacity = "";
			MozOpacity = "";
			filter = "";
		}
	} else {
		with (el.style) {
			opacity = (op / 100);
			MozOpacity = (op / 100);
			filter = "alpha(opacity=" + op + ")";
		}
	}
}

function fadeElement( el, out, phase, increments)
{
	var speed = (phase / increments) * 1000;
	var timer = 0;
	if (!!out) {
		for (var i = 99; (i >= 0); --i) {
			setTimeout( 'setOpacity( $("' + el.id + '"), ' + i + ')', (timer * speed) );
			++timer;
		}
		setTimeout( '$("' + el.id + '").style.display = "none"', (timer * speed) );
	} else {
		if (el.style.display === "none") {
			el.style.display = "";
		}
		for (var i = 0; (i <= 100); ++i) {
			setTimeout( 'setOpacity( $("' + el.id + '"), ' + i + ')', (timer * speed) );
			++timer;
		}
	}
}

function ElementDimensions(elem)
{
	if (!elem) {
		return {};
	}

	if (elem.clientWidth == 0 || elem.clientHeight == 0) {
		var
			old_display = elem.style.display,
			old_visibility = elem.style.visibility;
		with (elem.style) {
			visibility = "hidden";
			display = "block";
		}
	}

	this.inner = { // content and padding; gives 0 for inline elements (you can use scrollWidth/Height if it's inline)
		width: elem.clientWidth,
		height: elem.clientHeight
	};
	this.outer = { // everything (content, padding, scrollbar, border)
		width: elem.offsetWidth,
		height: elem.offsetHeight
	};
	this.scroll = { // width & height of entire content field (including padding), visible or not
		// incorrect in Opera; it doesn't include the padding
		width: elem.scrollWidth,
		// if there are no scrollbars, IE gives the actual height of the content instead of the height of the element
		height: (elem.scrollHeight < elem.clientHeight)? elem.clientHeight : elem.scrollHeight,
		//scroll position of content & padding
		left: elem.scrollLeft,
		top: elem.scrollTop
	};

	if (typeof old_display === "string" && typeof old_visibility === "string") {
		with (elem.style) {
			display = old_display;
			visibility = old_visibility;
		}
	}

	//position of element from the top-left corner of the document
	var temp = elem;
	this.left = this.top = 0;
	while (temp.offsetParent) {
		this.left += temp.offsetLeft;
		this.top += temp.offsetTop;
		temp = temp.offsetParent;
	}
}

function MouseCoordinates(e)
{
	if (e.pageX || e.pageY) {
		this.x = e.pageX;
		this.y = e.pageY;
	} else if (e.clientX || e.clientY) {
		this.x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		this.y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	} else {
		this.x = 0;
		this.y = 0;
	}
}

function fireClick(el)
{
	if (!el) {
		return false;
	}
	if (document.all) {
		el.click();
	} else {
		var e = document.createEvent("MouseEvents");
		e.initMouseEvent("click", true, true, document.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
		el.dispatchEvent(e);
	}
}


// var AjaxInterface = new Interface("AjaxInterface", ["request", "createXhrObject"]);

// AjaxSimpleHandler class
var AjaxSimpleHandler = function() {}; // implements AjaxInterface

AjaxSimpleHandler.prototype = {
	request: function(method, url, callback, postVars){
		var xhr = this.createXhrObject();
		xhr.onreadystatechange = function() {
			if (xhr.readyState !== 4) {
				return;
			}
			if (xhr.status === 200) {
				callback.success(xhr.responseText, xhr.responseXML)
			} else {
				callback.failure(xhr.status);
			}
		};
		xhr.open(method, url, true);
		if (method != "post") {
			postVars = null;
		}
		xhr.send(postVars);
	},
	createXhrObject: function() {
		var
			xhr,
			methods = [
				function() {
					return new XMLHttpRequest();
				},
				function() {
					return new ActiveXObject("Msxml2.XMLHTTP");
				},
				function() {
					return new ActiveXObject("Microsoft.XMLHTTP");
				}
			];
		for (var i in methods) {
			try {
				xhr = methods[i]();
			} catch(e) {
				continue;
			}
			// if we reach this point, method[i] worked
			this.createXhrObject = methods[i];
			return (typeof xhr === "function")? xhr() : xhr;
		}
		// if we reach this point, nothing worked
//		throw new Error("AjaxSimpleHandler is unable to create an XHR object.");
	}
};


// AjaxQueueHandler class
var AjaxQueueHandler = function() { // implements AjaxInterface
	this.queue = [];
	this.requestInProgress = false;
	this.retryDelay = 5000; // ms
};

extend(AjaxQueueHandler, AjaxSimpleHandler);

AjaxQueueHandler.prototype.request = function(method, url, callback, postVars, override) {
	if (this.requestInProgress && !override) {
		this.queue.push( {
			method: method,
			url: url,
			callback: callback,
			postVars: postVars
		} );
	} else {
		this.requestInProgress = true;
		var xhr = this.createXhrObject();
		var that = this;
		xhr.onreadystatechange = function() {
			if (xhr.readyState !== 4) {
				return;
			}
			if (xhr.status === 200) {
				callback.success(xhr.responseText, xhr.responseXML);
				that.advanceQueue();
				return;
			}
			callback.failure(xhr.status);
			setTimeout(
				function() {
					that.request(method, url, callback, postVars);
				},
				that.retryDelay
			);
		};
		xhr.open(method, url, true);
		if (method != "post") {
			postVars = null;
		}
		xhr.send(postVars);
	}
};

AjaxQueueHandler.prototype.advanceQueue = function() {
	if (this.queue.length === 0) {
		this.requestInProgress = false;
		return;
	}
	var req = this.queue.shift();
	this.request(req.method, req.url, req.callback, req.postVars, true);
};

// AjaxOfflineHandler class
var AjaxOfflineHandler = function() { // implements AjaxInterface
	this.storedRequests = [];
};

extend(AjaxOfflineHandler, AjaxSimpleHandler);

AjaxOfflineHandler.prototype.request = function(method, url, callback, postVars) {
	if (AjaxXhrManager.isOffline()) {
		this.storedRequests.push({
			method: method,
			url: url,
			callback: callback,
			postVars: postVars
		});
	} else {
		this.flushStoredRequests();
		AjaxOfflineHandler.superclass.request(method, url, callback, postVars);
	}
};

AjaxOfflineHandler.prototype.flushStoredRequests = function() {
	for (var i in storedRequests) {
		var req = storedRequests[i];
		AjaxOfflineHandler.superclass.request(req.method, req.url, req.callback, req.postVars);
	}
};

// AjaxXhrManager singleton
var AjaxXhrManager = {
	createXhrHandler: function() {
		var xhr;
		if (this.isOffline()) {
			xhr = new AjaxOfflineHandler();
		} else if (this.isHighLatency()) {
			xhr = new AjaxQueueHandler();
		} else {
			xhr = new AjaxSimpleHandler();
		}
	//	Interface.ensureImplements(xhr, AjaxInterface);
		return xhr;
	},
	isOffline: function() {
		return false;
	},
	isHighLatency: function() {
		return false;
	}
};



/* End of lib_v1.0004.js













 Below code used to be in common.js - moved 2010-12-09 */


	function write_default_text( objT, txtDefault ){
		if( typeof(objT) === "object" && objT.value === "" ){
			objT.value = txtDefault;
		}
	}

	function clear_textbox( objT, txtDefault ){
		if( typeof(objT) === "object" && objT.value === txtDefault ){
			objT.value = "";
		}
	}
/*
	function validateOrderConfirm( form ){
		if( form["terms"] && form["terms"].type === "checkbox" && form["terms"].checked === false ){
			alert("You must accept our terms and conditions to continue with your order");
			return false;
		}
	}
*/

if (!document.all) {
	XBrowserAddEvent(
		window,
		"load",
		function( ){
			return function( ){
				var
					elements = $c("jsBlurOnFocus"),
					length = elements.length;
				for (var i = 0; i < length; i++) {
					switch (elements[i].tagName.toUpperCase()) {
						case "A" :
						case "AREA" :
							var events = ["click", "mousedown", "focus"];
							break;
						case "IMG" :
							var events = ["click", "mousedown"];
							break;
						case "INPUT" :
							if (elements[i].type.toUpperCase() === "IMAGE") {
								var events = ["click", "mousedown", "focus"];
								break;
							}
					}
					var zength = events.length;
					for (var j = 0; j < zength; j++) {
						XBrowserAddEvent(
							elements[i],
							events[j],
							function( ){
								return function( ){
									this.blur();
								};
							}( )
						);
					}
				}
			};
		}( )
	);
}







// menu javascript


var menu_pause_time = 350,
	gc_timeout      =
	gc_timeout2     =
	gc_hide_timeout =
	gc2             =
	gc3             = false;


(function($){

	$(document).ready(function() {

		$('#menu_container').children('.menu_root').children('li').hover(
			function(){
				gc = $(this);
				if (gc2 != false){
					if (gc2 == $(this)){
						clearTimeout(gc_hide_timeout);
					}
					else{
						gc2.children('ul').hide();
						gc2.removeClass('sub_menu_hover');
					}
				}
				gc_timeout = setTimeout(function(){ gc.children('ul').show(); gc.addClass('sub_menu_hover'); }, menu_pause_time);
			},
			function (){
				gc2 = $(this);
				gc_hide_timeout = setTimeout(function(){ gc2.children('ul').hide(); gc2.removeClass('sub_menu_hover'); }, menu_pause_time);
				clearTimeout(gc_timeout);
			}
		);
		$('#menu_container').children('.menu_root').children('li').children('ul').hover(
			function(){
				gc = $(this);
				gc_timeout = setTimeout(function(){ gc.children('ul').show(); }, menu_pause_time);
			},
			function (){
				gc2 = $(this);
				gc_hide_timeout = setTimeout(function(){ gc2.children('ul').hide(); }, menu_pause_time);
			}
		);
		$('#womens_which_wear').hover(
			function(){
				if (gc3 != false){
					if (gc3.attr("id") == 'womens_mega_menu_container'){
						clearTimeout(gc_timeout2);
					}
					else{
						gc3.hide();
						$('#header .which_wear li#womens_which_wear').removeClass('big_nip_hover_off');
						$('#header .which_wear li#mens_which_wear').removeClass('big_nip_hover_on');
					}
				}
				gc3 = false;
				$('#header .which_wear li#womens_which_wear').addClass('big_nip_hover_on');
				$('#header .which_wear li#mens_which_wear').addClass('big_nip_hover_off');
				gc_timeout = setTimeout(function(){ $('#womens_mega_menu_container').show(); }, menu_pause_time);
			},
			function (){
				gc3 = $('#womens_mega_menu_container');
				gc_timeout2 = setTimeout(function(){
					if (gc3 != false){
						gc3.hide();
					}
					$('#header .which_wear li#womens_which_wear').removeClass('big_nip_hover_on');
					$('#header .which_wear li#mens_which_wear').removeClass('big_nip_hover_off');
				}, menu_pause_time);
				clearTimeout(gc_timeout);
			}
		);
		$('#mens_which_wear').hover(
			function(){
				if (gc3 != false){
					if (gc3.attr("id") == 'mens_mega_menu_container'){
						clearTimeout(gc_timeout2);
					}
					else{
						gc3.hide();
						$('#header .which_wear li#womens_which_wear').removeClass('big_nip_hover_on');
						$('#header .which_wear li#mens_which_wear').removeClass('big_nip_hover_off');
					}
				}
				gc3 = false;
				$('#header .which_wear li#womens_which_wear').addClass('big_nip_hover_off');
				$('#header .which_wear li#mens_which_wear').addClass('big_nip_hover_on');
				gc_timeout = setTimeout(function(){ $('#mens_mega_menu_container').show(); }, menu_pause_time);
			},
			function (){
				gc3 = $('#mens_mega_menu_container');
				gc_timeout2 = setTimeout(function(){
					if (gc3 != false){
						gc3.hide();
					}
					$('#header .which_wear li#womens_which_wear').removeClass('big_nip_hover_off');
					$('#header .which_wear li#mens_which_wear').removeClass('big_nip_hover_on');
				}, menu_pause_time);
				clearTimeout(gc_timeout);
			}
		);

		$('#mens_mega_menu_container').children('.menu_root').hover(
			function(){
				clearTimeout(gc_timeout2);
				$(this).parent().show();
			},
			function (){
				gc3 = $(this).parent();
				gc_timeout2 = setTimeout(function(){
					if (gc3 != false){
						gc3.hide();
					}
					$('#header .which_wear li#womens_which_wear').removeClass('big_nip_hover_off');
					$('#header .which_wear li#mens_which_wear').removeClass('big_nip_hover_on');
				}, menu_pause_time);
			}
		);


		$('#womens_mega_menu_container').children('.menu_root').hover(
			function(){
				clearTimeout(gc_timeout2);
				$(this).parent().show();
			},
			function (){
				gc3 = $('#womens_mega_menu_container');
				gc_timeout2 = setTimeout(function(){
					if (gc3 != false){
						gc3.hide();
					}
					$('#header .which_wear li#womens_which_wear').removeClass('big_nip_hover_on');
					$('#header .which_wear li#mens_which_wear').removeClass('big_nip_hover_off');
				}, menu_pause_time);
			}
		);
        
        jQuery('div#mens_mega_menu_container a').click(function(){
            document.cookie='mw_sector=menswear; path=/; domain=.my-wardrobe.com;';
        });

	});



})(this.jQuery);
