// IE判別
var isMSIE = /*@cc_on!@*/false;

// 画面情報等
var winWidth = window.screen.width;
var winHeight = window.screen.height;
var openWidth = parseInt(winWidth / 3 * 2);
var openHeight = parseInt(winHeight / 5 * 4);
var openX = parseInt((winWidth - openWidth) / 2);
var openY = parseInt((winHeight - openHeight) / 3);

// コンテンツの高さを考慮して最低580px
if(580 > openHeight) {
    openHeight = 580;
}


// フォームの郵便番号→住所検索
//
// sub = 'zip' で検索
// m に任意アクション（現在のアクション）をセットして次に進ませない
// 携帯のことを考慮してJS廃止
//function zipSearch(f,m) {
//    document.forms[f].sub.value = 'zip';
//    document.forms[f].m.value = m;
//    document.forms[f].submit();
//}

// 任意アクションをセットしてsubmit
//
// m に任意アクションをセット
//
function setActionSubmit(f,m) {
    document.forms[f].m.value = m;
    document.forms[f].submit();
}
// 送付先情報を判別してアクション切り替えしてsubmit（注文者情報入力画面用）
//
// m に任意アクションをセット
//
function setActionSubmitOrder(f,e) {
    
    var type_value = 0;
    var chk = 0;
    
    var dest_type = document.forms[f].elements[e];
    
    for(var i=0; i<dest_type.length; i++) {
        if(dest_type[i].checked) {
            type_value = dest_type[i].value;
            chk = 1;
            break;
        }
    }
    
    if(chk == 0) {
        alert('送付先が未選択です');
    }
    else {
        if(type_value == 0) {
            document.forms[f].m.value = 'order_index_transporter';
        }
        else {
            document.forms[f].m.value = 'order_index_destination';
        }
        
        document.forms[f].submit();
        
    }
    
}

// 会員登録時の確認画面のサブミット
//
// 入力項目が多いので、「戻る」の時、フォーム値を失わないようhistory.backを用いないできちんとサブミットするための配慮
//
function confirmSubmit(f,m) {
    document.forms[f].m.value = m;
    document.forms[f].submit();
}

// フォームの住所→郵便番号検索
function zipWin() {
    var url = 'http://www.post.japanpost.jp/zipcode/';
    window.open(url,'zipWin');
}

// 別ウィンドウをオープン
function openWin(url,name) {
    if(isMSIE == true) {
        w = 660;
    }
    else {
        w = 660;
    }
    if(!name) {
        name = randGenerate(8);
    }
    window.open(url,name,'width='+w+',height='+openHeight+',scrollbars=yes,resizable=yes,status=no,toolbar=no,left='+openX+',top='+openY);
}
function openWin2(url,name) {
    if(isMSIE == true) {
        w = 660;
    }
    else {
        w = 660;
    }
    if(!name) {
        name = randGenerate(8);
    }
    window.open(url,name,'width='+w+',height='+openHeight+',scrollbars=yes,resizable=yes,status=no,toolbar=no,left='+(openX+20)+',top='+(openY+20));
}

// ランダム文字列生成
function randGenerate(length) {
    
    var validchars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    
    var text = '';
    
    while(text.length < length){
        
        text += validchars.charAt( Math.floor( Math.random() * (validchars.length) ) );
    }
    
    return text;
    
}

// オプションをチェックして買い物かごへ商品submit
function addCartItem(f,i_op,i_opname) {
    var chk = 0;
    if(i_op == 1) {
        var io_id = document.forms[f].io_id;
        
        if(io_id.length) {
            for(var i=0; i<io_id.length; i++) {
                if(io_id[i].checked) {
                    chk = 1;
                }
            }
        }
        else {
            if(io_id.checked) {
                chk = 1;
            }
        }
        if(chk == 0) {
            if(!i_opname) {
                i_opname = 'オプション';
            }
            alert(i_opname+'を選択してください');
        }
    }
    else {
        chk = 1;
    }
    
    if(chk == 1) {
        document.forms[f].submit();
    }
}

function wholesale_input() {
    var change = window.document.wholesaleForm.shop_type;
    
    var shop_name = window.document.wholesaleForm.shop_name;
    var shop_name_kana = window.document.wholesaleForm.shop_name_kana;
    
    if(change.value==10 || change.value==11) {
        shop_name.value = '開店予定';
        shop_name_kana.value = 'カイテンヨテイ';
    }
    else {
        if(shop_name.value == '開店予定') {
            shop_name.value = '';
        }
        if(shop_name_kana.value == 'カイテンヨテイ') {
            shop_name_kana.value = '';
        }
    }
}


function jsLink(num,scheme) {
    
    var urls = new Array();
    
    if(!scheme) {
        scheme = 'http';
    }
    
    // ここにリンク先を羅列
    urls[0] = 'www.shiogamacci.jp/company/';
    urls[1] = 'dir.yahoo.co.jp/Business_and_Economy/Shopping_and_Services/Hobbies/Smoking/';
    urls[2] = 'maps.google.co.jp/maps?q=%E5%AE%AE%E5%9F%8E%E7%9C%8C%E4%BB%99%E5%8F%B0%E5%B8%82%E5%AE%AE%E5%9F%8E%E9%87%8E%E5%8C%BA%E5%87%BA%E8%8A%B13%E4%B8%81%E7%9B%AE28-6&lr=lang_ja&ie=UTF8&oe=utf-8&hq=&hnear=%E5%AE%AE%E5%9F%8E%E7%9C%8C%E4%BB%99%E5%8F%B0%E5%B8%82%E5%AE%AE%E5%9F%8E%E9%87%8E%E5%8C%BA%E5%87%BA%E8%8A%B1%EF%BC%93%E4%B8%81%E7%9B%AE%EF%BC%92%EF%BC%98%E2%88%92%EF%BC%96&ll=38.2832,140.986905&spn=0.024962,0.055833&z=15&iwloc=A&brcurrent=3,0x5f8985f16b2d45b9:0x83b39647948b3ccf,0';
    urls[3] = 'dir.yahoo.co.jp/Business_and_Economy/Shopping_and_Services/General_Merchandise/Imported/Asia/';
    urls[4] = '';
    urls[5] = '';
    urls[6] = '';
    urls[7] = '';
    urls[8] = '';
    urls[9] = '';
    
    var url = scheme+'://'+urls[num];
    
    var name = randGenerate(8);
    
    window.open(url,name);
}

function goSelf() {
    
    var url = location.href;
    location.href = url;
    
}

function setItemID(f,id) {
    window.document[f].i_id.value = id;
}

