// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

function confirm_entry()
{
input_box=confirm("Êtes-vous certain de vouloir poursuivre la suppression ?");
if (input_box==true)

{ 

}

else
{
return (false);
}

}
// Fonction qui vérifie qu'on veuille vraiment supprimer le produit
function confirm_delete()
{
input_box=confirm("Êtes-vous certain de vouloir enlever ce produit de votre panier ?");
if (input_box==true)
{ 
	return(true); 
} else {
	return (false);
}

}

// Fonction qui vérifie qu'on veuille vraiment supprimer le produit
function confirm_TR()
{
input_box=confirm("Êtes-vous certain de vouloir transférer ce concours sur troisrivieresplus.net ?");
if (input_box==true)
{ 
	return(true); 
} else {
	return (false);
}

}

// Fonction qui vérifie qu'on veuille vraiment supprimer le produit
function confirm_deleteEng()
{
input_box=confirm("Do you really want to remove this item from your cart ?");
if (input_box==true)
{ 
	return(true); 
} else {
	return (false);
}

}

// Fonction qui sert à vérifier si l'information entrée est un courriel valide

function CheckEmail(EMailToChk,Message)
{
var acomm=false;
var point=false;
var LAP=false;

	a = EMailToChk.value;

	for(tmp=0;tmp<a.length;tmp++)
	{
		charac = a.substring(tmp,tmp+1);
		if (charac == "@") acomm=true;
		if (acomm)
		{
			if (charac == ".") point=true;
		}
		if (point)
		{
			if ( ( (charac >= "A") && (charac <="Z") ) ||( (charac >="a") && (charac <="z") ) ) LAP=true;
		}
	}

	if (!(acomm && point && LAP))
	{
		alert(Message + " est invalide");
		EMailToChk.focus();
		return(false);
	}
	return(true);
}

// Fonction qui sert à vérifier si l'information entrée est un courriel valide

function CheckEmailEng(EMailToChk,Message)
{
var acomm=false;
var point=false;
var LAP=false;

	a = EMailToChk.value;

	for(tmp=0;tmp<a.length;tmp++)
	{
		charac = a.substring(tmp,tmp+1);
		if (charac == "@") acomm=true;
		if (acomm)
		{
			if (charac == ".") point=true;
		}
		if (point)
		{
			if ( ( (charac >= "A") && (charac <="Z") ) ||( (charac >="a") && (charac <="z") ) ) LAP=true;
		}
	}

	if (!(acomm && point && LAP))
	{
		alert(Message + " is invalid");
		EMailToChk.focus();
		return(false);
	}
	return(true);
}

// Vérifie que le code postal est bien entré

function CheckCP(CPToChk)
{
var CPOK=true;

	a = CPToChk;
	
	if (a.length != 7) CPOK=false;
	for (tmp=0;tmp<7;tmp++)
	{
		charac = a.substring(tmp,tmp+1);
		if ((tmp == 0) || (tmp == 2) || (tmp == 5))
		{
			if (!( ((charac >= "A") && (charac <="Z")) ||((charac >="a")&&(charac <="z")) )) CPOK=false;
		}
		if ((tmp == 1) || (tmp == 4) || (tmp == 6))
		{
			if ((charac < "0") || (charac > "9")) CPOK=false;
		}
		if (tmp == 3)
		{
			if (charac != " ") CPOK=false;
		}
	}
	if (!(CPOK))
	{
		alert("Le code postal n'est pas valide, veuillez entrer le code postal dans le format suivant : A9A 9A9");
		return(false);
	}
	return(true);
}
// Vérifie que le "ZIP code" est bien entré

function CheckZIP(ZIPToChk)
{
var ZIPOK=true;

	a = ZIPToChk;
	
	if (a.length != 10) CPOK=false;
	for (tmp=0;tmp<10;tmp++)
	{
		charac = a.substring(tmp,tmp+1);
		if (tmp != 5)
		{
			if ((charac < "0") || (charac > "9")) ZIPOK=false;
		}
		if (tmp == 5)
		{
			if (charac != "-") ZIPOK=false;
		}
	}
	if (!(ZIPOK))
	{
		return(false);
	}
	return(true);
}
// Vérifie que l'information entrée est bien de type numérique

function CheckNumber(NumToChk,Message)
{

	a = NumToChk.value;
	
	for (tmp=0;tmp<a.length;tmp++)
	{
		charac = a.substring(tmp,tmp+1);
		if (charac<"0" || charac>"9")
		{
		  if ((charac != ".") && (charac != ",")) 
		  {
		  	alert(Message + " doit être un nombre");
			NumToChk.focus();
			return(false);
		  }
		}
	}	
	return(true);
}
// Vérifie que l'information entrée est bien de type numérique

function CheckNumberEng(NumToChk,Message)
{

	a = NumToChk.value;
	
	for (tmp=0;tmp<a.length;tmp++)
	{
		charac = a.substring(tmp,tmp+1);
		if (charac<"0" || charac>"9")
		{
		  if ((charac != ".") && (charac != ",")) 
		  {
		  	alert(Message + " must be a number");
			NumToChk.focus();
			return(false);
		  }
		}
	}	
	return(true);
}
// Vérifie que l'information entrée est bien de type numérique entière

