/*
 * SimpleModal Contact Form
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2009 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: contact.js 185 2009-02-09 21:51:12Z emartin24 $
 *
 */
 
var $j = jQuery.noConflict();



$j(document).ready(function () {
	$j('#contactForm a.contact').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		$j.get("data/contact.php", function(data){
			// create a modal dialog with the data
			$j(data).modal({
				close: false,
				position: ["15%",],
				overlayId: 'contact-overlay',
				containerId: 'contact-container',
				onOpen: contact.open,
				onShow: contact.show,
				onClose: contact.close
			});
		});
	});

	// preload images
	var img = ['cancel.png', 'form_bottom.gif', 'form_top.gif', 'loading.gif', 'send.png'];
	$j(img).each(function () {
		var i = new Image();
		i.src = 'img/contact/' + this;
	});
});

$j(document).ready(function () {
	$j('#contactForm a.contact').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		$j.get("data/contact.php", function(data){
			// create a modal dialog with the data
			$j(data).modal({
				close: false,
				position: ["15%",],
				overlayId: 'contact-overlay',
				containerId: 'contact-container',
				onOpen: contact.open,
				onShow: contact.show,
				onClose: contact.close
			});
		});
	});

	// preload images
	var img = ['cancel.png', 'form_bottom.gif', 'form_top.gif', 'loading.gif', 'send.png'];
	$j(img).each(function () {
		var i = new Image();
		i.src = 'img/contact/' + this;
	});
});

$j(document).ready(function () {
	$j('#newsletterForm a.newsletter, #newsletterform input.newsletter').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		$j.get("data/newsletter.php", function(data){
			// create a modal dialog with the data
			$j(data).modal({
				close: false,
				position: ["15%",],
				overlayId: 'contact-overlay',
				containerId: 'contact-container',
				onOpen: newsletter.open,
				onShow: newsletter.show,
				onClose: newsletter.close	
			});
		});
	});

	// preload images
	var img = ['cancel.png', 'form_bottom.gif', 'form_top.gif', 'loading.gif', 'send.png'];
	$j(img).each(function () {
		var i = new Image();
		i.src = 'img/contact/' + this;
	});
});

$j(document).ready(function () {
	$j('#newsletterform input.submit').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		$j.get("data/newsletter.php", function(data){
			// create a modal dialog with the data
			$j(data).modal({
				close: false,
				position: ["15%",],
				overlayId: 'contact-overlay',
				containerId: 'contact-container',
				onOpen: submit.open,
				onShow: submit.show,
				onClose: submit.close	
			});
		});
	});

	// preload images
	var img = ['cancel.png', 'form_bottom.gif', 'form_top.gif', 'loading.gif', 'send.png'];
	$j(img).each(function () {
		var i = new Image();
		i.src = 'img/contact/' + this;
	});
});

$j(document).ready(function () {
	$j('#contactForm a.newsletter').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		$j.get("data/newsletter.php", function(data){
			// create a modal dialog with the data
			$j(data).modal({
				close: false,
				position: ["15%",],
				overlayId: 'contact-overlay',
				containerId: 'contact-container',
				onOpen: newsletter.open,
				onShow: newsletter.show,
				onClose: newsletter.close
			});
		});
	});

	// preload images
	var img = ['cancel.png', 'form_bottom.gif', 'form_top.gif', 'loading.gif', 'send.png'];
	$j(img).each(function () {
		var i = new Image();
		i.src = 'img/contact/' + this;
	});
});





$j(document).ready(function () {
	$j('#productForm1 a.product1').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		$j.get("data/product1.php", function(data){
			// create a modal dialog with the data
			$j(data).modal({
				close: false,
				position: ["15%",],
				overlayId: 'contact-overlay',
				containerId: 'contact-container',
				onOpen: product1.open,
				onShow: product1.show,
				onClose: product1.close
			});
		});
	});

	// preload images
	var img = ['cancel.png', 'form_bottom.gif', 'form_top.gif', 'loading.gif', 'send.png'];
	$j(img).each(function () {
		var i = new Image();
		i.src = 'img/contact/' + this;
	});
});

