//--------------------------------------------------------------------------------------------------
/**
 * 共通関数
 */

/**
 * 全画面に戻る
 */
function backWindow() {
    if(navigator.appName.charAt(0) == "N"){
        window.back();
    }else{
        history.back();
    }
}

/**
 * 文字列の長さを取得
 */
function getLength(moji) {
    var i,cnt = 0;
    for(i=0; i<moji.length; i++) {
        if (escape(moji.charAt(i)).length >= 4 ) cnt+=2;
        else cnt++;
    }
    return cnt;
}



/**
 * 文字列のトリム処理
 */
function trim(strData) {
    var strBuff = strData;
    var str     = "";

    while (strBuff.indexOf(' ') == 0 || strBuff.indexOf('　') == 0) {
        strBuff = strBuff.substr(1, strBuff.length);
    }

    if (strBuff.length > 0) {
        while (strBuff.lastIndexOf(' ') == strBuff.length - 1 || strBuff.lastIndexOf('　') == strBuff.length - 1) {
            strBuff = strBuff.substr(0, strBuff.length - 1);
        }
    }

    /* 改行文字の除去 */
    for(i=0; i<strBuff.length; i++) {
        if (escape(strBuff.charAt(i)) == "%0D" || escape(strBuff.charAt(i)) == "%0A") {
        } else {
            str = str + strBuff.charAt(i);
        }
    }

    return str;
}

/**
 * 文字列が半角英数かをチェックする
 */
function hankakuCheck(str){
  okstr = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

  err = 0;
  for (i=0;i<str.length;i++){
    if (okstr.indexOf(str.charAt(i)) == -1) err++;
  }

  if (err!=0) return false;
  else return true;
}

/**
 * jpg,jpegファイルの拡張子をチェックする
 */
function checkExtensionJpeg(filename) {
    point = filename.lastIndexOf(".");
    if (point != -1) {
        FExe = filename.substr(point);
        FExe = FExe.toLowerCase();
        if (FExe != ".jpg" && FExe != ".jpeg") return false;
        return true;
    } else {
        return false;
    }
}

/**
 * 文字列が半角英数かをチェックする
 */
function hankakuCheck(str){
  okstr = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

  err = 0;
  for (i=0;i<str.length;i++){
    if (okstr.indexOf(str.charAt(i)) == -1) err++;
  }

  if (err!=0) return false;
  else return true;
}

//--------------------------------------------------------------------------------------------------
/**
 * ログイン関連
 */

/**
 * IDとパスワードをチェック
 */
function loginCheck() {
    var id = trim(document.form1.id.value);
    var pw = trim(document.form1.pw.value);

    if (id == "") {
        alert('IDを入力して下さい');
        return;
    }

    if (pw == "") {
        alert('パスワードを入力して下さい');
        return;
    }
    document.form1.submit();
}

//--------------------------------------------------------------------------------------------------
/**
 * ID/パスワード管理関連
 */

/**
 * ID/パスワード管理チェック
 */
function adminUpCheck() {
    var id       = trim(document.form1.id.value);
    var password = trim(document.form1.pw.value);

    if (id == "") {
        alert('IDを入力して下さい');
        return;
    }

    if (hankakuCheck(id) == false) {
        alert('IDは半角英数字で入力して下さい');
        return;
    }

    if (getLength(id) > 9 || getLength(id) < 6) {
        alert('IDは半角英数字で6〜9文字で入力して下さい');
        return;
    }

    if (password == "") {
        alert('パスワードを入力して下さい');
        return;
    }

    if (hankakuCheck(password) == false) {
        alert('パスワードは半角英数字で入力して下さい');
        return;
    }

    if (getLength(password) > 9 || getLength(password) < 6) {
        alert('パスワードは半角英数字で6〜9文字で入力して下さい');
        return;
    }

    if (confirm("ID/パスワードを変更しますか？") == false) {
        return;
    }

    document.form1.submit();
}

//--------------------------------------------------------------------------------------------------
/**
 * カテゴリ情報関連
 */

/**
 * カテゴリ新規登録時のチェック
 */
function addCategory() {
    var name = trim(document.form1.name.value);

    if (name == "") {
        alert('カテゴリ名を入力して下さい');
        return;
    }

    if (getLength(name) > 20) {
        alert('カテゴリ名は全角10文字以内で入力して下さい');
        return;
    }

    if (confirm("カテゴリを登録しますか？") == false) {
        return;
    }

    document.form1.flag.value = 1;
    document.form1.submit();
}

/**
 * カテゴリ編集時のチェック
 *
 * @param id    カテゴリID
 *        name  カテゴリ名
 *        oname 前回のカテゴリ名
 */
