var EXP_INTEGER = /[+]|^\d$/;
var EXP_TELEPHONE_CDN = /[+]|[)]|[(]|^\d|-| $/;

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}


var maskpanel = function() {
    this.divobj;
    this.show = function() {

        if (!parent.document.getElementById("xdivmasking")) {
            var divEle = parent.document.createElement('div');
            divEle.setAttribute("id", "xdivmasking");
            parent.document.body.appendChild(divEle);
            var divSty = parent.document.getElementById("xdivmasking").style;
            divSty.position = "absolute"; divSty.top = "0px"; divSty.left = "0px";
            //            divSty.zIndex = "9999"; divSty.opacity = ".50"; divSty.backgroundColor = "#fff";
            divSty.zIndex = "5046"; divSty.opacity = ".50"; divSty.backgroundColor = "#fff";

            divSty.filter = "alpha(opacity=50)";

            var divFram = parent.document.createElement('iframe');
            divFram.setAttribute("id", "xmaskframe");
            parent.document.body.appendChild(divFram);
            divSty = parent.document.getElementById("xmaskframe").style;
            divSty.position = "absolute"; divSty.top = "0px"; divSty.left = "0px";
            divSty.zIndex = "0"; divSty.border = "none"; divSty.filter = "alpha(opacity=0)";
            divSty.zIndex = "5045"; divSty.border = "none"; divSty.filter = "alpha(opacity=0)";

        }

        this.divobj = parent.document.getElementById("xdivmasking");
        this.waitifrm = parent.document.getElementById("xmaskframe");
       
        var dsh = parent.document.documentElement.scrollHeight;
        var dch = parent.document.documentElement.clientHeight;
        var dsw = parent.document.documentElement.scrollWidth;
        var dcw = parent.document.documentElement.clientWidth;

        var bdh = (dsh > dch) ? dsh : dch;
        var bdw = (dsw > dcw) ? dsw : dcw;
        this.waitifrm.style.height = document.documentElement.scrollHeight + document.body.scrollTop;
        this.divobj.style.height = document.documentElement.scrollHeight + document.body.scrollTop;
        this.waitifrm.style.width = document.body.clientWidth + document.body.scrollLeft;
        this.divobj.style.width = document.body.clientWidth + document.body.scrollLeft;
        this.waitifrm.style.display = this.divobj.style.display = "block";
    };
    this.hide = function() {
        this.waitifrm.style.display = this.divobj.style.display = "none";
    };
}


function viewmaskpaneldemo() {

    if (readCookie('SS') == 'True') {

        var splashFrame = document.getElementById("ctl00_Iframe1");
        if (splashFrame == null ) {
            return;
        }
        
        demomask = new maskpanel();

        demomask.show();
        var demodiv = document.getElementById("viewdemodiv");
        demodiv.style.display = "block";


        var viewPortWidth;
        var viewPortHeight;

        // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
        if (typeof window.innerWidth != 'undefined') {
            viewPortWidth = window.innerWidth,
        viewPortHeight = window.innerHeight
        }
        // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
        else if (typeof document.documentElement != 'undefined' &&
             typeof document.documentElement.clientWidth != 'undefined' &&
             document.documentElement.clientWidth != 0) {
            viewPortWidth = document.documentElement.clientWidth,
        viewPortHeight = document.documentElement.clientHeight
        }
        // older versions of IE
        else {
            viewPortWidth = document.getElementsByTagName('body')[0].clientWidth,
        viewPortHeight = document.getElementsByTagName('body')[0].clientHeight
        }


        if ((((viewPortHeight) / 2) - (demodiv.offsetHeight / 2)) < 0) {
            demodiv.style.top = 0;
        }
        else  {
            demodiv.style.top = (((viewPortHeight) / 2) - (demodiv.offsetHeight / 2)) + 'px';
        }
       
        demodiv.style.left = (((viewPortWidth) / 2) - (demodiv.offsetWidth / 2)) + 'px';

        demodiv.style.width = 425 + 'px';

        //demodiv.style.height = 415 + 'px';
        demodiv.style.position = 'absolute'



    }
}

function hidemaskpaneldemo() {
    parent.document.getElementById("xdivmasking").style.display = "none";
    parent.document.getElementById("xmaskframe").style.display = "none";
    parent.document.getElementById("viewdemodiv").style.display = "none";

}




