function changeLanguage(lang){
		$('#bookApp_form').html('');
		$('#bookApp_form').load('form.php?lang='+lang);
}

function submitFunction() {
	/*
	 if ($("#input_firstName").val().length < 1 || $("#input_lastName").val().length < 1) {
	    $("#login_error").show();
	    $.fancybox.resize();
	    return false;
	}

	$.fancybox.showActivity();

	$.ajax({
		type		: "POST",
		cache	: false,
		url		: "/contact.php",
		data		: $(this).serializeArray(),
		success: function(data) {
			$.fancybox(data);
		}
	});
		      */


        $("#bookApp_form *").each(function(index, el) {
            $('#span_'+el.id).removeClass('error');
        });

		
        var count_errors = 0;
	var newsletterSubscription = false;
		
		$("#bookApp_form *").each(function(index, el) {
			if ( el.type == 'text' || el.type == 'checkbox' || el.type == 'textarea' || el.type == 'select-one' ) {
				if ($(el).attr('rel') == 'required' && $(el).val() == '') {
					//$('#errors').css('display', 'block');
				$('#span_'+el.id).addClass('error');
				count_errors++;
				}
				
				if ($(el).attr('rel') == 'required_email') {
					if ( !$(el).val().match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/) || $(el).val() == '' ) {
						//$('#errors').css('display', 'block');
					$('#span_'+el.id).addClass('error');
					count_errors++;
					}
				}
				
				if ($(el).attr('rel') == 'required_privacy') {
					if ( !el.checked ) {
						//$('#errors').css('display', 'block');
						$('#span_'+el.id).addClass('error');
						count_errors++;
					}
				}
				
				if ($(el).attr('rel') == 'required_newsletter') {
					if (el.checked ) {
						$newsletterSubscription = true;
					}
				}
				
				if ($(el).attr('rel') == 'required_date') {
					/*/^(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])-(19|20)\d\d\s\@\s([0-9]{1-2}:[0-9]{1-2}])$/*/
					if ( !$(el).val().match(/^\d\d-\d\d-\d\d\d\d\s@\s\d\d:\d\d$/) || $(el).val() == '' ) {
					//$('#errors').css('display', 'block');
					$('#span_'+el.id).addClass('error');
					count_errors++;
					}
				}
				
			}
		});
		
        if (count_errors > 0)
        {
            return false;
        }
		else
        {
			dataToSend = '';
            numPar = 0;
			$("#bookApp_form *").each(function(index, el){
				if (el.type == 'select-one' || el.type == 'text' || el.type == 'hidden' || el.type == 'textarea' || (el.type == 'checkbox' && el.checked)){
    				if ($(el).attr('rel') != 'not_post')
					{
					    if (numPar > 0) dataToSend += '&'
							    dataToSend += $(el).attr('name') + '=' + $(el).val();
					    numPar++;
					}
				}
			});
			
			$.ajax({
	  			type: "POST",
				beforeSend: startLoading("bookApp_form"),
	  			url: 'contacts.php',
				data: dataToSend,
				dataType: "html",
				complete: function (data){
					stopLoading("bookApp_form");
					if (data.responseText != "MailProblem")
					{
						$("#confirm_bookApp_form").css({"display":"block"});
						$("#bookApp_form fieldset").css({ "display":"none"});
						resetContacts('bookApp_form fieldset');
					}
					else
						{
						$("#bookApp_form").html('Error, appointment not comunicated to Steel And Style');
						}
				}
			});
		}
		return false;
}

function startLoading (idForm){ $("#loading_"+idForm).css({"display":"block"});}
function stopLoading (idForm){ $("#loading_"+idForm).css({"display":"none"});}
function resetContacts(idForm){
	$("#"+idForm+" *").each(function(index, el) {
            $('#span_'+el.id).removeClass('error');
	    $('#'+el.id).val('');
		//$('#errors').css('display', 'none');
        });
}

function datepickerCharge() {
	/*new Date(2009, 1 - 1, 26)*/
	$( "#datepicker" ).datetimepicker({ minDate: "10/21/2011", maxDate: "10/25/2011", separator: ' @ ', hour: 8, minute: 30, stepMinute: 15 , hourMin: 8, hourMax: 18, hourGrid: 2, minuteGrid: 15});
	$( "#datepicker" ).datetimepicker( "option", "dateFormat", "mm-dd-yy" );
	//$('#timepickr').timepickr({ });
}

