﻿function fnMoveUp(strListID) {
    var oList;
    re = new RegExp(strListID);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i];
        if (re.test(elm.name)) {
            oList = elm;
            break;
        }
    }
    if (oList != null) {
        var intLen = oList.length;
        for (var intCtr = 0; intCtr < intLen; intCtr++) {
            if (oList.options.selectedIndex == -1)
                break;
            var intSelectedIndex = oList.options[intCtr].index;
            if (oList.options[intCtr].selected == false)
                continue;
            if (intSelectedIndex == 0)
                break;
            var strPrevValue = oList.options[intSelectedIndex - 1].value;
            var strPrevID = oList.options[intSelectedIndex - 1].id;
            var strPrevText = oList.options[intSelectedIndex - 1].text;
            oList.options[intSelectedIndex - 1].value = oList.options[intSelectedIndex].value;
            oList.options[intSelectedIndex - 1].id = oList.options[intSelectedIndex].id;
            oList.options[intSelectedIndex - 1].text = oList.options[intSelectedIndex].text;
            oList.options[intSelectedIndex].value = strPrevValue;
            oList.options[intSelectedIndex].id = strPrevID;
            oList.options[intSelectedIndex].text = strPrevText;
            oList.options[intSelectedIndex - 1].selected = true;
            oList.options[intSelectedIndex].selected = false;
        }
        return oList;
    }
}

