function isEmail(string) {
  if(string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
    return true;
  else return false;
}
function ValidateForm(form) {
    var ret=true;
    var mail=true;
    var help=false;
		for(i=0;i<form.length;i++) {
      var swap=form.elements[i];
      //alert(swap.name +'='+ swap.value + ' | '+ swap.type);
      if((swap.type=='text' || swap.type=='textarea') && (swap.value=='' &&  swap.name.substring(0,6)=='check_')) {
        ret=false;
      }
      if(swap.type=='checkbox' && swap.name=='info') {
        if(!swap.checked) ret=false;
      }
      if(swap.name=='f_email' && !isEmail(swap.value)){ mail=false;}
    }
    if(!ret) alert("Formulář nebylo možno odeslat. Pravděpodobně jste nevyplnili některé povinné pole.")
    //if(help && ret) { alert("Formulář nebylo možno odeslat. Pravděpodobně jste nevyplnili některé povinné pole."); ret=false;}
    if(!mail && ret) { alert("Zadali jste špatnou emailovou adresu. Zkuste to prosím znova."); ret=false;}
    return ret;
}

var openedGalleries = new Array();

function showHideSubcategories(ident) {
  if(document.getElementById('subcategories-'+ ident)) {
    if(document.getElementById('subcategories-'+ ident).style.display == 'none') {
      openedGalleries[ident] = ident;
      document.getElementById('subcategories-'+ ident).style.display = 'block';
    } else {
      document.getElementById('subcategories-'+ ident).style.display = 'none';
      openedGalleries.splice(ident, 1);
    }
  }
}
function generateLink(element) {
  var ret = '';
  for(var x = 0 ; x < openedGalleries.length; x++) {
    if(openedGalleries[x] != null) ret = ret + (ret == '' ? '' : ';') + openedGalleries[x];
  }
  element.href = element.href +'?openedGaleries='+ ret;
}

function showHideMap() {
  if(document.getElementById('blah').style.opacity == 1) {
    document.getElementById('blah').setAttribute('style', 'opacity: 0;height: 0px;');
  } else {
    document.getElementById('blah').setAttribute('style', 'opacity: 1.0');
  }
}

function showHideOrganizationStructure(element) {
  if(document.getElementById(element).style.display == 'none')
    document.getElementById(element).style.display = 'table';
  else document.getElementById(element).style.display = 'none';
}

function initializeGoogleMap() {
  var myLatlng = new google.maps.LatLng(49.591928,17.252373);
  var myOptions = {
    zoom: 18,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    mapTypeControl: true,
    mapTypeControlOptions: {
        style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,
        position: google.maps.ControlPosition.TOP_RIGHT
    },
    navigationControl: true,
    navigationControlOptions: {
        style: google.maps.NavigationControlStyle.ZOOM_PAN,
        position: google.maps.ControlPosition.TOP_LEFT
    },
    scaleControl: true,
    scaleControlOptions: {
        position: google.maps.ControlPosition.BOTTOM_LEFT
    },
    streetViewControl: true

  };
  var map = new google.maps.Map(document.getElementById("mapContainer"), myOptions);
      
  var image = 'http://www.spoluolomouc.cz/images/logo-google-maps.png';
  var beachMarker = new google.maps.Marker({
      position: myLatlng,
      map: map,
      title:"SPOLU Olomouc!",
      icon: image
  });
  
  var windowContent = '<h3>SPOLU Olomouc</h3>'+
                '<p style="padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px;">'+
                '<img src="http://cbk0.google.com/cbk?output=thumbnail&w=90&h=68&ll=49.591949,17.252287&panoid=uJ2rPd2LZMASthbZEVJmiA&yaw=215.020004&pitch=-20.490000&thumb=0" style="float: right; margin-left: 20px;margin-right: 20px;">'+
                'Dolní náměstí 38<br />'+
                '779 00 Olomouc<br />'+
                '<a href="http://www.spoluolomouc.cz">www.spoluolomouc.cz</a><br /><br />'+
                'Projděte dřevěnými vraty mezi restauracemi Hanácká a U červeného volka na konec chodby ke skleněným dveřím a zvonkům.'+
                '</p>';
  var infowindow = new google.maps.InfoWindow({
      content: windowContent
  });
  infowindow.open(map);
  
  google.maps.event.addListener(beachMarker, 'mouseover', function() {
    infowindow.open(map,beachMarker);
  });

  google.maps.event.addListener(beachMarker, 'click', function() {
    infowindow.open(map,beachMarker);
  });
}


