﻿function CheckForm()
{
    try
    {
        if (String(Page_IsValid)!= "undefined" && !Page_IsValid)
        {
            var strValidationProblems = "";
            for (i=0; i<Page_Validators.length; i++) {
                if (!Page_Validators[i].isvalid && typeof(Page_Validators[i].errormessage) == "string") {
                    strValidationProblems += "<li style='list-style-type: disc; margin-left: 15px;'>" + Page_Validators[i].errormessage + "</li>";
                }
            }
            if (strValidationProblems != "" && document.getElementById('ValidationProblems') && document.getElementById('SummaryValidation'))
            {
                document.getElementById('ValidationProblems').innerHTML = strValidationProblems;
                document.getElementById('SummaryValidation').style.display = 'block';
                window.scrollTo(0,0);
            }
        }
    }
    catch(e)
    {

    }
}
function SwitchDiv(strArg)
{
try{
    if(document.getElementById(strArg))
        {
        document.getElementById(strArg).style.display == 'inline' ? document.getElementById(strArg).style.display = 'none' : document.getElementById(strArg).style.display = 'inline';
        }
   }
   catch(e)
   {
   }
}
function GetMail(strArg)
{
try{
		var strUrl = 'mailto:'+strArg.replace('|','@');
		window.open(strUrl,'_new');
		void(true);
	}
   catch(e)
   {
   }
}
function OnCheckBoxClientValidation(source, args)
{
try{
    var strCheckBoxId = source.controltovalidate || source.getAttribute("ControlToValidate");
        if(strCheckBoxId && document.getElementById(strCheckBoxId))
        {
            args.IsValid = document.getElementById(strCheckBoxId).checked;
        }
    }
   catch(e)
   {
   }
}
function ParseDateString(strArg,strDateFormat)
{
try
    {
    var strarrArg = strArg.split("/");
    if(strDateFormat == "dmy")
        return new Date(parseInt(strarrArg[2]),parseInt(strarrArg[1])-1,parseInt(strarrArg[0]));
    else if(strDateFormat == "mdy")
        return new Date(parseInt(strarrArg[1])-1,parseInt(strarrArg[2]),parseInt(strarrArg[0]));
    }
    catch(e)
    {
    }
}
function CheckDate(strDayId,strMonthId,strYearId,strContainerId)
        {
        try
        {
        SetContainerDate(strContainerId);
        var objListBoxDay = document.getElementById(strDayId);
        var objListBoxMonth = document.getElementById(strMonthId);
        var objListBoxYear = document.getElementById(strYearId);      
        if(objListBoxDay && objListBoxMonth && objListBoxYear)
                {                    
                        if(objListBoxDay.selectedIndex!=-1 && objListBoxDay.selectedIndex!=0 && objListBoxMonth.selectedIndex!=-1 && objListBoxMonth.selectedIndex!=0 && objListBoxYear.selectedIndex!=-1 && objListBoxYear.selectedIndex!=-1 && objListBoxYear.selectedIndex!=0)
                        { 
                            var intDay = parseInt(objListBoxDay.value);
                            var intMonth = parseInt(objListBoxMonth.value) - 1;
                            var intYear = parseInt(objListBoxYear.value);
                            var objDate = new Date(intYear,intMonth,intDay);
                            if(objDate.getMonth() != intMonth)
                            {
                            alert('Veuillez choisir un jour valide!');
                            objListBoxDay.selectedIndex = 0;
                            }
                            if(objDate.getFullYear()!=intYear)
                            {
                            alert('Veuillez choisir une année valide!');
                            objListBoxYear.selectedIndex = 0;
                            }
                        }  
                }
            }
            catch(e)
            {
                objListBoxDay.selectedIndex = 1;
                alert('Veuillez choisir une date valide!');
            }
        } 
