var ie = navigator.userAgent.indexOf('MSIE')!=-1 ;
var ns = navigator.userAgent.indexOf('Gecko')!=-1 ;
var municipis_illa = new Array();
var options_select = new Array();
var objForm;
var capa_avis;
var capa_fletxa;

if( ie ){
	
    window.attachEvent('onload', iniciMapeig );
}		
if( ns ){
    window.addEventListener( 'load', iniciMapeig, true );
}

function iniciMapeig(){
    capa_avis = document.getElementById('capaAvis');
    capa_fletxa = document.getElementById('capaFletxa');
    
    
    if(ns){
		document.onmousemove = mouseMove;
		document.captureEvents(Event.MOUSEMOVE);
    } else if (ie) {
		document.onmousemove = mouseMove;
    }
    
    objForm = document.getElementById('formMunicipio');
    updateSelect(objForm.municipio,options_select);

}

function platgesClick(nomPlatja){
    if ( municipis_illa[nomPlatja] ){
        marcarSelect(objForm.municipio,municipis_illa[nomPlatja].codi);
        sendForm('formMunicipio');
    }else{
        marcarSelect(objForm.municipio,'');
    }
}

function platgesOn(nomPlatja){
    var strHtml = nomPlatja;
    
    if ( municipis_illa[nomPlatja] ){
        strHtml += ' (<strong>'+ municipis_illa[nomPlatja].numPlatges+'</strong>)';
        // 20080416 obarnes: ponia dos veces el numero de playas
        //strHtml += ' (<strong>'+ municipis_illa[nomPlatja].numPlatges+'</strong>)';
    }
    capa_avis.innerHTML = strHtml;
    capa_avis.style.display = 'block';
    capa_fletxa.style.display = 'block';
    
 
}

function platgesOff(){
    capa_avis.style.display = 'none';
    capa_fletxa.style.display = 'none';
}

function mouseMove (e) {
    if (ns) {
		x=e.pageX; 
		y=e.pageY;
    } else if (ie) {
        x = window.event.clientX; 
        y = window.event.clientY;
        
        if (document.documentElement && document.documentElement.scrollTop){
          // Explorer 6 Strict
          scrolTop = document.documentElement.scrollTop;
        }else if (document.body){
          // all other Explorers
          scrolTop = document.body.scrollTop;
        }
        y = y + parseInt( scrolTop ,10);
    }
    capa_avis.style.left = (x-10)+'px';
    capa_avis.style.top = (y-40)+'px';
    capa_fletxa.style.left = (x-10)+'px';
    capa_fletxa.style.top = (y-20)+'px';
}

//objecte municipi
function municipi(codi, descripcio, numPlatges){
    this.codi = codi;
    this.descripcio = descripcio;
    this.numPlatges = numPlatges;
    options_select[options_select.length] = new Option (descripcio+' ('+numPlatges+')',codi);
}

