/*
收藏夹处理JS
*/
function addFavorite(action)
{
	var selected = chkcheckbox('select[]');
	var pobj;

	if (!getCookie('uid'))
	{
		//alert('ログインしてください!');
		document.location.href = '/login.htm';
		return false;
	}
	if ( selected == 0)
	{
		alert('製品を選択してください');
		return false;
	}
	var obj = document.getElementsByName('select[]');
	var y=0;
	var bodyhtml = '';
	$('favdata').innerHTML = '';
	$('alpha').style.display = 'block';
	$('loading').style.display = 'block';
	for(i=0;i<obj.length;i++){
		if (obj[i].checked == true)
		{
			y++;
			if ( (y % 2) ==0)
			{
				x = 'productlist_bg1';
			}else{
				x = 'productlist_bg';
			}
			//pobj = $('productId'+obj[i].value);
			bodyhtml = bodyhtml + '<input type="hidden" name="id[]" value="'+obj[i].value+'" />';
			//bodyhtml = bodyhtml + '<tr><td align="right" valign="top" onmouseover="this.className=\'productlist_bg2\'" onmouseout="this.className=\''+x+'\'" style="cursor:pointer;" class="'+x+'" >'+ pobj.innerHTML +'</td></tr>';
		}
	}
	
	
	
	var width = document.body.scrollWidth;
	var left = (document.body.clientWidth-500) / 2;
	$('alpha').style.height = document.body.scrollHeight+'px';
	$('loading').style.left = (document.body.clientWidth-300) / 2 + 'px';
	window.scroll(200,200);
		$('favdata').innerHTML = bodyhtml;
		$('addfavorite').style.left = left+'px';
		if (getos() == 'ff'){
			var object = $('favdata').getElementsByTagName('INPUT');
			for(i=0;i<object.length; i++)
			{
				object[i].checked=true;
			}
		}
		
	if(window.addEventListener){ // Mozilla, Netscape, Firefox
		$('saveFav').addEventListener('click', function(){saveFavorite(action)}, false);
	} else { // IE
		$('saveFav').attachEvent('onclick',  function(){saveFavorite(action)});
	};
	window.setTimeout(function () {
		$('loading').style.display = 'none';
		$('addfavorite').style.display = 'block';
	}, 1000)
}
function saveFavorite(action)
{
	var obj = $('favdata').getElementsByTagName('INPUT');
	var string = '';
	for(i=0;i<obj.length; i++)
	{
		string = string + '&id[]='+ obj[i].value;
	}
	var url = 'index.php?mod=favorite&object='+action+'&event=add'+string;
	var errno = ajax(url);
	if( errno == 200){
		alert('製品を'+ obj.length +'件お気に入りに追加しました!');
	}else if (errno == 503)
	{
		alert('ログインしてからお使いください');
		document.location.href = '/login.htm';
	}
	$('addfavorite').style.display = 'none';
	$('alpha').style.display = 'none';
}
