// contact page functions

function togglePay() {
	if (document.getElementById('pay').style.display == "none") { 
		var effect = Effect.BlindDown('pay', { duration: 0.8 });
	}
	else { 
		document.getElementById('pay').style.height = "20px";
		var effect = Effect.BlindUp('pay', { duration: 0.8 });
	}
	return false;
}
function sendQuote() {
	if (!validateQuote()) { return false; }
	else {
		
		new Ajax.Request('index.php', {
						 method: 'post',
						 parameters: { 
						 	name: document.contact.name.value,
							company: document.contact.company.value,
							email: document.contact.email.value,
							phone: document.contact.phone.value,
							url: document.contact.url.value,
							type: document.contact.type.value,
							budget: document.contact.budget.value,
							hosting: document.contact.hosting.value,
							description: document.contact.description.value,
							k: document.contact.k.value,
							jax: 'true'
						 },
						 onSuccess: function(contactSuccess) {
							if (contactSuccess.responseText == "1") { 
								var effect1 = Effect.Fade('contact_form', { duration: 0.5 });
								var effect2 = Effect.Appear('contact_sent', { duration: 0.5 });
							}
							else {
								$('contact_sent').innerHTML = '<h1 class="blue">error sending form...</h1>We\'re experiencing some technical difficulties. Please contact us at <a href="mailto:info@netstuffsolutions.com">info@netstuffsolutions.com</a> and let us know it\'s busted. Thanks!';
								var effect1 = Effect.Fade('contact_form', { duration: 0.5 });
								var effect2 = Effect.Appear('contact_sent', { duration: 0.5 });
								
							}
						 },
						 onFailure: function() { 
						 	$('contact_sent').innerHTML = '<h1 class="blue">error sending form...</h1>We\'re experiencing some technical difficulties. Please contact us at <a href="mailto:info@netstuffsolutions.com">info@netstuffsolutions.com</a> and let us know it\'s busted. Thanks!';
								var effect1 = Effect.Fade('contact_form', { duration: 0.5 });
								var effect2 = Effect.Appear('contact_sent', { duration: 0.5 });
								
						 }
		});
						
							
		return false;
	}
}
	
function validateQuote() {
	document.contact.name.style.border = "0";
	document.contact.email.style.border = "0";
	document.contact.type.style.border = "0";
	document.contact.budget.style.border = "0";
	document.contact.description.style.border = "0";
	
	var errors = 0;
	
	if (document.contact.name.value == "") { errors++; document.contact.name.style.border = "2px #fe4272 solid"; }
	if (document.contact.email.value == "") { errors++; document.contact.email.style.border = "2px #fe4272 solid"; }
	if (!validateEmail(document.contact.email)) { errors++; document.contact.email.style.border = "2px #fe4272 solid"; }
	if (document.contact.type.value == "none") { errors++; document.contact.type.style.border = "2px #fe4272 solid"; }
	if (document.contact.budget.value == "none") { errors++; document.contact.budget.style.border = "2px #fe4272 solid"; }
	if (document.contact.description.value == "") { errors++; document.contact.description.style.border = "2px #fe4272 solid"; }
	
	if (errors == 0) return true;
	else { 
		document.getElementById('req').innerHTML = '<span style="color: #fe4272; font-weight: bold;">(please enter valid data for the outlined fields)</span>';
		return false;
	}
}
function validateEmail(field) {
	
	var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	
	if (goodEmail) { return true; }
	else { return false; }
}
function validatePayForm() {
	var errors = 0;
	var msg = "";
	if (document.pay.item_name.value == "") { errors++; msg += "Please enter your invoice number.\n"; }
	if (document.pay.amount.value == "") { errors++; msg += "Please enter the $ amount to be paid."; }
	if (errors > 0) {
		alert(msg);
		return false;
	}
	else {
		document.pay.item_name.value = "Invoice #" + document.pay.item_name.value;
		return true;
	}
}
