function AutoComplete( oText, fGetString, fSelected, nMaxSize, tag)
{
	// public members
	this.nMaxSize = nMaxSize == null ? 10 : nMaxSize;
	this.onselected = fSelected;
	this.oTag = tag;
	this.getStrings = fGetString;

    // rearrange textbox area
    if( ! oText.tagName && oText.length ){// if boxes are many
        this.oText = oText[0];
        this.oTextArray = oText;
    } else {
        this.oText = oText;
        this.oTextArray = new Array(1); this.oTextArray[0] = oText;
    }
    // surrounding area
    var frameArea = document.createElement("table");
    frameArea.cellPadding = "0px"; frameArea.cellSpacing = "0px";
    document.body.appendChild( frameArea );
    var tr = frameArea.insertRow(0);//tBody.innerHTML = "<tr><td>FOO</td></tr>";
    var td = tr.insertCell(0);;
    frameArea.AutoComplete = this;
    frameArea.style.filter = "progid:DXImageTransform.Microsoft.Shadow(color=#676A68,direction=135,strength=4)";
    frameArea.style.position = "absolute";
    frameArea.style.border = "buttonshadow 1px solid";
    frameArea.style.top = ( AutoComplete.prototype._MeasureOffsetTop(this.oTextArray[this.oTextArray.length-1]) + this.oTextArray[this.oTextArray.length-1].offsetHeight - 1 + document.body.offsetTop ) + "px";
    frameArea.style.left = ( AutoComplete.prototype._MeasureOffsetLeft(this.oTextArray[0]) +  document.body.offsetLeft ) + "px" ;
    frameArea.style.zIndex = 10000;
    frameArea.style.visibility = "hidden";

    frameArea.onmouseover = function() {  this.AutoComplete.nowOnOver = true; }
    frameArea.onmouseout = function(){ this.AutoComplete.nowOnOver = false; }
    frameArea.onblur = function(){ if( !this.AutoComplete.nowOnOver) this.AutoComplete.showSelection(false); }
    
    // create dropdown area
    var area = document.createElement("div");
    td.appendChild( area );
    area.AutoComplete = this;
    area.onblur = frameArea.onblur;
    area.style.backgroundColor = "white";
    area.style.overflow = "auto";
    area.style.overflowY = "auto";
    area.style.overflowX = "hidden";
    area.style.fontSize = this.oTextArray[0].style.fontSize;
    area.style.fontStyle = this.oTextArray[0].style.fontStyle;
    area.style.cursor = "default";

    this.selectionFrame = frameArea;
    this.selectionArea = area;

    var o = document.createElement("table");
    o.border = "0px"; o.cellPadding = "0px"; o.cellSpacing = "0px";
    o.style.width = ( this.oTextArray[0].offsetWidth - 2 )  + "px";//"100%";//(area.offsetWidth-10) + "px";
    //o.onblur = AutoComplete.prototype.onblur;
    //o.onmouseover = function() { this.AutoComplete.nowOnOver = true; }
    //o.onmouseout = function(){ this.AutoComplete.nowOnOver = false; }
	//this.previousText = oText.value;
	//area.appendChild( document.createElement("tr") ).appendChild(document.createElement("td")).appendChild(o);
    area.appendChild(o);
	this.oDiv = o;
	this.selectedIndex = -1;
	
	var i;
	for( i=0; i<this.oTextArray.length; i++ ){
	    // attach handlers to the text-box
	    this.oTextArray[i].AutoComplete = this;
	    if( this.oTextArray[i].tagName.toLowerCase() == "input" ){
	        this.oTextArray[i].autocomplete = "off";
	    }
	    this.oTextArray[i].onkeydown = this.onItemKeyDown;
	    
	    //oText.onkeypress = this.onItemKeyPress;
	    this.oTextArray[i].onkeyup = this.onchange;//function(event){ this.AutoComplete.onchange(event); };//this.onchange;// function (event) { this.AutoComplete.onchange.call(this, event); }
	    this.oTextArray[i].onblur = this.onblurFromTextBox;//function () { }	
    }
}