var contact = {
	message: null,
	open: function (dialog) {
		// add padding to the buttons in firefox/mozilla
		if ($j.browser.mozilla) {
			$j('#contact-container .contact-button').css({
				'padding-bottom': '2px'
			});
		}
		// input field font size
		if ($j.browser.safari) {
			$j('#contact-container .contact-input').css({
				'font-size': '.9em'
			});
		}

		// dynamically determine height
		var h = 350;
		if ($j('#contact-subject').length) {
			h += 26;
		}
		if ($j('#contact-cc').length) {
			h += 22;
		}

		var title = $j('#contact-container .contact-title').html();
		$j('#contact-container .contact-title').html('Loading...');
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					$j('#contact-container .contact-content').animate({
						height: h
					}, function () {
						$j('#contact-container .contact-title').html(title);
						$j('#contact-container form').fadeIn(200, function () {
							$j('#contact-container #contact-name').focus();

							$j('#contact-container .contact-cc').click(function () {
								var cc = $j('#contact-container #contact-cc');
								cc.is(':checked') ? cc.attr('checked', '') : cc.attr('checked', 'checked');
							});

							// fix png's for IE 6
							if ($j.browser.msie && $j.browser.version < 7) {
								$j('#contact-container .contact-button').each(function () {
									if ($j(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
										var src = RegExp.$1;
										$j(this).css({
											backgroundImage: 'none',
											filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
										});
									}
								});
							}
						});
					});
				});
			});
		});
	},
	show: function (dialog) {
		$j('#contact-container .contact-send').click(function (e) {
			e.preventDefault();
			// validate form
			if (contact.validate()) {
				$j('#contact-container .contact-message').fadeOut(function () {
					$j('#contact-container .contact-message').removeClass('contact-error').empty();
				});
				$j('#contact-container .contact-title').html('Sending...');
				$j('#contact-container form').fadeOut(200);
				$j('#contact-container .contact-content').animate({
					height: '100px'
				}, function () {
					$j('#contact-container .contact-loading').fadeIn(200, function () {
						$j.ajax({
							url: 'data/contact.php',
							data: $j('#contact-container form').serialize() + '&action=send',
							type: 'post',
							cache: false,
							dataType: 'html',
							complete: function (xhr) {
								$j('#contact-container .contact-loading').fadeOut(200, function () {
									$j('#contact-container .contact-title').html('Thank you!');
									$j('#contact-container .contact-message').html(xhr.responseText).fadeIn(200);
								});
							},
							error: contact.error
						});
					});
				});
			}
			else {
				if ($j('#contact-container .contact-message:visible').length > 0) {
					var msg = $j('#contact-container .contact-message div');
					msg.fadeOut(200, function () {
						msg.empty();
						contact.showError();
						msg.fadeIn(200);
					});
				}
				else {
					$j('#contact-container .contact-message').animate({
						height: '30px'
					}, contact.showError);
				}
				
			}
		});
	},
	close: function (dialog) {
		$j('#contact-container .contact-message').fadeOut();
		$j('#contact-container .contact-title').html('Closing...');
		$j('#contact-container form').fadeOut(200);
		$j('#contact-container .contact-content').animate({
			height: 40
		}, function () {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						$j.modal.close();
					});
				});
			});
		});
	},
	error: function (xhr) {
		alert(xhr.statusText);
	},
	validate: function () {
		contact.message = '';
		if (!$j('#contact-container #contact-fname').val()) {
			contact.message += 'First Name is required. ';
		}
		
		if (!$j('#contact-container #contact-lname').val()) {
			contact.message += 'Last Name is required. ';
		}
		
		if (!$j('#contact-container #contact-address').val()) {
			contact.message += 'Address is required. ';
		}
		
		if (!$j('#contact-container #contact-city').val()) {
			contact.message += 'City is required. ';
		}
		
		if (!$j('#contact-container #contact-state').val()) {
			contact.message += 'State is required. ';
		}
		
		if (!$j('#contact-container #contact-zcode').val()) {
			contact.message += 'Zip Code is required. ';
		}
		
		if (!$j('#contact-container #contact-phone').val()) {
			contact.message += 'Phone is required. ';
		}

		var email = $j('#contact-container #contact-email').val();
		if (!email) {
			contact.message += 'Email Address is required. ';
		}
		else {
			if (!contact.validateEmail(email)) {
				contact.message += 'Email Address is invalid. ';
			}
		}
		
		if (!$j('#contact-container #contact-subject').val()) {
			contact.message += 'Subject is required. ';
		}

		if (!$j('#contact-container #contact-message').val()) {
			contact.message += 'Message is required.';
		}

		if (contact.message.length > 0) {
			return false;
		}
		else {
			return true;
		}
	},
	validateEmail: function (email) {
		var at = email.lastIndexOf("@");

		// Make sure the at (@) sybmol exists and  
		// it is not the first or last character
		if (at < 1 || (at + 1) === email.length)
			return false;

		// Make sure there aren't multiple periods together
		if (/(\.{2,})/.test(email))
			return false;

		// Break up the local and domain portions
		var local = email.substring(0, at);
		var domain = email.substring(at + 1);

		// Check lengths
		if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255)
			return false;

		// Make sure local and domain don't start with or end with a period
		if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain))
			return false;

		// Check for quoted-string addresses
		// Since almost anything is allowed in a quoted-string address,
		// we're just going to let them go through
		if (!/^"(.+)"$/.test(local)) {
			// It's a dot-string address...check for valid characters
			if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local))
				return false;
		}

		// Make sure domain contains only valid characters and at least one period
		if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1)
			return false;	

		return true;
	},
	showError: function () {
		$j('#contact-container .contact-message')
			.html($j('<div class="contact-error">').append(contact.message))
			.fadeIn(200);
	}
};


