﻿/* Trim string */
function trim(str) {
    var s = str;
    while((s.length > 0) && (s.charAt(0) == ' '))
        s = s.substring(1);
    while((s.length > 0) &&(s.charAt(s.length - 1) == ' '))
		s = s.substring(0, s.length - 1);
	return s;
}

/* Check if string contains just alphanumerical symbols*/
function IsOnlyAlphanumerical(str) {
    str = trim(str);
    if (str.length > 0) {
        var myRegxp = /^([a-zA-Z0-9]+)$/;
        if(myRegxp.test(str) == false) {
            return false;
        }
    }
    return true;
}

function IsOnlyAlphanumericalWithSpace(str) {
    str = trim(str);
    if (str.length > 0) {
        var myRegxp = /^([a-zA-Z0-9\s]+)$/;
        if(myRegxp.test(str) == false) {
            return false;
        }
    }
    return true;
}

function ReplaceAlphanumerical(str) {
    str = trim(str);
    if (str.length > 0) {
        str = str.replace(/[a-zA-Z0-9\s]+/g, '');
    }
    return str;
}

function ReplaceNonAlphanumerical(str) {
    str = trim(str);
    if (str.length > 0) {
        str = str.replace(/[^A-Za-z0-9\s]/g, '');
    }
    return str;
}

function TextAreaMaxLength(textAreaID, maxLen)
{
      textArea = document.getElementById(textAreaID);
      if(textArea.value.length >maxLen){
            textArea.value = textArea.value.substring(0, maxLen);
     }
}