var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;

offsetX = 20;
offsetY = 0;
var toolTipSTYLE="";
function initToolTips()
{
	if(ns4||ns6||ie4)
	{
		if(ns4) toolTipSTYLE = document.toolTipLayer;
		else if(ns6) toolTipSTYLE = document.getElementById("toolTipLayer").style;
		else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;
		toolTipSTYLE.visibility = "visible";
		toolTipSTYLE.display = "none";
	}
}

function closeToolTip() {
	if(ns4) toolTipSTYLE.visibility = "hidden";
    else toolTipSTYLE.display = "none";
}

function toolTip(message)
{
  if(toolTip.arguments.length == 0) // hide
  {
	toolTipSTYLE.visibility = "visible";
	toolTipSTYLE.display = "none";
	return false;
  }
  else // show
  {
    var content = '<div class="infobull">' + message + '</div>';
    if(ns4)
    {
      toolTipSTYLE.document.write(content);
      toolTipSTYLE.document.close();
      toolTipSTYLE.visibility = "visible";
    }
    if(ns6)
    {
      document.getElementById("toolTipLayer").innerHTML = content;
      toolTipSTYLE.display='block'
    }
    if(ie4)
    {
      document.all("toolTipLayer").innerHTML=content;
      toolTipSTYLE.display='block'
    }
	
	if(ns4||ns6)
	{
		y = e.pageY;
		x = e.pageX;
	}
	else
	{
		y = event.y + document.body.scrollTop;
		x = event.x + document.body.scrollLeft;
	}
	
	toolTipSTYLE.left = x + offsetX;
	toolTipSTYLE.top = y + offsetY;
	return true;
  }
}

function setObj(ssmenu) {
	if (ie4) {
		return document.all[ssmenu]
	} else if (ns6) {
		return document.getElementById(ssmenu);
	}
}
/*function showMenu(ssmenu)
{
	var pageurl = String(document.location);
	info = pageurl.split('/');
	pageurl = pageurl.replace(info[0]+'//'+info[1]+info[2]+'/', '');
	affdoss = 0;
	if( pageurl.search("actualite") != -1 || pageurl == "" ) {
		affdoss = 1;
		items = new Array('com', 'pratik', 'doss');
	} else {
		items = new Array('actu', 'com', 'pratik', 'doss');
	}
	
	objet = setObj(ssmenu);
	if (objet.style.display == "") {
		objet.style.display = "none";
		document.images['im-'+ssmenu].src='http://www.avmaroc.com/images/plus.gif';
	} else {
		objet.style.display = "";
		document.images['im-'+ssmenu].src='http://www.avmaroc.com/images/moins.gif';
		for(i=0; i<items.length; i++) {
			if( items[i] != ssmenu ) {
				setObj(items[i]).style.display = "none";
				document.images['im-'+items[i]].src='http://www.avmaroc.com/images/plus.gif';
			}
		}
		//exep
		if(affdoss == 1 || pageurl.search("dossiers") != -1 ) {
			objet = setObj('doss');
			objet.style.display = "";
			document.images['im-doss'].src='http://www.avmaroc.com/images/moins.gif';
		}
	}
}*/
function showMenu(ssmenu) {
	objet = setObj(ssmenu);
	if (objet.style.display == "") {
		objet.style.display = "none";
		document.images['im-'+ssmenu].src='http://www.avmaroc.com/images/plus.gif';
	} else {
		objet.style.display = "";
		document.images['im-'+ssmenu].src='http://www.avmaroc.com/images/moins.gif';
	}
}
function showBloc(bloc)
{
	objet = setObj(bloc);
	if (objet.style.display == "") {
		objet.style.display = "none";
	} else {
		objet.style.display = "";
	}
}

function initMenu(ssmenu) {
	var pageurl = String(document.location);
	info = pageurl.split('/');
	pageurl = pageurl.replace(info[0]+'//'+info[2]+'/', '');
	if( pageurl.search("actualite") != -1 || pageurl == "" ) showMenu('doss');
	if( pageurl.search("agenda") != -1 ) showMenu('actu');
	showMenu(ssmenu);
}

function openPop(url,w,h) {
	var iLeft = (screen.width  - w) / 2 ;
	var iTop  = (screen.height - h) / 2 ;
	var sOptions = "toolbar=0,status=0,resizable=0,scrollbars=1" ;
		sOptions += ",width=" + w ; 
		sOptions += ",height=" + h ;
		sOptions += ",left=" + iLeft ;
		sOptions += ",top=" + iTop ;
		window.open( url, "POPup", sOptions ) ;
}

function openPopAnim(url,w,h) {
	var iLeft = (screen.width  - w) / 2 ;
	var iTop  = (screen.height - h) / 2 ;
	var sOptions = "toolbar=0,status=0,resizable=0,scrollbars=0" ;
		sOptions += ",width=" + w ; 
		sOptions += ",height=" + h ;
		sOptions += ",left=" + iLeft ;
		sOptions += ",top=" + iTop ;
		window.open( url, "POPup", sOptions ) ;
}

