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 checkSerial(input){
	
	//check if exists
	if(input){
		
		if(input.value.length == 0){
			alert("Please enter a serial number.");
			//alert("The serial number must be 10 characters in length.");
			input.focus();
			return false;
		}else{
	
			return true;
		}	
	}else{
		return true;
	}
}

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, cartEmpty){
	
	if (form.other.value == "Example: UA844SWB"){
			form.other.value = "";
	}
	
	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) && isEmpty(form.other) && isEmpty(form.accessories2) && isEmpty(form.headphones)) &&  (cartEmpty == 1 || form.register_another_hidden.value == 1))
{ 
		alert("Please select a product to register.  For Wired Mics, Wireless Mics, Earphones/Mobile Headsets, and Accessories, you must select a product line, then a model number.");
		return false;
	}
	else
	{
		var notEmptyCount = 0;
		if(!isEmpty(form.wired_mics2)){
				notEmptyCount ++;
		}
		if(!isEmpty(form.earphones_mobile2)){
				notEmptyCount ++;
		}
		if(!isEmpty(form.wireless_mics2)){
				notEmptyCount ++;
		}
		if(!isEmpty(form.psm)){
				notEmptyCount ++;
		}
		if(!isEmpty(form.phono)){
				notEmptyCount ++;
		}
		if(!isEmpty(form.mixers_dsp)){
				notEmptyCount ++;
		}
		if(!isEmpty(form.conference)){
				notEmptyCount ++;
		}
		if(!isEmpty(form.accessories2)){
				notEmptyCount ++;
		}
		if(!isEmpty(form.other)){
				notEmptyCount ++;
		}
		if(!isEmpty(form.headphones)){
				notEmptyCount ++;
		}
		
		
		if(notEmptyCount > 1){
			alert("Only 1 product can be added at a time.")
			return false;	
		}
		else if((form.wired_mics2.options[form.wired_mics2.selectedIndex].value == "SM57" || form.wired_mics2.options[form.wired_mics2.selectedIndex].value == "SM58") && form.wiredSerial.value.length == 0){
			alert("Please enter a serial number.");
			form.wiredSerial.focus();
			return false;
			
			
		}else if((form.earphones_mobile.options[form.earphones_mobile.selectedIndex].value == "Earphone") && (form.earphones_mobile2.options[form.earphones_mobile2.selectedIndex].value != "") && form.earphoneSerial.value.length == 0){
			alert("Please enter a serial number.");
			form.earphoneSerial.focus();
			return false;
			
			
		}else if((form.wireless_mics2.options[form.wireless_mics2.selectedIndex].value != "") && form.wirelessSerial.value.length == 0){
			alert("Please enter a serial number.");
			form.wirelessSerial.focus();
			return false;
			
			
		}
	return true;
	}
}


function checkData(form){
//alert('register_another_hidden='+document.getElementById('register_another_hidden').value);
	
	//if(form.register_another_hidden.value == "1")
	//{
			//form.register_another_hidden.value = "1";

		//	return checkSerial(form.modelSerial);
			

		
	//}else{

	//if(checkSerial(form.modelSerial)){
	if(notEmpty(form.firstname, "First Name")){ 
	if(notEmpty(form.lastname, "Last Name")){ 
	//if(notEmpty(form.country, "Country")){ 
	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 {
			if ((form.unsubscribe_events.checked == false) && (form.unsubscribe_notes_newbies.checked == false) && (form.unsubscribe_notes_how.checked == false) && (form.unsubscribe_news.checked == false) && (form.unsubscribe_promo.checked == false) && (form.unsubscribe_product_microphones.checked == false) && (form.unsubscribe_product_wireless.checked == false) && (form.unsubscribe_product_psm.checked == false) && (form.unsubscribe_product_headphones.checked == false) && (form.unsubscribe_product_earphones.checked == false)  && (form.unsubscribe_all.checked == false)){
				
				
				var return_confirm = true;
				
				if(form.show_stayintouch_hidden.value != 1){
						//alert("stayintouchpopup");
						form.show_stayintouch_hidden.value = 1;
						aWindow2=window.open("popupStayInTouch.html","StayinTouch","toolbar=no,width=400,height=200,status=no,scrollbars=no,resize=no,menubar=no,top=300,left=300");
					  	aWindow2.focus();
						
						return_confirm = false;
					
				}
				
				//var return_confirm = confirm("Want to receive product announcements, special offers, news and event information from Shure via email?\nIf so, make your selections under Stay in Touch.\nClick CANCEL to to select Shure communications and submit your registration. \nClick OK to register your product. ");
	
			}
			
				
			return return_confirm;
			}
		}
		//return true;

	}//if (checkDate(form.birthDate)){
	}//if (checkDate(form.modelDate)){
	}//if(notEmpty(form.emailAddress, "Email")){ 
	//}//if not empty country
	}//if(notEmpty(form.lastname, "Last Name"))
	}//if(notEmpty(form.firstname, "First Name"))
	//}//if modelNumber != 10
	return false;
	
	//}//if(form.register_another.value == "1")
}//function checkData

function showHideSerial(inputname,selecteditem){
	 wiredSerial = document.getElementById('wired2serial');
	 wirelessSerial = document.getElementById('wirelessserial');
	 earphoneSerial = document.getElementById('earphonesserial');
	
	
	if(inputname == "wired2"){
		if(selecteditem.options[selecteditem.selectedIndex].value == "SM57" || selecteditem.options[selecteditem.selectedIndex].value == "SM58"){
			wiredSerial.style.display = '';	
			//wirelessSerial.style.display = 'none';
			//earphoneSerial.style.display = 'none';
		}else{
			wiredSerial.style.display = 'none';	
			//wirelessSerial.style.display = 'none';
			//earphoneSerial.style.display = 'none';	
		}
		
	}else if(inputname == "wireless"){
		//wiredSerial.style.display = 'none';	
		wirelessSerial.style.display = '';
		//earphoneSerial.style.display = 'none';	
	
	}else if(inputname == "earphones"){
		//alert("earphones=" + selecteditem.options[selecteditem.selectedIndex].value);
		
		if(selecteditem.options[selecteditem.selectedIndex].value == "Earphone"){
			//wiredSerial.style.display = 'none';	
			//wirelessSerial.style.display = 'none';
			earphoneSerial.style.display = '';	
		}else{
			//wiredSerial.style.display = 'none';	
			//wirelessSerial.style.display = 'none';
			earphoneSerial.style.display = 'none';	
			
		}
		
		
	}else{
		//wiredSerial.style.display = 'none';	
		//wirelessSerial.style.display = 'none';
		//earphoneSerial.style.display = 'none';
	}
	
	
	
}


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;
			
		}
			
}


