/*****************************************************************
* 功能：搜索提示字符串
* 参数：
	 elementId:要提示的元素id
	 text:提示文字
******************************************************************/
function initInputText(elementId, text) {
	var obj = $("#" + elementId);
	if($.trim(obj.val()) == "") {
		obj.val(text);
	}
	obj.focus(function() {
		if($.trim(obj.val()) == text) {
			$(this).val("");
		}
	});	
	obj.blur(function() {
		if($.trim(obj.val()) == "") {
			$(this).val(text);
		}
	});
}
/*****************************************************************
* 功能：选择所有checkbox
* 参数：
	  elementId:触发全选事件的元素
	  obj:包含checkbox的容器
******************************************************************/
function checkAll(elementId, obj) {
	$("#" + elementId).click(function() {
		if($(this).attr("checked")) {
			$(obj + " input[type=checkbox]").attr("checked", "true");
		} else {
			$(obj + " input[type=checkbox]").removeAttr("checked");
		}
	});
}

/*****************************************************************
* 功能：测试元素的值是否为空
* 参数：
	  elementId:触发全选事件的元素
	  msg:提示信息
******************************************************************/
function isEmpty(elementId, msg) {
	if($.trim($("#" + elementId).val()) == "") {
		$("#" + elementId).focus();
		alert(msg);
		return true;
	} else {
		return false;
	}
}

/*****************************************************************
* 功能：测试元素的值是否为0
* 参数：
	  elementId:触发全选事件的元素
	  msg:提示信息
******************************************************************/
function isZero(elementId, msg) {
	if($.trim($("#" + elementId).val()) == 0) {
		$("#" + elementId).focus();
		alert(msg);
		return true;
	} else {
		return false;
	}
}

/*****************************************************************
* 功能：判断非负数
******************************************************************/
function isNumber1(val) {
	if (/(^0(.\d+)?$)|(^[1-9](\d+)?(\.\d+)?$)/.test(val)) {
		return true;
	} else {
		return false;
	}
}

/*****************************************************************
* 功能：@ww格式化数字
* 参数：
		val: 要格式的数字
		numDigits:保留小数位数
******************************************************************/
function formatNumber(val, numDigits) {
	if (typeof(numDigits) != "number") {
		numDigits = 2;
	}
	var num = Math.round(val * Math.pow(10, numDigits + 1) + 1) / Math.pow(10, numDigits + 1);
	return num.toString().substr(0, num.toString().length - 1);
}

/*****************************************************************
* 功能：获取文件的扩展名
* 参数：
	  path:文件路径
******************************************************************/
function getFileExtension(path) {
	return path.substring(path.lastIndexOf("."), path.length).toLowerCase();
}

/*****************************************************************
* 功能：缩放图片
******************************************************************/
jQuery.fn.resizeImg = function(options) {
	options = $.extend({
		src: $(this).attr("src"),
		width: 120,
		height: 90
	}, options);
	var _self = this;
	var img = new Image();
	$(img).attr("src", options.src);
	if (img.width > options.width || img.height > options.height) {
		if (img.width / options.width > img.height / options.height) {
			$(this).width(options.width);
			$(this).height(img.height / (img.width / options.width));
		} else {
			$(this).height(options.height);
			$(this).width(img.width / (img.height / options.height));
		}
	} else {
		alert(0)
		$(this).width(img.width);
		$(this).height(img.height);
	}
};

/*****************************************************************
* 功能：判断字符串是否为Email格式
******************************************************************/
function isEmail(val) {
	if (/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(val)) {
		return true;
	} else {
		return false;
	}
}

/*****************************************************************
* 功能：收藏本页
******************************************************************/
function add_favorite(){
	var title = document.title;
	var url = document.URL;
	if (document.all) {
		window.external.AddFavorite(url,title);
	} else if (window.sidebar) {
		window.sidebar.addPanel(title,url,"");
	}
}

/*****************************************************************
* 功能：设为首页
******************************************************************/
function set_first(obj, url){    
  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" );      
      }    
    }     
    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);    
    prefs.setCharPref('browser.startup.homepage', url);    
  }
}  

