var documentDomain	=	document.domain;
if (documentDomain.indexOf('bbshouse.com') > -1) {
	document.domain = 'bbshouse.com';
} else if (documentDomain.indexOf('bbshouse.cn') > -1) {
	document.domain = 'bbshouse.cn';
}


//让Iframe高度自适应
function reinitIframe(iFrameId){
	var iframe = document.getElementById(iFrameId);
	try{
		var bHeight = iframe.contentWindow.document.body.scrollHeight;
		var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
		var height = Math.max(bHeight, dHeight);
		iframe.height =  height;
	}catch (ex){}
}

//添加到收藏夹
function addBookmark(title, url) {
	if (!title) {
		title	=	document.title;
	}
	if (!url) {
		url	=	document.location.href;
	}
	if (window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	} else if( document.all ) {
		window.external.AddFavorite(url, title);
	} else if( window.opera && window.print ) {
		//return true;
		alert("加入收藏失败，请使用Ctrl+D进行添加");
	}
}

//设为首页
function setHomepage(url) {
	if (url == 1) {
		url = 'http://' + window.location.hostname;
	}
	if (!url) {
		url	=	'http://www.bbshouse.com';
	}
	if (document.all) {
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(url);
	} else if (window.sidebar) {
		if(window.netscape)	{
			try	{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			} catch (e)	{
				alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" );
				return true;
			}
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage', url);
	}
}


/**
 根据图像比例调整适当大小
 */
function resize_image(id, width, height){
	var image = $('#' + id);
	if(image.width() > width){
		image.width(width);
		image.height(width / image.width() * image.height());
	}
	if(image.height() > height){
		image.height(height);
		image.width(height / image.height() * image.width());
	}
}


function isEmpty( inputStr ) { return !(inputStr && inputStr != '0' && inputStr.toString().length) }




function set_table_hover() {
	var color_hover	=	'#EEF5FF';
	var color_blur	=	'#ffffff';
	var color_checked	=	'#CCFFCC';
	var remainColor	=	'#ffffff';
	var ifHasCheckBox	=	$('#data_list').find('input[type=checkbox]').size() > 0 ? true : false;
	$('#data_list tr.data')
	.hover(
		function(){
			remainColor	=	$(this).find('td').css('background-color');
			$(this).find('td').css('background-color', color_hover);
		},
		function(){
			$(this).find('td').css('background-color', remainColor);
		}
	);

	if (ifHasCheckBox) {
		var checkBoxCheck = function(obj){
			var checked	=	obj.is(':checked');
			if (checked) {
				remainColor	=	color_checked;
			} else {
				remainColor	=	color_blur;
			}
			obj.parents('tr.data').find('td').css('background-color', remainColor);
		}
		
		$('#data_list tr.data')
		/*.click(function(){
			//$(this).find('input[type=checkbox]').change();
			var isChecked	=	! $(this).find('input[type=checkbox]').is(':checked');
			$(this).find('input[type=checkbox]').attr('checked', isChecked);
			if (isChecked) {
				remainColor	=	color_checked;
			} else {
				remainColor	=	color_blur;
			}
		})*/
		.find('input[type=checkbox]')
		.click(function(){
			checkBoxCheck($(this));
		})
		.change(function(){
			checkBoxCheck($(this));
		}).change();
	}
}

function swfPlayer(_file, _showInId, _width, _height) {
	var _playerUrl	=	g_baseUrl + 'flash/player/player.swf';
	var _logoUrl	=	g_baseUrl + 'img/logo.gif';
	if (!_width) {
		_width	=	300;
	}
	if (!_height) {
		_height	=	300;
	}
	swfobject.embedSWF(_playerUrl, _showInId, _width, _height, '9', '', {file: _file, logo: _logoUrl}, {allowfullscreen: true, allowscriptaccess: 'always', wmode:'transparent'});
}

$(document).ready(function(){
	/*$.ajaxSetup({
		cache : false
	});*/


	set_table_hover();

	//没有链接并且菜单栏要大于1个
	$('ul.nav_1').each(function(){
		if ( ( $(this).find('li > a').size() == 0 && $(this).find('li').size() > 1 ) || ( $(this).find('li.other').size() > 0 && $(this).find('li > a').size() == 1 && $(this).find('li').size() > 2 ) ) {
			$(this).find('li').not('.other').each(function(i){
				$(this).click(function(){
					$(this).parent().find('li').removeClass('active').eq(i).addClass('active');
					$(this).parent().next().children().hide().eq(i).show();
				});
			}).eq(0).click();
		}
	});


	//图片鼠标切换样式
	/*$('.imgBlockBorder').hover(
		function(){
			$(this).css('border', '1px solid #C0CBEB');
		},
		function(){
			$(this).css('border', '1px solid #EDEDED');
		}
	);
	$('.imgBlockBorder[bigImagedShow]').hover(
		function(){
			var $bigImagedShowUrl	=	$(this).attr('bigImagedShow');
			$("<img id='tmpBigImagedShow' src='"+ $bigImagedShowUrl +"' class='imgBlockBorder' />")
			.css('position', 'absolute')
			.css('top', $(this).offset().top)
			.css('left', $(this).offset().left + $(this).outerWidth() + 2)
			.appendTo('body');
		},
		function(){
			$('#tmpBigImagedShow').remove();
		}
	);*/
	
	$("div.imgMouseHover > img").hover(function() {
		var $this = $(this);
		$this.parent().css({'z-index' : '10'});
		if (! $this.attr('_tmpWidth')) {
			$this
			.attr('_tmpWidth', $(this).width())
			.attr('_tmpHeight', $(this).height())
			.attr('_tmpPadding', $(this).css('paddingTop'));
		}
		$this
			.addClass("hover")
			.stop()
			.animate({
				marginTop: '-106px', 
				marginLeft: '-106px', 
				top: '50%', 
				left: '50%', 
				width: '172px', 
				height: '172px',
				padding: '20px' 
			}, 400);
		} , function() {
		var $this = $(this);
		$this
			.removeClass("hover")
			.stop()
			.animate({
				marginTop: '0', 
				marginLeft: '0', 
				top: '0', 
				left: '0', 
				width: $this.attr('_tmpWidth'), 
				height: $this.attr('_tmpHeight'), 
				padding: $this.attr('_tmpPadding')
			}, 200, function(){$this.parent().css({'z-index' : '0'});});
	});



	$('<div id="loading" class="loading">数据处理中，请稍候……</div>')
	.appendTo('body')
	.css('position', 'absolute')
	.css({left: parseInt(($(window).width() - $('#loading').width()) / 2)})
	.bind("ajaxSend", function(){
		$(this).css({top: $(window).scrollTop() + 150}).show();
	})
	.bind("ajaxComplete", function(){
		$(this).hide();
	})
	;
	
	
	$('.numberPut').keyup(function(){
		$(this).val($(this).val().replace(/[^0123456789.]/g,''));
	});
	$('.numberNoDotPut').keyup(function(){
		$(this).val($(this).val().replace(/[^0123456789]/g,''));
	});

});

/*window.onload = function(){
	try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch(err) {}
}*/