/*****************************************************************
* 功能：搜索提示字符串
* 参数：
	 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 {
		$(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);	
}

// JavaScript Document 创源网络
function openproduct(id){
	window.open("productinfo.asp?code="+id,"","height=500,width=660,,top="+(window.screen.height-500)/2+",left="+(window.screen.width-660)/2+",resizable=no,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
}
function _act(code){
	if(code==1){
		document.formpage1.cp.value = document.formpage1.cp.value-1;
		document.formpage1.submit();
	}else{
		document.formpage2.cp.value = document.formpage2.cp.value-1;
		document.formpage2.submit();
	}
}

function popupImage(code,tag) {
	window.open("productinfo.asp?code="+code+"&tag="+tag,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=401,height=409,screenX=0,screenY=0,top='+(window.screen.height-409)/2+',left='+(window.screen.width-401)/2+'');
}

function changeImages(code,url,tag) {	
	$("#bpic"+code).attr("src","upfile/"+url);
}

function car_submit(){
	if ($("#company").val() == "") {
		alert("Company Name can not be empty");
		$("#company").focus();
		return false;
	}
	if ($("#Address").val() == "") {
		alert("Company Address Name can not be empty");
		$("#Address").focus();
		return false;
	}	
	if($("#uid").val()==""){
	if ($("#username").val() == "") {
		alert("Username can not be empty");
		$("#username").focus();
		return false;
	}
	if ($("#password").val() == "") {
		alert("PassWord can not be empty");
		$("#password").focus();
		return false;
	}
	}
	if ($("#vcode").val() == "") {
		alert("code Name can not be empty");
		$("#vcode").focus();
		return false;
	}
	return true;
}

function reg_submit(){
	if ($("#username").val() == "") {
		alert("Username can not be empty");
		$("#username").focus();
		return false;
	}
	if ($("#password").val() == "") {
		alert("PassWord can not be empty");
		$("#password").focus();
		return false;
	}
	if ($("#company").val() == "") {
		alert("Company Name can not be empty");
		$("#company").focus();
		return false;
	}
	if ($("#Address").val() == "") {
		alert("Company Address Name can not be empty");
		$("#Address").focus();
		return false;
	}	
	if ($("#vcode").val() == "") {
		alert("code Name can not be empty");
		$("#vcode").focus();
		return false;
	}
	return true;
}

function guest_submit(){	
	if ($("#subject").val() == "") {
		alert("Subject can not be empty");
		$("#subject").focus();
		return false;
	}
	if ($("#content").val() == "") {
		alert("Content can not be empty");
		$("#content").focus();
		return false;
	}	
	if ($("#company").val() == "") {
		alert("Company Name can not be empty");
		$("#company").focus();
		return false;
	}
	if ($("#vcode").val() == "") {
		alert("code Name can not be empty");
		$("#vcode").focus();
		return false;
	}
	return true;
}
