﻿// JScript File
function enterNumericDataOnly(e, ctrl) {
    var charCode = (e.which) ? e.which : event.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}

function enterNumericDataOnlyMembers(txtvalue, ctrl, fragment) {
    if (txtvalue == "0" || txtvalue == "1" || txtvalue == "2") {
        alert("Must have at least 3 team members to be eligible");
        tempField = document.getElementById("ctl00_ContentPlaceHolder_txtNoOfTeamMembers");
        setTimeout("tempField.focus();", 1);
        return false;
    }

    if (txtvalue != '') {
        if (parseInt(document.getElementById("ctl00_ContentPlaceHolder_hdnStepID").value) > parseInt(fragment)) {
            if (ctrl.value == '') {
                if (document.getElementById("ctl00_ContentPlaceHolder_hdnTextValue").value != "") {
                    ctrl.value = document.getElementById("ctl00_ContentPlaceHolder_hdnTextValue").value;
                    document.getElementById("ctl00_ContentPlaceHolder_hdnTextValue").value = "";
                    alert("You cannot keep the value blank");
                }
            }
        }
    }
    return true;
}


function enterDecimalDataOnly(e, ctrl) {
    var charCode = (e.which) ? e.which : e.keyCode;

    if (charCode == 46 && ctrl.value.indexOf(".") > -1)
        return false;
    if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46)
        return false;
    return true;
}
function enterDecimalDataOnly1(e, ctrl) {

    var charCode = (e.which) ? e.which : event.keyCode;
    if (charCode == 46 && ctrl.value.indexOf(".") > -1)
        return false;
    if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46 && charCode != 44 && charCode != 45)
        return false;


    return true;
}


function enterYN(e, ctrl) {

    var charCode = (e.which) ? e.which : event.keyCode;
    if (charCode == 89 || charCode == 78 || charCode == 121 || charCode == 110)
        return true;

    return false;


}

var http;
var url = "Registration.aspx"
function ConnectToPage() {
    alert("Connect");
    http = new XMLHttpRequest();
    http.open("GET", url, true);
    http.onreadystatechange = function () {//Call a function when the state changes.
        if (http.readyState == 4 && http.status == 200) {

        }
    }
    http.send(null);
}


function imposeMaxLength(Object, MaxLen) {
    return (Object.value.length <= MaxLen);
}

// Keep user from entering more than maxLength characters
function doKeypress(control, maxLength) {
    value = control.value;
    if (maxLength && value.length > maxLength - 1) {
        event.returnValue = false;
        maxLength = parseInt(maxLength);
    }
}
// Cancel default behavior
function doBeforePaste(control, maxLength) {
    if (maxLength) {
        event.returnValue = false;
    }
}
// Cancel default behavior and create a new paste routine
function doPaste(control, maxLength) {
    value = control.value;
    if (maxLength) {
        event.returnValue = false;
        maxLength = parseInt(maxLength);
        var oTR = control.document.selection.createRange();
        var iInsertLength = maxLength - value.length + oTR.text.length;
        var sData = window.clipboardData.getData("Text").substr(0, iInsertLength);
        oTR.text = sData;
    }
}

function doKeypressDate(control, e) {
    e.returnValue = false;
}
// Cancel default behavior
function doBeforePasteDate(control, e) {

    e.returnValue = false;

}
// Cancel default behavior and create a new paste routine
function doPasteDate(control, e) {
    e.returnValue = false;
}
function wordCounter(field, maxlimit, e) {
    var charCode = (e.which) ? e.which : event.keyCode;
    //alert(charCode);
    // debugger;
    if (charCode != 8 && charCode != 46 && charCode != 35 && charCode != 36 && charCode != 37 && charCode != 38 && charCode != 39 && charCode != 40) {
        var cnt;
        var words = field.value.split(/\s/);
        cnt = words.length;

        if (cnt >= (parseInt(maxlimit))) {
            if (charCode == 32) {
                e.returnValue = false;
                return false;
            }
        }
        if (cnt >= (parseInt(maxlimit) + 1)) { e.returnValue = false; return false; }


    }
}

function wordCounter1(field, maxlimit) {
    var cnt;
    //var fvalue = field.value;
    //alert(field);
    var fvalue = field.value.replace(/\s+/gi, ' ');
    //alert(fvalue);
    var words = fvalue.split(/\s/);
    cnt = words.length;
   
    if (cnt > (parseInt(maxlimit) + 1)) {
        alert('You have reached the word limit for this field. Please make sure that any copy and pasted text does not exceed this limit. It will be truncated.');


        //return false;

    }
    //alert(cnt);
    //alert(maxlimit);
    if (cnt > maxlimit) {
        var result = "";
       // alert("on");
        for (var i = 0; i <= maxlimit; i++) {
            result += words[i] + " ";
        }
        field.value = result;
    }

}

function empty_title(ctrl) {
    //ctrl.removeAttribute("title");  
    ctrl.setAttribute("title", "");
}
function apply_title(ctrl, errMsg) {
    ctrl.setAttribute("title", errMsg);
}
