/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$().ready(function()
{
    var options = {
        target:        '#output2',   // target element(s) to be updated with server response
        beforeSubmit:  Validate,  // pre-submit callback
        success:       showResponse,  // post-submit callback
        timeout:   3000,
        dataType:  'html'
    };

    // bind to the form's submit event
    $('form').submit(function() {

        $(this).ajaxSubmit(options);

        return false;
    });
    $('#order').click(function()
    {
        $('div[class*=msg]').hide();
        $(this).submit()
    });
});
function Validate(formData, jqForm, options)
{
    $('.category:hidden').remove();
    var transport = $('#transport').val();
    var count = $('.count:visible').val() ? $('.count:visible').val() : 0 ;
    var size_x = $('.size_x:visible').val() ? $('.size_x:visible').val() : 0;
    var size_y = $('.size_y:visible').val() ? $('.size_y:visible').val() : 0;
    var size_z = $('.size_z:visible').val() ? $('.size_z:visible').val() : 0;
    var kind_name = $('.kind :selected').text();
    var category_name = $('#category :selected').text();
    var whole_price = $('#whole_price').val();
   
    formData.push({'name':'transport', 'value' : transport});
    formData.push({'name':'whole_price', 'value' : whole_price});
    formData.push({'name':'count', 'value' : count});
    formData.push({'name':'size_x', 'value' : size_x});
    formData.push({'name':'size_y', 'value' : size_y});
    formData.push({'name':'size_z', 'value' : size_z});
    formData.push({'name':'kind_name', 'value' : kind_name});
    formData.push({'name':'category_name', 'value' : category_name});

    error = 0;
    $('div[class*=client] :input[class*=req]').each(function(){
       if($(this).val().length == 0)
       {
           $('div[class*=msg]').fadeIn();
           error = 1;
       }
    });
    return (!error);
    
}
function showResponse()
{
    
    $('.content:lt(2)').each(function(){$(this).remove()});
    $('#thx').fadeIn();
}

