$(function() {
	$('.error').hide();
	// $('input.text-input').css({backgroundColor:"#FFFFFF"});
	$('input.input1').focus(function(){
		$(this).css({borderColor:"#666666"});
	});
	$('input.input1').blur(function(){
		$(this).css({borderColor:"#DFDFDF"});
	});
	$('input.input2').focus(function(){
		$(this).css({borderColor:"#666666"});
	});
	$('input.input2').blur(function(){
		$(this).css({borderColor:"#DFDFDF"});
	});
	$('input.input3').focus(function(){
		$(this).css({borderColor:"#666666"});
	});
	$('input.input3').blur(function(){
		$(this).css({borderColor:"#DFDFDF"});
	});

	$(".button").click(function() {
		// validate and process form
		// first hide any error messages
	    //$('.error').hide();
	    $('#status').html('');
			
		var yourName = $("input#yourName").val();
		if (yourName == "") {
			//$("label#name_error").show();
			$("input#yourName").focus();
			$('input#yourName').css({borderColor: "#FF0000"});
			return false;
		}
			
		var yourEmail = $("input#yourEmail").val();
		/*if (email == "") {
			//$("label#name_error").show();
			//$("input#yourEmail").focus();
			$('input#yourEmail').css({borderColor: "#FF0000"});
			return false;
		}
		*/	
		var yourCity = $("input#yourCity").val();
		if (yourCity == "") {
			//$("label#name_error").show();
			//$("input#yourName").focus();
			$('input#yourCity').css({borderColor: "#FF0000"});
			return false;
		}
			
		var yourState = $("input#yourState").val();
		if (yourState == "") {
			//$("label#name_error").show();
			//$("input#yourName").focus();
			$('input#yourState').css({borderColor: "#FF0000"});
			return false;
		}
		
		var dataString = 'yourName='+ yourName + '&yourEmail=' + yourEmail + '&yourCity=' + yourCity + '&yourState=' + yourState;
		//alert (dataString);return false;
		
		$('#status').html('<img src="assets/images/sending.gif" alt="Sending..." width="173" height="35" />');
		
		$.ajax({
			type: "POST",
			url: "assets/php/process.php",
			data: dataString,
			success: function() {
				$('#status').html('<img src="assets/images/success.gif" alt="Thanks for Signing!" width="173" height="35" />');
				//$().html();
				//$('#myFrame').setAttribute("src", "tracking.htm?" + Math.random());
				ifrm = document.createElement("IFRAME");
				var aurl= "tracking.htm?" + Math.random();
				//alert("conversion " +aurl);
				ifrm.setAttribute("src", aurl);
				ifrm.setAttribute("frameborder", 0);
				ifrm.style.border = "none";
				ifrm.style.width = 200+"px";
				ifrm.style.height = 50+"px";
				//document.body.appendChild(ifrm);
				$('#footer').html(ifrm);
				//$('#message').html("<h2>Contact Form Submitted!</h2>")
				//.append("<p>We will be in touch soon.</p>")
				//.hide()
				//.fadeIn(1500, function() {
					//$('#message').append("<img id='checkmark' src='images/check.png' />");
				//});
			}
		});
		return false;
	});
});

runOnLoad(function(){
	//$("input#yourName").select().focus();
});
