﻿// Assurland  javascript ressources

var al_siteMode;

/////////////////////////////////////////////////////////////////////
//                         OLD COMMON                             //
////////////////////////////////////////////////////////////////////
var al_debug = false;

function displayAspNetFrameworkError(message, error)
{
    if(al_debug)
        alert(message + "\n" +
                "Service Error: " + error.get_message() + "\n" +
                "Status Code: " + error.get_statusCode() + "\n" +
                "Exception Type: " +  error.get_exceptionType() + "\n" +
                "Timedout: " + error.get_timedOut() + "\n" +
                "Stack Trace: " +  error.get_stackTrace());
    else
      alert(message + "\n" +
        "Service Error: " + error.get_message() + "\n" +
        "Status Code: " + error.get_statusCode() + "\n" +
        "Exception Type: " +  error.get_exceptionType() + "\n" +
        "Timedout: " + error.get_timedOut());  
}

//////////////////////////////
// Browser detection
/////////////////////////////

// Thanks to http://www.quirksmode.org/js/detect.html
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

//////////////////////////////
// Basic functions
/////////////////////////////

function trim(str)
{
	return str.replace(/^\s+/g,'').replace(/\s+$/g,'');
}
function trimChar(str, c) {
    return trimCharRight(trimCharLeft(str, c), c);
}
function trimCharLeft(str, c) {
    reg = new RegExp("^(" + c + ")+", "g");
    return str.replace(reg, '');
}
function trimCharRight(str, c) {
    reg = new RegExp("(" + c + ")+$", "g");
    return str.replace(reg, '');
}
function removeAccents(str) {
    var str2 = str;
    str2 = str2.replace(/[ÀÁÂÃÄÅ]/g, "A");
    str2 = str2.replace(/[àáâãäå]/g, "a");
    str2 = str2.replace(/[ÒÓÔÕÖØ]/g, "O");
    str2 = str2.replace(/[òóôõöø]/g, "o");
    str2 = str2.replace(/[ÈÉÊË]/g, "E");
    str2 = str2.replace(/[èéêë]/g, "e");
    str2 = str2.replace(/[ÌÍÎÏ]/g, "I");
    str2 = str2.replace(/[ìíîï]/g, "i");
    str2 = str2.replace(/[ÙÚÛÜ]/g, "U");
    str2 = str2.replace(/[ùúûü]/g, "u");
    str2 = str2.replace(/[Ÿ]/g, "Y");
    str2 = str2.replace(/[ÿ]/g, "y");
    str2 = str2.replace(/[Ñ]/g, "N");
    str2 = str2.replace(/[ñ]/g, "n");
    str2 = str2.replace(/[Ç]/g, "C");
    str2 = str2.replace(/[ç]/g, "c");
    return str2;
}

function strTofixed(str) {
    if (str) {
        return (parseFloat(str.replace(/,/g, '.'))).toFixed(2).replace(/\./g, ',');
    }
    return "";
}

function getInt(value) {
    return value * 1;
}

function mouseX(e)
{
    if (e.pageX) 
        return e.pageX;
    else if (e.clientX)
    return e.clientX + scrollX();
    else return null;
}
function mouseY(e)
{
    if (e.pageY) return e.pageY;
    else if (e.clientY)
        return e.clientY + scrollY();
    else return null;
}
function scrollX()
{
    var offsetX = 0;
	if(!window.pageXOffset)
	{
		if(!(document.documentElement.scrollLeft == 0))
			offsetX = document.documentElement.scrollLeft;
		else
			offsetX = document.body.scrollLeft;
    }
	else
		offsetX = window.pageXOffset;
    return offsetX;
}
function scrollY()
{
    var offsetY = 0;
	if(!window.pageYOffset)
	{
		if(!(document.documentElement.scrollTop == 0))
			offsetY = document.documentElement.scrollTop;
		else
			offsetY = document.body.scrollTop;
    }
	else
		offsetY = window.pageYOffset;
    return offsetY;
}

function scrollToTop()
{
    //scrollY_Move(0);
    // Delay update seems to be required to move scroll 
    // after updatepanel update
    setTimeout("scrollTo(0,0);",100); 
}

function getElementPositionAttribute(elt)
{
    if(elt.currentStyle)
        return elt.currentStyle.position;
    else
        return window.getComputedStyle(elt,null).position;    
}

function getFirstAbsoluteOrRelativeParent(elt)
{
    if(elt == null || elt == document)
        return null;
    
    var pos = getElementPositionAttribute(elt);         
    if(pos!= null && (pos == "relative" || pos == "absolute"))
    {
        return elt;
    }
    else
    {
        if(elt.parentNode != null)
            return getFirstAbsoluteOrRelativeParent(elt.parentNode);
        else
            return null;
    }
}
function getRelativeBounds(elt,popup)
{
    var relativeParent = getFirstAbsoluteOrRelativeParent(popup.parentNode);
    if(relativeParent != null)
    {
        var boundsParent = Sys.UI.DomElement.getBounds(relativeParent);
        var boundsElt = Sys.UI.DomElement.getBounds(elt);
        boundsElt.x = boundsElt.x - boundsParent.x;
        boundsElt.y = boundsElt.y - boundsParent.y;
        return boundsElt;
    }
    else
    {
        return Sys.UI.DomElement.getBounds(elt);
    }
}

function addToArray(array,value)
{
    if(array != null)
        array[array.length] = value;
}

// Cross-browser implementation of element.addEventListener()
function addListener(element, type, expression, bubbling)
{
    bubbling = bubbling || false;
    if(window.addEventListener) { // Standard
        element.addEventListener(type, expression, bubbling);
    return true;
    } else if(window.attachEvent) { // IE
        element.attachEvent('on' + type, expression);
    return true;
    } else return false;
}
function goToURL(url)
{
    /*window.location.href = url;*/
    /* location.href don't send HTTP_REFERER in request header on IE */
    var fakeLink = document.createElement("a");
    if (typeof(fakeLink.click) == 'undefined')
        location.href = url;  // sends referrer in FF, not in IE
    else
    {
        fakeLink.href = url;
        document.body.appendChild(fakeLink);
        fakeLink.click();   // click() method defined in IE only
    }
}
function show(eltId)
{
    if( $get(eltId) != null)
        $get(eltId).style.display = 'block';
}
function showInline(eltId)
{
    if( $get(eltId) != null)
        $get(eltId).style.display = 'inline';
}
function hide(eltId)
{
    if( $get(eltId) != null)
        $get(eltId).style.display = 'none';
}
function showHide(eltId)
{
    $get(eltId).style.display = (($get(eltId).style.display == 'none') || ($get(eltId).style.display == '')) ? 'block' : 'none';
}
function showRow(rowId)
{
    var elt = $get(rowId);
    if(elt != null)
    {
	    if (typeof window.opera!="undefined")
		    elt.style.display = 'table-row';
	    else if (navigator.appName == 'Microsoft Internet Explorer')
	        elt.style.display = 'block';
	    else
		    elt.style.display = 'table-row';
	}
}
function showCell(rowId)
{
    var elt = $get(rowId);
    if(elt != null)
    {
	    if (typeof window.opera!="undefined")
		    elt.style.display = 'table-cell';
	    else if (navigator.appName == 'Microsoft Internet Explorer')
	        elt.style.display = 'block';
	    else
		    elt.style.display = 'table-cell';
	}
}
function hideRow(rowId)
{
    if($get(rowId) != null)
        $get(rowId).style.display = 'none';
}

function isRowVisible(rowId) {
    if($get(rowId) != null)
        return $get(rowId).style.display != 'none';
    return false;
}

function showRows(rowIdArray)
{
    if(rowIdArray != null)
        for(var i=0; i<rowIdArray.length; i++)
            showRow(rowIdArray[i]);
}
function hideRows(rowIdArray)
{
    if(rowIdArray != null)
        for(var i=0; i<rowIdArray.length; i++)
            hideRow(rowIdArray[i]);
}
function setRowVisibility(rowId, visible)
{
    if(visible == true)
        showRow(rowId);
    else
        hideRow(rowId);
        
}
function hideElementByTypeIn(parentId, eltType)
{
    var elt = $get(parentId);
    if(elt != null)
    {
        var obj = elt.getElementsByTagName(eltType);
        if(obj && obj.length)
        {
            for(var i=0; i < obj.length; i++)
            {
                hide(obj[i].id);
            }
        }
    }
}
function setInnerHtml(eltId, text)
{
    var elt = $get(eltId);
    if(elt != null)
        elt.innerHTML = text;
}
function setEltEnabled(eltId, enabled)
{
    var elt = $get(eltId);
    if(elt != null)
        elt.disabled = !enabled;
}
function setBtnEnabled(eltId, enabled)
{
    setEltEnabled(eltId, enabled);
}
function setDropDownListEnabled(eltId, enabled)
{
    setEltEnabled(eltId, enabled);
}
function setTextBoxEnabled(eltId, enabled)
{
    var elt = $get(eltId);
    if(elt != null)
    {
        if(enabled == true)
        {
            elt.disabled = false;
            elt.style.background="#FFFFFF";
        }
        else
        {
            elt.disabled = true;
            elt.style.background="#CCCCCC";
        }
    }
}
function setRadioButtonListEnabled(groupName, enabled)
{
    var radioGroup = document.getElementsByName(groupName);
    for (var i = 0; i < radioGroup.length; i++)
        radioGroup[i].disabled = !enabled;
}
function clearDropDownList(eltId)
{
    var elt = $get(eltId);
    if(elt != null)
    {
        elt.options.length = 0;
    }
}
function clearSelectionDropDownList(eltId)
{
    var elt = $get(eltId);
    if(elt != null)
    {
        if(elt.options.length > 0)
            elt.options[0].selected = true;
    }
}
function selectItemDropDownList(eltId, value)
{
    var elt = $get(eltId);
    if(elt != null)
    {
        for(var j=0; j<elt.options.length; j++)
        {
            if(elt.options[j].value == value)
            {
                elt.options[j].selected = true;
                break;
            }
        }   
    }
}
function clearSelectionRadioButtonList(groupName)
{
    var radioGroup = document.getElementsByName(groupName);
    for (var i = 0; i < radioGroup.length; i++)
        radioGroup[i].checked = false;
}
function selectItemRadioButtonList(groupName, value)
{
    var radioGroup = document.getElementsByName(groupName);
    for (var i = 0; i < radioGroup.length; i++)
    {
        if(radioGroup[i].value == value)
        {
            radioGroup[i].checked = true;
            break;
        }
    }
}
function getRadioButtonListSelectedValue(groupName)
{
    var radioGroup = document.getElementsByName(groupName);
    for (var i = 0; i < radioGroup.length; i++)
    {
        if(radioGroup[i].checked == true)
        {
            return radioGroup[i].value;
        }
    }
    return null;
}
function getRadioButtonItem(groupName, value)
{
    var radioGroup = document.getElementsByName(groupName);
    for (var i = 0; i < radioGroup.length; i++)
    {
        if(radioGroup[i].value == value)
        {
            return radioGroup[i];
        }
    }
    return null;
}

function addBookmark(phrase,lien) 
{ 
    if (window.sidebar) 
    { 
        window.sidebar.addPanel(phrase, lien,""); 
    } 
    else if( document.all ) 
    { 
        window.external.AddFavorite(lien, phrase); 
    } 
    else 
    { 
        return true; 
    } 
} 

//////////////////////////////
// Rect area
/////////////////////////////

function RectArea()
{
  this.x = 0;
  this.y = 0;
  this.width = 0;
  this.height = 0;
}
RectArea.prototype = 
{ 
    toString: function()
    {
        var str = "";
        str = str + 'x = ' + this.x + '\n';
        str = str + 'y = ' + this.y + '\n';
        str = str + 'width = ' + this.width + '\n';
        str = str + 'height = ' + this.height + '\n';
        return str;
    }
}
RectArea.prototype = 
{ 
    PtIn: function(x,y)
    {
      if(x >= this.x && x <= (this.x + this.width))
        if(y >= this.y && y <= (this.y + this.height))
            return true
      return false;
    }
}

//////////////////////////////
// Popup 
/////////////////////////////
// import from old open.js

var browser2 = 1;
if (navigator.appName.substring(0,8) == "Netscape") browser2 = 1;
if (navigator.appName.substring(0,9) == "Microsoft") browser2 = 0;
var ns4 = (document.layers)? true:false;   //NS 4 
var ie4 = (document.all)? true:false;   //IE 4 
var dom = (document.getElementById)? true:false;   //DOM 

