function veriForm() {
	if(document.getElementById('passw').value == '' || document.getElementById('nomdut').value == '') {
		document.getElementById('divnom').innerHTML = "<img src=\"error.png\" alt=\"\" class=\"midtop\"> <small>Vous devez indiquez vos identifiants</small>";
	}
	else {
		document.getElementById('logForm').submit();
	}
}

function ShowHide(id) {
if(document.getElementById(id).style.display == 'none') {
	document.getElementById(id).style.display = 'block';
	}
	else {
	document.getElementById(id).style.display = 'none';
	}
}

function verifnomanimal() {
  	sendcode('q='+ escape(document.getElementById('nomAnimal').value), 'actions/qsearch.php', 'POST', 'verifnomanimal');
}

function testuser() {
  	sendcode('l='+ escape(document.getElementById('nomdut').value), 'actions/utest.php', 'POST', 'testuser');
}

function testmdp() {
  	sendcode('l='+ escape(document.getElementById('nomdut').value) +'&m='+ escape(document.getElementById('passw').value), 'actions/mtest.php', 'POST', 'testmdp');
}

function verifmdpreg() {
  	if (document.getElementById('passw').value.length > 2 && document.getElementById('passwconf').value.length) {
    		if(document.getElementById('passw').value != document.getElementById('passwconf').value) {
			document.getElementById('verifpass').innerHTML = "<img src=\"error.png\" alt=\"\" class=\"midtop\"> <small>Les deux mots de passe ne sont pas identiques</small>";
			document.getElementById('verifpassconf').innerHTML = "<img src=\"error.png\" alt=\"\" class=\"midtop\"> <small>Les deux mots de passe ne sont pas identiques</small>";
		}
		else {
			document.getElementById('verifpass').innerHTML = "<img src=\"ok.gif\" alt=\"\" class=\"midtop\"> <small>Mots de passe identiques, continuez...</small>";
			document.getElementById('verifpassconf').innerHTML = "<img src=\"ok.gif\" alt=\"\" class=\"midtop\"> <small>Mots de passe identiques, continuez...</small>";
		}	
  	}
}

function verifmdpprofil() {
  	if (document.getElementById('npassw').value.length > 2 && document.getElementById('npasswconf').value.length) {
    		if(document.getElementById('npassw').value != document.getElementById('npasswconf').value) {
			document.getElementById('verifpass').innerHTML = "<img src=\"error.png\" alt=\"\" class=\"midtop\"> <small>Les deux mots de passe ne sont pas identiques</small>";
			document.getElementById('verifpassconf').innerHTML = "<img src=\"error.png\" alt=\"\" class=\"midtop\"> <small>Les deux mots de passe ne sont pas identiques</small>";
		}
		else {
			document.getElementById('verifpass').innerHTML = "<img src=\"ok.gif\" alt=\"\" class=\"midtop\"> <small>Mots de passe identiques, continuez...</small>";
			document.getElementById('verifpassconf').innerHTML = "<img src=\"ok.gif\" alt=\"\" class=\"midtop\"> <small>Mots de passe identiques, continuez...</small>";
		}	
  	}
}

function send_confirmail() {
  	if (document.getElementById('mail').value.length > 2) {
    		sendcode('m='+ escape(document.getElementById('mail').value), 'actions/sendconfmail.php', 'POST', 'divnom');
  	}
  	else  {
    		document.getElementById('divnom').innerHTML = "<img src=\"error.png\" alt=\"\" class=\"midtop\"> <small>Indiquez une adresse valide...</small>";
  	}
}

function verifmailreg() {
    	sendcode('mail='+ document.getElementById('mail').value, 'actions/emailtest.php', 'POST', 'verifmail');
}

function verifuser() {
  	sendcode('q='+ escape(document.getElementById('nomdut').value), 'actions/usearch.php', 'POST','verifnom');
}

function editnom(id) {
	sendcode('id='+ id, 'actions/editnom.php', 'POST', 'dnom'+ id);
}

function editage(id) {
	sendcode('id='+ id, 'actions/editage.php', 'POST', 'dage'+ id);
}

function editcat(id) {
	sendcode('id='+ id, 'actions/editcat.php', 'POST', 'dcat'+ id);
}

function modnom(id) {
	sendcode('nom='+ escape(document.getElementById('nom'+ id).value), 'modjx.php?id='+ id, 'POST', 'dnom'+ id);
}

function modage(id) {
	sendcode('age='+ escape(document.getElementById('age'+ id).value), 'modjx.php?id='+ id, 'POST', 'dage'+ id);
}

function modcat(id) {
	sendcode('cat='+ escape(document.getElementById('cat'+ id).value), 'modjx.php?id='+ id, 'POST', 'dcat'+ id);
}

function modcomment(id) {
	sendcode('comment='+ escape(document.getElementById('comment').value), 'modjx.php?id='+ id, 'POST', 'presentation');
}

function verifageanimal() {
	if(document.getElementById('age').value != '') document.getElementById('verifageanimal').innerHTML = '<img src="ok.gif" alt="" class="midtop"> Indiquez un age poru cet animal';
}

function verifdescanimal() {
	if(document.getElementById('description').value != '') document.getElementById('verifdescanimal').innerHTML = '<img src="ok.gif" alt="" class="midtop"> Vous n\'avez entr&eacute; aucune description';
}

function usermailedit(id) {
	sendcode('mail='+ id, 'actions/mailedit.php', 'POST', 'usermail');
}

function usermailmod(id) {
	sendcode('mail='+ escape(document.getElementById('editedmail').value), 'actions/mailmod.php', 'POST', 'usermail');
}

function addpicfrm(id) {
	sendcode('', 'addphoto.php?id='+ id, 'GET', 'addphoto');
}