function SetContainerDate(strContainerId)
{
try
    { 
    if(strContainerId)
        {
         var objContainer = document.getElementById(strContainerId);
         var strDayId = strContainerId + "_objListBoxDay";
         var strMonthId = strContainerId + "_objListBoxMonth";
         var strYearId = strContainerId + "_objListBoxYear";
         var objListBoxDay = document.getElementById(strDayId);
         var objListBoxMonth = document.getElementById(strMonthId);
         var objListBoxYear = document.getElementById(strYearId);      
         if(objContainer && objListBoxDay && objListBoxMonth && objListBoxYear)
           { 
                objContainer.value = objListBoxDay.value + '/' + objListBoxMonth.value + '/' + objListBoxYear.value;
           }
        }
     }
   catch(e)
   {
   }
}
function ContainsNoInvalidDate(strValue)
{
try
    {
    return strValue.indexOf("/00")==-1 && strValue.indexOf("00/")==-1;
     }
   catch(e)
   {
   }
}
function OnDateCompareClientValidation(source, args)
{
try
    {    
    var objDateSelectorToValidate = source.controltovalidate || source.getAttribute("ControlToValidate");
    var objDateSelectorToCompare = source.getAttribute("ControlToCompare");
    if(objDateSelectorToValidate && document.getElementById(objDateSelectorToValidate) && objDateSelectorToCompare && document.getElementById(objDateSelectorToCompare))
        {
        SetContainerDate(objDateSelectorToValidate);
        SetContainerDate(objDateSelectorToCompare);
        if(ContainsNoInvalidDate(document.getElementById(objDateSelectorToCompare).value) && ContainsNoInvalidDate(document.getElementById(objDateSelectorToValidate).value) )
            {
            var objDateOne = ParseDateString(document.getElementById(objDateSelectorToCompare).value,"dmy");
            var objDateTwo = ParseDateString(document.getElementById(objDateSelectorToValidate).value,"dmy");
            args.IsValid = objDateOne < objDateTwo;
            }
        else{
            args.IsValid = true;
            }
        }
   }
   catch(e)
   {
   }
}
function OnDateCompareClientValidation2(source, args)
{
try
    {
    var objDateSelectorToValidate = source.controltovalidate || source.getAttribute("ControlToValidate");
    var objDateSelectorToCompare = source.getAttribute("ControlToCompare");
    if(ContainsNoInvalidDate(document.getElementById(objDateSelectorToCompare).value) && ContainsNoInvalidDate(document.getElementById(objDateSelectorToValidate).value) )
        {
        SetContainerDate(objDateSelectorToValidate);
        SetContainerDate(objDateSelectorToCompare);
        
        if(ContainsNoInvalidDate(document.getElementById(objDateSelectorToCompare).value) && ContainsNoInvalidDate(document.getElementById(objDateSelectorToValidate).value) )
            {
            var objDateTwo = ParseDateString(document.getElementById(objDateSelectorToCompare).value,"dmy");
            var objDateOne  = ParseDateString(document.getElementById(objDateSelectorToValidate).value,"dmy");
            args.IsValid = objDateOne < objDateTwo;
            }
        else{
            args.IsValid = true;
            }
        }
   }
   catch(e)
   {
   }
}
function ShowAlert(strElementId,strLightBoxBackGroundId,blnAutoHide)
{
try
   {
    if(document.getElementById(strElementId))
        {
        document.getElementById(strElementId).style.display = 'inline';
        if(blnAutoHide)
            setTimeout("document.getElementById('"+strElementId+"').style.display = 'none';",12000);
        }
    if(strLightBoxBackGroundId && document.getElementById(strLightBoxBackGroundId))
        {
        document.getElementById(strLightBoxBackGroundId).style.display = 'block';
        if(blnAutoHide)
            setTimeout("document.getElementById('"+strLightBoxBackGroundId+"').style.display = 'none';",12000);
        }
   }
   catch(e)
   {
   }
}
function RefreshPage()
{
try
    {
    document.location = document.location;
     }
   catch(e)
   {
   }
}
function CloseAlert(strElementId,strLightBoxBackGroundId)
{
try
    {
    if(document.getElementById(strElementId))
        {
        var objAllSelects = document.getElementsByTagName("select");
        if(objAllSelects && objAllSelects.length>0)
            {
            for(var intLooper=0; intLooper < objAllSelects.length; intLooper++)
                {
                objAllSelects[intLooper].disabled = false;
                }
            }
        document.getElementById(strElementId).style.display = 'none';
        }
    if(strLightBoxBackGroundId && document.getElementById(strLightBoxBackGroundId))
        {
        document.getElementById(strLightBoxBackGroundId).style.display = 'none';
        }
     }
   catch(e)
   {
   }
}
function SwapTextBoxMode(objInput,strTextBoxId)
{
try{
    if(document.getElementById(strTextBoxId))
        {
        var objTextBox = document.getElementById(strTextBoxId)
            if(objInput.checked)
            {
                objTextBox.className = 'TextBox';
                objTextBox.readOnly = false;
                objTextBox.focus();
            }
            else
            {
                objTextBox.className = 'TextBoxReadOnly';
                objTextBox.readOnly = true;
                objTextBox.value = "";
            }
        }
   }
   catch(e)
   {
   }
}
function CutOffText(objTextBox,intMaxLength)
{
try
    {
    if(objTextBox)
        {
        var strValue = objTextBox.value;
        var objRegex = /<(\S+).*>(.*)<\/\1>/gi;
        strValue = strValue.replace(objRegex,"$2");
        if(strValue.length > intMaxLength)
            {
            objTextBox.value = strValue.substring(0,intMaxLength);
            return false;
            }
            return true;
        }
   }
   catch(e)
   {
   }
}
function DisplayLength(objTextBox,objLabelArea)
{
try
    {
    if(objLabelArea)
        {
        var strValue = objTextBox.value;
        objLabelArea.innerHTML = strValue.length + " caractères";
        }
   }
   catch(e)
   {
   }
}
function ParseFloatInput(strArg)
{
try
    {  
    if(strArg.toString().indexOf(",")!=-1)
        {
        strArg = strArg.toString().replace(",",".");
        }
    var floResult = parseFloat(strArg.toString())
    if(isNaN(floResult))
        return 0;
    return floResult;
    }
   catch(e)
   {
    return 0;
   }
}
function ParseFloatOutput(strArg)
{
try
    {  
    strArg = strArg + "";
    if(strArg.indexOf(".")!=-1)
        {
        strArg = strArg.replace(".",",");
        }
    var strBeforeDecimal = "";
    var strAfterDecimal = "";
    if(strArg.indexOf(",")!=-1)
    {
    strBeforeDecimal = strArg.split(",")[0];
    strAfterDecimal = strArg.split(",")[1];
    if(strAfterDecimal.length>2)
        strAfterDecimal = strAfterDecimal.substring(0,2)
    }
    else
    {
    strBeforeDecimal = strArg;
    }
    if(strBeforeDecimal.length > 3)
        {
        strArg = "";
        var intPositionFromRight = 0;
        for(var intPosition = strBeforeDecimal.length; intPosition >= 0 ; intPosition--)
            {
            strArg = strBeforeDecimal.charAt(intPosition) + strArg;
            if(intPositionFromRight!=0 && intPositionFromRight % 3 == 0)
                strArg = " " + strArg;
            intPositionFromRight++;
            }
        if(strAfterDecimal!="")
            strArg += "," + strAfterDecimal;
        }
    return strArg;
    }
   catch(e)
   {
    return "";
   }
}
function CheckEntry(objEvent)
{
try
    {  
        if (arguments.length<1)
        {
           objEvent = window.event;
        }
        var target = objEvent.target || objEvent.srcElement;
        var key = objEvent.keyCode || objEvent.which;
        if(key==13 && target.tagName.toLowerCase() !== 'textarea')
        {
            return false;
        }
        return true;
    }
   catch(e)
   {
    
   }
}
function DisableField(objArg)
{
try
    {
    if(objArg)
        objArg.blur();
    }
catch(e)
    {
    }
}
try
    {
    window.history.forward(1);
        if (window.addEventListener)
        {
            document.addEventListener("keydown", CheckEntry, false);
        }
        else
        {
            document.attachEvent("onkeydown", CheckEntry);
        }
    }
