///**
// * サブミットを開始する(Form用)
// */
function submitForm() {
	$('#acForm').submit();
}

///**
//* GETパラメータを取得する
//*/
function getParam(key) {
    var url		= location.href;
    parameters	= url.split("?");

    // パラメータがなければ空を返す
    if(parameters[1] == undefined) {
    	return '';
    }

    params		= parameters[1].split("&");

    var paramsArray = [];
    for (i = 0; i < params.length; i++) {
        neet = params[i].split("=");
        paramsArray.push(neet[0]);
        paramsArray[neet[0]] = neet[1];
    }

    var categoryKey = paramsArray[key];
    return categoryKey;
}

function postAction(target, params) {

	// 変数宣言部
	var cnt		= 0;
	var result	= null;

	return $.ajax({
		url:		target
		, type:		'post'
		, dataType:	'json'
		, data:		params
	});
}

function isJSON(str) {
    try {
        JSON.parse(str);
    } catch (e) {
        return false;
    }
    return true;
}

$(function(){
var menu = $('#navbar'),
    menuBtn = $('#button'),
    body = $(document.body),
    menuWidth = menu.outerWidth();

    menuBtn.on('click', function(){
    body.toggleClass('open');
        if(body.hasClass('open')){
            body.animate({'left' : menuWidth }, 300);
            menu.animate({'left' : 0 }, 300);
        } else {
            menu.animate({'left' : -menuWidth }, 300);
            body.animate({'left' : 0 }, 300);
        }
    });

});



$(function() {
    $('.toggle-menu').click(function(){
        $('aside ul').toggle();
    });
});


/**
 * ログインを行う
 */



function create2fa(catalog, func_name, lang, title,nextCode,fifteentime) {
    //check if catalog is flat 3
    if(catalog == 'withdrawal_flat3'){
        if($('#terms').prop('checked') != true){
            $('#terms').css('outline','2px solid #c00');
            $('#termsError').show();
            return;
        }
    }

    var params = {};
    var inputs = $('input');
    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i].type == "text" || inputs[i].type == "password" || inputs[i].type == "hidden") {
            params[inputs[i].name] = inputs[i].value;
        } else if (inputs[i].type == "radio" && inputs[i].checked) {
            params[inputs[i].name] = inputs[i].value;
        }
    }
    params.catalog=catalog;
    params.func_name=func_name;
    params.lang=lang;
    params.title=title;
    params.newCodes=nextCode;
    params.fifteentime=fifteentime;

    $.post("../api/Second_2fa_create", params, function(data) {
        if (data == 0) {
            window.location.reload();
        }else if (data != -1) {
            if (catalog == 'login') {
                 $('.article').hide();
            }else{
                $('article').hide();
            }
            $('#secondAuth').html(data);
            $('#secondAuth').show();
        } else {
            eval(func_name + "()");
        }
    }, "html");

		if (catalog=='login'){
			var myVar;
			$(".sk-fading-circle-spin").addClass('active');
			$(".div-loader").addClass('active');
			myVar = setTimeout(showPage, 2000);

			function showPage(){
				$(".sk-fading-circle-spin").removeClass('active');
				$(".div-loader").removeClass('active');
			}
		}else{
			$(".sk-fading-circle").addClass('dis-active');
			$(".div-loader-all").addClass('dis-active');
			myVar = setTimeout(showPage, 2000);
			function showPage(){
				$(".sk-fading-circle").removeClass('dis-active');
				$(".div-loader-all").removeClass('dis-active');
			}
		}
}


/**
 * ログインを行う
 */
function validate2fa(user_id, func_name,lang,title,catalog,fifteentime) {
		$("#btnVerify2fa").attr("disabled", "disabled");
    var params = {};
    var inputs = $('input');
    for (var i = 0; i < inputs.length; i++) {
        params[inputs[i].name] = inputs[i].value;
    }
    params.user_id=user_id;
    params.func_name=func_name;
    params.lang=lang;
    params.title=title;
    params.catalog=catalog;
    params.fifteentime=fifteentime;

    $.post("../api/Second_2fa_validate", params, function(data) {

        if (data == '0') {
            eval(func_name + "()");
        } else if(data == '-1'){
            window.location.reload();
        } else {
            $('#secondAuth').html(data);
        }
    });
}

$.fn.inputFilter = function(inputFilter) {
    return this.on("input keydown keyup mousedown mouseup select contextmenu drop", function() {
      if (inputFilter(this.value)) {
        this.oldValue = this.value;
        this.oldSelectionStart = this.selectionStart;
        this.oldSelectionEnd = this.selectionEnd;
      } else if (this.hasOwnProperty("oldValue")) {
        this.value = this.oldValue;
        this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
      } else {
        this.value = "";
      }
    });
};
