(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();
		loadingDivs.each(function () {
			if($(this).find('div[@id*=dindex]').length == 0){
				var id = $(this).attr('id');
				if ($(this).attr('url')) {
					var obj = $(this);
					var url = obj.attr('url');
					jQuery.ajax({
						url: url,
						type: "GET",
						dataType: "html",
						complete: function(res, status){
							if ( status == "success" || status == "notmodified" ) {
								//解决ie6浏览器下not found问题
								var resText = res.responseText.toLowerCase().indexOf("404 not found");
								obj.html( resText >= 0 ? "": res.responseText );
								//回调
								obj.each( function () {
									loadComplete(id, obj);
									fn_disposePicPNG(obj);
								}, [res.responseText, status, res] );
							}
						}
					});
					/*
					$(this).load($(this).attr('url'), function () {
						loadComplete(id, obj);
						fn_disposePicPNG(obj);
					});
					*/
				}
			}
		});

		// 解决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;
				}
			});
		}

		//计数器
		if (typeof(siteId) != 'undefined' && typeof(webSiteUrl) != 'undefined')
		{
			var counterUrl = "http://" + document.domain +'/html/cms/count.bc?method=addCatalogArticleClickCount';
			if (typeof(siteId) != 'undefined') {
				counterUrl += "&columnId=" + siteId;
			}
			if (typeof(counterType) != 'undefined' && typeof(articleId) != 'undefined') {
				counterUrl += "&articleId=" + articleId;
			}
			//$.get(counterUrl, {time: +new Date()});
			$.ajax({
				type:"post",
				url:counterUrl,
				dataType:"json",
				data: + new Date(),
				success:function(json){
					if(json){
						if(document.getElementById('siteClickCount')){
							$('#siteClickCount').text(json.siteClickCount);
						}
					}
				}
			});
		}
	});
	window.loadComplete = function () {
	};

})(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);
}

