

function isNum(num) {
  if(num == "") {
	return false;
  }
  for (i=0; i<num.length; i++) {
	if(num.charAt(i) < "0" || num.charAt(i) > "9") {
	  return false;
	}
  }
  return true;
}

function validSize(num) {
  if(num.length < 4) {
	return false
  }
  return true
}

function validEmail(email) {
  invalidChars = " /:,;"
  if(email=="") {
	return false;
  }
  for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
	badChar = invalidChars.charAt(i);
	if (email.indexOf(badChar,0) > -1) {
	  return false;
	}
  }
  atPos=email.indexOf("@",1);
  if(atPos == -1) {
	return false;
  }
  if(email.indexOf("@", atPos+1) !=-1) {
	return false;
  }
  periodPos=email.indexOf(".", atPos+1)
  if(periodPos==-1) {
	return false;
  }
  if(periodPos+3>email.length) {
	return false;
  }
  atPos2=email.indexOf("@.",1);
  if(atPos2 != -1) {
	return false;
  }
  return true;
}


function validateUnsubForm()
{
var errors='';

  if(!validEmail(document.Submit.email.value)) {
   	errors+='\n Please enter a valid email address.';
  }	


  if(errors){
	alert('The following error(s) occurred:\n'+errors);
  }else{
  	document.Submit.submit();
  }
}



function validateForm()
{
var errors='';

	if(document.Submit.firstName.value=="") {
				errors+='\n Please enter your firstname.';				
	}
	if(document.Submit.lastName.value=="") {
				errors+='\n Please enter your last name.';				
	}
	
	var strCountry = "";
	if (navigator.appName=="Netscape"){
		CountryChoice = document.Submit.country.selectedIndex
		strCountry = document.Submit.country.options[CountryChoice].value;
		if(strCountry=="") {
			errors+='\n Please select your country.';
  		}
  	}
	else{  
	    strCountry = document.Submit.country.value;
  		if(strCountry=="") {
		    errors+='\n Please select your country.';
  		}
	}

    if (strCountry == "AU"){
        if (navigator.appName=="Netscape"){
		    StateChoice = document.Submit.state.selectedIndex		    
		    if(document.Submit.state.options[StateChoice].value=="") {
			    errors+='\n Please select your state.';
  		    }
  	    }
	    else{  
  		    if(document.Submit.state.value=="") {
		        errors+='\n Please select your state.';
  		    }
	    }
    
    
        if(document.Submit.postCode.value=="") {
				    errors+='\n Please enter your postcode.';				
	    }        
    }

	
	if(!validEmail(document.Submit.email.value)) {
 				errors+='\n Please enter a valid email address.';
   	}
	
	if(!(document.Submit.jetFamily.checked)&&!(document.Submit.jetMail.checked)&&!(document.Submit.jetTxt.checked)){
				errors+='\n Would you like updates via Family JetMail, JetMail or JetTXT.';				
	}
	
	if (document.Submit.jetTxt.checked==true){
	    if(!isNum(document.Submit.countryCode.value)){
	        errors+='\n Your mobile country code(numerical)';				
	    }
	    if(!isNum(document.Submit.mobile.value)){
	        errors+='\n Your mobile number(numerical)';				
	    }
	}
	  
	if(!(document.Submit.confirm.checked)){
				errors+='\n Please read and accept terms and conditions.';				
	}


  if(errors){
	alert('The following error(s) occurred:\n'+errors);
  }else{
  	document.Submit.submit();
  }
}


