function notEmpty(input, name){
	//take care of select form objects
	var inputFocus = input;
	
	if(input.type == "select-one")
		 input = input.options[input.selectedIndex];
	
	//check if empty
	if(input.value == "" || input.value == null) {
		alert( name + " must contain a value.");
		inputFocus.focus();
		return false;
	}
	return true;
}

function isEmpty(input){
	//take care of select form objects
	var inputFocus = input;
	
	if(input.type == "select-one")
		 input = input.options[input.selectedIndex];
	
	//check if empty
	if(input.value == "" || input.value == null) {
		//alert( input.value + " must contain a value.");
		//inputFocus.focus();
		return true;
	}
	return false;
}

function checkDate(date, name){
	if(date.value != null && date.value != ""){

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var matchArray = date.value.match(datePat);
	
	if(matchArray == null){
			alert("All Date fields should be in the form: ##/##/####");
			return false;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
	alert("Month must be between 1 and 12.");
	return false;
	}
	if (day < 1 || day > 31) {
	alert("Day must be between 1 and 31.");
	return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
	alert("Month "+month+" doesn't have 31 days!")
	return false;
	}
	if (month == 2) { // check for february 29th
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	if (day>29 || (day==29 && !isleap)) {
	alert("February " + year + " doesn't have " + day + " days!");
	return false;
    }}
	}
	else{
		//alert( name + " must contain a value.");
		//date.focus();
		//return false;
	
	}
	return true;  // date is valid
}

function checkDataPA(form){
	if(notEmpty(form.firstname, "First Name")){ 
	if(notEmpty(form.lastname, "Last Name")){ 
	if(notEmpty(form.emailAddress, "Email")){ 
	if(notEmpty(form.address1, "Address")){ 
	if(notEmpty(form.city, "City")){ 
	if(form.modelType1.value == "" && form.modelType2.value == "" && form.modelType3.value == "" && form.modelType4.value == "" && form.modelTypeOther.value == ""){
		alert("Please fill a Model Type.");
		form.modelType1.focus();
		return false; 
	}else{
	
		//alert("countryCheck-country="+form.country.options[form.country.selectedIndex].value+"state="+form.state.options[form.state.selectedIndex].value+ "postalcode="+form.postal_code.value);
		if(form.country.options[form.country.selectedIndex].value == "United States" && (form.state.options[form.state.selectedIndex].value == "" || form.postal_code.value == "" )  ) {
			alert("Please fill in zipcode AND state.");
			form.state.focus();
			return false; 
		}else{
			
			if (checkDate(form.birthDate)){
				if (form.dealerType.selectedIndex != 0){
					//alert("form.dealerName.value="+form.dealerName.value);
					if(form.dealerName.value == ""){
						alert("You have chosen a dealer type. Please choose a dealer name.");
						return false;
					}else{
					
						return true;
					
					}
				}
				
					return true;
				
			}else{
				return false;
			
			}
		
		}
		//return true;
	
	}//if(form.modelType1 = ""){
	}//if(notEmpty(form.address1, "Address")){ 
	}//if(notEmpty(form.city, "City")){ 
	}//if(notEmpty(form.emailAddress, "Email")){ 
	}//if(notEmpty(form.lastname, "Last Name"))
	}//if(notEmpty(form.firstname, "First Name"))
	return false;
	
	
	


}

function checkProductData(form){
	if(isEmpty(form.wired_mics2) && isEmpty(form.earphones_mobile2) && isEmpty(form.wireless_mics2) && isEmpty(form.psm) && isEmpty(form.phono) && isEmpty(form.mixers_dsp) && isEmpty(form.conference)){ 
		alert("Please select a product to register.  For Wired Mics, Wireless Mics, and Earphones/Mobile Headsets you must select a product line, then an model number.");
		return false;
	}
	return true;
}


function checkData(form){
	if(form.unsubscribe_all.checked){
		if(notEmpty(form.emailAddress, "Email")){ 
			if(form.emailAddress.value != form.emailAddressconfirm.value){
				alert("Email Address and Email Address Confirmation do not match.");
				form.emailAddress.focus();
				return false; 
			
			}
			
			else {
				return true;
			}
		
		
		}
		
	}else{
	
	//if(notEmpty(form.firstname, "First Name")){ 
	//if(notEmpty(form.lastname, "Last Name")){ 
	if(notEmpty(form.emailAddress, "Email")){ 
	//if (checkDate(form.modelDate, "Date Purchased")){
	if (checkDate(form.birthDate, "Date of Birth")){

	//alert("countryCheck-country="+form.country.options[form.country.selectedIndex].value+"state="+form.state.options[form.state.selectedIndex].value+ "postalcode="+form.postal_code.value);
		if(form.country.options[form.country.selectedIndex].value == "United States" && (form.postal_code.value == "" )  ) {
			alert("Please fill in zipcode.");
			form.postal_code.focus();
			return false; 
		}else{
			
			if(form.emailAddress.value != form.emailAddressconfirm.value){
				alert("Email Address and Email Address Confirmation do not match.");
				form.emailAddress.focus();
				return false; 
			
			}
			
		else {
		
		
			return true;
			}
		}
		//return true;

	}//if (checkDate(form.birthDate)){
	//}//if (checkDate(form.modelDate)){
	}//if(notEmpty(form.emailAddress, "Email")){ 
	//}//if(notEmpty(form.lastname, "Last Name"))
	//}//if(notEmpty(form.firstname, "First Name"))
	return false;
	}//end if(form.unsubscribe_all.checked){
}//function checkData

function unCheck(form){
		if (form.unsubscribe_all.checked){
			form.unsubscribe_notes_newbies.checked = false;
			form.unsubscribe_notes_how.checked = false;
			form.unsubscribe_news.checked = false;
			form.unsubscribe_otws.checked = false;
			form.unsubscribe_promo.checked = false;
			form.unsubscribe_product.checked = false;
			form.unsubscribe_events.checked = false;
			
		}
			
}

