function selectAllRegion(ite){
	var val = ite.value;
	if(ite.checked == true){
		var chk = true;
	}
	else{
		var chk = false;
	}
	var regions = document.getElementsByName('Region'+val+'[]');
	for(i=0;i<regions.length;i++){
		regions[i].checked = chk;
	}
}

function selectAllRegion2(ite){
	var val = ite.value;
	if(ite.checked == true){
		var chk = true;
	}
	else{
		var chk = false;
	}
	var regions = document.getElementsByName('Region_'+val+'[]');
	for(i=0;i<regions.length;i++){
		regions[i].checked = chk;
	}
}




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 != " ") && (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 entier");
			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 whole 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);
	}

}

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 IsValidSize(champ,Message,len)
{
	if (champ.value.length!=len)
	{
		if (Message != "")
		{
			alert(Message);
			champ.focus();
		}
		return(true);
	}
	return(false);
}

function CheckCP_eng(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 != " ") && (charac != "-")) CPOK=false;
		}
	}
	if (!(CPOK))
	{
		alert("Invalid postal code , please enter the postal code in the following format : A9A 9A9");
		return(false);
	}
	return(true);
}

function Click_All(TheValue,TheType,TheSubstring) {
	var inputarr = document.getElementsByTagName("input");
	var TheLength = TheSubstring.length;
	for (var i = 0; i < inputarr.length; i++) {
		if ((TheLength == 0 && inputarr[i].getAttribute("type") == TheType) || (TheLength > 0 && inputarr[i].getAttribute("type") == TheType && inputarr[i].getAttribute("name").substring(0,TheLength) == TheSubstring)) inputarr[i].checked = TheValue;
	}
}

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);
	
}