function CheckNumberInt(NumToChk,Message)
{

	a = NumToChk.value;
	
	for (tmp=0;tmp<a.length;tmp++)
	{
		charac = a.substring(tmp,tmp+1);
		if (charac<"0" || charac>"9")
		{
			alert(Message + " doit être un nombre");
			NumToChk.focus();
			return(false);
		}
	}
	return(true);
}
// Vérifie que l'information entrée est bien de type numérique entière

function CheckNumberIntEng(NumToChk,Message)
{

	a = NumToChk.value;
	
	for (tmp=0;tmp<a.length;tmp++)
	{
		charac = a.substring(tmp,tmp+1);
		if (charac<"0" || charac>"9")
		{
			alert(Message + " must be a number");
			NumToChk.focus();
			return(false);
		}
	}
	return(true);
}

// Vérifie que le numéro de téléphone a été entrée avec la bonne syntaxe

function CheckTel(TelToChk)
{

var TelOK = true;

a= TelToChk;
if (a.length != 12) TelOK = false;
for (tmp=0;tmp<=11;tmp++)
{
	charac = a.substring(tmp,tmp+1);
	
	if ((tmp == 3) || (tmp == 7))
		if (charac != "-") TelOK = false;	
	if ((tmp != 3) && (tmp != 7))
		if (charac <"0" || charac > "9") TelOK = false;	
}

if (!(TelOK)) 
{
return(false);
}

return(true);
}

// Vérifie si la date est dans le bon format

function CheckDate(DateToChk,Message)
{
//Format jj/mm/aaaa

	var err=0;
	var psj=0;
	a= DateToChk.value;
	if (a.length != 10) err=1
	b = a.substring(0, 2)// Jour
	c = a.substring(2, 3)// '/' ou '-'
	d = a.substring(3, 5)// Mois
	e = a.substring(5, 6)// '/' ou '-'
	f = a.substring(6, 10)// Année
	
	//Vérification des erreurs de base
	if (d<1 || d>12) err = 1;
	if ((c != '/') && (c != '-')) err = 1;
	if (b<1 || b>31) err = 1;
	if ((e != '/') && (c != '-')) err = 1;
	if (f<0 || f>9999) err = 1;
	
	//Vérification des erreurs avancées

	// Mois à 30 jour
	if (d==4 || d==6 || d==9 || d==11){
		if (b==31) err=1
	}

	// Février, année bisextile
	if (d==2){
		// feb
		var g=parseInt(f/4)
		if (isNaN(g)) {
			err=1
		}

		if (b>29) err=1
		if (b==29 && ((f/4)!=parseInt(f/4))) err=1
	}

	if (err==1){
		alert("La "+ Message + " n'est pas valide. Veuillez entrer la date dans le format jj/mm/aaaa ou jj-mm-aaaa");
		DateToChk.focus();
		return (false);
	}
	else{
		return (true);
	}

}

// Vérifie si la date est dans le bon format

function CheckDateAMJ(DateToChk,Message)
{
//Format aaaa-mm-jj

	var err=0;
	var psj=0;
	a= DateToChk.value;
	if (a.length != 10) err=1
	f = a.substring(0, 4)// Année
	c = a.substring(4, 5)// '/' ou '-'
	d = a.substring(5, 7)// Mois
	e = a.substring(7, 8)// '/' ou '-'	
	b = a.substring(8, 10)// Jour
	
	
	//Vérification des erreurs de base
	if (d<1 || d>12) err = 1;
	if ((c != '/') && (c != '-')) err = 1;
	if (b<1 || b>31) err = 1;
	if ((e != '/') && (c != '-')) err = 1;
	if (f<0 || f>9999) err = 1;
	
	//Vérification des erreurs avancées

	// Mois à 30 jour
	if (d==4 || d==6 || d==9 || d==11){
		if (b==31) err=1
	}

	// Février, année bisextile
	if (d==2){
		// feb
		var g=parseInt(f/4)
		if (isNaN(g)) {
			err=1
		}

		if (b>29) err=1
		if (b==29 && ((f/4)!=parseInt(f/4))) err=1
	}

	if (err==1){
		alert("La "+ Message + " n'est pas valide. Veuillez entrer la date dans le format aaaa-mm-jj ou aaaa/mm/jj");
		DateToChk.focus();
		return (false);
	}
	else{
		return (true);
	}

}

