/////////////////////////////////////////////
function send_message(where_send)
{
	var name 	= $('#name').val();
	var email	= $('#email').val();
	var text 	= $('#text').val();
	var site	= 0;
	var price	= 0;
	
	query = null;
		
	if(window.XMLHttpRequest) 
	{
		query = new XMLHttpRequest();
	}
	
	if(window.ActiveXObject)  
	{
		query = new ActiveXObject('Microsoft.XMLHTTP');
	}
	
	query.onreadystatechange = success_send;	
	
	if ( where_send != undefined )
	{
		site 	= $('#site').val();
		price 	= $('#price').val();
		params 	= "n=" + name + "&e=" + email + "&t=" + text + "&s=" + site + "&p=" + price;
	}
	else
	{
		params 	= "n=" + name + "&e=" + email + "&t=" + text;
	}	
			 
	//alert(params);
	query.open("POST","submitmail.php",true);
	query.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	query.send(params);
}


/////////////////////////////////////////////
var alert_icon 	= '<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span>';
var info_icon 	= '<p><span class="ui-icon ui-icon-info" style="float: left; margin-right: 0.3em;"></span>';


function success_send()
{
	//alert(query.responseText);	
	if ( query.readyState == 4 )
    {
		//alert((cquery.responseText == "error")); 
		if ( query.responseText == "" )
		{
			$('#error_message').html(info_icon + feedback_info + '</p>').addClass("ui-state-highlight ui-corner-all");
		}
		else
		{
			$('#error_message').html(alert_icon + feedback_alert + '</p>').addClass("ui-state-error ui-corner-all");
		}
	}
}


/////////////////////////////////////////////
function checkForm(where_send)
{
	var name 			= $('#name');
	var email			= $('#email');	
	var text 			= $('#text');	
	var norobot			= $('#norobot');
	var error_message 	= $('#error_message');
	var price			= 0;
	
	error_message.html("").removeClass("ui-state-error ui-state-highlight ui-corner-all");

	if ( (name.val() == " ") || (name.val() == hint_str) )
	{
		error_message.html(alert_icon + chechform_error_name + '</p>').addClass("ui-state-error ui-corner-all");
		name.focus();
		
		return false;
	}
	
	if ( (email.val() == " ") || (email.val() == hint_str) )
	{
		error_message.html(alert_icon + chechform_error_email1 + '</p>').addClass("ui-state-error ui-corner-all");
		email.focus();
		
		return false;
	}

	if (!(/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9]*[a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email.val()))
	{
		error_message.html(alert_icon + chechform_error_email2 + '</p>').addClass("ui-state-error ui-corner-all");
		email.focus();
		
		return false;
	}
	
	if ( where_send != undefined )
	{
		price = $('#price');
		
		if ( (price.val() == " ") || (price.val() == hint_str) )
		{
			error_message.html(alert_icon + chechform_error_price + '</p>').addClass("ui-state-error ui-corner-all");
			price.focus();
			
			return false;
		}
	}
	
	if ( (text.val() == " ") || (text.val() == hint_str) )
	{
		error_message.html(alert_icon + chechform_error_text + '</p>').addClass("ui-state-error ui-corner-all");
		text.focus();
		
		return false;
	}

	if (!norobot.attr('checked'))
	{
		error_message.html(alert_icon + chechform_error_robot + '</p>').addClass("ui-state-error ui-corner-all");
		norobot.focus();
		
		return false;
	}
	
	send_message(where_send);
}
