window.addEvent('domready', function() {


  						
  						$('details2').addEvent('submit', function(e){
  								e.stop();
 
										var error=0;
									  var fname = this.fullname.value;
										var email = this.email.value;
										var contact = this.contact.value;
										
										var myEffects = new Fx.Morph(this.fullname, {duration: 1000, transition: Fx.Transitions.Sine.easeOut});
 										var myEffects3 = new Fx.Morph(this.email, {duration: 1000, transition: Fx.Transitions.Sine.easeOut});
 										var myEffects4 = new Fx.Morph(this.contact, {duration: 1000, transition: Fx.Transitions.Sine.easeOut});
 						
										
										
										
										if(fname==""){

																				myEffects.start('.error');
					
										error = 1;
										} else {
													 							
																		myEffects.start('.normal');
											
										}
										
										
										if(email==""){

																				myEffects3.start('.error');
					
										error = 1;
										} else {
										
													 	if(!validate(email)){
														myEffects3.start('.error');
														$('emailTD').innerHTML = "<span style='color:red;'>Not Valid</span>";
        										error = 1;
														} else {
																	$('emailTD').innerHTML = "&nbsp;";
																	myEffects3.start('.normal'); 
																			 
														}
													 							
																		
											
										}
										
										if(contact==""){

																				myEffects4.start('.error');
					
										error = 1;
										} else {
													 							
																		if(!checkUKTelephone(contact)){
        														myEffects4.start('.error');
        														$('telTD').innerHTML = "<span style='color:red;'>Not Valid</span>";
                										error = 1;
        														} else {
																		$('telTD').innerHTML = "&nbsp;";
        																	myEffects4.start('.normal'); 
        																			 
        														}
											
										}
										
										
										
										
  									
  									if(error==0){	
  									
  									this.submit();
  									
  									}
  										
              });
  
	

});



         


	
	function validate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false) {
      return false;
   } else {
	 return true;
	 }
}



function checkUKTelephone (telephoneNumber) {

  // Convert into a string and check that we were provided with something
  var 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 "+")
  var 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;
  }
	
	// Disallow numbers allocated for dramas.
	 
  // Array holds the regular expressions for the drama telephone numbers
  var tnexp = new Array ();
	tnexp.push (/^(0113|0114|0115|0116|0117|0118|0121|0131|0141|0151|0161)(4960)[0-9]{3}$/);
	tnexp.push (/^02079460[0-9]{3}$/);
	tnexp.push (/^01914980[0-9]{3}$/);
	tnexp.push (/^02890180[0-9]{3}$/);
	tnexp.push (/^02920180[0-9]{3}$/);
	tnexp.push (/^01632960[0-9]{3}$/);
	tnexp.push (/^07700900[0-9]{3}$/);
	tnexp.push (/^08081570[0-9]{3}$/);
	tnexp.push (/^09098790[0-9]{3}$/);
	tnexp.push (/^03069990[0-9]{3}$/);
	
	for (var i=0; i<tnexp.length; i++) {
    if ( tnexp[i].test(telnum) ) {
      telNumberErrorNo = 5;
      return false;
    }
	}
  
  // Finally check that the telephone number is appropriate.
  exp = (/^(01|02|03|05|070|071|072|073|074|075|07624|077|078|079)[0-9]+$/);
	if (exp.test(telnum) != true) {
     telNumberErrorNo = 5;
     return false;
  }
  
  // Telephone number seems to be valid - return the stripped telehone number  
  return telnum;
}
var telNumberErrorNo = 0;
var telNumberErrors = new Array ();
telNumberErrors[0] = "Valid UK telephone number";
telNumberErrors[1] = "Telephone number not provided";
telNumberErrors[2] = "UK telephone number without the country code, please";
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";
