var pf0={};
var $=function(i){return document.getElementById(i);};
window.onload=function(){pf0=parent.document.forms[0].elements[0];}

function setLetters(a){
	var v = a.options[a.selectedIndex].value;
	if(v==0){
		if(parent.document.getElementById("unichart")){
		var m=parent.document.getElementsByTagName("form").length;
		var n=parent.document.getElementsByTagName("form").item(m-1);
		n.removeChild(n.lastChild);
		return;
		}
	}
	var t=parent.document.getElementById("unichart");
	if(t){loadHTML(v);}else{createDivTag();loadHTML(v);}
}
function createDivTag(){
	var s = document.createElement("div");
	s.setAttribute("id","unichart");
	var m=parent.document.getElementsByTagName("form").length;
	var n=parent.document.getElementsByTagName("form").item(m-1);
	n.appendChild(s);
}
function loadHTML(cc) {
	var dd = "parts/" + cc;
	try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}
	catch (e) { 	try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
			catch (e) {	xmlhttp = false;}}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	xmlhttp = new XMLHttpRequest();
	}

	if (xmlhttp) {
		xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		parent.document.getElementById("unichart").innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.open('GET', dd);
		xmlhttp.send('');
	}
}

function kd(){
  pf0.focus();
  var c=pf0.value;
  for(var i=0;i<document.forms.length;i++)document.forms[i].elements[0].value=c;
  if(kd.arguments.length==2){
	var nb=kd.arguments[0];
	var ch=kd.arguments[1];
	if (navigator.appName.indexOf("Microsoft") >= 0)document.charset=ch;
	document.forms[nb].submit();
	document.charset="shift_jis";
  }
}
function kwd(){pf0.focus();var c=pf0.value;for(var i=0;i<document.forms.length;i++)document.forms[i].elements[0].value=c;}
google.load("language","1");
function submitHonyaku(){
	var arg=submitHonyaku.arguments[0];
	if(!pf0.value)return;
	$('source').value=pf0.value.replace(/\"/g,'');
	if(navigator.appName.indexOf("Microsoft") >= 0)document.charset="utf-8";
	var w=$('source').value;
	var p=$('langpair');
	var l=p.options[p.selectedIndex].value;
	google.language.translate(w,"",l,function(r){if(!r.error){pf0.value=r.translation;(arg) ? kd(12,'utf-8') : null;}});
	document.charset="shift_jis";
	pf0.focus();
}
function submitTranslate(){
	var arg=submitTranslate.arguments[0];
	if(!pf0.value)return;
	$('source').value=pf0.value.replace(/\"/g,'');
	var w=$('source').value;
	var p=$('langpair');
	var l=p.options[p.selectedIndex].value;
	google.language.translate(w,"",l,function(r){if(!r.error){pf0.value=r.translation;(arg) ? sbm() : null;}});
	pf0.focus();
}
function sbm(){$('gWeb').elements[0].value=pf0.value;$('gWeb').submit();}
function charReference(baseNum){
	var baseNum,baseChar;
	var words=pf0.value;
	pf0.value="";
	if(baseNum==10)baseChar="&#"; else baseChar="&#x";
	if(words){
		if(words.match(/&#\d{1,5};|&#x[\da-fA-F]{1,5};/)){
			words=words.replace(/&#32;|&#x20;/gi," ");
			words=words.replace(/&#\d+;/g, function(a){return String.fromCharCode(a.replace(/&#|;/g,""));});
			words=words.replace(/&#x[\da-fA-F]{1,5};/gi,function(a){return String.fromCharCode( parseInt('0x'+a.replace(/&#x|;/gi,"")));});
			pf0.value=words;
		}
		else{
			for(var i=0;i<words.length;i++){pf0.value += baseChar + words.charCodeAt(i).toString(baseNum) + ";";}
			pf0.value=pf0.value.replace(/&#32;|&#x20;/gi," ");
		}
	}
	pf0.focus();
}
