/**
 * Vitty
 * 共通javascript
 * 
 * @author	BRAIN WAVE
 * @version	2008-06-16
 */


/**
 * cookieCheck
 * クッキーの有効・無効をチェックする
 */
function cookieCheck() {
    if (navigator.cookieEnabled == false) {
        if (document.getElementById("cookie")) {
    	    document.getElementById("cookie").style.display = 'block';
        }
    }
}

/**
 * catSearch
 * カテゴリIDをセットして送信する
 */
function catSearch(category) {
    document.catSearchForm.target = '_self';
    document.catSearchForm.categoryId.value = category;
    document.catSearchForm.submit();
}

/**
 * submitMode
 * 動作モードをセットして送信する
 */
function submitMode(mode, action) {
    document.postParam.target = '_self';
    if (action) {
        document.postParam.action = action;
    }
    document.postParam.mode.value = mode;
    document.postParam.submit();
}

/**
 * submitPage
 * ページ番号をセットして送信する
 */
function submitPage(page, action) {
    document.postParam.target = '_self';
    if (action) {
        document.postParam.action = action;
    }
    if (document.postParam.mode) {
        document.postParam.mode.value = '';
    }
    document.postParam.page.value = page;
    document.postParam.submit();
}

/**
 * submitCategory
 * カテゴリIDをセットして送信する
 */
function submitCategory(category, action, mode) {
    document.postParam.target = '_self';
    if (action) {
        document.postParam.action = action;
    }
    if (mode) {
        document.postParam.mode.value = mode;
    }
    document.postParam.categoryId.value = category;
    document.postParam.submit();
}

/**
 * submitItem
 * 商品IDをセットして送信する
 */
function submitItem(item, action) {
    document.postParam.target = '_self';
    if (action) {
        document.postParam.action = action;
    }
    document.postParam.itemId.value = item;
    document.postParam.submit();
}

/**
 * submitItemMode
 * 商品IDと動作モードをセットして送信する
 */
function submitItemMode(item, mode, action) {
    document.postParam.target = '_self';
    if (action) {
        document.postParam.action = action;
    }
    document.postParam.itemId.value = item;
    document.postParam.mode.value   = mode;
    document.postParam.submit();
}

/**
 * submitItemDate
 * 商品IDと日付をセットして送信する
 */
function submitItemDate(item, date, action) {
    document.postParam.target = '_self';
    if (action) {
        document.postParam.action = action;
    }
    document.postParam.itemId.value   = item;
    document.postParam.saleDate.value = date;
    document.postParam.submit();
}

/**
 * submitReviewEval
 * レビューIDと評価をセットして送信する
 */
function submitReviewEval(review, eval, action) {
    document.postParam.target = '_self';
    if (action) {
        document.postParam.action = action;
    }
    document.postParam.reviewId.value = review;
    document.postParam.eval.value     = eval;
    document.postParam.submit();
}

/**
 * submitUser
 * ユーザIDをセットして送信する
 */
function submitUser(user, action) {
    document.postParam.target = '_self';
    if (action) {
        document.postParam.action = action;
    }
    document.postParam.user.value = user;
    document.postParam.submit();
}

/**
 * submitCart
 * カートIDをセットして送信する
 */
function submitCart(cart, action) {
    document.postParam.target = '_self';
    if (action) {
        document.postParam.action = action;
    }
    document.postParam.cart.value = cart;
    document.postParam.submit();
}

/**
 * confSubmit
 * 確認後にモードをセットして送信する
 */
function confSubmit(msg, mode, action) {
    if (confirm(msg)) {
        document.postParam.target = '_self';
        if (action) {
            document.postParam.action = action;
        }
        document.postParam.mode.value = mode;
        document.postParam.submit();
    }
}

/**
 * setLang
 * 利用言語をクッキーに書き込む
 */
function setLang(lang) {

	var xDay1 = new Date;
	var xDay2 = new Date;

	// 現在の言語設定を削除する
	xDay1.setDate(xDay1.getDate() - 30);
	xDay = xDay1.toGMTString();
	document.cookie = "lang=" + lang + ";path=/;expires=" + xDay;

	// 有効期限を30日後に設定して書き込む
	xDay2.setDate(xDay2.getDate() + 30);
	xDay = xDay2.toGMTString();
	document.cookie = "lang=" + lang + ";path=/;expires=" + xDay;

	// リロードする
	location.reload();
}

/**
 * messageConfirm
 * メッセージつき確認
 */
function messageConfirm(message) {
    if (confirm(message)) {
        return true;
    } else {
        return false;
    }
}

/**
 * getCookie
 * クッキーを取得する
 */
function getCookie(key) {

	var tmp    = document.cookie + ';';
	var index1 = tmp.indexOf(key, 0);

	if (index1 != -1) {
		tmp = tmp.substring(index1, tmp.length);
		var index2 = tmp.indexOf('=', 0) + 1;
		var index3 = tmp.indexOf(';', index2);
		return unescape(tmp.substring(index2, index3));
	}
	return '';
}

/**
 * setCookie
 * クッキーを設定する
 */
function setCookie(cookieId, data, day) {

	if (cookieId == null) {
		return false;
	}

	if (day == '' || day == null) {
		document.cookie = cookieId + '=' + escape(data) + ';';
	} else {
		theDay = new Date();
		theDay.setTime(theDay.getTime() + (day * 86400));
		document.cookie = cookieId + "=" + escape(data) + ';expires=' + theDay.toGMTString();
	}
	return true;
}

/**
 * chooseLocale
 * 変換先の言語のセレクトボックスを制御する（英語版用）
 */
function chooseLocale() {
	var language = ['English', 'German', 'French', 'Japanese', 'Italian', 'Portuguese', 'Spanish', 'Dutch', 'Polish'];
	var locale   = ['en', 'de', 'fr', 'ja', 'it', 'pt-PT', 'es', 'nl', 'pl'];
	var _obj = document.postParam.foreignLocale;
	var motherLocale = document.postParam.motherLocale.value;

	if (motherLocale == '') {
		_obj.length = locale.length + 1;
	} else {
		_obj.length = locale.length;
	}

	_obj.disabled    = false;
	_obj[0].value    = '';
	_obj[0].text     = 'Please select';
	_obj[0].selected = true;

	var j = 1;
	for (var i = 0; i < locale.length; i++) {
		if (motherLocale != '' && motherLocale == locale[i]) {
			continue;
		}
		_obj[j].value    = locale[i];
		_obj[j].text     = language[i];
		_obj[j].selected = false;
		j++;
	}
}

/**
 * openChild
 * 子ウィンドウを開く
 */
function openChild(url) {
	var hWndOverride = window.open(url, 'override');
	hWndOverride.focus();
}

