


var d = document;

function ecrirebalise(id, contenu)
{
document.getElementById(id).innerHTML = contenu;
}

function $(id) { return d.getElementById(id); }

function createXMLHttpRequest() {
  if(window.XMLHttpRequest) {
    try { 
      xmlHttpRequest = new XMLHttpRequest();
    } catch(e) { return null; }
  } else if(window.ActiveXObject) {
    try {
      xmlHttpRequest = 
        new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        xmlHttpRequest = 
          new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) { return null; }
    }
  } else return null;
  return xmlHttpRequest;
}



function callInProgress(xmlHttp) 
{
    switch ( xmlHttp.readyState ) 
    {
        case 1, 2, 3:
        return true;
        break;

        // Case 4 and 0
        default:
        return false;
        break;
    }
}

function pfile(fichier, data)
{
if(window.XMLHttpRequest) // firefox
xhr_object = new XMLHttpRequest();
else if(window.ActiveXObject) // IE
xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
else
return(false);
if ( callInProgress(xhr_object) ) {
xhr_object.abort();
}
xhr_object.open("POST", fichier, false);
xhr_object.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=iso-8859-1');
//xhr_object.onreadystatechange = handleAJAXReturn;
xhr_object.send(data);
if(xhr_object.readyState == 4) { 
	if(xhr_object.status == 200)
        {
            return(xhr_object.responseText);
        }
     else
        {
            return('ERREUR');
        }
	
}
else {return(false);}
}


function Goto(FILE, METHOD, DATA, id)
{
if( METHOD == 'GET' && DATA != null )
{
FILE += '?' + DATA;
DATA = null;
}

var httpRequestM = null;

if( window.XMLHttpRequest )
{ // Firefox
httpRequestM = new XMLHttpRequest();
}
else if( window.ActiveXObject )
{ // Internet Explorer
httpRequestM = new ActiveXObject( "Microsoft.XMLHTTP" );
}
else
{ // XMLHttpRequest non support� par le navigateur
return "Votre navigateur ne supporte pas les objets XMLHTTPRequest...";
}
if ( callInProgress(httpRequestM) ) {
httpRequestM.abort();
}
httpRequestM.open( METHOD , FILE , true );
if( METHOD == 'POST' ){ httpRequestM.setRequestHeader( "Content-type" , "application/x-www-form-urlencoded" );}
httpRequestM.send(DATA);
httpRequestM.onreadystatechange = function() {
if( httpRequestM.readyState == 4) {
	res=httpRequestM.responseText;
if(res!='' && id=='') {alert(res);}
if(id!=''){ecrirebalise( id , res);}//alert(res);
}
 }
}



function recupForm(id) {
formulaire = $(id);
elt = new Array();
retour = '';
for (var i = 0; i<formulaire.length; i++) {
//alert(formulaire.elements[i].type);
	if(formulaire.elements[i].name!=undefined && formulaire.elements[i].name!=''){
		if(formulaire.elements[i].type=='checkbox' && formulaire.elements[i].checked==false){
		retour = retour + '&'+formulaire.elements[i].name+'=0';
		} else {
		retour = retour + '&'+formulaire.elements[i].name+'='+encodeURIComponent(formulaire.elements[i].value);
		}
	}
}
return retour;
}