function openWin(url,dimx,dimy,fen)
{
	if (browser2 == 0 && navigator.appVersion.indexOf("Win") > 0) dimy=dimy-19;
	featur = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrolling=no,scrollbars=no,resizable=no,width="+ dimx + ",height=" + dimy;
	cl = window.open(url,fen,featur);
	if (browser2 == 1) cl.focus(); else cl = window.open(url,fen,featur);
}
function openWinNet(url,dimx,dimy,top,left, fen)
{
	if (browser2 == 0 && navigator.appVersion.indexOf("Win") > 0) dimy=dimy-19;
	featur = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrolling=yes,scrollbars=yes,resizable=no,top=" + top + ",left=" + left + ",width="+ dimx + ",height=" + dimy;
	cl = window.open(url,fen,featur);
	if (browser2 == 1) cl.focus(); else cl = window.open(url,fen,featur);
}
function openWinScroll(url,dimx,dimy,fen)
{
	if (browser2 == 0 && navigator.appVersion.indexOf("Win") > 0) 
		dimy=dimy-19;
	featur = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrolling=auto,scrollbars=yes,resizable=no,width="+ dimx + ",height=" + dimy;
	cl = window.open(url,fen,featur);
	if (browser2 == 1) 
		cl.focus(); 
	else cl = window.open(url,fen,featur);
}
function openWinScrollWithMaximise(url,dimx,dimy,fen)
{
	if (browser2 == 0 && navigator.appVersion.indexOf("Win") > 0) 
		dimy=dimy-19;
	featur = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrolling=auto,scrollbars=yes,resizable=yes,width="+ dimx + ",height=" + dimy;
	cl = window.open(url,fen,featur);
	if (browser2 == 1) 
		cl.focus(); 
	else cl = window.open(url,fen,featur);
}
function openHtmlContentPopup(dimx,dimy,fen,title,htmlContent){
    newpage=open("",fen,'width='+dimx+',height='+dimy+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrolling=no,scrollbars=no,resizable=no');
    newpage.document.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>");
    newpage.document.write("<html><head><title>"+title+"</title></head>");
    newpage.document.write("<body><div style='font-size:12px;font-family:arial;text-align:justify;'>"+htmlContent+"<br/><br/><a href='#' onclick='window.close();'>Femer la fenêtre</a></div></body></html>");
}

//////////////////////////////
// Date
/////////////////////////////

function getNowDate() {
    return new Date();
}

function getTodayDate() {
    var d = getNowDate();
    return new Date(d.getFullYear(), d.getMonth(), d.getDate())
}

function addDays(d, n) {
    d.setDate(d.getDate() + n)
    return d;
}
function addMonths(d, n) {
    d.setMonth(d.getMonth() + n);
    return d;
}
function addYears(d) {
    d.setYear(d.getYear() + n);
    return d;
}

function getDateStringByFormat(d,sFormat){
    var jour;
    var mois;
    var annee;
    
    jour = d.getDate();
    if(jour < 10)
        jour = '0' + jour;
    mois = d.getMonth()+1;
    if(mois < 10)
        mois = '0' + mois;
    annee = d.getFullYear();
    
    switch (sFormat)
    {
        case 'dd/MM/yyyy': 
            return jour + '/' + mois + '/' + annee;
            break;
        case 'MM/yyyy': 
            return mois + '/' + annee;
            break;
    }
    return "";
}

function getDateByFormat(strDate,sFormat){
    var jour;
    var mois;
    var annee;
    var iTmp1;
    var iTmp2;
    switch (sFormat)
    {
        case 'dd/MM/yyyy': 
            iTmp1=0;
            iTmp2=strDate.indexOf('/');
            jour=strDate.substr(iTmp1,iTmp2-iTmp1);
            iTmp1=iTmp2+1
            iTmp2=strDate.indexOf('/',iTmp1);
            mois=strDate.substr(iTmp1,iTmp2-iTmp1)-1;
            annee=strDate.substr(iTmp2+1);    
            break;
        case 'MM/yyyy': 
            iTmp1=0;
            iTmp2=strDate.indexOf('/');
            mois=strDate.substr(iTmp1,iTmp2-iTmp1)-1;
            annee=strDate.substr(iTmp2+1);    
            break;
    }

    // TODO : vérifier cohérence date
    
    return new Date(annee,mois,jour);
}

function isValidDate(d) {
    if (d == "NaN" || d == "Invalid Date"|| d == null)
        return false
    return true
}

function isTrueValidDate(day, month, year) {
    var dteDate = new Date(year, month - 1, day);
    return ((day == dteDate.getDate()) && ((month - 1) == dteDate.getMonth()) && (year == dteDate.getFullYear()));
}

function getValidDate(day, month, year) {
    if (isTrueValidDate(day, month, year))
        return new Date(year, month - 1, day);
    return null;
}

function calcul_age(date_birthday){
    var age;
    var dateNow = new Date();   
    age = dateNow.getFullYear() - date_birthday.getFullYear();
    if (dateNow.getMonth() <= date_birthday.getMonth())
    {
        age--;
        if (dateNow.getMonth() == date_birthday.getMonth())
          if (dateNow.getDate() >= date_birthday.getDate())
            age++;
    }
    return age;
}
//GetMonthText
function GetMonthText(iMonth) {
    iMonth = iMonth * 1.0;    
    switch (iMonth) {
        case 1: 
            return "janvier";
            break;
        case 2:
            return "février";
            break;
        case 3:
            return "mars";
            break;
        case 4:
            return "avril";
            break;
        case 5:
            return "mai";
            break;
        case 6:
            return "juin";
            break;
        case 7:
            return "juillet";
            break;
        case 8:
            return "août";
            break;
        case 9:
            return "septembre";
            break;
        case 10:
            return "octobre";
            break;
        case 11:
            return "novembre";
            break;
        case 12:
            return "décembre";
            break;           
    }
}

//////////////////////////////
// Help bubble
/////////////////////////////

function HelpPoup_PopupProperties(popupId,iframeId,htmlTargetElementId)
{
    this.popupId = popupId;
    this.iframeId = iframeId;
    this.htmlTargetElementId = htmlTargetElementId;
    this.visible = false;
    this.senderArea = new RectArea();
}
HelpPoup_PopupProperties.prototype = 
{ 
    toString: function()
    {
        var str = "";
        str = str + 'popupId = ' + this.popupId + '\n';
        str = str + 'iframeId = ' + this.iframeId + '\n';
        str = str + 'htmlTargetElementId = ' + this.htmlTargetElementId + '\n';
        str = str + 'visible = ' + this.visible + '\n';
        str = str + 'senderArea = ' + this.senderArea.toString() + '\n';
        return str;
    }
}

var helppopup_popupPropertiesArray;
function helppopup_init()
{
    helppopup_popupPropertiesArray = new Array(); 
    // Add onmouse event
    addListener(document, 'mousemove', helppopup_updateAllPopupVisibility);
}
function helppopup_addPopup(popupId, iframeId, htmlTargetElementId)
{
    var obj = new HelpPoup_PopupProperties(popupId,iframeId,htmlTargetElementId);
    helppopup_popupPropertiesArray[popupId] = obj;
}
function helppopup_show(senderId, popupId, pos, helpType, helpGroupId, helpElementId)
{
 
    // Get popup properties
    var prop = helppopup_popupPropertiesArray[popupId];
    
    if(prop == null)
        return false;
        
    // Get DOM elements
    var sender = $get(senderId);
    var popup = $get(popupId);
    var iframe = $get(prop.iframeId);
    var htmlTargetElement = $get(prop.htmlTargetElementId);
    var boundSender = Sys.UI.DomElement.getBounds(sender);
    // /!\ Popup can be in a relative or absolute container.
    // Relative position to this container has to be used instead of window position
    var relativeBoundSender = getRelativeBounds(sender,popup); //Sys.UI.DomElement.getBounds(target);
    var boundPopup = Sys.UI.DomElement.getBounds(popup);
    
    // Hide popup
    //popup.style.display = 'none';

    // Bound failed to get width/height from css attribut ...
    var widthPopup = popup.style.width.replace(/px/g,"");
    var heightPopup = popup.style.height.replace(/px/g,"");
    var widthSender = boundSender.width;
    var heightSender = boundSender.height;
    var margin = 5;
    
    // Compute new position
    var x = relativeBoundSender.x;
    var y = relativeBoundSender.y;
    switch(pos)
    {
        case "TopLeft" :
            x = x + widthSender - widthPopup;
            y = y - heightPopup - margin;
            break;
        case "TopRight" :
            x = x;
            y = y - heightPopup - margin;
            break;
        case "Left" :
            x = x - widthPopup - margin;
            y = y;
            break;
        case "Right" :
            x = x + widthSender + margin;
            y = y;
            break;
        case "BottomLeft" :
            x = x + widthSender - widthPopup;
            y = y + heightSender + margin;
            break;
        case "BottomRight" :
            x = x;
            y = y + heightSender + margin;
            break;
    }
    Sys.UI.DomElement.setLocation(popup, x, y);
    htmlTargetElement.scrollTop = 0;
    htmlTargetElement.innerHTML = '<img src="/Images2/loading_help.gif" alt="" />';
    
    // Show popup
    popup.style.display = 'block';
    
    // Update iframe heigth
    if(iframe != null)
    {
        iframe.style.height = htmlTargetElement.offsetHeight + 15;
    }
    
    // Update popup state
    var areaMargin = 5;
    prop.visible = true;
    prop.senderArea.x = boundSender.x - areaMargin;
    prop.senderArea.y = boundSender.y - areaMargin ;
    prop.senderArea.width = boundSender.width + 2*areaMargin;
    prop.senderArea.height = boundSender.height + 2*areaMargin;
        
    // Update content
    var helppopup_succeededCallback = function(result, eventArgs)
    {
        if(result == null)
        {
            htmlTargetElement.innerHTML = '<span class="al_helpPopupTextTitle">Help not found</span>';
        }
        else {
            // if (result.Title != "")
            //    htmlTargetElement.innerHTML = '<span class="al_helpPopupTextTitle">' + result.Title + '</span><br/><br/><div class="al_helpPopupTextContent">' + result.Text + '</div>';
            //else
                htmlTargetElement.innerHTML = '<div class="al_helpPopupTextContent">' + result.Text + '</div>';
        }
    }
    // This is the callback function invoked if the Web service failed.
    var helppopup_failedCallback = function(error)
    {
        htmlTargetElement.innerHTML = '<span class="al_helpPopupTextTitle">Error</span>';
        //displayAspNetFrameworkError("AssurlandWeb.WebRessourcesAccess.GetFormHelp failed",error);
    }
    
    // Call WS
    if(helpType == "Form")
        AssurlandWeb.WebRessourcesAccess.GetFormHelp(helpElementId, helppopup_succeededCallback, helppopup_failedCallback);
    else if(helpType == "Restitution")
        AssurlandWeb.WebRessourcesAccess.GetProductBaseHelp(helpGroupId, helpElementId, helppopup_succeededCallback, helppopup_failedCallback);
    else
        helppopup_succeededCallback(null, null);
}
function helppopup_hide(senderId, popupId)
{
    // Hide popup
    hide(popupId);
    
    var prop = helppopup_popupPropertiesArray[popupId];
    if(prop != null)
    {
        prop.visible = false; 
    }
}
function helppopup_hideAll()
{
    //alert("not implemented method");
}
// Sometimes, popup is not hidden after onmouseover event 
// (depending on sender/link size, mouse speed, ... ?)
// To resolve this unexpected bug, popup are hidden if 
// required (mouse is not the sender area and popup is still visible)
// at each mousemove event (performance leak ?)
function helppopup_updateAllPopupVisibility(e)
{
    if(helppopup_popupPropertiesArray != null)
    {
        var prop;
        var x = mouseX(e);
        var y = mouseY(e);
        for(key in helppopup_popupPropertiesArray)
        {
            prop = helppopup_popupPropertiesArray[key];
            if(prop.visible == true)
            {
                if(prop.senderArea.PtIn(x,y) == false)
                {
                    helppopup_hide(null, prop.popupId);
                }
            }
        }
    }
}

function helpLink_changeHelpElementId(hlId,helpGroupId,helpElementId) {
 var hl = $get(hlId); 
 var type="onmouseover";
 var linkAction =hl.onmouseover;

 if (linkAction == "") 
 {
    type="onclick";
    linkAction= hl.onclick;
 }
 linkAction=linkAction.toString();
 var newLink= "linkAction =" + linkAction.substring(0,linkAction.substring(0,linkAction.lastIndexOf(",")).lastIndexOf(","));
 newLink += ',"' + helpGroupId + '","'+ helpElementId + '");\n};';
eval(newLink);
newLink=linkAction;
 if (type=="onmouseover")
    hl.onmouseover=newLink;
 else
     hl.onclick=newLink;
}
// Init popup manager
// Start by code
//helppopup_init();


///////////////////////////////////////////////////////////////////
//        OLD FORM.js                                            //
///////////////////////////////////////////////////////////////////
// Assurland form client framework

var formId = null;
var formUpdatePanelId = null;
var formBtnValidateId = null;

////////////////////////////////////////
// WebForms
////////////////////////////////////////

var prm;
// Do before asynchrone page post
function beginRequest() {
    $get(formBtnValidateId).disabled = true;
    document.body.style.cursor = "progress";
    prm._scrollPosition = null;
}
// Do after asynchrone page post
function endRequest() {
    $get(formBtnValidateId).disabled = false;
    document.body.style.cursor = "";
    prm._scrollPosition = null;
}
if(typeof(Sys.WebForms) != 'undefined')
{
    prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_beginRequest(beginRequest);
    prm.add_endRequest(endRequest);
}

function form_doBeforePost() {
// NOT REQUIRED ANYMORE (Form background is white on white. Not flicked effect)
//    if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 7)
//    {
//        /* 
//            [IE6] During aschynchrone postback in updatepanel, dropdownlists flash
//            due to windows Interet Explorer rendering method. 
//            Page background, and not parent background, is visible. 
//            To attenuate this bad effect, dropdownlist are hidden before postback
//            to show parent background instead of page background.
//        */
//        var panel = $get(formUpdatePanelId);
//        if(panel != null)
//        {
//            hideElementByTypeIn(formUpdatePanelId, "select");
//        }
//    }
}

function form_escapeIFrame() {
    if (top.location != self.document.location) {
        // Post form in a new window
        document.forms[0].target = '_blank'; 
        // Remove asynchrone trigger on update panel
        if(formUpdatePanelId)
            Sys.WebForms.PageRequestManager.getInstance()._updateControls([formUpdatePanelId], [], [], 180);
     }
}

function isValidBonusByDrivLicenceDate(bonus, drivLicenceDate) {
    var years = calcul_age(drivLicenceDate);
    return isValidBonus(bonus, years);
}

////////////////////////////////////////
// Dynamic form error message manager
////////////////////////////////////////

var VALID = 0;
var ERROR = 1;
var WARNING = 2;

function ErrMgr_FormEltProperties(eltId,state,msgEltId,group,cssClassError,cssClassWarning)
{
    //TODO eltid=> targetId
    // element = label du message id
    this.eltId = eltId;
    this.state = state;
    this.msgEltId = msgEltId;
    this.group = group;    
    this.cssClassError = cssClassError;
    this.cssClassWarning =cssClassWarning;
}
ErrMgr_FormEltProperties.prototype = 
{ 
    toString: function()
    {
        var str = "";
        str = str + 'eltId = ' + this.eltId + '\n';
        str = str + 'state = ' + this.state + '\n';
        str = str + 'msgEltId = ' + this.msgEltId + '\n';
        str = str + 'group = ' + this.group + '\n';        
        str = str + 'cssClassError = ' + this.cssClassError + '\n';
        str = str + 'cssClassWarning = ' + this.cssClassWarning + '\n';
        return str;
    }
}
function ErrMgr_GroupProperties(name, rowId, questionRowId, questionCellId, arrowEltId, changeLabelQuestionActivate)
{
    this.name = name;
    this.rowId = rowId;
    this.questionRowId = questionRowId;
    this.questionCellId = questionCellId;
    this.arrowEltId = arrowEltId;
    this.changeLabelQuestionActivate = changeLabelQuestionActivate;
    this.formEltPropertiesArray = new Array();    
}
ErrMgr_GroupProperties.prototype = 
{ 
    toString: function()
    {
        var str = "";
        str = str + 'name = ' + this.name + '\n';
        str = str + 'rowId = ' + this.rowId + '\n';
        str = str + 'questionRowId = ' + this.questionRowId + '\n';
        str = str + 'questionCellId = ' + this.questionCellId + '\n';
        str = str + 'arrowEltId = ' + this.arrowEltId  + '\n';
        return str;
    }
}
ErrMgr_GroupProperties.prototype = 
{
    getState : function()
    {
        var state = VALID;
        for(i in this.formEltPropertiesArray)
        {
            if(this.formEltPropertiesArray[i].state == 1)
                return ERROR;
            else
                if(this.formEltPropertiesArray[i].state == 2)
                    state = WARNING;
        }
        return state;
    } 
}

// Arrays of form control' error properties
var errMgr_formEltPropertiesArray;
// Array of form group' error properties
var errMgr_groupPropertiesArray;
// Global error message ID
var errMgr_globalErrorMessageId = null;
// Error picto tooltip
var errMgt_errorPictoToolTip = "Cette information est incorrecte. Merci de la corriger afin de pouvoir passer à l'étape suivante.";
// Warning picto tooltip
var errMgt_warningPictoToolTip = "Cette information ne semble pas cohérente. Merci de vérifier votre saisie.";
// Error manager basic functions
function errMgr_reset()
{        
    errMgr_formEltPropertiesArray = new Array();
    errMgr_groupPropertiesArray = new Array();
}
function errMgr_init()
{
    errMgr_reset();
}
function errMgr_addFormElt(eltId,state,msgEltId,group,groupRowId,groupQuestionRowId,groupQuestionCellId,arrowEltId,cssClassError,cssClassWarning,changeLabelQuestionActivate)
{
    var obj = new ErrMgr_FormEltProperties(eltId,state,msgEltId,group,cssClassError,cssClassWarning);
    //alert(obj.toString());
    errMgr_formEltPropertiesArray[eltId] = obj;
    if(group != null)
    {
        if(errMgr_groupPropertiesArray[group] == null)
        {
            errMgr_addGroup(group, groupRowId, groupQuestionRowId, groupQuestionCellId, arrowEltId, changeLabelQuestionActivate);
        }
        var objGroup = errMgr_groupPropertiesArray[group];
        objGroup.formEltPropertiesArray[eltId] = obj;
    }
}
function errMgr_addGroup(name, rowId, questionRowId, questionCellId, arrowEltId, changeLabelQuestionActivate)
{
    var obj = new ErrMgr_GroupProperties(name, rowId, questionRowId, questionCellId, arrowEltId, changeLabelQuestionActivate);
    errMgr_groupPropertiesArray[name] = obj;
}
function errMgr_pageHasError()
{
    for(key in errMgr_formEltPropertiesArray)
    {
        if(errMgr_formEltPropertiesArray[key].state == ERROR)
            return true;
    }
    return false;
}
// Error manager function to notify state change
function errMgr_changeState(eltId, state, message)
{
 //alert("errMgr_changeState : " + message);
     eltProp = errMgr_formEltPropertiesArray[eltId];
    if(eltProp != null)
    {
        //alert(eltProp.toString());
        eltProp.state = state;
        // Hide/Show error message associoted to
        if($get(eltProp.msgEltId) != null)
        {
            if(eltProp.state == 0)            
                hide(eltProp.msgEltId);                
            else                
            {
                var msgEltCtrl = $get(eltProp.msgEltId)
                if (message!="") 
                    msgEltCtrl.innerHTML = message;                  
                
                if (state==1)
                    msgEltCtrl.className = eltProp.cssClassError;
                else
                    msgEltCtrl.className = eltProp.cssClassWarning;
                    
                show(eltProp.msgEltId);   
                
                msgEltCtrl=null;            
             }  
            groupProp = errMgr_groupPropertiesArray[eltProp.group];

            if(groupProp != null) {                
                if($get(groupProp.rowId) != null)
                {
                    //alert(groupProp.getState());
                    // Check state of all element in group
                    // and hide/show associated row
                    if(groupProp.getState() == VALID)
                    {
                        if (groupProp.changeLabelQuestionActivate && $get(groupProp.questionCellId) != null)
                            $get(groupProp.questionCellId).rowSpan = 1;
    
                        hideRow(groupProp.rowId);                                               
                        if(groupProp.arrowEltId != null)
                        {                       
                            ErrorPicto= form_eltPropertiesObjArray[groupProp.arrowEltId];                           
                            if (ErrorPicto)
                            {
                                $get(ErrorPicto.arrowId).className= ErrorPicto.cssClass;
                                $get(ErrorPicto.pictoId).className= ErrorPicto.cssClass;
                            }
                        }
                    }
                    else
                    {

                        if (groupProp.changeLabelQuestionActivate && $get(groupProp.questionCellId) != null)
                            $get(groupProp.questionCellId).rowSpan = 2;    
                            
                       showRow(groupProp.rowId);                     
                       if(groupProp.getState() == ERROR)
                        {   
                            if(groupProp.arrowEltId != null)
                            {                       
                                ErrorPicto= form_eltPropertiesObjArray[groupProp.arrowEltId];                               
                                if (ErrorPicto)
                                {
                                    $get(ErrorPicto.arrowId).className= ErrorPicto.cssClassError;
                                    picto=$get(ErrorPicto.pictoId);
                                    picto.className= ErrorPicto.cssClassError;
                                    picto.title = errMgt_errorPictoToolTip;
                                }
                            }                            
                        }
                        else
                        {                        
                            if(groupProp.arrowEltId != null)
                            {                       
                                ErrorPicto= form_eltPropertiesObjArray[groupProp.arrowEltId];                               
                                if (ErrorPicto)
                                {
                                    $get(ErrorPicto.arrowId).className= ErrorPicto.cssClassWarning;
                                    picto=$get(ErrorPicto.pictoId);
                                    picto.className= ErrorPicto.cssClassWarning;
                                    picto.title = errMgt_warningPictoToolTip;
                                }
                            }                            
                        }
                    }
                }
            }
        }
    }
    // Update global error message visibility
    errMgr_updateGlobalErrorMessageVisibility();
}
// Update global error visibility
function errMgr_updateGlobalErrorMessageVisibility()
{
     if(errMgr_pageHasError() == true)
        show(errMgr_globalErrorMessageId);
    else
        hide(errMgr_globalErrorMessageId);
}
// Get element state
function errMgr_getState(eltId) {
    var state = VALID;
    eltProp = errMgr_formEltPropertiesArray[eltId];
    if (eltProp != null) {
        state = eltProp.state;
    }
    return state;
}
// Init default error manager
errMgr_init();

////////////////////////////////////////
// Form element additional properties
////////////////////////////////////////

var form_eltPropertiesObjArray = new Array();
function form_addEltPropertiesObj(eltId, prop)
{
    form_eltPropertiesObjArray[eltId] = prop;    
}

function ErrorPictoProperties(ucId,cssClass,cssClassError,cssClassWarning,arrowId,pictoId)
{
    this.ucId = ucId;   
    this.arrowId = arrowId;  
    this.pictoId = pictoId;
    this.cssClass = cssClass;
    this.cssClassError = cssClassError;
    this.cssClassWarning = cssClassWarning;
}

function TextBoxWrapperProperties(ucId, eltId, initialValue, errorMode, defaultText, currentValueIsDefaultText, cssClass, cssClassFocus, cssClassError, cssClassDefaultText, cssClassDefaultTextError, cssClassWarning, messageError, clientFunctionError, clientFunctionWarning, allowDefaultValue, hasMask,mask, inputDirectionMask, clearMaskOnLostFocus, clientFunctionRemoveMask, zipCodeDropDownListDynamicVisibility)
{ 
    this.ucId = ucId;
    this.eltId = eltId;
    this.initialValue = initialValue;
    this.errorMode = errorMode;
    this.defaultText = defaultText;
    this.currentValueIsDefaultText = currentValueIsDefaultText;
    this.cssClass = cssClass;
    this.cssClassFocus = cssClassFocus;
    this.cssClassError = cssClassError;
    this.cssClassDefaultText = cssClassDefaultText;
    this.cssClassDefaultTextError = cssClassDefaultTextError;
    this.cssClassWarning=cssClassWarning;
    this.messageError=messageError;
    this.clientFunctionError=clientFunctionError;
    this.clientFunctionWarning = clientFunctionWarning;
    this.allowDefaultValue = allowDefaultValue;
    this.hasMask = hasMask;
    this.mask =mask;
    this.inputDirectionMask = inputDirectionMask;
    this.clearMaskOnLostFocus = clearMaskOnLostFocus;
    this.clientFunctionRemoveMask = clientFunctionRemoveMask;
    this.zipCodeDropDownListDynamicVisibility = zipCodeDropDownListDynamicVisibility;
   
}
TextBoxWrapperProperties.prototype = 
{ 
    toString: function()
    {
        var str = "";
        str = str + 'ucId = ' + this.ucId + '\n';
        str = str + 'eltId = ' + this.eltId + '\n';
        str = str + 'initialValue = ' + this.initialValue + '\n';
        str = str + 'errorMode = ' + this.errorMode + '\n';
        str = str + 'defaultText = ' + this.defaultText + '\n';
        str = str + 'currentValueIsDefaultText = ' + this.currentValueIsDefaultText + '\n';
        str = str + 'cssClass = ' + this.cssClass + '\n';
        str = str + 'cssClassFocus = ' + this.cssClassFocus + '\n';
        str = str + 'cssClassError = ' + this.cssClassError + '\n';
        str = str + 'cssClassDefaultText = ' + this.cssClassDefaultText + '\n';
        str = str + 'cssClassDefaultTextError = ' + this.cssClassDefaultTextError + '\n';
        str = str + 'cssClassWarning = ' +this.cssClassWarning + '\n';
        str = str + 'messageError = ' + this.messageError + '\n';
        str = str + 'clientFunctionError = '+ this.clientFunctionError + '\n';
        str = str + 'clientFunctionWarning = ' + this.clientFunctionWarning + '\n';
        str = str + 'allowDefaultValue = ' + this.allowDefaultValue + '\n';
        str = str + 'hasMask = ' + this.hasMask + '\n';
        str = str + 'inputDirectionMask = ' + this.inputDirectionMask + '\n';
        str = str + 'clearMaskOnLostFocus = ' + this.clearMaskOnLostFocus + '\n';
        str = str + 'clientFunctionRemoveMask = ' + this.clientFunctionRemoveMask + '\n';
        str = str + 'zipCodeDropDownListDynamicVisibility = ' + this.zipCodeDropDownListDynamicVisibility + '\n';
        return str;
    }
}
function DropDownListWrapperProperties(ucId, eltId, initialValue, errorMode, cssClass, cssClassFocus, cssClassError, formDataListTypeId, hfIdFormDataListTypeLoadedOnClient, populatedOnClient, defaultValue, currentValueIsDefaultValue, cssClassWarning, messageError, clientFunctionError, clientFunctionWarning)
{ 
    this.ucId = ucId;
    this.eltId = eltId;
    this.initialValue = initialValue;
    this.errorMode = errorMode;
    this.cssClass = cssClass;
    this.cssClassFocus = cssClassFocus;
    this.cssClassError = cssClassError;
    this.formDataListTypeId = formDataListTypeId;
    this.hfIdFormDataListTypeLoadedOnClient = hfIdFormDataListTypeLoadedOnClient;
    this.populatedOnClient = populatedOnClient;
    this.defaultValue = defaultValue;
    this.currentValueIsDefaultValue = currentValueIsDefaultValue;
    this.cssClassWarning=cssClassWarning;
    this.messageError=messageError;
    this.clientFunctionError=clientFunctionError;
    this.clientFunctionWarning=clientFunctionWarning;    
}
DropDownListWrapperProperties.prototype = 
{ 
    toString: function()
    {
        var str = "";
        str = str + 'ucId = ' + this.ucId + '\n';
        str = str + 'eltId = ' + this.eltId + '\n';
        str = str + 'initialValue = ' + this.initialValue + '\n';
        str = str + 'errorMode = ' + this.errorMode + '\n';
        str = str + 'cssClass = ' + this.cssClass + '\n';
        str = str + 'cssClassFocus = ' + this.cssClassFocus + '\n';
        str = str + 'cssClassError = ' + this.cssClassError + '\n';
        str = str + 'formDataListTypeId = ' + this.formDataListTypeId + '\n';
        str = str + 'hfIdFormDataListTypeLoadedOnClient = ' + this.hfIdFormDataListTypeLoadedOnClient + '\n';
        str = str + 'populatedOnClient = ' + this.populatedOnClient + '\n';
        str = str + 'defaultValue = ' + this.defaultValue + '\n';
        str = str + 'currentValueIsDefaultValue = ' + this.currentValueIsDefaultValue + '\n';
        str = str + 'cssClassWarning = ' +this.cssClassWarning + '\n';
        str = str + 'messageError = ' + this.messageError + '\n';
        str = str + 'clientFunctionError = '+ this.clientFunctionError + '\n';
        str = str + 'clientFunctionWarning = ' + this.clientFunctionWarning + '\n';
        return str;
    }
}
function DateDropDownListWrapperProperties(ucId,ddlDayId,ddlMonthId,ddlYearId,selectionMode,initialValue,errorMode,cssClass,cssClassFocus,cssClassError,cssClassWarning,messageError,clientFunctionError,clientFunctionWarning)
{
    this.ucId = ucId; 
    this.ddlDayId = ddlDayId;
    this.ddlMonthId = ddlMonthId;
    this.ddlYearId = ddlYearId;
    this.selectionMode = selectionMode;
    this.initialValue = initialValue;
    this.errorMode = errorMode;
    this.cssClass = cssClass;
    this.cssClassFocus = cssClassFocus;
    this.cssClassError = cssClassError;
    this.cssClassWarning=cssClassWarning;
    this.messageError=messageError;
    this.clientFunctionError=clientFunctionError;
    this.clientFunctionWarning=clientFunctionWarning;
}
DateDropDownListWrapperProperties.prototype = 
{ 
    toString: function()
    {
        var str = "";
        str = str + 'ucId = ' + this.ucId + '\n';
        str = str + 'ddlDayId = ' + this.ddlDayId + '\n';
        str = str + 'ddlMonthId = ' + this.ddlMonthId + '\n';
        str = str + 'ddlYearId = ' + this.ddlYearId + '\n';
        str = str + 'selectionMode = ' + this.selectionMode + '\n';
        str = str + 'initialValue = ' + this.initialValue + '\n';
        str = str + 'errorMode = ' + this.errorMode + '\n';
        str = str + 'cssClass = ' + this.cssClass + '\n';
        str = str + 'cssClassFocus = ' + this.cssClassFocus + '\n';
        str = str + 'cssClassError = ' + this.cssClassError + '\n';
        str = str + 'cssClassWarning = ' +this.cssClassWarning + '\n';
        str = str + 'messageError = ' + this.messageError + '\n';
        str = str + 'clientFunctionError = '+ this.clientFunctionError + '\n';
        str = str + 'clientFunctionWarning = ' + this.clientFunctionWarning + '\n';
        return str;
    }
}
DateDropDownListWrapperProperties.prototype = 
{
    getValue : function()
    {
    	var v = '';
		if(this.selectionMode == 1)
		{
			v = v + $get(this.ddlDayId).value;
			v = v + '/';
	    }
		v = v + $get(this.ddlMonthId).value;
		v = v + '/';
		v = v + $get(this.ddlYearId).value;
		return v;
    }
}
function RadioButtonListWrapperProperties(ucId, eltId, initialValue, errorMode, cssClass, cssClassError, groupName, defaultValue, currentValueIsDefaultValue, cssClassWarning, messageError, clientFunctionError, clientFunctionWarning)
{
    this.ucId = ucId;
    this.eltId = eltId;
    this.initialValue = initialValue;
    this.errorMode = errorMode;
    this.cssClass = cssClass;
    this.cssClassError = cssClassError;
    this.groupName = groupName;
    this.defaultValue = defaultValue;
    this.currentValueIsDefaultValue = currentValueIsDefaultValue;
    this.cssClassWarning=cssClassWarning;
    this.messageError=messageError;
    this.clientFunctionError=clientFunctionError;
    this.clientFunctionWarning=clientFunctionWarning;
}
RadioButtonListWrapperProperties.prototype = 
{ 
    toString: function()
    {
        var str = "";
        str = str + 'ucId = ' + this.ucId + '\n';
        str = str + 'eltId = ' + this.eltId + '\n';
        str = str + 'initialValue = ' + this.initialValue + '\n';
        str = str + 'errorMode = ' + this.errorMode + '\n';
        str = str + 'cssClass = ' + this.cssClass + '\n';
        str = str + 'cssClassError = ' + this.cssClassError + '\n';
        str = str + 'groupName = ' + this.groupName + '\n';
        str = str + 'defaultValue = ' + this.defaultValue + '\n';
        str = str + 'currentValueIsDefaultValue = ' + this.currentValueIsDefaultValue + '\n';
        str = str + 'cssClassWarning = ' +this.cssClassWarning + '\n';
        str = str + 'messageError = ' + this.messageError + '\n';
        str = str + 'clientFunctionError = '+ this.clientFunctionError + '\n';
        str = str + 'clientFunctionWarning = ' + this.clientFunctionWarning + '\n';
        return str;
    }
}

function ListItem(v,t)
{
  this.Value = v;
  this.Text = t;
}
ListItem.prototype = 
{ 
    toString: function()
    {
        var str = "";
        str = str + 'Value = ' + this.Value + '\n';
        str = str + 'Text = ' + this.Text + '\n';
        return str;
    }
}

////////////////////////////////////////
// Form element handler
////////////////////////////////////////

var maskSpace = String.fromCharCode(160);
function RemoveNumericMask(str) {
    var reg;
    // Remove space first
    reg = new RegExp("(" + maskSpace + ")", "g");
    str = str.replace(reg, "");
    // Remove all '_' on left
    str = trimCharLeft(str, " ");
    // Replace all '_' By ''
    str = str.replace(/( )/g, "");
    return str;
}

function RestoreNumericMask(value)
{
 //rajout d'un espace tout les 3 caract
  var maskedValue = '';
  value=""+value;
  for (var i=value.length-1; i>=0; i--) {
    maskedValue = value.charAt(i) + maskedValue;
    if (i>0 && (value.length-i)%3 == 0){
        maskedValue = " " + maskedValue;
      }
    
  } 
  return maskedValue;

}

function RemovePhoneNumberMask(str) {
    // Remove space first
    reg = new RegExp("(" + maskSpace + ")", "g");
    str = str.replace(reg, "");
    // Remove all '_'
    reg = new RegExp("(_)", "g");
    str = str.replace(reg, "");
    // Remove all '.'
    reg = new RegExp("(\\.)", "g");
    str = str.replace(reg, "");
    return str;
}

function textBox_findCssClass(eltId) {
    var prop = form_eltPropertiesObjArray[eltId];
    if (prop != null) {
        var state = errMgr_getState(eltId);
        if (state == WARNING) {
            // Warning
            return prop.cssClassWarning;
        }
        else if (state == ERROR) {
            // Error
            if (prop.currentValueIsDefaultText)
                return prop.cssClassDefaultTextError;
            else
                return prop.cssClassError;
        }
        else {
            // No error, no warning
            if (prop.currentValueIsDefaultText)
                return prop.cssClassDefaultText;
            else
                return prop.cssClass;
            return 
        }
    }
    return "";
}

function textBox_clear(eltId)
{
    var elt = $get(eltId);
    if(elt != null) 
    {
        elt.value = "";
        var prop = form_eltPropertiesObjArray[elt.id];
        if(prop != null)
        {
            if (prop.defaultText != null) {
                elt.value = prop.defaultText;
                prop.currentValueIsDefaultText = true;
            }
        }
        textBox_clearError(eltId);
    }
}
function textBox_clearError(eltId)
{
    var elt = $get(eltId);
    if(elt != null) 
    {
        var prop = form_eltPropertiesObjArray[eltId];
        if(prop != null)
        {
            prop.errorMode = false;
            errMgr_changeState(eltId, VALID);
            elt.className = textBox_findCssClass(eltId);
        }
    }
}
function textBox_disable(eltId)
{
    textBox_setEnabled(eltId, false);
}
function textBox_enable(eltId)
{
    textBox_setEnabled(eltId, true);    
}
function textBox_setEnabled(eltId, enabled)
{
    setTextBoxEnabled(eltId, enabled);
    if(enabled == false)
        textBox_clearError(eltId);
}
function textBox_reset(eltId)
{
    textBox_clear(eltId);
}
function textBox_show(eltId)
{
    show(eltId);
}
function textBox_hide(eltId)
{
    textBox_clearError(eltId);
    hide(eltId);
}
function textBox_onfocus(sender)
{
    var prop = form_eltPropertiesObjArray[sender.id];
    if(prop != null)
    {
        if(prop.defaultText != null)
        {
            if (prop.currentValueIsDefaultText && sender.value ==prop.defaultText )
                sender.value = '';
        }
        if(prop.cssClassFocus != null)
        {
            sender.className = prop.cssClassFocus;
        }

        if (prop.hasMask) {
            // Chrome remove cursor in next non accessible events
            // Force move cursor after (n ms)
            if (navigator.userAgent.indexOf('WebKit/') > -1) {
                setTimeout("setSelectionRangeChrome('" + sender.id + "')", 10);
            }
        }
    }
}
function textBox_onblur(sender) {
    var prop = form_eltPropertiesObjArray[sender.id];
    if(prop != null) {
        var value = sender.value;
        
        // Remove mask if required
        if (prop.hasMask && prop.clearMaskOnLostFocus)
            value = prop.clientFunctionRemoveMask(value);

        // Move to default value ?
        if (prop.defaultText != null
            && (value == '' || (value == prop.defaultText && !prop.allowDefaultValue)
            || value==prop.mask)) {
            prop.currentValueIsDefaultText = true
            sender.value = prop.defaultText;
            value = sender.value;
        }
        else
            prop.currentValueIsDefaultText = false
          
        // Has warning ?
        var messWarning="";
        if(prop.clientFunctionWarning != null)
        {       
            messWarning = prop.clientFunctionWarning(sender); 
        }
        
        if(prop.errorMode == false)        
        {
            if(messWarning!="")
                errMgr_changeState(prop.eltId, WARNING, messWarning);                            
            else
                errMgr_changeState(prop.eltId, VALID);
        }       
        else
        {
            var messError="";   
            if( prop.clientFunctionError == null) {
                if(value == prop.initialValue)
                    messError = prop.messageError;
            }
            else
            {            
                messError = prop.clientFunctionError(sender);                         
            }
            if (messError != "") {
                errMgr_changeState(prop.eltId, ERROR, messError);
            }
            else {
                if (messWarning != "")
                    errMgr_changeState(prop.eltId, WARNING, messWarning);
                else
                    errMgr_changeState(prop.eltId, VALID);
            }
        }

        // Update CssClass
        sender.className = textBox_findCssClass(prop.eltId);
    }
}
function textBox_onUpdate(sender) {
    //Function call to update error or warning message and css style
    if (sender)
        sender.onblur();
}
/* Cursor to Mask on chrome */
function setSelectionRangeChrome(id) {
    var prop = form_eltPropertiesObjArray[id];
    if (prop != null) {
        var input = $get(prop.eltId);
        if (input.setSelectionRange) {
            if (prop.inputDirectionMask == 0)
                input.setSelectionRange(-1, -1);
            else
                input.setSelectionRange(input.value.length, input.value.length);
        }
        input.focus();
    }
}

function dropDownList_findCssClass(eltId) {
    var prop = form_eltPropertiesObjArray[eltId];
    if (prop != null) {
        var state = errMgr_getState(eltId);
        if (state == WARNING) {
            // Warning
            return prop.cssClassWarning;
        }
        else if (state == ERROR) {
            return prop.cssClassError;
        }
        else {
            return prop.cssClass;
        }
    }
    return "";
}

function dropDownList_clear(eltId)
{
    var elt = $get(eltId);
    if(elt != null) 
    {
        clearDropDownList(eltId);
        var prop = form_eltPropertiesObjArray[eltId];
        if(prop != null)
        {
            prop.formDataListTypeId = -1;
            if(prop.populatedOnClient == true)
            {
                var hf = $get(prop.hfIdFormDataListTypeLoadedOnClient);
                if(hf != null)
                    hf.value = "-1";
            }
        }
        dropDownList_clearError(eltId);
    }
}
function dropDownList_clearSelection(eltId)
{
    var elt = $get(eltId);
    if(elt != null) 
    {
        clearSelectionDropDownList(eltId);
        var prop = form_eltPropertiesObjArray[eltId];
        if(prop != null)
        {
            if(prop.defaultValue != null)
                elt.value = prop.defaultValue;
        }
        dropDownList_clearError(eltId);
    }
}
function dropDownList_clearError(eltId)
{
    var elt = $get(eltId);
    if(elt != null) 
    {
        var prop = form_eltPropertiesObjArray[eltId];
        if(prop != null)
        {
            prop.errorMode = false;
            errMgr_changeState(eltId, VALID);
            elt.className = dropDownList_findCssClass(eltId);
        }
    }
}
function dropDownList_disable(eltId)
{
    dropDownList_setEnabled(eltId, false);
}
function dropDownList_enable(eltId)
{
    dropDownList_setEnabled(eltId, true);    
}
function dropDownList_setEnabled(eltId, enabled)
{
    setDropDownListEnabled(eltId, enabled);
    if(enabled == false)
        dropDownList_clearError(eltId);
}
function dropDownList_reset(eltId)
{
    dropDownList_clearSelection(eltId);
}
function dropDownList_show(eltId)
{
    show(eltId);
}
function dropDownList_hide(eltId)
{
    dropDownList_clearError(eltId);
    hide(eltId);
}
function dropDownList_onfocusin(sender)
{
    var prop = form_eltPropertiesObjArray[sender.id];
    if(prop != null)
    {
        if(prop.cssClassFocus != null)
        {
            if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version >= 7)
                    sender.className = prop.cssClassFocus;
            else {
                // See dropDownList_onfocus
            }
        }
    }
}
function dropDownList_onfocus(sender)
{
    var prop = form_eltPropertiesObjArray[sender.id];
    if(prop != null)
    {
        if(prop.cssClassFocus != null)
        {
            if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version >= 7) {
                // See dropDownList_onfocusin ...
            }
            else
                sender.className = prop.cssClassFocus;
        }
    }
}
function dropDownList_onchange(sender) {
    var prop = form_eltPropertiesObjArray[sender.id];
    if(prop != null)
    {
        var value = sender.value;

        // Default value is allowed.
        // After any change, value is not default value anymore
        prop.currentValueIsDefaultValue = false;
        
        var messWarning="";        
        if(prop.clientFunctionWarning != null)
        {       
            messWarning=prop.clientFunctionWarning(sender);
        }
        
        if(prop.errorMode == true)
        {
            var messError="";                 
            if( prop.clientFunctionError == null) { 
                if(value == prop.initialValue)
                    messError=prop.messageError;
            }              
            else
                messError=prop.clientFunctionError(sender); 
                
            if(messError!="")
            {
                errMgr_changeState(prop.eltId, ERROR, messError);
            }
            else
            {
                if (messWarning!="")
                    errMgr_changeState(prop.eltId, WARNING, messWarning);
                else
                    errMgr_changeState(prop.eltId, VALID);
            }
        }
        else
            if (messWarning!="")
                errMgr_changeState(prop.eltId, WARNING, messWarning);
            else
                errMgr_changeState(prop.eltId, VALID);
    }
    
    // Css class is updated in onblur event
}
function dropDownList_onblur(sender)
{
    var prop = form_eltPropertiesObjArray[sender.id];
    if (prop != null) {
        sender.className = dropDownList_findCssClass(prop.eltId); 
    }
    // Control state is updated in onchange event
}
function dropDownList_fill(eltId, formDataListTypeId, defaultValue, selectedValue, addFirstItemText, firstItemText)
{                      
    var dropDownList_fillCallback = function(result, eventArgs)
    {
        dropDownList_bind(eltId, formDataListTypeId, result, defaultValue, selectedValue, addFirstItemText, firstItemText);  
    }
    // This is the callback function invoked if the Web service failed.
    var dropDownList_fillFailedCallback = function (error)
    {
        // Clear list and update formDataListTypeId property 
        // to allow list update on server-side on postback even if request failed ...
        var prop = form_eltPropertiesObjArray[eltId];
        if(prop != null)
        {
            if(formDataListTypeId == -1 || prop.formDataListTypeId != formDataListTypeId)
            {
                dropDownList_clear(eltId);
                prop.formDataListTypeId = formDataListTypeId;
                var hf = $get(prop.hfIdFormDataListTypeLoadedOnClient);
                if(hf != null)
                    hf.value = formDataListTypeId;
            }
        }
        
        displayAspNetFrameworkError("AssurlandWeb.WebRessourcesAccess.GetFormDataList failed",error);
    }
    // Call WS
    AssurlandWeb.WebRessourcesAccess.GetFormDataList(formDataListTypeId, dropDownList_fillCallback, dropDownList_fillFailedCallback);
}
function dropDownList_bind(eltId, formDataListTypeId, result, defaultValue, selectedValue, addFirstItemText, firstItemText)
{
    var prop = form_eltPropertiesObjArray[eltId];
    var dv="";
    var bFindSelectedValue=false;
    var optionsDefaultValue;
    if (addFirstItemText == null)
        addFirstItemText = true;
    if(firstItemText == null || firstItemText == "")
        firstItemText = "-- Sélectionnez --";
    if(prop != null)
    {
        if(formDataListTypeId != -1 && prop.formDataListTypeId == formDataListTypeId)
            return;
                    
        var elt = $get(eltId);
        if(elt != null) 
        {
            // Clear list
            dropDownList_clear(eltId);
            
            // Update form data list type id
            prop.formDataListTypeId = formDataListTypeId;
            var hf = $get(prop.hfIdFormDataListTypeLoadedOnClient);
            if(hf != null)
                hf.value = formDataListTypeId;
         
            // Feed new list
            if(result.length > 0) {
                if (addFirstItemText) {
                    elt.options[0] = new Option(firstItemText, "");
                }
                for(var i=0; i<result.length; i++) {
                    var j = i;
                    if (addFirstItemText) {
                        j = i + 1;
                    }
                    elt.options[j] = new Option(result[i].Text, result[i].Value);
                    if (selectedValue)
                        if (result[i].Value == selectedValue)
                            {
                                elt.options[j].selected = true;
                                bFindSelectedValue=true;
                             }
                    if (defaultValue)
                        if (result[i].Value == defaultValue)  
                            {
                                optionsDefaultValue = elt.options[j];
                             }
                }
                if( !bFindSelectedValue)
                    if (optionsDefaultValue)
                        optionsDefaultValue.selected=true;
            }
        }
    }
}
function dropDownList_onUpdate(sender) {
    //Function call to update error or warning message and css style
    if (sender) {
        sender.onchange();
        sender.onblur();
    }
}

