var urlSite="http://"+document.location.host;

function bookmark_it(){
	if ( navigator.appName != 'Microsoft Internet Explorer' ) { 
		   window.sidebar.addPanel("Deux Flics &agrave; Miami - L'encyclop&eacute;die",""+url_site,"");
	}else {
		   window.external.AddFavorite(""+url_site,"Deux Flics &agrave; Miami - L'encyclop&eacute;die");
	}
}

function checkEmail(chaine) {

	a=chaine.indexOf("@");
	point=chaine.lastIndexOf(".");
	if (a>0 && point > a+1 && point < chaine.length-1 ){
	   return true;}
	else{
	   return false;
	}
}

function checkSite(chaine) {

	a=chaine.indexOf("http://");
	lg_chaine=chaine.length;
	if (a==0 && lg_chaine>10){
	   return true;}
	else{
	   return false;
	}
}

function endsWith(str, suffix) {
    return str.indexOf(suffix, str.length - suffix.length) !== -1;
}

function effacer(target) {
	if (target.value == target.defaultValue) { target.value = ""; }
}

function remplacer(target) {
	if (target.value == "") { target.value = target.defaultValue; }
}

function verifComment()
{
	var isValid=true;
	var icone_ok = "/images/icone_ok.png";
	var icone_ko = "/images/icone_no.png";
	
		/* Vérification PSEUDO */
	if(document.formComment.commentPseudo.value==document.formComment.commentPseudo.defaultValue){
		changeContainerBackground('linePseudo', '#2F292B url('+ icone_ko+') no-repeat top right');
		isValid = false;
	}else{
		changeContainerBackground('linePseudo', '#2F292B url('+ icone_ok+') no-repeat top right');
	}
	
	/* Vérification MESSAGE */
	if(document.formComment.commentMessage.value==document.formComment.commentMessage.defaultValue){
		changeContainerBackground('lineMessage', '#2F292B url('+ icone_ko+') no-repeat top right');
		isValid = false;
	}else{
		changeContainerBackground('lineMessage', '#2F292B url('+ icone_ok+') no-repeat top right');
	}
	
	/* Vérification CALCUL */
	if(document.formComment.commentCalcul.value==document.formComment.commentCalcul.defaultValue){
		changeContainerBackground('lineCalcul', '#2F292B url('+ icone_ko+') no-repeat top right');
		isValid = false;
	}else{
		changeContainerBackground('lineCalcul', '#2F292B url('+ icone_ok+') no-repeat top right');
	}
	
	if(document.formComment.commentFollowing.checked){
		//Si suivi demandé, on vérifie l'e-mail
		/* Vérification E-MAIL */
		if(document.formComment.commentEmail.value==document.formComment.commentEmail.defaultValue){
			changeContainerBackground('lineEmail', '#2F292B url('+ icone_ko+') no-repeat top right');
			isValid = false;
		}else{
			if(!(checkEmail(document.formComment.commentEmail.value))){
				changeContainerBackground('lineEmail', '#2F292B url('+ icone_ko+') no-repeat top right');
				isValid = false;		
			}else{
				changeContainerBackground('lineEmail', '#2F292B url('+ icone_ok+') no-repeat top right');
			}
		}	
	}
	else
	{
		changeContainerBackground('lineEmail', '#2F292B');
	}
	
	return isValid;
}

function verifContact()
{
	var isValid=true;
	var icone_ok = "/images/icone_ok.png";
	var icone_ko = "/images/icone_no.png";
	
	/* Vérification OBJECT */
	if(document.formContact.contactObject.value==document.formContact.contactObject.defaultValue){
		changeContainerBackground('lineObject', 'transparent url('+ icone_ko+') no-repeat top right');
		isValid = false;
	}else{
		changeContainerBackground('lineObject', 'transparent url('+ icone_ok+') no-repeat top right');
	}

	/* Vérification NOM */
	if(document.formContact.contactName.value==document.formContact.contactName.defaultValue){
		changeContainerBackground('lineName', 'transparent url('+ icone_ko+') no-repeat top right');
		isValid = false;
	}else{
		changeContainerBackground('lineName', 'transparent url('+ icone_ok+') no-repeat top right');
	}

	/* Vérification PRENOM */
	if(document.formContact.contactFirstName.value==document.formContact.contactFirstName.defaultValue){
		changeContainerBackground('lineFirstName', 'transparent url('+ icone_ko+') no-repeat top right');
		isValid = false;
	}else{
		changeContainerBackground('lineFirstName', 'transparent url('+ icone_ok+') no-repeat top right');
	}

	/* Vérification E-MAIL */
	if(document.formContact.contactEmail.value==document.formContact.contactEmail.defaultValue){
		changeContainerBackground('lineEmail', 'transparent url('+ icone_ko+') no-repeat top right');
		isValid = false;
	}else{
		if(!(checkEmail(document.formContact.contactEmail.value))){
			changeContainerBackground('lineEmail', 'transparent url('+ icone_ko+') no-repeat top right');
			isValid = false;		
		}else{
			changeContainerBackground('lineEmail', 'transparent url('+ icone_ok+') no-repeat top right');
		}
	}	
	
	/* Vérification MESSAGE */
	if(document.formContact.contactMessage.value==document.formContact.contactMessage.defaultValue){
		changeContainerBackground('lineMessage', 'transparent url('+ icone_ko+') no-repeat top right');
		isValid = false;
	}else{
		changeContainerBackground('lineMessage', 'transparent url('+ icone_ok+') no-repeat top right');
	}
	
	/* Vérification CALCUL */
	if(document.formContact.contactCalcul.value==document.formContact.contactCalcul.defaultValue){
		changeContainerBackground('lineCalcul', 'transparent url('+ icone_ko+') no-repeat top right');
		isValid = false;
	}else{
		changeContainerBackground('lineCalcul', 'transparent url('+ icone_ok+') no-repeat top right');
	}
	
	return isValid;
}

