// JavaScript Document
// 检测浏览器
NS4 = document.layers && true;
IE4 = document.all && parseInt(navigator.appVersion) >= 4;

//函数名：chksafe
//功能介绍：检查是否含有"'",'\\',"/"
//参数说明：要检查的字符串
//返回值：0：是  1：不是
function chksafe(a)
{
	fibdn = new Array ("'",'\\',"/");
	i=fibdn.length;
	j=a.length;
	for (ii=0;ii<i;ii++)
	{
		for (jj=0;jj<j;jj++)
		{	
			temp1=a.charAt(jj);
			temp2=fibdn[ii];
			if (temp1==temp2)
			{
				//alert("You have entered invalid char!");
				return 0;
			}
		}
	}
	return 1;
}

//函数名：chkspc
//功能介绍：检查是否含有空格
//参数说明：要检查的字符串
//返回值：0：是  1：不是
function chkspc(a)
{

	var i=a.length;
	for (j=0;(j<i) && (a.charAt(j)==' ');j++)
	{
	
	}
	if (i==j)
	{
		//alert("You have enter enough space!")
		return 0;
	}
	else
	{
		return 1;
	}
	if (i==0)
	{
		return 0;
	}

}

//验证特殊字符1
function strangecode(code)
{   var strangCode = "~`!@#$%^&*()+=-|\'/　？,， 。.<>";
    var temp;
    for (var i = 0; i<code.length; i++ )
    {
        temp = code.substring(i,i+1);
        if (strangCode.indexOf(temp) !=-1)
        {
            return (false);
        }
    }
}

//函数名：fucPWDchk
//功能介绍：检查是否含有非数字或字母
//参数说明：要检查的字符串
//返回值：0：含有非数字或字母 1：全部为数字或字母
function fucPWDchk(str)
{
  var strSource ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()_-+=|\}{[]:;'?/>.,<";
  var ch;
  var i;
  var temp;
  
  for (i=0;i<=(str.length-1);i++)
  {
  
    ch = str.charAt(i);
    temp = strSource.indexOf(ch);
    if (temp==-1) 
    {
     return 0;
    }
  }
  if (strSource.indexOf(ch)==-1)
  {
    return 0;
  }
  else
  {
    return 1;
  } 
}

//函数名：fucStrchk
//功能介绍：检查是否含有非数字或字母
//参数说明：要检查的字符串
//返回值：0：含有非数字或字母 1：全部为数字或字母
function fucStrchk(str)
{
  var strSource ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  var ch;
  var i;
  var temp;
  
  for (i=0;i<=(str.length-1);i++)
  {
  
    ch = str.charAt(i);
    temp = strSource.indexOf(ch);
    if (temp==-1) 
    {
     return 0;
    }
  }
  if (strSource.indexOf(ch)==-1)
  {
    return 0;
  }
  else
  {
    return 1;
  } 
}

function jtrim(str)
{     while ((str.charAt(0)==" ")||(str.charAt(0)=="　"))
          {str=str.substr(1);}      
     while (str.charAt(str.length-1)==" ")
         {str=str.substr(0,str.length-1);}
     return(str);
}


//函数名：fucCheckNUM
//功能介绍：检查是否为数字
//参数说明：要检查的数字
//返回值：1为是数字，0为不是数字
function fucCheckNUM(NUM)
{
	var i,j,strTemp;
	strTemp="0123456789";
	for (i=0;i<NUM.length;i++)
	{
		j=strTemp.indexOf(NUM.charAt(i));	
		if (j==-1)
		{
		//说明有字符不是数字
			return 0;
		}
	}
	//说明是数字
	return 1;
}

