/*
**************************************************************
「カートポップアップ、ヘッダーの商品数、金額に使用。」
$Revision: 1 $ $Date: 08/10/20 9:20 $
08/10/20 : BRP-08040400 : 「買い物かご追加表示ポップアップ」
**************************************************************
--------------------------------------------------------------
各種ポップアップの関数
--------------------------------------------------------------
*/

/* 以下、ポップアップの制御(cssのスタイルをvisibleにする。タイムアウトを設定する。) */

// ポップアップのタイムアウト
var objTimerID;

//"買い物かごに入れる"ポップアップ表示関数
function showPopup( result ){
	if ( result == 1 ){
		document.getElementById( 'cart-success-popup' ).style.visibility = 'visible';
		objTimerID = setTimeout( "document.getElementById( 'cart-success-popup' ).style.visibility = 'hidden';", 1000*10 );
	}else if ( result == 2 ){
		document.getElementById( 'cart-soldout-popup' ).style.visibility = 'visible';
		objTimerID = setTimeout( "document.getElementById( 'cart-soldout-popup' ).style.visibility = 'hidden';", 1000*10 );
	}else if ( result == 3 ){
		document.getElementById( 'cart-suspend-popup' ).style.visibility = 'visible';
		objTimerID = setTimeout( "document.getElementById( 'cart-suspend-popup' ).style.visibility = 'hidden';", 1000*10 );
	}
}

// "カートに入れました"ポップアップ終了関数
function closeSuccessPopup(){
	clearTimeout( objTimerID );
	document.getElementById( 'cart-success-popup' ).style.visibility = 'hidden';
}

// "カートに入れられません"ポップアップ終了関数
function closeSoldoutPopup(){
	clearTimeout( objTimerID );
	document.getElementById( 'cart-soldout-popup' ).style.visibility = 'hidden';
}

// "一時停止"ポップアップ終了関数
function closeSuspendPopup(){
	clearTimeout( objTimerID );
	document.getElementById( 'cart-suspend-popup' ).style.visibility = 'hidden';
}


//ヘッダーのカートポップアップ表示関数
function cartHeaderPopup(){
	document.getElementById( 'cart-header-popup' ).style.visibility='visible';
	objTimerID = setTimeout( "document.getElementById( 'cart-header-popup' ).style.visibility = 'hidden';", 1000*10 );
}

//ヘッダーのカートポップアップ終了関数
function closeHeaderPopup(){
	clearTimeout( objTimerID );
	document.getElementById( 'cart-header-popup' ).style.visibility = 'hidden';
}

/* 
--------------------------------------------------------------
合計数、金額をクッキーから抽出。
ヘッダーの買い物かごに使用。
--------------------------------------------------------------
*/

//cookie名
var cookieName = 'CARTSUM'

//カートデータ(商品合計数　-　合計価格)
var cartdata;

//カートデータ区切り文字
var separator = '-' ;

//カートデータを配列に
var cartdataArray;

//合計数
var totalQuantity;

//合計金額
var totalMoney;

/* 合計数、金額をクッキーから抽出 */
function _cartRead(){
	var cookie = document.cookie + ';';
	var start  = cookie.indexOf(cookieName + '=');
	var end    = cookie.indexOf(';', start);
	
	if (start != -1){
		cartdata = cookie.substring(start + cookieName.length + 1, end);
		cartdataArray = cartdata.split(separator);
	}else{
		cartdataArray = new Array(0,0);
	}
	
	totalQuantity=cartdataArray[0];
	totalMoney=cartdataArray[1];

	return;
}

//合計数量関数
function TotalQuantity(){
	_cartRead();
	return totalQuantity;
}

//ベルーナ、リュリュ用
function OutputTotal(){
	_cartRead();
	if(totalQuantity=="x"){
		outputTotal="";
	}else{
		outputTotal="商品計"+totalQuantity+"点　\\"+totalMoney;
	}
	return outputTotal;
}

//俺ライフ用
function mensOutputTotal(){
	_cartRead();
	if(totalQuantity=="x"){
		outputTotal="";
	}else{
		outputTotal="TOTAL　\\"+totalMoney+"/"+totalQuantity+"点";
	}
	return outputTotal;
}

