﻿
function limitText(limitField, limitNum) {
    limitField = $(limitField);
	if (limitField.val().length > limitNum) {
		limitField.val(limitField.val().substring(0, limitNum));
	} else {
		limitCount.val(limitNum - limitField.val().length);
	}
}

function IsNumeric(strString) //  check for valid numeric strings	
{
 	if(!/\D/.test(strString)) return true;//IF NUMBER
 	else if(/^\d+\.\d+$/.test(strString)) return true;//IF A DECIMAL NUMBER HAVING AN INTEGER ON EITHER SIDE OF THE DOT(.)
 	else return false;
}

function pageWidth() {return $(window).width();}
function pageHeight() {return $(window).height();}

function PopUpWindowWidth()
{
    var Width = pageWidth();
    if(Width < 700){Width = 700;}//force a Minimum size
    return Width;
}

function PopUpWindowHeight()
{
    var Height = pageHeight();
    if(Height < 600){Height = 600;}//force a Minimum size
    return Height;
}

function RefreshPage()
{
    setTimeout("window.location.href = window.location.href;", 500);//needs a timeout because it may call AjaxRequestString
}

function isValidEmail(strEmailAddress)//single
{
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strEmailAddress.trim()))
    {
        return true;
    }
    else
    {
        return false;
    }
}

function isValidEmails(strEmails)//Multiple - uses isValidEmail
{
    var boolValidEmails = true;
    var emails = strEmails.split(",");
    for(i = 0; i < emails.length; i++){
	    if(!isValidEmail(emails[i]))
	    {
	        boolValidEmails = false;
	        break;
	    }
    }
    return boolValidEmails;
}

String.prototype.trim = function () {
    return this.replace(/^\s*|\s*$/,"");
}

String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}