﻿// JScript 文件

function $( nodeId )
{
	//return document.getElementById( nodeId );
	if(document.getElementById)
	{ 
      return eval('document.getElementById("' + nodeId + '")'); 
    }
    else
    { 
     return eval('document.all.' + nodeId); 
    } 

}

function $Names( nodeName )
{
	return document.getElementsByName( nodeName );
}

function $TagNames( nodeName )
{
	return document.getElementsByTagName( nodeName );
}
function getParameter(key)
{
	var parameters = unescape(window.location.search.substr(1)).split("&");
	for( var i = 0 ; i < parameters.length ; i++ )
	{
		var paramCell = parameters[i].split("=");
		if( paramCell.length == 2 && paramCell[0].toUpperCase() == key.toUpperCase() )
		{
			return paramCell[1];
		}
	}
	return new String();
}
function getCookie(name)
            {
             var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
             if(arr != null) return unescape(arr[2]); return null;
            }
function setCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
function winopen(url)
{
	var name='',parameter = [];
	var width,height,resizable,scrollbars;
	if( arguments[1] != null )	//name
	{
		name = arguments[1];
	}
	if( arguments[2] != null )	//width
	{
		parameter[parameter.length] = "width=" + arguments[2];
	}
	if( arguments[3] != null )			//height
	{
		parameter[parameter.length] = "height=" + arguments[3];
	}
	if( arguments[4] != null )			//resizable
	{
		parameter[parameter.length] = "resizable=" + (arguments[4] ? "yes" : "no");
	}
	if( arguments[5] != null )			//scrollbars
	{
		parameter[parameter.length] = "scrollbars=" + (arguments[5] ? "yes" : "no");
	}
	return window.open(url,name,parameter.join(","));
}
function String.prototype.trim()
{
	return this.replace(/^\s*|\s*$/gi,"");
}

function String.prototype.isNumeric()
{
	return /^[-]?(\d+|\d+\.\d+)$/gi.test(this);
}

function String.prototype.isIntNumeric()
{
	return /^[-]?(\d+)$/gi.test(this);
}

function String.prototype.isEmail()
{
	return /^\w+\@{1}\w+\.\w{1}[\w\.]+[^\.]$/gi.test(this);
}

function String.prototype.isUrl()
{
	return /^(http|ftp|https)\:\/\/\w+/gi.test(this);
}
 function Array.prototype.removesplit(dx,obj)
 {
  if(isNaN(dx)||dx>this.length){return false;}
  this.splice(dx,1,obj);
 }
 function Array.prototype.remove(dx)
 {
  if(isNaN(dx)||dx>this.length){return false;}
  this.splice(dx,1);
 }
//过滤危险字符
function String.prototype.filtrateDangerCharacter( str )
{
	var s = this;
	for( var i = 0 ; i < str.length ; i++ )
	{
		s = s.replace( new RegExp( "\\" +  str.charAt( i ),"gi"), "" );
	}
	return s;
}

//得到字符串的字节长度
function String.prototype.getByteLength()
{
	var lenC = 0;
	var CJK = this.match(/[\u4E00-\u9FA5\uF900-\uFA2D]/g);
	if (CJK != null) lenC += CJK.length;

	var tmp = 0
	for (var i=0; i<this.length; i++)
	{
		tmp += /[\u4E00-\u9FA5\uF900-\uFA2D]/.test(this.charAt(i)) ? 2 : 1;
	}
	return tmp;
}
function JHshStrLen(sString)
{
var sStr,iCount,i,strTemp ;

iCount = 0 ;
sStr = sString.split("");
for (i = 0 ; i < sStr.length ; i ++)
{
strTemp = escape(sStr[i]);
if (strTemp.indexOf("%u",0) == -1) // 表示是汉字
{
iCount = iCount + 1 ;
}
else
{
iCount = iCount + 2 ;
}
}
return iCount ;
}

            /***实现局部打印***/
           function  printdiv(printpage)   
               {   
               var    headstr    =    "<html><head><title></title></head><body>";   
               var    footstr    =    "</body>";   
               var    newstr    =    document.all.item(printpage).innerHTML;   
               var    oldstr    =    document.body.innerHTML;   
               document.body.innerHTML    =    headstr+newstr+footstr;   
               window.print();     
               document.body.innerHTML    =    oldstr;   
               return    false;   
               }   
                //保留两位小数
                        function  ForDight(Dight,How)     
                                {     
                                  Dight     =     Math.round     (Dight*Math.pow(10,How))/Math.pow(10,How);     
                                  return     Dight;     
                                }
 function getMousePosition()//获取鼠标位置
                        {
                            var e = e||window.event;
                            
                            var objSrc = e.srcElement;//event source element
                            
                            
                            var left = 0;
                            var top  = 0;

                            while (objSrc.offsetParent){
                                left += objSrc.offsetLeft;
                                top  += objSrc.offsetTop;
                                objSrc     = objSrc.offsetParent;
                            }

                            left += objSrc.offsetLeft;//source element's offsetTop
                            top  += objSrc.offsetTop;//source element's offsetLeft
                            
                            //alert(e.offsetX);
                            mouseOffsetX = left + e.offsetX;
                            mouseOffsetY = top + e.offsetY;
                             hf_id=eval(div_modd); 
                             hf_id.style.display='inline';
                             hf_id.style.left=mouseOffsetX;
                             hf_id.style.top=mouseOffsetY;
                        }
            function showhideleibie(kk,cc)
            {
            var leibie=document.getElementById(kk);
            if(leibie.style.display=='none')
            {
            leibie.style.display='';
            if(kk=='left_lan'){

            cc.className="moretd";}
            }
            else
            {
            leibie.style.display='none';
            if(kk=='left_lan'){
            cc.className="moretd2";}
            }

            }
