/* Add classified Google Maps */

function gAddClaLoad() 
{
	
	if (GBrowserIsCompatible()) 
	{
		var map = new GMap2(document.getElementById("map_canvas"));
	
		var myGMap = getMyGMap();
		
		var center = new GLatLng(parseFloat(myGMap.lat), parseFloat(myGMap.lng));

		map.addControl(new GLargeMapControl()); //plus/minus i przesuwanie

		var marker = new GMarker(center, {draggable: true});// dragging markers
		
		GEvent.addListener(marker, "dragend", function()
		{
			map.panTo(new GLatLng(marker.getPoint().lat(),marker.getPoint().lng()),map.getZoom());
		
			document.getElementById("announcement_map_latitude").value = marker.getPoint().lat();
			document.getElementById("announcement_map_longitude").value = marker.getPoint().lng();
			document.getElementById("announcement_map_zoom").value = map.getZoom();
			
			marker.openInfoWindowHtml('Jeżeli wskazałeś miejsce,<br />wypełnij pozostałe pola formularza. <br /><br />Lub przesuwaj "Pinezkę" dalej.');
		});

		GEvent.addListener(map, "mouseout", function()
		{
			document.getElementById("announcement_map_latitude").value = marker.getPoint().lat();
			document.getElementById("announcement_map_longitude").value = marker.getPoint().lng();
			document.getElementById("announcement_map_zoom").value = map.getZoom();
		
		});

		GEvent.addListener(marker, "dragstart", function()
		{
          map.closeInfoWindow();
        });

	
		GEvent.addListener(map, "zoomend", function()
		{
			document.getElementById("announcement_map_zoom").value = map.getZoom();
		});
	
	    map.addOverlay(marker);
	    
	    map.setCenter(center, parseInt(myGMap.zoom,10));
	    
	    marker.openInfoWindowHtml('<br />Przesuń "Pinezkę", by wskazać miejsce.');
  
	}
}

function gAddClaUnload()
{
	GUnload();
}

function getMyGMap()
{
	var myGMapGet = {};
	myGMapGet.lat = document.getElementById("announcement_map_latitude").value;
	myGMapGet.lng = document.getElementById("announcement_map_longitude").value;
	myGMapGet.zoom = document.getElementById("announcement_map_zoom").value;

	return myGMapGet;
}

function gAddClaShow()
{
	var gLegend = document.getElementById('aCCFGoogleMap');//legend map
	gLegend.style.display = 'block';
	
	if(document.getElementById('map_canvas') == null)
	{
		var gMapPlace = document.getElementById('aCCFGoogleMapsBox');
		gMapPlace.innerHTML += '<div id="map_canvas" style="width: 580px; height: 430px" class="aCCFGoogleMaps"></div>';
		gAddClaLoad();
	}
}

function gAddClaHide() 
{
	var gLegend = document.getElementById('aCCFGoogleMap');//legend map
	gLegend.style.display = 'none';
	
	var	oShowPlace = document.getElementById('aCCFGoogleMapsBox');
	oShowPlace.innerHTML = '';
	gAddClaUnload();
}
/**************** END MAP ******************/


/* Add classified Title counter */

function titleCounter(lettersForm)
{
	var maxLength = 66;
	var thisLength = lettersForm.value.length;
	var countLength = maxLength - thisLength;
	var objCounter = document.getElementById('titleCounterID');
	objCounter.innerHTML = '';
	objCounter.innerHTML = 'Pozostało ' + countLength + ' znaków';
}

/* Add classified Quarter, Place name  */

function regionFieldsHide()
{
  document.getElementById('field-row-announcement_voivodeship').style.display          = 'none';
  document.getElementById('field-row-announcement_voivodeship_poviat').style.display   = 'none';
  document.getElementById('field-row-announcement_surroundings_poviat').style.display  = 'none';
  document.getElementById('field-row-announcement_quarter').style.display              = 'none';
  for (var i = 0; i < document.getElementById('announcement_quarter').options.length; i++)
  {
    var optionValue = document.getElementById('announcement_quarter').options[i].value;
    if (optionValue != '' && document.getElementById('field-row-announcement_housing_estate_' + optionValue))
      document.getElementById('field-row-announcement_housing_estate_' + optionValue).style.display  = 'none';
  }
  document.getElementById('field-row-announcement_city').style.display                 = 'none';
  document.getElementById('field-row-announcement_street').style.display               = 'none';
}

function regionFieldsShow(element)
{
  regionFieldsHide();
  var selectedIndex = element.selectedIndex;
  switch (element.options[selectedIndex].value)
  {
    case '1':
      document.getElementById('field-row-announcement_voivodeship').style.display  = 'block';
      document.getElementById('field-row-announcement_city').style.display         = 'block';
      document.getElementById('field-row-announcement_street').style.display       = 'block';
      break;
      
    case '2':
      document.getElementById('field-row-announcement_voivodeship_poviat').style.display  = 'block';
      document.getElementById('field-row-announcement_city').style.display                = 'block';
      document.getElementById('field-row-announcement_street').style.display              = 'block';
      break;
      
    case '3':
      document.getElementById('field-row-announcement_surroundings_poviat').style.display = 'block';
      document.getElementById('field-row-announcement_city').style.display                = 'block';
      document.getElementById('field-row-announcement_street').style.display              = 'block';
      break;
      
    case '4':
      document.getElementById('field-row-announcement_quarter').style.display = 'block';
      document.getElementById('field-row-announcement_street').style.display  = 'block';
      document.getElementById('announcement_quarter').onchange();
      break;
  }
}

function housingEstateFieldHide()
{
  for (var i = 0; i < document.getElementById('announcement_quarter').options.length; i++)
  {
    var optionValue = document.getElementById('announcement_quarter').options[i].value;
    if (optionValue != '' && document.getElementById('field-row-announcement_housing_estate_' + optionValue))
      document.getElementById('field-row-announcement_housing_estate_' + optionValue).style.display  = 'none';
  }
}

function housingEstateFieldShow(element)
{
  housingEstateFieldHide();
  var selectedIndex = element.selectedIndex;
  var selectedValue = element.options[selectedIndex].value;
  if (selectedValue != '' && document.getElementById('field-row-announcement_housing_estate_' + selectedValue))
    document.getElementById('field-row-announcement_housing_estate_' + selectedValue).style.display  = 'block';
}

/* Add www adress in adding classified - last step */

function addUrlHide(_id)
{
	var objMail = document.getElementById(_id);
	objMail.style.display = "none";
}

function addUrlShowHide(obj)
{
	var objMail = document.getElementById(obj);
	objMail.style.display == "none" ? objMail.style.display = "block" : objMail.style.display = "none";
}


/* open links in new window */

function openNewWindow(elem)
{
	var tabElem = document.getElementById(elem);
	
	if(tabElem != null)
	{
		var colLinks = tabElem.getElementsByTagName('A');
		
		colLinksLength = colLinks.length;
		
		if(colLinksLength > 0)
		{
		
			for (var i=0; i<colLinksLength; i++)
			{
				colLinks[i].onclick = newWindowShow;
			}
		}
	}
}

function newWindowShow()
{
	var windowHref = this.href;
	window.open(windowHref); 
	return false;
}


