window.onload = function()
{

var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var thisform = document.formdesjardins
thisform.datetmp.value = (day + "/" + month + "/" + year);
thisform.date.value = (day + "/" + month + "/" + year);
}

function showpricetotal(){
var thisform = document.formdesjardins
var total = 0;
var tmpprice = 0;
var countchecked = 0;
//var checkboxfields = document.getElementsByName('choix_activite[]');
var checkboxfields = document.getElementsByTagName('INPUT');
var totalfield = thisform.elements['total'];
var rabaisdancefield = thisform.elements['rabais_dance'];
//alert(totalfield.value);
var max = checkboxfields.length;
	for (var idx = 0; idx < max; idx++) {
	if(checkboxfields[idx].name.indexOf('choix_activite[') == 0){
		if (eval("checkboxfields[" + idx + "].checked") == true) {
			countchecked += 1;
			//var checkednumber = checkboxfields[idx].checked+idx;
			var checkednumber = checkboxfields[idx].name.replace('choix_activite[', '').replace(']', '');
			var myPrices=new Array(
			// TOUJOURS LE LAISSER VIDE
			"",
            // AFC 1 fois semaine LUNDI
            "70",
            // AFC 1 fois semaine MERCREDI
            "70",
            // CardioTonus 1 fois semaine MARDI
            "70",
            // CardioTonus 1 fois semaine JEUDI
            "70",
            // Pilates 1 fois semaine MARDI
            "70",
            // Pilates 1 fois semaine JEUDI
            "70",
            // Cardio-Tonus-Posture
            "70",
            //Pilates débutant
            "70",
            //Anglais débutant
            "85",
            //Anglais conversation intermédiaire
            "85",
            //Anglais conversation avancé
            "85",
            //Espagnol débutant
            "85",
            //Espagnol intermédiaire
            "85",
            //Italien débutant
            "85",
            //Italien intermédiaire
            "85",
            //Baladi débutant MERCREDI
            "80",
            //Baladi débutant VENDREDI
            "80",
            //Danse Folklorique Intermédiaire
			"65",
            //Danse Folklorique débutant
            "55",
            //Dessin, formes et couleurs
            "90",
            //Hockey Cosom
            "45",
            //Volleyball intermédiaire, avancé
            "45",
            //Volleyball récréatif
            "45",
            //Tennis de table
            "45",
            //
            "90",
            //Yoga débutant,26
            "75",
            //Yoga Intermédiaire
            "75",
            //Yoga débutant pour les 50 ans et plus
            "60",
            //Secourisme général
            "135",
            //Secourisme en millieu de garde gr1,30
            "70",
            //Secourisme en millieu de garde gr2
            "70",
            //Secourisme en millieu de garde gr3
			"70", 
            //Secourisme en millieu de garde gr4
			"70", 
           //
			"70", 
            // 
            "25",  
            //
			"20",
            //Soccer 5-7 ans  
            "20",
            //Soccer 8-10 ans
            "20",
            //Tennis de table débutant
			"20",
            //Tennis de table intermédiaire 
            "20",
            //Chindai
            "25",
            //Chindai     
            "25",
            //Danse Hip Hop 5-7 ans
            "25",
            //Danse Hip Hop 8-12 ans
            "25",
            //Dessin et peinture
            "25",
            //Gardiens Avertis
            "45",
            
            
            "30",
            "30",
            "30",
            "30",
            "30",
            "30",
            "45",
            "45",
            "55",
            "35"
			);
			tmpprice += Number(myPrices[checkednumber]);
			//alert(tmpprice);
			totalfield.value = tmpprice;
		}

		if(countchecked == 0){
			totalfield.value = "";
		}
	}
	}
	
    var bool1 = false;
    var bool2 = false;
    var bool3 = false;
    var bool4 = false;
    var bool5 = false;
    var bool6 = false;
    var bool16 = false;
    var bool17 = false;
    //calcul pour 2 activités pour moins chères ( mise en forme et baladi)
    bool1 = thisform.elements['choix_activite[1]'].checked;
    bool2 = thisform.elements['choix_activite[2]'].checked;    
    bool3 = thisform.elements['choix_activite[3]'].checked;
    bool4 = thisform.elements['choix_activite[4]'].checked;   
    bool5 = thisform.elements['choix_activite[5]'].checked;
    bool6 = thisform.elements['choix_activite[6]'].checked; 
    bool7 = thisform.elements['choix_activite[7]'].checked;
    bool8 = thisform.elements['choix_activite[8]'].checked; 
    
    
    bool16 = thisform.elements['choix_activite[16]'].checked;   
    bool17 = thisform.elements['choix_activite[17]'].checked; 
      
    var iNbOfBoolTrue = 0;
    var iNbOfBoolTrue2 = 0; 
    if (bool1)
    {
        iNbOfBoolTrue ++;
    }
    if (bool2)
    {
        iNbOfBoolTrue ++;
    }
    if (bool3)
    {
        iNbOfBoolTrue ++;
    }
    if (bool4)
    {
        iNbOfBoolTrue ++;
    }
    if (bool5)
    {
        iNbOfBoolTrue ++;
    }
    if (bool6)
    {
        iNbOfBoolTrue ++;
    }
    if (bool7)
    {
        iNbOfBoolTrue ++;
    }
    if (bool8)
    {
        iNbOfBoolTrue ++;
    }
    if (bool16)
    {
        iNbOfBoolTrue2 ++;
    }
    if (bool17)
    {
        iNbOfBoolTrue2 ++;
    }
    
    if (iNbOfBoolTrue == 2 || iNbOfBoolTrue == 3)
    {
          tmpprice = tmpprice - 60;
    }
    if (iNbOfBoolTrue == 4 || iNbOfBoolTrue == 5)
    {
          tmpprice = tmpprice - 120;
    }
    if (iNbOfBoolTrue == 6 || iNbOfBoolTrue == 7)
    {
          tmpprice = tmpprice - 180;
    }
    if (iNbOfBoolTrue == 8)
    {
          tmpprice = tmpprice - 240;
    }
    
    if (iNbOfBoolTrue2 == 2)
    {
          tmpprice = tmpprice - 60;
    }
    
    totalfield.value = tmpprice;

}

