// JavaScript Document
function validateEmail(v_string)  {
	var regex = /^([\w\-\'\-]+)(\.[\w-\'\-]+)*@([\w\-]+\.){1,5}([A-Za-z]){2,4}$/;
	if ( (v_string.length != 0 ) && (regex.test(v_string)) )
		return true;
	else
		return false;
 }
 
function removeInputClass(target)
{
	if ($('#error').val() == target){
		$('#error').val('');
		$('#'+target).removeClass('input_error');
		$('#'+target).addClass('input_ok');
		$('#'+target).val('');
	}
}

function showInputErrorClass(target, text)
{
	$('#'+target).val(text);
	$('#'+target).removeClass('input_ok');
	$('#'+target).addClass('input_error');
	$('#error').val(target);
	$('#'+target).focus();
}

function ShowFormComments(idclient){

	$('#fComment')[0].reset();
	$('#idclient').val(idclient);
	$('#dnew_comment').lightbox_me({
		centered: true
	});

}

function doSubmitComment() 
{
	if ($('#author').val() == '')
	{
		showInputErrorClass('author', 'Field Personal Information is required. You can write your name, occupation, company.');
		return false;
	}
	if ($('#description').val() == '')
	{
		showInputErrorClass('description', 'Field Testimonial is required');
		return false;
	}
	var update = $("#update").val();
  	$.post("phplibs/send_comment.php", { update: update, idclient: $("#idclient").val(), author: $("#author").val(), description: $("#description").val() },
   	function(data){
		var myResponse = eval('(' + data + ')');
     	if (update == 'yes'){
			$("#dtestimonials").html(myResponse.testimonials);
		}
	    $('#dnew_comment').fadeOut('fast'); 
     	$("#messagebox").html(myResponse.html);
		$("#messagebox").attr('class', myResponse.status);
		$('#messagebox').lightbox_me({
			centered: true
		});
   	});
	return true;
}


function CloseFormComments(){

	$('.lb_overlay').fadeOut('slow'); 
    $('#dnew_comment').fadeOut('slow'); 
    return false;

}


function doSubmitContactForm() 
{
	if ($('#firstname').val() == '')
	{
		showInputErrorClass('firstname', 'Field First Name is required');
		return false;
	}
	if ($('#email').val() == '')
	{
		showInputErrorClass('email', 'Field Email is required');
		return false;
	}
	if (!validateEmail($('#email').val())) {
		showInputErrorClass('email', 'Please, enter a valid email address');
		return false;
	}   
	if ($('#subject').val() == '')
	{
		showInputErrorClass('subject', 'Field Subject is required');
		return false;
	}
	if ($('#message').val() == '')
	{
		showInputErrorClass('message', 'Field Message is required');
		return false;
	}
	
  	$.post("phplibs/send_contact.php", { firstname: $("#firstname").val(), lastname: $("#lastname").val(), email: $("#email").val(), subject: $("#subject").val(), message: $("#message").val() },
   	function(data){
		var myResponse = eval('(' + data + ')');
     	$("#messagebox").html(myResponse.html);
		$("#messagebox").attr('class', myResponse.status);
		$('#fContact')[0].reset();
		$('#messagebox').lightbox_me({
			centered: true
		});
   	});
	return true;
}