function dateDropDownList_clearSelection(eltId)
{
    var prop = form_eltPropertiesObjArray[eltId];
    if(prop != null)
    {
        clearSelectionDropDownList(prop.ddlDayId);
        clearSelectionDropDownList(prop.ddlMonthId);
        clearSelectionDropDownList(prop.ddlYearId);    
    }
    dateDropDownList_clearError(eltId)
}
function dateDropDownList_clearError(eltId)
{
    var prop = form_eltPropertiesObjArray[eltId];
    if(prop != null)
    {
        prop.errorMode = false;
        errMgr_changeState(eltId, VALID);
    }
}
function dateDropDownList_reset(eltId)
{
    dateDropDownList_clearSelection(eltId);
}
function dateDropDownList_show(eltId)
{
    alert("Not implemented method (dateDropDownList_show)");
}
function  dateDropDownList_hide(eltId)
{
    alert("Not implemented method (dateDropDownList_hide)");
}
function  dateDropDownList_getDate(eltId)
{
    var prop = form_eltPropertiesObjArray[eltId];    
    if(prop != null)
    {
        if ($get(prop.ddlDayId))
            return new Date($get(prop.ddlYearId).value,$get(prop.ddlMonthId).value-1,$get(prop.ddlDayId).value);
        else{
            if ($get(prop.ddlYearId).value > 0)
                return new Date($get(prop.ddlYearId).value,$get(prop.ddlMonthId).value-1,1);
            else
                 return null;
        }
    }
    return null;
}
function dateDropDownList_setDate(eltId,date)
{
    var prop = form_eltPropertiesObjArray[eltId];    
    if(prop != null)
    {
        if ($get(prop.ddlDayId))
            $get(prop.ddlDayId).value=date.getDate();
            
        $get(prop.ddlMonthId).value=date.getMonth()+1  ;            
        $get(prop.ddlYearId).value=date.getFullYear();
    }
}
function dateDropDownList_onfocusin(sender, parentId)
{
    var prop = form_eltPropertiesObjArray[parentId];
    if(prop != null)
    {
        if(prop.cssClassFocus != null)
        {
            if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version >= 7)
                sender.className = prop.cssClassFocus;
            else {
                // See dropDownList_onfocus
            }
        }
    }
}
function dateDropDownList_onfocus(sender, parentId)
{
    var prop = form_eltPropertiesObjArray[parentId];
    if(prop != null)
    {
        if(prop.cssClassFocus != null)
        {
            if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version >= 7) {
                // See dropDownList_onfocusin ...
            }
            else
                sender.className = prop.cssClassFocus;
        }
    }
}
function dateDropDownList_onblur(sender, parentId)
{
    var prop = form_eltPropertiesObjArray[parentId];
    if(prop != null)
    {
        var ddlDay = $get(prop.ddlDayId);
        var ddlMonth = $get(prop.ddlMonthId);
        var ddlYear = $get(prop.ddlYearId);
        var value = prop.getValue();
        var messWarning="";        
        if(prop.clientFunctionWarning != null)
        {       
            messWarning=prop.clientFunctionWarning(sender); 
        }   
        if(prop.errorMode == true)
        {
            var messError="";                 
            if( prop.clientFunctionError == null)
            {
                if(value == prop.initialValue)
                    messError=prop.messageError;
            }
            else
                messError=prop.clientFunctionError(sender);
                
            if(messError!="")
            {
                sender.className = prop.cssClassError;
                // Please see onchange event for other dropdownlist css updates
                //errMgr_changeState(prop.ucId, 1);
            }
            else
            {
                if (messWarning!="")
                    sender.className = prop.cssClassWarning;
                else
                    sender.className = prop.cssClass;
                // Please see onchange event for other dropdownlist css updates
                //errMgr_changeState(prop.ucId, 0);
            }
        }
        else
        {
            if (messWarning!="")
                sender.className = prop.cssClassWarning;
            else
                sender.className = prop.cssClass;
        }
    }
}
function dateDropDownList_onchange(sender, parentId)
{
    var prop = form_eltPropertiesObjArray[parentId];
    if(prop != null)
    {
        var ddlDay = $get(prop.ddlDayId);
        var ddlMonth = $get(prop.ddlMonthId);
        var ddlYear = $get(prop.ddlYearId);
        var value = prop.getValue();
        
         var messWarning="";        
        if(prop.clientFunctionWarning != null)
        {       
            messWarning=prop.clientFunctionWarning(sender); 
        }  
        if(prop.errorMode == true)
        {
            // Please see onblur event for sender dropdownlist css updates
            var messError="";                 
            if( prop.clientFunctionError == null)
            {
                if(value == prop.initialValue)
                    messError=prop.messageError;
            }
            else
                messError=prop.clientFunctionError(sender);
                
            if(messError!="")
            {                    
                if(prop.selectionMode == 1)
                    if(sender.id != ddlDay.id)
                        ddlDay.className = prop.cssClassError;
                if(sender.id != ddlMonth.id)
                    ddlMonth.className = prop.cssClassError;
                if(sender.id != ddlYear.id)
                    ddlYear.className = prop.cssClassError;
                errMgr_changeState(prop.ucId, ERROR, messError);
            }
            else
            {
                if (messWarning!="")
                {
                   if(prop.selectionMode == 1)
                        if(sender.id != ddlDay.id)
                            ddlDay.className = prop.cssClassWarning;
                    if(sender.id != ddlMonth.id)
                        ddlMonth.className = prop.cssClassWarning;
                    if(sender.id != ddlYear.id)
                        ddlYear.className = prop.cssClassWarning;
                    errMgr_changeState(prop.ucId, WARNING, messWarning); 
                }
                else
                {
                    if(prop.selectionMode == 1)
                        if(sender.id != ddlDay.id)
                            ddlDay.className = prop.cssClass;
                    if(sender.id != ddlMonth.id)
                        ddlMonth.className = prop.cssClass;
                    if(sender.id != ddlYear.id)
                        ddlYear.className = prop.cssClass;
                    errMgr_changeState(prop.ucId, VALID);
                }
            }
        }
        else
        {
            if (messWarning!="")
            {
               if(prop.selectionMode == 1)
                    if(sender.id != ddlDay.id)
                        ddlDay.className = prop.cssClassWarning;
                if(sender.id != ddlMonth.id)
                    ddlMonth.className = prop.cssClassWarning;
                if(sender.id != ddlYear.id)
                    ddlYear.className = prop.cssClassWarning;
                errMgr_changeState(prop.ucId, WARNING, messWarning); 
            }
            else
            {
                if(prop.selectionMode == 1)
                    if(sender.id != ddlDay.id)
                        ddlDay.className = prop.cssClass;
                if(sender.id != ddlMonth.id)
                    ddlMonth.className = prop.cssClass;
                if(sender.id != ddlYear.id)
                    ddlYear.className = prop.cssClass;
                errMgr_changeState(prop.ucId, VALID);
            }
        }
    }
}