//函数名：fucCheckNumeric
//功能介绍：检查是否为数字
//参数说明：要检查的数字
//返回值：1为是数字，0为不是数字
function fucCheckNumeric(NUM)
{
	var i,j,strTemp;
	var PointNum;
	PointNum=0
	strTemp="0123456789.";
	for (i=0;i<NUM.length;i++)
	{
		j=strTemp.indexOf(NUM.charAt(i));	
		if (j==-1)
		{
		//说明有字符不是数字
			return 0;
		}
		if(j==10)
		{
			PointNum=PointNum+1;
		}
		
	}
	if(PointNum>1)
	{
		//含有两个以上小数点
		return 0;
	}
	//说明是数字
	return 1;
}

//函数名：fucCheckTel
//功能介绍：检查是否为电话号码
//参数说明：要检查的电话号码
//返回值：1为是电话号码，0为不是电话号码
function fucCheckTel(Tel)
{
	var i,j,strTemp;
	strTemp="0123456789-#() ";
	if (Tel.length < 7 )
	{
	 return 0;
	 }
	for (i=0;i<Tel.length;i++)
	{
		j=strTemp.indexOf(Tel.charAt(i));	
		if (j==-1)
		{
		//说明不是电话号码
			return 0;
		}
	}
	//说明是电话号码
	return 1;
}

//验证电话号码
function phone(phone)
{
    var phoneNum = "1234567890()- #";
    var temp;
    if (phone.length < 7)
    {
         return (false);
    }
    for (var i = 0; i < phone.length; i++)
    {
        temp = phone.substring(i,i+1);
        if (phoneNum.indexOf(temp) == -1)
        {
            return (false);
        }
    }
}

//函数名：chkemail
//功能介绍：检查是否为Email Address
//参数说明：要检查的字符串
//返回值：0：不是  1：是
function chkemail(a)
{

	var i=a.length;

	var temp = a.indexOf('@');
	//var tempd = a.indexOf('.');
	var tempd = a.indexOf('.');

	if (tempd > 0) {
		tempd = (a.substring(temp)).indexOf('.');
		
		if (temp > 1) {
		
			if ((i-temp) > 5){
				if (tempd > 2){
				
					if ((i-temp-tempd)>1){
						return 1;
					}
				}
			}
		}

	}
	
	return 0;
	
}


//opt1 小数     opt2   负数
//当opt2为1时检查num是否是负数
//当opt1为1时检查num是否是小数
//返回1是正确的，0是错误的
function chknbr(num,opt1,opt2)
{
	var i=num.length;
	var status;
//staus用于记录.的个数
	status=0;
	if ((opt2!=1) && (num.charAt(0)=='-'))
	{
		//alert("You have enter a invalid number.");
		return 0;
	
	}
//当最后一位为.时出错
	if (num.charAt(i-1)=='.')
	{
		//alert("You have enter a invalid number.");
		return 0;
	}

	for (j=0;j<i;j++)
	{
		if (num.charAt(j)=='.')
		{
			status++;
		}

		if (status>1) 
		{
		//alert("You have enter a invalid number.");
		return 0;		
		}
		if (num.charAt(j)<'0' || num.charAt(j)>'9' )
		{
			if (((opt1==0) || (num.charAt(j)!='.')) && (j!=0)) 
			{
				//alert("You have enter a invalid number.");
				return 0;
			}
		}
	}
	return 1;
}

