var strSpace = " \t\n\r";
function isEmail(e){ 

		var i = 1;
		var j;
		var sLength = e.length;

		if (sLength < 5) {
			return false;
		}

		while ((i < sLength) && (e.charAt(i) != "@")) { 
			i++;
		}

		if ((i >= sLength) || (e.charAt(i) != "@")) return false;
		else i += 2;

		j = i;

		while ((i < sLength) && (e.charAt(i) != "_")) {
			i++;
		}
		if ((i < sLength - 1) || (e.charAt(i) == "_")) return false;
		
		while ((j < sLength) && (e.charAt(j) != ".")) { 
			j++;
		}

		// there must be at least one character after the .
		if ((j >= sLength - 1) || (e.charAt(j) != ".")) return false;

		i = sLength;
		while ((i > 0) && (e.charAt(i) != ".")) {
			i--;
		}
		if ((i <= 0) || (e.charAt(i) != ".")) return false;
		else i += 1;
		
		if ((sLength - i) > 3) return false;
		
		j = 0;
		i = 0;
		while (i < sLength) {
			if (e.charAt(i) == "@") {
				j++;
			}
			i++;
		}
		if (j > 1) return false;

		i = 0;
		while (i < sLength) {
			if ((!isLetterOrDigit(e.charAt(i))) && (e.charAt(i) != "_") && (e.charAt(i) != ".") && (e.charAt(i) != "@")	&& (e.charAt(i) != "-")) {
				return false;
			}
			i++;
		}
		return true;
}


function isEmpty(s){
   var i;
    if ((s == null) || (s.length == 0)) return true;

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (strSpace.indexOf(c) == -1) return false;
    }
    return true;
}

function isLetterOrDigit (c){
   return (isLetter(c) || isDigit(c));
}

function isDigit (c){
   return ((c >= "0") && (c <= "9"));
}

function isLetter (c){
   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) );
}

function isInt( str ){
	var s = "0123456789";
	var i = new Number(str);

	if ( i < 0 ){
		return false;
	}
	if( str == "" || str == null ){
		return false;
	}
	if( str == "-" ){
		return false;
	}
	if( s.indexOf( str.charAt(0) ) == -1 ){		
		return false;
	}
	for( r = 0; r<str.length; r++ ){
		if( s.indexOf( str.charAt(r) ) == -1 ){		
			return false;
		}
	}
	return true;
}

function CheckQty(obj){
	if (!isInt(obj.value) || obj.value <= 0){
		alert('Please enter a whole number that is bigger then 0.');
		obj.value = 1;
		obj.focus();
		obj.select();
	}	
}