AutoComplete.prototype.onblurFromTextBox = function()
{
    var ac = this.AutoComplete ? this.AutoComplete : this;
    if( ! ac.nowOnOver ) ac.showSelection(false); 
}

AutoComplete.prototype._MeasureOffsetTop = function(obj)
{
 var curtop = 0;
 while (obj.offsetParent != null)
 {
        curtop += obj.offsetTop - obj.scrollTop;
        obj = obj.offsetParent;
 }
 return curtop;
}

AutoComplete.prototype._MeasureOffsetLeft = function(obj)
{
 var curleft = 0;
 while (obj.offsetParent != null)
 {
 curleft += obj.offsetLeft - obj.scrollLeft;
 obj = obj.offsetParent;
 }
 return curleft;
}

AutoComplete.prototype.showSelection = function ( show )
{
    if( show )
    {
        this.selectionFrame.style.top = ( AutoComplete.prototype._MeasureOffsetTop(this.oTextArray[this.oTextArray.length-1]) + this.oTextArray[this.oTextArray.length-1].offsetHeight - 1 + document.body.offsetTop ) + "px";
        this.selectionFrame.style.left = ( AutoComplete.prototype._MeasureOffsetLeft(this.oTextArray[0]) +  document.body.offsetLeft ) + "px" ;
    }
    this.selectionFrame.style.visibility = show ? "visible" : "hidden";
}
AutoComplete.prototype.isSelectionVisible = function ()
{
    return this.selectionFrame.style.visibility== "hidden" ? false : true;
}

AutoComplete.prototype.selectItem = function( idx )
{
	var e;
	var nRows = this.oDiv.rows.length;
	if( 0 <= this.selectedIndex && this.selectedIndex < nRows ){
		e = this.oDiv.rows[this.selectedIndex];//.cells[0];
		e.style.color = "windowtext";
		e.style.backgroundColor = "";
	}
	if( 0 <= idx && idx < nRows  ){
	    var rowTo = this.oDiv.rows[idx];
		e = rowTo;//rowTo.cells[0];
		e.style.color = "captiontext";
		e.style.backgroundColor = "highlight";
		this.selectedIndex = idx;
		//e.focus();
	    if ( e.offsetTop + e.offsetHeight > this.selectionArea.scrollTop + this.selectionArea.offsetHeight ){
	        this.selectionArea.scrollTop += rowTo.offsetHeight;
	    } else if ( e.offsetTop < this.selectionArea.scrollTop  ){
	        this.selectionArea.scrollTop -= rowTo.offsetHeight;
	    }
	} else {
		this.selectedIndex = -1;
    }
}

AutoComplete.prototype.selectMoveDown = function()
{
    if( this.selectedIndex < this.oDiv.rows.length - 1 )
        this.selectItem( this.selectedIndex + 1 );
}

AutoComplete.prototype.selectMoveUp = function()
{
    if( this.selectedIndex > 0 )
        this.selectItem( this.selectedIndex - 1 );
}

AutoComplete.prototype.onItemKeyDown = function(event)
{
	if( event == null ) event = window.event;
    if( event.keyCode == 38 ){// UP
        this.AutoComplete.selectMoveUp();
       event.resultValue = false;
    } else if( event.keyCode == 40 ){// DOWN
    	if( !this.AutoComplete.isSelectionVisible() ){
    		this.AutoComplete.openSelection(true);
    	} else
    		this.AutoComplete.selectMoveDown();
        event.resultValue = false;
    } else if( event.keyCode == 27 ){// ESC
        if( this.AutoComplete.isSelectionVisible() ){
            this.AutoComplete.showSelection(false);
        }
    } else if( event.keyCode == 13 && this.AutoComplete.isSelectionVisible() ){// return
        event.cancelBubble = true;
        event.returnValue = false;
        if( this.AutoComplete.selectedIndex >= 0 )
        {
        //var save = this.AutoComplete.oText.onkeyup;
        //this.AutoComplete.oText.onkeyup = null;
            this.AutoComplete.onItemDetermin( this.AutoComplete.oDiv.rows[ this.AutoComplete.selectedIndex ].cells[0], false );
            //this.AutoComplete.oText.onkeyup = save;
            //this.AutoComplete.oDiv.rows[ this.AutoComplete.selectedIndex ].cells[0].onmouseup();
        }
        return false;
    }
}

