<!--
//---------------------------------------------------------------------------------------
// PiXL Pivotal Business Server HTML Forms Generator
// Copyright 2003, 2004 Consultants Crac! Inc.
// Use of this component is subject to the clauses of a licence agreement.
// Please read your licence agreement carefully before using or modifying this component
//
//---------------------------------------------------------------------------------------
// File      : FormFieldFunctions.js
// Version   : 1.1
// DateTime  : 2003-11-22 13:32
// Author    : P.Custeau
// Purpose   : This document's purpose is to hold various functions that serve in displaying
//             special HTML field elements and poping up various forms
//---------------------------------------------------------------------------------------


var STR_ERROR_NO_PERMISSION = 'You have no permissions to modify this data'

function ShowCBO(oSource, oTarget) {
    oSource.style.width = oTarget.offsetWidth;
    oSource.style.left = oTarget.offsetLeft;
    oSource.style.top = oTarget.offsetHeight + oTarget.offsetTop;
    oSource.style.display = '';
    oSource.focus();
}

function CBOSelected(oSource, oTarget) {
    oTarget.value = oSource.value;
    oSource.style.display = 'none';
}

function CBONavigation(oEvnt, oSource, oTarget) {
    var iKeyCode = -1;
    if (oEvnt && oEvnt.which)
        iKeyCode = oEvnt.which; // Netscape
    else if (window.event && window.event.keyCode)
        iKeyCode = window.event.keyCode; // IE
    if(iKeyCode == 13 || iKeyCode == 32) {
        CBOSelected(oSource, oTarget);
    }
}

function DropCBO(oEvnt, oSource, oTarget) {
    
    var iKeyCode = -1;
    if (oEvnt && oEvnt.which)
        iKeyCode = oEvnt.which; // Netscape
    else if (window.event && window.event.keyCode)
        iKeyCode = window.event.keyCode; // IE
    if(iKeyCode == 40) {
        ShowCBO(oSource, oTarget);
    }
}

function ShowRecordPicker(sFieldId, sTableId) {

    var iWidth = window.screen.availWidth;
    var iHeight = window.screen.availHeight;
    var iDocWidth = iWidth * 0.8;
    var iDocHeight = iHeight * 0.8;
    var iDocTop = iHeight * 0.1;
    var iDocLeft = iWidth * 0.1;
    var sFeatures = 'status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes';
    sFeatures += ',height=' + iDocHeight.toFixed();
    sFeatures += ',width=' + iDocWidth.toFixed();
    sFeatures += ',top=' + iDocTop.toFixed();
    sFeatures += ',left=' + iDocLeft.toFixed();
    var sURL = 'rIdPicker.asp?TableId=';
    sURL += sTableId;
    sURL += '&FieldId=' + sFieldId;
    
    window.open(sURL, 'rIdPicker', sFeatures);
    
}

function ShowDatePicker(oField) {
    var sURL = 'dtPicker.asp?FieldId=' + oField.id;
    window.self.name = 'main';

    var iWidth = window.screen.availWidth;
    var iHeight = window.screen.availHeight;
    var iDocWidth = iWidth * 0.15;
    var iDocHeight = iHeight * 0.15;
    var iDocTop = iHeight * 0.425;
    var iDocLeft = iWidth * 0.425;
    var sFeatures = 'dependent=yes,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=no';
    sFeatures += ',height=' + iDocHeight.toFixed();
    sFeatures += ',width=' + iDocWidth.toFixed();
    sFeatures += ',top=' + iDocTop.toFixed();
    sFeatures += ',left=' + iDocLeft.toFixed();
    window.open(sURL, "CAL", sFeatures, true)
}

function GetSegmentFromField(oField){
    if(oField.id != ""){
        var sFldId = String(oField.id);
        var a = sFldId.split('_');
        var sSegtmentId = 'seg_' + String(a[1]);
        return document.getElementById(sSegtmentId);
    }
}
    
function SegDispMgr(sSegmentId, sValue){
    if(sSegmentId == ""){return false}
    if(sValue == "1"){
        document.getElementById(sSegmentId).style.display = "";
    } else {
        document.getElementById(sSegmentId).style.display = "none";
    }
}

function EmailCheck(oField) {
    var sAddr = String(oField.value);
    if(sAddr.length < 1) { return; }
	var regInvalid = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
    var regValid = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
    if (regInvalid.test(sAddr) || !regValid.test(sAddr)) {
        window.alert("Merci de bien vouloir vérifier votre adresse e-mail");
        oField.focus();
        return false;
    }
}

