﻿
Prototype(document).ready(function() {

if (Prototype("body").html().indexOf(AlertMessage()) == -1) {
    Prototype("body").append(AlertMessage());
    }

});

function alertMessage(obj, msg) {
    var alertDiv = Prototype("#alertMsg");
    alertDiv.css("top", obj.offset().top + obj.height() + 5 + "px");
    alertDiv.css("left", obj.offset().left + "px");
    alertDiv.css("zIndex", 1000);
    alertDiv.html(msg);
    alertDiv.show();

    initAlertMsg();

    obj.bind("onblur", function() {
        alertDiv.css("display", "none");
        Prototype("#alertMsgFrame").css("display", "none");
        Prototype("#alertMsgFrame").remove();
    });

    obj.focus();
}
function iframeDecorateDiv(divId, iframId) {
    if (Prototype.browser.msie && Prototype.browser.version < 7) {

        if (Prototype("#" + divId + " > iframe").length > 0) {
            return;
        }

        var div = Prototype("#" + divId);
        var divIframe = Prototype('<iframe/>');

        div.append(divIframe);
        if (iframId) {
            divIframe.attr("id", iframId);
        }
        divIframe.css("position", "absolute");
        divIframe.css("display", "none");
        divIframe.css("display", "block");
        divIframe.css("z-index", "-1");
        divIframe.css("top", "-2");
        divIframe.css("left", "-2");
        try {
            divIframe.css("width", div.width() + parseInt(div.css("padding")) * 2 + 4 + "px");
            divIframe.css("height", div.height() + parseInt(div.css("padding")) * 2 + 4 + "px");
        } catch (e) {
        }
        divIframe.css("filter", "mask(color=#a09261)");
    }
}
function initAlertMsg() {
    if (Prototype.browser.msie) {
        iframeDecorateDiv("alertMsg", "alertMsgFrame");
    }

    document.body.onmousedown = function() {
    Prototype("#alertMsg").css("display", "none");
    Prototype("#alertMsgFrame").css("display", "none");
    Prototype("#alertMsgFrame").remove();
    }
}
function showMoreInfo(target, popBoxId) {
    if (Prototype('#' + popBoxId).html()) {
        Prototype('#' + popBoxId).css('top', Prototype(target).offset().top + Prototype(target).height());
        Prototype('#' + popBoxId).css('left', Prototype(target).offset().left);
        Prototype('#' + popBoxId).show();
    }
}

var AlertMessage = function() {
    var div = "<div id=\"alertMsg\" style=\"z-index: 99999; margin: 0px; padding: 10px; font-size: 12px; text-align: left; background: #FFFFE8; border: 1px solid #FFDF47; color: #000;  white-space: nowrap; position: absolute; display: none;\">" +
         " </div>";
    return div;
}

var StringUtils = {};
StringUtils.isBlank = function(value) {
var trimValue = Prototype.trim(value);
    return trimValue == "";
};
StringUtils.IsMobile = function(value) {
    var reg = /^[1][3,5,8][0-9]{9}$/;
    return reg.test(value);
};
StringUtils.isEmail = function(value) {
var trimValue = Prototype.trim(value);
    if (trimValue == "")
        return true;
    var reg = /^\b(^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-])+(\.[A-Za-z0-9-]+)*((\.[A-Za-z0-9]{2,})|(\.[A-Za-z0-9]{2,}\.[A-Za-z0-9]{2,}))$)\b$/;
    return reg.test(trimValue);
};
var DateUtils = {};
DateUtils.convertStringToDate = function(date) {
    if (typeof (date) == 'string') {
        date = new Date(date.replace(/-/g, '/'));
    }
    return date;
}
DateUtils.dateAfter = function(d1, d2) {
    return Date.parse(this.convertStringToDate(d1)) - Date.parse(this.convertStringToDate(d2)) > 0;
}
var Prototyped = document.getElementById;

var mid = "ctl00_ContentMain_";

var CheckLogin = function() {

if (Prototype("#" + mid + "txtUserName").val() == 'カード番号/メールアドレス/（中国の）携帯番号') {

    alertMessage(Prototype("#" + mid + "txtUserName"), "会員番号を記入ください。");

    if (Prototype.browser.msie) {
        Prototyped("" + mid + "txtUserName").focus();
        }

        return false;
    }
    if (StringUtils.isBlank(Prototype("#" + mid + "txtpwd").val())) {

        alertMessage(Prototype("#" + mid + "txtpwd"), "パスワードをご記入ください。");
        if (Prototype.browser.msie) {
            Prototyped("" + mid + "txtpwd").focus();
        }

        return false;
    }

    return true;
}


var CheckSMS = function() {

if (StringUtils.isBlank(Prototype("#" + mid + "txtUsername").val())) {

    alertMessage(Prototype("#" + mid + "txtUsername"), "お名前ご記入ください。!");

    if (Prototype.browser.msie) {
        Prototyped("" + mid + "txtUsername").focus();
        }
        return false;
    }
    if (StringUtils.isBlank(Prototype("#" + mid + "txtMobile").val()) || !isMobile(Prototype("#" + mid + "txtMobile").val())) {

        alertMessage(Prototype("#" + mid + "txtMobile"), "正しい中国の携帯電話番号をご記入ください。");

        if (Prototype.browser.msie) {
            Prototyped("" + mid + "txtMobile").focus();
        }
        return false;
    }
    return true;
}

var CheckEmail = function() {

if (StringUtils.isBlank(Prototype("#" + mid + "txtName").val())) {

    alertMessage(Prototype("#" + mid + "txtName"), "お名前ご記入ください!");

    if (Prototype.browser.msie) {
        Prototyped("" + mid + "txtName").focus();
        }
        return false;
    }
    if (StringUtils.isBlank(Prototype("#" + mid + "txtEmaill").val()) || !validate(Prototype("#" + mid + "txtEmaill").val(), "Email", "")) {

        alertMessage(Prototype("#" + mid + "txtEmaill"), "正しいメールアドレスをご記入ください。");

        if (Prototype.browser.msie) {
            Prototyped("" + mid + "txtEmaill").focus();
        }
        return false;
    }
    return true;

}