AutoComplete.prototype.onItemDetermin = function( oItem, moveFocus )
{
    var t;
    if( oItem.value ) t = oItem.value;
    else t = oItem.innerHTML;
    if( oItem.AutoComplete.onselected != null ){
        t = this.onselected( oItem );
    }
	if( typeof(t)!="undefined" && t != false ){
        this.previousText = t;
	    this.oText.value = t;
	}
	this.showSelection( false );
	if( moveFocus == false ) return;
    this.oText.focus();
}

AutoComplete.prototype.onDivMouseDown = function( moveFocus )
{
    this.AutoComplete.onItemDetermin( this, moveFocus );
}

AutoComplete.prototype.onDivMouseOver = function()
{
	this.AutoComplete.selectItem( this.indexNumber );
}

AutoComplete.prototype.openSelection = function( forceOpen )
{
	var txt = ""; var i;
	for( i=0; i< this.oTextArray.length; i++ ){
	    var ob = this.oTextArray[i];
	    if( ob.tagName.toLowerCase() == "select" && ob.selectedIndex>=0 ){ txt += ob.options[ ob.selectedIndex ].value; }
	    else { txt += ob.value; }
	}
	if( this.previousText == txt && (forceOpen == null || forceOpen == false ) ){
	    return;
	}
	//alert(  this.updating  + "---" + this.previousText + ":::" + txt + ":::" + forceOpen);
	this.previousText = txt;
	var aaStr;
	if( typeof(this.getStrings)=="function" ){
		aaStr = this.getStrings(txt );
	} else {
		aaStr = this.getStrings;
	}
	if( aaStr != null )
	    this.setOptions( aaStr );
}

AutoComplete.prototype.onchange = function(event)
{
	if( event == null ) event = window.event;
    if( event.keyCode == 13) return;
    //this.AutoComplete.openSelection.call(this.AutoComplete, false);
    this.AutoComplete.openSelection(false);
}

AutoComplete.prototype.setOptions = function( aStr )
{
	if( aStr.length > 0 ){
		while ( this.oDiv.childNodes.length > 0 /*aStr.length */){
			this.oDiv.removeChild(this.oDiv.lastChild);
		}
		this.selectItem( -1 );
		this.oDiv.scrollTop = 0;
		// add each string to the popup-div
		var i, n = aStr.length;
		var startingTime = (new Date()).getTime();
		for ( i = 0; i < n ; i++ )
		{
		    if( this.maxLatency != null ){
		        if( (new Date()).getTime() - startingTime > this.maxLatency ) break;
		    }
			var oRow;
			if( this.oDiv.childNodes.length <= i ){
				if( this.oDiv.insertRow ){ // for IE
				    oRow = this.oDiv.insertRow( this.oDiv.rows.length );
				} else { // for FireFox
				    oRow = document.createElement("TR");
				    //oDiv = document.createElement("TD");
				    this.oDiv.appendChild(oRow);
				    //this.oDiv.appendChild( oRow );
				}
			} else {
			    oRow = this.oDiv.rows[i];
			}
			oRow.style.lineHeight = "normal";
			var ar;
			if( aStr[i].push ){
			    ar = aStr[i];
			} else {
			    ar = new Array( aStr[i] );
			}
			var ii;
		    for( ii=0; ii<ar.length; ii++ ){
		        var oCell = oRow.insertCell( oRow.cells.length );
				oCell.noWrap = true;
		        var iToAdd = ar[ii];
			    if( typeof( iToAdd ) == "object" ){
			        if( iToAdd.html )
			            oCell.innerHTML = iToAdd.html;
			        else if( iToAdd.text )
			            oCell.innerHTML = iToAdd.text;
			        if( iToAdd.value )
			            oCell.value = iToAdd.value;
			    } else {
			        oCell.innerHTML = iToAdd;
			    }
			    oCell.onmouseup = this.onDivMouseDown;
			    oCell.onmouseover = this.onDivMouseOver;
			    oCell.onkeydown = this.onItemKeyDown;
			    oCell.AutoComplete = this;
			    oCell.indexNumber = i;
		    }
		}
		if( i > 10 ){
		    this.selectionArea.style.height = (( this.oDiv.rows[8].offsetTop ) + "px");}
		else  { this.selectionArea.style.height = (( this.oDiv.offsetHeight ) + "px" ); }
        if( document.all ){// only for IE
            var ii; var w = this.oDiv.offsetWidth;
            this.selectionFrame.style.width = this.oDiv.offsetWidth + "px";
            //this.oDiv.style.width = "100%";
        }
		this.showSelection( true );
		//alert(this.selectionArea.style.height);
	}
	else // hide the popup-div
	{
	    this.showSelection( false );
	}
}


