var lang=null;
function select_birth(_lang)
{
    lang = _lang;
    $("#welcome").fadeOut("slow");
     $("#bienvenue").fadeOut("slow",function(){

            if(lang == "fr")
           $("#container_birth_fr").fadeIn("slow");
       else{
          // $("#container_birth_fr").remove();
           $("#container_birth_en").fadeIn("slow");}
     });
    
//xajax_setLang(lang);

}

function checkInputs()
{
    errors=0;
    var pass = false;


    if(lang == "fr")
        {

            		var day = $("#fr_lstBirthDay").val();
		var month = $("#fr_lstBirthMonth").val();
		var year = $("#fr_lstBirthYear").val();
		var age = 18;

if(day!="" && month!="" && year!="")

{
                                if(!isEighteen(day, month, year, age) && $('#fr_lstProvince').val()=="QC"){
                                        alert('Vous devez avoir 18ans pour entrer');
                     errors+=1;
                }
                                 if (!isEighteen(day, month, year, 21) && $('#fr_lstProvince').val()!="QC"){
                                        errors+=1;
                    alert('Vous devez avoir 21 ans pour entrer');
                }
        }


                        if($("#fr_lstBirthMonth").val() ==""){
                    $('#fr_lstBirthMonth').css("background-color","#ee184e");
                    errors += 1
                }
                else
                    $('#fr_lstBirthMonth').css("background-color","white");

                if($("#fr_lstBirthDay").val() ==""){
                     $('#fr_lstBirthDay').css("background-color","#ee184e");
                    errors +=1}
                    else
                    $('#fr_lstBirthDay').css("background-color","white");

                if($("#fr_lstBirthYear").val() ==""){
                    $('#fr_lstBirthYear').css("background-color","#ee184e");
                    errors +=1}
                    else
                    $('#fr_lstBirthYear').css("background-color","white");

                    if($("#fr_lstProvince").val() ==""){
                    $('#fr_lstProvince').css("background-color","#ee184e");
                    errors +=1}
                    else
                    $('#fr_lstProvince').css("background-color","white");
        }

      else
            {
                var day = $("#en_lstBirthDay").val();
		var month = $("#en_lstBirthMonth").val();
		var year = $("#en_lstBirthYear").val();
		var age = 18;

if(day!="" && month!="" && year!="")

{
                                if(!isEighteen(day, month, year, 18) && $('#en_lstProvince').val()=="QC"){
                    errors+=1;
                    alert('You need to be 18 years old to enter');
                }
                if (!isEighteen(day, month, year, 21) && $('#en_lstProvince').val()!="QC"){
                                        errors+=1;
                    alert('You need to be 21 years old to enter');
                }

}
if($("#en_lstBirthMonth").val() ==""){
        $('#en_lstBirthMonth').css("background-color","#ee184e");
        errors += 1
    }
    else
        $('#en_lstBirthMonth').css("background-color","white");

    if($("#en_lstBirthDay").val() ==""){
         $('#en_lstBirthDay').css("background-color","#ee184e");
        errors +=1}
        else
        $('#en_lstBirthDay').css("background-color","white");

    if($("#en_lstBirthYear").val() ==""){
        $('#en_lstBirthYear').css("background-color","#ee184e");
        errors +=1}
        else
        $('#en_lstBirthYear').css("background-color","white");

        if($("#en_lstProvince").val() ==""){
        $('#en_lstProvince').css("background-color","#ee184e");
        errors +=1}
        else
        $('#en_lstProvince').css("background-color","white");

            }		

if(!errors)
    {pass=true;      
      xajax_setBirth(lang);}

 // if(pass) window.location="./"
}


function checkPV()
{

  $("p[class='left']").each(function(index) {
     if(index!=0) 
     {$(this).fadeOut(100);
     $(this).css('display','none');}
  });

             //$("p[class='left']").each(function(index) {
                 switch($('#lstProvince').val())
                 {
                        case "QC":
                        $(this).fadeIn(100);
                        $('#quebec_pv').css('display','block');
                        break;

                        case "AB":
                        $(this).fadeIn(100);
                        $('#alberta_pv').css('display','block');
                        break;

                         case "NB":
                        $(this).fadeIn(100);
                        $('#nb_pv').css('display','block');
                        break;

                        case "OTHERS":
                        $(this).fadeIn(100);
                        $('#other_pv').css('display','block');
                        break;
                 }
            //if(index !=0) $(this).fadeOut(100);


   /* switch($('#lstProvince').val())
    {
        case "QC":
            $('#quebec_pv').css('display','block');
            break;
    }*/
}

function isEighteen(day, month, year, age)
{
    var resp=false;
    var mydate = new Date();
		mydate.setFullYear(year, month-1, day);

		var currdate = new Date();
		currdate.setFullYear(currdate.getFullYear() - age);
		if ((currdate - mydate) < 0){
			resp=false
		}
                else
                    resp=true

                return resp;
}
