function submitEnable()
{
	document.getElementById("submit").disabled=false;
}


function isEmail (s)
{     
    // is s whitespace?
    // if (ContainsWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) 
    {
	return false;
	submitEnable();
    }
    else return true;
}

function Form_Validator(theForm)
{
if (theForm.Surname.value=="")  { alert("Please enter your surname"); theForm.Surname.focus(); submitEnable(); return (false);  }
  if  (theForm.Email.value=="" || (!isEmail(theForm.Email.value)) )
  {
    alert("Please enter a valid email address");
    theForm.Email.focus();
    submitEnable();
    return (false);
  } 
  if (theForm.DaytimePhone.value=="") { alert("Please enter your daytime phone number"); theForm.DaytimePhone.focus(); submitEnable(); return (false);  }
  if (!ifInteger(theForm.DaytimePhone.value)) { alert("Please enter correct daytime phone number"); theForm.DaytimePhone.focus(); submitEnable(); return (false);  }
  if (theForm.BranchID.value == 0) {alert("Please select your nearest branch"); return false;}
    return (true);
}

function ifInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9")) && (c != " ")) return false;
    }
    // All characters are numbers.
    return true;
}