function updateCategory(id, name, oname) {
    if (trim(name) == "") {
        name = oname;
    }

    if (getLength(trim(name)) > 20) {
        alert('カテゴリ名は全角10文字以内で入力して下さい');
        return;
    }

    if (confirm("カテゴリを更新しますか？") == false) {
        return;
    }

    document.form2.flag.value = 2;
    document.form2.upid.value = id;
    document.form2.upname.value = name;
    document.form2.submit();
}

/**
 * カテゴリ削除時の確認
 */
function delCategory() {
    var f = document.form2;
    var i;
    var obj;
    var selected = false;

    for (i=0;(obj=f.elements[i]) != null;i++) {
        if ((f.elements[i].name).length > 10) {
            if ((f.elements[i].name).substr(0, 10) == "categoryid" && f.elements[i].checked==true) {
                selected = true;
                break;
            }
        }
    }

    if (selected == false) {
        alert('カテゴリを選択して下さい');
        return;
    }

    if (confirm("カテゴリを削除しますか？") == false) {
        return;
    }

    f.flag.value = 3;
    f.submit();
}

//--------------------------------------------------------------------------------------------------
/**
 * 観光情報関連
 */

/**
 * 観光情報登録・編集チェック
 */
function sightSeeAddCheck() {
    var areaid      = trim(document.form1.areaid.value);
    var name        = trim(document.form1.name.value);
    var address     = trim(document.form1.address.value);
    var newcomments = trim(document.form1.newcomments.value);
    var comments1   = trim(document.form1.comments1.value);
    var comments2   = trim(document.form1.comments2.value);
    var picture     = trim(document.form1.picture.value);

    if (areaid == "0") {
        alert('所在地を選択して下さい');
        return;
    }

    if (name == "") {
        alert('観光地名を入力して下さい');
        return;
    }

    if (getLength(name) > 60) {
        alert('観光地名は全角30文字以内で入力して下さい');
        return;
    }

    if (address == "") {
        alert('住所を入力して下さい');
        return;
    }

    if (getLength(address) > 200) {
        alert('住所は全角100文字以内で入力して下さい');
        return;
    }

    if (getLength(newcomments) > 60) {
        alert('新着コメントは全角30文字以内で入力して下さい');
        return;
    }

    if (comments1 == "") {
        alert('簡易コメントを入力して下さい');
        return;
    }

    if (getLength(comments1) > 50) {
        alert('簡易コメントは全角25文字以内で入力して下さい');
        return;
    }

    if (comments2 == "") {
        alert('詳細コメントを入力して下さい');
        return;
    }

    if (getLength(comments2) > 600) {
        alert('詳細コメントは全角300文字以内で入力して下さい');
        return;
    }

    if(picture != "" && getLength(picture.substring(picture.lastIndexOf("\\")+1,picture.length)) > 200) {
        alert("写真の画像ファイル名は半角200文字以内で入力して下さい");
        return;
    }

    if(picture != "") {
        if(checkExtensionJpeg(picture) == false) {
            alert("画像ファイルはJPEG形式しかサポートしていません");
            return;
        }
    }

    if (confirm("観光情報を登録しますか？") == false) {
        return;
    }

    document.form1.submit();
}

/**
 * 観光情報削除時の確認
 */
function delSightSee() {
    var f = document.form1;
    var i;
    var obj;
    var selected = false;

    for (i=0;(obj=f.elements[i]) != null;i++) {
        if ((f.elements[i].name).length > 10) {
            if ((f.elements[i].name).substr(0, 10) == "sightseeno" && f.elements[i].checked==true) {
                selected = true;
                break;
            }
        }
    }

    if (selected == false) {
        alert('観光情報を選択して下さい');
        return;
    }

    if (confirm("観光情報を削除しますか？") == false) {
        return;
    }

    f.flag.value = 3;
    f.submit();
}

//--------------------------------------------------------------------------------------------------
/**
 * イベント情報関連
 */

/**
 * イベント情報登録・編集チェック
 */
