var telNumberErrorNo = 0;
telNumberErrors = new Array (0);
telNumberErrors[0] = "Valid UK telephone number.";
telNumberErrors[1] = "Please enter your telephone number in the space provided.";
telNumberErrors[2] = "Please eneter a UK telephone number without the country code.";
telNumberErrors[3] = "UK telephone numbers should contain 10 or 11 digits.";
telNumberErrors[4] = "The telephone number should start with a 0.";
telNumberErrors[5] = "The telephone number is either invalid or inappropriate.";

function validateEmail(thisEmailField) {
  if(-1 == thisEmailField.value.indexOf("@")) { 
     alert("Your email address must have a '@'."); 
     return false; 
  }
  if(-1 == thisEmailField.value.indexOf(".")) { 
     alert("Your email address must have a '.'."); 
     return false; 
  }
  if(-1 != thisEmailField.value.indexOf(",")) { 
     alert("Your email address must not have a ',' in it"); 
     return false; 
  }
  if(-1 != thisEmailField.value.indexOf("#")) { 
     alert("Your email address must not have an '#' in it." ); 
     return false; 
  }
  if(-1 != thisEmailField.value.indexOf("!")) { 
     alert("Your email address must not have a '!' in it." ); 
     return false; 
  }
  if(-1 != thisEmailField.value.indexOf(" ")) { 
     alert("Your email address must not have a space in it." ); 
     return false; 
  }
  if(thisEmailField.value.length == (thisEmailField.value.indexOf("@")+1) ) {
     alert("Your email address must have a domain name after the '@'.");
     return false;
  }
  return true;
}

function checkUKTelephone(telephoneNumber) {
  var telNum;
  // Convert into a string and check that we were provided with a number
  telNum = telephoneNumber + " ";
  if (telNum.length == 1)  {
     telNumberErrorNo = 1;
     return false
  }
  telNum.length = telNum.length - 1;
  
  // Don't allow country codes to be included (assumes a leading "+")
  exp = /^(\+)[\s]*(.*)$/;
  if (exp.test(telNum) == true) {
     telNumberErrorNo = 2;
     return false;
  }
  
  // Remove spaces from the telephone number to help validation
  while (telNum.indexOf(" ")!= -1)  {
    telNum = telNum.slice (0,telNum.indexOf(" ")) + telNum.slice (telNum.indexOf(" ")+1)
  }
  
  // Remove hyphens from the telephone number to help validation
  while (telNum.indexOf("-")!= -1)  {
    telNum = telNum.slice (0,telNum.indexOf("-")) + telNum.slice (telNum.indexOf("-")+1)
  }  
  
  // Now check that all the characters are digits
  exp = /^[0-9]{10,11}$/
  if (exp.test(telNum) != true) {
     telNumberErrorNo = 3;
     return false;
  }
  
  // Now check that the first digit is 0
  exp = /^0[0-9]{9,10}$/
  if (exp.test(telNum) != true) {
     telNumberErrorNo = 4;
     return false;
  }
  
  // Now check that the telephone number is appropriate.
  exp = /^(01|02|05|070|077|078|079)[0-9]+$/;
  if (exp.test(telNum) != true) {
     telNumberErrorNo = 5;
     return false;
  }
  
  // Seems to be valid - return the stripped telephone number
  
  return telNum;
}

function validateTelNumber(thisTelField) {
  var telNum = thisTelField.value;
  // If invalid number, report back error
  if (!checkUKTelephone(telNum)) {
     alert(telNumberErrors[telNumberErrorNo]);
	 return false;
  }
}

function validateCCNum(intCCNum) {
     return true; 
}

function uncheckRadioGroup(radGroup) {
	intRecords = radGroup.length;
	if (intRecords == undefined) intRecords = 1;		
	if (intRecords == 1) {
		radGroup.checked = false
	}
	else
	{
		for (intCounter = 0; intCounter < intRecords; intCounter++) {
			radGroup[intCounter].checked = false
		}
	}
}

function launchCenter(url, name, height, width) {
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
  return window.open(url, name, str);
}