﻿


/*
āáǎàaōóǒòoēéěèeīíǐìiūúŭùuǖǘǚǜü

āáǎà a
ōóǒò o
ēéěè e
īíǐì i
ūúŭù u
ǖǘǚǜ ü
*/
toneMarksArray = new Array();
toneMarksArray['a'] = {1:'ā',2:'á',3:'ǎ',4:'à',5:'a'}
toneMarksArray['o'] = {1:'ō',2:'ó',3:'ǒ',4:'ò',5:'o'}
toneMarksArray['e'] = {1:'ē',2:'é',3:'ě',4:'è',5:'e'}
toneMarksArray['i'] = {1:'ī',2:'í',3:'ǐ',4:'ì',5:'i'}
//toneMarksArray['u'] = {1:'ū',2:'ú',3:'ŭ',4:'ù',5:'u'}
toneMarksArray['u'] = {1:'ū',2:'ú',3:'ǔ',4:'ù',5:'u'}
toneMarksArray['ü'] = {1:'ǖ',2:'ǘ',3:'ǚ',4:'ǜ',5:'ü'}

toneMarksArray['A'] = {1:'Ā',2:'Á',3:'Ǎ',4:'À',5:'A'}
toneMarksArray['O'] = {1:'Ō',2:'Ó',3:'Ǒ',4:'Ò',5:'O'}
toneMarksArray['E'] = {1:'Ē',2:'É',3:'Ě',4:'È',5:'E'}
toneMarksArray['I'] = {1:'Ī',2:'Í',3:'Ǐ',4:'Ì',5:'I'}
toneMarksArray['U'] = {1:'Ū',2:'Ú',3:'Ŭ',4:'Ù',5:'U'}
toneMarksArray['Ü'] = {1:'Ǖ',2:'Ǘ',3:'Ǚ',4:'Ǜ',5:'Ü'}