function eventAddCheck(num) {
    var name        = trim(document.form1.name.value);
    var address     = trim(document.form1.address.value);
    var year        = trim(document.form1.year.value);
    var month       = trim(document.form1.month.value);
    var date        = trim(document.form1.date.value);
    var between     = trim(document.form1.between.value);
    var newcomments = trim(document.form1.newcomments.value);
    var comments    = trim(document.form1.comments.value);
    var password    = trim(document.form1.password.value);
    var picture     = trim(document.form1.picture.value);

    if (name == "") {
        alert('イベント名を入力して下さい');
        return;
    }

    if (getLength(name) > 80) {
        alert('イベント名は全角40文字以内で入力して下さい');
        return;
    }

    if (address == "") {
        alert('開催場所を入力して下さい');
        return;
    }

    if (getLength(address) > 200) {
        alert('開催場所は全角100文字以内で入力して下さい');
        return;
    }

    if (year == "0") {
        alert('開催年を選択して下さい');
        return;
    }

    if (month == "0") {
        alert('開催月を選択して下さい');
        return;
    }

    if (date == "0") {
        alert('開催日を選択して下さい');
        return;
    }

    if (between == "0") {
        alert('開催日数を選択して下さい');
        return;
    }

//    if(month < 10) {
//        month = "0" + month;
//    }

//    if(date < 10) {
//        date = "0" + date;
//    }

//    var day = year + month + date;

    /* 以下、本日の日付文字列を作成します */
//    now	     = new Date;
//    nowYear  = new String(now.getFullYear());
//    nowMonth = new String(now.getMonth()+1);
//    nowDate  = new String(now.getDate());

//    var strDate = nowYear;

    /* 今日の"月"を取得 */
//    if((now.getMonth()+1) < 10) {
//        strDate = strDate + "0" + nowMonth;
//    } else {
//        strDate = strDate + nowMonth;
//    }

    /* 今日の"日"を取得 */
//    if(now.getDate() < 10) {
//        strDate = strDate + "0" + nowDate;
//    } else {
//        strDate = strDate + nowDate;
//    }

    /* 今日の日付より開始日が前だったらエラー */
//    if(day < strDate ) {
//        alert("開催日は本日以降の日付を入力して下さい。");
//        return;
//    }

    if (getLength(newcomments) > 60) {
        alert('新着コメントは全角30文字以内で入力して下さい');
        return;
    }

    if (comments == "") {
        alert('コメントを入力して下さい');
        return;
    }

    if (getLength(comments) > 1200) {
        alert('コメントは全角600文字以内で入力して下さい');
        return;
    }

    // 編集時は結果報告もチェック
    if (num == 2) {
        var result = document.form1.result.value;

        if (getLength(result) > 1200) {
            alert('結果報告は全角600文字以内で入力して下さい');
            return;
        }
    }

    if (password == "") {
        alert('パスワードを入力して下さい');
        return;
    }

    if (hankakuCheck(password) == false) {
        alert('パスワードは半角英数字で入力して下さい');
        return;
    }

    if (getLength(password) == 4) {
    } else {
        alert('パスワードは半角英数字4文字で入力して下さい');
        return;
    }

    if(picture != "" && getLength(picture.substring(picture.lastIndexOf("\\")+1,picture.length)) > 200) {
        alert("写真の画像ファイル名は半角200文字以内で入力して下さい");
        return;
    }

    if(picture != "") {
        if(checkExtensionJpeg(picture) == false) {
            alert("画像ファイルはJPEG形式しかサポートしていません");
            return;
        }
    }

    if (confirm("イベント情報を登録しますか？") == false) {
        return;
    }

    document.form1.submit();
}

/**
 * イベント情報編集パスワードチェック
 */
function eventEditCheck() {
    var password = trim(document.form1.password.value);

    if (password == "") {
        alert('パスワードを入力して下さい');
        return;
    }

    document.form1.submit();
}

/**
 * イベント情報削除時の確認
 */
function delEvent() {
    var f = document.form1;
    var i;
    var obj;
    var selected = false;

    for (i=0;(obj=f.elements[i]) != null;i++) {
        if ((f.elements[i].name).length > 7) {
            if ((f.elements[i].name).substr(0, 7) == "eventno" && f.elements[i].checked==true) {
                selected = true;
                break;
            }
        }
    }

    if (selected == false) {
        alert('イベント情報を選択して下さい');
        return;
    }

    if (confirm("イベント情報を削除しますか？") == false) {
        return;
    }

    f.flag.value = 3;
    f.submit();
}

//--------------------------------------------------------------------------------------------------
/**
 * ショップ情報関連
 */

/**
 * ショップ情報登録・編集チェック
 */
