/**
 * /common/action.js
 * 
 * @author     HASSY
 * @version    2006/12/05
 * @updatehist 2006/12/12 ファイルの文字コードをEUC→SJISに変更
 * 
 * 
 * 
 */


/**
 * 変数の初期化
 */
var searchPHP     = "/addrSearch.php?cadm_zip_code=";		// 住所抽出用PHP
var itemsearchPHP = "/goods/itemlist.php";						// 商品検索用PHP
var delOrderPHP   = "./my_order_del.php";					// 注文を削除PHP
var cartBackPHP   = "./my_order_back.php";					// カートに戻すPHP
var editAddrPHP   = "/myPage/my_adr_edit.php?nmar_adrno=";		// 届け先変更PHP
var delAddrPHP    = "/myPage/my_adr_del.php?nmar_adrno=";		// 届け先削除PHP
var zip           = "";
var addrCode      = "";
var addrName      = "";


/**
 * 住所１表示テキストボックスを入力不可にする
 * @author   HASSY
 * @versiion 2006/12/06
 * @param
 */
function setAddr1Status() {
	document.getElementById("hidden_AddrName").readOnly = true;
}


/**
 * 入力された郵便番号を取得して郵便番号検索用PHPにGET送信
 * @author   HASSY
 * @versiion 2006/12/05
 * @param param1,param2 郵便番号を入力するフォーム名
 */
function searchPref(param1, param2) {
	
	//全角数字配列
	var char1 = new Array("１","２","３","４","５","６","７","８","９","０");
	//半角数字配列
	var char2 = new Array(1,2,3,4,5,6,7,8,9,0);
	
	// 入力された郵便番号を一つの変数に格納
	zip = document.getElementById(param1).value + document.getElementById(param2).value;
	
	//全角 → 半角
	while(zip.match(/[０-９]/))
	{
		for(count = 0; count < char1.length; count++)
		{
			zip = zip.replace(char1[count], char2[count]);
		}
	
	}
	
	// パラメタを持って新規ウインドオープン

	window.open(searchPHP + zip, "srcphp", "width=300,height=500,scrollbars=yes,resizable=yes");
}

/**
 * 代引き不可地域のポップアップ
 * @author   KITOU
 * @versiion 2007/03/02
 */
function openSubs() {
	window.open("/cart/substitution.php", "substitute", "width=300,height=350,scrollbars=yes,resizable=yes");
}

/**
 * 呼び出し元のウインドに、地域名と住所コードを送る
 * @author   HASSY
 * @versiion 2006/12/05
 * @param param1 住所コード１１桁 param2 住所名称
 */
function getAddrCode(addrCode, addrName) {
	// 呼び出し元の指定の位置に取得データを表示させる
//	window.opener.document.getElementById("arvlAddrCode").value    = addrCode;
//	window.opener.document.getElementById("hidden_AddrName").value = addrName;

//	window.opener.document.getElementById("arvlAddrCode").setAttribute("value", addrCode);
//	window.opener.document.getElementById("hidden_AddrName").setAttribute("value", addrName);
	window.opener.document.getElementById("arvlAddrCode").value = addrCode;
	window.opener.document.getElementById("hidden_AddrName").value = addrName;
	
	// 自分自身を閉じる(何故か分かりませんが、この下に一行空行がないとwindow.close()が効きません…かも 2006/12/06 HASSY
	
	window.close();
}


/**
 * 住所表示テキストボックスの初期化
 * @author   HASSY
 * @versiion 2006/12/05
 * @param
 */
function watchTxtBox() {
	document.getElementById("hidden_AddrName").value = "";
}


/**
 * ヘッダー部分商品検索
 * @author   HASSY
 * @versiion 2006/12/12
 * @param
 */
function searchItem() {
	param = document.getElementById('searchword').value;
// 9:31 2007/02/16	Kuroda フリー検索を可能にする
//	if( param.length == 0 ) {
//		alert("検索文字が入力されていません。");
//		return false;
//	} else {
		document.getElementById('SEARCH_ITEM').action = itemsearchPHP;
		document.getElementById('SEARCH_ITEM').submit();
//	}
}


