(function ($) {
	$(function () {
		//var loadingDivs = $('div', '#dindex');
		var loadingDivs = $("div[@id*=dindex]");
		var date = new Date();
		var str = "" + date.getYear()
				+ date.getMonth()
				+ date.getDate()
				+ date.getHours();
		$('a').each(function(){
			if($(this).attr('href').indexOf('/')!=-1&&$(this).attr('href').indexOf('#')==-1)
			{
				$(this).attr('target','_self');
			}
		});
		loadingDivs.each(function () {
			if($(this).find('div[@id*=dindex]').length == 0){
				var id = $(this).attr('id');
				if ($(this).attr('url')) {
					var obj = $(this);
					$(this).load($(this).attr('url'), function () {
						loadComplete(id, obj);
						fn_disposePicPNG(obj);
						$('a',obj).each(function(){
							if($(this).attr('href').indexOf('/')!=-1&&$(this).attr('href').indexOf('#')==-1)
							{
								$(this).attr('target','_self');
							}
						});
					});
					obj=null;
				}
			}
		});

		// 解决ie6图片显示问题
		function fn_disposePicPNG(obj) {
			$("img", obj).each(function () {
				var imgName = $(this).attr("src").toUpperCase();
				if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
					var imgID = (this.id)? "id='" + this.id + "' ": "";
					var imgClass = (this.className) ? "class='" + this.className + "' " : "";
					var imgTitle = (this.title) ? "title='" + this.title + "' " : "title='" + this.alt + "' ";
					var imgStyle = "display:inline-block;" + this.style.cssText;
					if (this.align == "left") imgStyle = "float:left;" + imgStyle;
					if (this.align == "right") imgStyle = "float:right;" + imgStyle;
					if (this.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
					var strNewHTML = "<span " + imgID + imgClass + imgTitle
						+ " style=\"" + "width:" + this.width + "px; height:" + this.height + "px;" + imgStyle + ";"  
						+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"  
						+ "(src=\'" + this.src + "\', sizingMethod='image');\"></span>"; 
					this.outerHTML = strNewHTML;
					strNewHTML=null;
				}
			});
			obj=null;
		}
		
		fn_disposePicPNG(document.body);

		//计数器
		if (typeof(siteId) != 'undefined' && typeof(webSiteUrl) != 'undefined')
		{
			//var counterUrl = "http://" + document.domain +'/html/cms/count.bc?method=addCatalogArticleClickCount';
			var counterUrl = "http://" + document.domain + "/bg/stat/count.bc?method=count";
			if (typeof(siteId) != 'undefined') {
				counterUrl += "&columnId=" + siteId;
			}
			if (typeof(counterType) != 'undefined' && typeof(articleId) != 'undefined') {
				counterUrl += "&articleId=" + articleId;
			}
			$.get(counterUrl, {time: +new Date()},function(count){
				try{
					eval("var theJsonValue = "+count);
					count = parseInt(theJsonValue.count);
					if(!isNaN(count)) {
						if($('#siteClickCount'))
						{
							$('#siteClickCount').html(count);
						}
					}
				}catch(e)
				{
				}
			});
		}
	});

	window.loadComplete = function (id, obj, time) {
		if (id.indexOf('dindex_2_2') >= 0 && typeof(listPage) != 'undefined') {
			$('#dindex_2_2').height('auto');
			time = time || 1500;
			var done=false;
			window.setTimeout(function () {
				if(done) return;
				var rightH = $('#dindex_2_2').height();
				if (!isNaN(parseInt($('#dindex_2_1').height())) && !isNaN(rightH)) {
					if (parseInt(rightH) > parseInt($('#dindex_2_1').height())) {
						window.leftHeight = parseInt($('#dindex_2_1').height());
						$('#dindex_2_1').height(rightH);
						done=true;
					} else {
						$('#dindex_2_2').height($('#dindex_2_1').height());
						done=true;
					}
				}
			}, time);
		}
	};

	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	$.getScript(gaJsHost + 'google-analytics.com/ga.js', function () {
		try {
			var pageTracker = _gat._getTracker("UA-7318186-2");
			pageTracker._trackPageview();
		} catch(err) {}
	});

})(jQuery);


function writeStrToHtmlField(inputStr,parentId,strLen){
	inputStr = inputStr.replace(/<[^>]+>/ig, '');
	//统计当前字符串长度的标志位
	var flagLen = 0;
	//结果字符串
	var resStr;
	//是否要加省略号
	var slFlag = false;
	//最终要截取的位置
	var i;
	if(inputStr.length <= strLen){
		resStr = inputStr;
	} else {
		for(i = 0; i < inputStr.length; i++){
			if(inputStr.charCodeAt(i)<=256){
				flagLen++;
			}else{
				flagLen += 2;
			}
			if(flagLen > (strLen * 2)){
				slFlag = true;
				break;
			}
		}
		resStr = inputStr.substr(0,i);
		if(slFlag){
			resStr += "...";
		}
	}
	$('#' + parentId).text(resStr);
}

function writeStrToHtmlField_new(inputStr,strLen){
	inputStr = inputStr.replace(/<[^>]+>/ig, '');
	//inputStr = inputStr.replace(/&nbsp;/ig, '');
	//统计当前字符串长度的标志位
	var flagLen = 0;
	//结果字符串
	var resStr;
	//是否要加省略号
	var slFlag = false;
	//最终要截取的位置
	var i;
	if(inputStr.length <= strLen){
		resStr = inputStr;
	} else {
		for(i = 0; i < inputStr.length; i++){
			if(inputStr.charCodeAt(i)<=256){
				flagLen++;
			}else{
				flagLen += 2;
			}
			if(flagLen > (strLen * 2)){
				slFlag = true;
				break;
			}
		}
		resStr = inputStr.substr(0,i);
		if(slFlag){
			resStr += "...";
		}
	}
	document.write(resStr);
}