function shopAddCheck() {

    var password        = trim(document.form1.password.value);
    var categoryid      = trim(document.form1.categoryid.value);
    var name            = trim(document.form1.name.value);
    var representative1 = trim(document.form1.representative1.value);
    var representative2 = trim(document.form1.representative2.value);
    var tel1            = trim(document.form1.tel1.value);
    var tel2            = trim(document.form1.tel2.value);
    var tel3            = trim(document.form1.tel3.value);
    var fax1            = trim(document.form1.fax1.value);
    var fax2            = trim(document.form1.fax2.value);
    var fax3            = trim(document.form1.fax3.value);
    var zip1            = trim(document.form1.zip1.value);
    var zip2            = trim(document.form1.zip2.value);
    var address         = trim(document.form1.address.value);
    var shour           = trim(document.form1.shour.value);
    var smin            = trim(document.form1.smin.value);
    var ehour           = trim(document.form1.ehour.value);
    var emin            = trim(document.form1.emin.value);
    var holiday         = trim(document.form1.holiday.value);
    var mail            = trim(document.form1.mail.value);
    var url             = trim(document.form1.url.value);
    var newcomments     = trim(document.form1.newcomments.value);
    var comments1       = trim(document.form1.comments1.value);
    var comments2       = trim(document.form1.comments2.value);
    var cost            = trim(document.form1.cost.value);
    var picture         = trim(document.form1.picture.value);
    var map             = trim(document.form1.map.value);

    if (password == "") {
        alert('パスワードを入力して下さい');
        return;
    }

    if (hankakuCheck(password) == false) {
        alert('パスワードは半角英数字で入力して下さい');
        return;
    }

    if (getLength(password) == 8) {
    } else {
        alert('パスワードは半角英数字8文字で入力して下さい');
        return;
    }

    if (categoryid == "0") {
        alert('カテゴリを選択して下さい');
        return;
    }

    if (name == "") {
        alert('ショップ名を入力して下さい');
        return;
    }

    if (getLength(name) > 60) {
        alert('ショップ名は全角30文字以内で入力して下さい');
        return;
    }

    //if (representative1 == "") {
    //    alert('代表者名を入力して下さい');
    //    return;
    //}

    //if (representative2 == "") {
    //    alert('代表者名を入力して下さい');
    //    return;
    //}

    //if ((getLength(representative1) + getLength(representative2)) > 40) {
    //    alert('代表者名は全角20文字以内で入力して下さい');
    //    return;
    //}

    if (tel1 == "" || tel2 == "" || tel3 == "") {
        alert('電話番号を入力して下さい');
        return;
    } else {
        var cnt = getLength(tel1) + getLength(tel2) + getLength(tel3);

        if(isNaN(trim(tel1)) == true || isNaN(trim(tel2)) == true || isNaN(trim(tel3)) == true) {
            alert("電話番号は数値を入力して下さい");
            return;
        }

        if (cnt > 11 || cnt < 10) {
            alert('電話番号は10桁もしくは11桁で入力してください');
            return;
        }
    }

    var cnt = getLength(fax1) + getLength(fax2) + getLength(fax3);

    if (cnt != 0) {

        if (fax1 == "" || fax2 == "" || fax3 == "") {
            alert('正しいFAX番号を入力して下さい');
            return;
        }

        if(isNaN(trim(fax1)) == true || isNaN(trim(fax2)) == true || isNaN(trim(fax3)) == true) {
            alert("FAX番号は数値を入力して下さい");
            return;
        }

        if (cnt > 10 || cnt < 10) {
            alert('FAX番号は10桁で入力してください');
            return;
        }
    }

    if (zip1 == "" || zip2 == "") {
        alert('郵便番号を入力して下さい');
        return;
    } else {
        var cnt = getLength(zip1) + getLength(zip2);

        if(isNaN(trim(zip1)) == true || isNaN(trim(zip2)) == true) {
            alert("郵便番号は数値を入力して下さい");
            return;
        }

        if (cnt > 7 || cnt < 7) {
            alert('郵便番号を正しく入力してください');
            return;
        }

        if (getLength(zip1) != 3) {
            alert('郵便番号を正しく入力してください');
            return;
        }

        if (getLength(zip2) != 4) {
            alert('郵便番号を正しく入力してください');
            return;
        }
    }

    if (address == "") {
        alert('住所を入力して下さい');
        return;
    }

    if (getLength(address) > 200) {
        alert('住所は全角100文字以内で入力して下さい');
        return;
    }

    if (shour == "0" && smin == "0" && ehour == "0" && emin == "0") {
    } else {
        var stime = shour + smin;
        var etime = ehour + emin;

        if (getLength(stime) != 4) {
            alert("正しい営業開始時間を選択して下さい");
            return;
        }

        if (getLength(etime) != 4) {
            alert("正しい営業終了時間を選択して下さい");
            return;
        }
    }

    if (getLength(holiday) > 200) {
        alert('店休日は全角100文字以内で入力して下さい');
        return;
    }

    if (mail == "") {
        alert('メールアドレスを入力して下さい');
        return;
    }

    if (getLength(mail) > 100) {
        alert('メールアドレスは半角100文字以内で入力して下さい');
        return;
    }

    if (mail != "") {
        if (mail.indexOf("@") < 1 ) {
            alert("メールアドレスを正しく入力してください");
            return;
        }
    }

    if (getLength(url) > 200) {
        alert('関連URLは半角200文字以内で入力して下さい');
        return;
    }

    if (getLength(newcomments) > 60) {
        alert('新着コメントは全角30文字以内で入力して下さい');
        return;
    }

    if (comments1 == "") {
        alert('簡易コメントを入力して下さい');
        return;
    }

    if (getLength(comments1) > 60) {
        alert('簡易コメントは全角30文字以内で入力して下さい');
        return;
    }

    if (comments2 == "") {
        alert('詳細コメントを入力して下さい');
        return;
    }

    if (getLength(comments2) > 600) {
        alert('詳細コメントは全角300文字以内で入力して下さい');
        return;
    }

    var f = document.form1;
    var selpayment1;
    var selpayment2;
    var selpayment3;
    var selpay1;
    var selpay2;
    var obj;

    for (i=0;(obj=f.elements[i]) != null;i++) {
        if (f.elements[i].name == "payment1" && f.elements[i].checked==true) {
            selpayment1 = f.elements[i].value;
            break;
        }
    }

    for (i=0;(obj=f.elements[i]) != null;i++) {
        if (f.elements[i].name == "payment2" && f.elements[i].checked==true) {
            selpayment2 = f.elements[i].value;
            break;
        }
    }

    for (i=0;(obj=f.elements[i]) != null;i++) {
        if (f.elements[i].name == "payment3" && f.elements[i].checked==true) {
            selpayment3 = f.elements[i].value;
            break;
        }
    }

//    if (selpayment1 != "1" && selpayment2 != "1" && selpayment3 != "1") {
//        alert('お支払い方法を選択して下さい');
//        return;
//    }

    if (selpayment1 == 1) {
        for (i=0;(obj=f.elements[i]) != null;i++) {
            if (f.elements[i].name == "pay1" && f.elements[i].checked==true) {
                selpay1 = f.elements[i].value;
                break;
            }
        }

        if (selpay1 != "1" && selpay1 != "2") {
            alert('郵便振込みは商品発送前か後かを選択して下さい');
            return;
        }
    }

    if (selpayment2 == 1) {
        for (i=0;(obj=f.elements[i]) != null;i++) {
            if (f.elements[i].name == "pay2" && f.elements[i].checked==true) {
                selpay2 = f.elements[i].value;
                break;
            }
        }

        if (selpay2 != "1" && selpay2 != "2") {
            alert('銀行振込みは商品発送前か後かを選択して下さい');
            return;
        }
    }

//    if (cost == "") {
//        alert('送料を入力して下さい');
//        return;
//    }

    if (getLength(cost) > 600) {
        alert('送料は全角300文字以内で入力して下さい');
        return;
    }

    if(picture != "" && getLength(picture.substring(picture.lastIndexOf("\\")+1,picture.length)) > 200) {
        alert("写真の画像ファイル名は半角200文字以内で入力して下さい");
        return;
    }

    if(picture != "") {
        if(checkExtensionJpeg(picture) == false) {
            alert("画像ファイルはJPEG形式しかサポートしていません");
            return;
        }
    }

    if(map != "" && getLength(map.substring(map.lastIndexOf("\\")+1,map.length)) > 200) {
        alert("地図の画像ファイル名は半角200文字以内で入力して下さい");
        return;
    }

    if(map != "") {
        if(checkExtensionJpeg(map) == false) {
            alert("画像ファイルはJPEG形式しかサポートしていません");
            return;
        }
    }

    if (confirm("ショップ情報を登録しますか？") == false) {
        return;
    }

    document.form1.submit();
}

