// function to show Lookup Kantor Cabang Bank
function LookUp(_oKode, _oNama, _oFocus, _sURL, _oControl) {
	var vKode=document.getElementById(_oKode).value;
	var oSetting = "center:yes;resizable:no;status:no;dialogwidth:641px;dialogheight:440px;";
	var MyArgs = window.showModalDialog(_sURL + vKode, [], oSetting);
	AcceptData(MyArgs, _oKode, _oNama, _oFocus, _oControl);
}

function AcceptData(MyArgs, _oKode, _oNama, _oFocus, _oControl) {		
	if (MyArgs != null)	{	
		if (_oKode != '') {			
			document.getElementById(_oKode).value = MyArgs[0].toString();
		}
		if (_oNama != '') {			
			document.getElementById(_oNama).value = MyArgs[1].toString();
		}		
        document.getElementById(_oFocus).focus();        
	}
}

//<!-- 
function createRequestObject() {  
	var xmlhttp;
	try {
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e) {
			try {
				 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(f) {
				 xmlhttp=null;
			}
		}
		if(! xmlhttp&&typeof XMLHttpRequest!="undefined") {
			 xmlhttp=new XMLHttpRequest();
		}
	return  xmlhttp;
}

var http = createRequestObject(); 
var timeoutholder=null; 
var hasil;
var iWidth;
var iId;
var oControl;

function sndReq(search) { 
	search=escape(search); 
	try {
		http.open('get', 'Referensi.aspx?id='+iId+'&key='+search+'&width='+iWidth);  	
		http.onreadystatechange = handleResponse; 
		http.send(null);
	}
	catch(e) {}
	finally {}
}

function handleResponse() {
	try{
		if((http.readyState == 4)&& (http.status == 200)){
			var response = http.responseText;
			if (iId==1) response = replace(response,'txtHasil','tbNamaLembaga');
			if (iId==2) response = replace(response,'txtHasil','tbNamaUnit');
			if (iId==3) response = replace(response,'txtHasil','tbNamaSatker');
			if (iId==4) response = replace(response,'txtHasil','tbNamaMap');
			if (iId==5) response = replace(response,'txtHasil','tbNamaKppnPenerima');
			if (iId==6) response = replace(response,'txtHasil','tbNamaLokasi');
			if (iId==7)	response = replace(response,'txtHasil','txtNmCabang');
			if (iId==8) response = replace(response,'txtHasil','tbKPBCNm');
			if (iId==9) response = replace(response,'txtHasil','tbKPKNNm');
			if (iId==10) response = replace(response,'txtHasil','txtKodePosNMHide');
			
			document.getElementById(hasil).innerHTML = response; 
			
			if (iId==7){
				if (document.getElementById('txtNmCabang').value != ""){
					document.getElementById(oControl).value = document.getElementById('txtKdCabang').value ;
				}
				else {
					alert ("Kode cabang " + document.getElementById('txtKdCabang').value + " tidak ditemukan!") ;
					document.getElementById('txtKdCabang').value = "" ;
					document.getElementById(oControl).value = "" ;
				}
			}
			else if (iId==8){
				if (document.getElementById('tbKPBCNm').value != ""){
					document.getElementById(oControl).value = document.getElementById('tbKPBC').value ;
				}
				else {
					alert ("Kode KPBC " + document.getElementById('tbKPBC').value + " tidak ditemukan!") ;
					document.getElementById('tbKPBC').value = "" ;
					document.getElementById(oControl).value = "" ;
				}
			}
			else if (iId==9){
				if (document.getElementById('tbKPKNNm').value != ""){
					document.getElementById(oControl).value = document.getElementById('tbKPKN').value ;
				}
				else {
					alert ("Kode KPKN " + document.getElementById('tbKPKN').value + " tidak ditemukan!") ;
					document.getElementById('tbKPKN').value = "" ;
					document.getElementById(oControl).value = "" ;
				}
			}
			else if (iId==10){ //Ini Untuk Kodepos
			
				if (document.getElementById('txtKodePosNMHide').value != ""){
					var data=document.getElementById('txtKodePosNMHide').value;
					var kelurahan;  
					var kelurahan1;
					var kelurahan2; 
					var kelurahan3;
					var kecamatan;
					var kota;
					var propinsi;
					
										
					kelurahan=data.substring(0, data.indexOf(";"));
					data=data.substring(data.indexOf(";")+1,data.length );
					kecamatan=data.substring(0, data.indexOf(";"));
					data=data.substring(data.indexOf(";")+1,data.length );
					kota=data.substring(0, data.indexOf(";"));
					data=data.substring(data.indexOf(";")+1,data.length );
					propinsi=data;
					
					document.getElementById('txtKelurahan').value='';
					document.getElementById('txtKecamatan').value='';
					document.getElementById('txtKota').value='';
					document.getElementById('txtPropinsi').value='';
				
					if (kelurahan.indexOf("@") > 0)
					{
						kelurahan1=kelurahan.substring(0, kelurahan.indexOf("@"));
						kelurahan=kelurahan.substring(kelurahan.indexOf("@")+1,kelurahan.length );
						if (kelurahan.indexOf("@") > 0)
						{
							kelurahan2=kelurahan.substring(0, kelurahan.indexOf("@"));
							kelurahan=kelurahan.substring(kelurahan.indexOf("@")+1,kelurahan.length );
							if (kelurahan.indexOf("@") > 0)
							{
								kelurahan3=kelurahan.substring(0, kelurahan.indexOf("@"))	;	
							}
							else
							{
								kelurahan3 = kelurahan;
							}
						}
						else
						{
							kelurahan2=kelurahan;
						}	
						
						if (kelurahan2 != "")
						{
							//window.document.getElementById("cbokelurahan").disabled = false;
							//window.document.getElementById("txtKelurahan").style.visibility = "hidden";
							//window.document.getElementById("cbokelurahan").drop.options[1] = new Option(kelurahan1, '');
							//window.document.getElementById("cbokelurahan").drop.options[2] = new Option(kelurahan2, '');
							buildoption(kelurahan1, kelurahan2, kelurahan3);
						}
						else
						{
							//window.document.getElementById("cbokelurahan").disabled = true;
							//window.document.getElementById("txtKelurahan").style.visibility = "visible";
							divcbo.innerHTML = '';
						}
					}
					else
					{
						divcbo.innerHTML = '';
						//window.document.getElementById("cbokelurahan").disabled = true;
						//window.document.getElementById("txtKelurahan").style.visibility = "visible";
						document.getElementById('txtKelurahan').value=kelurahan;
					}
					
					document.getElementById('txtKecamatan').value=kecamatan;
					document.getElementById('txtKota').value=kota;
					document.getElementById('txtPropinsi').value=propinsi;
					
					
					
					document.getElementById(oControl).value = document.getElementById('txtKodePos').value ;
				}
				else {
					alert ("Kode Pos " + document.getElementById('txtKodePos').value + " tidak ditemukan!") ;
					document.getElementById('txtKodePos').value = "" ;
					document.getElementById(oControl).value = "" ;
				}
			}
		}
	}
	catch(e) {}
	finally {}
}


function buildoption(kel1, kel2, kel3)
{
	var sDrop;
	var aOptions = new Array();
	var aIsi = new Array(kel1,kel2,kel3)
	var i;

	sDrop = "<select id=\'cbokelurahan\' onchange=\'isikelurahan()\' class=\'text130\' style=\'WIDTH: 184px\'>";

	aOptions[0] = "<option value=\"" + 0 + "\">-- Pilih kelurahan --"  + "</option>";

	for(i=0; i<3; i++) {
		if (aIsi[i] == undefined) aIsi[i]='';
		aOptions[i+1] = "<option value=\"" + aIsi[i] + "\">" + aIsi[i] + "</option>";
	}

	divcbo.innerHTML = sDrop + aOptions.join("") + "</select>";
}

function getreadytolook(_oId, _oKey1, _oKey2, _oKey3, _oHasil, _oWidth, _oControl){
	var search;
	var search1=document.getElementById(_oKey1).value;
	var search2=document.getElementById(_oKey2).value;
	var search3=document.getElementById(_oKey3).value;
	var control=document.getElementById(_oControl).value;
	oControl = _oControl



	//if(navigator.appName.indexOf("Microsoft")!=-1){theKey=window.event.keyCode}
	//if (theKey == 13 ) {
	if (search1.length == document.getElementById(_oKey1).maxLength && search1 != control){
		search=search1+';'+search2+';'+search3
		hasil=_oHasil;
		iWidth=_oWidth;
		iId=_oId;
		if(timeoutholder!=null)window.clearTimeout(timeoutholder);
		timeoutholder=window.setTimeout("sndReq(\'"+search+"\');", 400);
	}
}

// -->
