
// modify the connect word after H3 tags
function setH3(){
	var geth3 = document.getElementsByTagName("h3");
	for(i = 0; i < geth3.length; i++) geth3[i].innerHTML = geth3[i].innerHTML + " ";
}

function translator(pattern) {
	var open_in_same_window = 0;
	var my_location = unescape(document.location.toString());
	var new_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) new_location = document.location;
		else {
			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;
		}
	} else {
		new_location = document.location;
		
	}

	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 = 1;
			thisurl = "http://66.163.168.225/babelfish/translate_url_content?lp=" + new_pattern + "&trurl=" + new_location;
		}
	}

	if (open_in_same_window == 1) 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;
	}
}
//Zhe following is Writed By Jamy
window.onload=function(){
	var href=document.location.href;
	if(href.indexOf("66.163.168.225")!=-1){
		if(window.event){
			var a=document.getElementsByTagName("html")[0].outerHTML;
			document.write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n"+a);
		}
		var form=document.getElementsByTagName("form");
		if(form.length){
			for(var i=0;i<form.length;i++)
			{
				form[i].action=form[i].getElementsByTagName("input")[2].value;
			}
		}
	}
	setH3();
}

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");


document.getElementById("curlanguage").onmouseover=view;
document.getElementById("curlanguage").onclick=stopbubble;
document.getElementById("translator").onclick=stopbubble;
document.onclick=hidden;
document.getElementById("q").onfocus=q_onfocus;
document.getElementById("q").onblur=q_onblur;
over("mainmenu",540,10);//max-width,min-pad
over("secondmenu",777,10);
over("ctlisttitle",198,10);
over("contacttitle",198,10);

function q_onfocus(){if(this.value=="search")this.value="";}

function q_onblur(){if(this.value=="")this.value="search";}

function view(){
	this.style.cursor="pointer";
	var obj=document.getElementById("translator");
	obj.style.zIndex="2";
}
function stopbubble()
{
	if(window.event){window.event.cancelBubble=true;}
	else{arguments[0].stopPropagation();}
}

function hidden(){document.getElementById("translator").style.zIndex="0";}
//overflow
function over(sender,maxwid,minpad)
{
	var obj=document.getElementById(sender);
	var link=obj.getElementsByTagName("a");
	if(link==null)link=obj.getElementsByTagName("span");
	var wid=0;
	for(var i=0;i<link.length;i++)
	{
		link[i].style.paddingLeft=minpad+"px";
		link[i].style.paddingRight=minpad+"px";
		wid+=link[i].offsetWidth;
	}
	while(wid>maxwid){wid=fontsize(link,-1);}
	var pad=(maxwid-wid+link.length*minpad*2)/(link.length*2);
	for(var i=0;i<link.length;i++)
	{
		link[i].style.paddingLeft=pad+"px";
		link[i].style.paddingRight=pad+"px";
	}
}
function fontsize(link,step)
{
	var size=link[0].currentStyle?link[0].currentStyle.fontSize:document.defaultView.getComputedStyle(link[0],null).fontSize;
	size=parseInt(size)+step;
	var wid=0;
	for(var i=0;i<link.length;i++)
	{
		link[i].style.fontSize=size+"px";
		wid+=link[i].offsetWidth;
	}
	return wid;
}