function pin_to_num_js(ts){
var test_str = ""+ts;
var test_tranlow = test_str;

var test_wen = "b|p|m|f|d|t|n|l|g|k|h|j|q|x|zh|ch|sh|r|z|c|s|y|w";
var test_sing = "a|o|e|ai|ei|ao|ou|an|en|ang|eng|ong|er|i|ia|iao|ie|iu|ian|in|iang|ing|iong|u|ua|uo|uai|ui|uan|un|uang|ue|uan|un|ü|üe|üan|ün";

var test_reg = /(zh|ch|sh|b|p|m|f|d|t|n|l|g|k|h|j|q|x|r|z|c|s|y|w)(iang|iong|uang|uai|ang|eng|ong|ian|uan|iao|uan|ing|ia|ie|iu|ai|ei|ao|ou|an|en|er|un|ue|un|in|ua|uo|ui|a|o|e|i|u|ü|üe|üan|ün)/gm ;
var test_reg2 = /(zh|ch|sh|b|p|m|f|d|t|n|l|g|k|h|j|q|x|r|z|c|s|y|w)(iang|iong|uang|uai|ang|eng|ong|ian|uan|iao|uan|ing|ia|ie|iu|ai|ei|ao|ou|an|en|er|un|ue|un|in|ua|uo|ui|a|o|e|i|u|ü|üe|üan|ün)/gm ;


for (x in toneMarksArray){
	for (i = 1; i < 6; i++){
		//alert(toneMarksArray[x][i]);
		//test_tranlow = test_tranlow.replaceAll(toneMarksArray[x][i],x);
		//test_tranlow = test_tranlow.replace(new RegExp(toneMarksArray[x][i],"gm"),x);
		//test_tranlow = test_tranlow.replace(toneMarksArray[x][i],x);

		var test_tranlow_x = test_tranlow.replace(toneMarksArray[x][i],x);
		while (test_tranlow != test_tranlow_x){
			test_tranlow = test_tranlow_x;
			test_tranlow_x = test_tranlow.replace(toneMarksArray[x][i],x);
		}
	}
}
test_tranlow = test_tranlow.toLowerCase();
//alert(test_tranlow);

//var und = test_tranlow.match(test_reg);

//alert(und);

var test_start_pos = 0;
var test_output = "";
//	alert("here");
var ie_plus = 0;
while ((myArray = test_reg.exec(test_tranlow)) != null) {


//document.writeln("myArray[0] " + myArray[0] + "<br>");
	//var test_copy_to_pos = test_reg.lastIndex - myArray[0].length;
	if (document.all){
		//ie
		test_copy_to_pos = test_start_pos + test_tranlow.substring(test_start_pos,ie_plus + test_reg.lastIndex  ).search(test_reg2);
	} else {
		//firefix
		test_copy_to_pos = test_start_pos + test_tranlow.substring(test_start_pos,test_reg.lastIndex  ).search(test_reg2);
	}
//document.writeln("test_copy_to_pos "+test_copy_to_pos+"<br>");
	test_output+=test_str.substring(test_start_pos, test_copy_to_pos);
//document.writeln("test_output "+test_output+"<br>");
	
	var test_org_text_to_process = test_str.substr(test_copy_to_pos, myArray[0].length);


for (x in toneMarksArray){
	for (i = 1; i < 5; i++){
		//alert(toneMarksArray[x][i]);
		//test_tranlow = test_tranlow.replaceAll(toneMarksArray[x][i],x);
		//if (test_org_text_to_process.search(new RegExp(toneMarksArray[x][i],"gm"))!= -1){
		if (test_org_text_to_process.indexOf((toneMarksArray[x][i]))!= -1){
			//test_org_text_to_process = test_org_text_to_process.replace(new RegExp(toneMarksArray[x][i],"gm"),x);
			var test_org_text_to_process_x = test_org_text_to_process.replace((toneMarksArray[x][i]),x);
			while (test_org_text_to_process != test_org_text_to_process_x){
				test_org_text_to_process = test_org_text_to_process_x;
				test_org_text_to_process_x = test_org_text_to_process.replace((toneMarksArray[x][i]),x);
			}
			test_org_text_to_process += i;
			break ;
		}
	}
	//alert("ere");
}

//document.writeln("test_org_text_to_process "+test_org_text_to_process+"<br>");
	test_output+=test_org_text_to_process;
//  document.writeln("Found " + myArray[0] +
//     ". Next match starts at " + test_reg.lastIndex + "<br>");
     ie_plus += test_reg.lastIndex ;
    test_start_pos =  test_copy_to_pos+myArray[0].length;
//document.writeln("test_start_pos "+test_start_pos+"<br> <br>");
  
}

test_output+=test_str.substring(test_start_pos, test_str.length);

//document.writeln(test_str+"<br>");
//document.writeln(test_output);

return test_output;
}

//document.writeln(pin_to_num(test_str));


function ping_to_num(ver){
	
	var spans = document.getElementsByTagName('span');
	//alert(spans.length);
	for (i = 0 ; i < spans.length; i++){
		var x = spans[i];
		//alert("jere");
		if (x.id == "pin_to_num"){
			//alert(x.childNodes.length);
			var done = true;
			var s,t;
			if (x.childNodes.length != 2) {
				done = false;
			}else {
				s = x.childNodes[0];
				t = x.childNodes[1];
				//alert(s.tagName +  s.id);
				if (s.tagName != 'SPAN' || s.id != '$billy_pin$') done = false;
				if (t.tagName != 'SPAN' || t.id != '$billy_num$') done = false;
			}
			/*
			var s = x.getElementById('$billy_pin$');
			var t = x.getElementById('$billy_num$');
			*/
			if (done){
				//alert("here");
				if (ver == 1){
					s.style.display="";
					t.style.display="none";
				} else if (ver == 2){
					s.style.display="none";
					t.style.display="";
				}
			} else {
				if (ver == 1){
					x.innerHTML="<span id='$billy_pin$'>"+x.innerHTML+"</span><span id='$billy_num$' style='display:none'>"+pin_to_num_js(x.innerHTML)+"</span>";
				} else if (ver == 2){
					x.innerHTML="<span id='$billy_pin$' style='display:none'>"+x.innerHTML+"</span><span id='$billy_num$'>"+pin_to_num_js(x.innerHTML)+"</span>";
				}				
				//alert(x.innerHTML);
				//alert(x.innerText);
				//var uu = ""+x.innerHTML;
				//var yy = pin_to_num_js(uu);
				//x.innerHTML=yy;
			}
			//alert(x);
		}//if == "pin_to_num"
	}//foreach
	
}
