var whitespace = " \t\n\r";

//Checks for white spaces
function isWhitespace(s){ //To check whitespaces
    var i;
    if ((s == null) || (s.length == 0)) return true;
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}


//Checks if the parameter is a valid number
function checkNumber(s,t){//To check Number
	if (t == "r"){
		if (checkNull(s)){
			if (!isInteger(s.value)){
				return warnInvalid(s);
			}	
			else{
				if(s.value.valueOf()>0)
					return true;
				else
					return warnInvalid(s);
			}
		}
		else return false;	
	}
	else{
			if (s.value != ""){
			if (!isInteger(s.value)){
				return warnInvalid(s);
			}	
			else return true;
			}
		else return true;
	}	
}

//Checks if the parameter is a valid integer
function isInteger (s){
    var i;
    if ((s == null) || (s.length == 0)) 
       if (isInteger.arguments.length == 1) return false;
       else return (isInteger.arguments[1] == true);
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    return true;
}

//Checks if the parameter is a valid string
function checkString(s,t){//To check String
	if (t == "r"){
		if(checkNull(s)){
			if(s.value.length == 0)
				return false;
			else
				return true;
		}else 
			return false;
	}
	else
		return true;		
}

//Checks if the parameter is a digit
function isDigit (c){ 
  return ((c >= "0") && (c <= "9"));
}

//Checks if the parameter is an alphabet
function isLetter(c){
 return true;//( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || (c == " ") || (c == ".") || (c == "-") ||(c ==","));
}

//Verifies if a value is between given range
function isIntegerInRange (s, a, b){
   var num = s.value;
    if (num.indexOf("0") == 0)
		 num = num.charAt(1);
	num = parseInt (num);
    return ((num >= a) && (num <= b));
}


//Validates the length of the object passed against the length passed as the parameter and return true/false
function fnCheckLength(sString, nLength){
	if (sString.length > nLength)
		return false;
	return true;
}

//Validates if the parameter(drop down list box) is selected or not
function checkSelect(s,t){//To check Select Box
	var Selected=false;
	if (t == "r"){
		for (Count = 1; Count < s.length; Count++) {
			if (s[Count].selected)
				Selected = true;
		}
		if (Selected)
			return true;
		else
			return false;
	}

	else

		return true;

}

//Removed embedded white spaces in the string
function fnRemoveSpace(sObject){
	var sString;
	sString=sObject.value;
	sString = sString.replace(/ /g,"");
	sObject.value = sString;
}

function fnCheckEMail(sEMailAddr, bReqd){
	var nPos;
	if(sEMailAddr == "") {
		if (bReqd == "nr")
			return true;
		return false;
	}
	nPos = sEMailAddr.indexOf("@",0);
	if (nPos == -1)
		return false;
	if (sEMailAddr.indexOf("@",nPos+1) != -1)
		return false;
	if (sEMailAddr.indexOf(".", nPos+1) == -1)
		return false;
	if (sEMailAddr.indexOf(".", nPos+1)+3 > sEMailAddr.length)
		return false;
	return true;
}

function fnCheckRadioButton(sObject){
	var nLength, nStart, bChecked=false;
	nLength = sObject.length;
	for(nStart=0;nStart<nLength;nStart++){
		if (sObject[nStart].checked)
			bChecked=true;
	}
	return bChecked
}