		var page = 1;
	   	function showSucForInst(selObj, page) {
	   	  fetchSelectCityForInstit();
	   	  $('#loader_inst').show();
		  $('#cautare').hide();
		  
		  $.ajax({
			  url: "/institutii/getSucForInst",
			  data: "id_parent=" + $('#id_parent').val() + "&city="+ $('#city').val() + "&page=" + page ,			  
			  success: function (msg) {
			  			    
			    respArr = msg.split('***');
			    msg = respArr[0];
			    nrTotPag = respArr[1];			  	
			  	msgArr = msg.split("||");
			  	putOnMap(msgArr);
			  	putOnPage(msgArr, nrTotPag, page);
			  	
			  	$('#loader_inst').hide();
			  	
			  	if ( $('#id_parent option:selected').text() != "" && $('#city option:selected').text() != "") 		  	
			  	$('#cautare').html($('#id_parent option:selected').text().substring(0,32) + ' din ' + $('#city option:selected').text());
			  	else $('#cautare').html('Nu exista nici o adresa.');
			  			  	
			  	$('#cautare').show();		  	
			  }
		  });
	    }
	   	
		function fetchSelectCityForInstit() {
			var options = "";
			
		   	$('#loader_inst').show();
			$('#cautare').hide();
						
			$.ajax({
				  url: "/institutii/getCitysForInst",
				  data: "id_parent=" + $('#id_parent').val(),			  
				  success: function (msg) {
				      msgArrCity = msg.split('||');

				      var index = 0;
				      var selClass = ''; 
				      
				      for (index in msgArrCity) { 
				    	  
						  arrCity = msgArrCity[index].split('|');
						  
						  selClass = arrCity[0] == $("#city").val() ? ' selected ' : '';
						  
						  if (arrCity[0] && arrCity[1]) 
				          options += '<option value="' + arrCity[0] + '" ' + selClass + '>' + arrCity[1] + '</option>';
				      }
				      
				      $("#city").html(options);

				  	  $('#loader_inst').hide();		  				  	
				  	  $('#cautare').show();
		  	
				  }
			  });
		}	    

	    function showSelectedInst(id) {
	    	$('#id_parent').val(id);
		    var obj = {};
		    obj.value = id;
		    showSucForInst(obj, 1);
		}
	   
	    
		function setSucPage(pageNr) {
			showSucForInst(document.getElementById('id_parent'), pageNr);
		}

	    function putOnMap(msgArr) {
	    	map.removeMarkersAll();		    
	    	var c = 0;
			for (inst in msgArr) {
				instDetArr = msgArr[inst].split('|');
				
				if ($.trim(instDetArr[0]).length > 0 && instDetArr[0].match(/^[0-9,\.\s]+$/g) &&
					$.trim(instDetArr[1]).length > 0 && instDetArr[1].match(/^[0-9,\.\s]+$/g )) {
					
						lat = instDetArr[0];
						lon = instDetArr[1];						
						title_inst = instDetArr[3];		
						
						//map = new YMap(document.getElementById('map'),YAHOO_MAP_REG);						
						myGeoPoint = new YGeoPoint(lat, lon);						

						var adresa =  '<div class="suc_adresa">' + instDetArr[4] + '</div>';
					 										
						printMarker(myGeoPoint,'<div id=map_divover style="padding:3px;"><span id="nume"><strong>' + title_inst + '</strong></span></div>', '<div id=map_divexpand_' +instDetArr[2] + '  style="margin-left:5px;"><span id="nume">&nbsp;&nbsp;&nbsp;<br /><strong>' + title_inst + '</strong>' + adresa + '&nbsp;&nbsp;&nbsp;<a href="/institutii_financiare/sucursale_si_agentii/' + instDetArr[5] + '.html" title_inst="title_inst" target="_parent" class="suc_selected">Vezi detalii</a><br /><br /></div>','blue', instDetArr[2]);

						if (c == 0) {							
							my_marker = map.getMarkerObject(instDetArr[2]);
							my_marker.openAutoExpand();
							map.drawZoomAndCenter(myGeoPoint , 6);							
						}

						c++;
											 
				}			
			}

		}

		function putOnPage(msgArr, nrTotPag, page) {
			$('#listing_sucursale').html('');
			var instDetArr, c = 0;
			for (inst in msgArr) {
				instDetArr = msgArr[inst].split('|');
				cntArr = instDetArr.length;
				credit = instDetArr[cntArr-1];
				instSlug = instDetArr[cntArr-2];
				
					//instDetArr[(instDetArr.length)-2] != 'undefined' || instDetArr[(instDetArr.length)-1] != 'undefined'
				
				if ($.trim(instDetArr[0]).length > 0 && instDetArr[0].match(/^[0-9,\.\s]+$/g) &&
					$.trim(instDetArr[1]).length > 0 && instDetArr[1].match(/^[0-9,\.\s]+$/g )) {
					
					if (c == 0) {
						$('#listing_sucursale').html(
								$('#listing_sucursale').html() + '<div class="suc_selected" id="suc_' + instDetArr[2] +'" >' + instDetArr[3] + '&nbsp;&nbsp;&nbsp;<br /><a href="/' + credit + '/' + instSlug + '/' + instDetArr[5] + '_sucursala.html" class="instLink" target="_parent">Detalii</a>&nbsp;&nbsp;&nbsp;<a href="#" class="instLink" onClick="goToInst(' + instDetArr[0] +','+ instDetArr[1] + ',' + instDetArr[2] + ');return false;">Vezi pe harta</a></div>'
						);
					} else {
						$('#listing_sucursale').html(
								$('#listing_sucursale').html() + '<div class="suc_lista" id="suc_' + instDetArr[2] +'" >' + instDetArr[3] + '&nbsp;&nbsp;&nbsp;<br /><a href="/' + credit + '/' + instSlug + '/' + instDetArr[5] + '_sucursala.html" class="instLink" target="_parent">Detalii</a>&nbsp;&nbsp;&nbsp;<a href="#" class="instLink" onClick="goToInst(' + instDetArr[0] +','+ instDetArr[1] + ',' + instDetArr[2] + ');return false;">Vezi pe harta</a></div>'	
						);						
					}				
				}				
				c++;
			}

			if (c > 1 && nrTotPag > 1) 	{
				var selPage = '';
				for (i=1; i<= nrTotPag; i++) {
					
					if (page == i) selPage = ' class="selPage"';
					else selPage = ' ';
					
					$('#listing_sucursale').html (						
						$('#listing_sucursale').html() + '&nbsp;<a ' + selPage + 'href="#" onClick="javascript:setSucPage(' + i + ');" class="suc_pag">Pag. ' + i + '</a>'
					);	
				}
			}	
					
		}

		function goToInst(lat, lon, id) {
			selectSucc(id);				
			my_marker = map.getMarkerObject(id);
			my_marker.closeAutoExpand();
			my_marker.openAutoExpand(); 
			map.drawZoomAndCenter(new YGeoPoint(lat, lon)  , 6);			
			return false;
		}
		
		function goToInstLine(selected)
		{
			for (inst in msgArr)
			{
				instDetArr = msgArr[inst].split('|');
				
				if ($.trim(instDetArr[0]).length > 0 && instDetArr[0].match(/^[0-9,\.\s]+$/g) && $.trim(instDetArr[1]).length > 0 && instDetArr[1].match(/^[0-9,\.\s]+$/g ))
				{
					if (instDetArr[2]== selected)
					{
						goToInst(instDetArr[0], instDetArr[1], instDetArr[2]); break;
					}
				}
			}	
			$('#map').show();
		}

		function selectSucc(id) {
			sucDiv = $('#suc_'+ id);
			$('.suc_selected').addClass('suc_lista');
			$('.suc_selected').removeClass('suc_selected');		
			
			sucDiv.addClass('suc_selected');		
		}
