/// コンテンツ閲覧画面_消しゴム書式オーバーレイ
/// <reference path="../common/js/avweb.js" />

/// <reference path="../common/js/screenLock.js" />

/// <reference path="../common/js/common.js" />

/// <reference path="../common/js/i18n.js" />

/// <reference path="../common/js/jquery-1.8.1.min.js" />

/// <reference path="../common/js/jquery-ui-1.8.23.custom.min.js" />

/// <reference path="../common/js/jquery.toastmessage.js" />

/// <reference path="../common/js/pageViewer.js" />

/// ===============================================================================================
/// Eraser group [start]
/// ===============================================================================================

// Show eraser
function ShowEraser(targetDiv) {
    
    //$('#dlgGomu').dialog("open");
    //$(".ui-dialog-titlebar").hide();
    //lockLayout();
    // $('#dlgGomu').fadeIn('medium', function(){
    	// $('#dlgGomu').draggable();
    // });
    $('#dlgGomu').show();
    $('#dlgGomu').draggable();
    Eraser_SetDefaultValue();
     $('#dlgGomu').center();
};
// Set default value for easer.
function Eraser_SetDefaultValue() {
    var typeValue = undefined;
    typeValue = ClientData.erase_size();
    if (typeValue == 5) {
        $("#dlgGomu_rdo1").attr('checked', 'checked');
        $("#dlgGomu_rdo1").focus();
    }
    else if (typeValue == 12.5) {
        $("#dlgGomu_rdo2").attr('checked', 'checked');
        $("#dlgGomu_rdo2").focus();
    }
    else if (typeValue == 25) {
        $("#dlgGomu_rdo3").attr('checked', 'checked');
        $("#dlgGomu_rdo3").focus();
    }
    else if (typeValue == 50) {
        $("#dlgGomu_rdo4").attr('checked', 'checked');
        $("#dlgGomu_rdo4").focus();
    }
    else {
        typeValue = 5;
        $("#dlgGomu_rdo1").attr('checked', 'checked');
        $("#dlgGomu_rdo1").focus();
    }
    dlgGomu_chooseType(typeValue);
};
// Choose type of eraser, and draw to canvas
function dlgGomu_chooseType(typeValue) {

    var canvas = document.getElementById('dlgGomu_cvMain');

    if (canvas.getContext) {
        
        // use getContext to use the canvas for drawing
        var ctx = canvas.getContext('2d');

        // Draw shapes
        ctx.fillStyle = "#888888";
        ctx.fillRect(0, 0, canvas.width, canvas.height);
        
        ctx.beginPath();
        //ctx.arc(60, 60, typeValue, 0, Math.PI * 2, true);  // Outer circle

        ctx.arc(canvas.width/2, canvas.height/2, typeValue, 0, 2 * Math.PI, true);
        ctx.fillStyle = "#ffffff";
        ctx.fill();
        ctx.stroke();

    }
};

function dlgGomu_rdo1_click() {
    dlgGomu_chooseType(5);
};
function dlgGomu_rdo2_click() {
    dlgGomu_chooseType(12.5);
};
function dlgGomu_rdo3_click() {
    dlgGomu_chooseType(25);
};
function dlgGomu_rdo4_click() {
    dlgGomu_chooseType(50);
};

// Event of button OK
function dlgGomu_dspOK_click() {

    // Set selected value to local storage
    var typeValue = undefined;

    if ($("#dlgGomu_rdo1").attr('checked') == 'checked') {
        typeValue = 5;
    }
    else if ($("#dlgGomu_rdo2").attr('checked') == 'checked') {
        typeValue = 12.5;
    }
    else if ($("#dlgGomu_rdo3").attr('checked') == 'checked') {
        typeValue = 25;
    }
    else if ($("#dlgGomu_rdo4").attr('checked') == 'checked') {
        typeValue = 50;
    }

    // Set value to local
    ClientData.erase_size(typeValue);
	eraseSize = typeValue;

    // Close dialog
    //$("#dlgGomu").dialog('close');
	/*$("#dlgGomu").fadeOut('medium', function(){
		//unlockLayout();
	});*/
	$("#dlgGomu").hide();
	
	/*enable button */
	enableButtonMarking();
	ClientData.IsAddingMarking(true);
	isAddingMarking = ClientData.IsAddingMarking();
	
	/* unlock dialog overlay */
	$("#overlay").hide();
	
	$('#dlgMarking_imgEraserOption').removeClass();
	$('#dlgMarking_imgEraserOption').addClass('eraser_option_hover');
};
// Event of button cancel
function dlgGomu_dspCancel_click() {

    // Close dialog
    //$("#dlgGomu").dialog('close');
	/*$("#dlgGomu").fadeOut('medium', function(){
		//unlockLayout();
	});*/
	$("#dlgGomu").hide();
	
	/*enable button */
	enableButtonMarking();
	ClientData.IsAddingMarking(true);
	isAddingMarking = ClientData.IsAddingMarking();
	
	/* unlock dialog overlay */
	$("#overlay").hide();
	
	$('#dlgMarking_imgEraserOption').removeClass();
	$('#dlgMarking_imgEraserOption').addClass('eraser_option_hover');
};

