// 字数统计
function charStatistic(s)
{
	var lenE = s.length;
	var lenC = 0;
	var CJK = s.match(/[^\x00-\xff]/g);
	var enter = s.match(/\r\n/g);

	if (CJK != null)
		lenC += CJK.length;

	if (enter != null)
		lenC -= enter.length;

	return (lenE + lenC);
}

// 日期比较
function compareDate(d1, d2)
{
	return ((new Date(d1.replace(/-/g, "\/"))) > (new Date(d2.replace(/-/g, "\/"))));
}

function HTMLEncode(text)
{
	text = text.replace(/&/g, "&amp;") ;
	text = text.replace(/"/g, "&quot;") ;
	text = text.replace(/</g, "&lt;") ;
	text = text.replace(/>/g, "&gt;") ;
	text = text.replace(/\ /g,"&nbsp;");
	text = text.replace(/\n/g,"<br>");
	text = text.replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;");

	return text;
}

function cleanHtml( html )
{
	html = html.replace(/<script[^>]*?>.*?<\/script>/gi, '');
	html = html.replace(/<style[^>]*?>.*?<\/style>/gi, '') ;
	html = html.replace(/<[/!]*?[^<>]*?>/gi, '') ;
	html = html.replace(/&(quot|#34);/gi, '"') ;
	html = html.replace(/&(amp|#38);/gi, '&') ;
	html = html.replace(/&(lt|#60);/, '<');
	html = html.replace(/&(gt|#62);/, '>');
	html = html.replace(/&(nbsp|#160);/, ' ');

	return html;
}

function getAbsoluteLocation(element)
{
	if ( arguments.length != 1 || element == null )
	{
		return null;
	}

	var offsetTop = element.offsetTop;
	var offsetLeft = element.offsetLeft;
	var offsetWidth = element.offsetWidth;
	var offsetHeight = element.offsetHeight;

	while( element = element.offsetParent ) 
	{
		offsetTop += element.offsetTop; 
		offsetLeft += element.offsetLeft; 
	}

	return { absoluteTop: offsetTop, absoluteLeft: offsetLeft,
			offsetWidth: offsetWidth, offsetHeight: offsetHeight };
}

function DrawImage(ImgD, imageWidth, imageHeight)
{
	var image = new Image();
	image.src = ImgD.src;

	if (image.width > 0 && image.height > 0)
	{
		if (image.width / image.height >= imageWidth / imageHeight)
		{
			if (image.width > imageWidth)
			{
				ImgD.width = imageWidth;
				ImgD.height = (image.height * imageWidth) / image.width;
			}
			else
			{
				ImgD.width = image.width;
				ImgD.height = image.height;
			}
		}
		else
		{
			if (image.height > imageHeight)
			{
				ImgD.height = imageHeight;
				ImgD.width = (image.width * imageHeight) / image.height;
			}
			else
			{
				ImgD.width = image.width;
				ImgD.height = image.height;
			}
		}
	}
}

function rgbToHex(R, G, B)
{
    return (
        Math.round(256 + 255*R).toString(16).substr(1) +
        Math.round(256 + 255*G).toString(16).substr(1) +
        Math.round(256 + 255*B).toString(16).substr(1)
    )
}

$(document).ready(function(){
	// 导航
	$(".na li").each(function(){
		$(this).hover(
			function(){
				$(".nav_sub").hide();
				$(".nav").removeClass('selected');
				$(this).find(".nav").addClass('selected');
				$("#nav_sub_" + $(this).attr('rel')).show();
			},
			function(){
			}
	)})

	$("#news_ul li:even").addClass('hui');
	$("#faq_ul li:even").addClass('hui');

	/*
	$("#parttab,#top10tab,#updatetab").idTabs(function(id, list, set){ 
		$("a", set).removeClass("ona").filter("[@href='" + id + "']", set).addClass("ona");
		$("li", set).css({'background-image': 'url(/images/03b.gif)'});
		$("a",set).filter("[@href='" + id + "']", set).parent().css({'background-image': 'url(/images/03.gif)'});

		for(i in list) 
			$(list[i]).hide();

		$(id).show();

    return false; });
	*/
});