var newsletter = {
	message: null,
	open: function (dialog) {
		// add padding to the buttons in firefox/mozilla
		if ($j.browser.mozilla) {
			$j('#contact-container .contact-button').css({
				'padding-bottom': '2px'
			});
		}
		// input field font size
		if ($j.browser.safari) {
			$j('#contact-container .contact-input').css({
				'font-size': '.9em'
			});
		}

		// dynamically determine height
		var h = 150;
		if ($j('#contact-subject').length) {
			h += 26;
		}
		if ($j('#contact-cc').length) {
			h += 22;
		}

		var title = $j('#contact-container .contact-title').html();
		$j('#contact-container .contact-title').html('Loading...');
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					$j('#contact-container .contact-content').animate({
						height: h
					}, function () {
						$j('#contact-container .contact-title').html(title);
						$j('#contact-container form').fadeIn(200, function () {
							$j('#contact-container #contact-email').focus();

							

							// fix png's for IE 6
							if ($j.browser.msie && $j.browser.version < 7) {
								$j('#contact-container .contact-button').each(function () {
									if ($j(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
										var src = RegExp.$1;
										$j(this).css({
											backgroundImage: 'none',
											filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
										});
									}
								});
							}
						});
					});
				});
			});
		});
	},
	show: function (dialog) {
		$j('#contact-container .contact-send').click(function (e) {
			e.preventDefault();
			// validate form
			if (newsletter.validate()) {
				$j('#contact-container .contact-message').fadeOut(function () {
					$j('#contact-container .contact-message').removeClass('contact-error').empty();
				});
				$j('#contact-container .contact-title').html('Sending...');
				$j('#contact-container form').fadeOut(200);
				$j('#contact-container .contact-content').animate({
					height: '100px'
				}, function () {
					$j('#contact-container .contact-loading').fadeIn(200, function () {
						$j.ajax({
							url: 'data/newsletter.php',
							data: $j('#contact-container form').serialize() + '&action=send',
							type: 'post',
							cache: false,
							dataType: 'html',
							complete: function (xhr) {
								$j('#contact-container .contact-loading').fadeOut(200, function () {
									$j('#contact-container .contact-title').html('Thank you for registering!');
									$j('#contact-container .contact-message').html(xhr.responseText).fadeIn(200);
								});
							},
							error: newsletter.error
						});
					});
				});
			}
			else {
				if ($j('#contact-container .contact-message:visible').length > 0) {
					var msg = $j('#contact-container .contact-message div');
					msg.fadeOut(200, function () {
						msg.empty();
						newsletter.showError();
						msg.fadeIn(200);
					});
				}
				else {
					$j('#contact-container .contact-message').animate({
						height: '30px'
					}, newsletter.showError);
				}
				
			}
		});
	},
	close: function (dialog) {
		$j('#contact-container .contact-message').fadeOut();
		$j('#contact-container .contact-title').html('Closing...');
		$j('#contact-container form').fadeOut(200);
		$j('#contact-container .contact-content').animate({
			height: 40
		}, function () {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						$j.modal.close();
					});
				});
			});
		});
	},
	error: function (xhr) {
		alert(xhr.statusText);
	},
	validate: function () {
		newsletter.message = '';
		

		var email = $j('#contact-container #contact-email').val();
		if (!email) {
			newsletter.message += 'Email is required. ';
		}
		else {
			if (!newsletter.validateEmail(email)) {
				newsletter.message += 'Email is invalid. ';
			}
		}

		

		if (newsletter.message.length > 0) {
			return false;
		}
		else {
			return true;
		}
	},
	validateEmail: function (email) {
		var at = email.lastIndexOf("@");

		// Make sure the at (@) sybmol exists and  
		// it is not the first or last character
		if (at < 1 || (at + 1) === email.length)
			return false;

		// Make sure there aren't multiple periods together
		if (/(\.{2,})/.test(email))
			return false;

		// Break up the local and domain portions
		var local = email.substring(0, at);
		var domain = email.substring(at + 1);

		// Check lengths
		if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255)
			return false;

		// Make sure local and domain don't start with or end with a period
		if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain))
			return false;

		// Check for quoted-string addresses
		// Since almost anything is allowed in a quoted-string address,
		// we're just going to let them go through
		if (!/^"(.+)"$/.test(local)) {
			// It's a dot-string address...check for valid characters
			if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local))
				return false;
		}

		// Make sure domain contains only valid characters and at least one period
		if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1)
			return false;	

		return true;
	},
	showError: function () {
		$j('#contact-container .contact-message')
			.html($j('<div class="contact-error">').append(newsletter.message))
			.fadeIn(200);
	}
};


