function toggleVideos(id) {
	new Effect.toggle(id, 'appear');
	if($(id).visible() == true) 
		$('txt_more').update('Plus de vid&eacute;os');
	else
		$('txt_more').update('Fermer les vid&eacute;os');
}
// JavaScript Document
	
var GLOAppear = false;
	
function cleanMsg(idElem, valueTxt, secondValue){
	if(secondValue != "") {
		if($(idElem).value==valueTxt || $(idElem).value==secondValue) $(idElem).value="";	
	}
	else {
		if($(idElem).value==valueTxt) $(idElem).value="";
	}
}

// GOOGLE MAPS

function Checkzip(rub) {
	
	var zip = new String($('inputCP').value);

	if (zip.search(/^[0-9][0-9][0-9][0-9][0-9]$/)==-1) {
		$('inputCP').value = "5 chiffres requis";
		$('inputCP').style.color = "red";
	}
	else {
		new Ajax.Request('Select_ville.php?zip='+zip,
			{
				asynchronous:true,
				method: 'post',
				onSuccess: function(t) {
					eval(t.responseText);
					var body = $("carte_points_vente");
					show(zip+" "+region, body, 8, zip, false, rub);
				},
				onLoading: function() {
					$('loadingMap').show();
				},
				onComplete: function(){  
					$('loadingMap').hide();
				}
		});
	}
}
function createFixedMarker(point,icone, itineraire, html, rub) {

	var marker = new GMarker(point, icone);
	marker.infoTabs = [
		new GInfoWindowTab("Le chantier", html)
		//new GInfoWindowTab("Itinéraire", itineraire)
	];
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowTabsHtml(marker.infoTabs);
	});
	return marker;
 }
function show(address, body, zoom, zip, detail, rub) {
	var geocoder = new GClientGeocoder();
	if (geocoder) {
		geocoder.getLatLng(address, function(point) {
			if (!point) { 
				load(47, 1.8, 5, body, zip, detail, rub);
			} 
			else {
				var lat = point.y;
				var lng = point.x;
				
				load(lat, lng, zoom, body, zip, detail, rub);
			}
		});
	}
}

function load(lat, lng, zoom, body, zip, detail, rub) {
	var icon = new GIcon();
	icon.image = "images/google_maps/icone-BO.png";
	icon.shadow = "images/google_maps/shadow-BO.png";
	icon.iconSize = new GSize(55, 55);
	icon.shadowSize = new GSize(115, 53);
	icon.iconAnchor = new GPoint(30, 55);
	icon.infoWindowAnchor = new GPoint(30, 58);
	
	var markers = new Array();
	var infos_map = new Array();
	
	if (GBrowserIsCompatible()) {		
		
		var myPano = new GStreetviewPanorama($("pano"));
		
		gmap = new GMap2(body);
		gmap.setUIToDefault();
		
		svOverlay = new GStreetviewOverlay();
		GEvent.addListener(gmap,"click", function(overlay,latlng) {
			if(GLOAppear == false) {
				new Effect.Appear('txt_pano', {duration:1, fps:25, from:0.0, to:1.0});
				new Effect.Appear('pano', {duration:1, fps:25, from:0.0, to:1.0});
				
				GLOAppear = true;
			}
			myPano.setLocationAndPOV(latlng);
		});
		
		if(zip == "") {
			new Ajax.Request('geoIP.php',
				{
					asynchronous:true,
					method: 'get',
					onSuccess: function(t) {
						eval(t.responseText);
						
						if((GEOlat != 0) && (GEOlng != 0)) {
							gmap.setCenter(new GLatLng(GEOlat, GEOlng), 14);
						}
						else {
							gmap.setCenter(new GLatLng(lat, lng), zoom);
						}
						new Ajax.Request('Select_point.php?rub='+rub,
							{
								asynchronous:true,
								method: 'get',
								onSuccess: function(t) {
									eval(t.responseText);
									for(var k=0; k<markers.length; k++) {
										gmap.addOverlay(markers[k]);
									}
								},
								onLoading: function() {
									$('loadingMap').show();
								},
								onComplete: function(){  
									$('loadingMap').hide();
								}
						});
					},
					onLoading: function() {
						$('loadingMap').show();
					},
					onComplete: function(){  
						$('loadingMap').hide();
					}
			});
		}
		else {
			gmap.setCenter(new GLatLng(lat, lng), zoom);
			new Ajax.Request('Select_point.php?zip='+zip+'&rub='+rub,
				{
					asynchronous:true,
					method: 'get',
					onSuccess: function(t) {
						eval(t.responseText);
						$('totalMap').update(total+" r&eacute;sultat(s) trouv&eacute;(s)");
						
						for(var k=0; k<markers.length; k++) {
							gmap.addOverlay(markers[k]);
						}
					},
					onLoading: function() {
						$('loadingMap').show();
					},
					onComplete: function(){  
						$('loadingMap').hide();
					}
			});
		}
	}
}

function loadMap(zip, rub) {	
	$('pano').style.display = 'none';
	$('txt_pano').style.display = 'none';
	if(zip == "") {
		var body = $("carte_points_vente");
		load(47, 1.8, 5, body, "", false, rub);
	}
}

// FIN GOOGLE MAPS

// INSTANT GAGNANT
//Affiche les félicitations et le lot lorsqu'un gain est gagné, au clic sur le flash
function showLots()
{
	Lightview.show({ href: 'infoGain', rel: 'inline', options:{width:600,height:400} });
}

//Pré-remplir le formulaire d'inscription
document.observe("dom:loaded", function() {
	if($('in_email')) {
		$('in_email').observe('change', function(){
			var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');

			if(reg.test($('in_email').value))
			{
				new Ajax.Request('metaltex-instant-gagnant-particip.html',
					{
						method: 'post',
						parameters:{emailTest:$('in_email').value, id_ig:$('id_ig').value},
						onComplete: function(t) {
							if(t.responseText!="")
							{
								if(confirm(unescape("Vous avez d%E9j%E0 particip%E9 %E0 un instant gagnant, voulez-vous pr%E9-remplir le formulaire?")))
								{
									var infos=t.responseText.split("**");
									$("in_nom").value=infos[0];
									$("in_prenom").value=infos[1];
									var reg2=new RegExp('[0-9]* [a-z0-9]+([_|\.|-]{1}[a-z]+)*$','i');
									var adr=reg2.exec(infos[2]);
									$("in_adresse").value=infos[2].substring(0,infos[2].indexOf(adr[0])-1);
									$("in_cp").value=adr[0].substring(0,adr[0].indexOf(" "));
									$("in_ville").value=adr[0].substring(adr[0].indexOf(" ")+1,adr[0].length);
									$("in_tel").value=infos[3];
									if(infos[4]=="1")
									{
										var i=0;
										$$('.box').each(function(elem){if(i==0)elem.checked=true;i++;});
									}
								}
							}
						}
				});
			}
		});
	}
});

// FIN INSTANT GAGNANT