/**********************************************************************************
Nom de la fonction:	newContactWindow()
**********************************************************************************/
function newContactWindow(pURL, pTitre, pWidth, pHeight, pScrollBar, pLeft, pTop, pMenuBar, pResizable, pStatus, pToolBar, pLocation) {
    var objDialogWin = new Object();

    //Valeurs par défaut si paramètre absent
    var lValeurLeft = '50';
    var lValeurTop = '50';
    var lValeurWidth = '561';
    var lValeurHeight = '415';
    var lValeurScrollbar = 'no';
    var lValeurMenuBar = 'no';
    var lValeurResizable = 'no';
    var lValeurStatus = 'no';
    var lValeurToolBar = 'no';
    var lValeurLocation = 'no';

    if (typeof (pLeft) != 'undefined') {
        lValeurLeft = pLeft;
    }
    if (typeof (pTop) != 'undefined') {
        lValeurTop = pTop;
    }
    if (typeof (pWidth) != 'undefined') {
        lValeurWidth = pWidth;
    }
    if (typeof (pHeight) != 'undefined') {
        lValeurHeight = pHeight;
    }

    if (typeof (pScrollBar) != 'undefined') {
        if (pScrollBar) {
            lValeurScrollbar = 'yes';
        }
        else {
            lValeurScrollbar = 'no';
        }
    }
    if (typeof (pMenuBar) != 'undefined') {
        if (pMenuBar) {
            lValeurMenuBar = 'yes';
        }
        else {
            lValeurMenuBar = 'no';
        }
    }
    if (typeof (pResizable) != 'undefined') {
        if (pResizable) {
            lValeurResizable = 'yes';
        }
        else {
            lValeurResizable = 'no';
        }
    }
    if (typeof (pStatus) != 'undefined') {
        if (pStatus) {
            lValeurStatus = 'yes';
        }
        else {
            lValeurStatus = 'no';
        }
    }
    if (typeof (pToolBar) != 'undefined') {
        if (pToolBar) {
            lValeurToolBar = 'yes';
        }
        else {
            lValeurToolBar = 'no';
        }
    }
    if (typeof (pLocation) != 'undefined') {
        if (pLocation) {
            lValeurLocation = 'yes';
        }
        else {
            lValeurLocation = 'no';
        }
    }
    
    //    objDialogWin.win = window.open(pURL, pTitre, "left=" + lValeurLeft + ",top=" + lValeurTop + ",height=" + lValeurHeight + ",width=" + lValeurWidth + ", menubar=" + lValeurMenuBar + ",resizable=" + lValeurResizable + ",status=" + lValeurStatus + ",toolbar=" + lValeurToolBar + ",location=" + lValeurLocation + ",scrollbars=" + lValeurScrollbar);
    objDialogWin.win = window.open(pURL, pTitre, "'left=" + lValeurLeft + ",top=" + lValeurTop + ",height=" + lValeurHeight + ",width=" + lValeurWidth + ", menubar=" + lValeurMenuBar + ",resizable=" + lValeurResizable + ",status=" + lValeurStatus + ",toolbar=" + lValeurToolBar + ",location=" + lValeurLocation + ",scrollbars=" + lValeurScrollbar + "'");

}

function OnClientItemExpand(sender, args) {
    //dsftag_send2('DCSext.navigation', 'fn_faq', 'WT.ti', args.get_item().get_text());
    dsftag_send('DCSext.navigation', 'fn_collapse', 'WT.ti', args.get_item().get_text());

}

function OnClientCloseMaster(oWnd) {
    oWnd.setUrl('/_layouts/blank.htm');
    oWnd.remove_close(OnClientCloseMaster);
}

function CenterRadWindowEdit(oW) {
    var Wwidth = oW.GetWidth();
    var Wheight = oW.GetHeight();
    var posx;
    var posy;
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        myWidth = window.innerWidth;
        myHeight = ((window.innerHeight - Wheight) / 2) + document.documentElement.scrollTop;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        myWidth = document.documentElement.clientWidth;
        myHeight = ((document.documentElement.clientHeight - Wheight) / 2) + document.documentElement.scrollTop;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        myWidth = document.body.clientWidth;
        myHeight = ((document.body.clientHeight - Wheight) / 2) + document.body.scrollTop;
    }
    posx = ((myWidth - Wwidth) / 2);
    if (myHeight < 0) {
        myHeight = 0;
    }
    posy = myHeight;
    oWindow.MoveTo(posx, posy);
}


function fg_AcceptOnly(pregMask, pEvent) {
    var strCar;
    var strResetCar;
    
    mblnOnKeyPress = false; mregMask = /^$/;

    if (navigator.appName != "Netscape") {
        strCar = String.fromCharCode(pEvent.keyCode);
        strResetCar = "pEvent.keyCode=0";
    }
    else {
        strCar = String.fromCharCode(pEvent.which);
        strResetCar = "pEvent.which = 0;";
    }

    if (strCar < " ") return true;
    if (!pregMask.test(strCar)) {
        return false;
    }
    return true;
}

function OnChangeSelectionProvince(_province) {
    var newUrl;
    if (window.location.href.indexOf('?') == -1) { newUrl = window.location.href + '?province=' + _province + '&navigation=fn_changeprovince'; }
    else {
        var strQuery = parent.location.href.split('?');
        newUrl = strQuery[0] + '?province=' + _province + '&navigation=fn_changeprovince';
    }
    window.location = newUrl;
}

function OnChangeSplashScreenProvince(_province) {
    var newUrl;
    if (parent.location.href.indexOf('?') == -1) { newUrl = parent.location.href + '?province=' + _province }
    else {
        var strQuery = parent.location.href.split('?');
        var qs = new Querystring(strQuery[1]);
        var qsProvince = qs.get('province');
        if (typeof (qsProvince) != 'undefined') {
            newUrl = parent.location.href.replace(/province=[a-zA-Z][a-zA-Z]/, 'province=' + _province);
        }
        else {
            newUrl = parent.location.href + '&province=' + _province;
        }
    }
    parent.location = newUrl;
} 