/**
 * ショップ情報削除時の確認
 */
function delShop() {
    var f = document.form1;
    var i;
    var obj;
    var selected = false;

    for (i=0;(obj=f.elements[i]) != null;i++) {
        if ((f.elements[i].name).length > 6) {
            if ((f.elements[i].name).substr(0, 6) == "shopno" && f.elements[i].checked==true) {
                selected = true;
                break;
            }
        }
    }

    if (selected == false) {
        alert('ショップ情報を選択して下さい');
        return;
    }

    if (confirm("ショップ情報を削除しますか？") == false) {
        return;
    }

    f.flag.value = 3;
    f.submit();
}


//--------------------------------------------------------------------------------------------------
/**
 * 商品情報関連
 */

/**
 * 商品情報登録・編集チェック
 */
function goodsAddCheck() {

    var shopno      = trim(document.form1.shopno.value);
    var name        = trim(document.form1.name.value);
    var price       = trim(document.form1.price.value);
    var newcomments = trim(document.form1.newcomments.value);
    var comments    = trim(document.form1.comments.value);
    var picture     = trim(document.form1.picture.value);

    if (shopno == "0") {
        alert('ショップ名を選択して下さい');
        return;
    }

    if (name == "") {
        alert('商品名を入力して下さい');
        return;
    }

    if (getLength(name) > 100) {
        alert('商品名は全角50文字以内で入力して下さい');
        return;
    }

    if (price == "") {
        alert('価格を入力して下さい');
        return;
    }

    if (isNaN(trim(price))) {
        alert('価格は数値を入力して下さい');
        return;
    }

    if (getLength(newcomments) > 60) {
        alert('新着コメントは全角30文字以内で入力して下さい');
        return;
    }

    if (comments == "") {
        alert('コメントを入力して下さい');
        return;
    }

    if (getLength(comments) > 600) {
        alert('コメントは全角300文字以内で入力して下さい');
        return;
    }

    if(picture != "" && getLength(picture.substring(picture.lastIndexOf("\\")+1,picture.length)) > 200) {
        alert("写真の画像ファイル名は半角200文字以内で入力して下さい");
        return;
    }

    if(picture != "") {
        if(checkExtensionJpeg(picture) == false) {
            alert("画像ファイルはJPEG形式しかサポートしていません");
            return;
        }
    }

    if (confirm("商品情報を登録しますか？") == false) {
        return;
    }

    document.form1.submit();
}

