/**
 *  The Commerce JavaScript For Front
 *  @author  fukuda -peepz inc.-
 *  @created 2009/3/6
 */

/*
 * JSONから住所を取得する
 */
var getAddressFromZipCode = function(){
	AjaxZip2.JSONDATA = '/js/zip/data';
	AjaxZip2.zip2addr('zipcode1','prefecture','city','zipcode2','address2','address1');
};
/*
 * JSONから住所を取得するForCart
 */
var getAddressFromZipCodeForCart = function(target){
	var zipcode1 = target + "[zipcode1]";
	var zipcode2 = target + "[zipcode2]";
	var prefecture = target + "[prefecture]";
	var city = target + "[city]";
	var address1 = target + "[address1]";
	var address2 = target + "[address2]";
	AjaxZip2.JSONDATA = '/js/zip/data';
	AjaxZip2.zip2addr(zipcode1,prefecture,city,zipcode2,address2,address1);
};

/*
 * カートでセレクトボックスから数量を更新する
 */
var updateQuantity = function(id){
	var product = "product_id_" + id;
	var quantity_id = "quantity_" + id;
	
	//valueを取得
	var product_id = document.getElementById(product).value;
	var selector = document.getElementById(quantity_id);
	var quantity = selector.options[selector.selectedIndex].value;
	
	//valueをセットしてサブミット
	document.updateCart.product_id.value = product_id;
	document.updateCart.quantity.value = quantity;
	document.updateCart.submit();
};

/*
 * お気に入り登録します。
 */
var addFavorite = function(url){
	var requestUrl = url;
	var ajax = new Ajax.Request(requestUrl,{method:'post',
		onComplete:function(o){
		contents = o.responseText;
		document.getElementById("message").innerHTML = contents;
		}
	});
};

var actionSubmit = function(name,message){
	if(window.confirm(message)){
		$(name).submit();
	}else{
		return false;
	}
};