var product1 = {
	message: null,
	open: function (dialog) {
		// add padding to the buttons in firefox/mozilla
		if ($j.browser.mozilla) {
			$j('#contact-container .contact-button').css({
				'padding-bottom': '2px'
			});
		}
		// input field font size
		if ($j.browser.safari) {
			$j('#contact-container .contact-input').css({
				'font-size': '.9em'
			});
		}

		// dynamically determine height
		var h = 350;
		if ($j('#contact-subject').length) {
			h += 26;
		}
		if ($j('#contact-cc').length) {
			h += 22;
		}

		var title = $j('#contact-container .contact-title').html();
		$j('#contact-container .contact-title').html('Loading...');
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					$j('#contact-container .contact-content').animate({
						height: h
					}, function () {
						$j('#contact-container .contact-title').html(title);
						$j('#contact-container form').fadeIn(200, function () {
							$j('#contact-container #contact-fname').focus();

							

							// fix png's for IE 6
							if ($j.browser.msie && $j.browser.version < 7) {
								$j('#contact-container .contact-button').each(function () {
									if ($j(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
										var src = RegExp.$1;
										$j(this).css({
											backgroundImage: 'none',
											filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
										});
									}
								});
							}
						});
					});
				});
			});
		});
	},
	show: function (dialog) {
		$j('#contact-container .contact-send').click(function (e) {
			e.preventDefault();
			// validate form
			if (product1.validate()) {
				$j('#contact-container .contact-message').fadeOut(function () {
					$j('#contact-container .contact-message').removeClass('contact-error').empty();
				});
				$j('#contact-container .contact-title').html('Sending...');
				$j('#contact-container form').fadeOut(200);
				$j('#contact-container .contact-content').animate({
					height: '100px'
				}, function () {
					$j('#contact-container .contact-loading').fadeIn(200, function () {
						$j.ajax({
							url: 'data/product1.php',
							data: $j('#contact-container form').serialize() + '&action=send',
							type: 'post',
							cache: false,
							dataType: 'html',
							complete: function (xhr) {
								$j('#contact-container .contact-loading').fadeOut(200, function () {
									$j('#contact-container .contact-title').html('Email to a Friend Message Sent!');
									$j('#contact-container .contact-message').html(xhr.responseText).fadeIn(200);
								});
							},
							error: product1.error
						});
					});
				});
			}
			else {
				if ($j('#contact-container .contact-message:visible').length > 0) {
					var msg = $j('#contact-container .contact-message div');
					msg.fadeOut(200, function () {
						msg.empty();
						product1.showError();
						msg.fadeIn(200);
					});
				}
				else {
					$j('#contact-container .contact-message').animate({
						height: '30px'
					}, product1.showError);
				}
				
			}
		});
	},
	close: function (dialog) {
		$j('#contact-container .contact-message').fadeOut();
		$j('#contact-container .contact-title').html('Closing...');
		$j('#contact-container form').fadeOut(200);
		$j('#contact-container .contact-content').animate({
			height: 40
		}, function () {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						$j.modal.close();
					});
				});
			});
		});
	},
	error: function (xhr) {
		alert(xhr.statusText);
	},
	validate: function () {
		product1.message = '';
		if (!$j('#contact-container #contact-friendname').val()) {
			product1.message += 'Friend Name is required. ';
		}

		var femail = $j('#contact-container #contact-femail').val();
		if (!femail) {
			product1.message += 'Friend Email is required. ';
		}
		else {
			if (!product1.validateFEmail(femail)) {
				product1.message += 'Friend Email is invalid. ';
			}
		}
		
		if (!$j('#contact-container #contact-name').val()) {
			product1.message += 'Your Name is required. ';
		}

		var email = $j('#contact-container #contact-youremail').val();
		if (!email) {
			product1.message += 'Your Email is required. ';
		}
		else {
			if (!product1.validateEmail(email)) {
				product1.message += 'Your Email is invalid. ';
			}
		}

		if (!$j('#contact-container #contact-message').val()) {
			product1.message += 'Message is required.';
		}

		if (product1.message.length > 0) {
			return false;
		}
		else {
			return true;
		}
	},
	validateEmail: function (email) {
		var at = email.lastIndexOf("@");

		// Make sure the at (@) sybmol exists and  
		// it is not the first or last character
		if (at < 1 || (at + 1) === email.length)
			return false;

		// Make sure there aren't multiple periods together
		if (/(\.{2,})/.test(email))
			return false;

		// Break up the local and domain portions
		var local = email.substring(0, at);
		var domain = email.substring(at + 1);

		// Check lengths
		if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255)
			return false;

		// Make sure local and domain don't start with or end with a period
		if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain))
			return false;

		// Check for quoted-string addresses
		// Since almost anything is allowed in a quoted-string address,
		// we're just going to let them go through
		if (!/^"(.+)"$/.test(local)) {
			// It's a dot-string address...check for valid characters
			if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local))
				return false;
		}

		// Make sure domain contains only valid characters and at least one period
		if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1)
			return false;	

		return true;
	},
	validateFEmail: function (femail) {
		var at = femail.lastIndexOf("@");

		// Make sure the at (@) sybmol exists and  
		// it is not the first or last character
		if (at < 1 || (at + 1) === femail.length)
			return false;

		// Make sure there aren't multiple periods together
		if (/(\.{2,})/.test(femail))
			return false;

		// Break up the local and domain portions
		var local = femail.substring(0, at);
		var domain = femail.substring(at + 1);

		// Check lengths
		if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255)
			return false;

		// Make sure local and domain don't start with or end with a period
		if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain))
			return false;

		// Check for quoted-string addresses
		// Since almost anything is allowed in a quoted-string address,
		// we're just going to let them go through
		if (!/^"(.+)"$/.test(local)) {
			// It's a dot-string address...check for valid characters
			if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local))
				return false;
		}

		// Make sure domain contains only valid characters and at least one period
		if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1)
			return false;	

		return true;
	},
	showError: function () {
		$j('#contact-container .contact-message')
			.html($j('<div class="contact-error">').append(product1.message))
			.fadeIn(200);
	}
};


