// JavaScript Document

//=======Click Listeners===========
jQuery("#submit").click(validate_form); //Listens for the "submit" button clicked on the contact us page

jQuery("#sndcrds_o").click(sendcards_o); //An attempt to make a button to change between a div and iframe - SendOutCards page

jQuery("#sndcrds_c").click(sendcards_c);

//Sends the form information to the validator, if valid, sends it to the mail handler
function validate_form(){
	if (valid_form(document.contact_us)){
		snd_mail();
	}
}

function valid_form(passForm){
	var cnt = -1
	for (i = 0; i<passForm.contact.length; i++) {
		if (passForm.contact[i].checked) {
			cnt = i
		}
	}
	if (passForm.full_name.value == "")
	{
		alert("Please enter your name.");
		passForm.full_name.focus();
		return false;
	}
	if (passForm.email_address.value == "")
	{
		alert("Please enter your email address.");
		passForm.email_address.focus();
		return false;
	}
	if (passForm.comment.value == "")
	{
		alert("Please let us know how we can help.");
		passForm.comment.focus();
		return false;
	}
	if (cnt == -1) {
		alert("Please choose a way for us to contact you.")
		return false
	}
	if ($("input[name='contact']:checked").val() == "phone") {
		if (passForm.contact_time.value == "") 
			{
				alert("Please let us know what time to contact you.");
				passForm.contact_time.focus();
				return false;
			}
	}
	return true;
}

function snd_mail() {
	var email = $("input[name='email_address']").val();
	var name = $("input[name='full_name']").val();
	var comment = $("textarea[name='comment']").val();
	var contact = $("input[name='contact']:checked").val();
	var contact_time = $("textarea[name='contact_time']").val();
	jQuery.post("send_mail.php", {full_name:name, email_address:email, comment:comment, contact:contact, contact_time:contact_time});
	$("input[name='email_address']").val("");
	$("input[name='full_name']").val("");
	$("textarea[name='comment']").val("");
	$("textarea[name='contact_time']").val("");
	
	alert("Thank you, your message has been sent.");
	
}
	

function sendcards_o() {
	$('#pg_content').attr("visability", "hidden");
	$('#pg_content').attr("display","none");
	$('#sndcrds_content').attr("visability","normal");
	$('#sndcrds_content').attr("display", '');
}

function sendcards_c() {
	$('#pg_content').attr("visability", "normal");
	$('#pg_content').attr("display",'');
	$('#sndcrds_content').attr("visability", "hidden");
	$('#sndcrds_content').attr("display", "none");
}


if (typeof testim != "undefined" && testim)
	testim_ld();
	
function testim_ld(){
	$("#testimony").load("/db/testim_load.php", {});
	//alert("javascript connected");
}

function flashsetup() {
	window.location = "preferences.php";
}

function specialsRD() {
	window.location = "promotionalprod.php";
	$("#products").attr('src', 'http://www.promoplace.com/6969/seed_items.htm');
}