function dateDropDownList_onUpdate(sender) {
    //Function call to update error or warning message and css style
    if (sender) {
        sender.onchange();
        sender.onblur();
    }
}

function radioButtonList_clearSelection(eltId)
{
    var prop = form_eltPropertiesObjArray[eltId];
    if(prop != null)
    {
        $get(prop.eltId).className = prop.cssClass;
        clearSelectionRadioButtonList(prop.groupName);
        if(prop.defaultValue != null)
        {
            selectItemRadioButtonList(prop.groupName, prop.defaultValue);
        }
        radioButtonList_clearError(eltId);
    }
}
function radioButtonList_clearError(eltId)
{
    var prop = form_eltPropertiesObjArray[eltId];
    if(prop != null)
    {
        prop.errorMode = false;
        errMgr_changeState(eltId, VALID);
        $get(prop.eltId).className = prop.cssClass;
    }
}
function radioButtonList_disable(eltId)
{
    radioButtonList_setEnabled(eltId, false);
}
function radioButtonList_enable(eltId)
{
    radioButtonList_setEnabled(eltId, true);    
}
function radioButtonList_setEnabled(eltId, enabled)
{
    var prop = form_eltPropertiesObjArray[eltId];
    if(prop != null)
    {
        setRadioButtonListEnabled(prop.groupName, enabled);
    }
    if(enabled == false)
        radioButtonList_clearError(eltId);
}
function radioButtonList_reset(eltId)
{
    radioButtonList_clearSelection(eltId);
}
function radioButtonList_show(eltId)
{
    show(eltId);
}
function radioButtonList_hide(eltId)
{
    radioButtonList_clearError(eltId);
    hide(eltId);
}
function radioButtonList_click(sender, rblId)
{
    var prop = form_eltPropertiesObjArray[rblId];
    if(prop != null)
    {
        var elt = $get(prop.eltId);
        var value = "";
        if (sender != null)
            value = sender.value;

        // Default value is allowed.
        // After any change, value is not default value anymore
        prop.currentValueIsDefaultValue = false;
            
        var messWarning="";        
        if(prop.clientFunctionWarning != null)
        {       
            messWarning=prop.clientFunctionWarning(sender); 
        }           
        if(elt != null)
        {
            if(prop.errorMode == true)
            {
                var messError="";                 
                if( prop.clientFunctionError == null)
                {
                    if(value == prop.initialValue)
                        messError=prop.messageError;
                }               
                else
                    messError=prop.clientFunctionError(sender); 
                    
                if(messError!="")
                {
                    elt.className = prop.cssClassError;
                    errMgr_changeState(prop.eltId, ERROR, messError);
                }
                else
                {
                    if (messWarning!="")
                    {
                        elt.className = prop.cssClassWarning;
                        errMgr_changeState(prop.eltId, WARNING, messWarning);
                    }
                    else
                    {                    
                        elt.className = prop.cssClass;
                        errMgr_changeState(prop.eltId, VALID);
                    }
                }
            }
            else
            {
                if (messWarning!="")
                {
                    elt.className = prop.cssClassWarning;
                    errMgr_changeState(prop.eltId, WARNING, messWarning);
                }
                else
                {                    
                    elt.className = prop.cssClass;
                    errMgr_changeState(prop.eltId, VALID);
                }
            }
          radioButtonList_setClassSelected(prop.groupName)
        }
    }
}
function radioButtonList_setClassSelected(groupName)
{
    var radioGroup = document.getElementsByName(groupName);
    for (var i = 0; i < radioGroup.length; i++){
        radioGroup[i].parentNode.className = radioGroup[i].parentNode.className.replace(' al_selected','');
        if (radioGroup[i].checked)
             radioGroup[i].parentNode.className = radioGroup[i].parentNode.className + ' al_selected';
    }
        
}
function radioButtonList_setSelectedValue(rblId, value) {
    var prop = form_eltPropertiesObjArray[rblId];
    if (prop != null) {
        selectItemRadioButtonList(prop.groupName, value);
    }
    radioButtonList_onUpdateById(rblId);
}
function radioButtonList_getSelectedValue(rblId)
{
    var prop = form_eltPropertiesObjArray[rblId];
    if(prop != null)
    {
        return getRadioButtonListSelectedValue(prop.groupName)
    } 
    return null;
}
function radioButtonList_getItemByValue(rblId, value)
{
    var prop = form_eltPropertiesObjArray[rblId];
    if(prop != null)
    {
        return getRadioButtonItem(prop.groupName, value);
    }
    return null;
}
function radioButtonList_getLabelItemByValue(rblId, value)
{
    var item = radioButtonList_getItemByValue(rblId, value);
    // Search associated label
    var elt = $get(rblId);
    if(elt != null)
    {
        var obj = elt.getElementsByTagName("label");
        if(obj && obj.length)
        {
            for(var i=0; i < obj.length; i++)
            {
                if(obj[i].htmlFor == item.id)
                {
                    return obj[i]
                }
            }
        }
    }
}
function radioButtonList_updateLabelByValue(rblId, value, text)
{        
    var label = radioButtonList_getLabelItemByValue(rblId, value);
    if(label != null)
    {
        label.innerHTML = text;
    }
}
function radioButtonList_isCurrentValueIsDefaultValue(rblId) {
    var prop = form_eltPropertiesObjArray[rblId];
    if (prop != null) {
        return prop.currentValueIsDefaultValue
    }
    return false;
}