catch(e)
    {
    }
Math.baseround = Math.round;
Math.round = function(floArg,intDecimalPlaces)
{
try
    {  
        if(arguments.length==2)
        {
            return(Math.baseround(floArg * Math.pow(10,intDecimalPlaces)) / Math.pow(10,intDecimalPlaces));
        }
        else if(arguments.length==1)
        {
            return Math.baseround(strArg);
        }
        else{
            return Number.NaN;
        }
    }
   catch(e)
   {
    return Number.NaN;
   }
}
function SetCheckBox(strCheckboxId)
{
    try
        {
        if(document.getElementById(strCheckboxId))
            {
            document.getElementById(strCheckboxId).checked = true;
            }
        }
        catch(e)
        {
        }
}
function CopyValue(/*string*/ strSourceId, /*string*/ strDestinationId)
{
    try
    {
    if(document.getElementById(strSourceId) && document.getElementById(strDestinationId))
        {
        document.getElementById(strDestinationId).value = document.getElementById(strSourceId).value;
        }
    }
    catch(e)
    {
    }
}
function ClearValue(/*string*/ strFieldId)
{
    try
    {
    if(document.getElementById(strFieldId))
        {
        document.getElementById(strFieldId).value = "";
        }
    }
    catch(e)
    {
    }
}