/**
 * 商品詳細検索
 * @author  HASSY
 * @version 2007/01/04
 * @param
 */
function itemDetailSearch(searchType) {
//	document.getElementById('DETAIL_SEARCH_ITEM').action = "." + itemsearchPHP;
	document.getElementById('DETAIL_SEARCH_ITEM').action = itemsearchPHP;
	document.getElementById('DETAIL_SEARCH_ITEM').submit();
}




/**
 * 注文を削除及びカートに戻す関数
 * @author   HASSY
 * @versiion 2006/12/14
 * @param
 */
function orderStatusCng(datano, param) {
	// 引数の値によって、処理を分岐
	
	// 全て削除ボタン押下時
	if( param == "0" )
	{
		document.getElementById('ORD_STATUS_CNG' + datano).action = delOrderPHP;
		document.getElementById('ORD_STATUS_CNG' + datano).submit();
	} else {
		if( window.confirm('この注文を、一度取り消します。\nよろしいですか？') ) {
			document.getElementById('ORD_STATUS_CNG' + datano).action = cartBackPHP;
			document.getElementById('ORD_STATUS_CNG' + datano).submit();
		} else {
			return false;
		}
	}
}


/**
 * 勤務先名称・所属部署名称入力ボックスの状態変更
 * @author   HASSY
 * @versiion 2006/12/19
 * @param
 */
function cngOfficeBox(param) {
	
	// 知人・その他選択時
	if( param == "1" )
	{
		document.getElementById("office_name").disabled = true;
		document.getElementById("post_name").disabled   = true;
		//住所３　入力不可
		document.getElementById("vmar_arvl_adr3").disabled = false;
		
		document.getElementById("office_name").style.backgroundColor = '#DCDCDC';
		document.getElementById("post_name").style.backgroundColor   = '#DCDCDC';
		//住所３
		document.getElementById("vmar_arvl_adr3").style.backgroundColor   = '#FFFFFF';
//		document.getElementById("ADDR3").className="opt";
//		document.getElementById("BRANCH").className="";

		document.getElementById("vmar_arvl_name1").readOnly = false;
		document.getElementById("vmar_arvl_name2").readOnly = false;
		document.getElementById("vmar_arvl_kana1").readOnly = false;
		document.getElementById("vmar_arvl_kana2").readOnly = false;
		
		// 2007/05/24 HASSY
		document.getElementById("post_clr").style.backgroundColor    = '#F0F0F0';
		// マンション名背景
		document.getElementById("man_name").style.backgroundColor    = '#EDF9DB';
	
	
	
	}
	// 勤務先選択時
	else if(param == "0")
	{
		document.getElementById("office_name").disabled = false;
		document.getElementById("post_name").disabled   = false;
		//住所３　入力可
		document.getElementById("vmar_arvl_adr3").disabled = true;
		
		document.getElementById("office_name").style.backgroundCol   = '#FFFFFF';
		document.getElementById("post_name").style.backgroundColor   = '#FFFFFF';
		// 背景色を緑にへんこう
		document.getElementById("post_clr").style.backgroundColor    = '#EDF9DB';
		document.getElementById("man_name").style.backgroundColor    = '#F0F0F0';
		
		//住所３
		document.getElementById("vmar_arvl_adr3").style.backgroundColor   = '#DCDCDC';
//		document.getElementById("ADDR3").className="";
//		document.getElementById("BRANCH").className="opt";
		
		document.getElementById("vmar_arvl_name1").value = document.getElementById("user_name1").value;
		document.getElementById("vmar_arvl_name2").value = document.getElementById("user_name2").value;
		document.getElementById("vmar_arvl_kana1").value = document.getElementById("user_kana1").value;
		document.getElementById("vmar_arvl_kana2").value = document.getElementById("user_kana2").value;
		
		//入力不可
		document.getElementById("vmar_arvl_name1").readOnly = true;
		document.getElementById("vmar_arvl_name2").readOnly = true;
		document.getElementById("vmar_arvl_kana1").readOnly = true;
		document.getElementById("vmar_arvl_kana2").readOnly = true;
	}
}