var YZipCodeServiceUrl = "YZipCode.asmx";
var YZipCodeBaseUrl = "";
var YZipCodeCrossDomain = null;
var YZipCodeDelimiter = "-";
var YZipCodeShowIndicator = true;
var YZipCodeIndicatorImageUrl = null;
var YZipCodeIndicatorCompleteImageUrl = null;
var YZipCodeIndicatorErrorImageUrl = null;
var YZipCodeIndicatorProgressImageUrl = null;
var YZipCodeMaxLatency = 250;
var YZipCodeProxyFrame = null;
var YZipCodeCrossDomainOnProxy = null;
var YZipCodeLHolder = false;
var YZipCode_savedWindowOnload = window.onload;

window.onload = function(){
    // analyze current domain 
    if( YZipCodeBaseUrl.indexOf( "http://" )>=0 || YZipCodeBaseUrl.indexOf( "https://" )>=0 )
    {
        var i = YZipCodeBaseUrl.indexOf( "://" );
        var td = YZipCodeBaseUrl.substring( i+3 );
        i = td.indexOf("/"); if( i>=0 ) td = td.substring( 0, i );
        i = td.indexOf(":"); if( i>=0 ) td = td.substring( 0, i );
        if( document.domain && document.domain != td )// this is cross domain problem!
        {
            var dom = document.domain;
            domArray = dom.split(".").reverse();
            tdArray = td.split(".").reverse();
            var stDomain = "";
            for( i=0; i<domArray.length && i<tdArray.length; i++ ){
                if( domArray[i] != tdArray[i] ) break;
                if( stDomain != "" ) stDomain = "." + stDomain;
                stDomain = domArray[i] + stDomain;
            }
            YZipCodeCrossDomain = stDomain;
        }
    }
    if( YZipCodeCrossDomain != null && YZipCodeCrossDomain != "" ){
        document.domain = YZipCodeCrossDomain;
        YZipCodeProxyFrame = document.createElement('iframe');
        if( YZipCodeProxyFrame != null ){
            document.body.appendChild(YZipCodeProxyFrame);
            YZipCodeProxyFrame.width = 0; YZipCodeProxyFrame .height=0;
            YZipCodeProxyFrame.frameBorder = "0";
            YZipCodeProxyFrame.id = "YZipCodeProxyFrame";
            YZipCodeProxyFrame.src = YZipCodeBaseUrl + "YZipCodeProxy.aspx?domain=" + YZipCodeCrossDomain;
        }
    }
    if( typeof(YZipCode_savedWindowOnload) == "function" ) YZipCode_savedWindowOnload();
}

