




    // -------------------------------------------------------------------
    // Madgex Limited
    // Copyright (c) 2007 Madgex Limited. All Rights Reserved.
    // Unobtrusive form validation v1.0 
    // Glenn Jones
    // 27 June 2007
    // -------------------------------------------------------------------
	
	var vmComfirmEmail = {
		
		name:'vmComfirmEmail',
		version: '0.1',
		Errors: [],

		config: {
			"findClass": '',
			"ErrorTxt": 'The email addresses you have entered to not match.'
		},

		Reset: function(){
			for (var x = 0; x < this.Errors.length; x++){
				FormValidator.RemoveError( this.Errors[x], this );
			}
			this.Errors.length = 0;
		},
		
		Validate: function( formNode ){
		   
		    if( document.getElementById( "emailaddress" ) ){
		    	var elt1 =document.getElementById( "emailaddress" );
			    var elt2 = document.getElementById( "confirmemailaddress" );
		        addEvent(elt1, 'blur', FormValidator.modules[this.ModuleIndex].ValidateItem, false);
			    addEvent(elt2, 'blur', FormValidator.modules[this.ModuleIndex].ValidateItem, false);
			}
			
			return this.ValidateItem();
		},

		ValidateItem: function(  ){
		    var isValid = true;
			var elt1, elt2, email, emailconfirm, elem;
			
			if( document.getElementById( "emailaddress" ) ){
			    
			    elt1 =document.getElementById( "emailaddress" );
			    elt2 = document.getElementById( "confirmemailaddress" );
			    email = elt1.value.trim();
			    emailconfirm = elt2.value.trim();
			    
			    if( email != "" && emailconfirm != "" ){
			        if( email != emailconfirm ){
			            isValid = false;
			        }
			    }
			    if( isValid == false )
			        FormValidator.AddError( elt2, vmComfirmEmail);
			    else
			        FormValidator.RemoveError( elt2, vmComfirmEmail);
			}
			
			return isValid;
		}	
		
	};
	
	// go register with the FormValidator
	vmComfirmEmail.ModuleIndex = FormValidator.Register( vmComfirmEmail );
	
	
	
	
	var vmConfirmPassword = {
		
		name:'vmConfirmPassword',
		version: '0.1',
		Errors: [],

		config: {
			"findClass": '',
			"ErrorTxt": 'The passwords you have entered do not match.'
		},

		Reset: function(){
			for (var x = 0; x < this.Errors.length; x++){
				FormValidator.RemoveError( this.Errors[x], this );
			}
			this.Errors.length = 0;
		},
		
		Validate: function( formNode ){
		   
		    if( document.getElementById( "password" ) ){
		    	var elt1 =document.getElementById( "password" );
			    var elt2 = document.getElementById( "confirm" );
		        addEvent(elt1, 'blur', FormValidator.modules[this.ModuleIndex].ValidateItem, false);
			    addEvent(elt2, 'blur', FormValidator.modules[this.ModuleIndex].ValidateItem, false);
			}
			return this.ValidateItem();
			//return true;
		},

		ValidateItem: function(  ){
		    var isValid = true;
			var elt1, elt2, password, passwordconfirm, elem;
		
			if( document.getElementById( "password" ) ){
			
			    elt1 = document.getElementById( "password" );
			    elt2 = document.getElementById( "confirm" );
			    password = elt1.value.trim();
			    passwordconfirm = elt2.value.trim();
			    
			    if( password != "" && passwordconfirm != "" ){
			        if( password != passwordconfirm ){
			            isValid = false;
			        }
			    }
			    
			    if( isValid == false )
			        FormValidator.AddError( elt2, vmConfirmPassword);
			    else
			        FormValidator.RemoveError( elt2, vmConfirmPassword);
			}
		   
			return isValid;
		}	
		
	};
	

	// go register with the FormValidator
    vmConfirmPassword.ModuleIndex = FormValidator.Register( vmConfirmPassword );
    
    
    
    
    var vmUKSelected = {
		
		name:'vmUKSelected',
		version: '0.1',
		Errors: [],

		config: {
			"findClass": '',
			"ErrorTxt": 'If you select the United Kingdom as your country you must enter a county.'
		},

		Reset: function(){
			for (var x = 0; x < this.Errors.length; x++){
				FormValidator.RemoveError( this.Errors[x], this );
			}
			this.Errors.length = 0;
		},
		
		Validate: function( formNode ){
		   
		    if( document.getElementById( "country" ) ){
		   	    elt1 = document.getElementById( "country" );
			    elt2 = document.getElementById( "county" );
		        addEvent(elt1, 'blur', FormValidator.modules[this.ModuleIndex].ValidateItem, false);
			    addEvent(elt2, 'blur', FormValidator.modules[this.ModuleIndex].ValidateItem, false);
			}
			return this.ValidateItem();
		},

		ValidateItem: function(  ){
		    var isValid = true;
			var elt1, elt2, password, passwordconfirm, elem;
		
			if( document.getElementById( "country" ) ){

			    elt1 = document.getElementById( "country" );
			    elt2 = document.getElementById( "county" );
			    
			    country = elt1.options[elt1.selectedIndex].value;
			    county = elt2.value.trim();
			    
			    if( country == "GB" && county == "" ){
			        isValid = false;
			    }
			    
			    if( isValid == false )
			        FormValidator.AddError( elt2, vmUKSelected);
			    else
			        FormValidator.RemoveError( elt2, vmUKSelected);
			}
		   
			return isValid;
		}	
		
	};
	

	// go register with the FormValidator
    vmUKSelected.ModuleIndex = FormValidator.Register( vmUKSelected );
    
   
   
   
    var vmUKNeedsPostCode = {
		
		name:'vmUKNeedsPostCode',
		version: '0.1',
		Errors: [],

		config: {
			"findClass": '',
			"ErrorTxt": 'If you select the United Kingdom as your country you must enter a postcode.'
		},

		Reset: function(){
			for (var x = 0; x < this.Errors.length; x++){
				FormValidator.RemoveError( this.Errors[x], this );
			}
			this.Errors.length = 0;
		},
		
		Validate: function( formNode ){
		   
		    if( document.getElementById( "country" ) ){
		   	    elt1 = document.getElementById( "country" );
			    elt2 = document.getElementById( "postcode" );
		        addEvent(elt1, 'blur', FormValidator.modules[this.ModuleIndex].ValidateItem, false);
			    addEvent(elt2, 'blur', FormValidator.modules[this.ModuleIndex].ValidateItem, false);
			}
			return this.ValidateItem();
		},

		ValidateItem: function(  ){
		    var isValid = true;
			var elt1, elt2, password, passwordconfirm, elem;
		
			if( document.getElementById( "country" ) ){

			    elt1 = document.getElementById( "country" );
			    elt2 = document.getElementById( "postcode" );
			    
			    var country = elt1.options[elt1.selectedIndex].value;
			    var postcode = elt2.value.trim();
			    
			    if( country == "GB" && postcode == "" ){
			        isValid = false;
			    }
			    
			    if( isValid == false )
			        FormValidator.AddError( elt2, vmUKNeedsPostCode);
			    else
			        FormValidator.RemoveError( elt2, vmUKNeedsPostCode);
			}
		   
			return isValid;
		}	
		
	};
	

	// go register with the FormValidator
    vmUKNeedsPostCode.ModuleIndex = FormValidator.Register( vmUKNeedsPostCode );
    
   
   
      
   
   

    var vmECRegNoOnlyIfInEC = {
		
		name:'vmECRegNoOnlyIfInEC',
		version: '0.1',
		Errors: [],

		config: {
			"findClass": '',
			"ErrorTxt": 'You can only enter an EC VAT No. if you are located in the EC.'
		},

		Reset: function(){
			for (var x = 0; x < this.Errors.length; x++){
				FormValidator.RemoveError( this.Errors[x], this );
			}
			this.Errors.length = 0;
		},
		
		Validate: function( formNode ){
		   
		    if( document.getElementById( "country" ) ){
		   	    var country = document.getElementById( "country" );
			    var regno = document.getElementById( "ecregistrationnumber" );
		        addEvent(country, 'blur', FormValidator.modules[this.ModuleIndex].ValidateItem, false);
			    addEvent(regno, 'blur', FormValidator.modules[this.ModuleIndex].ValidateItem, false);
			}
			return this.ValidateItem();
		},

		ValidateItem: function(  ){
		    var isValid = true;
		
			if( country = document.getElementById( "country" ) ){

			    var regno = document.getElementById( "ecregistrationnumber" );
			    var currcountry = country.options[elt1.selectedIndex].value;
			    var ECCountries = "AT,BE,CY,CZ,DK,EE,FI,FR,DE,GR,HU,IE,IT,LV,LT,LU,MT,NL,PL,PT,SK,SI,ES,SE,GB";
			    
			    if( (ECCountries.indexOf(currcountry) == "-1") && regno.value.trim() != "" ){
			        isValid = false;
			    }
			    
			    if( isValid == false )
			        FormValidator.AddError( regno, vmECRegNoOnlyIfInEC);
			    else
			        FormValidator.RemoveError( regno, vmECRegNoOnlyIfInEC);
			}
		   
			return isValid;
		}	
		
	};
	

	// go register with the FormValidator
    vmECRegNoOnlyIfInEC.ModuleIndex = FormValidator.Register( vmECRegNoOnlyIfInEC );
    
   
   
      
   
   

