// JavaScript Document

	var browserType;
	
	if (document.layers) {browserType = "nn4"}
	if (document.all) {browserType = "ie"}
	if (window.navigator.userAgent.toLowerCase().match("gecko")) {
	 browserType= "gecko"
	}

/* Disables view of address fields */	
	function hideDiv(divId) {
	  if (browserType == "gecko" )
		 document.poppedLayer = 
			 eval('document.getElementById(divId)');
	  else if (browserType == "ie")
		 document.poppedLayer = 
			eval('document.getElementById(divId)');
	  else
		 document.poppedLayer =   
			eval('document.layers[divId]');
	  document.poppedLayer.style.display = "none";
	}

/* Disables view of address fields */	
	function hideTab(divId) {
	  if (browserType == "gecko" )
		 document.poppedLayer = 
			 eval('document.getElementById(divId)');
	  else if (browserType == "ie")
		 document.poppedLayer = 
			eval('document.getElementById(divId)');
	  else
		 document.poppedLayer =   
			eval('document.layers[divId]');
	  document.poppedLayer.style.visibility = "hidden";
	}
	
/* Enables view of address book */	
	function showDiv(divId) {
	  if (browserType == "gecko" )
		 document.poppedLayer = 
			 eval('document.getElementById(divId)');
	  else if (browserType == "ie")
		 document.poppedLayer = 
			eval('document.getElementById(divId)');
	  else
		 document.poppedLayer = 
			 eval('document.layers[divId]');
	  document.poppedLayer.style.display = "inline";
	}
/* Enables view of tables */	
	function showTab(divId) {
	  if (browserType == "gecko" )
		 document.poppedLayer = 
			 eval('document.getElementById(divId)');
	  else if (browserType == "ie")
		 document.poppedLayer = 
			eval('document.getElementById(divId)');
	  else
		 document.poppedLayer = 
			 eval('document.layers[divId]');
	  document.poppedLayer.style.visibility = "visible";
	}

/* Disables validation of address fields */	
	function disableValidate() {
		add1.disable();
		zip.disable();
		city.disable();
	}
/* Enables validation of address fields */	
	function enableValidate() {
		add1.enable();
		zip.enable();
		city.enable();
	}
/* Enables validation of contact fields */	
	function enableValidateContact() {
		contact_name.enable();
		email_address.enable();
		phone_number.enable();
	}
	
/* Disables validation of contact fields */	
	function disableValidateContact() {
		contact_name.disable();
		email_address.disable();
		phone_number.disable();
	}

/* Shop address fields */
	function validate_form() {
		var add1 = new LiveValidation( 'add1', {onlyOnSubmit: false } );
		add1.add( Validate.Presence, { failureMessage: "Please enter a valid shipping address!" } );
		var zip = new LiveValidation( 'zip', {onlyOnSubmit: true } );
		zip.add( Validate.Presence, {failureMessage: "Please enter a valid zip code!" } );
		zip.add( Validate.Length, {minimum: 4, maximum: 7} );
		zip.add( Validate.Numericality, { onlyInteger: true } );
		var city = new LiveValidation( 'city', {onlyOnSubmit: true } );
		city.add( Validate.Presence, { failureMessage: "Please enter a valid city!" } );
		
		var automaticOnSubmit = add1.form.onsubmit;
		
		add1.form.onsubmit = function(){
				
			var valid = automaticOnSubmit();
			if(valid)
				return false;
		return false;
		
		}
	}

/* Shop address fields */
	function validate_address() {
		var contact_name = new LiveValidation( 'contact_name', {onlyOnSubmit: true } );
		contact_name.add( Validate.Presence, { failureMessage: "Please enter a valid contact name!" }  );
		var email_address = new LiveValidation( 'email_address', {onlyOnSubmit: true } );
		email_address.add( Validate.Presence, { failureMessage: "Please enter a valid contact email!" } );
		email_address.add( Validate.Email, { failureMessage: "Please enter a valid contact email!" } );
		var confirm_email = new LiveValidation( 'confirm_email', {onlyOnSubmit: true } );
		confirm_email.add( Validate.Presence, { failureMessage: "Please enter a valid contact email!" } );
		confirm_email.add( Validate.Confirmation, { match: 'confirm_email' } );
		var phone_number = new LiveValidation( 'phone_number', {onlyOnSubmit: true } );
		phone_number.add( Validate.Presence, { failureMessage: "Please enter a valid contact phone number!" } );
		phone_number.add( Validate.Numericality, {onlyInteger: true, failureMessage: "Please enter only numbers!" }  );
		phone_number.add( Validate.Length, {minimum: 8, maximum: 14} );
		phone_number.add( Validate.Exclusion, { within: [ '00000000' , '11111111', '33333333', '44444444', '55555555', '66666666', '77777777', '88888888', '99999999', '12345678' ], failureMessage: "Please enter a valid contact phone number!" } );
		var add1 = new LiveValidation( 'add1', {onlyOnSubmit: true } );
		add1.add( Validate.Presence, { failureMessage: "Please enter a valid shipping address!" } );
		var zip = new LiveValidation( 'zip', {onlyOnSubmit: true } );
		zip.add( Validate.Presence, {failureMessage: "Please enter a valid zip code!" } );
		zip.add( Validate.Length, {minimum: 4, maximum: 7} );
		zip.add( Validate.Numericality, { onlyInteger: true } );
		
		var automaticOnSubmit = add1.form.onsubmit;
		add1.form.onsubmit = function(){
			var valid = automaticOnSubmit();
			if(valid) 
				return true;
		return false;
		}
	}