// FONCTION CHAINE
function IsNumeric(chaine) {
   var ValidChars = "0123456789.,";
   var IsNumber=true;
   var Char;
   for (i = 0; i < chaine.length && IsNumber == true; i++) 
      { 
      Char = chaine.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

  function checkDate(field)
  {
    var allowBlank = true;
    var minYear = 1902;
    var maxYear = (new Date()).getFullYear();

    var errorMsg = "";

    // regular expression to match required <em>date</em> format
    re = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
    
    if(field.value != '') {
      if(regs = field.value.match(re)) {
        if(regs[1] < 1 || regs[1] > 31) {
          errorMsg = "Le jour n'est pas valide: " + regs[1];
        } else if(regs[2] < 1 || regs[2] > 12) {
          errorMsg = "Le mois n'est pas valide: " + regs[2];
        } else if(regs[3] < minYear || regs[3] > maxYear) {
          errorMsg = "L'année n'est pas valide: " + regs[3] + " - doit être entre " + minYear + " et " + maxYear;
        }
      } else {
        errorMsg = "Format de la date incorrect: " + field.value;
      }
    } else if(!allowBlank) {
      errorMsg = "La date doit être renseignée";
    }
    
    if(errorMsg != "") {
      alert(errorMsg);
      field.focus();
      return false;
    }
    
    return true;
  }

function preinscription(){

}

function initFade(id) {
for (var i=0;i<11;i++){
	setOpacity(id, i);
	setTimeout('setOpacity("'+id+'", '+i+')',100*i);
}
return false;
}

function initClaire(id) {
for (var i=10;i>=0;i--){
	setOpacity(id, i);
	setTimeout('setOpacity("'+id+'", '+i+')',100*i);
}
return false;
}

function setOpacity(id, value)
{
	elt = d.getElementById(id);
	elt.style.opacity = value/10;
	elt.style.filter = 'alpha(opacity=' + value*10 + ')';
}


function getRegion(id, c){
$('cont_region'+c).innerHTML = pfile('get/region.php', 'id=' + id + '&c=' + c);
getVille(0, c);
}

function getVille(id, c){
$('cont_ville'+c).innerHTML = pfile('get/ville.php', 'id=' + id + '&c=' + c);
}


function getCSSValue(el, property, int)
{
   if (typeof(int) == 'undefined')
      var int = false;
   if (typeof(window.getComputedStyle) == 'function')
   {
      var styleValue = window.getComputedStyle(el, null)[property];
   }
   else
   {
      var styleValue = el.currentStyle[property];
   }
   if (int)
      return isNaN(parseInt(styleValue)) ? 0 : parseInt(styleValue);
   else
      return typeof(styleValue) != 'undefined' ? styleValue : '';
}


function display(appelant, appel, action) {
var elt = $(appel);
action = action.toString();

if(action != null){
if(action.indexOf('display')>-1) {
	if(getCSSValue(elt, 'display', '') != 'block' && getCSSValue(elt, 'display', '') != 'table-row'){
		if(action.indexOf('display')>-1) {
			initClaire(appel);
		}
		//alert(elt.tagName);
		if(elt.tagName == 'TR'){
		elt.style['display'] = 'table-row';
		} else {
		elt.style['display'] = 'block';
		}
		elt.style['visibility']='visible';
	} else {
		//initFade(appel);
		elt.style['display'] = 'none';
		elt.style['visibility']='hidden';
	}
}
if(action.indexOf('icone')>-1) {
	if(elt.style['display'] == 'none') {
		appelant.src = appelant.src.replace('moins', 'plus');
		if(elt.parentNode.tagName == 'FIELDSET'){ elt.parentNode.style['padding'] = '0%'; elt.parentNode.style['borderWidth'] = '0px'; } 
	} else {
		appelant.src = appelant.src.replace('plus', 'moins');
		if(elt.parentNode.tagName == 'FIELDSET'){ elt.parentNode.style['padding'] = '1%'; elt.parentNode.style['borderWidth'] = '1px'; } 
	}
}
	
if(action.indexOf('fleche')>-1) {
	if(elt.style['display'] == 'none') {
		appelant.src = appelant.src.replace('fb', 'fd');
	} else {
		appelant.src = appelant.src.replace('fd', 'fb');
	}
}

}


}



function pli_flash(id, v){
	var elt = $(id);
	if(v == '1'){
	elt.style.height = '100px';	
	//var o = elt.offsetHeight;
		var p = 1;
		//for(i=o; i>100; i--){
		//	setTimeout('document.getElementById("'+id+'").style.height = "'+i+'px"', p*1);
		//	p++;
		//}
	} else {
	elt.style.height = '500px';		
	var o = elt.offsetHeight;
		var p = 1;
		//for(i=o; i<500; i++){
		//	setTimeout('document.getElementById("'+id+'").style.height = "'+i+'px"', p*1);
		//	p++;
		//}
	}
}

function nb_toc(id){
$('nb_toc_'+id).innerHTML = 300 - $('toc_msg_'+id).value.length;
}

function nb_humeur(){
$('nb_humeur').innerHTML = 160 - $('nouvelle_humeur').value.length;
}

function humeurs(m){
h = '';
if(m == 2){h = $('nouvelle_humeur').value;}
$('humeur').innerHTML = pfile('get/humeur.php', 'm=' + m + '&h=' + h);
if(m == 1){ $('nouvelle_humeur').focus();}
if(m == 2){return false};
}

function profil(id){
	$('cont_profil').innerHTML = pfile('get/profil.php', 'id=' + id);
	pli_flash('flash', '1');
}

function toquer(id){
	display('', 'toc_'+id, 'display');
}

function toc(id){
	$('toc_'+id).innerHTML = pfile('get/toc.php', 'id=' + id + '&m=' + ($('toc_msg_'+id).value));
	if($('nb_toc').innerHTML > 0){$('nb_toc').innerHTML = $('nb_toc').innerHTML-1;}
	
}

function option(id, m){
	display('', 'option_'+id, 'display');
	$('option_'+id).innerHTML = pfile('get/option.php', 'id=' + id + '&m=' + m);
}

function bloquer(id){
	$('option_'+id).innerHTML = pfile('get/bloquer.php', 'id=' + id + '&m=' + $('remarque_blocage_'+id).value);
	return false;
}

function ami(id){
	$('option_'+id).innerHTML = pfile('get/ami.php', 'id=' + id + '&a=' + $('ami_'+id).value);
	return false;
}

function envoi_message(id){
	$('option_'+id).innerHTML = pfile('get/message.php', 'id=' + id + '&sujet=' + $('sujet_'+id).value + '&message=' + $('message_'+id).value);
	return false;
}

function avatar_modif(n){
$('avatar_modif').innerHTML = pfile('get/avatar.php', 'n=' + n);
}

function recherche_avancee(){
	display('', 'recherche_avancee', 'display');
}

function bouton(elt, img, m){
	url = getCSSValue(elt, 'backgroundImage', '');
	nimg = url.substring(url.lastIndexOf("/"), url.lastIndexOf("."));
	if(m == 1){
		if(img == '_o'){
			elt.style.backgroundImage = url.replace(nimg+".", "/"+nimg+"_o.");
		}
		if(img == 'menu' && getCSSValue(elt, 'marginTop', '') != "43px"){
			var p = 10;
		//initClaire(elt.id);
		for(i=0; i<43; i++){
			setTimeout('document.getElementById("'+elt.id+'").style.marginTop = "'+i+'px"', p*1);
			p++;
		}
		}
	} else {
		if(img == '_o'){
			elt.style.backgroundImage = url.replace("_o.", ".");
			
		}
		if(img == 'menu' && getCSSValue(elt, 'marginTop', '') != "43px"){
			var p = 5;
		for(i=43; i>0; i--){
			setTimeout('document.getElementById("'+elt.id+'").style.marginTop = "'+i+'px"', p*1);
			p++;
		}
		}
	
	}
}