var engagement = {
	message: null,
	open: function (dialog) {
		$j(".engagement-content #engagement-dob").datepicker();
		// add padding to the buttons in firefox/mozilla
		if ($j.browser.mozilla) {
			$j('#engagement-container .engagement-button').css({
				'padding-bottom': '2px'
			});
		}
		// input field font size
		if ($j.browser.safari) {
			$j('#engagement-container .engagement-input').css({
				'font-size': '.9em'
			});
		}

		// dynamically determine height
		var h = 570;
		if ($j('#engagement-subject').length) {
			h += 26;
		}
		if ($j('#engagement-cc').length) {
			h += 22;
		}

		var title = $j('#engagement-container .engagement-title').html();
		$j('#engagement-container .engagement-title').html('Loading...');
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					$j('#engagement-container .engagement-content').animate({
						height: h
					}, function () {
						$j('#engagement-container .engagement-title').html(title);
						$j('#engagement-container form').fadeIn(200, function () {
							$j('#engagement-container #engagement-salutation').focus();

							

							// fix png's for IE 6
							if ($j.browser.msie && $j.browser.version < 7) {
								$j('#engagement-container .engagement-button').each(function () {
									if ($j(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
										var src = RegExp.$1;
										$j(this).css({
											backgroundImage: 'none',
											filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
										});
									}
								});
							}
						});
					});
				});
			});
		});
	},
	show: function (dialog) {
		$j('#engagement-container .engagement-send').click(function (e) {
			e.preventDefault();
			// validate form
			if (engagement.validate()) {
				$j('#engagement-container .engagement-message').fadeOut(function () {
					$j('#engagement-container .engagement-message').removeClass('engagement-error').empty();
				});
				$j('#engagement-container .engagement-title').html('Sending...');
				$j('#engagement-container form').fadeOut(200);
				$j('#engagement-container .engagement-content').animate({
					height: '100px'
				}, function () {
					$j('#engagement-container .engagement-loading').fadeIn(200, function () {
						$j.ajax({
							url: 'data/engagement.php',
							data: $j('#engagement-container form').serialize() + '&action=send',
							type: 'post',
							cache: false,
							dataType: 'html',
							complete: function (xhr) {
								$j('#engagement-container .engagement-loading').fadeOut(200, function () {
									$j('#engagement-container .engagement-title').html('You have successfully sent your request!');
									$j('#engagement-container .engagement-message').html(xhr.responseText).fadeIn(200);
								});
							},
							error: engagement.error
						});
					});
				});
			}
			else {
				if ($j('#engagement-container .engagement-message:visible').length > 0) {
					var msg = $j('#engagement-container .engagement-message div');
					msg.fadeOut(200, function () {
						msg.empty();
						engagement.showError();
						msg.fadeIn(200);
					});
				}
				else {
					$j('#engagement-container .engagement-message').animate({
						height: '30px'
					}, engagement.showError);
				}
				
			}
		});
	},
	close: function (dialog) {
		$j('#engagement-container .engagement-message').fadeOut();
		$j('#engagement-container .engagement-title').html('Closing...');
		$j('#engagement-container form').fadeOut(200);
		$j('#engagement-container .engagement-content').animate({
			height: 40
		}, function () {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						$j.modal.close();
					
					});
				});
			});
		});
	},
	error: function (xhr) {
		alert(xhr.statusText);
	},
	validate: function () {
		engagement.message = '';
		if (!$j('#engagement-container #engagement-salutation').val()) {
			engagement.message += 'Salutation is required. ';
		}
		
		if (!$j('#engagement-container #engagement-fname').val()) {
			engagement.message += 'First Name is required. ';
		}
		
		if (!$j('#engagement-container #engagement-lname').val()) {
			engagement.message += 'Last Name is required. ';
		}

		var email = $j('#engagement-container #engagement-email').val();
		if (!email) {
			engagement.message += 'Email Address is required. ';
		}
		else {
			if (!engagement.validateEmail(email)) {
				engagement.message += 'Email Address is invalid. ';
			}
		}
		
		if (!$j('#engagement-container #engagement-zcode').val()) {
			engagement.message += 'Zip Code is required. ';
		}
		
		if (!$j('#engagement-container #engagement-country').val()) {
			engagement.message += 'Country is required. ';
		}
		
		if (!$j('#engagement-container #engagement-state').val()) {
			engagement.message += 'State is required. ';
		}
		
		if (!$j('#engagement-container #engagement-time').val()) {
			engagement.message += 'Preferred Time is required. ';
		}
		
		if (!$j('#engagement-container #engagement-date').val()) {
			engagement.message += 'Preferred Date is required. ';
		}
		

		if (engagement.message.length > 0) {
			return false;
		}
		else {
			return true;
		}
	},
	validateEmail: function (email) {
		var at = email.lastIndexOf("@");

		// Make sure the at (@) sybmol exists and  
		// it is not the first or last character
		if (at < 1 || (at + 1) === email.length)
			return false;

		// Make sure there aren't multiple periods together
		if (/(\.{2,})/.test(email))
			return false;

		// Break up the local and domain portions
		var local = email.substring(0, at);
		var domain = email.substring(at + 1);

		// Check lengths
		if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255)
			return false;

		// Make sure local and domain don't start with or end with a period
		if (/(^\.|\.$j)/.test(local) || /(^\.|\.$)/.test(domain))
			return false;

		// Check for quoted-string addresses
		// Since almost anything is allowed in a quoted-string address,
		// we're just going to let them go through
		if (!/^"(.+)"$/.test(local)) {
			// It's a dot-string address...check for valid characters
			if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local))
				return false;
		}

		// Make sure domain contains only valid characters and at least one period
		if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1)
			return false;	

		return true;
	},
	showError: function () {
		$j('#engagement-container .engagement-message')
			.html($j('<div class="engagement-error">').append(engagement.message))
			.fadeIn(200);
	}
};


