
function setH3(){
	var geth3 = document.getElementsByTagName("h3");
	for(i = 0; i < geth3.length; i++) geth3[i].innerHTML = geth3[i].innerHTML + " ";
}
setH3();


function $A(iterable) {
	var results = [];
	for (var i = 0; i < iterable.length; i++) results.push(iterable[i]);
	return results;
}

Function.prototype.bind = function() {
	var __method = this, args = $A(arguments), object = args.shift();
	return function() {
		return __method.apply(object, args.concat($A(arguments)));
	};
};


function flipMenu(flipObj){
	this.flipObj = flipObj;
	this.initialize();
}

(function(){
	var flipMenuTime;
	
	flipMenu.prototype = {
		initialize: function(){
			this.getaim;
			this.flag = this.flipObj.flag;
			this.aimPos = this.flipObj.aimTagPos;
			this.alpha = parseFloat(this.flipObj.opacity);
			this.freq = parseInt(this.flipObj.frequency);
			this.getflip = this.getNodeById(this.flipObj.flipMenuId);

			if(!this.getflip) return;

			var getanchor = this.getNodeById(this.aimPos.idarr).getElementsByTagName(this.aimPos.tagarr);
			for(a = 0; a < getanchor.length; a++){
				if(eval("getanchor[a]." + this.aimPos.paraname + ".indexOf('" + this.aimPos.paravalue + "')") != -1){
					this.getaim = getanchor[a];
					break;
				}
			}

			if(!this.getaim) return;
			
			var obj = this;
			this.getaim.onmouseover = function(){
				clearTimeout(flipMenuTime);
				var aimleft = obj.getaim.offsetLeft;
				var aimtop = obj.getaim.offsetTop;
				if(obj.checkNav("MSIE 6") || obj.checkNav("MSIE 7")){
					aimleft = obj.nodeRecursion(obj.getaim, "parentNode", "offsetLeft");
					aimtop = obj.nodeRecursion(obj.getaim, "parentNode", "offsetTop");
				}

				obj.getflip.style.position = "absolute";
				obj.getflip.style.left = aimleft + parseInt(obj.flipObj.offset.x) + "px";

				if(obj.flag == "up") aimtop -= obj.getProperty(obj.getflip, "offsetHeight");
				obj.getflip.style.top = aimtop + parseInt(obj.flipObj.offset.y) + "px";

				obj.opacity(obj.getflip, obj.alpha);
				obj.getflip.style.display = "block";
			};

			this.getaim.onmouseout = function(){
				obj.changeOpacity(obj.getflip, obj.alpha, obj.freq);
			};

			this.getflip.onmouseover = function(){
				clearTimeout(flipMenuTime);
				obj.opacity(this, obj.alpha);
				this.style.display = "block";
			};

			this.getflip.onmouseout = function(){
				obj.changeOpacity(obj.getflip, obj.alpha, obj.freq);
			};
		},
		
		getProperty: function(flipObj, property){
			this.opacity(flipObj, 0);
			flipObj.style.display = "block";
			return eval("flipObj." + property);
		},

		opacity: function(flipObj, percent){
			if(document.all) flipObj.style.filter = "Alpha(opacity=" + percent * 10 + ")";
			else flipObj.style.opacity = percent / 10;
		},

		changeOpacity: function(flipObj, percent, freq){
			if(percent > 0){
				freq = freq / 2;
				this.opacity(flipObj, --percent);
				flipMenuTime = setTimeout(this.changeOpacity.bind(this, flipObj, percent, freq), freq);
			}
			else flipObj.style.display = "none";
		},

		checkNav: function(ver){
			var nav = navigator.userAgent.indexOf(ver);
			if(nav == -1) return false;
			else return true;
		},

		nodeRecursion: function(tobj, tarnodes, nodepro){
			var provalue;
			if(!provalue) provalue = 0;

			try {
				tobj = eval("tobj." + tarnodes);
				provalue = this.nodeRecursion(tobj, tarnodes, nodepro);
			}
			catch (e){}
			var temp = eval("tobj." + nodepro);
			temp = parseInt(temp);

			if(tobj.tagName.toLowerCase() == "body") temp = 0;
			if(!isNaN(temp)) provalue += temp;

			return provalue;
		},

		getCssStyle: function(obj, type, thisvar, removefrom){
			var value;
			if(obj.currentStyle){
				//for(s in obj.currentStyle) document.getElementById('error').innerHTML += s + ' : ' + obj.currentStyle[s] + '<br>';
				if(type == "opacity") value = parseInt(obj.currentStyle['filter'].replace(/[^\d]/gi, "")) / 10;
				else var value = obj.currentStyle[type];
			}
			else if(window.getComputedStyle){
				type = type.toLowerCase();
				value = parseFloat(document.defaultView.getComputedStyle(obj, null)[type]) * 10;
			}

			if(thisvar) eval(thisvar + "=value;");

			if(removefrom){
				var removearr = removefrom.split("_");
				if(removearr[1] == "body") document.body.removeChild(obj);
			}

			return value;
		},
		
		getNodeById: function(idname){
			var tags;
			var bodyhtml = document.body.innerHTML;
			var reg = new RegExp("<(\\w*)([^>]*) id=([\'\"]?)" + idname + "\\3(>| [^>]+>)", "i");
			bodyhtml.replace(reg, function(){ tags = arguments[1]; });

			var getags = document.getElementsByTagName(tags);
			for(i = 0; i < getags.length; i++){
				if(getags[i].id == idname){
					return getags[i];
				}
			}
		}
	}
})();