var cursor = {x:0, y:0};

function GetMouse(e) 
{
try 
    {
        e = e || window.event;
        
        if (e.pageX || e.pageY) {
            cursor.x = e.pageX;
            cursor.y = e.pageY;
        } 
        else {
            cursor.x = e.clientX + 
                (document.documentElement.scrollLeft || 
                document.body.scrollLeft) - 
                document.documentElement.clientLeft;
            cursor.y = e.clientY + 
                (document.documentElement.scrollTop || 
                document.body.scrollTop) - 
                document.documentElement.clientTop;
        }
    }
catch (e) 
    {
    }
}

document.onmousemove = GetMouse;

function WarnWhenLeaving(e) 
{
    try 
    {
        if ( parseInt(cursor.x.toString()) > 700 )
        {
            return "Souhaitez-vous quitter ce formulaire sans l'envoyer?";
        }
    }
    catch (e) 
    {
    }
}

function ValiderTVA(source, arguments) {
    try 
    {
        var number = arguments.Value + "";
        if (number.Length < 10) {
            arguments.IsValid = false;
        }
        else {
            var inputnumber = number.substring(0, 8);
            var zerotrimmed = "";
            var OtherThanZeroPassed = false;
            for (var loop = 0; loop < inputnumber.length; loop++) {
                if (inputnumber.substring(loop, loop + 1) != '0' || (OtherThanZeroPassed)) {
                    zerotrimmed += inputnumber.substring(loop, loop + 1);
                    OtherThanZeroPassed = true;
                }
            }
            var intnumber = parseInt(zerotrimmed);
            var modulonumber = intnumber % 97;
            var remainnumber = 97 - modulonumber;
            if (remainnumber == 0)
                remainnumber = 97;
            if (remainnumber.toString().length == 1)
                remainnumber = "0" + remainnumber.toString();

            var lastTwo = number.substring(8, 10);
            if (lastTwo == remainnumber.toString())
                arguments.IsValid = true;
            else
                arguments.IsValid = false;
        }
    }
    catch (e) {}
}