/*****************************************************************
* 功能：设置文字大小
******************************************************************/
function doZoom(size){
	zoom.style.fontSize=size+'px';
}

/*****************************************************************
* 功能：打印新闻内容
******************************************************************/
function doPrint(){
	bdhtml=window.document.body.innerHTML;
	sprnstr="<!--startprint-->";
	eprnstr="<!--endprint-->";
	prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
	prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
	window.document.body.innerHTML=prnhtml;
	window.print();
}

/*****************************************************************
* 功能：生成分页代码
******************************************************************/
function createPageHTML(_nPageCount, _nCurrIndex, _sPageName, _sPageExt)
{
  if(_nPageCount == null || _nPageCount<=1){
    return;
  }
  var nCurrIndex = _nCurrIndex || 0;

  var pghtml = "";

  pghtml += "<ul>\n";


  if(nCurrIndex == 0)
  {
    pghtml += "<li class='pgEmpty'>首页</li>\n";
    pghtml += "<li class='pgEmpty'>上一页</li>\n";
  }
  else
  {
    pghtml += "<li><a href=\""+_sPageName+"."+_sPageExt+"\">首页</a></li>\n";
    var pt = "";
    if (nCurrIndex>1) pt = "_" + (nCurrIndex-1);
    pghtml += "<li><a href=\""+_sPageName+pt+"."+_sPageExt+"\">上一页</a></li>\n";
  }

  for(var i=0; i<_nPageCount; i++)
  {
    if(nCurrIndex == i)
      pghtml += "<li class='pgCurrent'>"+(i+1)+"</li>\n";
    else
    {
      var pt = "_" + i;
      if (i==0) pt = "";
      pghtml += "<li><a href=\""+_sPageName+pt+"."+_sPageExt+"\">"+(i+1)+"</a></li>\n";
    }
  }

  if(nCurrIndex >= _nPageCount-1)
  {
    pghtml += "<li class='pgEmpty'>下一页</li>\n";
    pghtml += "<li class='pgEmpty'>尾页</li>\n";
  }
  else
  {
    pghtml += "<li><a href=\""+_sPageName+"_"+(nCurrIndex+1)+"."+_sPageExt+"\">下一页</a></li>\n";
    pghtml += "<li><a href=\""+_sPageName+"_"+(_nPageCount-1)+"."+_sPageExt+"\">尾页</a></li>\n";
  }
  pghtml += "</ul>\n";
  return pghtml;
}

/*****************************************************************
* 功能：获取日期星期
* 参数：
******************************************************************/
function today(){
	var now = new Date();
	var strDate="";
	strDate += now.getYear()+"年"+(now.getMonth()+1)+"月"+now.getDate()+"日";
	strDate += " 星期" + "日一二三四五六".split("")[now.getDay()];
	document.write(strDate);	
}




var flag=false;
function DrawImage(ImgD,iwidth,iheight){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){ 
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width; 
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){ 
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height; 
}else{
ImgD.width=image.width; 
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}


function Checked(){ //定义函数checked 
	$(".chk").each(function(){ //遍历html中class为chk的复选框标签 
		if($(this).attr("checked") == true){ //如果当前复选框的checked属性为true 
			$(this).attr("checked",false); //将该属性改为false 
		} 
		else{ //如果当前复选框的checked属性为false 
			$(this).attr("checked",true); //将该属性改为true 
		} 
	}); 
	if($("#selectalltext").html() == "全选"){ //修改label的文本为“反选” 
		$("#selectalltext").html("反选"); 
	} 
	else if($("#selectalltext").html() == "反选"){ //修改label的文本为“全选” 
		$("#selectalltext").html("全选"); 
	}
}
function onload(){
	var left=$("#left").height();
	var conn=$("#content .right").height();
	if(left<conn){
		$("#left .cplb ul").height(conn-525);
	}else{
		$("#content .right .c").height(left-75);
	}
}
