/**
* Page		: divers.js
* Contenu	: Code javascript divers pour la page principale
* Date		: 02/08/10
* @author	Gael Sauvanet
* @version	1.0
*/

/** 
 * Redirection pour changer de zone
 */
function changePage(newpage){ 
	setTimeout("window.location.href = '"+URL_BASE_SITEWEB+DOSSIER_SITEWEB+newpage+"'" , 0 ); 
} 

/** 
 * Sauvegarde la position actuelle sur la carte
 */
function save_coord(e){ 
	pixel = controlMousePosition.lastXy;
	lonlat = map.getLonLatFromPixel(pixel);
	lonlat = MToLonLat(lonlat);
} 

/** 
 * PopUp vers la feuille de route
 */
function imprimer() {
	if(typeof(mode_colonne_droite) == 'undefined' || mode_colonne_droite == 1 || mode_colonne_droite == 6)
	{
		var lien = "feuille_de_route.php";
		lien += "?lat1=" + defItineraire.lat1;
		lien += "&lng1=" + defItineraire.lon1;
		lien += "&lat2=" + defItineraire.lat2;
		lien += "&lng2=" + defItineraire.lon2;
		lien += "&mode=" + mode_colonne_droite;
		if (defItineraire.ListemarkerEtape!=null)
			for (var i=1; i<defItineraire.ListemarkerEtape.length; i++)
			{
				ll = new OpenLayers.LonLat(defItineraire.ListemarkerEtape[i].geometry.x,defItineraire.ListemarkerEtape[i].geometry.y);
				ll=MToLonLat(ll);
				lien+="&latE"+i+'='+ll.lat;
				lien+="&lonE"+i+'='+ll.lon;
			}
		lien += "&latc=" + MToLonLat(map.getCenter()).lat;
		lien += "&lngc=" + MToLonLat(map.getCenter()).lon;
		lien += "&z=" + map.getZoom();
		lien += "&i=" + solution_actuelle;
		Rad=window.open(lien,'Window','resizable=no,menubar=yes,width=800,height=600,left=100,top=100,scrollbars=yes');
		Rad.focus();
	}
	else if(mode_colonne_droite == 4)
	{
		if(!creationBaladeEnCours && $j('#formCreerBalade #idBalade').val() != -1)
		{
			Rad=window.open('balade.php?n='+$j('#formCreerBalade #idBalade').val(),'Window','resizable=no,menubar=yes,width=800,height=600,left=100,top=100,scrollbars=yes');
			Rad.focus();
		}
		else
		{
			messageModal("Vous devez consulter une balade avant de pouvoir l'imprimer");
		}
	}
}

/** 
 * dialog de chargement en jquery
 */
$j(document).ready(function() {
    $j("#dialog").dialog({autoOpen:false,modal:true,title:'Calcul en cours',height:73,width:200,closeOnEscape:false,resizable: false,zIndex: 3999,dialogClass:'noTitle'});
});

/**
 * Fonction lancant la fenêtre de chargement
 */
function debutChargement()
{
	$j("#dialog").dialog( "open" );
	$j("#dialog").height(73);
	$j("#dialog").css('min-height',73);
}

/**
 * Fonction arretant la fenêtre de chargement
 */
function finChargement()
{
	$j("#dialog").dialog( "close" );
}

function array_search(valeur, tableau)
{
	var index_du_tableau=-1
 
	for(elt in tableau){
		index_du_tableau++;
		if (tableau[elt].numero==valeur){return index_du_tableau}
	}
	index_du_tableau=-1;
	return index_du_tableau;
}

function middlepop(Tab,a){
	return (a>Tab.length)?false:(Tab.slice(0,a).concat(Tab.slice(a+1,Tab.length)));
}

/**
 * Affichage de la fenêtre d'aide en montrant une certaine section
 */
function afficherAide(numero)
{
    $j( "#dialogAide" ).dialog("open");
    $j( "#accordionAide" ).accordion("activate",numero);
}

/**
 * Affiche un message comme dialogue modal jquery, d'une manière équivalente à window.alert()
 * @param message
 */
function messageModal(message)
{
	$j("#dialog-messageModal").html(message).dialog({
		modal:true,
		resizable:false,
		width:300,
		minHeight:100,
		show:{effect:'highlight',color:'#b7db3c'},
		open: function(event, ui) {
			$j('.ui-widget-overlay').bind('click', function(){$j("#dialog-messageModal").dialog('close'); }); 
		}
		});
}