function CheckDateAMJEng(DateToChk,Message)
{
//Format aaaa-mm-jj

	var err=0;
	var psj=0;
	a= DateToChk.value;
	if (a.length != 10) err=1
	f = a.substring(0, 4)// Année
	c = a.substring(4, 5)// '/' ou '-'
	d = a.substring(5, 7)// Mois
	e = a.substring(7, 8)// '/' ou '-'	
	b = a.substring(8, 10)// Jour
	
	
	//Vérification des erreurs de base
	if (d<1 || d>12) err = 1;
	if ((c != '/') && (c != '-')) err = 1;
	if (b<1 || b>31) err = 1;
	if ((e != '/') && (c != '-')) err = 1;
	if (f<0 || f>9999) err = 1;
	
	//Vérification des erreurs avancées

	// Mois à 30 jour
	if (d==4 || d==6 || d==9 || d==11){
		if (b==31) err=1
	}

	// Février, année bisextile
	if (d==2){
		// feb
		var g=parseInt(f/4)
		if (isNaN(g)) {
			err=1
		}

		if (b>29) err=1
		if (b==29 && ((f/4)!=parseInt(f/4))) err=1
	}

	if (err==1){
		alert("The "+ Message + " is invalid. Please enter your date in the following format : aaaa-mm-jj");
		DateToChk.focus();
		return (false);
	}
	else{
		return (true);
	}

}

function DateCmp(DateMin,DateMax,Message)
{
	var a = DateMin.value;
	var b = DateMax.value;

	aJour = a.substring(0, 2)// Jour date minimum
	aMois = a.substring(3, 5)// Mois date minimum
	aAnnee = a.substring(6, 10)// Année date minimum

	bJour = b.substring(0, 2)// Jour date maximum
	bMois = b.substring(3, 5)// Mois date maximum
	bAnnee = b.substring(6, 10)// Année date maximum
	
	// Vérification sur l'année
	if (bAnnee < aAnnee)
	{
		alert(Message);
		return(false);
	} else if (bAnnee > aAnnee) {
				return(true);
		   }
	// Vérification sur le mois	   
	if (bMois < aMois)
	{
		alert(Message);
		return(false);
	} else if (bMois > aMois) {
				return(true);
		   }
	// Vérification sur le jour	   
	if (bJour < aJour)
	{
		alert(Message);
		return(false);
	} else if (bJour > aJour) {
				return(true);
		   } else {
		   		alert(Message);
		   }
}

function GetRadio(obj)
{
	var i;

	for( i=0; i<obj.length; ++i)
		if( obj[i].checked)
			return obj[i].value;
	// default (non selected)
	return -1;
}
function FormatNumber(expr, decplaces) {

var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));

while (str.length <= decplaces) {
str = "0" + str;
}

var decpoint = str.length - decplaces;

return str.substring(0,decpoint) + "." + str.substring(decpoint, str.length);

} //End function FormatNumber 
function IsEmpty(champ,Message)
{
	if (champ.value == "")
	{
		if (Message != "")
		{
			alert(Message);
			champ.focus();
		}
		return(true);
	}
	return(false);
}

function sajax_init_object() {
 
 			
 			var A;
			try {
				A=new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					A=new ActiveXObject("Microsoft.XMLHTTP");
				} catch (oc) {
					A=null;
				}
			}
			if(!A && typeof XMLHttpRequest != "undefined")
				A = new XMLHttpRequest();
			if (!A)
				alert("Could not create connection object.");
			return A;
		}

function callURL(url,leID) 
{
	document.getElementById(leID).innerHTML = "...";
	var uri;
	var post_data;
	uri = url;
	x = sajax_init_object();
	
	x.open("GET", uri, true);
	
	x.onreadystatechange = function() {
	if (x.readyState != 4) 
		return;
	
	
	document.getElementById(leID).innerHTML = x.responseText;
	
	var status;
	var data;
	status = x.responseText.charAt(0);
	data = x.responseText.substring(2);
	if (status == "-") 
		alert("Error: " + data);
	
		}
	x.send(post_data);
	
}

function getMouseY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
	if (document.documentElement){
		theST = document.documentElement.scrollTop;
	}
	if (theST == 0 && document.body && document.body.scrollTop) {
		theST = document.body.scrollTop;
	}
	
    tempY = event.clientY + theST;
  } else {  // grab the x-y pos.s if browser is NS
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  return tempY;
}
function getMouseX(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
	if (document.documentElement)
		theST = document.documentElement.scrollLeft
	else if (document.body && document.body.scrollLeft)
		theST = document.body.scrollLeft;
    tempX = event.clientX + theST;
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  return tempX;
}
function DisplayInfoDate(TheDate, Etat, Pos, event, lan) {
	if (Etat.substr(0,5) == 'ZDisp') {
		if (lan == "fr") Etat ='Libre';
		if (lan == "en") Etat ='Available';
		if (lan == "es") Etat ='Libre';
	}
	document.getElementById('DateDispo').innerHTML=TheDate;
	document.getElementById('EtatDispo').innerHTML=Etat;
//	document.getElementById('TarifDispo').innerHTML=Prix;
	TopValue = getMouseY(event) + 5;
	LeftValue = getMouseX(event);
	document.getElementById('InfoDate').style.top = TopValue + 'px';
	document.getElementById('InfoDate').style.left = LeftValue + 'px';
	document.getElementById('InfoDate').style.visibility = 'visible';
}