//提交查询之前在地址栏绑定参数
function AddParamsBeforeSubmit(button) {
	var AddParamsBeforeSubmit = C.Create();
	AddParamsBeforeSubmit.prototype = {Initilize:function (button) {
		var fnSubmit = C.BindAsEventListener(this, this.Submit);
		C.AddEventHandler(button, "click", fnSubmit);
	}, GenerateUrl:function () {
		switch (parseInt(C.Name("search").value)) {
		  case 1:
			return "search/searchShop.do?keyWord=" + C.Name("searchKey").value;
		  case 2:
			return "search/searchClothes.do?keyWord=" + C.Name("searchKey").value;
		  case 3:
		    return "search/searchBrands.do?keyWord=" + C.Name("searchKey").value;
		}
	}, Submit:function () {
		if (document.all) {
			window.open("/" + encodeURI(this.GenerateUrl()));
		} else {
			window.open(encodeURI(this.GenerateUrl()));
		}
	}};
	new AddParamsBeforeSubmit(button);
}

//为input添加enter提交事件
function EnterToSubmit(tagInput, tagA) {//tagA表示A标签
	var EnterToSubmit = C.Create();
	EnterToSubmit.prototype = {Initilize:function (tagInput, tagA) {
		var fnEnterToSubmit = C.BindAsEventListener(this, this.EnterToSubmit, tagA);
		C.AddEventHandler(tagInput, "keypress", fnEnterToSubmit);
		C.Delete(fnEnterToSubmit);
	}, EnterToSubmit:function (oEvent, tagA) {
		if (oEvent.keyCode == 13) {
			this.Submit(tagA);
		}
	}, Submit:function (tagA) {
		if (C.IsIE) {
			tagA.click();
		} else {
			var evt = document.createEvent("MouseEvents");
			evt.initEvent("click", true, true);
			tagA.dispatchEvent(evt);
			C.Delete(evt);
		}
	}};
	new EnterToSubmit(tagInput, tagA);
}

//设为主页
function SetHomePage(tag) {
	if(!document.all){
			try{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
				var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
	        	prefs.setCharPref("browser.startup.homepage", window.location); 
	        }
	        catch(e){
	            alert("抱歉：您的浏览器不支持该操作。"); 
	        }
	    }else{
			document.body.style.behavior="url(#default#homepage)";
	        document.body.setHomePage(window.location);
	    }
}

//导航栏
function NavigationMouseOver(endWord, navigationName) {
	var NavigationMouseOver = C.Create();
	NavigationMouseOver.prototype = {EndWord:"0", NavigationName:"navigation", Initilize:function (endWord, navigationName) {
		if (endWord != undefined) {
			this.EndWord = endWord;
			if (navigationName != undefined) {
				this.NavigationName = navigationName;
			}
		}
		var fnMouseOver = C.BindAsEventListener(this, this.MouseOver);
		var fnMouseOut = C.BindAsEventListener(this, this.MouseOut);
		C.AddEventHandler(C.Name(this.NavigationName), "mouseover", fnMouseOver);
		C.AddEventHandler(C.Name(this.NavigationName), "mouseout", fnMouseOut);
		C.Delete[fnMouseOver, fnMouseOut];
	}, MouseOver:function (oEvent) {
		var thisObj = {};
		if (C.IsIE) {
			thisObj = oEvent.srcElement;
		} else {
			thisObj = oEvent.target;
		}
		var imgDat = thisObj.src.split(".")[thisObj.src.split(".").length - 1];
		var imgName = thisObj.src.replace("." + imgDat, "");
		C.SetAttr(thisObj, "src", imgName + this.EndWord + "." + imgDat);
		C.Delete[thisObj, imgDat, imgName];
	}, MouseOut:function (oEvent) {
		var thisObj = {};
		if (C.IsIE) {
			thisObj = oEvent.srcElement;
		} else {
			thisObj = oEvent.target;
		}
		var imgDat = thisObj.src.split(".")[thisObj.src.split(".").length - 1];
		var imgName = thisObj.src.replace("." + imgDat, "");
		if (C.EndWith(imgName, "0")) {
			C.SetAttr(thisObj, "src", imgName.substr(0, imgName.length - 1) + "." + imgDat);
		}
		C.Delete[thisObj, imgDat, imgName];
	}};
	new NavigationMouseOver();
}

function PreloadImages(){
	var div = document.createElement("div");
	$(div).css("display","none");
	var img = document.createElement("img");
	for (var i = 0; i < arguments.length; i = i + 1) {
			var imgClone = img.cloneNode(false);
			$(imgClone).attr( "src", arguments[i]);
			div.appendChild(imgClone);
		}
	var body = document.getElementsByTagName("body");
	body[0].appendChild(div);
}