/**
 * 商品情報削除時の確認
 */
function delGoods() {
    var f = document.form1;
    var i;
    var obj;
    var selected = false;

    for (i=0;(obj=f.elements[i]) != null;i++) {
        if ((f.elements[i].name).length > 7) {
            if ((f.elements[i].name).substr(0, 7) == "goodsno" && f.elements[i].checked==true) {
                selected = true;
                break;
            }
        }
    }

    if (selected == false) {
        alert('商品情報を選択して下さい');
        return;
    }

    if (confirm("商品情報を削除しますか？") == false) {
        return;
    }

    f.flag.value = 3;
    f.submit();
}

//--------------------------------------------------------------------------------------------------
/**
 * 買い物カゴ関連
 */

/**
 * 買い物カゴ購入者情報登録チェック
 */
function editCartUser() {

    var name1    = trim(document.form1.name1.value);
    var name2    = trim(document.form1.name2.value);
    var kana1    = trim(document.form1.kana1.value);
    var kana2    = trim(document.form1.kana2.value);
    var tel1     = trim(document.form1.tel1.value);
    var tel2     = trim(document.form1.tel2.value);
    var tel3     = trim(document.form1.tel3.value);
    var zip1     = trim(document.form1.zip1.value);
    var zip2     = trim(document.form1.zip2.value);
    var address  = trim(document.form1.address.value);
    var zip21    = trim(document.form1.zip21.value);
    var zip22    = trim(document.form1.zip22.value);
    var address2 = trim(document.form1.address2.value);
    var mail     = trim(document.form1.mail.value);
    var comments = trim(document.form1.comments.value);

    if (name1 == "") {
        alert('お名前を入力して下さい');
        return;
    }

    if (name2 == "") {
        alert('お名前を入力して下さい');
        return;
    }

    if ((getLength(name1) + getLength(name2)) > 40) {
        alert('お名前は全角20文字以内で入力して下さい');
        return;
    }

    if (kana1 == "") {
        alert('ふりがなを入力して下さい');
        return;
    }

    if (kana2 == "") {
        alert('ふりがなを入力して下さい');
        return;
    }

    if ((getLength(kana1) + getLength(kana2)) > 80) {
        alert('ふりがなは全角40文字以内で入力して下さい');
        return;
    }

    if (tel1 == "" || tel2 == "" || tel3 == "") {
        alert('電話番号を入力して下さい');
        return;
    } else {
        var cnt = getLength(tel1) + getLength(tel2) + getLength(tel3);

        if(isNaN(trim(tel1)) == true || isNaN(trim(tel2)) == true || isNaN(trim(tel3)) == true) {
            alert("電話番号は数値を入力して下さい");
            return;
        }

        if (cnt > 11 || cnt < 10) {
            alert('電話番号は10桁もしくは11桁で入力してください');
            return;
        }
    }

    if (zip1 == "" || zip2 == "") {
        alert('郵便番号を入力して下さい');
        return;
    } else {
        var cnt = getLength(zip1) + getLength(zip2);

        if(isNaN(trim(zip1)) == true || isNaN(trim(zip2)) == true) {
            alert("郵便番号は数値を入力して下さい");
            return;
        }

        if (cnt > 7 || cnt < 7) {
            alert('郵便番号を正しく入力してください');
            return;
        }

        if (getLength(zip1) != 3) {
            alert('郵便番号を正しく入力してください');
            return;
        }

        if (getLength(zip2) != 4) {
            alert('郵便番号を正しく入力してください');
            return;
        }
    }

    if (address == "") {
        alert('住所を入力して下さい');
        return;
    }

    if (getLength(address) > 200) {
        alert('住所は全角100文字以内で入力して下さい');
        return;
    }

    var cnt = getLength(zip21) + getLength(zip22);

    if (cnt != 0) {

        if(isNaN(trim(zip21)) == true || isNaN(trim(zip22)) == true) {
            alert("郵便番号2は数値を入力して下さい");
            return;
        }

        if (cnt > 7 || cnt < 7) {
            alert('郵便番号2を正しく入力してください');
            return;
        }

        if (getLength(zip21) != 3) {
            alert('郵便番号2を正しく入力してください');
            return;
        }

        if (getLength(zip22) != 4) {
            alert('郵便番号2を正しく入力してください');
            return;
        }
    }

    if (getLength(address2) > 200) {
        alert('住所2は全角100文字以内で入力して下さい');
        return;
    }

    if (mail == "") {
        alert('メールアドレスを入力して下さい');
        return;
    }

    if (getLength(mail) > 100) {
        alert('メールアドレスは半角100文字以内で入力して下さい');
        return;
    }

    if (mail != "") {
        if (mail.indexOf("@") < 1 ) {
            alert("メールアドレスを正しく入力してください");
            return;
        }
    }

    if (getLength(comments) > 600) {
        alert('コメントは全角300文字以内で入力して下さい');
        return;
    }

    document.form1.submit();
}