function displayloading() {
	document.getElementById('indicateur').innerHTML = "<img src=\"ok.gif\" alt=\"\" class=\"midtop\" /> <small>Chargement...</small>";
}

function displayphotos(id, value) {
	sendcode('id='+ id +'&userisadmin='+ value, 'showpics.php', 'POST', 'addphoto');
}	

function switchphoto(id) {
	document.getElementById('photoctr').src = "redimpic.php?size=440&img=photos/" + id;
}

function createsupphoto(animal, photo) {
    	document.getElementById('supphoto').innerHTML = '<img src="suppr.gif" alt="Supprimer cette photo" onclick="supphoto('+ animal +', '+ photo +'); displayphotos('+ animal +', 1)" class="midtop" />';	
}	

function supphoto(animal, photo) {
	sendcode('animal='+ animal +'&photo='+ photo, 'delpic.php', 'POST', 'addphoto');
    	document.getElementById('supphoto').innerHTML = '';
	setTimeout('loadmainphoto('+animal+')',500);
	setTimeout('displayphotos('+animal+',1)',500);
}

function loadmainphoto(id) {
	sendcode('id='+ id, 'mainpic.php', 'POST', 'mainphoto');
}

function thumbs(id) {
	sendcode('id='+ id, 'minipic.php', 'POST', 'mphoto'+ id);
}

function thindex(id) {
	sendcode('id='+ id, 'indpic.php', 'POST', 'mphoto'+ id);
}

function editdesc(id) {
	sendcode('id='+ id, 'actions/editdesc.php', 'POST', 'presentation');
}

function votefor(id) {
	sendcode('id='+ id, 'actions/votefor.php', 'POST', 'wtvote');
}

function refreshnbvotes(id) {
	sendcode('id='+ id, 'actions/nbvotes.php', 'POST', 'nbvotes');
}

function sendmail(id) {
	sendcode('id='+ id, 'actions/sendmail.php', 'POST', 'listanimaux');
}

function send(id) {
	sendcode( 'mailto='+ escape(id) 
		+ '&sujet=' + escape(document.getElementById('sujet').value)
		+ '&message=' + escape(document.getElementById('message').value), 'actions/mailer.php', 'POST', 'sentmail'); 
}

function changesender() {
	document.getElementById('sender').value = 'Envoyer';
}

function addcomform(id) {
	document.getElementById('comments').innerHTML 	= '<form action="addcomment.php" method="post" class="com">'
							+ '<input type="hidden" name="idanimal" value="'+ id +'" />'
							+ '<img src="smileys/1.gif" alt=":)" onclick="document.getElementById(\'message\').value += \':)\'" /> '
							+ '<img src="smileys/2.gif" alt=":)" onclick="document.getElementById(\'message\').value += \':??:\'" /> '
							+ '<img src="smileys/3.gif" alt=":)" onclick="document.getElementById(\'message\').value += \':jap:\'" /> '
							+ '<img src="smileys/4.gif" alt=":)" onclick="document.getElementById(\'message\').value += \':hello:\'" /> '
							+ '<img src="smileys/5.gif" alt=":)" onclick="document.getElementById(\'message\').value += \':top:\'" /> '
							+ '<img src="smileys/6.gif" alt=":)" onclick="document.getElementById(\'message\').value += \':snif:\'" /> '
							+ '<img src="smileys/7.gif" alt=":)" onclick="document.getElementById(\'message\').value += \':ouin:\'" /> '
							+ '<img src="smileys/8.gif" alt=":)" onclick="document.getElementById(\'message\').value += \':hun:\'" /> '
							+ '<img src="smileys/9.gif" alt=":)" onclick="document.getElementById(\'message\').value += \':smile:\'" /> '
							+ '<img src="smileys/10.gif" alt=":)" onclick="document.getElementById(\'message\').value += \':non:\'" /> '
							+ '<textarea style="width:90%" cols="40" rows="10" name="comment" id="message"></textarea><br />'
							+ '<input type="submit" value="Envoyer" /> '
							+ '<input type="button" value="Annuler" onclick="window.location=\'animal.php?id='+ id +'\'" />'
							+ '</form>';
}

function genupload(id) {
	newpge = window.open('','new','width=350,height=100');
	newpge.document.write('<form action="upload.php" enctype="multipart/form-data" method="post">');
	newpge.document.write('<input type="hidden" name="MAX_FILE_SIZE" value="100000">');
	newpge.document.write('<input type="hidden" name="id" value="'+ id +'">');
	newpge.document.write('<input name="Champ1" type="file" id="Champ1"> ');
	newpge.document.write('<input type="submit" value="Envoyer"><br />');
	newpge.document.write('<small>Attention ! Le fichier ne dois pas peser plus de 98 Ko, et être au format .jpg. Si vous ne savez pas encore réduire la taille de la photo, <a href="http://www.1milliondamis.com/forum.php?viewtopic&fid=2&tid=7" target="_blank">visitez ce lien sur le forum</a></small>');
	newpge.document.write('</form>');
}

function sendcode(data, page, method, div) {
  	if (window.ActiveXObject) {
    		//Internet Explorer
    		var XhrObj = new ActiveXObject("Microsoft.XMLHTTP") ;
  	}
  	else {
    		var XhrObj = new XMLHttpRequest();
  	}

  	//définition de l'endroit d'affichage:
  	var content = document.getElementById(div);

  	//Ouverture du fichier en methode POST
  	XhrObj.open("POST", page);

  	//Ok pour la page cible
  	XhrObj.onreadystatechange = function() {
    		if (XhrObj.readyState == 4 && XhrObj.status == 200)
      		content.innerHTML = XhrObj.responseText ;
  	}   

  	XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  	XhrObj.send(data);
}