function fnMoveDown(strListID) {
    var oList;
    re = new RegExp(strListID);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i];
        if (re.test(elm.name)) {
            oList = elm;
            break;
        }
    }
    if (oList != null) {
        var intLen = oList.length;
        for (var intCtr = intLen - 1; intCtr >= 0; intCtr--) {
            if (oList.options.selectedIndex == -1)
                break;
            var intSelectedIndex = oList.options[intCtr].index;
            if (oList.options[intCtr].selected == false)
                continue;
            if (intSelectedIndex == intLen - 1)
                break;
            var strNextValue = oList.options[intSelectedIndex + 1].value;
            var strNextText = oList.options[intSelectedIndex + 1].text;
            oList.options[intSelectedIndex + 1].value = oList.options[intSelectedIndex].value;
            oList.options[intSelectedIndex + 1].text = oList.options[intSelectedIndex].text;
            oList.options[intSelectedIndex].value = strNextValue;
            oList.options[intSelectedIndex].text = strNextText;
            oList.options[intSelectedIndex].selected = false;
            oList.options[intSelectedIndex + 1].selected = true;
        }
        return oList;
    }
}
function fnDisableCopy(event) {
    alert("Copy is not allow");
    return false;
}
function fnDisablePaste(event) {
    alert("Paste is not allow");
    return false;
}
function fnDeleteConfirm() {
    return confirm("Are you sure you want to delete?");
}
function fnAlreadyExist() {
    alert("Item already exist.");
}
function fnAlreadyUse() {
    alert("Sorry you can't delete the selected item because it's already in use.");
}
function fnOnlyNumber(event) {
    var boolResult = true;
    var keycode = event.keyCode;
    if (keycode != 8 && keycode != 9 && keycode != 13 && keycode != 46 && keycode != 37 && keycode != 39 && keycode != 110 && keycode != 190 && (keycode < 48 || keycode > 57) && (keycode < 96 || keycode > 105)) {

        boolResult = false;
    }
    else {

        boolResult = true;
    }
    if (event.shiftKey == true) {
        if (keycode == 9) {
            boolResult = true;
        }
        else
            boolResult = false;
    }
    return boolResult;
}
function EnsureNoSpecialCharater(evt, strTextboxID, blnShowAlert) {
    var blnCheck = specialCharacterCheck(strTextboxID);
    var objTextbox = document.getElementById(strTextboxID);

    if (blnCheck == false) {
        if (blnShowAlert != false) {
            alert("Special characters %,&,<,>,# are not allowed.");
        }
        objTextbox.value = objTextbox.value.toString().replace(/%/g, "").replace(/&/g, "").replace(/</g, "").replace(/>/g, "").replace(/#/g, "");
    }

    return blnCheck;
}

function specialCharacterCheck(txtControl) {
    var iChars = "&#%<>";
    var txtControlValue = document.getElementById(txtControl).value;

    for (var i = 0; i < txtControlValue.length; i++) {
        if (iChars.indexOf(txtControlValue.charAt(i)) != -1) {
            return false;
        }
    }
    return true;
}
function CheckForValidFile(fileName, extArray) {
    if (fileName == '') {
        return true;
    }
    //Setting the extension array for diff. type of text files 
    //var extArray = new Array(".gif",".jpg",".jpeg",".bmp",".png");

    //getting the file name
    while (fileName.indexOf("\\") != -1)
        fileName = fileName.slice(fileName.indexOf("\\") + 1);

    //Getting the file extension                     
    var ext = fileName.slice(fileName.lastIndexOf(".")).toLowerCase();
    //matching extension with our given extensions.
    for (var i = 0; i < extArray.length; i++) {
        if (extArray[i] == ext) {
            return true;
        }
    }
    return false;
}
function EnsureDecimal(event) {


    var charCode = (event.which) ? event.which : event.keyCode

    if (charCode == 46) {
        var src = (typeof event.target != 'undefined') ? event.target : evt.srcElement;
        var myArray = src.value.split('');
        for (i = 0; i < myArray.length; i++) {
            if (myArray[i] == '.') {
                return false;
            }
        }
    }
    else if (event.keyCode == 39 || event.keyCode == 37 || event.keyCode == 35) {
        return true;
    }
    else if (charCode >= 48 && charCode <= 57) {
        //    alert(obj.getAttribute("value"));
        //         var myArray = obj.getAttribute("value").split('');
        //         
        //         for (i=0;i<myArray.length;i++)
        //         {alert(myArray[i])
        //            if (myArray[i] == '.')
        //            {   
        //                if(i < myArray.length-2) 
        //                    return false;
        //            }
        //        }

    }
    else if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    }
    return true;
}
function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g, "");
}
function ltrim(stringToTrim) {
    return stringToTrim.replace(/^\s+/, "");
}
function rtrim(stringToTrim) {
    return stringToTrim.replace(/\s+$/, "");
}
function OnlyNumberWithOnePoint(event, value) {
    var boolResult = true;
    var keycode = event.keyCode;
    if (keycode != 8 && keycode != 9 && keycode != 13 && keycode != 46 && keycode != 37 && keycode != 39 && keycode != 110 && keycode != 190 && (keycode < 48 || keycode > 57) && (keycode < 96 || keycode > 105)) {
        boolResult = false;
    }
    else {
        boolResult = true;
    }
    if (event.shiftKey == true) {
        if (keycode == 9) {
            boolResult = true;
        }
        else
            boolResult = false;
    }
    return Boolean(boolResult);
}