function dlgGomu_rdo1_text_click(){
	$('#dlgGomu_rdo1').attr('checked','checked');
	$('#dlgGomu_rdo2').removeAttr('checked');
	$('#dlgGomu_rdo3').removeAttr('checked');
	$('#dlgGomu_rdo4').removeAttr('checked');
	dlgGomu_rdo1_click();
};

function dlgGomu_rdo2_text_click(){
	$('#dlgGomu_rdo1').removeAttr('checked');
	$('#dlgGomu_rdo2').attr('checked','checked');
	$('#dlgGomu_rdo3').removeAttr('checked');
	$('#dlgGomu_rdo4').removeAttr('checked');
	dlgGomu_rdo2_click();
};

function dlgGomu_rdo3_text_click(){
	$('#dlgGomu_rdo1').removeAttr('checked');
	$('#dlgGomu_rdo2').removeAttr('checked');
	$('#dlgGomu_rdo3').attr('checked','checked');
	$('#dlgGomu_rdo4').removeAttr('checked');
	dlgGomu_rdo3_click();
};

function dlgGomu_rdo4_text_click(){
	$('#dlgGomu_rdo1').removeAttr('checked');
	$('#dlgGomu_rdo2').removeAttr('checked');
	$('#dlgGomu_rdo3').removeAttr('checked');
	$('#dlgGomu_rdo4').attr('checked','checked');
	dlgGomu_rdo4_click();
};
/*
----------------------------------------------------------------------------
Event groups [start]
----------------------------------------------------------------------------
*/


/*
----------------------------------------------------------------------------
Event groups [ end ]
----------------------------------------------------------------------------
*/


function touchStart_BtnOk_Gomu(e){
	e.preventDefault();
	$('#dlgGomu').draggable("destroy");
	
	
	dlgGomu_dspOK_click();
	
};

function touchStart_BtnCancel_Gomu(e){
	e.preventDefault();
	$('#dlgGomu').draggable("destroy");
	
	dlgGomu_dspCancel_click();
};

// Setting dialog
$(function () {
    // ---------------------------------
    // Setup for easer [start]
    // ---------------------------------
	if(isTouchDevice() == true){
		document.getElementById('dlgGomu_dspOK').addEventListener('touchstart',touchStart_BtnOk_Gomu,false);
	 	document.getElementById('dlgGomu_dspCancel').addEventListener('touchstart',touchStart_BtnCancel_Gomu,false);
	}
	
	
    $("#dlgGomu_dspOK").click(dlgGomu_dspOK_click);
    $("#dlgGomu_dspCancel").click(dlgGomu_dspCancel_click);

    // Event for radio
    $("#dlgGomu_rdo1").click(dlgGomu_rdo1_click);
    $("#dlgGomu_rdo2").click(dlgGomu_rdo2_click);
    $("#dlgGomu_rdo3").click(dlgGomu_rdo3_click);
    $("#dlgGomu_rdo4").click(dlgGomu_rdo4_click);
    
    // $("#dlgGomu_rdo1_text").click(dlgGomu_rdo1_text_click);
    // $("#dlgGomu_rdo2_text").click(dlgGomu_rdo2_text_click);
    // $("#dlgGomu_rdo3_text").click(dlgGomu_rdo3_text_click);
    // $("#dlgGomu_rdo4_text").click(dlgGomu_rdo4_text_click);

	//$('#dlgGomu_rdo1_text').click()
    // ---------------------------------
    // Setup for easer [ end ]
    // ---------------------------------
    /*$('#dlgGomu').dialog({
        autoOpen: false,
        title: i18nText('txtDltOpt'),
        modal: true,
        resizable: false,
        width: 450,
        height: 300
    });*/
});

/// ===============================================================================================
/// Eraser group [ end ]
/// ===============================================================================================