function check_mail_form() {
	form = document._ContactPending;
	if(form.name.value == "") {
		alert('You have to insert name!');
		form.name.focus();
		return false;
	}
	if(form.tel.value == "") {
		alert('You have to insert phone number!');
		form.tel.focus();
		return false;
	}
	if(form.email.value == "") {
		alert('You have to insert email!');
		form.email.focus();
		return false;
	}
	if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value)) {
		alert("E-mail address is invalid!\nPlease re-enter!");
		form.email.value = "";
		form.email.focus();
		return false;
	}
	if(form.message.value == "") {
		alert('You have to insert questions/comments!');
		form.message.focus();
		return false;
	}
	return true;
}

function clearMailForm() {
	form = document._ContactPending;
	form.name.value = "";
	form.tel.value = "";
	form.email.value = "";
	form.message.value = "";
}

function popUp(URL, width, height) {
	day = new Date();
	id = day.getTime();
	if(width >= 640) {
		width = 640;
	}
	if(height >= 480) {
		height = 480;
	}
	eval("page" + id + " = window.open('includes/show_image.php?image=../"+URL+"&width="+width+"', '" + id + "', 'toolbar=0, scrollbars=yes, location=0, statusbar=0, menubar=0, resizable=0, width=" + (width+40) + ", height=" + (height+40) + "');");
}

function check_user_form() {
	form = document._WarrantyPending;
	if(form.oFirstName.value == "") {
		alert('You have to insert name!');
		form.oFirstName.focus();
		return false;
	}
	if(form.oLastName.value == "") {
		alert('You have to insert last name!');
		form.oLastName.focus();
		return false;
	}
	if(form.oAddress.value == "") {
		alert('You have to insert address!');
		form.oAddress.focus();
		return false;
	}
	if(form.oCity.value == "") {
		alert('You have to insert City!');
		form.oCity.focus();
		return false;
	}
	if(form.oState.value == "--Select One--") {
		alert('You have to choose State!');
		form.oState.focus();
		return false;
	}
	if(form.oZip.value == "") {
		alert('You have to insert Zip!');
		form.oZip.focus();
		return false;
	}
	if(form.oEmail.value == "") {
		alert('You have to insert email!');
		form.oEmail.focus();
		return false;
	}
	if(form.oHomePhone.value == "") {
		alert('You have to insert Home Phone!');
		form.oHomePhone.focus();
		return false;
	}
	return true;
}

window.addEvent('domready', function(){  
	if($('WarrantyPending')) {
		$('WarrantyPending').addEvent('submit', function(e) {  
			new Event(e).stop();  
			if(check_user_form()) {
				var log = $('status').empty().appendText('Sending...');  
				this.send({  
					update: log,  
					onComplete: function() {
						clearForm();
						//log.empty().addClass('error');
					}  
				});  
			}
		}); 
	}
	if($('ContactPending')) {
		$('ContactPending').addEvent('submit', function(e) {  
			new Event(e).stop();  
			if(check_mail_form()) {
				var log = $('status').empty().appendText('Sending...');  
				this.send({  
					update: log,  
					onComplete: function() {
						clearMailForm();
						//log.empty().addClass('error');
					}  
				});  
			}
		}); 
	}
}); 