var C = {Create:function () {
	return function () {
		this.Initilize.apply(this, arguments);
	};
}, Tag:function () {
	if (arguments.length == 1) {
		var a = document.getElementsByTagName(arguments[0]);
		return a.length >= 2 ? a : (a.length == 1 ? a[0] : undefined);
	}
}, Id:function () {
	if (arguments.length == 1) {
		return document.getElementById(arguments[0]);
	}
}, Name:function () {
	if (arguments.length == 1) {
		var a = document.getElementsByName(arguments[0]);
		return a.length >= 2 ? a : (a.length == 1 ? a[0] : undefined);
	}
}, Next:function (a, b) {
	if (!a) {
		return;
	}
	do {
		a = a.nextSibling;
	} while (a && a.nodeType != 1);
	while (a && b) {
		if (a.nodeName == b.toUpperCase()) {
			break;
		} else {
			do {
				a = a.nextSibling;
			} while (a && a.nodeType != 1);
		}
	}
	return a;
}, Tag$Class:function () {
	if (arguments.length == 2 && typeof arguments[0] == "string" && typeof arguments[1] == "string") {
		var a = C.Tag(arguments[0]);
		var c = [];
		for (var b = 0; b < a.length; b = b + 1) {
			if (a[b].className == arguments[1]) {
				c.push(a[b]);
			}
		}
		C.Delete(a);
		return c.length >= 2 ? c : (c.length == 1 ? c[0] : undefined);
	}
}, Tag$Name:function () {
	if (arguments.length == 2 && typeof arguments[0] == "string" && typeof arguments[1] == "string") {
		var a = C.Tag(arguments[0]);
		var c = [];
		for (var b = 0; b < a.length; b = b + 1) {
			if (a[b].getAttribute("name") == arguments[1]) {
				c.push(a[b]);
			}
		}
		C.Delete(a);
		return c.length >= 2 ? c : (c.length == 1 ? c[0] : undefined);
	}
}, Bind:function () {
	if (arguments.length >= 2) {
		var b = arguments;
		var a = Array.prototype.slice.call(b, 2);
		return function () {
			return b[1].apply(b[0], a);
		};
	}
}, BindAsEventListener:function () {
	if (arguments.length >= 2) {
		var b = arguments;
		var a = Array.prototype.slice.call(b, 2);
		return function (c) {
			return b[1].apply(b[0], [c || window.event].concat(a));
		};
	}
}, AddEventHandler:function (b, d, a) {
	if (b.length >= 1) {
		for (var c = 0; c < b.length; c = c + 1) {
			if (b[c].addEventListener) {
				b[c].addEventListener(d, a, false);
			} else {
				if (b[c].attachEvent) {
					b[c].attachEvent("on" + d, a);
				} else {
					b[c]["on" + d] = a;
				}
			}
		}
	} else {
		if (b.addEventListener) {
			b.addEventListener(d, a, false);
		} else {
			if (b.attachEvent) {
				b.attachEvent("on" + d, a);
			} else {
				b["on" + d] = a;
			}
		}
	}
}, RemoveEventHandler:function (b, d, a) {
	if (b.length >= 1) {
		for (var c = 0; c < b.length; c = c + 1) {
			if (b[c].removeEventListener) {
				b[c].removeEventListener(d, a, false);
			} else {
				if (b[c].detachEvent) {
					b[c].detachEvent("on" + d, a);
				} else {
					b[c]["on" + d] = null;
				}
			}
		}
	} else {
		if (b.removeEventListener) {
			b.removeEventListener(d, a, false);
		} else {
			if (b.detachEvent) {
				b.detachEvent("on" + d, a);
			} else {
				b["on" + d] = null;
			}
		}
	}
}, SetAttr:function () {
	if (arguments.length >= 3) {
		var b = Array.prototype.shift.call(arguments);
		if (b && b.length >= 1) {
			while (arguments.length > 0) {
				var a = Array.prototype.shift.call(arguments);
				var d = Array.prototype.shift.call(arguments);
				for (var c = 0; c < b.length; c = c + 1) {
					b[c][a] = d;
				}
			}
		} else {
			if (b) {
				while (arguments.length > 0) {
					b[Array.prototype.shift.call(arguments)] = Array.prototype.shift.call(arguments);
				}
			}
		}
		C.Delete(b);
	}
}, SetCSS:function () {
	if (arguments.length >= 3) {
		var b = Array.prototype.shift.call(arguments);
		if (b && b.length >= 1) {
			while (arguments.length > 0) {
				var a = Array.prototype.shift.call(arguments);
				var d = Array.prototype.shift.call(arguments);
				for (var c = 0; c < b.length; c = c + 1) {
					b[c].style[a] = d;
				}
			}
		} else {
			if (b) {
				while (arguments.length > 0) {
					b.style[Array.prototype.shift.call(arguments)] = Array.prototype.shift.call(arguments);
				}
			}
		}
		C.Delete(b);
	}
}, Delete:function () {
	for (var a = 0; a < arguments.length; a = a + 1) {
		delete arguments[a];
	}
}, StartWith:function () {
	if (arguments.length == 2 && typeof arguments[0] == "string" && typeof arguments[1] == "string") {
		return arguments[0].slice(0, 1) == arguments[1] ? true : false;
	}
}, EndWith:function () {
	if (arguments.length == 2 && typeof arguments[0] == "string" && typeof arguments[1] == "string") {
		return arguments[0].slice(arguments[0].length - 1) == arguments[1] ? true : false;
	}
}, Load:function (a) {
	var b = C.Bind(this, a);
	C.AddEventHandler(window, "load", a);
	C.Delete(b);
}, IsIE:(document.all) ? true : false, IsIE6:(window.XMLHttpRequest) ? false : true};


