//-------------------------------------------------------------------
// Trim functions
//   Returns string with whitespace trimmed
//-------------------------------------------------------------------
function LTrim(str){
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
	}
function RTrim(str){
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
	}
function Trim(str){return LTrim(RTrim(str));}
//-------------------------------------------------------------------
// 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){
	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);}

//-------------------------------------------------------------------
// 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;
	}


function isEmail (s)
{   
    if (isBlank(s)) return false;
    
    var i = 1;
    var sLength = s.length;

    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function CheckFieldBlank(theForm, fldName, fldCalled){

	var fld = eval('theForm["' + fldName + '"]');
	if (isBlank(fld.value))
	{
		alert('Please fill ' + fldCalled + ' field.');
		fld.focus();
		return false;	
	};
	return true;	
}

function CheckEmailField(theForm, fldName, fldCalled){

	var fld = eval('theForm["' + fldName + '"]');
	if (!isEmail(fld.value))
	{
		alert('Please fill ' + fldCalled + ' with valid email.');
		fld.focus();
		return false;	
	};
	return true;	
}

function CheckRadio(theForm, fldName, fldCalled){

	var fld = eval('theForm["' + fldName + '"]');
	for (var i=0; i < fld.length; ++i) {
		if(document.form1.Business[i].checked) {
			return true;
		}
	};
	alert('Please select ' + fldCalled + '.');
	fld[0].focus();
	return false;
}

function CheckSelect(theForm, fldName, fldCalled){

	var fld = eval('theForm["' + fldName + '"]');
	if (isBlank(fld[fld.selectedIndex].value))
	{
		alert('Please select ' + fldCalled + '.');
		fld.focus();
		return false;	
	};
	return true;
}

function CheckFieldDigits(theForm, fldName, fldCalled){

	var fld = eval('theForm["' + fldName + '"]');
	if (isBlank(fld.value))
	{
		alert('Please fill ' + fldCalled + '.');
		fld.focus();
		return false;	
	};
	if (!isInteger(fld.value))
	{
		alert('Please fill ' + fldCalled + ' field with digits only.');
		fld.focus();
		return false;	
	};
	return true;	
}