function valid_email(email) {
	
	   at = email.indexOf("@");
	   dot = email.lastIndexOf(".");
	
	   if((at >= 1) && (dot > at)) {
	   	return(true);
	   } else {
	   	return(false);
	   }
	}
	
	function form_get(form) {
   valid = 1;

   	if((valid) && (!valid_email(form.email.value))) {
         valid = 0;
         alert('Please enter a valid email address.');
         form.email.focus();
      }

      if(valid) {
			form.cmd.value = "getdetails";
         form.submit();
      }
	}
	
	function form_sub(form) {
   valid = 1;

      if((valid) && (form.title.value == '')) {
         valid = 0;
         alert("Please select your title.");
         form.title.focus();
      }

      if((valid) && (form.name.value == '')) {
         valid = 0;
         alert("Please enter your name.");
         form.name.focus();
      }

      if((valid) && (form.position.value == '')) {
         valid = 0;
         alert("Please enter your position.");
         form.position.focus();
      }

      if((valid) && (form.company.value == '')) {
         valid = 0;
         alert("Please enter your company name.");
         form.company.focus();
      }

      if((valid) && (form.address1.value == '')) {
         valid = 0;
         alert("Please enter the first line of your address.");
         form.address1.focus();
      }

      if((valid) && (form.town.value == '')) {
         valid = 0;
         alert("Please enter your town/city.");
         form.town.focus();
      }

      if((valid) && (form.postcode.value == '')) {
         valid = 0;
         alert("Please enter your postcode.");
         form.postcode.focus();
      }

      if((valid) && (form.country.value == '')) {
         valid = 0;
         alert("Please enter your county.");
         form.country.focus();
      }

   	if((valid) && (!valid_email(form.email.value))) {
         valid = 0;
         alert('Please enter a valid email address.');
         form.email.focus();
      }
      
      /*if((valid) && (form.distributor.checked || form.distributor2.checked || form.installer.checked || form.local.checked || form.special.checked || form.other.checked)) {
		} else if (valid){
			valid = 0;
			alert('Please select your company type.');
		}*/
      
      if((valid) && (form.byemail.checked || form.bypost.checked)) {
		} else if (valid){
			valid = 0;
			alert('Please select how you would prefer to receive our mailings.');
		}

      if(valid) {
			form.action = 'mailing_submit.php';
			form.cmd.value = "sub";
         form.submit();
      }
	}
	
	function form_unsub(form) {
   valid = 1;

   	if((valid) && (!valid_email(form.email.value))) {
         valid = 0;
         alert('Please enter a valid email address.');
         form.email.focus();
      }

      if(valid) {
      	if (confirm('Are you sure you wish to unsubscribe from the Videx mailing list?\nBy doing so you will no longer receive exclusive offers and information!')){
   			form.action = 'mailing_submit.php';
				form.cmd.value = "unsub";
	         form.submit();
	      }	
      }
	}