function YZipCodeLookup( keyword, zipcodeControl, addressControl, addressKanaControl, addressPlaceControl, addressPlaceKanaControl, pobControl )
{
    if( window.YZipCodeLookup_proxy != null ){
        return window.YZipCodeLookup_proxy.apply( this, arguments );
    }
	var turl = YZipCodeBaseUrl + "YZipCode.ashx" + "?Delimiter=1";
	if( document.charset && document.charset != "") turl += "&encoding=" + document.charset;
	if( YZipCodeCrossDomainOnProxy != null ) turl += "&domain=" + YZipCodeCrossDomainOnProxy;
	if( YZipCodeCrossDomain != null ) turl += "&domain=" + YZipCodeCrossDomain;
	
	if( typeof( encodeURI ) == "function" ){
		turl += "&LookupFor=" + escape(keyword);
	} else {
		turl += "&LookupFor=" + escape(keyword);
	}
	var controls = new Array();
	for( i=1; i<arguments.length; i++ )
	    controls[i-1] = arguments[i];
  	namesToControlArrays( controls );

	if( window.showModalDialog ){ // MODAL DIALOG VERSION
		var yzipcode_retval = window.showModalDialog(turl, 0,  "dialogWidth:600px;dialogHeight:260px;center:1;edge:raised;status:0;" );
		FillZipCodeForm( yzipcode_retval, controls );
	} else {
		var w = window.open( turl , "_zipcode_search","height=260,directories=0,scrollbars=no,status=0,toolbar=0" );
		w.focus();
		w.parameters = controls;
		w.onZipFormClose = FillZipCodeFormCallback;//new Function( "result, w", 'opener.FillZipCodeFormCallback("HOO" )' );
		//w.onZipFormClose();
	}
}

function FillZipCodeFormCallback( result, w )
{
    FillZipCodeForm( result, w.parameters );
}

function FillZipCodeForm( result, controls )
{
	if( typeof( result ) != "string" ) return;
	var zipcodeControl = controls[0];
	var addressControl = controls[1];
	var ar = result.split( ";" );
	// 郵便番号の処理
	if( zipcodeControl != null && ar[0] != "" ){
	    if( zipcodeControl.length ){
		    zipcodeControl[0].value = ar[0].substr(0,3)
		    zipcodeControl[1].value = ar[0].substr(3)
	    } else {
    	    //zipcodeControl.AutoComplete.previousText = ar[0];
	        zipcodeControl.value = ar[0].substr(0,3) + ( ar[0].length > 3 ? YZipCodeDelimiter + ar[0].substr(3) : "" );
	    }
	}
	// 住所部分の処理
	sar = ar[1].split(" ");
	if( ar.length >= 7 ) sar[ sar.length ] = ar[6];
	if( addressControl != null ){
	    if( addressControl.length ){
	        if( addressControl[0].options ){// 県名がSELECTの場合
	            var sobj = addressControl[0];
	            for( i=0; i < sobj.options.length; i++ ){
	                //alert( sar[0] + ";;;" + sobj.options[i].value ) ;
		            if( sobj.options[i].value == sar[0] ){
			            sobj.selectedIndex = i;
			            break;
		            } else if( sobj.options[i].value != ""){
		                if( sar[0].indexOf( sobj.options[i].value ) == 0 ){
		                    //sar.push( sar[0].substring( sobj.options[i].value.length ));
		                    sar[ sar.length ] = sar[0].substring( sobj.options[i].value.length );
			                sobj.selectedIndex = i;
			                break;
		                } else if( sar[0].indexOf( sobj.options[i].text ) == 0 ){
		                    //sar.push( sar[0].substring( sobj.options[i].text.length ));
		                    sar[sar.length] = sar[0].substring( sobj.options[i].text.length );
			                sobj.selectedIndex = i;
			                break;
		                }
		            }
	            }
	        } else {
	            addressControl[0].value = sar[0];
	        }
            sar[0]="";//sar.shift();
	        addressControl[1].value = sar.join("");
	    } else {
		    addressControl.value = sar.join("");
	    }
	}
	// その他の情報
	for( i=2; i<controls.length && i<ar.length; i++ )
	{
	    if( controls[i] != null )
	        controls[i].value = ar[i];
	}
}

