function displayStatusMsg(msgStr) {
  status=msgStr;
  // document.MM_returnValue = true;
}

function ValidateForm(f)
{
  var fieldEmpty = '';
  for(var noElement = 0; noElement<f.elements.length; noElement++)
  {
    var element = f.elements[noElement];
    if(((element.type == 'text') || (element.type == 'textarea')) && element.name != 'form_surname' && element.name != 'form_company')
    {
      if(element.value == null || element.value == '')
      {
        fieldEmpty = true;
      }
    }
  }
  if(fieldEmpty)
  {
    f.action = '';
    alert("Proszę wypełnić wymagane pola!");
    return false;
  }
  return true;
}


function loadSearchCriteria( section )
{
     advAJAX.get
    (
        {
            url: "?module=Search&action=ajax_updateSearchCriteria",
            parameters:
            {
                "section": section
            },
            onLoading: function( obj )
            {
                document.getElementById( 'search_criteria_loading' ).innerHTML = '<img src="images/frontend/loading2.gif" width="30" height="30">';
            },
            onSuccess: function( obj )
            {
                document.getElementById( 'search_criteria_loading' ).innerHTML = "";
                document.getElementById( 'ajax_search_criteria' ).innerHTML = obj.responseText;
            },
            onError: function( obj )
            {
                document.getElementById( 'search_criteria_loading' ).innerHTML = "";
                document.getElementById( 'ajax_search_criteria' ).innerHTML = 'Wystąpił błąd';
            }
        }
    );
  
}


/* ------------------------ GMAPS ---------------------------------------- */

var side_bar_html = "";
var gmarkers = [];
var map ; 



function createMarker(point, number , icon , type, name, placeId) 
{  
	var marker = new GMarker(point,icon);  
	GEvent.addListener(marker, "click", function() {
		//marker.openInfoWindowHtml(number);
		map.setCenter(point, 13);
	});
	
    gmarkers.push(marker);
    side_bar_html += number + '<br/>' + '<a class="showonmap" href="javascript:showonmap(' + (gmarkers.length-1) + ',' + placeId + ')">' + 'pokaż na mapie' + '<\/a><br>';

	
	return marker;
}

function showonmap(i,placeId) {
	GEvent.trigger(gmarkers[i], "click");
	//update_place_info (placeId);
}


function myclick(i,placeId) {
	GEvent.trigger(gmarkers[i], "click");
	update_place_info (placeId);
}




function GUload(lat, lng, zoom, marker) 
{ 
    if (GBrowserIsCompatible()) 
	{ 
    	map = new GMap2(document.getElementById("map")); 
		map.addControl(new GLargeMapControl());
		map.addControl(new GScaleControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl());
      	map.setCenter(new GLatLng(lat, lng), zoom);
		
		if (marker)
		{
			var point = new GLatLng(lat, lng);  
			var marker = new GMarker(point); 
			map.addOverlay(marker);
		}
    } 
}



