

function contactvalidate()

   {
	name=document.add_comp.fname.value.length
	cname=document.add_comp.fcname.value.length
	add1=document.add_comp.fadd1.value.length
 test = document.add_comp.fpcode.value; size = test.length
 test = test.toUpperCase(); //Change to uppercase	
	tel=document.add_comp.ftel.value.length
	cemail=document.add_comp.femail.value.length
	pass=document.add_comp.fpass.value.length
	cpass=document.add_comp.cfpass.value.length
	
 	if (name == 0)
		{
		alert("Please enter a Company name!")
		document.add_comp.fname.focus()
		return false
		} 	

 	if (cname == 0)
		{
		alert("Please enter a Contact name!")
		document.add_comp.fcname.focus()
		return false
		} 	

 	if (add1 == 0)
		{
		alert("Please enter an Address!")
		document.add_comp.fadd1.focus()
		return false
		} 
		
//###################################################################################################


 while (test.slice(0,1) == " ") //Strip leading spaces
  {test = test.substr(1,size-1);size = test.length
  }

 while(test.slice(size-1,size)== " ") //Strip trailing spaces
  {test = test.substr(0,size-1);size = test.length
  }

 if (size < 6 || size > 8){ //Code length rule
  alert(test + " is not a valid postcode")
  document.add_comp.fpcode.focus()
  return false
  }

 if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
   alert(test + " is not a valid postcode - cannot start with a number")
   document.add_comp.fpcode.focus()
   return false
  }

 if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule
   alert(test + " is not a valid postcode - alpha character in wrong position")
   document.add_comp.fpcode.focus()
   return false
  }

 if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position")
   document.add_comp.fpcode.focus()
   return false
  }

 if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position")
   document.add_comp.fpcode.focus()
   return false
  }

 if (!(test.charAt(0) == "K")){//space in position length-3 rule
   alert(test + " is not a valid ayrshire postcode")
   document.add_comp.fpcode.focus()
   return false
   }

 if (!(test.charAt(1) == "A")){//space in position length-3 rule
   alert(test + " is not a valid postcode - must be KA")
   document.add_comp.fpcode.focus()
   return false
   }   

 count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ")
 if (count1 != count2){//only one space rule
   alert(test + " is not a valid postcode - only one space allowed")
   document.add_comp.fpcode.focus()
   return false
  }
//###################################################################################################
		

 	if (tel == 0)
		{
		alert("Please enter a Telephone number!")
		document.add_comp.ftel.focus()
		return false
		} 	

 	if (cemail == 0)
		{
		alert("Please enter an email address!")
		document.add_comp.femail.focus()
		return false
		} 	

 	if (pass == 0)
		{
		alert("Please enter a password!")
		document.add_comp.fpass.focus()
		return false
		} 	

 	if (cpass == 0)
		{
		alert("Please confirm password!")
		document.add_comp.cfpass.focus()
		return false
		} 	


   }