function formatPostCode( code )
{
    var a = code.replace('-','' );
    if( a.length > 3 )
        a = a.substring(0,3) + "-" + a.substring(3);
    return a;
}
/*----------------------------------
 -----------------------------------*/
function namesToControlArrays( ar )
{
    var i, ii;
    for( i=0; i<ar.length; i++ ){
        if( ar[i] == null )
        {}
        else if( typeof(ar[i]) == "string" )
        {
            if( document.getElementById ){
                ar[i] = document.getElementById(ar[i]);
            } else {
                ar[i] = document.all[ar[i]];
            }
        }  else if( typeof( ar[i].length ) != "undefined" ){
            namesToControlArrays(ar[i]);
        }
    }
}

function YZipCodeAutoComplete( oText, zipcodeControl, addressControl, addressKanaControl, addressPlaceControl, addressPlaceKanaControl, pobControl )
{
	this.controls = new Array();
	if( typeof(document.getElementById) == "undefined" ) return; // NOT SUPPORTED IE4 or former

	namesToControlArrays( arguments );
	for( i=1; i<arguments.length; i++ )
	{
	    if( arguments[i] != null ){ this.controls[i-1] = arguments[i] ; }
	}
	    
	
    var ac = new AutoComplete( oText );
    ac.maxLatency = YZipCodeMaxLatency;
    ac.onselected = this.onselected;

    if( YZipCodeLHolder != true )
    {
	    var yokinsoft = document.createElement("div");
	    yokinsoft.align = "center";
	    yokinsoft.style.cursor = "hand";
	    yokinsoft.onclick = function() { window.open("http://www.yo-ki.com/software/yzipcode/", "_blank" ); ac.oTextArray[0].focus();}
	    yokinsoft.style.backgroundColor = "black";
	    yokinsoft.style.fontSize = "xx-small";
	    yokinsoft.style.fontFamily = "helvetica";
	    yokinsoft.style.color = "white";
	    yokinsoft.innerHTML = "&#38525;&#27671;&#12395;&#37109;&#20415;&#30058;&#21495;&#26908;&#32034; &copy; 2006-2008 Yokinsoft";
	    var td = ac.selectionFrame.insertRow(-1).insertCell(0);
	    td.noWrap = true; td.appendChild(yokinsoft);
	}
	
    //this.savedOnblur = ac.oTextArray[0].onblur;
    ac.oTextArray[0].onblur = this.onblur;
    //this.AutoComplete = ac;
    ac.getStrings = this.getStrings;
    ac.YZipCodeAutoCompleteObject = this;
    if( YZipCodeShowIndicator ){
        if( YZipCodeIndicatorImageUrl != null )
        {
            this.indicator = document.createElement("img");
            //this.indicator.style.position = "relative"; this.indicator.style.top = "-0.5em";
            this.indicator.align = "top";
            this.indicator.style.cursor = "hand";
            this.indicator.src = YZipCodeIndicatorErrorImageUrl;
            this.indicator.alt = "郵便番号検索...";
            this.indicator.onclick = function() { if( !ac.isSelectionVisible() ){ ac.openSelection(true); }}
            var to = ac.oTextArray[ ac.oTextArray.length - 1];
            to.parentNode.insertBefore( this.indicator, to.nextSibling ); //"<sup><font color='#EEEEEE'><b>&#12306;</b></font></sup>" );

            this.indicator.showProgress = function(){ this.style.visibility = "visible"; this.src = YZipCodeIndicatorProgressImageUrl; };
            this.indicator.showComplete = function(){ this.style.visibility = "visible";  this.src = YZipCodeIndicatorCompleteImageUrl==null ? YZipCodeIndicatorImageUrl : YZipCodeIndicatorCompleteImageUrl;};
            this.indicator.hide = function(){ this.style.visibility = "hidden"; };
            this.indicator.showError = function(){ this.style.visibility = "visible";  this.src = YZipCodeIndicatorErrorImageUrl; };
        } else {
            this.indicator = document.createElement("font");
            this.indicator.onclick = function() { if( !ac.isSelectionVisible() ){ ac.openSelection(true); }}
            this.indicator.style.position = "relative"; this.indicator.style.top = "-0.5em";
            this.indicator.style.cursor = "hand";
            this.indicator.color= "gray";
            this.indicator.innerHTML = "<sup><b title='&#26908;&#32034;&#20013;...'>&#12306;</b></sup>";
            var to = ac.oTextArray[ ac.oTextArray.length - 1];
            to.parentNode.insertBefore( this.indicator, to.nextSibling ); //"<sup><font color='#EEEEEE'><b>&#12306;</b></font></sup>" );

            this.indicator.showProgress = function(){ this.style.visibility = "visible"; this.style.color = "red";};
            this.indicator.showComplete = function(){ this.style.visibility = "visible"; this.style.color = "gray";};
            this.indicator.hide = function(){ this.style.visibility = "hidden"; };
            this.indicator.showError = function(){ this.style.color = "gray"; };
        }
	}

}