/**
 * 商品情報削除時の確認
 */
function delCartGoods() {
    var f = document.form1;
    var i;
    var obj;
    var selected = false;

    for (i=0;(obj=f.elements[i]) != null;i++) {
        if ((f.elements[i].name).length > 7) {
            if ((f.elements[i].name).substr(0, 7) == "goodsno" && f.elements[i].checked==true) {
                selected = true;
                break;
            }
        }
    }

    if (selected == false) {
        alert('購入をキャンセルする商品を選択して下さい');
        return;
    }

    if (confirm("選択された商品の購入をキャンセルしますか？") == false) {
        return;
    }

    f.submit();
}

//--------------------------------------------------------------------------------------------------
/**
 * 販売履歴情報関連
 */

/**
 * 販売履歴情報検索チェック
 */
function saleSearchCheck() {

    var shopno = trim(document.form1.shopno.value);
    var year   = trim(document.form1.year.value);
    var month  = trim(document.form1.month.value);
    var date   = trim(document.form1.date.value);

    if (shopno == "0") {
        alert('ショップ名を選択して下さい');
        return;
    }

    if (year == "0") {
        alert('年を選択して下さい');
        return;
    }

    if (month == "0") {
        alert('月を選択して下さい');
        return;
    }

    if (date == "0") {
        alert('日を選択して下さい');
        return;
    }

    document.form1.submit();
}

/**
 * 販売履歴情報検索チェック
 */
function saleSearchCheck2() {

    var shopno = trim(document.form1.shopno.value);

    if (shopno == "0") {
        alert('ショップ名を選択して下さい');
        return;
    }

    document.form1.submit();
}

/**
 * 販売履歴情報削除時の確認
 */
function delSaleHistory() {
    var f = document.form2;
    var i;
    var obj;
    var selected = false;

    for (i=0;(obj=f.elements[i]) != null;i++) {
        if ((f.elements[i].name).length > 9) {
            if ((f.elements[i].name).substr(0, 9) == "historyno" && f.elements[i].checked==true) {
                selected = true;
                break;
            }
        }
    }

    if (selected == false) {
        alert('販売履歴情報を選択して下さい');
        return;
    }

    if (confirm("販売履歴情報を削除しますか？") == false) {
        return;
    }

    f.submit();
}

//--------------------------------------------------------------------------------------------------
/**
 * お知らせ関連
 */

/**
 * お知らせ登録・編集チェック
 */
function topNewsCheck() {

    var comments = trim(document.form1.comments.value);
    var url      = trim(document.form1.url.value);

    if (comments == "") {
        alert('ニュース名を入力して下さい');
        return;
    }

    if (getLength(comments) > 60) {
        alert('ニュース名は全角30文字以内で入力して下さい');
        return;
    }

    if (url == "") {
        alert('URLを入力して下さい');
        return;
    }

    if (getLength(url) > 200) {
        alert('URLは半角200文字以内で入力して下さい');
        return;
    }

    if (confirm("お知らせを登録しますか？") == false) {
        return;
    }

    document.form1.submit();
}

/**
 * お知らせ削除時の確認
 */
function delTopNews() {
    var f = document.form1;
    var i;
    var obj;
    var selected = false;

    for (i=0;(obj=f.elements[i]) != null;i++) {
        if ((f.elements[i].name).length > 2) {
            if ((f.elements[i].name).substr(0, 2) == "no" && f.elements[i].checked==true) {
                selected = true;
                break;
            }
        }
    }

    if (selected == false) {
        alert('お知らせを選択して下さい');
        return;
    }

    if (confirm("お知らせを削除しますか？") == false) {
        return;
    }

    f.flag.value = 3;
    f.submit();
}


