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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function validateCompetition()
{
	with (window.document.competitionform) {
		if (competitionEmail.value.length == 0) {
			competitionEmail.focus();
			alert("Please enter a valid email address in the space provided.");
			return false;
		}
		if (competitionEmail.value.length != 0){
		  if (validateEmail(competitionEmail) == false){
			return false;}
		}
		submit();
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

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);
}