function radioButtonList_onUpdateById(rblId) {
    //Function call to update error or warning message and css style
    radioButtonList_click(null, rblId);
}
function radioButtonList_onUpdate(sender) {
    //Function call to update error or warning message and css style
    if (sender) {
        sender.onclick();
    }
}

////////////////////////////////////////
// Zip code / Insee code
////////////////////////////////////////

function zipcode_initLocations(sender, zipCode, ddlEltId, defaultInseeCode)
{
    var zipcode_succeededCallback = function(result, eventArgs) {
        // This is the callback function invoked if the Web service succeeded.
        // It accepts the result object as a parameter.
        var ddl = $get(ddlEltId);
        if (ddl) {
            // Reset error
            dropDownList_clearError(ddlEltId);
            //show location dropdownlist
            show(ddlEltId);
            // Reset width
            ddl.style.width = null;
            // Clear first
            ddl.options.length = 0;
            // Init dropdownlist next
            if (result.length == 0) {
                ddl.options[0] = new Option("sans objet", "");
            }
            else if (result.length == 1) {
                ddl.options[0] = new Option(result[0].Location, result[0].InseeCode);
            }
            else {
                ddl.options[0] = new Option("-- Sélectionnez --", "");
                for (var i = 0; i < result.length; i++) {
                    ddl.options[i + 1] = new Option(result[i].Location, result[i].InseeCode);
                }
            }
            if (defaultInseeCode != null) {
                for (var j = 0; j < ddl.options.length; j++) {
                    if (ddl.options[j].value == defaultInseeCode) {
                        ddl.options[j].selected = true;
                        break;
                    }
                }
            }
        }
    }
    if (zipCode) {
        // Call WS
        AssurlandWeb.WebRessourcesAccess.GetLocations(zipCode, zipcode_succeededCallback, zipcode_failedCallback);
    }
    else {
        var ddl = $get(ddlEltId);
        // Clear
        ddl.options.length = 0;
        // Reset error
        dropDownList_clearError(ddlEltId);
        // Hide ?
        var prop = form_eltPropertiesObjArray[sender.id];
        if (prop != null) {
            if (prop.zipCodeDropDownListDynamicVisibility) {
                //hide location dropdownlist
                hide(ddlEltId);
            }
        }
    }
}
// This is the callback function invoked if the Web service failed.
function zipcode_failedCallback(error)
{
    displayAspNetFrameworkError("AssurlandWeb.WebRessourcesAccess.GetLocations failed",error);
}

