
function setH3(){
	var geth3 = document.getElementsByTagName("h3");
	for(i = 0; i < geth3.length; i++) geth3[i].innerHTML = geth3[i].innerHTML + " ";
}
setH3();

function translator(pattern) {
	var open_in_same_window = false;
	var my_location = unescape(document.location.toString());
	var new_location = document.location;
	var new_pattern = '';
	var islocal = 1;

	if(my_location.indexOf('babelfish/translate_url_content?') != -1){
		var indexof_u = my_location.indexOf('&trurl=');
		if (indexof_u != -1) {
			var subs = my_location.substring(indexof_u, my_location.length);
			var ss = subs.split('&');
			new_location = ss[1].substring(6, ss[1].length);
			islocal = 0;
		}
	}

	indexof_p = pattern.indexOf('|');
	var isen = '';
	var lg = '';
	if (indexof_p == -1) {
		indexof_p1 = pattern.indexOf('><');
		if (indexof_p1 == -1) {
			new_pattern = pattern;
			if (pattern == 'en') isen = 1;
		}
		else {
			var psplit = pattern.split('><');
			new_pattern = psplit[0] + '_' + psplit[1];
			if (psplit[1] == 'en') isen = 1;
			else lg = psplit[1];
		}
	}
	else {
		var psplit = pattern.split('|');
		new_pattern = psplit[0]+'_'+psplit[1];
		if (psplit[1] == 'en') isen = 1;
		else lg = psplit[1];
	}

	var thisurl = '';
	if (isen == 1) thisurl = new_location;
	else {
		new_location = escape(new_location);
		if (islocal == 1) {
			thisurl = "language.php?to=" + lg + "&url=" + new_location;
		} else {
			open_in_same_window = true;
			thisurl = "http://66.163.168.225/babelfish/translate_url_content?lp=" + new_pattern + "&trurl=" + new_location;
		}
	}

	if (open_in_same_window) window.location.href = thisurl;
	else {
		msgWindow=window.open('' ,'subwindow','toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,menubar=yes,resizable=yes,left=0,top=0');
		msgWindow.focus();
		msgWindow.location.href = thisurl;
	}
}

var dhref = document.location.href;

window.onload = function(){
	if(dhref.indexOf("66.163.168.225") != -1){
		alength();
		if(window.event){
			document.write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n" + document.getElementsByTagName("html")[0].outerHTML);
		}
		var form = document.getElementsByTagName("form");
		for(var i = 0; i < form.length; i++){
			form[i].action = form[i].getElementsByTagName("input")[2].value;
		}
		try {
			var getinput = document.getElementById("search").getElementsByTagName("input");
			for(s = 0; s < getinput.length; s++){
				if(getinput[s].type == "submit") getinput[s].value = "";
			}
		}
		catch (e){}
	}
};


var fontinfo = [
	// [ID, TagName, Fontsize(max, min), Padding(this-cycle, min), Letterspace, Totalwidth]
	["menu", "a", "12", "10", "18-4", "1", "0", "600"]
];

function alength(){
	for(j = 0;j < fontinfo.length;j++){
		var fonts = new Array();
		fonts = fontinfo[j];

		var geta, spm = 1, over = 1;
		var fsize = fonts[2], ftmin = fonts[3];
		var pthis = fonts[4].split("-"), pdmin = fonts[5];
		var lspace = fonts[6];
		var gtag = new Array();
		var wide = fonts[7] - gtag.length * 10;
		geta = document.getElementById(fonts[0]);
		gtag = geta.getElementsByTagName(fonts[1]);

		while(over){
			over = 0;
			twide = wide;
			for(i = 0;i < gtag.length;i++){
				twide = twide - gtag[i].offsetWidth;
				if(twide < 0){
					switch(spm){ 
						case 1: {
							if(pthis[1]) { spm--; pthis[1]--; }
							spm++;
							if(parseInt(pthis[0]) > pdmin) { 
								pthis[0] = pthis[0] - 2; 
								for(m = 0;m < gtag.length;m++){
									gtag[m].style.paddingLeft = pthis[0] + "px";
									gtag[m].style.paddingRight = pthis[0] + "px";
								}
								break;
							}
						}
						case 2:{
							spm++;
							if(fsize >= ftmin) { fsize--; break; }
						}
						default: {
							lspace--; spm = 1; break;
						}
					}
					geta.style.cssText = "font-size:" + fsize + "px; letter-spacing:" + lspace + "px;";
					over = 1;
					break;
				}
			}
		}
	}
}


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)));
	};
};
var flipMenuTime;

function flipMenu(flipObj){
	this.flipObj = flipObj;
	this.initialize();
}

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);
		if(getanchor) getanchor = getanchor.getElementsByTagName(this.aimPos.tagarr);
		else return;

		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");
				if(obj.checkNav("MSIE 7")) aimtop = obj.nodeRecursion(obj.getaim, "parentNode", "offsetTop") / 2;

				if(obj.flag != "up") aimtop *= 2;
			}

			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 = parseInt(eval("tobj." + nodepro));

		if(!isNaN(temp)) provalue += temp;
		return provalue;
	},
	
	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];
			}
		}
		return null;
	}
}

var flipObj = {
	aimTagPos: {idarr: "menu", tagarr: "a", paraname: "href", paravalue: "products.html"},
	flipMenuId: "flipmenu",
	offset: {x: "0", y: "42"},
	opacity: "9.5",
	frequency: "200"
};

new flipMenu(flipObj);


var flipObj = {
	aimTagPos: {idarr: "foot", tagarr: "a", paraname: "href", paravalue: "products.html"},
	flipMenuId: "flipmenu",
	offset: {x: "0", y: "1"},
	opacity: "9.3",
	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 = "";
						};
					}
					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");


