/*
收藏夹处理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++;
			bodyhtml = bodyhtml + '<input type="hidden" name="id[]" value="'+obj[i].value+'" />';
		}
	}
	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';
		//$('addfavorite').style.left = '254px';
	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 = '';
	var errno = null;
	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';
}