function Gload_places (lat, lng, zoom) 
{ 

	if (GBrowserIsCompatible()) { 
    	
		map = new GMap2(document.getElementById("map"));   

    	map.enableScrollWheelZoom(); 
		map.addControl(new GLargeMapControl());
		map.addControl(new GScaleControl());
		map.addControl(new GOverviewMapControl());
      	map.setCenter(new GLatLng(lat, lng), zoom); 

   
		map.hideControls();  
		GEvent.addListener(map, "mouseover", function(){map.showControls();});  
		GEvent.addListener(map, "mouseout", function(){map.hideControls();});  
  

		
		
       
		GDownloadUrl('index.php?module=Places&action=GetPlacesXML', function(data2, responseCode2) 
		{
	
			if(responseCode2 == 200) {	
				
				var xml = GXml.parse(data2);
				var places = xml.documentElement.getElementsByTagName('place');


				var icon_project = new GIcon();  				
				/*icon_project.image = "http://maps.google.com/mapfiles/ms/micons/blue-pushpin.png";*/
				icon_project.image = "images/frontend/markerp_n.png";	
				/*icon_project.shadow = "images/frontend/shadow.png";*/						 
		        icon_project.iconAnchor=new GPoint(18,58);
		        icon_project.infoWindowAnchor = new GPoint(19,0);	

				var icon_colletion = new GIcon();  				
				/*icon_colletion.image = "http://maps.google.com/mapfiles/ms/micons/red-pushpin.png";*/
				icon_colletion.image = "images/frontend/markerc_n.png";
				/*icon_colletion.shadow = "images/frontend/shadow.png";*/						 
		        icon_colletion.iconAnchor=new GPoint(18,58);
		        icon_colletion.infoWindowAnchor = new GPoint(19,0);	
		        
				var icon_project_and_colletion = new GIcon();  				
				/*icon_project_and_colletion.image = "http://maps.google.com/mapfiles/ms/micons/grn-pushpin.png";*/
				icon_project_and_colletion.image = "images/frontend/markerc_n.png";
				/*icon_project_and_colletion.shadow = "images/frontend/shadow.png";*/							 
		        icon_project_and_colletion.iconAnchor=new GPoint(18,58);
		        icon_project_and_colletion.infoWindowAnchor = new GPoint(19,0);	
		        
				var icon_unknown = new GIcon();  				
				/*icon_unknown.image = "http://labs.google.com/ridefinder/images/mm_20_black.png";*/
				icon_unknown.image = "images/frontend/markerc_n.png";
				/*icon_unknown.shadow = "images/frontend/shadow.png";*/							 
		        icon_unknown.iconAnchor=new GPoint(18,58);
		        icon_unknown.infoWindowAnchor = new GPoint(19,0);	
		        		        		        
					
				for (var i = 0; i < places.length; i++) 
				{
				
					var icon = new GIcon();  				
	
					if (places[i].getAttribute('placeName').length > 0)
					{
						place_name = '<h2><strong>' + places[i].getAttribute('placeName') + '</strong></h2>';
					}
					else
					{
						place_name = '' ; 
					}

					if (places[i].getAttribute('type').length > 0)
					{
						if (places[i].getAttribute('type')=="1"){ //project
							icon	=	icon_project ;
							place_category = '<div style="font-size:xx-small;">' + '<span class="italic">' + "Project" + '</span>' + '</div><br/>';
						}
						else{
							if (places[i].getAttribute('type')=="2"){ //colletion 
								icon	=	icon_colletion ;
								place_category = '<div style="font-size:xx-small;">' + '<span class="italic">' + "Colletion" + '</span>' + '</div><br/>';
							}
							else{
								if (places[i].getAttribute('type')=="3"){ //project&colletion
									icon	=	icon_project_and_colletion ;
									place_category = '<div style="font-size:xx-small;">' + '<span class="italic">' + "Project&Colletion" + '</span>' + '</div><br/>';
								}
								else{
									icon	=	icon_unknown ;
									place_category = '<div style="font-size:xx-small;">' + '<span class="italic">' + "(nieznane)" + '</span>' + '</div><br/>';								
								}
							}
							
						}
						
					}
					else
					{
						place_category = '' ; 
					}

					if (places[i].getAttribute('address').length > 0)
					{
						place_address = '<p>' + places[i].getAttribute('address') + '</p>';
					}
					else
					{
						place_address = '' ; 
					}

					if (places[i].getAttribute('phone').length > 0)
					{
						place_phone = '<p>' + places[i].getAttribute('phone') + '</p>';
					}
					else
					{
						place_phone = '' ; 
					}
					if (places[i].getAttribute('email').length > 0)
					{
						place_email = '<p><strong>e-mail: </strong>' + '<a href="mailto:' +places[i].getAttribute('email') +'">' +places[i].getAttribute('email') + '</a>'  + '</p>';
					}
					else
					{
						place_email = '' ; 
					}
															
		        
					var info =  place_name  + place_category + place_address + place_phone +  place_email;

					var point = new GLatLng(parseFloat(places[i].getAttribute("lat")), parseFloat(places[i].getAttribute("lng")));
								 
					map.addOverlay(createMarker(point, info  , icon , places[i].getAttribute('type'), place_name, places[i].getAttribute('placeId')));  
		        
			        			
				}
				//document.getElementById("side_bar").innerHTML = side_bar_html;
				
			}			
		});		
	}
}

/*
function update_place_info (placeId){	
     advAJAX.get
    (
        {
            url: "?module=Places&action=ajax_getPlace",
            parameters:
            {
                "placeId": placeId
            },
            onLoading: function( obj )
            {
                document.getElementById( 'place_info' ).innerHTML = '<img src="images/frontend/loading2.gif" width="30" height="30">';
            },
            onSuccess: function( obj )
            {
                document.getElementById( 'place_info' ).innerHTML = "";
                document.getElementById( 'place_info' ).innerHTML = obj.responseText;
            },
            onError: function( obj )
            {
                document.getElementById( 'place_info' ).innerHTML = "";
                document.getElementById( 'place_info' ).innerHTML = 'Wystąpił błąd podczas ładowania informacji o salonie';
            }
        }
    );
    	
}
*/	
function LeftMenu(){
	$('.SubMenu ul').addClass('hide');
	$('.SubMenu').find('.selected').parents('.SubMenu ul').removeClass('hide');
	$('.selected ul:first').removeClass('hide');
}
function SwitchImg(){
	$('.thumb').bind('click',function(){
	
		var anchor=$(this).attr('href');
		$('.topimg').attr('src',anchor);
		$('.blocks li').removeClass('selected');
		$(this).parent('li').addClass('selected');
		return false;
	});
}
function Flashe(){
	$('#col-flash').flash({
		src: './swf/main_col.swf',
		width: 450,
		height: 322,
		wmode: 'transparent'
	});
	$('#pro-flash').flash({
		src: './swf/main_pro.swf',
		width: 450,
		height: 322,
		wmode: 'transparent'
	});
	$('#col-flash-e').flash({
		src: './swf/main_col_eng.swf',
		width: 450,
		height: 322,
		wmode: 'transparent'
	});
	$('#pro-flash-e').flash({
		src: './swf/main_pro_eng.swf',
		width: 450,
		height: 322,
		wmode: 'transparent'
	});
	$('#colbig-flash').flash({
		src: './swf/col.swf',
		width: 737,
		height: 539,
		wmode: 'transparent'
	});
	$('#projbig-flash').flash({
		src: './swf/pro.swf',
		width: 737,
		height: 539,
		wmode: 'transparent'
	});
	$('#colbig-flash-e').flash({
		src: './swf/col_eng.swf',
		width: 737,
		height: 539,
		wmode: 'transparent'
	});
	$('#projbig-flash-e').flash({
		src: './swf/pro_eng.swf',
		width: 737,
		height: 539,
		wmode: 'transparent'
	});
}
$(document).ready(function() {
	LeftMenu();
	SwitchImg();
	Flashe();	
});