function fnOnlyOnePoint(id, value) {
    var varPointCount = 0;
    if (value.length > 0) {
        for (var i = 0; i < value.length; i++) {
            if (value[i] == ".") {
                varPointCount = varPointCount + 1;
                if (varPointCount > 1) {
                    document.getElementById(id).value = value.substring(0, value.length - 1);
                    return true;
                }
            }
        }
    }
}
function fnOnlyNumber1(event) {
    var boolResult = true;
    var keycode = event.keyCode;    
    if (keycode != 8 && keycode != 9 && keycode != 13 && keycode != 46 && keycode != 37 && keycode != 39  && (keycode < 48 || keycode > 57) && (keycode < 96 || keycode > 105)) {

        boolResult = false;
    }
    else {

        boolResult = true;
    }
    if (event.shiftKey == true) {
        if (keycode == 9) {
            boolResult = true;
        }
        else
            boolResult = false;
    }
    return boolResult;
}
function getDateObject(dateString, dateSeperator) {
    //This function return a date object after accepting 
    //a date string ans dateseparator as arguments
    var curValue = dateString;
    var sepChar = dateSeperator;
    var curPos = 0;
    var cDate, cMonth, cYear;

    //extract day portion
    curPos = dateString.indexOf(sepChar);
    cMonth = dateString.substring(0, curPos);

    //extract month portion				
    endPos = dateString.indexOf(sepChar, curPos + 1);
    cDate = dateString.substring(curPos + 1, endPos);

    //extract year portion				
    curPos = endPos;
    endPos = curPos + 5;
    cYear = curValue.substring(curPos + 1, endPos);

    //Create Date Object
    dtObject = new Date(cYear, cMonth - 1, cDate);
    return dtObject;
}
function fnOnlyNumberForContactNo(event) {
    var boolResult = true;
    var keycode = event.keyCode;
    if (keycode != 8 && keycode != 9 && keycode != 13 && keycode != 46 && keycode != 37 && keycode != 39 && keycode != 109 && keycode != 190 && (keycode < 48 || keycode > 57) && (keycode < 96 || keycode > 105)) {
        boolResult = false;
    }
    else {
        boolResult = true;
    }
    if (event.shiftKey == true) {
        if (keycode == 9) {
            boolResult = true;
        }
        else
            boolResult = false;
    }
    return boolResult;
}

function fnOnlyNumberForPostalCode(event) {
    var boolResult = true;
    var keycode = event.keyCode;
    if (keycode != 8 && keycode != 9 && keycode != 13 && keycode != 46 && keycode != 37 && keycode != 39 && keycode != 190 && (keycode < 48 || keycode > 57) && (keycode < 96 || keycode > 105)) {
        boolResult = false;
    }
    else {
        boolResult = true;
    }
    if (event.shiftKey == true) {
        if (keycode == 9) {
            boolResult = true;
        }
        else
            boolResult = false;
    }
    return boolResult;
}

function fnCheckMaxlengthOnKeyPress(field, maxChars, evt) {
    var charCode = 0;
    if (evt.keyCode) {
        charCode = evt.keyCode;
    }
    if (evt.which) {
        charCode = evt.which;
    }
    if (charCode == 8 || charCode == 9 || charCode == 20 || charCode == 27 || (charCode >= 33 && charCode <= 40)
        || charCode == 16 || charCode == 17 || charCode == 18 || charCode == 45 || charCode == 46
        || charCode == 91 || (charCode >= 112 && charCode <= 123) || charCode == 144 || charCode == 0) {
        return true;
    }

    if (field.value.length >= maxChars) {
        if (evt.returnValue) {
            evt.returnValue = false;
            evt.cancelBubble = true;
        }
        if (evt.preventDefault) {
            evt.preventDefault();
            evt.stopPropagation();
        }
        return false;
    }
}

function fnCheckMaxlengthOnPaste(field, maxChars, evt) {
    var charCode = 0;
    if (evt.keyCode) {
        charCode = evt.keyCode;
    }
    if (evt.which) {
        charCode = evt.which;
    }
    if (charCode == 8 || charCode == 9 || charCode == 20 || charCode == 27 || (charCode >= 33 && charCode <= 40)
        || charCode == 16 || charCode == 17 || charCode == 18 || charCode == 45 || charCode == 46
        || charCode == 91 || (charCode >= 112 && charCode <= 123) || charCode == 144 || charCode == 0) {
        return true;
    }
    if (evt.returnValue) {
        evt.returnValue = false;
        evt.cancelBubble = true;
    }
    if (evt.preventDefault) {
        evt.preventDefault();
        evt.stopPropagation();
    }

    if ((field.value.length + window.clipboardData.getData("Text").length) > maxChars) {
        return false;
    }
    return true;
}
