var IE = document.all?true:false
var tempX = 0
var tempY = 0
function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY

  return true
}

function mouseMove (evt) 
{ 

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.


// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s


// Main function to retrieve mouse x-y pos.s

		var x=0; var y=0;
		if (document.layers) {
			x=evt.x; y=evt.y;
		} 
		if (document.all) {
			x=event.clientX; y=event.clientY;
		} else {
			if (document.getElementById) {
				x=evt.clientX; y=evt.clientY; 
			}
		}
		document.getElementById('def').style.left = tempX+15;
		document.getElementById('def').style.top = tempY;
}
 
function popup(url, name, width, height, scroll, resizable) {
   winSet = "toolbar=no,location=no,directories=no,menubar=no,scrollbars="+scroll+",resizable="+resizable+"";
   winSet += ",width="+width +",height="+height+",left="+(screen.availWidth-width)/2+",top="+(screen.availHeight-height)/2;
   popwnd = window.open(url, name, winSet);
   popwnd.focus();
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function affiche(j) {
	if(document.getElementById(j).style.display=="block")
		document.getElementById(j).style.display="none";
	else
		document.getElementById(j).style.display="block";
}

function masque(j) {
	document.getElementById(j).style.display="none";
}
function affiche_on(j) {
	document.getElementById(j).style.display="block";
}

function afficheInscription(j,j2) {
		document.getElementById(j).style.display="block";
		document.getElementById(j2).style.display="none";
}

function writeDiv(texte, box) {
	document.getElementById(box).innerHTML = texte;
}

function sendAction(nompage,maform,monaction){
		theform = eval('this.document.'+maform);
		
		var inputs=document.getElementsByTagName("*");
		// Max, Ne rend plus obligatoire, l'insertion du champ faction.
		for (var i=0; i<inputs.length;i++){
			if ( inputs.item(i).name == "faction") {
				theform.faction.value = monaction;
			}
		}

		theform.method = "POST";
		mapage = nompage;
		theform.action = mapage;
		theform.submit();

}

function file(fichier, data) {
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);
	// variable envoyé par l'url
	xhr_object.open("POST", fichier, false);
	/* Effectue la requête en envoyant les données : */
	xhr_object.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr_object.send(data);
	if(xhr_object.readyState == 4) return(xhr_object.responseText);
	else return(false);
}

function affdefinition(definition,titre)
{
	document.getElementById('def').innerHTML = "<u>"+titre+":</u><br>"+definition;
	document.getElementById('def').style.display = "block";
	
	if (document.layers) 
	document.captureEvents(Event.MOUSEMOVE); 
	if (document.layers || document.all) 
	document.onmousemove = mouseMove; 
	if (document.addEventListener) 
	document.addEventListener('mousemove', mouseMove, true); 
	
}

/* Vérification de l'existence du contenu d'un input */
function verifinputjs(moninput, monform, inputname, mondiv, message) {
	leform = eval('this.document.'+monform);
	linput = eval('this.document.'+monform+'.'+inputname);
	
	// variable de controle
	erreur = 1;
	
	/* si l'input est rempli */
	if(linput.value != '') {
		document.getElementById(mondiv).style.display="none";
		ecrireDiv("", mondiv);
		erreur = 1;
	} else {
		document.getElementById(mondiv).style.display="block";
		ecrireDiv(message, mondiv);
		erreur = 2;
	}
	
	/* ne pas envoyer le formulaire si une erreur a été detecté */
	if(erreur == 2)
		return false;
	else
		return true;
}

/* Vérification de l'adresse email */
function verifemailjs(monemail, monform, mondiv, messageobligatoire, messageinvalide) {
	leform = eval('this.document.'+monform);

	monemail = monemail.replace('    ', '');
	monemail = monemail.replace('   ', '');
	monemail = monemail.replace('  ', '');
	monemail = monemail.replace(' ', '');
	leform.email.value=monemail;

	/* si l'email est rempli */
	if(monemail != '') {
		verifformatmailf = verifformatmail(monemail);
		
		if(verifformatmailf == true) {
			/* afficher le div erreur de email et afficher message erreur */
			document.getElementById(mondiv).style.display="none";
			ecrireDiv("", mondiv);
			erreur = 1;
		} else {
			document.getElementById(mondiv).style.display="block";
			ecrireDiv(messageinvalide, mondiv);
			erreur = 2;
		}
	} else {
		/* afficher le div erreur de email et afficher message erreur */
		document.getElementById(mondiv).style.display="block";
		ecrireDiv(messageobligatoire, mondiv);
		erreur = 2;
	}
	
	/* ne pas envoyer le formulaire si une erreur a été detecté */
	if(erreur == 2)
		return false;
	else
		return true;
}

function verifformatmail(email) {
	var reg = new RegExp('^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$', 'i');

	if(reg.test(email)) {
		return(true);
	} else {
		return(false);
	}
}

function ecrireDiv(montexte, mondiv) {
	document.getElementById(mondiv).innerHTML = montexte;
}

function divcontact(reference) {
	Modalbox.show('/vietnam/include/contact/index.php?reference=' + reference, {title: 'Villagegraphic.com - Nous contacter', width: 500});
	Modalbox.deactivate();
	return false;
}
function fermercontact() {
	Modalbox.hide();
	return false;
}
function fformcontact(emailobligatoire, emailinvalide, messageobligatoire) {
	erreuremail = verifemailjs(document.formcontact.email.value, 'formcontact', 'emailDivE', emailobligatoire, emailinvalide);
	erreurmessage = verifinputjs(document.formcontact.message.value, 'formcontact', 'message', 'messageDivE', messageobligatoire);
	
	if(erreuremail != true || erreurmessage != true) {
		Modalbox.resizeToContent();
		return false;
	} else {
		formcontactaction = file('/vietnam/pages/contact/contact.php', 'email=' + escape(document.formcontact.email.value) + '&nom=' + escape(document.formcontact.nom.value) + '&societe=' + escape(document.formcontact.societe.value) + '&reference=' + escape(document.formcontact.reference.value) + '&message=' + escape(document.formcontact.message.value) + '&type=' + escape(document.formcontact.type.value) + '&format=' + escape(document.formcontact.format.value));
		if(formcontactaction == 1) {
			document.getElementById('envoyer').style.display="none";
			document.getElementById('confirmation').style.display="block";
			Modalbox.resizeToContent();
			setTimeout("Modalbox.hide()",2000);
			return true;
		} else {
			return false;
		}
	}
}

