﻿// scan &#1111;
function scan_unicode_ReplaceAllTextBox_AToU()
{
	var f = document.forms[0];
	if (f == null)return;
	var t = null;
	var newValue = null;
	//alert(f.elements.length);
	for (var i=0; i < f.elements.length; i++)
	{
		t = f.elements[i];
		if (t.tagName.toLowerCase() == 'input'
			&& t.type == 'text')
		{
			newValue = scan_unicode_U2A(t.value);
			if (newValue != null)
				t.value = newValue;
		}
		else if(t.tagName.toLowerCase() == 'textarea')
		{
		    newValue = scan_unicode_U2A(t.value);
			if (newValue != null)
				t.value = newValue;
		}
		else if(t.tagName.toLowerCase() == 'select')
		{
		   for (var j=0; j < t.length; j++)
		    {
		        newValue = scan_unicode_U2A(t.options[j].text);
		        
			    if (newValue != null)
				    t.options[j].text = newValue;
			}
		}
	}
}

function scan_unicode_U2A(text) { //Unicode -> ASCII转换
	var code = text.match(/&#(\d+);/g);
	if (code == null) { return null; }
	return text.replace(/&#(\d+);/g, function(s0, s1)
		{
			return String.fromCharCode(s1.replace(/[&#;]/g, ''));
		}
	);
}

scan_unicode_ReplaceAllTextBox_AToU();

