/*** Positionnement du foot ***/
function getWindowHeight() {
    var windowHeight=0;
    if (typeof(window.innerHeight)=='number') {
        windowHeight=window.innerHeight;
    }
    else {
     if (document.documentElement&&
       document.documentElement.clientHeight) {
         windowHeight = document.documentElement.clientHeight;
    }
    else {
     if (document.body&&document.body.clientHeight) {
         windowHeight=document.body.clientHeight;
      }
     }
    }
    return windowHeight;
}

function setFooter() {
    if (document.getElementById) {
        var windowHeight=getWindowHeight();
        if (windowHeight>0) {
            var contentHeight=
            document.getElementById('global').offsetHeight;
            var footerElement=document.getElementById('foot');
            var footerHeight=footerElement.offsetHeight;
        if (windowHeight-(contentHeight+footerHeight)>=0) {
            footerElement.style.position='relative';
            footerElement.style.top=
            (windowHeight-(contentHeight+footerHeight))+'px';
        }
        else {
            footerElement.style.position='static';
        }
       }
      }
}



/*** Pop-Up ***/
function popupCentree(page, largeur, hauteur, options)
{
    var top = (screen.height-hauteur)/2;
    var left = (screen.width-largeur)/2;
    window.open(page, "" ,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

function popupDynamiqueCentree(html, largeur, hauteur, options)
{
  var top = (screen.height-hauteur)/2;
  var left = (screen.width-largeur)/2;
	
	var generator = window.open("", "_blank","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
  generator.document.write(html);
  generator.document.close();
}



/*** Gestion de l'affichage dynamique d'éléments ***/
function visibilite(thingId)
{
  var targetElement;
  targetElement = document.getElementById(thingId) ;
  if (targetElement.style.display == "none")
  {
  	targetElement.style.display = "" ;
  }
	else
	{
  	targetElement.style.display = "none" ;
  }
  
	setFooter();
}

function openall(thingId)
{
  targetElement = document.getElementById(thingId) ;
  targetElement.style.display = "" ;
}

function closeall(thingId)
{
  targetElement = document.getElementById(thingId) ;
  targetElement.style.display = "none" ;
}



/*** Copier un objet dans le presse-papier  /!\ IE seulement /!\  ***/
function copy2Clipboard(obj)
{
	var textRange = document.body.createTextRange();
	textRange.moveToElementText(obj);
	textRange.execCommand("Copy");
}



/*** Vérification de formulaires ***/
function checkemail(EMAIL)
{
	var place = EMAIL.indexOf("@",1);
	var point = EMAIL.indexOf(".",place+1);
	var point2 = EMAIL.lastIndexOf(".")+1;
	if ((place > -1) && (EMAIL.length >= 7) && (point > 1) && (point2 != EMAIL.length))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function sub_annu()
{
	if ((document.annu.alfortvilleHidden.value == '0') && (document.annu.creteilHidden.value == '0') && (document.annu.limeilHidden.value == '0'))
	{
  	alert('Vous devez au moins choisir une ville dans le cadre "Localisation"');
  	return false;
	}
}

function sub_annuins()
{
	if (document.annuins.nom.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "NOM" est obligatoire');
		document.annuins.nom.focus();
		return false;
	}
	if (document.annuins.adresse.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "ADRESSE" est obligatoire');
		document.annuins.adresse.focus();
		return false;
	}
	if (document.annuins.cp.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "CODE POSTAL" est obligatoire');
		document.annuins.cp.focus();
		return false;
	}
	if (document.annuins.ville.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "VILLE" est obligatoire');
		document.annuins.ville.focus();
		return false;
	}
	if (document.annuins.telephone.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "TELEPHONE" est obligatoire');
		document.annuins.telephone.focus();
		return false;
	}
	if (document.annuins.numero_siret.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "N° SIRET" est obligatoire');
		document.annuins.numero_siret.focus();
		return false;
	}
}

function sub_contact()
{
	if (document.contact.nom.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "NOM" est obligatoire');
		document.contact.nom.focus();
		return false;
	}
	if (!checkemail(document.contact.email.value.replace(/[\s]+$/g,'')))
	{
		alert('Un email valide est obligatoire');
		document.contact.email.focus();
		return false;
	}
	if (document.contact.message.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "MESSAGE" est obligatoire');
		document.contact.message.focus();
		return false;
	}
}

function sub_offrelocaux()
{
	if ((document.offrelocaux.venteHidden.value == '0') && (document.offrelocaux.locationHidden.value == '0'))
	{
		alert('Le champs "TRANSACTION" est obligatoire');
		return false;
	}
	if ((document.offrelocaux.terrainHidden.value == '0') && (document.offrelocaux.bureauxHidden.value == '0') && (document.offrelocaux.activiteHidden.value == '0') && (document.offrelocaux.entreprotHidden.value == '0') && (document.offrelocaux.commerceHidden.value == '0') && (document.offrelocaux.autreHidden.value == '0'))	
	{
		alert('Le champs "TYPE DE BIEN" est obligatoire');
		return false;
	}
	if ((document.offrelocaux.proprietaireHidden.value == '0') && (document.offrelocaux.locataireHidden.value == '0') && (document.offrelocaux.commercialisateurHidden.value == '0') && (document.offrelocaux.commercialHidden.value == '0') )
	{
		alert('Le champs "CONTACT > Interlocuteur" est obligatoire');
		return false;
	}
	if (document.offrelocaux.nomChp.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "CONTACT > Nom" est obligatoire');
		document.offrelocaux.nomChp.focus();
		return false;
	}
	if (document.offrelocaux.prenomChp.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "CONTACT > Prénom" est obligatoire');
		document.offrelocaux.prenomChp.focus();
		return false;
	}
	if (document.offrelocaux.adresseChp.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "CONTACT > Adresse" est obligatoire');
		document.offrelocaux.adresseChp.focus();
		return false;
	}
	if (document.offrelocaux.cpChp.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "CONTACT > Code Postal" est obligatoire');
		document.offrelocaux.cpChp.focus();
		return false;
	}
	if (document.offrelocaux.villeChp.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "CONTACT > Ville" est obligatoire');
		document.offrelocaux.villeChp.focus();
		return false;
	}
	if (document.offrelocaux.telChp.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "CONTACT > Tel" est obligatoire');
		document.offrelocaux.telChp.focus();
		return false;
	}
	if ((document.offrelocaux.emailChp.value.replace(/[\s]+$/g,'') != '') && (!checkemail(document.offrelocaux.emailChp.value.replace(/[\s]+$/g,''))))
	{
		alert('L\'adresse email entrée est invalide');
		document.offrelocaux.emailChp.focus();
		return false;
	}
}

function sub_demandelocaux()
{
	if ((document.demandelocaux.achatHidden.value == '0') && (document.demandelocaux.locationHidden.value == '0'))
	{
		alert('Le champs "TRANSACTION" est obligatoire');
		return false;
	}
	if ((document.demandelocaux.terrainHidden.value == '0') && (document.demandelocaux.bureauxHidden.value == '0') && (document.demandelocaux.activiteHidden.value == '0') && (document.demandelocaux.entreprotHidden.value == '0') && (document.demandelocaux.commerceHidden.value == '0') && (document.demandelocaux.autreHidden.value == '0'))	
	{
		alert('Le champs "TYPE DE BIEN" est obligatoire');
		return false;
	}
	if (document.demandelocaux.nomChp.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "CONTACT > Nom" est obligatoire');
		document.demandelocaux.nomChp.focus();
		return false;
	}
	if (document.demandelocaux.prenomChp.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "CONTACT > Prénom" est obligatoire');
		document.demandelocaux.prenomChp.focus();
		return false;
	}
	if (document.demandelocaux.adresseChp.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "CONTACT > Adresse" est obligatoire');
		document.demandelocaux.adresseChp.focus();
		return false;
	}
	if (document.demandelocaux.cpChp.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "CONTACT > Code Postal" est obligatoire');
		document.demandelocaux.cpChp.focus();
		return false;
	}
	if (document.demandelocaux.villeChp.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "CONTACT > Ville" est obligatoire');
		document.demandelocaux.villeChp.focus();
		return false;
	}
	if (document.demandelocaux.telChp.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champs "CONTACT > Tel" est obligatoire');
		document.demandelocaux.telChp.focus();
		return false;
	}
	if ((document.demandelocaux.emailChp.value.replace(/[\s]+$/g,'') != '') && (!checkemail(document.demandelocaux.emailChp.value.replace(/[\s]+$/g,''))))
	{
		alert('L\'adresse email entrée est invalide');
		document.demandelocaux.emailChp.focus();
		return false;
	}
}

function sub_tousavelo()
{
	if (document.tousavelo.nom.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champ "NOM" est obligatoire');
		document.tousavelo.nom.focus();
		return false;
	}
	if (document.tousavelo.prenom.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champ "PRENOM" est obligatoire');
		document.tousavelo.prenom.focus();
		return false;
	}
	if (document.tousavelo.date_naissance.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champ "DATE DE NAISSANCE" est obligatoire');
		document.tousavelo.date_naissance.focus();
		return false;
	}
	if (document.tousavelo.adresse.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champ "ADRESSE" est obligatoire');
		document.tousavelo.adresse.focus();
		return false;
	}
	if (document.tousavelo.cp.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champ "CODE POSTAL" est obligatoire');
		document.tousavelo.cp.focus();
		return false;
	}
	if (document.tousavelo.ville.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champ "VILLE" est obligatoire');
		document.tousavelo.ville.focus();
		return false;
	}
	if (!checkemail(document.tousavelo.email.value.replace(/[\s]+$/g,'')))
	{
		alert('Un email valide est obligatoire');
		document.tousavelo.email.focus();
		return false;
	}
	if (document.tousavelo.club.value.replace(/[\s]+$/g,'') == '')
	{
		alert('Le champ "CLUB" est obligatoire');
		document.tousavelo.email.focus();
		return false;
	}	
	if ((document.tousavelo.ffcHidden.value == '0') && (document.tousavelo.ffctHidden.value == '0') && (document.tousavelo.autresHidden.value == '0') && (document.tousavelo.non_licencieHidden.value == '0'))
	{
		alert('Le champ "LICENCIE" est obligatoire');
		return false;
	}
}



/*** Gestion de la valeur du champs du moteur de recherche ***/
function rechercheClick()
{
	document.getElementById('ajaxField_recherche').style.color = '#3333FF';
	
	if (document.recherche.ajaxField_recherche.value == 'recherche')
	{
		document.recherche.ajaxField_recherche.value = '';
	}
}

function rechercheBlur()
{
	if (document.recherche.ajaxField_recherche.value == '')
	{
		document.recherche.ajaxField_recherche.value = 'recherche';
		document.getElementById('ajaxField_recherche').style.color = '#666666';
	}
}

function rechercheKeyup()
{
	if (typeof ajaxTimeout_recherche != 'undefined')
	{
		clearTimeout(ajaxTimeout_recherche);
		ajaxTimeout_recherche = setTimeout('ajaxDelay_recherche()', 1000);
	}
	else
	{
		ajaxTimeout_recherche = setTimeout('ajaxDelay_recherche()', 1000);
	}
	
	if (document.recherche.ajaxField_recherche.value.length < 3)
	{
		document.getElementById('ajaxBox_recherche').style.display = 'none';
	}
}