function ZipCode_SearchBoxProperties(popupId,iframeId,tbIdZipCode,lbIdLocation)
{
    this.popupId = popupId;
    this.iframeId = iframeId;
    this.tbIdZipCode = tbIdZipCode;
    this.lbIdLocation = lbIdLocation;
    this.tbIdTargetZipCode = null;
    this.ddlIdTargetLocation = null;
    this.visible = false;
}
ZipCode_SearchBoxProperties.prototype = 
{ 
    toString: function()
    {
        var str = "";
        str = str + 'popupId = ' + this.popupId + '\n';
        str = str + 'iframeId = ' + this.iframeId + '\n';
        str = str + 'tbIdZipCode = ' + this.tbIdZipCode + '\n';
        str = str + 'lbIdLocation = ' + this.lbIdLocation + '\n';
        str = str + 'tbIdTargetZipCode = ' + this.tbIdTargetZipCode + '\n';
        str = str + 'ddlIdTargetLocation = ' + this.ddlIdTargetLocation + '\n';
        str = str + 'visible = ' + this.visible + '\n';
        return str;
    }
}

var zipcode_searchBoxPropertiesArray;
function zipcode_searchBoxInit()
{
    zipcode_searchBoxPropertiesArray = new Array();   
}
function zipcode_addSearchBox(popupId,iframeId,tbIdZipCode,lbIdLocation)
{
    var obj = new ZipCode_SearchBoxProperties(popupId,iframeId,tbIdZipCode,lbIdLocation,null,null);
    zipcode_searchBoxPropertiesArray[popupId] = obj;
}
function zipcode_searchBoxShow(senderId, popupId, tbIdTargetZipCode, ddlIdTargetLocation)
{
    var prop = zipcode_searchBoxPropertiesArray[popupId];
    if(prop != null)
    {
        // Update configuration
        prop.tbIdTargetZipCode = tbIdTargetZipCode;
        prop.ddlIdTargetLocation = ddlIdTargetLocation;
        // Show popup
        var popup = $get(popupId);
        var target = $get(tbIdTargetZipCode);
        if(popup != null && target != null)
        {
            // Compute new location
            var margin = 5;
            //var boundTarget = Sys.UI.DomElement.getBounds(target);
            // /!\ Popup can be in a relative or absolute container.
            // Relative position to this container has to be used instead of window position
            var boundTarget = getRelativeBounds(target,popup); //Sys.UI.DomElement.getBounds(target);
            var x = boundTarget.x;
            var y = boundTarget.y + boundTarget.height + margin;
            Sys.UI.DomElement.setLocation(popup, x, y);
            // Show popup
            $get(prop.tbIdZipCode).value = '';
            $get(prop.lbIdLocation).options.length = 0;
            show(popupId);
            //prop.visible = true;
            // Delay visible property update to not hide popup in concurrent function 
            // zipcode_updateAllSearchBoxVisibility() called by onclick event
            setTimeout("zipcode_searchBoxSetVisible('" + popupId + "',true);",50);
        }
    }
}
function zipcode_searchBoxHide(popupId)
{
    zipcode_searchBoxSetVisible(popupId, false);
    hide(popupId);   
}
function zipcode_searchBoxSwitchVisibility(senderId, popupId, tbIdTargetZipCode, ddlIdTargetLocation)
{
    var prop = zipcode_searchBoxPropertiesArray[popupId];
    if(prop != null)
    {
        if(prop.visible)
        {
            // Hide
            zipcode_searchBoxHide(popupId);
        }
        else
        {
            // Show
            zipcode_searchBoxShow(senderId, popupId, tbIdTargetZipCode, ddlIdTargetLocation)  
        }
    }
}
function zipcode_searchBoxSetVisible(popupId,visible)
{
    var prop = zipcode_searchBoxPropertiesArray[popupId];
    if(prop != null)
    {
        prop.visible = visible;   
    }
}
function zipcode_searchBox_keyUp(sender, popupId)
{
    if(sender.value.length >= 3)
    {
        var str = sender.value;
        var prop = zipcode_searchBoxPropertiesArray[popupId];
        if(prop != null)
        {
            var zipcode_searchBoxSucceededCallback = function(result, eventArgs)
            {
                // This is the callback function invoked if the Web service succeeded.
                // It accepts the result object as a parameter.
                var lb = $get(prop.lbIdLocation);
                if(lb)
                {
                    // Clear first
                    lb.options.length = 0;
                    // Init listbox next
                    if(result.length == 0)
                    {
                        // Nothing to do ...
                    }
                    else
                    {  
                        for(var i=0; i<result.length; i++)
                        {
                            lb.options[i] = new Option(result[i].Location + " (" + result[i].ZipCode + ")", result[i].InseeCode);
                        }  
                    }
                }
            }
            // Call WS
            AssurlandWeb.WebRessourcesAccess.SearchLocations(str, zipcode_searchBoxSucceededCallback, zipcode_searchBoxFailedCallback);
        }
    }
}
function zipcode_searchBoxValidate(popupId)
{
    // Init linked form input
    var prop = zipcode_searchBoxPropertiesArray[popupId];
    if(prop != null)
    {
        var locationLb = $get(prop.lbIdLocation);
        var targetZipCodeTb = $get(prop.tbIdTargetZipCode);
        var targetLocationDdl = $get(prop.ddlIdTargetLocation);
        var inseeCode = locationLb.value;
        var zipCode = '';
        // Get zipcode
        var zipcode_searchBoxValidateSucceededCallback = function(result, eventArgs)
        {
            if(result != null)
            {
                zipCode = result.ZipCode;
                // Update form
                targetZipCodeTb.value = zipCode;
                // Reset error
                textBox_clearError(prop.tbIdTargetZipCode);
                // Update location
                zipcode_initLocations(targetZipCodeTb, zipCode, prop.ddlIdTargetLocation, inseeCode);
            }
        }
        // Call WS
        AssurlandWeb.WebRessourcesAccess.GetZipCodeByInseeCode(inseeCode, zipcode_searchBoxValidateSucceededCallback, zipcode_searchBoxFailedCallback);
    }
    // Hide popup
    zipcode_searchBoxHide(popupId);
}
// This is the callback function invoked if the Web service failed.
function zipcode_searchBoxFailedCallback(error)
{
    displayAspNetFrameworkError("AssurlandWeb.WebRessourcesAccess.GetZipCodeByInseeCode failed",error);
}
// Init search box manager
zipcode_searchBoxInit();

function zipcode_updateAllSearchBoxVisibility(e)
{
    if(zipcode_searchBoxPropertiesArray != null)
    {
        var areaMargin = 2;
        var prop;
        var x = mouseX(e);
        var y = mouseY(e);

        for(key in zipcode_searchBoxPropertiesArray)
        {
            prop = zipcode_searchBoxPropertiesArray[key];
            if(prop.visible == true)
            {
                var boundSender = Sys.UI.DomElement.getBounds($get(prop.popupId));
                var area = new RectArea();
                area.x = boundSender.x - areaMargin;
                area.y = boundSender.y - areaMargin;
                area.width = boundSender.width + 2*areaMargin;
                area.height = boundSender.height + 2*areaMargin;
            
                if(area.PtIn(x,y) == false)
                {
                    zipcode_searchBoxHide(prop.popupId);
                }
            }
        }
    }
}

addListener(document, 'click', zipcode_updateAllSearchBoxVisibility);
////////////////////////////////////////
// Address
////////////////////////////////////////
var address_sex;

function address_warningTitleAndSex(sender) {
    if (sender.value != '') {
        var title = sender.value.substr(0, 2);
        if ((title == "MA" && address_sex != "F") || (address_sex == "F" && title == "MO")) {
            if (address_sex == "F")
                return "Vous avez déclaré auparavant être une femme, êtes vous certain d'avoir sélectionné la bonne civilité ? ";
            else
                return "Vous avez déclaré auparavant être un homme, êtes vous certain d'avoir sélectionné la bonne civilité ? ";           
        }
    }
    return "";
}
var address_sex_2;

function address_warningTitleAndSex2(sender) {
   
    if (sender.value != '') {
        var title = sender.value.substr(0, 2);
        if ((title == "MA" && address_sex_2 != "F") || (address_sex_2 == "F" && title == "MO")) {
            if (address_sex_2 == "F")
                return "Vous avez déclaré que c'était une femme, êtes vous certain d'avoir sélectionné la bonne civilité ? ";
            else
                return "Vous avez déclaré que c'était un homme, êtes vous certain d'avoir sélectionné la bonne civilité ? ";
        }
    }
    return "";
}
////////////////////////////////////////
// Agencies
////////////////////////////////////////

var agency_addressId;
var agency_ddlAgencyId;
var agency_ddlDepartmentId;

// Carrefour Agency
function agency_carrefourUpdateDepartment(dep)
{
    // Call
    var agency_carrefourUpdateDepartment_Callback = function(result, eventArgs)
    {
        //alert(result);
        dropDownList_bind(agency_ddlAgencyId, -1, result, "", "", true, "-- Sélectionnez un magasin --");
    }
    AssurlandWeb.AgencyAccess.SearchCarrefourAgencies(dep, agency_addressId, agency_carrefourUpdateDepartment_Callback, agency_carrefourUpdateDepartment_FailedCallback);

}
function agency_carrefourUpdateDepartment_FailedCallback(error)
{
    displayAspNetFrameworkError("AssurlandWeb.AgencyAccess.SearchCarrefourAgencies failed",error);
}

// MMA Agency
var agency_rbAgency1Id;
var agency_rbAgency2Id;
var agency_rbAgency3Id;
var agency_rbAgency4Id;
var agency_rowErrAgencyId;

function agency_mmaUpdateDepartment(dep)
{
    // Call
    var agency_mmaUpdateDepartment_Callback = function(result, eventArgs)
    {
        //alert(result);
        dropDownList_bind(agency_ddlAgencyId, -1, result, "", "", true, "-- Sélectionnez une agence --");
    }
    AssurlandWeb.AgencyAccess.SearchMmaAgencies(dep, agency_mmaUpdateDepartment_Callback, agency_mmaUpdateDepartment_FailedCallback);

}
function agency_mmaUpdateDepartment_FailedCallback(error)
{
    displayAspNetFrameworkError("AssurlandWeb.AgencyAccess.SearchMmaAgencies failed",error);
}
function agency_mmaAgencyRadioButtonClick()
{
    // Get selected agency index
    var rbChecked = 0;
    if($get(agency_rbAgency1Id).checked == true)
        rbChecked = 1;
    else if($get(agency_rbAgency2Id).checked == true)
        rbChecked = 2;
    else if($get(agency_rbAgency3Id).checked == true)
        rbChecked = 3;
    else if($get(agency_rbAgency4Id).checked == true)
        rbChecked = 4;
    
    // Enable/disable department search
    if(rbChecked == 4)
    {
        dropDownList_enable(agency_ddlDepartmentId)
        dropDownList_enable(agency_ddlAgencyId)      
    }
    else
    {
        dropDownList_disable(agency_ddlDepartmentId)
        dropDownList_disable(agency_ddlAgencyId)
    }
}

////////////////////////////////////////
// Proposal call back
////////////////////////////////////////
var rowCallBackOnlyId;

function CallBackInfo_Calendar()
{
    this.dates = new Array();
    this.rangesByDate = new Array();
}
CallBackInfo_Calendar.prototype = 
{ 
    toString: function()
    {
        var str = "";
        str = str + 'dates = ' + this.dates + '\n';
        return str;
    }
}
CallBackInfo_Calendar.prototype = 
{ 
    getDaysByMonth: function(month)
    {
        var array = new Array();
        for(var i=0; i<this.dates.length; i++)
        {
            if(this.dates[i].getMonth() == (month-1))
            {
                addToArray(array, this.dates[i]); 
            }
        }
        return array;
    }
}

