// JavaScript Document
function $(id) {
	return document.getElementById(id);
}

function echo(obj,html)
{
	$(obj).innerHTML=html;
}

function fopen(obj)
{
	$(obj).style.display="";
}
function fclose(obj)
{
	$(obj).style.display="none";
}
function fremove(obj)
{
	$(obj).removeNode(true);
	
}
function lTrim(str)
{
if (str!==""){
  if (str.charAt(0) == " ")
  {
    //如果字串左边第一个字符为空格
    str = str.slice(1);//将空格从字串中去掉
    //这一句也可改成 str = str.substring(1, str.length);
    str = lTrim(str);    //递归调用
  }
}
  return str;
}

//去掉字串右边的空格
function rTrim(str)
{
if (str!==""){
  var iLength;
  
  iLength = str.length;
  if (str.charAt(iLength - 1) == " ")
  {
    //如果字串右边第一个字符为空格
    str = str.slice(0, iLength - 1);//将空格从字串中去掉
    //这一句也可改成 str = str.substring(0, iLength - 1);
    str = rTrim(str);    //递归调用
  }
}
  return str;
}

//去掉字串两边的空格
function trim(str)
{
  return lTrim(rTrim(str));
}
function sck(s)
{
	return s.replace(/\n/g,"[br]");
	//s=s.replace(chr(13)&chr(23),"<br />");	
	//return s;
}
function f(obj)
{
	//return trim(eval("document.forms[0]."+obj+".value"));
	return trim($(obj).value);
}

function setf(obj)
{
	//return eval("document.forms[0]."+obj+".focus();");
	return $(obj).focus();
}

function show(obj)
{
	var s=$(obj).style;
	s.display=s.display=="none" ? "block" : "none";
}

function checknum(obj)
{
	if($(obj).value!="")
    {
		if($(obj).value.search(/^[0-9]*/)==-1)
        {
            alert("请输入整数");
            $(obj).focus();
            return false;
        }
	}
return true;
}

function createxmlhttp()
{
	var xmlhttp=false;
	try	{
  		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	}
	catch (e) {
  		try {
   			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  		}
		catch (e) {
   			xmlhttp = false;
 		}
 	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  		xmlhttp = new XMLHttpRequest();
				if (xmlhttp.overrideMimeType) {//设置MiME类别
			xmlhttp.overrideMimeType('text/xml');
		}
	}

	return xmlhttp;
}

function getdata(url,obj1,obj2)
{
	if (url.indexOf("?")>0){
	url=url+"&randomnum="+escape(Math.random())
	}else{
	url=url+"?randomnum="+escape(Math.random())
	}	
	var xmlhttp=createxmlhttp();
	if(!xmlhttp)
	{
		alert("你的浏览器不支持XMLHTTP！！");
		return;
	}
	xmlhttp.onreadystatechange=requestdata;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	function requestdata()
	{
		fopen(obj2);
		echo(obj2,"正在加载数据，请稍等......");
		if(xmlhttp.readyState==4)
		{
			if(xmlhttp.status==200)
			{
				if(obj1!=obj2){fclose(obj1);};
				echo(obj2,xmlhttp.responseText);
			}
		}
	}
}

function postdata(url,obj,data)
{	
	if (url.indexOf("?")>0){
	url=url+"&randomnum="+escape(Math.random())
	}else{
	url=url+"?randomnum="+escape(Math.random())
	}
	var xmlhttp=createxmlhttp();
	if(!xmlhttp)
	{
		alert("你的浏览器不支持XMLHTTP！！");
		return;
	}
	xmlhttp.open("POST", url, true);
	xmlhttp.onreadystatechange=requestdata;
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send(data);
	function requestdata()
	{
		fopen(obj);
		echo(obj,"正在提交数据，请稍等......");
		//alert(xmlhttp.readyState);
		if(xmlhttp.readyState==4)
		{
			//alert(xmlhttp.status);
			if(xmlhttp.status==200)
			{
				echo(obj,xmlhttp.responseText);
			}
		}
	}
}

function overli(obj)
{
	$(obj).style.background="#fffab3";
	$(obj).style.cursor="hand";
}
function outli(obj)
{
	$(obj).style.background="";
	$(obj).style.cursor="";
}
function checkli(obj1,obj2,obj3,obj4,obj5)
{
	if (obj2!==""){
	$(obj2).value=obj3;
	}
	if (obj4!==""){
	$(obj4).value=obj5;
	}
	fclose(obj1);
}

function touming(){//显示透明层
	$("hui").style.left = 0;
	$("hui").style.top = 0;
	$("hui").style.width = window.screen.availWidth-22;//$("mainbody").offsetWidth;
	$("hui").style.height = window.screen.availHeight; //$("mainbody").offsetHeight;
	$("hui").style.display="block";
}

function JuzhongXianshicen(LabelId,Wnum,Hnum){//居中显示层
	var Swidth,Sheight;
	Sheight=document.body.clientHeight;//window.screen.availHeight;
	Swidth=document.body.clientWidth;//window.screen.availWidth;
	var Dtop = ((Sheight - Hnum) / 2)-60+document.body.scrollTop;
	if(Number(Dtop) < 0){
		Dtop = 0;
	}
	$(LabelId).style.left = ((Swidth-Wnum) / 2)+"px";
	$(LabelId).style.top = Dtop;
	$(LabelId).style.width = Wnum;
	$(LabelId).style.height = Hnum;
	$(LabelId).style.display="block";
}

