// ===================================================================
// Customer Data
// ===================================================================

function submitCustomerData(idForm){
	
	$("#"+idForm).bind('submit', function(evt){

        $("#"+idForm+" span").each(function(index, el) {
        	if (el.id.length > 0)
        	{
	            $('#'+idForm+' #'+el.id).removeClass('error');        		
        	}
        });
        
        var count_errors = 0;
		
		$("#"+idForm+" *").each(function(index, el) 
		{
            if (el.id.length > 0)
            {
				if ($(el).css("display") != "none")
				{
	                if (el.type == 'text' ||  el.type == 'password' || el.type == 'checkbox' || el.type == 'textarea' || el.type == 'select-one') 
					{
						if ($(el).attr('rel') == 'required' && el.type == 'select-one' && $(el).val() == '0')
						{
		                    $('#'+idForm+' #span_'+el.id).addClass('error');
		                    count_errors++;
						}
						else if ($(el).attr('rel') == 'required' && el.type == 'checkbox')
						{
							if ($(el).is(':checked') == false) {
			                    $('#'+idForm+' #span_'+el.id).addClass('error');
			                    count_errors++;
							}
						}
						else if ($(el).attr('rel') == 'required' && $(el).val() == '') {
		                    $('#'+idForm+' #span_'+el.id).addClass('error');
		                    count_errors++;
						}
					}
				}
            	
            }
			
		});
		
        if (count_errors == 0)
        {
		
			dataToSend = '';
            numPar = 0;
			$("#"+idForm+" *").each(function(index, el){
				if (el.type == 'select-one' || el.type == 'password' || 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(""+idForm+""),
	  			url: '/ws/customer.php',
				data: dataToSend,
				dataType: "html",
				complete: function (data){
					stopLoading(""+idForm+"");
					$('#customerData').slideUp();
					$.scrollTo(0, 800);
				}
			});
        }
		else
        {
        	$.scrollTo(0, 800);
            return false;
        }
		return false;
	});
}