/**
 * 届け先住所変更・削除画面遷移
 * @author   HASSY
 * @versiion 2006/12/23
 * @param type 遷移先指定：0→変更/1→削除 addrno 該当住所番号
 */
function jumpAddrDetail(type, addrno) {
	if( type == 0 ) {
		window.location.href = editAddrPHP + addrno;
	} else {
		window.location.href = delAddrPHP + addrno;
	}
}

/**
 * カートログイン画面から会員登録画面に遷移
 * @author   HASSY
 * @versiion 2007/01/22
 */
function memRegist() {
	document.getElementById('IN_CART_MEMREG').action = "../regist/index.php";
	document.getElementById('IN_CART_MEMREG').submit();
}


/**
 * カート内数量変更
 * @author   HASSY
 * @versiion 2007/01/22
 */
function cngItemCnt(mainLoop, prm) {
	formName = 'CART_LIST' + mainLoop + '_' + prm;
	
//	document.getElementById(formName).action = "./cartlist.php";
	document.getElementById(formName).action = "./cngNum.php";
	document.getElementById(formName).submit();
}


/**
 * 受注保留フラグチェック
 * @author   onishi
 * @versiion 2007/02/11
 */
function chkSus(mainLoop, subLoop) {

	var formName     = 'CART_SEND' + mainLoop;
	var susChk       = 'ncrd_order_sus_chk' + mainLoop + '_' + subLoop;
    var susChk2      = 'ncrd_order_sus_chk' + mainLoop + '_';

    var checkCount = 0;
    for (var i = 0; i < maxCnt[mainLoop]; i++) {

        if (document.getElementsByName(susChk2 + i)[0].checked == true) {
            checkCount++;
        }

    }

    if (maxCnt[mainLoop] == checkCount) {

        document.getElementById("errStr" + mainLoop).innerHTML = '<p class="alert">これ以上、別のお届け先に変更できません。</p>';

        document.getElementsByName(susChk)[0].checked = false;

    } else {
        if (document.getElementById("errStr" + mainLoop).innerHTML != '') {
            document.getElementById("errStr" + mainLoop).innerHTML = '';
        }

    }

}

/**
 * 受注保留フラグの値をhiddenにセットする
 * @author   onishi
 * @versiion 2007/02/11
 */
function setSusVal(mainLoop, subLoop) {
	var formName     = 'CART_SEND' + mainLoop;
    var susChk2      = 'ncrd_order_sus_chk' + mainLoop + '_';
	var hiddenName   = 'ncrd_order_sus_flg';

    for (var i = 0; i < maxCnt[mainLoop]; i++) {

        if (typeof(document.getElementsByName(susChk2 + i)[0]) != 'undefined') {

            if (document.getElementsByName(susChk2 + i)[0].checked == true) {

                document[formName][hiddenName + i].value = document.getElementsByName(susChk2 + i)[0].value;

            }

        }

    }

}

/**
 * cartlist_html.phpで使用
 * カートに入れるボタンを押下時にチェックを行う関数
 * @author   onishi
 * @version  2007/02/15
 */
function checkCartIn(mainLoop, formObj) {
   
   var colorValue = formObj.ccrd_clr_code.value;
   var colorType  = formObj.ccrd_clr_code.type;
   var sizeValue  = formObj.ccrd_size_code.value;
   var sizeType   = formObj.ccrd_size_code.type;
   var colorFlg   = 0;
   var sizeFlg    = 0;
   var isOk       = false;
  
   if (colorType != "hidden" && colorValue == "") {
        colorFlg = 1;
   }
   if (sizeType != "hidden" && sizeValue == "") {
        sizeFlg = 1;
   }

   if (colorFlg == 1 && sizeFlg == 1) {
       alert("カラー、及びサイズを選択して下さい");
   } else {
       if (colorFlg == 1) {
        alert("カラーを選択して下さい");
       } else if (sizeFlg == 1) {
        alert("サイズを選択して下さい");
       } else {
        isOk = true;
       }
   }

   return isOk;

}


