/**
 * @author Z120U
 */

function trim(s)
{
    var l=0; var r=s.length -1;
    while(l < s.length && s[l] == ' ')
    {     l++; }
    while(r > l && s[r] == ' ')
    {     r-=1;     }
    return s.substring(l, r+1);
} 

 function checkSeach() {
 	searchbox 	= document.getElementById('searchbox').value;
	sports		= document.getElementById('sports').value;
	output 		= '';
	if(trim(searchbox)=="") output += 'Please enter a POST CODE';
	
	
	if (trim(sports) == "") {
		if(output=="") output += "Please choose "; else output += ", and ";
		output += 'a SPORT';
	}
	
	if (output != "") {
		document.getElementById('errormsg').style.visibility = 'visible';
		document.getElementById('errormsg').innerHTML = output;
		return false;
	}
	
 }

 // calculate the ASCII code of the given character
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function checkNumber(val) {
  var strPass = document.getElementById(val).value;
  var strLength = strPass.length;
  var lchar = document.getElementById(val).value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);
//  alert(cCode);

  /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */

  if ((cCode < 48 || cCode > 57) && (cCode != 46)) {
    var myNumber = document.getElementById(val).value.substring(0, (strLength) - 1);
    document.getElementById(val).value = myNumber;
  }
  return false;
}


function IsNumeric(sText,isDec){
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	var strValue = document.getElementById(sText).value;
	
	for (i = 0; i < strValue.length && IsNumber == true; i++) { 
		Char = strValue.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}

