function CreditCardNew(){

    this.bgUploadted = false;
    
    this.doCommit = function() {
      
      var swap_action  = $('image_form').action;
      var swap_onsubmit =  $('image_form').onsubmit;
      
      $('image_form').action = '/new/publish';
      $('image_form').onsubmit = '';
      $('image_form').submit();
      $('image_form').action = swap_action;
      $('image_form').onsubmit = swap_onsubmit;
    }
    
    this.showPrice = function(){
        alert(price);
    };
    
    this.updateBackgroundNoContent = function(){
        if (ccnew.bgUploadted == false) {
            this.updateBackgroundFailure();
        }
    };
    
    this.updateBackgroundSuccess = function(imageTag, fileID){
				
        ccnew.bgUploadted = true;
        $('background').innerHTML = imageTag;
        $('form_bg_id').value = fileID;
        
        setTimeout(function(){
            ccnew.newCropper();
        }, 500);
    };
    
    this.updateBackgroundFailure = function(){
    
        ccnew.bgUploadted = true;
        $('background').innerHTML = '背景画像のアップロードに失敗しました。2M以下の画像ファイルのみアップロード可能です。';
    };
    
    this.updateBackgroundBefore = function(button){
        this.bgUploadted = false;
        this.beDisable(button);
        this.showProgressIndicator('background');
    };
    
    this.updatePreviewBefore = function(){
        this.beDisable('form_submit');
        this.showProgressIndicator('preview');
    };
    
    this.showProgressIndicator = function(target){
        $(target).innerHTML = "<img src='/images/ajax-loader.gif' />";
    };
    
    this.beDisable = function(target){
        $(target).disable();
        setTimeout(function(){
            $(target).enable()
        }, 6000);
    };
    this.newCropper = function(){
    
        this.cropper = new Cropper.Img("bg_image", {
            ratioDim: {
                x: 250,
                y: 158
            },
            displayOnInit: true,
            minWidth: 250,
            minHeight: 158,
            onEndCrop: function(coords, dimensions){
                $('form_bg_x').value = coords.x1;
                $('form_bg_y').value = coords.y1;
                $('form_bg_width').value = dimensions.width;
                $('form_bg_height').value = dimensions.height;
            }
        });
    };
    
    this.initColorPickers = function(){
    
        new Control.ColorPicker("form_arrow_options_fill", {
            "swatch": "form_arrow_options_fill_colorbox"
        });
        new Control.ColorPicker("form_arrow_options_stroke", {
            "swatch": "form_arrow_options_stroke_colorbox"
        });
        
        new Control.ColorPicker("form_brand_options_fill", {
            "swatch": "form_brand_options_fill_colorbox"
        });
        new Control.ColorPicker("form_brand_options_stroke", {
            "swatch": "form_brand_options_stroke_colorbox"
        });
        
        new Control.ColorPicker("form_strings_card_holder_name_options_stroke", {
            "swatch": "form_strings_card_holder_name_options_stroke_colorbox"
        });
        new Control.ColorPicker("form_strings_card_holder_name_options_fill", {
            "swatch": "form_strings_card_holder_name_options_fill_colorbox"
        });
        
        new Control.ColorPicker("form_strings_credit_card_number_options_stroke", {
            "swatch": "form_strings_credit_card_number_options_stroke_colorbox"
        });
        new Control.ColorPicker("form_strings_credit_card_number_options_fill", {
            "swatch": "form_strings_credit_card_number_options_fill_colorbox"
        });
        
        new Control.ColorPicker("form_strings_credit_card_first_4_number_options_stroke", {
            "swatch": "form_strings_credit_card_first_4_number_options_stroke_colorbox"
        });
        new Control.ColorPicker("form_strings_credit_card_first_4_number_options_fill", {
            "swatch": "form_strings_credit_card_first_4_number_options_fill_colorbox"
        });
        
        new Control.ColorPicker("form_strings_expiry_date_options_stroke", {
            "swatch": "form_strings_expiry_date_options_stroke_colorbox"
        });
        new Control.ColorPicker("form_strings_expiry_date_options_fill", {
            "swatch": "form_strings_expiry_date_options_fill_colorbox"
        });
        
        new Control.ColorPicker("form_strings_expiry_date_top_header_options_stroke", {
            "swatch": "form_strings_expiry_date_top_header_options_stroke_colorbox"
        });
        new Control.ColorPicker("form_strings_expiry_date_top_header_options_fill", {
            "swatch": "form_strings_expiry_date_top_header_options_fill_colorbox"
        });
        
        new Control.ColorPicker("form_strings_valid_true_options_stroke", {
            "swatch": "form_strings_valid_true_options_stroke_colorbox"
        });
        new Control.ColorPicker("form_strings_valid_true_options_fill", {
            "swatch": "form_strings_valid_true_options_fill_colorbox"
        });
        
        new Control.ColorPicker("form_strings_card_brand_name_options_stroke", {
            "swatch": "form_strings_card_brand_name_options_stroke_colorbox"
        });
        new Control.ColorPicker("form_strings_card_brand_name_options_fill", {
            "swatch": "form_strings_card_brand_name_options_fill_colorbox"
        });
        
        new Control.ColorPicker("form_strings_corporation_symbol_options_stroke", {
            "swatch": "form_strings_corporation_symbol_options_stroke_colorbox"
        });
        new Control.ColorPicker("form_strings_corporation_symbol_options_fill", {
            "swatch": "form_strings_corporation_symbol_options_fill_colorbox"
        });
        
        new Control.ColorPicker("form_strings_service_logo_options_stroke", {
            "swatch": "form_strings_service_logo_options_stroke_colorbox"
        });
        new Control.ColorPicker("form_strings_service_logo_options_fill", {
            "swatch": "form_strings_service_logo_options_fill_colorbox"
        });
    };
    this.init = function(){
        setTimeout(function(){
            ccnew.initColorPickers();
        }, 5000);
    };
}

var ccnew = new CreditCardNew();