var flipObj = {
	aimTagPos: {idarr: "menu", tagarr: "a", paraname: "href", paravalue: "products.html"},
	flipMenuId: "flipmenu",
	offset: {x: "0", y: "37"},
	opacity: "9.5",
	frequency: "200"
};

new flipMenu(flipObj);


var flipObj = {
	aimTagPos: {idarr: "link", tagarr: "a", paraname: "href", paravalue: "products.html"},
	flipMenuId: "flipmenu",
	offset: {x: "0", y: "-8"},
	opacity: "9.5",
	frequency: "200",
	flag: "up"
};

new flipMenu(flipObj);



function check_mform_value(method){
	var dhref = document.location.href;
	if((dhref.indexOf("contact.html") == -1) && (dhref.indexOf("linkex.html") == -1)) return;

	var text_email = document.getElementById("text_email").value;
	var text_please_enter = document.getElementById("text_please_enter").value;
	var text_please_select = document.getElementById("text_please_select").value;
	var text_email_is_invalid = document.getElementById("text_email_is_invalid").value;

	if(method == "init"){
		var alltag = ["input", "textarea"];
		for(j = 0; j < alltag.length; j++){
			var getag = document.getElementsByTagName(alltag[j]);
			for(i = 0; i < getag.length; i++){
				if(getag[i].className == "blur"){
					getag[i].onfocus = function(){ this.className = "focus"; }
					getag[i].onblur = function(){ this.className = "blur"; }
				}
			}
		}
		try {
			if(/\/\w{2}\/contact.html/.test(dhref)){
				document.getElementById("tips").innerHTML = '<font color="red"><b>For better serves for you, please as far as possible use English to fill in the followings!</b></font>';
			}
		}
		catch(e){}
	}

	var mailreg = /^[._a-zA-Z0-9-]+@([-_a-zA-Z0-9]+\.)+[a-zA-Z0-9]{2,4}$/;
	var getform = document.getElementsByTagName("form");
	for(i = 0; i < getform.length; i++){
		if((method == "init") || (getform[i].id == method.id) || (getform[i].id == "contact")){
			var getr = getform[i].getElementsByTagName("tr");
			for(j = 0; j < getr.length; j++){
				var tdesp = getr[j].getElementsByTagName("td")[0].innerHTML;
				if(tdesp.indexOf("*") != -1){
					var operate = "enter";
					var getd = getr[j].getElementsByTagName("td")[1];
					if(!getd) continue;

					var getele = getd.getElementsByTagName("input")[0];
					if(!getele) getele = getd.getElementsByTagName("textarea")[0];
					if(!getele){
						operate = "select";
						getele = getd.getElementsByTagName("select")[0];
					}
					if(!getele) continue;
					
					if(method == "init"){
						getele.onblur = function(){
							this.className = "blur";
							var chvalid = true;
							var ftd = this.parentNode.parentNode.getElementsByTagName("td")[0];
							if(ftd.innerHTML.indexOf(text_email) != -1){
								chvalid = mailreg.test(this.value);
							}
							if(!this.value || !chvalid) ftd.style.color = "red";
						};
						getele.onfocus = function(){
							this.className = "focus";
							this.parentNode.parentNode.getElementsByTagName("td")[0].style.color = "black";
						};
					}
					else {
						tdesp = tdesp.replace(/<\/?[^>]*>|\*|:/gi, "");
						tdesp = tdesp.replace(/^\s*|\s*$/gi, "");
						if(!getele.value){
							if(operate == "enter")	alert(text_please_enter + " " + tdesp);
							else if(operate == "select")	alert(text_please_select + " " + tdesp);
							return false;
						}
						else if(tdesp.indexOf(text_email) != -1){
							if(!mailreg.test(getele.value)){
								alert(text_email_is_invalid);
								return false;
							}
						}
					}
				}
			}
			if(method != "init") return true;
		}
	}
}

check_mform_value("init");