function showpricetotalcamp(typeservice){
var total = 0;
var tmpprice = 0;
var tmpprice2 = 0;
var tmpprice3 = 0;
var tmpprice4 = 0;
var countchecked = 0;
var countchecked2 = 0;
//var max = document.formdesjardins.semcamp.length;
//var max2 = document.formdesjardins.servicegarde.length;

	
		for (var idxx = 1; idxx <= 8; idxx++) {
		if (eval("document.formdesjardins.servicegarde" + idxx + ".checked") == true) {
		if(eval("document.formdesjardins.semcamp" + idxx + ".checked") == false && typeservice == 'servicegarde') {
		document.formdesjardins.elements['semcamp'+idxx].checked = true;
		}
			countchecked2 += 1;
		}
		tmpprice2 = 35*countchecked2;
		if(countchecked2 == 0){
			document.formdesjardins.total.value = "";
		}
	}
	
		for (var idx = 1; idx <= 8; idx++) {
		if (eval("document.formdesjardins.semcamp" + idx + ".checked") == true) {
			countchecked += 1;
		}else{
		if (eval("document.formdesjardins.servicegarde" + idx + ".checked") == true) {
		document.formdesjardins.elements['servicegarde'+idx].checked = false;
		tmpprice3 = -35;
		}
		}
		tmpprice = 55*countchecked;
		if(countchecked == 0){
			document.formdesjardins.total.value = "";
		}
	}
	
	if(document.formdesjardins.elements['chandail'].checked == true){
	tmpprice4 = 12;
	}else{
	tmpprice4 = 0;
	}
			
			document.formdesjardins.total.value = tmpprice+tmpprice2+tmpprice3+tmpprice4;

}

function getStyleObject(objectId) {
  if (document.getElementById && document.getElementById(objectId)) {
    return document.getElementById(objectId).style;
  } else if (document.all && document.all(objectId)) {
    return document.all(objectId).style;
  } else {
    return false;
  }
}


function showDiv(the_div,the_change){
  var the_style = getStyleObject(the_div);
  if (the_style != false){

  if(the_style.display=='block'){
      the_style.display = 'none';
  }else{
    the_style.display = the_change;
	}
  }
}