//函数名：chkdate
//功能介绍：检查是否为日期
//参数说明：要检查的字符串
//返回值：0：不是日期  1：是日期
function chkdate(datestr)
{
	var lthdatestr=datestr.length;
	var tmpy="";
	var tmpm="";
	var tmpd="";
	var datestr;
	var status;
	status=0;
	for (i=0;i<lthdatestr;i++)
	{	if (datestr.charAt(i)== '-')
		{
			status++;
		}
		if (status>2)
		{
			//alert("Invalid format of date!");
			return 0;
		}
		if ((status==0) && (datestr.charAt(i)!='-'))
		{
			tmpy=tmpy+datestr.charAt(i)
		}
		if ((status==1) && (datestr.charAt(i)!='-'))
		{
			tmpm=tmpm+datestr.charAt(i)
		}
		if ((status==2) && (datestr.charAt(i)!='-'))
		{
			tmpd=tmpd+datestr.charAt(i)
		}

	}
	year=new String (tmpy);
	month=new String (tmpm);
	day=new String (tmpd)
	//tempdate= new String (year+month+day);
	//alert(tempdate);
	if ((tmpy.length!=4) || (tmpm.length>2) || (tmpd.length>2))
	{
		//alert("Invalid format of date!");
		return 0;
	}
	if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) )
	{
		//alert ("Invalid month or day!");
		return 0;
	}
	if (!((year % 4)==0) && (month==2) && (day==29))
	{
		//alert ("This is not a leap year!");
		return 0;
	}
	if ((month<=7) && ((month % 2)==0) && (day>=31))
	{
		//alert ("This month is a small month!");
		return 0;
	
	}
	if ((month>=8) && ((month % 2)==1) && (day>=31))
	{
		//alert ("This month is a small month!");
		return 0;
	}
	if ((month==2) && (day==30))
	{
		//alert("The Febryary never has this day!");
		return 0;
	}
	return 1;
}



//函数名：fucCheckLength
//功能介绍：检查字符串的长度
//参数说明：要检查的字符串
//返回值：长度值
function fucCheckLength(strTemp)
{
	var i,sum;
	sum=0;
	for(i=0;i<strTemp.length;i++)
	{
		if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))
			sum=sum+1;
		else
			sum=sum+2;
	}
	return sum;
}

//函数名：jreplace
//功能介绍：替换字符串中的'
//参数说明：要检查的字符串
//返回值：已经替换好的字符串
function jreplace(str)
{
	var strTemp=str;
	var i=0;
	while (i!=-1)
	{
		i=strTemp.indexOf("'");
		if (i!=-1)
		{
			strTemp=strTemp.substring(0,i)+"’"+strTemp.substring(i+1,strTemp.length);
		}
	}
	return strTemp;
}

//函数名：fucChkFileName
//功能介绍：检查是否含有 "gif","jpg","zip","htm","html"
//参数说明：filename: 要检查的字符串
//	filenarr(): 被包含的字符集合
//返回值：0：没有  1：有
function fucChkFileName(filename, filenarr)
{
	var intfarrlen = filenarr.length;
	var intflen = filename.length;
	var strfilen = filename.toLowerCase();
	for (i=0;i<intflen;i++)
	{
			temp=filenarr[i];
			if ( temp==strfilen )
			{
				//You upload a image
				return 1;
			}

	}
	return 0;
}

//函数名
//功能介绍：将月、日变为两位
//参数说明：strDate为 要检查的字符串
//返回值：变换完毕的日期型字符串（yyyy-mm-dd）
//请先用chkdate检查日期的合法性
function datechange(strDate)
{
	var tempy="";
	var tempm="";
	var tempd="";
	var tempDate;
	var status;
	status=0;
	for (i=0;i<strDate.length;i++)
	{	if (strDate.charAt(i)== '-')
		{
			status++;
		}
		if ((status==0) && (strDate.charAt(i)!='-'))
		{
			tempy=tempy+strDate.charAt(i);
		}
		if ((status==1) && (strDate.charAt(i)!='-'))
		{
			tempm=tempm+strDate.charAt(i);
		}
		if ((status==2) && (strDate.charAt(i)!='-'))
		{
			tempd=tempd+strDate.charAt(i);
		}

	}
	tempy="0000"+tempy;tempy=tempy.substring(tempy.length-4,tempy.length);
	tempm="00"+tempm;tempm=tempm.substring(tempm.length-2,tempm.length);
	tempd="00"+tempd;tempd=tempd.substring(tempd.length-2,tempd.length);
	tempDate=tempy+"-"+tempm+"-"+tempd;
	return tempDate;

}

//函数名：fucDateLimit
//功能介绍：处理客户端的时间有效性检查
//参数说明：要检查的时间串
//返回TRUE时说明时间没有越界，返回FALSE则相反
//注意必须保证前四位为年份
function fucDateLimit(strDate)
{
	var strTempYear;
	strTempYear=strDate.substring(0,4);
	if ((strTempYear<"1900") ||(strTempYear>"2999"))
	{
		return false;
	}
	return true;
}


