//-------------------------------------------------------------------
// 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;
}

//-------------------------------------------------------------------
// 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;
}

//---------------------------------------------------------------
// isSpecialChar(value)
// Returns true if value is a non special char value
//---------------------------------------------------------------
function isSpecialChar(val){
    //    if(val.length>1){return false;}
    var string="()>,<+-*\|-_[]{};:/?.`~!@#$%^&*";
    for(var i=0;i<val.length;i++){
        if (string.indexOf(val.charAt(i))==-1){return false;}
    }
    return true;
}

function isStringOnly(val){
    //  if(val.length>1){return false;}
    var string="ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz";
    for(var i=0;i<val.length;i++){
        if (string.indexOf(val.charAt(i))==-1){return false;}
    }
    return true;
}

function isAlphaNumaric(val){
    //  if(val.length>1){return false;}
    var string="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_.";
    for(var i=0;i<val.length;i++){
        if (string.indexOf(val.charAt(i))==-1){return false;}
    }
    return true;
}

function validationAlert(strAlert, hField) {
	// Displays an alert, focuses a form field, and returns false.
	alert(strAlert);
	try { hField.focus(); } catch(ex) {}
	return false;
}

function validateInput(hInput, minLength, inputDescription) {
	if (hInput.value.length == 0) {
		return validationAlert("Please enter " + inputDescription + ".", hInput);
	} else if (hInput.value.length < minLength) {
		return validationAlert("Please re-enter " + inputDescription + ".\n(The information you entered is incomplete.)", hInput);
	}
	return true;
}

function validateSelectbox(hSelectbox, strAlert) {
	if (hSelectbox.value == '') {
		return validationAlert(strAlert, hSelectbox);
	}
	return true;
}

function isValidEmail(strEmail) {
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

	if (strEmail.length < 5) { return false; }

	if (!strEmail.match(re)) { return false; }

	return true;
}