var submit = {
	message: null,
	open: function (dialog) {
		// add padding to the buttons in firefox/mozilla
		if ($j.browser.mozilla) {
			$j('#engagement-container .engagement-button').css({
				'padding-bottom': '2px'
			});
		}
		// input field font size
		if ($j.browser.safari) {
			$j('#engagement-container .engagement-input').css({
				'font-size': '.9em'
			});
		}

		// dynamically determine height
		var h = 150;
		if ($j('#engagement-subject').length) {
			h += 26;
		}
		if ($j('#engagement-cc').length) {
			h += 22;
		}

		var title = $j('#engagement-container .engagement-title').html();
		$j('#engagement-container .engagement-title').html('Loading...');
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					$j('#engagement-container .engagement-content').animate({
						height: h
					}, function () {
						$j('#engagement-container .engagement-title').html(title);
						$j('#engagement-container form').fadeIn(200, function () {
							$j('#engagement-container #engagement-email').focus();

							

							// fix png's for IE 6
							if ($j.browser.msie && $j.browser.version < 7) {
								$j('#engagement-container .engagement-button').each(function () {
									if ($j(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
										var src = RegExp.$1;
										$j(this).css({
											backgroundImage: 'none',
											filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
										});
									}
								});
							}
						});
					});
				});
			});
		});
	},
	show: function (dialog) {
		$j('#engagement-container').click(function (e) {
			e.preventDefault();
			// validate form
			if (submit.validate()) {
				$j('#engagement-container .engagement-message').fadeOut(function () {
					$j('#engagement-container .engagement-message').removeClass('engagement-error').empty();
				});
				$j('#engagement-container .engagement-title').html('Sending...');
				$j('#engagement-container form').fadeOut(200);
				$j('#engagement-container .engagement-content').animate({
					height: '100px'
				}, function () {
					$j('#engagement-container .engagement-loading').fadeIn(200, function () {
						$j.ajax({
							url: 'data/newsletter.php',
							data: $j('#engagement-container form').serialize() + '&action=send',
							type: 'post',
							cache: false,
							dataType: 'html',
							complete: function (xhr) {
								$j('#engagement-container .engagement-loading').fadeOut(200, function () {
									$j('#engagement-container .engagement-title').html('Thank you for registering!');
									$j('#engagement-container .engagement-message').html(xhr.responseText).fadeIn(200);
								});
							},
							error: submit.error
						});
					});
				});
			}
			else {
				if ($j('#engagement-container .engagement-message:visible').length > 0) {
					var msg = $j('#engagement-container .engagement-message div');
					msg.fadeOut(200, function () {
						msg.empty();
						submit.showError();
						msg.fadeIn(200);
					});
				}
				else {
					$j('#engagement-container .engagement-message').animate({
						height: '30px'
					}, submit.showError);
				}
				
			}
		});
	},
	close: function (dialog) {
		$j('#engagement-container .engagement-message').fadeOut();
		$j('#engagement-container .engagement-title').html('Closing...');
		$j('#engagement-container form').fadeOut(200);
		$j('#engagement-container .engagement-content').animate({
			height: 40
		}, function () {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						$j.modal.close();
					});
				});
			});
		});
	},
	error: function (xhr) {
		alert(xhr.statusText);
	},
	validate: function () {
		submit.message = '';
		

		var email = $j('#engagement-container #engagement-email').val();
		if (!email) {
			submit.message += 'Email Address is required. ';
		}
		else {
			if (!submit.validateEmail(email)) {
				submit.message += 'Email Address is invalid. ';
			}
		}

		

		if (submit.message.length > 0) {
			return false;
		}
		else {
			return true;
		}
	},
	validateEmail: function (email) {
		var at = email.lastIndexOf("@");

		// Make sure the at (@) sybmol exists and  
		// it is not the first or last character
		if (at < 1 || (at + 1) === email.length)
			return false;

		// Make sure there aren't multiple periods together
		if (/(\.{2,})/.test(email))
			return false;

		// Break up the local and domain portions
		var local = email.substring(0, at);
		var domain = email.substring(at + 1);

		// Check lengths
		if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255)
			return false;

		// Make sure local and domain don't start with or end with a period
		if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain))
			return false;

		// Check for quoted-string addresses
		// Since almost anything is allowed in a quoted-string address,
		// we're just going to let them go through
		if (!/^"(.+)"$/.test(local)) {
			// It's a dot-string address...check for valid characters
			if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local))
				return false;
		}

		// Make sure domain contains only valid characters and at least one period
		if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1)
			return false;	

		return true;
	},
	showError: function () {
		$j('#engagement-container .engagement-message')
			.html($j('<div class="engagement-error">').append(submit.message))
			.fadeIn(200);
	}
};
