/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function do_validate_login(client_email, client_password)
{
    $('#button_validate_login').hide();
    $('#validating_login_progress_sign') .show();
    $('#error-heading-title_small').hide();
    $.post(
        '/client/account/do_validate_login',
        {
            'client_email' : client_email,
            'client_password' : client_password
        },
        function(data)
        {
            if(data['result'] === 'success')
                {
                    $('#error-heading-title_small').hide();
                    $('#validating_login_progress_sign') .hide();
                    $('#existing_customer_login').empty();
                    $('#existing_customer_login').html(
                        "<tr>"
                        +  '<td valign="middle" align="left" class="col-1 f"><div class="text">Welcome Back</div> </td>'
                        +  '<td valign="middle" align="left" class="col-1"><div class="text2"> ' + data['firstname'] + ' ' +  data['lastname']+'  ( ' + data['email'] + ' ) <br/> '+data['companyname']+ ' </div></td>'
                        +  '</tr>'
                    );
                }
            if(data['result'] === 'failed')
                {
                    $('#validating_login_progress_sign') .hide();
                    $('#error-heading-title_small').empty();
                    $('#error-heading-title_small').html('Invalid login, please try again!');
                    $('#error-heading-title_small').show();
                    $('#button_validate_login').show();
                }
        },
        'json'
    );
    //eof do_login

}

function populate_state(iso2_country_code )
{
    var the_country_iso2 = iso2_country_code ;
    $.post(
            '/client/account/do_get_state',
            {
                'the_country_iso2' : the_country_iso2
            },
            function(data)
            {
                $('#state_list').empty();
                $('#state_list').html(data);
            }
        );
}

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
function apply_coupon_voucher(action, coupon_voucher_code , url_string)
{
    //alert($action + '---' + $coupon_voucher_code + "--" + url_string);
    if($('#cart_summary_progress_sign').length)
        {
            $('#cart_summary_progress_sign').show();
     }
    $.post(
        url_string,
        {
            'action' : action,
            'coupon_code' : coupon_voucher_code
        },
        function (data)
        {
            //alert( data.indexOf( '300' ) );
            if( data.indexOf( '201_'  ) == 1 || data.indexOf( '201_'  ) == 0)
                {
                    data = data.replace('201_', '');
                    if($('#lh_cart').length != 0)
                        {
                                $('#lh_cart').empty();
                                $('#lh_cart').html(data);
                        }
                    $('#coupon_validation_message').empty();
                    $('#coupon_validation_message').html('<span style="color:red;">Invalid Coupon, please verify and try again</span> ');
                }
                else if( data.indexOf( '300_' ) == 1 || data.indexOf( '300_' ) == 0)
                {
                    data = data.replace('300_', '');
                    $('#coupon_validation_message').empty();
                    $('#coupon_validation_message').html('<span style="color:red;">Coupon is removed</span> ');
                    $('#coupon_voucher').attr('readonly', '');
                    $('#coupon_voucher').val('');
                    $('#coupon_voucher_action').val('apply');
                    $('#coupon_voucher_action').html('Validate');
                    if($('#lh_cart').length != 0)
                        {
                                $('#lh_cart').empty();
                                $('#lh_cart').html(data);
                        }
                }
                else
                    {
                        if($('#lh_cart').length != 0)
                        {
                                $('#lh_cart').empty();
                                $('#lh_cart').html(data);
                        }
                        $('#coupon_validation_message').empty();
                        $('#coupon_validation_message').html('<span style="color:#42732A;"></span> ');
                        $('#coupon_voucher').attr('readonly', 'readonly');
                        $('#coupon_voucher_action').val('remove');
                        $('#coupon_voucher_action').html('Remove');
                    }
                    
        }
    );
    
}