//--------------------------------------------------------------------------------------------------
/**
 * ニュース関連
 */

/**
 * ニュース登録・編集チェック
 */
function newsAddCheck() {

    var title       = trim(document.form1.title.value);
    var comments    = trim(document.form1.comments.value);
    var year        = trim(document.form1.year.value);
    var month       = trim(document.form1.month.value);
    var date        = trim(document.form1.date.value);
    var picture     = trim(document.form1.picture.value);

    if (title == "") {
        alert('タイトルを入力して下さい');
        return;
    }

    if (getLength(title) > 40) {
        alert('タイトルは全角20文字以内で入力して下さい');
        return;
    }

    if (comments == "") {
        alert('コメントを入力して下さい');
        return;
    }

    if (getLength(comments) > 600) {
        alert('コメントは全角300文字以内で入力して下さい');
        return;
    }

    if (year == "0") {
        alert('掲載年を選択して下さい');
        return;
    }

    if (month == "0") {
        alert('掲載月を選択して下さい');
        return;
    }

    if (date == "0") {
        alert('掲載日を選択して下さい');
        return;
    }

    if(picture != "" && getLength(picture.substring(picture.lastIndexOf("\\")+1,picture.length)) > 200) {
        alert("写真の画像ファイル名は半角200文字以内で入力して下さい");
        return;
    }

    if(picture != "") {
        if(checkExtensionJpeg(picture) == false) {
            alert("画像ファイルはJPEG形式しかサポートしていません");
            return;
        }
    }

    if (confirm("ニュースを登録しますか？") == false) {
        return;
    }

    document.form1.submit();
}

/**
 * ニュース削除時の確認
 */
function delNews() {
    var f = document.form1;
    var i;
    var obj;
    var selected = false;

    for (i=0;(obj=f.elements[i]) != null;i++) {
        if ((f.elements[i].name).length > 2) {
            if ((f.elements[i].name).substr(0, 2) == "no" && f.elements[i].checked==true) {
                selected = true;
                break;
            }
        }
    }

    if (selected == false) {
        alert('ニュースを選択して下さい');
        return;
    }

    if (confirm("ニュースを削除しますか？") == false) {
        return;
    }

    f.flag.value = 3;
    f.submit();
}

//--------------------------------------------------------------------------------------------------
/**
 * 配信動画関連
 */

/**
 * 配信動画登録・編集チェック
 */
function movieAddCheck() {
    var title       = trim(document.form1.title.value);
    var comments    = trim(document.form1.comments.value);
    var picture     = trim(document.form1.picture.value);
    var movie       = trim(document.form1.movie.value);
    var flag        = trim(document.form1.flag.value);

    if (title == "") {
        alert('タイトルを入力して下さい');
        return;
    }

    if (getLength(title) > 40) {
        alert('タイトルは全角20文字以内で入力して下さい');
        return;
    }

    if (comments == "") {
        alert('コメントを入力して下さい');
        return;
    }

    if (getLength(comments) > 300) {
        alert('コメントは全角150文字以内で入力して下さい');
        return;
    }

    if(picture != "" && getLength(picture.substring(picture.lastIndexOf("\\")+1,picture.length)) > 200) {
        alert("写真の画像ファイル名は半角200文字以内で入力して下さい");
        return;
    }

    if(picture != "") {
        if(checkExtensionJpeg(picture) == false) {
            alert("画像ファイルはJPEG形式しかサポートしていません");
            return;
        }
    }

    if (flag == "1") {
        if (movie == "") {
            alert('動画ファイルを選択して下さい');
            return;
        }
    }

    if(movie != "" && getLength(movie.substring(movie.lastIndexOf("\\")+1,movie.length)) > 200) {
        alert("動画ファイル名は半角200文字以内で入力して下さい");
        return;
    }

    if (confirm("配信動画を登録しますか？") == false) {
        return;
    }

    document.form1.time.value = document.form1.hour.value + document.form1.min.value + document.form1.sec.value;

    document.form1.submit();
}

/**
 * 配信動画削除時の確認
 */
function delMovie() {
    var f = document.form1;
    var i;
    var obj;
    var selected = false;

    for (i=0;(obj=f.elements[i]) != null;i++) {
        if ((f.elements[i].name).length > 2) {
            if ((f.elements[i].name).substr(0, 2) == "no" && f.elements[i].checked==true) {
                selected = true;
                break;
            }
        }
    }

    if (selected == false) {
        alert('配信動画を選択して下さい');
        return;
    }

    if (confirm("配信動画を削除しますか？") == false) {
        return;
    }

    f.flag.value = 3;
    f.submit();
}