function ycceng(cengId){//隐藏层
	var CengIds = cengId.split(",");
	for(var i=0;i<CengIds.length;i++){
		$(CengIds[i]).style.display="none";		
	}
}

//指向改变颜色
function mOvr(src,clrOver){if (!src.contains(event.fromElement)) {src.style.background=clrOver}}
function mOut(src,clrIn){if (!src.contains(event.toElement)) {src.style.background=clrIn;}}

//图片按比例缩放
//参数增加定义图片宽高,在调用时候就可以确定显示宽高.
function DrawImage(ImgD,iwidth,iheight){
	var image=new Image();
	//定义允许图片宽度
	if (iwidth==""){
	iwidth = 260; 
	}else{
	iwidth = iwidth; 
	}
	//定义允许图片高度
	if (iheight==""){
	iheight = 200;
	}else{
	iheight = iheight; 
	}
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){
	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;
	}
	}
	else{
	if(image.height>iheight){ 
	ImgD.height=iheight;
	ImgD.width=(image.width*iheight)/image.height; 
	}else{
	ImgD.width=image.width; 
	ImgD.height=image.height;
	}
	}
	}
} 
//调用：<img src="图片" onload="javascript:DrawImage(this,iwidth,iheight)">

function DBC2SBC(str) 
{ 
	var i; 
	var result=''; 
	for(i=0;i<str.length;i++) 
		{
			if(str.charCodeAt(i)>65295 && str.charCodeAt(i)<65306){
				result+=String.fromCharCode(str.charCodeAt(i)-65248); 
			}
			else {
				if(str.charCodeAt(i)>47 && str.charCodeAt(i)<58)
				result+=String.fromCharCode(str.charCodeAt(i)); 
			}
			if(str.charCodeAt(i)==46){//小数点
				result+=String.fromCharCode(str.charCodeAt(i)); 
			}
		} 
	return result; 
}
//str.charCodeAt(i)>47 && str.charCodeAt(i)<58//数字
//str.charCodeAt(i)>65295 && str.charCodeAt(i)=<65305

function checkname(obj){
	//alert(f(obj).length);
	if(38 == event.keyCode || 40 == event.keyCode){
		fopen("namesearch",null);
	}
	if (f(obj)!==""){
		fopen("namesearch",null);
		var str = ""
		+ "<div id=showxqnamediv "
		+ "style='"
		+ "z-index:6000;"
		+ "width:300px;"
		+ "height:100px;"
		+ "background-color:#ffffff;"
		+ "font-size:8pt;"
		+ "font-family:Tahoma;"
		+ "position:absolute;"
		+ "cursor:default;"
		+ "border:2px solid #0;"
		+ "'>"
		+ "<div id=showxqname style='"
		+ "width:100%;"
		+ "height:100px;"
		+ "background-color:white;"
		+ "line-height:14px;"
		+ "word-break:break-all;"
		+ "padding:3px;"
		+ "'>至少 2 个汉字</div>"
		+ "<div onclick='fclose(\"namesearch\",null);' "
		+ "style='"
		+ "width:100%;"
		+ "color:blue;"
		+ "'>"
		+ "<span style='float:right;' >关闭</span>"
		+ "</div>"
		+ "</div>"
		namesearch.innerHTML=str;
			if (f(obj).length >= 2 ){
				getdata("PiaoWu_List_JS.asp?action=GetJQname&inputkey="+escape(f(obj)),"showxqname","showxqname");
			}
	}else{
		fclose("namesearch");
	}
}

function getCookieVal (offset) { 
	var endstr = document.cookie.indexOf (";", offset); 
	if (endstr == -1) 
	endstr = document.cookie.length; 
	return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) { 
	var arg = name + "="; 
	var alen = arg.length; 
	var clen = document.cookie.length; 
	var i = 0; 
	while (i < clen) { 
	var j = i + alen; 
	if (document.cookie.substring(i, j) == arg) 
	return getCookieVal (j); 
	i = document.cookie.indexOf(" ", i) + 1; 
	if (i == 0) break; 
	} 
	return null;
}
function SetCookie(name, value)
{ 
var LargeExpDate = new Date (); 
LargeExpDate.setTime(LargeExpDate.getTime() + (1000*3600*24*30)); 
document.cookie = name + "=" + escape (value)+";path=/;expires=" +LargeExpDate.toGMTString(); 
} 
function DeleteCookie (name) { 
	var exp = new Date(); 
	exp.setTime (exp.getTime() - 1); 
	var cval = GetCookie (name); 
	document.cookie = name + "=" + cval + ";path=/; expires=" + exp.toGMTString();
}
/*
用途：检查输入结束日期是否在今天之后，结束如期格式：yy-MM-dd
结束如期>=起始日期
输入：
startDate：起始日期，字符串
endDate：结束如期，字符串
返回：
如果通过验证返回true,否则返回false 
*/
function checkEndDate(edate) {
	var day = new Date(); 
	var Year = 0;
	var Month = 0;
	var Day = 0;
	var CurrentDate = "";
	//初始化时间
	Year= day.getFullYear();
	Month = day.getMonth()+1;
	Day= day.getDate();
	CurrentDate += Year + "-";
	if (Month >= 10 )
	{CurrentDate += Month + "-";}
	else{CurrentDate += "0" + Month + "-";}
	if (Day >= 10 )
	{CurrentDate += Day ;}
	else{CurrentDate += "0" + Day ;} 
	var startDate = new Date(CurrentDate.replace("-",",")).getTime() ;
	var endDate = new Date(edate.replace("-",",")).getTime() ;
	if( startDate > endDate ){return false;}
	return true;
	} 
