// Fichier JavaScript des pages produits

// Activation des outils concernés
// Affichage carte Google Maps
Event.observe(window, 'load', initStretch, false);
// Surveillance du formulaire de contact
Event.observe(window, 'load', prepFormulaire, false);

function prepFormulaire() {
	var thisForm = document.forms['contact'];
	thisForm.onsubmit = function() {
			return checkThisForm(this);
		}
}

// ------------------------------------------------
// Vérification du formulaire
// ------------------------------------------------
function checkThisForm(thisform) {
	var alertTxt = "";
	//var thisform = $('contactFormGen');
	var submitCheck = false;
	
	for(var i=0; i<thisform.elements.length; i++) {
		var element = thisform.elements[i];
		if(element.className.indexOf("obligatoire") != -1) {
			if(!estRempli(element)) {
				var alertTxt = alertTxt + " <br />- <b>" + element.name + "</b>";
				submitCheck = false;
			} else {
				if(element.className.indexOf("email") != -1) {
					if(!estEmail(element)) {
						var alertTxt = alertTxt + "<br />- <b>Adresse e-mail invalide!</b>";
						submitCheck = false;
					} else {
						submitCheck = true;
					}
				}
			}
		}
	}
	if(submitCheck == false) {
		dispWarnings(alertTxt);
		return false;
	} else {
		return true;
	}
}

function estRempli(field) {
	if(field.value.length < 1 || field.value == field.defaultvalue) {
		return false;
	} else {
		return true;
	}
}

function estEmail(email) {
	if(email.value.indexOf("@") == -1 || email.value.indexOf(".") == -1) {
		return false;
	} else {
		return true;
	}
}

function dispWarnings(alertTxt) {
	alertTxt = "Attention! Les champs suivants sont obligatoires:" + alertTxt;
	warnDiv = document.getElementById("mailAlert");
	warnDiv.innerHTML = alertTxt;
	warnDiv.style.display = 'block';
	window.scroll(warnDiv.offsetLeft,warnDiv.offsetTop + 25);
}



// ------------------------------------------------
// Google Maps
// ------------------------------------------------

// Merci Google inc.
function loadGoogleMap() {
      var X_coord = 50.645921;
	  var Y_coord = 5.807570;
	  if (GBrowserIsCompatible()) {
	  	
		var map = new GMap2(document.getElementById("googlemap"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(X_coord, Y_coord), 16);
		map.setMapType(G_HYBRID_MAP);
		
		// Create the label
		function createMarker(point, number) {
		  var marker = new GMarker(quatuorMrkr, icon);
		  GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml("<font face=arial font-size=8px color=#666666><b>Quatuor</b><br />Rue de Herve, 107<br />4651 BATTICE<br />Tel.: +32 87 67 93 00<br />Fax: +32 87 67 80 71</font>");
		  });
		  return marker;
		}
		
		// Create the Quatuor icon
		var icon = new GIcon();
		icon.image = "http://www.quatuor.be/img/google_maps/icon_quatuor_2.png";
		icon.shadow = "http://www.quatuor.be/img/google_maps/icon_quatuor_2-shadow.png";
		icon.iconSize = new GSize(140, 100);
		icon.shadowSize = new GSize(140, 100);
		icon.iconAnchor = new GPoint(35, 100);
		icon.infoWindowAnchor = new GPoint(60, 10);

		// Create the marker
		var quatuorMrkr = new GLatLng(X_coord, Y_coord);
		  map.addOverlay(createMarker(quatuorMrkr, 1));
	  }
    }
	
// On charge la carte Google Maps
function googlemapLoader() {
	if($('accordDiv').offsetHeight == 0){
		GUnload();
	} else {
		loadGoogleMap();
		}
	
	}

// On Anime l'apparition de la carte Google Maps
function initStretch() {
	if($('accordDiv')) {
		var togglers = $('accordToggle');
		var accordDiv = $('accordDiv');
		accordDiv.hide()
	
		togglers.onclick =  function() { 
			Effect.toggle(accordDiv, 'blind', { duration: 2.0 });
			var wait = setTimeout("googlemapLoader()", 501);
			return false;
		}
	}
}