//函数名：DrawImage 
//功能介绍：成比例缩小图片显示尺寸
//参数说明：ImgD图片对象,x图片宽度，y图片高度
var flag=false;
function DrawImage(ImgD,x,y){
   var image=new Image();
   image.src=ImgD.src;
   if(image.width>0 && image.height>0){
    flag=true;
    if(image.width/image.height>= x/y){
     if(image.width>x){  
     ImgD.width=x;
     ImgD.height=(image.height*x)/image.width;
     }else{
     ImgD.width=image.width;  
     ImgD.height=image.height;
     }
     //ImgD.alt=image.width+"×"+image.height;
     }
    else{
     if(image.height>y){  
     ImgD.height=y;
     ImgD.width=(image.width*y)/image.height;     
     }else{
     ImgD.width=image.width;  
     ImgD.height=image.height;
     }
     //ImgD.alt=image.width+"×"+image.height;
     }
    }
} 

//选择所有选项,多选列表
function ListSelectedAll(oSrc){
        if(!oSrc) return false;
        var i;
        for(i=0;i<oSrc.options.length;i++){
                oSrc.options.item(i).selected=true;
        }

}

//改变字体大小
function doZoom(size){ 
		document.getElementById('zoom').style.fontSize=size+'px'
	setTailPosition()
	}
	



// 选择指定的tab.
function selectTab(tab) {
    var form   = document.tabform;
    var TabLayer1 = getLayerStyle("TabLayer1");
    var TabLayer2 = getLayerStyle("TabLayer2");

    if (tab == "TabLayer2") {
        _showLayer(TabLayer1, false);
        _showLayer(TabLayer2, true);


    } else {
        _showLayer(TabLayer2, false);
        _showLayer(TabLayer1, true);

    }
    return true;
}


function _showLayer(layer, display) {
    if (layer) {
        if (display) {
            layer.display = "block";
        } else {
            layer.display = "none";
        }
    }
}

// 取得指定id的layer
function getLayerStyle(id) {
    if (IE4 && document.all(id)) {
        return document.all(id).style;
    } else if (NS4 && document.layers[id]) {
        return document.layers[id];
    } else {
        return null;
    }
}

//检查是否至少有一个被选择

function checkSub(theform,theid)
{
  var k=0;
  for(var i=0;i<theform.elements.length;i++)
  {  
     var e = theform.elements[i];
	 //alert(e.name+"|"+theid);
     if (e.name == theid) {
     if(e.checked==true)
	    {
		  k++;
		}
     }
  }
 return k;
}

//复选框全选与取消

function checkAll(obj,chkid,theform)
{
 var flag;
  if(obj.value==0)
  {flag=true;obj.value=1;}
  else
  {flag=false;obj.value=0;}
  
  for(var i=0;i<theform.elements.length;i++)
  {  
     var e = theform.elements[i];
     if (e.name == chkid) {
        e.checked = flag;
     }
  }
}

function TableBgLock(Obj){
	if(!Obj.checked){
		Obj.style.backgroundColor='';
	}else{
		Obj.style.backgroundColor='orange';
	}
}
//Iframe 自动伸缩
function autoIframeResize()
{
try
{
document.all['help'].style.height=help.document.body.scrollHeight;
}
catch(e){}
}


//会员登录检测
function chkLogin(theform)
	{
	  if(theform.UserId.value=="")
	    {
		  alert("请输入用户名!");
		  theform.UserId.focus();
		  return(false);
		}
	  if(theform.Password.value=="")
	    {
		  alert("请输入密码!");
		  theform.Password.focus();
		  return(false);
		}
	  if(theform.GetCode.value=="")
	    {
		  alert("请输入验证码!");
		  theform.GetCode.focus();
		  return(false);
		}
	 if((fucCheckNUM(theform.GetCode.value)==0) || (theform.GetCode.value.length!=4) )
		 {
		   alert("请正确输入验证码!\n必须为与右边提示数字相同!");
		   theform.GetCode.focus();
		   return(false);
		 }
		 theform.submit();
}

