// JavaScript Document

var $oldWidth = jQuery(window).width();
var minHeight = 600;
var minWidth = 1034;
var widthOffset = 40;

function fixWidth() {
	$curWidth = jQuery(window).width();
	debug("Reize: curWidth = " + $curWidth + ', oldWidth = ' + $oldWidth + ', height ' + jQuery(window).height());
	if ($curWidth != $oldWidth) {

		var height = wHight = jQuery(window).height();
		if(minHeight > wHight)
			height = minHeight;

		if ($curWidth < minWidth-widthOffset) {
			jQuery(window).width(minWidth);
			//if(!jQuery.browser.msie)
			window.resizeTo(minWidth, height);
		}
		$oldWidth = jQuery(window).width();
	}
}

jQuery(document).ready(function($) {

	$("#clear").live('click',function(){
		$(this).parent().find('input, textarea').each(function(i){
			$(this).val('').blur();
		});
		$(this).parent().find('select').each(function(){
			document.getElementById(this.id).selectedIndex = 0;
		});
		$("#txtOther").hide().val('');
	});
	
	$("#txtHeard").change(function(){
		if($(this).val() == 'Other')
			$("#txtOther").val($("#txtOther").attr('title')).show();
		else
			$("#txtOther").hide().val('');
	});
		
	$(".btt").click(function(){
		window.location = "#";
	});
	
	$("input, textarea").live('focus',function(){
		if($(this).val() == $(this).attr('title'))
			$(this).val('');
	}).live('blur',function(){
		if($(this).val() == '')
			$(this).val($(this).attr('title'));
	});
	
	$("#submit").click(function(){
		if(checkContactForm()) {
			$.post("ajax-email.php",
				   {
					name: $("#txtName").val(),
					email: $("#txtEmail").val(),
					phone: $("#txtPhone").val(),
					comments: $("#txtComments").val(),
					heard_about: $("#txtHeard").val() == "Other" ? $("#txtOther").val() : $("#txtHeard").val()
				   },
				   function(data){
						if(data.success) {
							alert("Thank you for you message!");
							$("#clear").click();
						}
						else
							alert("There was an error submitting your request, please try again.");
			},"json");
		}		
	});
});