function ValidateForm()
{
	//This function demonstrates a simple validation function.  It can be used to verify variables
	//and then display an alert with all the items that require the users attention.  Note that this
	//is used with the SendInfo function above.
	var AlertString = "";
	var formValid = true;
	//Amount
	/*if( document.forms['Payment'].elements['ChkOther'].checked == true )
	{
		document.forms['Payment'].elements['TxtAmount'].value = ConditionValue(document.forms['Payment'].elements['TxtAmount'].value);
		if(IsNumeric(document.forms['Payment'].elements['TxtAmount'].value) == false)
		{
			AlertString += "Le montant doit être une numéro.\r\n";
			formValid = false;
		}
	}*/
	currentform = document.forms['formdesjardins'];
	var lang = 'fra';
	if(isBlank(currentform.elements['nom'].value) == true)
	{
		AlertString += "Le nom est requis."+"\r\n";
		formValid = false;
	}
		if(isBlank(currentform.elements['prenom'].value) == true)
	{
		AlertString += "Le prénom est requis."+"\r\n";
		formValid = false;
	}
		if(isChecked(currentform.elements['sexe']) == true)
	{
		AlertString += "Le sexe est requis."+"\r\n";
		formValid = false;
	}
		if(isBlank(currentform.elements['adresse'].value) == true)
	{
		AlertString += "L'adresse est requise."+"\r\n";
		formValid = false;
	}
			if(isBlank(currentform.elements['ville'].value) == true)
	{
		AlertString += "La ville est requise."+"\r\n";
		formValid = false;
	}
		if(isBlank(currentform.elements['code_postal'].value) == true)
	{
		AlertString += "Le code postal est requis."+"\r\n";
		formValid = false;
	}
		if(isBlank(currentform.elements['tel_res'].value) == true)
	{
		AlertString += "Le numéro de téléphone résidentiel est requis."+"\r\n";
		formValid = false;
	}
	if(isBlank(currentform.elements['courriel'].value) == true)
	{
	AlertString += "Votre adresse courriel est requise."+"\r\n";
	formValid = false;
	}else{
	if(validateEMail(currentform.elements['courriel'].value == true)){
		AlertString += "Votre adresse courriel est invalide."+"\r\n";
		formValid = false;
	}
	}
		//if(isBlank(currentform.elements['ddn'].value) == true)
	//{
		//AlertString += "La date de naissance est requise."+"\r\n";
		//formValid = false;
	//}
		//if(isBlank(currentform.elements['age'].value) == true)
	//{
		//AlertString += "L'Ã¢ge est requis."+"\r\n";
		//formValid = false;
	//}
	if(currentform.elements['total'].value == '' || currentform.elements['total'].value == 0){
	AlertString += "Vous devez sélectionner au moins activité"+"\r\n";
	formValid = false;
	}
	if(isBlank(AlertString) == false)
	{
		alert(AlertString);
	}
	return formValid;
}

function isBlank(testStr) 
{ 
	//This simple function will check to see if a variable is blank or not.
	if (testStr.length == 0)
		return true;
	for (var i = 0; i <= testStr.length-1; i++)
		if (testStr.charAt(i) != " ") 
			return false;
	return true;
}

function isChecked(testStr) 
{ 
boxes = testStr.length
txt = ""
for (i = 0; i < boxes; i++) {
if (testStr[i].checked) {
txt = txt + testStr[i].value + " "
}
}


if (txt == "") {
return true;
}
else {
return false;

}

}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   
   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsNumber = false;
      }
      else
      {
      	 if(Char == ".")
      	 {
      	 	ValidChars = "0123456789";
      	 }
      }
   }
   return IsNumber;
}

function validateEMail(email) 
{ 
	//A primitive but effective function to verify if a string is an email or not.
	//this function will only validate the basics "@" and ".".  It will not validate
	//whether the email actually exists or not.
	if (isBlank(email))
    	{ 
		return false;
    	} 
	var atsignPos = email.indexOf("@", 0);
	if (atsignPos == -1)     
    	{ 
		return false;
    	} 
	if (email.indexOf(".", atsignPos) == -1)   
    	{
		return false;
    	} 
	return true;
} 