function chkBBsLogin(theform)
	{
	  if(theform.UserId.value=="")
	    {
		  alert("请输入用户名!");
		  theform.UserId.focus();
		  return(false);
		}
	  if(theform.Password.value=="")
	    {
		  alert("请输入密码!");
		  theform.Password.focus();
		  return(false);
		}
	  if(theform.GetCode.value=="")
	    {
		  alert("请输入验证码!");
		  theform.GetCode.focus();
		  return(false);
		}
	 if((fucCheckNUM(theform.GetCode.value)==0) || (theform.GetCode.value.length!=4) )
		 {
		   alert("请正确输入验证码!\n必须为与下面提示数字相同!");
		   theform.GetCode.focus();
		   return(false);
		 }
	  if(!theform.Law.checked)
	    {
		  alert("请确认接受服务条款!");
		  theform.Law.focus();
		  return(false);
		}
}


//会员服务提交
function chkService(theform)
  {
	  if(theform.content.value=="")
	    {
		  alert("请输入您要了解的信息,留下联系方式.\n\n我们将为您提供最好的服务!");
		  theform.content.focus();
		  return(false);
		}
	  if(theform.content.value.length<5)
	    {
		  alert("您留的信息也太少了吧,5个字都没得!\n\n我们将为您提供最好的服务!");
		  theform.content.focus();
		  return(false);
		}
	  if(theform.ContactStyle.value.length<4 || theform.ContactStyle.value=="输入你的联系方式如:电话、QQ、Email")
	    {
		  alert("请您留下联系方式.\n\n我们将及时与你联系!");
		  theform.ContactStyle.focus();
		  return(false);
		}
  }
  
//****************搜索**********//
  ///2006-2-18 cobra

/*下接列表选择对应值*/
		    function selObj(obj,sel)
			{
			  for(i=0;i<obj.options.length;i++)
			  {
			    if(sel==obj.options[i].value)
				{
				  obj.options[i].selected=true;
				}
			   }
			  }
  
    function chkSearch(theform)
	{
	  if(theform.Keyword.value=="")
	  {
	    alert("请输入您要搜索的关键字");
		theform.Keyword.focus();
		return false;
	  }
	  if(chksafe(theform.Keyword.value)==0)
	   {
		  alert("请在搜索关键字中不要输入',\\,/等类似似字符");
		  theform.Keyword.focus();
		  return false
		}
		/* switch(theform.Class.value){
	          case "1":
			   theform.action="/Search/Products.asp";
			    break;
	          case "2": 
			  theform.action="/Search/buy.asp";
			    break;
	          case "3": 
			  theform.action="/Search/Sell.asp";
			    break;
	          case "4": 
			  theform.action="/Search/company.asp";
			    break;
	          case "5":
			   theform.action="/News/NewsSearch.asp";
			    break;
	          case "6": 
			  theform.action="/Ask/TopicSearch.asp";
			    break;
			  default: 
			  theform.action="/Search/Product.asp";
			  }
			  return 1;*/
			  theform.submit();
	}
	
    function chkSearchIndex(theform)
	{
	  if(theform.Keyword.value=="")
	  {
	    alert("请输入您要搜索的关键字");
		theform.Keyword.focus();
		return false;
	  }
	  if(chksafe(theform.Keyword.value)==0)
	   {
		  alert("请在搜索关键字中不要输入',\\,/等类似似字符");
		  theform.Keyword.focus();
		  return false
		}	
		theform.submit();
	}
//收藏检测
function chkFav(theform)
{
  if(checkSub(theform,'Id')<1)
   {  alert("请最少选择一条记录进行收藏操作!");
   }
   else
   {
    theform.submit();
   }
 }