YZipCodeAutoComplete.prototype.onblur = function()
{
    var o = this.AutoComplete.YZipCodeAutoCompleteObject;
	if( o.httpRequest ){
	     o.httpRequest.abort();
    }
    this.AutoComplete.onblurFromTextBox();
    //o.savedOnblur();//.call(this);
}

YZipCodeAutoComplete.prototype.onselected = function ( o )
{
    if( this.YZipCodeAutoCompleteObject.controls.length == 0 ){
        var a = o.value.split(";");
        if( a.length > 1 )
            return a[1];
        return false;
    }
    FillZipCodeForm( o.value, this.YZipCodeAutoCompleteObject.controls );
    return false;
}

function NSResolver(prefix) {
  if(prefix == 'html') {
    return 'http://www.w3.org/1999/xhtml';
  }
  else if(prefix == 'mathml') {
    return 'http://www.w3.org/1998/Math/MathML'
  }
  else if(prefix == 'soap') {
    return 'http://schemas.xmlsoap.org/soap/envelope/'
  }
  else  {
  //this shouldn't ever happen
    return null;
  }
}

YZipCodeAutoComplete.prototype.onReadyStateChange = function (ac)
{
    if( typeof(this.indicator) != "undefined" )
    {
        //this.indicator.style.visibility = "visible";
        this.indicator.showProgress();
    }
    var req = YZipCodeAutoComplete.prototype.httpRequest;//this.YZipCodeAutoCompleteObject.httpRequest;
    if (req != null && req.readyState == 4) {
        //var ac = req.AutoComplete;
        // only if "OK"
        if (req.status == 200) {
            var xml = req.responseXML;
            var ar = new Array();
            var i,j;
            var nar; var node; var index = 0;
            var bType = typeof(xml.evaluate) != "undefined" ? 0 : typeof(xml.selectNodes)!="undefined" ? 1 : 2;
            if( bType == 0 ){
                nar = xml.evaluate("//area",xml.documentElement, NSResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE , null );
                node = nar.iterateNext();
            } else if( bType == 1 ){// MSXML
                nar = xml.selectNodes( "/soap:Envelope/soap:Body/LookupNextLevelAddressResponse/LookupNextLevelAddressResult/result/area" );
                //nar = xml.getElementsByTagName("area");//selectNodes( "/soap:Envelope/soap:Body/LookupNextLevelAddressResponse/LookupNextLevelAddressResult/result/area" );
                node = nar.nextNode();
            } else if( bType == 2 ){
                nar = xml.getElementsByTagName("area");//selectNodes( "/soap:Envelope/soap:Body/LookupNextLevelAddressResponse/LookupNextLevelAddressResult/result/area" );
                node = nar.length > 0 ? nar[index++] : null;
            }
            var names = new Array("post-code","name","name-kana","place-name","place-name-kana","place-POB","extra");
            while( node != null ){
                var vnames = new Array( names.length );
                for( j=0; j<names.length; j++ ){
                    vnames[j] = node.getAttribute( names[j] );
                }
                var vname = node.getAttribute("name");
                var postcode = node.getAttribute("post-code");
                var place = node.getAttribute("place-name");
                var o = new Object();
                o.html = "<div  style='margin:1px;'><font size='-1'>"
                     + ( postcode !=null ? "<font color='red'><b>&#12306;</b></font><b>" + formatPostCode(postcode) + "</b><br/>&nbsp;&nbsp;&nbsp;&nbsp;" : "" )  + vname + ""
                     + ( place == null ? "" : "<br/>&nbsp;&nbsp;&nbsp;&nbsp;<font color='blue'>" + place + "</font>" ) + "</font></div>";
                o.value = vnames.join(";");
                ar[ ar.length ] = o;
                if( bType == 0 ){
                    node = nar.iterateNext();
                } else if( bType==1 ){
                    node = nar.nextNode();
                } else {
                    node = nar.length > index ? nar[index++] : null;
                }
            }
            ac.setOptions( ar );
            // ...processing statements go here...
            if( typeof(this.indicator) != "undefined" ){ this.indicator.showComplete(); }

        } else {
            if( typeof(this.indicator) != "undefined" ){ this.indicator.showError(); } // this.indicator.style.color = "gray";

            //alert("There was a problem retrieving the XML data:\n" + req.status + ", " + req.statusText);
        }
    }
}