function EcrireCookie(nom, valeur,expires,path,domain,secure) {
	document.cookie=nom+"="+escape(valeur)+
	((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}

function affectId(frm,valId,valWhat) {
	document.forms[frm].id_ann.value = valId;
	document.forms[frm].action.value = valWhat;
	document.forms[frm].submit();
}

function resizePopUp(monImage, monTitre) {
	w = window.open('','chargement','width=10,height=10,top=100,left=100');
	w.document.write( "<html><head><title>"+  monTitre+"</title>\n" ); 
	w.document.write( "<script language='JavaScript'>\n"); 
	w.document.write( "IE5=NN4=NN6=false;\n"); 
	w.document.write( "if(document.all)IE5=true;\n"); 
	w.document.write( "else if(document.getElementById)NN6=true;\n"); 
	w.document.write( "else if(document.layers)NN4=true;\n"); 
	w.document.write( "function autoSize() {\n"); 
	w.document.write( "if(IE5) self.resizeTo(document.images[0].width+10,document.images[0].height+31)\n"); 
	w.document.write( "else if(NN6) self.sizeToContent();\n");
	w.document.write( "else window.resizeTo(document.images[0].width,document.images[0].height+20)\n"); 
	w.document.write( "self.focus();\n"); 
	w.document.write( "}\n</script>\n");
	w.document.write( "</head><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onLoad='javascript:autoSize();'>" );
	w.document.write( "<a href='javascript:window.close();'><img src='"+monImage+"' border=0 alt='"+monTitre+"'></a>" ); 
	w.document.write( "</body></html>" );
	w.document.close(); 
}
function verif_email(email) { 
   var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/
   return (reg.exec(email)!=null)
}
function favoris() 
{
if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 )) {
        window.external.addFavorite("http://www.avmaroc.com", "AtlasVista");
    } else {
        alert("Cette fonction n'est activée que dans Internet Explorer v5.0 ou + ...\n Tapez CTRL + D pour ajouter AtlasVista dans vos favoris !");
    }
}

function HomePage(obj)
{
    obj.style.behavior='url(#default#homepage)';
    obj.setHomePage('http://www.avmaroc.com');
}

//compteur de caractères
function restrictinput(maxlength,e,placeholder){
	if (window.event&&event.srcElement.value.length>=maxlength)
	return false
	else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
		var pressedkey=/[a-zA-Z0-9\.\,\/]/ 
		if (pressedkey.test(String.fromCharCode(e.which)))
		e.stopPropagation()
	}
}

function countlimit(maxlength,e,placeholder){
	var theform=eval(placeholder)
	var lengthleft=maxlength-theform.value.length
	var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
	if (window.event||e.target&&e.target==eval(placeholder)){
	if (lengthleft<0)
		theform.value=theform.value.substring(0,maxlength)
		placeholderobj.innerHTML=lengthleft
	}
}

function displaylimit(thename, theid, thelimit){
var theform=theid!=""? document.getElementById(theid) : thename
var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> char Max'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
	eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
	eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
	document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
	document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
}
}

String.prototype.trim = function() { 
	return this.replace(/(^\s*)|(\s*$)/g,''); 
}

//recherche rapide rencontres
function makechange(start, indice) {
	if(indice == 1) xindice = 2;
	else xindice = 1;
	option = '<select name="age'+ indice +'" onChange="makechange(this.value, ' + xindice + ')" style="width:41px;">';
	if(start != 0) {
		start++;
		for(i=18; i<100; i++) {
			if( indice == 2 && start == i )
				option += '<option value="'+ i +'" selected>'+ i +'</option>';
			else
				option += '<option value="'+ i +'">'+ i +'</option>';
		}
	} else {
		option += '<option value="0">--</option>';
	}
	option += '</select>';
	if(indice == 2) document.getElementById("age"+indice).innerHTML = option; 
}

function test() {
	k = 0;
	for(i=1; i<3; i++) {
		if( document.frmRecherche.elements[i].value != 0 ) 
			k++;
	}
	if(k == 0) {
		alert('Veuillez renseigner au moins 1 critère de recherche');
		return false;
	} else {
		if( document.frmRecherche.age2.value != 0 && (document.frmRecherche.age2.value<document.frmRecherche.age1.value) ) {
			alert('Age2 < Age1');
			return false;	
		}
	}
	return true;
}
function goAjax(page, data, Felement, contener) { 
	var xhr_object = null; 
	if(window.XMLHttpRequest) 
		xhr_object = new XMLHttpRequest();// Firefox 
	else if(window.ActiveXObject) 
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");// Internet Explorer 
	else { // XMLHttpRequest non supporté par le navigateur 
		alert(" Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		return; 
	} 
	xhr_object.open("POST", page, true); 
	xhr_object.onreadystatechange = function() { 
		if(contener != "") document.getElementById(contener).innerHTML = '<center><img src="http://www.avmaroc.com/images/loading.gif"><br>Chargement en cours...<br />Merci de patienter ...</center>';
		//Felement.disabled = true;
		
		if(xhr_object.readyState == 4){
			//Felement.disabled = false;
			document.getElementById(contener).innerHTML = xhr_object.responseText;
		} else {
			//Felement.disabled = true;	
		}
	} 
	
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
	xhr_object.send( data );
}