var callbackinfo_calendar = new CallBackInfo_Calendar();
function callbackinfo_addDate(d)
{
    addToArray(callbackinfo_calendar.dates, d);
}
function callbackinfo_addRange(strDate,range)
{
    if(callbackinfo_calendar.rangesByDate[strDate] == null)
        callbackinfo_calendar.rangesByDate[strDate] = new Array();
    addToArray(callbackinfo_calendar.rangesByDate[strDate], range);
}
function callbackinfo_getDateString(d)
{
    var str = callbackinfo_getDayString(d) + '/' + callbackinfo_getMonthString(d) + '/' + d.getFullYear();
    return str;
}
function callbackinfo_getDayString(d)
{
    var day = d.getDate();
    if(day > 9)
        return day
    else
        return "0" + day
}
function callbackinfo_getMonthString(d)
{
    var month = d.getMonth()+1;
    if(month > 9)
        return month
    else
        return "0" + month
}

var callbackinfo_ddlDayId = null;
var callbackinfo_ddlMonthId = null;
var callbackinfo_ddlHourId = null;
var callbackinfo_tbPhoneNumberId = null;

function callbackinfo_updateMonth(month)
{
    // Update days
    var dates = callbackinfo_calendar.getDaysByMonth(month);
    var elt = $get(callbackinfo_ddlDayId);
    dropDownList_clear(callbackinfo_ddlDayId);
    if(dates.length > 0)
    {
        // Update liste
        for(var i=0; i<dates.length; i++)
        {
            elt.options[i] = new Option(callbackinfo_getDayString(dates[i]), callbackinfo_getDateString(dates[i]));
        }
        // Update range
        callbackinfo_updateDay(callbackinfo_getDateString(dates[0]));
    }
    else
    {
        elt.options[0] = new Option("sans objet","");     
    }
}
function callbackinfo_updateDay(day)
{
    // Update open hours
    var elt = $get(callbackinfo_ddlHourId);
    dropDownList_clear(callbackinfo_ddlHourId);
    if(callbackinfo_calendar.rangesByDate[day] != null)
    {
        var rangeArray = callbackinfo_calendar.rangesByDate[day];
        // Update liste
        for(var i=0; i<rangeArray.length; i++)
        {
            elt.options[i] = new Option(rangeArray[i], rangeArray[i]);
        }
    }
    else
    {
        elt.options[0] = new Option("sans objet",""); 
    }
}
function callbackinfo_setEnabled(enabled)
{
    dropDownList_setEnabled(callbackinfo_ddlDayId, enabled);
    dropDownList_setEnabled(callbackinfo_ddlMonthId,enabled);
    dropDownList_setEnabled(callbackinfo_ddlHourId,enabled);
    textBox_setEnabled(callbackinfo_tbPhoneNumberId,enabled);
}

////////////////////////////////////////
// Misc functions (shared product js)
////////////////////////////////////////

function isValidBonus(bonus, years) {
    if ((years < 12 && bonus == 0.5) || (years < 11 && bonus <= 0.51) || (years < 10 && bonus <= 0.54) || (years < 9 && bonus <= 0.57) || (years < 8 && bonus <= 0.6) || (years < 7 && bonus <= 0.64) || (years < 6 && bonus <= 0.68) || (years < 5 && bonus <= 0.72) || (years < 4 && bonus <= 0.76) || (years < 3 && bonus <= 0.8) || (years < 2 && bonus <= 0.85) || (years < 1 && bonus <= 0.9)) {
        return false;
    }
    return true;
}
function getBonusFromForm(bonus){
    if (bonus >= 10.0)  return 0.5;
    return  bonus;    
}
function getMaturity(month){
        var maturity;
        var dNow = new Date();
        //year
        if (dNow.getMonth()+1 == month) {
            dNow.setDate(dNow.getDate() + 1);
            if (dNow.getDate()<10)
                maturity ="0" + dNow.getDate()+"/";
            else
                maturity = dNow.getDate() + "/";
                
            if (dNow.getMonth()*1 +1 <10)
                maturity =maturity+"0" + (dNow.getMonth()*1 +1)+"/";
            else
                maturity =maturity+ (dNow.getMonth()*1 +1)+"/";
                
            maturity =maturity+ dNow.getFullYear();
        }
        else {
            if (dNow.getMonth()+1 < month) 
                maturity = "01/" + month +"/"+ dNow.getFullYear()
            else
                maturity = "01/" + month +"/"+ (dNow.getFullYear()+1)
            }
        return maturity;
}
/////////////////////////////////////////////////////////////////////////
//          OLD WEBRESSOURCESACCESS.asmx.js                            //
////////////////////////////////////////////////////////////////////////
Type.registerNamespace('AssurlandWeb');
AssurlandWeb.WebRessourcesAccess=function() {
AssurlandWeb.WebRessourcesAccess.initializeBase(this);
this._timeout = 0;
this._userContext = null;
this._succeeded = null;
this._failed = null;
}
AssurlandWeb.WebRessourcesAccess.prototype={
_get_path:function() {
 var p = this.get_path();
 if (p) return p;
 else return AssurlandWeb.WebRessourcesAccess._staticInstance.get_path();},
GetFormHelp:function(helpId,succeededCallback, failedCallback, userContext) {
return this._invoke(this._get_path(), 'GetFormHelp',false,{helpId:helpId},succeededCallback,failedCallback,userContext); },
GetProductBaseHelp:function(groupId,eltId,succeededCallback, failedCallback, userContext) {
return this._invoke(this._get_path(), 'GetProductBaseHelp',false,{groupId:groupId,eltId:eltId},succeededCallback,failedCallback,userContext); },
GetFormDataList:function(listId,succeededCallback, failedCallback, userContext) {
return this._invoke(this._get_path(), 'GetFormDataList',false,{listId:listId},succeededCallback,failedCallback,userContext); },
GetLocations:function(zipCode,succeededCallback, failedCallback, userContext) {
return this._invoke(this._get_path(), 'GetLocations',false,{zipCode:zipCode},succeededCallback,failedCallback,userContext); },
GetZipCode:function(zipCode,inseeCode,succeededCallback, failedCallback, userContext) {
return this._invoke(this._get_path(), 'GetZipCode',false,{zipCode:zipCode,inseeCode:inseeCode},succeededCallback,failedCallback,userContext); },
GetZipCodeByInseeCode:function(inseeCode,succeededCallback, failedCallback, userContext) {
return this._invoke(this._get_path(), 'GetZipCodeByInseeCode',false,{inseeCode:inseeCode},succeededCallback,failedCallback,userContext); },
SearchLocations:function(start,succeededCallback, failedCallback, userContext) {
return this._invoke(this._get_path(), 'SearchLocations',false,{start:start},succeededCallback,failedCallback,userContext); }}
AssurlandWeb.WebRessourcesAccess.registerClass('AssurlandWeb.WebRessourcesAccess',Sys.Net.WebServiceProxy);
AssurlandWeb.WebRessourcesAccess._staticInstance = new AssurlandWeb.WebRessourcesAccess();
AssurlandWeb.WebRessourcesAccess.set_path = function(value) { AssurlandWeb.WebRessourcesAccess._staticInstance.set_path(value); }
AssurlandWeb.WebRessourcesAccess.get_path = function() { return AssurlandWeb.WebRessourcesAccess._staticInstance.get_path(); }
AssurlandWeb.WebRessourcesAccess.set_timeout = function(value) { AssurlandWeb.WebRessourcesAccess._staticInstance.set_timeout(value); }
AssurlandWeb.WebRessourcesAccess.get_timeout = function() { return AssurlandWeb.WebRessourcesAccess._staticInstance.get_timeout(); }
AssurlandWeb.WebRessourcesAccess.set_defaultUserContext = function(value) { AssurlandWeb.WebRessourcesAccess._staticInstance.set_defaultUserContext(value); }
AssurlandWeb.WebRessourcesAccess.get_defaultUserContext = function() { return AssurlandWeb.WebRessourcesAccess._staticInstance.get_defaultUserContext(); }
AssurlandWeb.WebRessourcesAccess.set_defaultSucceededCallback = function(value) { AssurlandWeb.WebRessourcesAccess._staticInstance.set_defaultSucceededCallback(value); }
AssurlandWeb.WebRessourcesAccess.get_defaultSucceededCallback = function() { return AssurlandWeb.WebRessourcesAccess._staticInstance.get_defaultSucceededCallback(); }
AssurlandWeb.WebRessourcesAccess.set_defaultFailedCallback = function(value) { AssurlandWeb.WebRessourcesAccess._staticInstance.set_defaultFailedCallback(value); }
AssurlandWeb.WebRessourcesAccess.get_defaultFailedCallback = function() { return AssurlandWeb.WebRessourcesAccess._staticInstance.get_defaultFailedCallback(); }
AssurlandWeb.WebRessourcesAccess.set_path("/Ws/WebRessourcesAccess.asmx");
AssurlandWeb.WebRessourcesAccess.GetFormHelp= function(helpId,onSuccess,onFailed,userContext) {AssurlandWeb.WebRessourcesAccess._staticInstance.GetFormHelp(helpId,onSuccess,onFailed,userContext); }
AssurlandWeb.WebRessourcesAccess.GetProductBaseHelp= function(groupId,eltId,onSuccess,onFailed,userContext) {AssurlandWeb.WebRessourcesAccess._staticInstance.GetProductBaseHelp(groupId,eltId,onSuccess,onFailed,userContext); }
AssurlandWeb.WebRessourcesAccess.GetFormDataList= function(listId,onSuccess,onFailed,userContext) {AssurlandWeb.WebRessourcesAccess._staticInstance.GetFormDataList(listId,onSuccess,onFailed,userContext); }
AssurlandWeb.WebRessourcesAccess.GetLocations= function(zipCode,onSuccess,onFailed,userContext) {AssurlandWeb.WebRessourcesAccess._staticInstance.GetLocations(zipCode,onSuccess,onFailed,userContext); }
AssurlandWeb.WebRessourcesAccess.GetZipCode= function(zipCode,inseeCode,onSuccess,onFailed,userContext) {AssurlandWeb.WebRessourcesAccess._staticInstance.GetZipCode(zipCode,inseeCode,onSuccess,onFailed,userContext); }
AssurlandWeb.WebRessourcesAccess.GetZipCodeByInseeCode= function(inseeCode,onSuccess,onFailed,userContext) {AssurlandWeb.WebRessourcesAccess._staticInstance.GetZipCodeByInseeCode(inseeCode,onSuccess,onFailed,userContext); }
AssurlandWeb.WebRessourcesAccess.SearchLocations= function(start,onSuccess,onFailed,userContext) {AssurlandWeb.WebRessourcesAccess._staticInstance.SearchLocations(start,onSuccess,onFailed,userContext); }
var gtc = Sys.Net.WebServiceProxy._generateTypedConstructor;
if (typeof(AssurlandWeb.OnlineHelp) === 'undefined') {
AssurlandWeb.OnlineHelp=gtc("AssurlandWeb.OnlineHelp");
AssurlandWeb.OnlineHelp.registerClass('AssurlandWeb.OnlineHelp');
}
Type.registerNamespace('common');
if (typeof(common.ZipCode) === 'undefined') {
common.ZipCode=gtc("common.ZipCode");
common.ZipCode.registerClass('common.ZipCode');
}

/////////////////////////////////////////////////////
// UserTracking.asmx/js                            //
/////////////////////////////////////////////////////
Type.registerNamespace('AssurlandWeb');
AssurlandWeb.UserTracking = function() {
    AssurlandWeb.UserTracking.initializeBase(this);
    this._timeout = 0;
    this._userContext = null;
    this._succeeded = null;
    this._failed = null;
}
AssurlandWeb.UserTracking.prototype = {
    _get_path: function() {
        var p = this.get_path();
        if (p) return p;
        else return AssurlandWeb.UserTracking._staticInstance.get_path();
    },
    Track: function(funnel, pageType, succeededCallback, failedCallback, userContext) {
        return this._invoke(this._get_path(), 'Track', false, { funnel: funnel, pageType: pageType }, succeededCallback, failedCallback, userContext);
    } 
}
AssurlandWeb.UserTracking.registerClass('AssurlandWeb.UserTracking', Sys.Net.WebServiceProxy);
AssurlandWeb.UserTracking._staticInstance = new AssurlandWeb.UserTracking();
AssurlandWeb.UserTracking.set_path = function(value) { AssurlandWeb.UserTracking._staticInstance.set_path(value); }
AssurlandWeb.UserTracking.get_path = function() { return AssurlandWeb.UserTracking._staticInstance.get_path(); }
AssurlandWeb.UserTracking.set_timeout = function(value) { AssurlandWeb.UserTracking._staticInstance.set_timeout(value); }
AssurlandWeb.UserTracking.get_timeout = function() { return AssurlandWeb.UserTracking._staticInstance.get_timeout(); }
AssurlandWeb.UserTracking.set_defaultUserContext = function(value) { AssurlandWeb.UserTracking._staticInstance.set_defaultUserContext(value); }
AssurlandWeb.UserTracking.get_defaultUserContext = function() { return AssurlandWeb.UserTracking._staticInstance.get_defaultUserContext(); }
AssurlandWeb.UserTracking.set_defaultSucceededCallback = function(value) { AssurlandWeb.UserTracking._staticInstance.set_defaultSucceededCallback(value); }
AssurlandWeb.UserTracking.get_defaultSucceededCallback = function() { return AssurlandWeb.UserTracking._staticInstance.get_defaultSucceededCallback(); }
AssurlandWeb.UserTracking.set_defaultFailedCallback = function(value) { AssurlandWeb.UserTracking._staticInstance.set_defaultFailedCallback(value); }
AssurlandWeb.UserTracking.get_defaultFailedCallback = function() { return AssurlandWeb.UserTracking._staticInstance.get_defaultFailedCallback(); }
AssurlandWeb.UserTracking.set_path("/Ws/UserTracking.asmx");
AssurlandWeb.UserTracking.Track = function(funnel, pageType, onSuccess, onFailed, userContext) { AssurlandWeb.UserTracking._staticInstance.Track(funnel, pageType, onSuccess, onFailed, userContext); }
if (typeof (AssurlandWeb.UserTrackingFunnel) === 'undefined') {
    AssurlandWeb.UserTrackingFunnel = function() { throw Error.invalidOperation(); }
    AssurlandWeb.UserTrackingFunnel.prototype = { UNKNOWN: 0, FORM_CAR_V1: 1, FORM_HEALTH_V1: 2, FORM_HOME_V1: 3, FORM_MOTO_V1: 4, FORM_LPR_V1: 5, FORM_VIE_V1: 6, FORM_LIFE_V1: 7, FORM_BORROW_V1: 8, FORM_CYCLO_V1: 9 }
    AssurlandWeb.UserTrackingFunnel.registerEnum('AssurlandWeb.UserTrackingFunnel', true);
}
if (typeof (AssurlandWeb.UserTrackingPage) === 'undefined') {
    AssurlandWeb.UserTrackingPage = function() { throw Error.invalidOperation(); }
    AssurlandWeb.UserTrackingPage.prototype = { BA: 1, QUOTATION_WAIT: 2, RESTIT: 3, PROPOSAL_WAIT: 4, THANKS: 5, FORM_CAR_V1_P1: 6, FORM_CAR_V1_P2: 7, FORM_CAR_V1_P3: 8, FORM_CAR_V1_P4: 9, FORM_HEALTH_V1_P1: 10, FORM_HEALTH_V1_P2: 11, FORM_HOME_V1_P1: 12, FORM_HOME_V1_P2: 13, FORM_HOME_V1_P3: 14, FORM_MOTO_V1_P1: 15, FORM_MOTO_V1_P2: 16, FORM_MOTO_V1_P3: 17, FORM_MOTO_V1_P4: 18, FORM_CYCLO_V1_P1: 19, FORM_CYCLO_V1_P2: 20, FORM_CYCLO_V1_P3: 21, FORM_CYCLO_V1_P4: 22, FORM_LPR_V1_P1: 23, FORM_VIE_V1_P1: 24, FORM_VIE_V1_P2: 25, FORM_LIFE_V1_P1: 26, FORM_BORROW_V1_P1: 27, FORM_BORROW_V1_P2: 28, FORM_CAR_V1_PROPOSAL: 29, FORM_HEALTH_V1_PROPOSAL: 30, FORM_HOME_V1_PROPOSAL: 31, FORM_MOTO_V1_PROPOSAL: 32, FORM_CYCLO_V1_PROPOSAL: 33, FORM_LPR_V1_PROPOSAL: 34, FORM_VIE_V1_PROPOSAL: 35, FORM_LIFE_V1_PROPOSAL: 36, FORM_BORROW_V1_PROPOSAL: 37 }
    AssurlandWeb.UserTrackingPage.registerEnum('AssurlandWeb.UserTrackingPage', true);
}