function verifResearch()
{
	if(document.getElementById('researchParam').value == document.getElementById('researchParam').defaultValue){
		var span = document.createElement('span');
		span.innerHTML='Renseignez le champ mot-cl&eacute; SVP.';
		alert(span.innerHTML);
		return false;
	}
	else
	{
		//alert(document.getElementById('researchParam').value.length);
		if(document.getElementById('researchParam').value.length < 3)
		{
			var span = document.createElement('span');
			span.innerHTML='Merci de renseigner un mot cl&eacute; d\'au moins 3 lettres, SVP.';
			alert(span.innerHTML);
			return false;
		}
	}
	return true;	
}

function changeContainerBackground(containerId, bgValue)
{
	document.getElementById(containerId).style.background=bgValue;	
}

function GMap_Initialize(defaultLat,defaultLng,defaultZoom) {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("viceMap"));
		map.setCenter(new GLatLng(defaultLat, defaultLng), defaultZoom);
		var extLargeMapControl = new ExtLargeMapControl();
		map.addControl(extLargeMapControl);
		mgr = new MarkerManager(map, {
			trackMarkers: true
		});
		window.setTimeout(setupLocationMarkers, 0);
	}
}

function getIcon(images) {
	var icon = null;
	if (images) {
		if (icons[images[0]]) {
			icon = icons[images[0]];
		} else {
			icon = new GIcon();
			icon.image = "/images/" + images[0] + ".png";
			var size = iconData[images[0]];
			icon.iconSize = new GSize(size.width, size.height);
			//icon.iconSize = new GSize(44, 39);
			////icon.iconAnchor = new GPoint(size.width >> 1, size.height >> 1);
			//icon.iconAnchor = new GPoint((size.width / 2), size.height);
			icon.iconAnchor = new GPoint((30 / 2), 40);
			icons[images[0]] = icon;
		}
	}
	return icon;
}

function setupLocationMarkers() {
	for (var i in pointsLayer) {
		if (pointsLayer.hasOwnProperty(i)) {
			var layer = pointsLayer[i];
			var markers = [];
			for (var j in layer["places"]) {
				if (layer["places"].hasOwnProperty(j)) {
					var place = layer["places"][j];
					var icon = getIcon(place["icon"]);
					var title = place["name"];
					var url = place["link"];
					var posn = new GLatLng(place["posn"][0], place["posn"][1]);
					var marker = createMarker(posn, title, icon, url);
					markers.push(marker);
				}
			}
			mgr.addMarkers(markers, layer["zoom"][0], layer["zoom"][1]);
		}

	}
	mgr.refresh();
}

function createMarker(posn, title, icon, url) {
	var marker = new GMarker(posn, {
		title: title,
		icon: icon,
		draggable: false
	});
	GEvent.addListener(marker, 'click', function() {
		//alert(map.getZoom());
		document.location.replace(chemin_site+"/v2"+url);
	});
	return marker;
}


/*****************************************************************************************************************************************************************/
/********** COMPTE A REBOURS FRENCH TWIST CONVENTION *************************************************************************************************************/
/*****************************************************************************************************************************************************************/
function compte_a_rebours(dateCible1,dateCible2,numCible) {  
	var dateCible = dateCible1;
	if(numCible=='2')
		dateCible = dateCible2;

	var date1 = new Date();
	var date2 = new Date (dateCible);  
	if(date1<date2)
	{
		var sec = (date2 - date1) / 1000;  
		var n = 24 * 3600;  
		if (sec > 0) {  
			j = Math.floor (sec / n);  
			h = Math.floor ((sec - (j * n)) / 3600);  
			mn = Math.floor ((sec - ((j * n + h * 3600))) / 60);  
			sec = Math.floor (sec - ((j * n + h * 3600 + mn * 60)));  
			var s = "s";
			if(j<2)
				s=""
			if(h<10)
				h = "0"+h;
			if(mn<10)
				mn = "0"+mn;
			if(sec<10)
				sec = "0"+sec;
	
			reboursJours.innerHTML = j +" jour"+s;  
			reboursHeures.innerHTML = h +":"+ mn +":"+ sec;  
		}else
		{
			if(j==0 && h=="00" && mn=="00")
			{
				clearTimeout();
				if(numCible=='2')
				{
					reboursGeneral.style.display = "none";
				}else
				{
					compte_a_rebours(dateCible2,dateCible2,'2');
				}
			}	
		}
		  
		tRebour=setTimeout ("compte_a_rebours('"+dateCible1+"','"+dateCible2+"','"+numCible+"');", 1000);  
	}
	else
	{
		if(numCible=='2')
		{
			clearTimeout();
			reboursGeneral.innerHTML = "Event Over...";
		}else
		{
			compte_a_rebours(dateCible2,dateCible2,'2');
		}
	}

}  



