/**
* Méthode init
*/
function init() {

	}

/**
* Méthode anti spam
*/
function noSpam(user,domain) {

	locationstring = "mailto:" + user + "@" + domain;

	window.location = locationstring;

	}

/**
* Méthode anti click droit
*/
function killRightClick(mButton)

{ 

return false;

}

document.oncontextmenu = killRightClick; 


function getXhr(){
					var xhr = null; 
	if(window.XMLHttpRequest) // Firefox et autres
	   xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
	   try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
	}
	else { // XMLHttpRequest non supportÃ© par le navigateur 
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	   xhr = false; 
	} 
					return xhr
}

/**
* Méthode pour zapper les mois dans le calendrier
*/
function changeMonth(date){
	var xhr = getXhr()
	// On dÃ©fini ce qu'on va faire quand on aura la rÃ©ponse
	xhr.onreadystatechange = function(){
		// On ne fait quelque chose que si on a tout reÃ§u et que le serveur est ok
		if(xhr.readyState == 4 && xhr.status == 200){
			var html = xhr.responseText;
			document.getElementById('calendar_totem').innerHTML = html;
		}
	}
	xhr.open("POST","/page/xhttp_calendrier.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("cal1_date=" + date);
}

/**
* Méthode afficher une image en grand
*/
function affImg(id, obj){
	var xhr = getXhr()
	// On dÃ©fini ce qu'on va faire quand on aura la rÃ©ponse
	xhr.onreadystatechange = function(){
		// On ne fait quelque chose que si on a tout reÃ§u et que le serveur est ok
		if(xhr.readyState == 4 && xhr.status == 200){
			var objOverlay = document.getElementById('overlay');
			var objImgbox = document.getElementById('imgbox');
			
			var html = xhr.responseText;
			
			var posY = getPosy();
			var posX = getPosx();
			
			objImgbox.innerHTML = html;
			objOverlay.style.display = 'block';
			objImgbox.style.display = 'block';
			
			objImgbox.style.top = posY + 5  + 'px';
			objImgbox.style.left = posX - 410  + 'px';
		}
	}
	xhr.open("POST","/page/xhttp_pix.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("id=" + id + "&m=pix");
}

/**
* Méthode next image
*/
function next(id){
	affImg(eval(id*1+1))
}

/**
* Méthode previous image
*/
function previous(id){
	affImg(eval(id*1-1))
}

/**
* Méthode ferme image
*/
function close(){
	document.getElementById('imgbox').style.display = 'none';
	document.getElementById('overlay').style.display = 'none';
}

function getPosy() {
	
 	var yScroll;

	if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	} else {
		yScroll = window.pageYOffset;
	}
	return 	yScroll;	
}

function getPosx() {
	
	var pos = document.body.clientWidth/2 ;
	
	return pos;
}

/**
* Méthode afficher une image en grand
*/
function abo(){
	var xhr = getXhr()
	// On dÃ©fini ce qu'on va faire quand on aura la rÃ©ponse
	xhr.onreadystatechange = function(){
		// On ne fait quelque chose que si on a tout reÃ§u et que le serveur est ok
		if(xhr.readyState == 4 && xhr.status == 200){
			var objAbo = document.getElementById('abo');
			var mailabo = document.getElementById('mailabo').value;
			var html = xhr.responseText;

			objAbo.innerHTML = html;
		}
	}
	xhr.open("POST","/page/xhttp_abo.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("mail=" + document.getElementById('mailabo').value);
}

/**
* Méthode dump 
*/
function dump(arr,level) {
var dumped_text = "";
if(!level) level = 0;

//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += "    ";

if(typeof(arr) == 'object') { //Array/Hashes/Objects
 for(var item in arr) {
  var value = arr[item];
 
  if(typeof(value) == 'object') { //If it is an array,
   dumped_text += level_padding + "'" + item + "' ...\n";
   dumped_text += dump(value,level+1);
  } else {
   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
  }
 }
} else { //Stings/Chars/Numbers etc.
 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
} 




/**
* Méthode addsmiley 
*/
function addsmiley(n)
{
document.msg.msg.value=document.msg.msg.value + n;
}


/**
* Méthode valid form guestbook 
*/
function valid() {
	if(document.msg.msg.value=="" || document.msg.pseudo.value=="" || document.msg.ville.value=="") {
		alert("Veuillez renseigner Pseudo, Ville et Message correctement! Merci.");
	} else {
		guestbook(1);
	}
}

/**
* Méthode afficher guestbook
*/
function guestbook(index){
	var xhr = getXhr()
	// On dÃ©fini ce qu'on va faire quand on aura la rÃ©ponse
	xhr.onreadystatechange = function(){
		// On ne fait quelque chose que si on a tout reÃ§u et que le serveur est ok
		if(xhr.readyState == 4 && xhr.status == 200){
			var objPage = document.getElementById('page');
			var html = xhr.responseText;

			objPage.innerHTML = html;
		}
	}
	xhr.open("POST","/page/xhttp_guestbook.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=iso-8859-1');
	if (index != null) {
		xhr.send("index=" + index + "&ecrire=oui&pseudo=" + document.msg.pseudo.value + "&mail=" + document.msg.mail.value + "&url=" + document.msg.url.value + "&ville=" + document.msg.ville.value + "&msg=" + document.msg.msg.value);
	} else {
		xhr.send("index=0&ecrire=oui&pseudo=" + document.msg.pseudo.value + "&mail=" + document.msg.mail.value + "&url=" + document.msg.url.value + "&ville=" + document.msg.ville.value + "&msg=" + document.msg.msg.value);
	}
}


/**
* Méthode filtre form annuaire 
*/
function filtre() {
	if(document.cp.cp.value=="") {
		alert("Veuillez renseigner le Code Postal correctement! Merci.");
	} else {
		annuaire(document.cp.cp.value);
	}
}

/**
* Méthode filtre annuaire
*/
function annuaire(cp){
	var xhr = getXhr()
	// On dÃ©fini ce qu'on va faire quand on aura la rÃ©ponse
	xhr.onreadystatechange = function(){
		// On ne fait quelque chose que si on a tout reÃ§u et que le serveur est ok
		if(xhr.readyState == 4 && xhr.status == 200){
			var html = xhr.responseText;
			document.getElementById('page').innerHTML = html;
		}
	}
	xhr.open("POST","/page/xhttp_annuaire.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("cp=" + cp);
}

/**
* Méthode afficher un contact
*/
function affConcessionnaire(id, obj){
	var xhr = getXhr()
	// On dÃ©fini ce qu'on va faire quand on aura la rÃ©ponse
	xhr.onreadystatechange = function(){
		// On ne fait quelque chose que si on a tout reÃ§u et que le serveur est ok
		if(xhr.readyState == 4 && xhr.status == 200){
			var objOverlay = document.getElementById('overlay');
			var objImgbox = document.getElementById('imgbox');
			
			var html = xhr.responseText;
			
			var posY = getPosy();
			var posX = getPosx();
			
			objImgbox.innerHTML = html;
			objOverlay.style.display = 'block';
			objImgbox.style.display = 'block';
			
			objImgbox.style.top = posY + 5  + 'px';
			objImgbox.style.left = posX - 410  + 'px';
		}
	}
	xhr.open("POST","/page/xhttp_concessionnaire.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("id=" + id);
}