// Track question
function track(funnelId, pageId) {
    AssurlandWeb.UserTracking.Track(funnelId, pageId, null, null);
}

////////////////////////////////////////
// Form 2 
////////////////////////////////////////
// One question per page
// && select answer by one click

// Funnel ID
var form2_funnelId;
// Shadow submit button
var form2_validateBtnId;
// Progress bar ID
var form2_progressBarPanelId;
// Back hyperlink ID
var form2_backBtnId;
// Question label ID
var form2_questionLabelId;
// Help link ID
var form2_helpHlId;
// Loading functions stack
var form2_loadFctStack = new Array();
// Back URL
var form2_backUrl;
// Current question group panel ID
var form2_panelId;
// Current question group loading function
var form2_loadFct;
// Current question group validation function
var form2_validateFct;

// Alert if b is true and return !b
function form2_alert(b, msg) {
    if (b) alert(msg);
    return !b;
}
// Track question
function form2_track(pageId) {
    track(form2_funnelId, pageId);
}
// Submit form and send data so server
function form2_submit() {
    $get(form2_validateBtnId).click();
}
// Update progress bar
function form2_updateProgressBar(img) {
    var img = "url(/Images2/Form/Form2/v2/progressbar/" + img + ")";
    if ($get(form2_progressBarPanelId).style.backgroundImage != img)
        $get(form2_progressBarPanelId).style.backgroundImage = img;
}
// Add loading function to stack
function form2_pushLoadFct(loadFct) {
    form2_loadFctStack.push(loadFct);
}
// Init and show current question group panel ID
function form2_show(panelId, validateFct) {
    form2_validateFct = validateFct;
    form2_panelId = panelId;
    show(form2_panelId);
}
// Set question label
function form2_setQuestion(str) {
    setInnerHtml(form2_questionLabelId, str);
}
// Hide and disable help
function form2_disableHelp() {
    hide(form2_helpHlId);
}
// Show and configure help
function form2_enableHelp(helpElementId) {
    helpLink_changeHelpElementId(form2_helpHlId, "", helpElementId);
    show(form2_helpHlId);
}
// Hide and disable back button
function form2_disableBack() {
    hide(form2_backBtnId);
}
// Show and configure back button
function form2_enableBack() {
    show(form2_backBtnId);
}
// Update back
function form2_updateBack() {
    if (form2_loadFctStack.length == 0 && form2_backUrl == "") {
        form2_disableBack();
    }
}
// Go back
function form2_goBack() {
    // Get back function from stack and go back
    if (form2_loadFctStack.length > 0) {
        // Unload current controls
        hide(form2_panelId);
        // Load back page
        form2_loadFct = form2_loadFctStack.pop();
        form2_loadFct();
    }
    else {
        if (form2_backUrl != "")
            goToURL(form2_backUrl + "?b=1")
    }
    // Update back button state
    form2_updateBack();
}
// Validate current question group
function form2_validate() {
    form2_validateFct();
}
// Go next question group
function form2_goNext(nextLoadFct) {
    // Update back load function stack
    form2_loadFctStack.push(form2_loadFct);
    // Unload current controls
    hide(form2_panelId);
    // Load next
    form2_loadFct = nextLoadFct;
    form2_loadFct();
    // Update back button state
    form2_enableBack();
}
// Init first load
function form2_init(loadFct, stackLoadFct) {
    // Update stack
    if(stackLoadFct != null)
        form2_loadFctStack = stackLoadFct;
    // Load current
    form2_loadFct = loadFct
    form2_loadFct();
    // Update back button state
    form2_updateBack();
}
// Update form
function form2_update(qPanelId, validateFct, qLabel, helpElementId, progressBar, trackPageId) {
    // Update question label
    form2_setQuestion(qLabel);
    
    // Update help
    if (helpElementId != null)
        form2_enableHelp(helpElementId);
    else
        form2_disableHelp();
    
    // Manage progress bar
    if(progressBar != null)
        form2_updateProgressBar(progressBar);
    
    // Show question panel
    form2_show(qPanelId, validateFct);
    
    // Track page
    if(trackPageId != null)
        form2_track(trackPageId);
}

////////////////////////////////////////
// Form element additional properties
////////////////////////////////////////

function ListBoxTableProperties(ucId, parentUcId, tblId, hfId, fctClick) {
    this.ucId = ucId;
    this.parentUcId = parentUcId;
    this.tblId = tblId;
    this.hfId = hfId;
    this.fctClick = fctClick;
}
ListBoxTableProperties.prototype =
{
    toString: function() {
        var str = "";
        str = str + 'ucId = ' + this.ucId + '\n';
        str = str + 'parentUcId = ' + this.parentUcId + '\n';
        str = str + 'tblId = ' + this.tblId + '\n';
        str = str + 'hfId = ' + this.hfId + '\n';
        return str;
    }
}

function CalendarTableProperties(ucId, mode, dayUcId, monthUcId, yearUcId, fctClick) {
    this.ucId = ucId;
    this.mode = mode;
    this.dayUcId = dayUcId;
    this.monthUcId = monthUcId;
    this.yearUcId = yearUcId;
    this.fctClick = fctClick;
}
CalendarTableProperties.prototype =
{
    toString: function() {
        var str = "";
        str = str + 'ucId = ' + this.ucId + '\n';
        str = str + 'mode = ' + this.mode + '\n';
        str = str + 'dayUcId = ' + this.dayUcId + '\n';
        str = str + 'monthUcId = ' + this.monthUcId + '\n';
        str = str + 'yearUcId = ' + this.yearUcId + '\n';
        return str;
    }
}

function ZipCodeForm2Properties(ucId, tbId, ddlId, btnId, fctClick) {
    this.ucId = ucId;
    this.tbId = tbId;
    this.ddlId = ddlId;
    this.btnId = btnId;
    this.fctClick = fctClick;
}
ZipCodeForm2Properties.prototype =
{
    toString: function() {
        var str = "";
        str = str + 'ucId = ' + this.ucId + '\n';
        str = str + 'tbId = ' + this.tbId + '\n';
        str = str + 'ddlId = ' + this.ddlId + '\n';
        str = str + 'btnId = ' + this.btnId + '\n';
        return str;
    }
}

////////////////////////////////////////
// Form element handler
////////////////////////////////////////

function listBoxTable_getValue(ucId) {
    var prop = form_eltPropertiesObjArray[ucId];
    if (prop != null) {
        return $get(prop.hfId).value;
    }
}
function listBoxTable_setValue(ucId, value, cell) {
    var prop = form_eltPropertiesObjArray[ucId];
    if (prop != null) {
        // Clear selection
        listBoxTable_clearSelection(ucId);
        // Update value
        $get(prop.hfId).value = value;
        cell.className = "al_selected";
        // Do action if required
        if (prop.fctClick != null)
            if (prop.parentUcId != null)
                prop.fctClick(prop.parentUcId, ucId);
        else
            prop.fctClick(ucId);
    }
}
function listBoxTable_clearSelection(ucId) {
    var prop = form_eltPropertiesObjArray[ucId];
    if (prop != null) {
        // Update other cell style
        var cells = $get(prop.tblId).getElementsByTagName("td");
        for (var i = 0; i < cells.length; i++) {
            cells[i].className = "";
        }
    }
}
function listBoxTable_onMouseOver(ucId, value, cell) {
    var prop = form_eltPropertiesObjArray[ucId];
    if (prop != null) {
        if (value == listBoxTable_getValue(ucId)) {
            cell.className = "al_selectedOver";
        }
        else {
            cell.className = "al_over";
        }
    }
}
function listBoxTable_onMouseOut(ucId, value, cell) {
    var prop = form_eltPropertiesObjArray[ucId];
    if (prop != null) {
        if (value == listBoxTable_getValue(ucId)) {
            cell.className = "al_selected";
        }
        else {
            cell.className = "";
        }
    }
}
function listBoxTable_validate(ucId, msg) {
    if (listBoxTable_getValue(ucId) == "") {
        if (msg != null) alert(msg);
        return false;
    }
    return true;
}

function calendarTable_getDate(ucId) {
    var prop = form_eltPropertiesObjArray[ucId];
    if (prop != null) {
        if (prop.mode == 0)
            return getValidDate(1, listBoxTable_getValue(prop.monthUcId), listBoxTable_getValue(prop.yearUcId))
        else
            return getValidDate(listBoxTable_getValue(prop.dayUcId), listBoxTable_getValue(prop.monthUcId), listBoxTable_getValue(prop.yearUcId))
    }
}
function calendarTable_update(ucId, ucId2) {
    var prop = form_eltPropertiesObjArray[ucId];
    if (prop != null) {
        var bFull = false;

        if (prop.mode == 0)
            bFull = (listBoxTable_getValue(prop.monthUcId) != "" && listBoxTable_getValue(prop.yearUcId) != "");
        else
            bFull = (listBoxTable_getValue(prop.dayUcId) != "" && listBoxTable_getValue(prop.monthUcId) != "" && listBoxTable_getValue(prop.yearUcId) != "");

        // Do action if required
        if (bFull && ucId2 == prop.yearUcId && prop.fctClick != null)
            prop.fctClick(ucId);
    }
}
function calendarTable_validate(ucId, msg) {
    var prop = form_eltPropertiesObjArray[ucId];
    if (prop != null) {
        if ((prop.mode == 1 && !listBoxTable_validate(prop.dayUcId))
            || !listBoxTable_validate(prop.monthUcId)
            || !listBoxTable_validate(prop.yearUcId)) {
            if (msg != null) alert(msg);
            return false;     
        }
    }
    return true;
}
function calendarTable_validateDate(ucId, msg) {
    if (calendarTable_getDate(ucId) == null) {
        if (msg != null) alert(msg);
        return false;
    }
    return true;
}

function zipCodeForm2_getZipCode(ucId) {
    var prop = form_eltPropertiesObjArray[ucId];
    if (prop != null) {
        return $get(prop.tbId).value;
    }
}
function zipCodeForm2_getInseeCode(ucId) {
    var prop = form_eltPropertiesObjArray[ucId];
    if (prop != null) {
        return $get(prop.ddlId).value;
    }
}
function zipCodeForm2_validate(ucId, msg1, msg2, msg3) {
    if (msg1 == null)
        msg1 = "Veuillez préciser le code postal."
    if (msg2 == null)
        msg2 = "Le code postal n'est pas valide."
    if (msg3 == null)
        msg3 = "Veuillez préciser votre ville."

    var prop = form_eltPropertiesObjArray[ucId];
    if (prop != null) {
        if (zipCodeForm2_getZipCode(ucId) == "") {
            if (msg1 != null) alert(msg1);
            $get(prop.tbId).focus();
            return false;
        }
        if (zipCodeForm2_getInseeCode(ucId) == "") {
            if ($get(prop.ddlId).length == 0 || ($get(prop.ddlId).length == 1 && $get(prop.ddlId).options[0].value == "")) {
                if (msg2 != null) alert(msg2);
                $get(prop.tbId).focus();
                return false;
            }
            if (msg3 != null) alert(msg3);
            $get(prop.ddlId).focus();
            return false;
        }
    }
    return true;
}
function zipCodeForm2_updateLocation(ucId) {
    var prop = form_eltPropertiesObjArray[ucId];
    if (prop != null) {
        if ($get(prop.tbId).value == "") {
            hide(prop.ddlId);
        }
        else {
            zipcode_initLocations(prop.tbId, $get(prop.tbId).value, prop.ddlId, null);
        }
    }
}
function zipCodeForm2_btnClick(ucId) {
    var prop = form_eltPropertiesObjArray[ucId];
    if (prop != null) {
        if (prop.fctClick != null)
            prop.fctClick(ucId);
    }
}
function zipCodeForm2_focus(ucId) {
    var prop = form_eltPropertiesObjArray[ucId];
    if (prop != null) {
        $get(prop.tbId).focus();
    }
}