/**
 * cartpayset_html.phpで使用
 * 次へボタンを押下時にチェックを行う関数
 * @author   onishi
 * @version  2007/02/16
function checkPaysetNext() {

    var isOk           = false;
    var pointSelectVal = document.PAY_SET.ncrd_minus_pt_number.value;
    var pointVal       = document.PAY_SET.minus_pt_val.value;
    if (pointSelectVal == "2") {
    // ポイントを使用するラジオボタンにチェックがある場合
        
        if (pointVal.match(/[^0-9]/g)) {
            alert("ポイントは半角数値で入力してください。");
        } else {
            isOk = true;
        }
    } else {
        isOk = true;
    }

}

 * cartpayset_html.phpで使用
 * ポイント使用選択ラジオボタン押下時にポイント入力エリアを制御する関数
 * @author   onishi
 * @version  2007/02/16
function enabledPointForm() {

    var pointSelectVal = document.PAY_SET.ncrd_minus_pt_number.value;

    if (pointSelectVal == "2") {
        document.PAY_SET.minus_pt_val.readonly = false;
    } else {
        document.PAY_SET.minus_pt_val.readonly = true;
    }

}
 */

// 会員情報変更『電話番号』で使用..
	/**
	 * 入力項目の種類「必須／任意」の切替
	 *  
	 * @author  hashino
	 * @version 2007/04/09
	 */
	function chgImportancePhone(ys, ns)
	{
		window.document.getElementById(ys).className="must";
		window.document.getElementById(ns).className="";
	}
// ..会員情報変更『電話番号』で使用

// 会員情報変更『メールアドレス』で使用..
	/**
	 * 入力項目の種類「必須／任意」の切替
	 *  
	 * @author  hashino
	 * @version 2007/04/09
	 */
	function chgImportanceEMail(ys, ns)
	{
		showMust(ys);
		showNormal(ns);
	}

	/**
	 * 入力項目の種類「必須／任意」の切替（両方用）
	 *  
	 * @author  hashino
	 * @version 2007/04/09
	 */
	function chgImportanceEMailAll(ys)
	{
		for(i=0;i< ys.length;i++) showMust(ys[i]);
	}

	/**
	 * 入力項目の種類を「必須」へ切替
	 *  
	 * @author  hashino
	 * @version 2007/04/09
	 */
	function showMust(target)
	{
		window.document.getElementById(target).className="must";
		window.document.getElementById(target + "R").className="must";
	}

	/**
	 * 入力項目の種類を「任意」へ切替
	 *  
	 * @author  hashino
	 * @version 2007/04/09
	 */
	function showNormal(target)
	{
		window.document.getElementById(target).className="";
		window.document.getElementById(target + "R").className="";
	}
// ..会員情報変更『メールアドレス』で使用

// 届け先住所登録・変更『勤務先名』で使用..
	/**
	 * 入力項目の種類「必須」の切替
	 *  
	 * @author  haryu
	 * @version 2007/04/12
	 */
	function showImportanceOffice(ys)
	{
		window.document.getElementById(ys).className="must";
	}

	/**
	 * 入力項目の種類「任意」の切替
	 *  
	 * @author  haryu
	 * @version 2007/04/12
	 */
	function hideImportanceOffice(ys)
	{
		window.document.getElementById(ys).className="";
	}
// ..届け先住所登録・変更『勤務先名』で使用

// 届け先住所登録・変更『勤務先名』で使用..
	/**
	 * 入力項目の色「必須」の切替
	 *  
	 * @author  haryu
	 * @version 2007/04/13
	 */
	function showOfficeColor(flg)
	{

		if( flg == 1 ) {
			window.document.getElementById("office_name").style.backgroundColor ="#fffbcd";
//			window.document.getElementById("post_name").style.backgroundColor   ="#fffbcd";
		}

	}

	/**
	 * 入力項目の色「任意」の切替
	 *  
	 * @author  haryu
	 * @version 2007/04/13
	 */
	function hideOfficeColor(is)
	{
		window.document.getElementById(is).style.backgroundColor ="#DCDCDC";
	}
// ..届け先住所登録・変更『勤務先名』で使用
