var error_process = false; error_message = ''; wdiv_message = '#div_message_process'; wfrm_login = '#frm_login'; wfrm_data = '#frm_data'; wfrm_search = '#frm_search';
function open_chat ( u ) { window.open( u, '', 'toolbar=no,scrollbars=0,location=0,statusbar=0,status=0,menubar=0,resizable=0,width=452,height=335,left=140,top=25'); }
function aj_msg_error ( message ) {
    message = '<div class="message_error_process">' + message + '</div>';
	$( wdiv_message ).hide(); $( wdiv_message ).html( message ); $( wdiv_message ).show();
}
function aj_msg_info ( message ) {
    message = '<div class="message_info_process">' + message + '</div>';
	$( wdiv_message ).hide(); $( wdiv_message ).html( message ); $( wdiv_message ).show();
}

function aj_check_input ( field_name, field_size, message ) {
    var field_id = '#' + field_name;
    if ( ( $( field_id ).length > 0 ) && ( $( field_id ).is('hidden') == false ) ) {
        var field_value = $( field_id ).val();
        if ( field_value.length < field_size ) {
            error_process = true;
            error_message = error_message + '&#8226; ' + message + '<br />';
            aj_msg_error( error_message );
        }
    }
}
function aj_check_radio( field_name, message ) {
    var field_id = '#' + field_name; isChecked = false;
    if ( ( $( field_id ).length > 0 ) && ( $( field_id ).is('hidden') == false ) ) {
        var radio = form.elements[field_name];
        for ( var i=0; i<radio.length; i++ ) {
            if (radio[i].checked == true) {
                isChecked = true;
                break;
            }
        }
    if (isChecked == false) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}

/************************************************************************************/

function ajx_show_box_design () {
    if ( $('#div_list_product_design').length > 0 ) {
        $('#div_list_product_design').modal(
            { close: false,
              onShow: function ( dialog ) {
                var div_content = '<div id="div_list_product_design_content"><div id="list_content"></div></div>';
                div_content = div_content + '<div class="buttons">';
                div_content = div_content + '<a href="javascript:;" onclick="ajx_box_design_select();">' + lbl_set + '</a>';
                div_content = div_content + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                div_content = div_content + '<a href="javascript:;" onclick="ajx_box_design_cancel();">' + lbl_cancel + '</a>';
                div_content = div_content + '</div>';
                
                $('#div_list_product_design').html(div_content);
				$('.head_bar').html(div_content);
                ajx_load_design_categories( 1 );
              }
            }
        );
    }
}
function ajx_box_design_select() { if ( ajx_design_set() ) { ajx_design_pre_select(0); $.modal.close(); } }
function ajx_box_design_cancel() { ajx_design_pre_select(0); $.modal.close(); }
function ajx_load_design_categories ( p ) {
    var pd = $('#hPD').val();
    $('#list_content').fadeOut('fast', function() {
        $('#list_content').html( '<br/><span class="loading">' + msg_load + '</span>' );
        $('#list_content').fadeIn('fast',function(){
            $.ajax( { type: "POST",
                      url: ".ajx_design_category_list.php",
                      data: "pd=" + pd + "&p=" + p + "&nocache=" + Math.random() + "&control=sended",
                      success: function( rpta ) { $('#list_content').fadeOut('fast', function() { $('#list_content').html(rpta); $('#list_content').fadeIn('slow'); } ); }
            } );
        } )
    } )
}
function ajx_load_designs ( c, p ) {
    var pd = $('#hPD').val();
    $('#list_content').fadeOut( 'fast', function() {
        $('#list_content').html( '<br/><span class="loading">' + msg_load + '</span>' );
        $('#list_content').fadeIn( 'fast', function() {
            $.ajax( { type: "POST",
                      url: ".ajx_design_list.php",
                      data: "pd=" + pd + "&c=" + c + "&p=" + p + "&nocache=" + Math.random() + "&control=sended",
                      success: function( rpta ) { $('#list_content').fadeOut('fast', function() { $('#list_content').html(rpta); $('#list_content').fadeIn('slow'); } ); }
            } );
        } )
    } )
}
function ajx_design_pre_select( d ) {
    $('#hPD').val( d );
    if ( d > 0) {
        $('#ajbox_design_barr').fadeOut( 'fast', function() {
            $('#ajbox_design_barr').html( '&nbsp;' );
            $('#ajbox_design_barr').show( 'fast', function () {
                $.ajax( { type: "POST",
                          url: ".ajx_design_update.php",
                          data: "d=" + d + "&nocache=" + Math.random() + "&control=sended",
                          success: function( rpta ) {
                                $('#ajbox_design_barr').hide( 'fast', function() {
                                    $('#ajbox_design_barr').html(rpta); $('#ajbox_design_barr').fadeIn('slow');
                                } );
                          }
                } );
            } )
        } )
    }
}
function ajx_design_set () {
    var d = $('#hPD').val();
    if ( d == 0 ) { alert( msg_sd ); return false; }
    $.ajax( { type: "POST",
              url: ".ajx_design_set.php",
              data: "d=" + d + "&nocache=" + Math.random() + "&control=sended",
              success: function( rpta ) { $('#div_box_product_design').html(rpta); }
    } );
    return true;
}


/************************************************************************************/

function ajx_car_show_box_design( i, t ) {
    var hd = '#hd-' + i + '-' + t; pd = $(hd).val();
    if ( $('#div_list_product_design').length > 0 ) {
        $('#div_list_product_design').modal(
            { close: false,
              onShow: function ( dialog ) {
                var div_content = '<div id="div_list_product_design_content"><div id="list_content"></div></div>';
                div_content = div_content + '<div class="buttons">';
                div_content = div_content + '<a href="javascript:;" onclick="ajx_car_box_design_select(' + i + ',' + t + ');">' + lbl_set + '</a>';
                div_content = div_content + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                div_content = div_content + '<a href="javascript:;" onclick="ajx_car_box_design_cancel(' + i + ',' + t + ',' + pd + ');">' + lbl_cancel + '</a>';
                div_content = div_content + '</div>';
                
                $('#div_list_product_design').html(div_content);
                ajx_car_load_design_categories( i, t, 1 );
              }
            }
        );
    }
}
function ajx_car_box_design_select( i, t ) {
    if ( ajx_car_design_set( i, t ) ) $.modal.close();
}
function ajx_car_box_design_cancel( i, t, pd ) {
    ajx_car_design_pre_select( i, t, pd );
    $.modal.close();
}
function ajx_car_load_design_categories ( i, t, p ) {
    var hd = '#hd-' + i + '-' + t; pd = $(hd).val();
    
    $('#list_content').fadeOut('fast', function() {
        $('#list_content').html( '<br/><span class="loading">' + msg_load + '</span>' );
        $('#list_content').fadeIn('fast',function(){
            $.ajax( { type: "POST",
                      url: ".ajx_car_design_category_list.php",
                      data: "i=" + i + "&t=" + t + "&pd=" + pd + "&p=" + p + "&nocache=" + Math.random() + "&control=sended",
                      success: function( rpta ) { $('#list_content').fadeOut('fast', function() { $('#list_content').html(rpta); $('#list_content').fadeIn('slow'); } ); }
            } );
        } )
    } )
}
function ajx_car_load_designs ( i, t, c, p ) {
    var hd = '#hd-' + i + '-' + t; pd = $(hd).val();

    $('#list_content').fadeOut( 'fast', function() {
        $('#list_content').html( '<br/><span class="loading">' + msg_load + '</span>' );
        $('#list_content').fadeIn( 'fast', function() {
            $.ajax( { type: "POST",
                      url: ".ajx_car_design_list.php",
                      data: "i=" + i + "&t=" + t + "&pd=" + pd + "&c=" + c + "&p=" + p + "&nocache=" + Math.random() + "&control=sended",
                      success: function( rpta ) { $('#list_content').fadeOut('fast', function() { $('#list_content').html(rpta); $('#list_content').fadeIn('slow'); } ); }
            } );
        } )
    } )
}
function ajx_car_design_pre_select( i, t, d ) {
    var hd = '#hd-' + i + '-' + t;
    $(hd).val( d );
    if ( d > 0) {
        $('#ajbox_design_barr').fadeOut( 'fast', function() {
            $('#ajbox_design_barr').html( '&nbsp;' );
            $('#ajbox_design_barr').show( 'fast', function () {
                $.ajax( { type: "POST",
                          url: ".ajx_design_update.php",
                          data: "d=" + d + "&nocache=" + Math.random() + "&control=sended",
                          success: function( rpta ) {
                                $('#ajbox_design_barr').hide( 'fast', function() {
                                    $('#ajbox_design_barr').html(rpta); $('#ajbox_design_barr').fadeIn('slow');
                                } );
                          }
                } );
            } )
        } )
    }
}
function ajx_car_design_set ( i, t ) {
    var div_options = '#' + i + '_' + t +'_design_options'; div_code = '#' + i + '_' + t +'_design_code'; hd_name = '#hd-' + i + '-' + t;
    var d = $(hd_name).val();
    if ( d == 0 ) { alert( msg_sd ); return false; }
    $.ajax( { type: "POST", url: ".ajx_car_design_set.php", data: "d=" + d + "&nocache=" + Math.random() + "&control=sended", success: function( rpta ) { $(div_code).html(rpta); } } );
    $.ajax( { type: "POST", url: ".ajx_car_design_remove.php", data: "opt=add&i=" + i + "&t=" + t + "&nocache=" + Math.random() + "&control=sended", success: function( rpta ) { $(div_options).html(rpta); } } );
    return true;
}
function ajx_car_remove_design( i, t ) {
    var div_options = '#' + i + '_' + t +'_design_options'; div_code = '#' + i + '_' + t +'_design_code'; hd_name = '#hd-' + i + '-' + t;
    $(div_code).html('&nbsp;'); $(hd_name).val(0);
    $.ajax( { type: "POST", url: ".ajx_car_design_remove.php", data: "opt=del&i=" + i + "&t=" + t + "&nocache=" + Math.random() + "&control=sended", success: function( rpta ) { $(div_options).html(rpta); } } );
}