YZipCodeAutoComplete.prototype.httpRequest = null;

YZipCodeAutoComplete.prototype.newHttpRequest = function ()
{
    var req = null;
    if(window.XMLHttpRequest) {
	    req = new XMLHttpRequest();
    } else if(window.ActiveXObject) {
    	//req = new ActiveXObject("Msxml2.XMLHTTP");
    	req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return req;
}


YZipCodeAutoComplete.prototype.getStrings = function ( txt )
{
    var ac = this;
    var req = null;
    // if proxy is available
    if( window.YZipCodeAutoComplete_getStrings_proxy ){
        return YZipCodeAutoComplete_getStrings_proxy( this, txt );
    }
    //
	if( YZipCodeAutoComplete.prototype.httpRequest != null ){
	     req = YZipCodeAutoComplete.prototype.httpRequest;
	     if( req.readyState != 0 )
	     {
	        req.abort();
	     }
	     //req.abort();
    }
    if( req == null ){
        req = YZipCodeAutoComplete.prototype.newHttpRequest(); 
    }
	if(req != null ) {
	    var url = YZipCodeBaseUrl + YZipCodeServiceUrl;
	    YZipCodeAutoComplete.prototype.httpRequest = req;
	    //req.AutoComplete = ac;
		req.onreadystatechange = function(){ eval('try{ ac.YZipCodeAutoCompleteObject.onReadyStateChange(ac);}catch(e){ req.abort(); ac.YZipCodeAutoCompleteObject.indicator.showError();}'); };// function(){ o.onReadyStateChange.call( ac ); }
		req.open("POST", url, true);
		req.setRequestHeader("Content-Type", "text/xml; charset=utf-8" );
		req.setRequestHeader("SOAPAction", "http://www.yo-ki.com/software/yzipcode/LookupNextLevelAddress" );
		var body = '<?xml version="1.0" encoding="utf-8"?>'
                + '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
                + '<soap:Body>'
                + '<LookupNextLevelAddress xmlns="http://www.yo-ki.com/software/yzipcode">'
                + '<keyword>' + txt + '</keyword></LookupNextLevelAddress>'
                + '</soap:Body></soap:Envelope>';
                
		req.send( body );
	}
    return null;
}

YZipCodeBaseUrl = 'http://www.yo-ki.com/software/yzipcode/';YZipCodeLHolder = true;
