$(document).ready(function(){
	
	$('#contactForm').submit(function(e) {

		contact();
		e.preventDefault();
		
	});

});



function contact()
{
	hideshow('loading',1);
	error(0);
	
	$.ajax({
		type: "POST",
		url: "/wp-content/themes/gtreasury/contactform.php",
		data: $('#contactForm').serialize(),
		dataType: "json",
		success: function(msg){
		
			if(parseInt(msg.status)==1)
			{
				error(1,msg.txt);
				$('#error').css({'visibility': 'visible', 'background-color': '#ccffcc', 'border': '1px solid #33CC33', 'margin-right': '128px', 'text-align': 'center'});
			}
			else if(parseInt(msg.status)==0)
			{
				error(1,msg.txt);
				$('#error').css({'visibility': 'visible', 'background-color': '#FFEBE8', 'border': '1px solid #DD3C10', 'margin-right': '128px', 'text-align': 'center'});
			}
			
			hideshow('loading',0);
		}
	});

}

function hideshow(el,act)
{
	if(act) $('#'+el).css('visibility','visible');
	else $('#'+el).css('visibility','hidden');
}

function error(act,txt)
{
	hideshow('error',act);
	if(txt) $('#error').html(txt);
}

$('#success').css('visibility','visible');

