﻿// JScript File
//------------------------------------------------------------------
//Script for removing the spaces from left side of the text box and
//right side of the text box.
//------------------------------------------------------------------
function TrimL(text) {
    while (text.value.charAt(0) == ' ')
        text.value = text.value.substring(1, text.value.length)
    //          while(text.value.charAt(text.value.length-1)=='#')
    //              text.value=text.value.substring(0,text.value.length-1)
    //while(text.value.charAt(text.value.length-1)==' ')
}
function TrimAll(text) {
    while (text.value.charAt(text.value.length - 1) == ' ')
        text.value = text.value.substring(0, text.value.length - 1)
}
function TrimR(text) {
    while (text.value.charAt(text.value.length - 1) == ' ')
        text.value = text.value.substring(0, text.value.length - 1)
}
//-----------------------------------------------------------------

// JScript File

//-------------------------------------------------------------------
// isNull(value)
//   Returns true if value is null
//-------------------------------------------------------------------
function isNull(val) { return (val == null); }

//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val) {
    if (val == null) { return true; }
    for (var i = 0; i < val.length; i++) {
        if ((val.charAt(i) != ' ') && (val.charAt(i) != "\t") && (val.charAt(i) != "\n") && (val.charAt(i) != "\r")) { return false; }
    }
    return true;
}
//-------------------------------------------------------------------
// isSplChar(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isSplChar1(val) {
    if (val == null) { return true; }
    for (var i = 0; i < val.length; i++) {
        if (
		(val.charAt(i) != '!')
		&& (val.charAt(i) != "@")
		&& (val.charAt(i) != "#")
		&& (val.charAt(i) != "$")
		&& (val.charAt(i) != "%")
		&& (val.charAt(i) != "^")
		&& (val.charAt(i) != "&")
		&& (val.charAt(i) != "*")
		&& (val.charAt(i) != "(")
		&& (val.charAt(i) != ")")
		&& (val.charAt(i) != ".")
		&& (val.charAt(i) != ",")
		&& (val.charAt(i) != ":")
		&& (val.charAt(i) != ";")
		&& (val.charAt(i) != "'")
		&& (val.charAt(i) != "|")
		&& (val.charAt(i) != "\\")
		&& (val.charAt(i) != "+")
		&& (val.charAt(i) != "-")
		&& (val.charAt(i) != "[")
		&& (val.charAt(i) != "]")
		&& (val.charAt(i) != ";")
		&& (val.charAt(i) != "{")
		&& (val.charAt(i) != "}")
		&& (val.charAt(i) != "<")
		&& (val.charAt(i) != ">")
		&& (val.charAt(i) != "?")
		&& (val.charAt(i) != "\"")
		&& (val.charAt(i) != "~")
		&& (val.charAt(i) != "`")
		&& (val.charAt(i) != "_")
		&& (val.charAt(i) != "=")
		&& (val.charAt(i) != "/")
		)
        { return false; }
    }
    return true;
}
//-------------------------------------------------------------------
// isSplChar1(value) 
// Returns any validation for any special character in the string.
//-------------------------------------------------------------------
function isSplChar(val) {
    var iChars = "!`@#$%^&*()+=-[]\\\';,./{}|\":<>?~_";
    for (var i = 0; i < val.length; i++) {
        if (iChars.indexOf(val.charAt(i)) != -1) {
            return true;
        }



    }

}

//-------------------------------------------------------------------
// isInteger(value)
//   Returns true if value contains all digits
//-------------------------------------------------------------------
function isInteger(val) {
    if (isBlank(val)) { return false; }
    for (var i = 0; i < val.length; i++) {
        if (!isDigit(val.charAt(i))) { return false; }
    }
    return true;
}

//-------------------------------------------------------------------
// isNumeric(value)
//   Returns true if value contains a positive float value
//-------------------------------------------------------------------
function isNumeric(val) { return (parseFloat(val, 10) == (val * 1)); }

//-------------------------------------------------------------------
// isArray(obj)
// Returns true if the object is an array, else false
//-------------------------------------------------------------------
function isArray(obj) { return (typeof (obj.length) == "undefined") ? false : true; }

//-------------------------------------------------------------------
// isDigit(value)
//   Returns true if value is a 1-character digit
//-------------------------------------------------------------------
function isDigit(num) {
    if (num.length > 1) { return false; }
    var string = "1234567890";
    if (string.indexOf(num) != -1) { return true; }
    return false;
}


//-------------------------------------------------------------------
// isChanged(input_object)
//   Returns true if input object's value has changed since it was
//   created.
//-------------------------------------------------------------------
function isChanged(obj) { return (getInputValue(obj) != getInputDefaultValue(obj)); }



//-------------------------------------------------------------------
// isFormModified(form_object,hidden_fields,ignore_fields)
//   Check to see if anything in a form has been changed. By default
//   it will check all visible form elements and ignore all hidden 
//   fields. 
//   You can pass a comma-separated list of field names to check in
//   addition to visible fields (for hiddens, etc).
//   You can also pass a comma-separated list of field names to be
//   ignored in the check.
//-------------------------------------------------------------------
function isFormModified(theform, hidden_fields, ignore_fields) {
    if (hidden_fields == null) { hidden_fields = ""; }
    if (ignore_fields == null) { ignore_fields = ""; }
    var hiddenFields = new Object();
    var ignoreFields = new Object();
    var i, field;
    var hidden_fields_array = hidden_fields.split(',');
    for (i = 0; i < hidden_fields_array.length; i++) {
        hiddenFields[Trim(hidden_fields_array[i])] = true;
    }
    var ignore_fields_array = ignore_fields.split(',');
    for (i = 0; i < ignore_fields_array.length; i++) {
        ignoreFields[Trim(ignore_fields_array[i])] = true;
    }
    for (i = 0; i < theform.elements.length; i++) {
        var changed = false;
        var name = theform.elements[i].name;
        if (!isBlank(name)) {
            var type = theform.elements[i].type;
            if (!ignoreFields[name]) {
                if (type == "hidden" && hiddenFields[name]) { changed = isChanged(theform[name]); }
                else if (type == "hidden") { changed = false; }
                else { changed = isChanged(theform[name]); }
            }
        }
        if (changed) { return true; }
    }
    return false;
}


//-------------------------------------------------------
function ValidateNumeric() {
    var keyCode = window.event.keyCode;
    if (keyCode > 57 || keyCode < 4)
        window.event.returnValue = false;
}