//获取子类列表 用于ie浏览器
            function gettypes(type)
            {
            var types=objvc.GetItem(type).split("|");
            var typeids=objvc.GetItem(type+"id").split("|");
            for(var i=0;i<types.length;i++)
            {
            document.write("<option value='"+typeids[i]+"'>"+types[i]+"</option>");
            }
            }
            //获取子类列表，支持主流浏览器
           function gettypes2(pname,type)
            {
                var types=objvc.GetItem(type).split("|");
                var typeids=objvc.GetItem(type+"id").split("|");
                var vhtml= " <select name="+pname+">"
                for(var i=0;i<types.length;i++)
                {
                  vhtml+= "<option value='"+typeids[i]+"'>"+types[i]+"</option>";
                 
                }
                vhtml+="</select>";
               
               return vhtml;
               
             
            }
            //图片自适应尺寸
            function picsize(obj,MaxWidth,MaxHeight){
  img=new Image();
  img.src=obj.src;
if (img.width>MaxWidth && img.height>MaxHeight){
	if (img.width/img.height>MaxWidth/MaxHeight) {
		obj.height=MaxWidth*img.height/img.width;
		obj.width=MaxWidth;
	}else {
		obj.width=MaxHeight*img.width/img.height;
		obj.height=MaxHeight;
	}
}else if (img.width>MaxWidth) {
	obj.height=MaxWidth*img.height/img.width;
	obj.width=MaxWidth;
}else if (img.height>MaxHeight) {
	obj.width=MaxHeight*img.width/img.height;
	obj.height=MaxHeight;
}else{
		obj.width=img.width;
		obj.height=img.height;
}
}


/*控制字数*/
function subTitle(kstrs,_l,bstr)
{
    var rstrs=kstrs;
   if(kstrs.toString().length>_l)
   {
      rstrs=kstrs.toString().substring(0,_l)+bstr.toString();
   }
   return rstrs
}
//获取分类名称
function gy(t,v)
{
 var sstext;
  var objstrs=objvc.GetItem(t).split("|");
  if(v=="99")
  {
    sstext= "其他";
  }
  else if(v<=0)
  {
   sstext="无";
  }
  else{
  sstext= objstrs[v];
  //alert(sstext);
  }
  return sstext;
} 
////////////////////////////////////////
//检查用户输入是否合法。。。通用
function dengdailogin()
{
   $("dengdaigif").style.display="inline";
   if($("logindiv")!=null)
   {
     $("logindiv").style.display="none";
   }
  
   
}
function CheckClientCode(obj,equaid,type)	
          {	
           var now=new Date();
           //alert(now.getMinutes());
           var code=$(obj).value;
           var equa=$(equaid).value;
          // alert(code+","+equa);
          if(type==1)
          {
               if(code.trim().length<4)
               {
                 //alert("请输入客户编码4-20个字符");
                 $(obj).focus();
                // alert("请输入用户名、密码。");
                return;
               }
               else if(equa.trim().length<6)
               {
                 $(equaid).focus();
                 return;
               }
          } 
          dengdailogin();
             var oXHR = zXmlHttp.createRequest();
             oXHR.open("get","/CheckClientCode.aspx?code="+code+"&type="+type+"&equa="+equa+"&n="+now.getMinutes(),true);
             oXHR.onreadystatechange = function () 
              {
                if (oXHR.readyState == 4) 
                {
                    if (oXHR.status == 200 || oXHR.status == 304) 
                    {
                       var returnvalue=oXHR.responseText;
                       //$("usernames").innerText=code;
                       if(returnvalue=="0"&&type==1)
                       {
                         alert("您输入的用户名或者密码错误！");
                       }
                        loginstatus(returnvalue);
                        
                    } 
                    else 
                    {
                         alert("登陆过程中发生一个错误: " + oXHR.statusText+"请重试!"); //statusText is not always accurate
                         loginstatus(0);
                    }
                }    
            };
            oXHR.send(null);
            }
       //静态页跳转 -相册
          function gotourl(t,p,s)
{
  var xmlDoc=checkXMLDocObj("/album/xmlconfig/config.xml");
  var objxml=xmlDoc.documentElement;
  var obj=objxml.getElementsByTagName("xc"+t);
  if(obj.length>0)
  {
    var vv=obj[0].text.parseJSON();
    if(s==0)
    {
    top.location.href="/album/"+t+"/_"+eval("vv.xpid"+p)+".html";
    }
    else{
    winopen("/album/"+t+"/_"+eval("vv.xpid"+p)+".html");
    }
  }
  else{
  top.location.href="/caselistbook.aspx?t="+t;
  }
}   
  //静态页跳转 -子类
  function gotourl1(zilei,t,p,s)
{
  var xmlDoc=checkXMLDocObj("/album/xmlconfig/classconfig.xml");
  var objxml=xmlDoc.documentElement;
  var obj=objxml.getElementsByTagName("type"+zilei);
  if(obj.length>0)
  {
    var vv=obj[0].text.parseJSON();
    if(s==0)
    {
    top.location.href="/album/channel"+t+"/type/"+zilei+"/_"+eval("vv.xpid"+p)+".html";
    }
    else{
    winopen("/album/channel"+t+"/type/"+zilei+"/_"+eval("vv.xpid"+p)+".html");
    }
  }
  else{
  top.location.href="/album/caselistbook.aspx?t="+t;
  }
}   