﻿function DoRefresh() {
    document.location.reload();
}

function trim(value) {
    value = lTrim(value);
    return rTrim(value);
}

function rTrim(value) {
    while (value.charAt((value.length - 1)) == " ") {
        value = value.substring(0, value.length - 1);
    }
    return value;
}

function lTrim(value) {
    while (value.charAt(0) == " ") {
        value = value.replace(value.charAt(0), "");
    }
    return value;
}

function showThis(objToShow) {
    if (objToShow != null) {
        objToShow.style.visibility = 'visible';
        objToShow.style.display = 'inline';
    }
}

function hideThis(objToHide) {
    if (objToHide != null) {
        objToHide.style.visibility = 'hidden';
        objToHide.style.display = 'none';
    }
}

function isInteger(value) {
    var index;
    for (index = 0; index < value.length; index++) {
        // Check that current character is number.
        var currentChar = value.charAt(index);
        if (((currentChar < "0") || (currentChar > "9")))
            return false;
    }
    // All characters are numbers.
    return true;
}

function isEmail(value) {
    var regexValue = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

    return regexValue.test(value);
}

function isContainsAlphabetsOnly(value) {
    var regexValue = /^[a-zA-Z]+$/;

    return regexValue.test(value);
}

function isContainsAlphabetsAndASpaceOnly(value) {
    var regexValue = /^[a-zA-Z\s]+$/;

    if(regexValue.test(value))
    {
        if(getMatches(value, ' ') > 1)
        {
            return false;
        }
        return true;
    }
    return false;
}

function getMatches(text, charac)
{
    var counter = 0;
    
    var textArray = text.split('');
    
    for (i = 0; i < text.length;i++)
    {
        if (textArray[i] == charac)
        {
            counter++;
        }
    }
    return counter;
}

function isContainsAlphanumericOnly(value) {
    var regexValue =  /^[a-zA-Z0-9]+$/;

    return regexValue.test(value);
}

function showSuccessMsg(msgObj, msg) {
    msgObj.style.color = 'green';
    showThis(msgObj);
    msgObj.innerHTML = msg;
}

function showErrorMsg(msgObj, msg) {
    msgObj.style.color = 'red';
    showThis(msgObj);
    msgObj.innerHTML = msg;
}

function validateThisTextBox(valueToValidate, reqErrMsg, errObj) {
    var isValid = true;

    if (trim(valueToValidate) == '') {
        errObj.innerHTML = reqErrMsg;
        showThis(errObj);
        isValid = false;
    }
    else {
        errObj.innerHTML = '';
        hideThis(errObj);
        isValid = true;
    }
    return isValid;
}

function showValidationResponse(errObj, errMsg, isValidationSuccess) {
    errObj.innerText = errMsg;

    if (isValidationSuccess) {
        hideThis(errObj);
    }
    else {
        showThis(errObj);
    }
}

function MM_openNewBrWindow(theURL, winName, features) {
    window.open(theURL, winName, features);
}
function eprintwin(wid, ht) {
    eprintwinclose = window.open("", "eprintwinclose", "status=no,toolbar=no,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=yes,width=" + wid + ",height=" + ht + ",left=300,top=150")
}
function eprintwin1(wid, ht) {
    eprintwinclose1 = window.open("", "eprintwinclose1", "status=no,toolbar=no,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=yes,width=" + wid + ",height=" + ht + ",left=20,top=0")
}